summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIlya Maximets <i.maximets@ovn.org>2022-07-25 14:19:39 +0200
committerIlya Maximets <i.maximets@ovn.org>2022-07-29 17:17:50 +0200
commit9c8ea6aca8595275e71bf04c4628cd8fc66019ec (patch)
treeda6991ad68b2448f0e978037a0309533dacf69ea
parente0b417a03e3fbf0228c395f4d50b9f5b3b82f6fb (diff)
downloadopenvswitch-9c8ea6aca8595275e71bf04c4628cd8fc66019ec.tar.gz
debian: Fix incorrect linkage of the python C extension.
Current version of debian/rules simply passes the libopenvswitch.a as a command line argument via LDFLAGS, but that doesn't actually lead to this library being statically linked into python extension, which is a shared library. Instead, the build "succeeds", but the resulted extension is not usable, because most of the symbols are missing: from ovs import _json ImportError: /usr/lib/python3/dist-packages/ovs/_json.cpython-310-x86_64-linux-gnu.so: undefined symbol: json_parser_finish '-lopenvswitch' with a path to a static library should be passed instead to make it actually statically linked. But even that is not enough as all the libraries that libopenvswitch.a was built with also has to be passed. Otherwise, we'll have unresolved symbols like ssl, cap-ng, etc. The most convenient way to get all the required libraries and cflags seems to be by using pkg-config. Setting several environment variables for pkg-config, so it can find the libopenvswitch.pc in non-standard directory, not skip default locations and also report them with the right base directory. Extra '-Wl,-Bstatic -lopenvswitch -Wl,-Bdynamic' is added before all the libs to ensure static linking of libopenvswitch even if the dynamic library is available in a system. One more problem here is that it is not possible to link static library into dynamic library if the static one is not position independent. So, we have to build everything with -fPIC, otherwise it's not possible to build C extensions. Also added a simple CI script to check that we're able to use python C extension after installing a package. Fixes: 6ad3be9749ab ("debian: Fix build of python json C extension.") Acked-by: Frode Nordahl <frode.nordahl@canonical.com> Reviewed-by: David Marchand <david.marchand@redhat.com> Signed-off-by: Ilya Maximets <i.maximets@ovn.org>
-rwxr-xr-x.ci/linux-build.sh7
-rwxr-xr-xdebian/rules11
2 files changed, 15 insertions, 3 deletions
diff --git a/.ci/linux-build.sh b/.ci/linux-build.sh
index c396ec1e8..9746a8239 100755
--- a/.ci/linux-build.sh
+++ b/.ci/linux-build.sh
@@ -212,6 +212,13 @@ if [ "$DEB_PACKAGE" ]; then
echo $deps | xargs sudo apt -y install
# install the locally built openvswitch packages
sudo dpkg -i $packages
+
+ # Check that python C extension is built correctly.
+ python3 -c "
+from ovs import _json
+import ovs.json
+assert ovs.json.from_string('{\"a\": 42}') == {'a': 42}"
+
exit 0
fi
diff --git a/debian/rules b/debian/rules
index 1ab0c74a0..971bc1775 100755
--- a/debian/rules
+++ b/debian/rules
@@ -2,6 +2,7 @@
# -*- makefile -*-
#export DH_VERBOSE=1
export DEB_BUILD_MAINT_OPTIONS = hardening=+all
+export DEB_CFLAGS_MAINT_APPEND = -fPIC
%:
dh $@
@@ -91,10 +92,14 @@ override_dh_auto_install:
execute_after_dh_install:
set -e && for pyvers in $(PYTHON3S); do \
- cd python && \
+ cd python; \
+ export PKG_CONFIG_PATH=$(CURDIR)/debian/tmp/usr/lib/pkgconfig; \
+ export PKG_CONFIG_SYSROOT_DIR=$(CURDIR)/debian/tmp; \
+ export PKG_CONFIG_SYSTEM_INCLUDE_PATH=/; \
+ export PKG_CONFIG_SYSTEM_LIBRARY_PATH=/; \
enable_shared=no \
- CFLAGS=-I$(CURDIR)/debian/tmp/usr/include \
- LDFLAGS=$(CURDIR)/debian/tmp/usr/lib/libopenvswitch.a \
+ extra_cflags="`pkg-config --cflags libopenvswitch`" \
+ extra_libs="-Wl,-Bstatic -lopenvswitch -Wl,-Bdynamic `pkg-config --libs --static libopenvswitch`" \
python$$pyvers setup.py install --install-layout=deb \
--root $(CURDIR)/debian/python3-openvswitch; \
cd ..; \