]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
build: fix handling of dependancies to fix build on openSUSE
authorAleksa Sarai <cyphar@cyphar.com>
Fri, 28 Oct 2022 01:38:20 +0000 (12:38 +1100)
committerAleksa Sarai <cyphar@cyphar.com>
Fri, 28 Oct 2022 03:34:27 +0000 (14:34 +1100)
Among other things, openSUSE places seccomp.h inside a non-default
include directory (/usr/include/seccomp/seccomp.h) which revealed
several issues with how dependencies were being handled previously.

The most notable issue is that the include cflags of our build
dependencies were not being provided to the recipes for static
executables (yet they still expected access to the dependency headers).

This also involved a minor cleanup of how these dependencies are
collected, and added liburing to the set of private pkg-config libs
(which I assume was an oversight?).

Signed-off-by: Aleksa Sarai <cyphar@cyphar.com>
meson.build
src/lxc/cmd/meson.build
src/lxc/meson.build

index c804b6f6ac6a0a0180b97a0169ed2366ca2f3746..0765c9b02cd3a54ab0c3e6850dcaac974dc681bb 100644 (file)
@@ -22,6 +22,9 @@ cc = meson.get_compiler('c')
 pkgconfig = import('pkgconfig')
 pkgconfig_libs = []
 
+liblxc_dependencies = []
+oss_fuzz_dependencies = []
+
 # Version.
 liblxc_version = '1.7.0'
 version_data = configuration_data()
@@ -254,6 +257,8 @@ if want_io_uring
     if cc.has_function('io_uring_prep_poll_add', prefix: '#include <liburing.h>', dependencies: liburing) == false
         error('liburing version does not support IORING_POLL_ADD_MULTI')
     endif
+    pkgconfig_libs += liburing
+    liblxc_dependencies += liburing
 
     srcconf.set10('HAVE_LIBURING', true)
 else
@@ -289,7 +294,7 @@ if not want_sd_bus.disabled()
         has_sd_bus = false
     endif
 
-    if not cc.has_function('sd_bus_call_method_asyncv', prefix: '#include <systemd/sd-bus.h>', dependencies: libsystemd) 
+    if not cc.has_function('sd_bus_call_method_asyncv', prefix: '#include <systemd/sd-bus.h>', dependencies: libsystemd)
         if not sd_bus_optional
             error('libsystemd misses required sd_bus_call_method_asyncv function')
         endif
@@ -297,6 +302,13 @@ if not want_sd_bus.disabled()
         has_sd_bus = false
     endif
 
+    if has_sd_bus
+        liblxc_dependencies += libsystemd
+        if want_oss_fuzz
+            oss_fuzz_dependencies += libsystemd
+        endif
+    endif
+
     srcconf.set10('HAVE_LIBSYSTEMD', has_sd_bus)
 else
     has_sd_bus = false
@@ -348,12 +360,14 @@ endif
 
 ## Threads.
 threads = dependency('threads')
+liblxc_dependencies += threads
 
 ## Seccomp.
 if want_seccomp
     libseccomp = dependency('libseccomp', required: false)
     srcconf.set10('HAVE_SECCOMP', libseccomp.found())
     pkgconfig_libs += libseccomp
+    liblxc_dependencies += libseccomp
     if libseccomp.found()
         if libseccomp.version().version_compare('>=2.5.0')
             # https://github.com/seccomp/libseccomp/commit/dead12bc788b259b148cc4d93b970ef0bd602b1a
@@ -380,7 +394,7 @@ if want_seccomp
         ]
 
             # We get -1 if the size cannot be determined
-            if cc.sizeof(decl, prefix: seccomp_headers, args: '-D_GNU_SOURCE') > 0
+            if cc.sizeof(decl, prefix: seccomp_headers, args: '-D_GNU_SOURCE', dependencies: libseccomp) > 0
                 srcconf.set10('HAVE_' + decl.underscorify().to_upper(), true)
             else
                 srcconf.set10('HAVE_' + decl.underscorify().to_upper(), false)
@@ -396,6 +410,7 @@ if want_selinux
     libselinux = dependency('libselinux', required: false)
     srcconf.set10('HAVE_SELINUX', libselinux.found())
     pkgconfig_libs += libselinux
+    liblxc_dependencies += libselinux
 else
     srcconf.set10('HAVE_SELINUX', false)
 endif
@@ -404,6 +419,8 @@ endif
 if want_apparmor
     libapparmor = dependency('libapparmor', required: false)
     srcconf.set10('HAVE_APPARMOR', libapparmor.found())
+    # We do not use the AppArmor library at runtime, so it's not in our pkg-config.
+    liblxc_dependencies += libapparmor
 else
     srcconf.set10('HAVE_APPARMOR', false)
 endif
@@ -413,6 +430,7 @@ if want_openssl
     libopenssl = dependency('openssl', required: false)
     srcconf.set10('HAVE_OPENSSL', libopenssl.found())
     pkgconfig_libs += libopenssl
+    liblxc_dependencies += libopenssl
 else
     srcconf.set10('HAVE_OPENSSL', false)
 endif
@@ -429,6 +447,7 @@ if want_capabilities
     endif
     srcconf.set10('HAVE_LIBCAP', libcap.found())
     pkgconfig_libs += libcap
+    liblxc_dependencies += libcap
 
     libcap_static = dependency('libcap', required: false, static: true)
     if not libcap_static.found()
@@ -453,7 +472,6 @@ endif
 
 libutil = cc.find_library('util', required: false)
 
-oss_fuzz_dependencies = []
 if want_oss_fuzz
     srcconf.set10('FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION', true)
     srcconf.set10('RUN_ON_OSS_FUZZ', true)
@@ -472,8 +490,14 @@ pkgconfig_libs += pam
 have = cc.has_function('fmemopen', prefix: '#include <stdio.h>', args: '-D_GNU_SOURCE')
 srcconf.set10('HAVE_FMEMOPEN', have)
 
-have_openpty = cc.has_function('openpty', dependencies: libutil, prefix: '#include <pty.h>')
-srcconf.set10('HAVE_OPENPTY', have_openpty)
+have = cc.has_function('openpty', dependencies: libutil, prefix: '#include <pty.h>')
+srcconf.set10('HAVE_OPENPTY', have)
+if have
+    liblxc_dependencies += libutil
+    if want_oss_fuzz
+        oss_fuzz_dependencies += libutil
+    endif
+endif
 
 have = cc.has_function('pthread_setcancelstate', prefix: '#include <pthread.h>')
 srcconf.set10('HAVE_PTHREAD_SETCANCELSTATE', have)
@@ -598,7 +622,7 @@ foreach decl: [
 ]
 
     # We get -1 if the size cannot be determined
-    if cc.sizeof(decl, prefix: decl_headers, args: '-D_GNU_SOURCE') > 0
+    if cc.sizeof(decl, prefix: decl_headers, args: '-D_GNU_SOURCE', dependencies: liblxc_dependencies) > 0
         srcconf.set10('HAVE_' + decl.underscorify().to_upper(), true)
     else
         srcconf.set10('HAVE_' + decl.underscorify().to_upper(), false)
@@ -814,51 +838,19 @@ liblxc_includes = include_directories(
     'src/lxc/cgroups',
     'src/lxc/storage')
 
+# Our static sub-project binaries don't (and in fact can't) link to our
+# dependencies directly, but need access to the headers when compiling (most
+# notably seccomp headers).
+liblxc_dependency_headers = []
+foreach dep: liblxc_dependencies
+    liblxc_dependency_headers += dep.partial_dependency(compile_args: true)
+endforeach
+
 # Early sub-directories.
 subdir('src/include')
 subdir('src/lxc')
 subdir('src/lxc/pam')
 
-# Library.
-liblxc_dependencies = [
-    threads,
-]
-
-if want_seccomp
-    liblxc_dependencies += libseccomp
-endif
-
-if want_capabilities
-    liblxc_dependencies += [libcap]
-endif
-
-if want_openssl
-    liblxc_dependencies += [libopenssl]
-endif
-
-if want_selinux
-    liblxc_dependencies += [libselinux]
-endif
-
-if want_apparmor
-    liblxc_dependencies += [libapparmor]
-endif
-
-if want_io_uring
-    liblxc_dependencies += [liburing]
-endif
-
-if has_sd_bus
-    liblxc_dependencies += [libsystemd]
-endif
-
-if have_openpty
-    liblxc_dependencies += [libutil]
-    if want_oss_fuzz
-        oss_fuzz_dependencies += [libutil]
-    endif
-endif
-
 liblxc_link_whole = [liblxc_static]
 
 liblxc = shared_library(
index f84269ecbcab6d3d1e1b83d0d35fd5d8a3a4cd79..e083130254bb15dd626860904dfaba4a2136eed2 100644 (file)
@@ -68,7 +68,7 @@ if sanitize == 'none'
         link_with: [liblxc_static],
         link_args: ['-static'],
         c_args: ['-DNO_LXC_CONF'],
-        dependencies: [libcap_static],
+        dependencies: [libcap_static] + liblxc_dependency_headers,
         install_dir: sbindir,
         install: true)
 endif
index 38faf7f5ed5470a4e3272bf2944ca6ed6cfc6160..86e86b87f6fc9236bb5741873689873e1b84e6eb 100644 (file)
@@ -152,7 +152,7 @@ liblxc_static = static_library(
     liblxc_sources + include_sources + netns_ifaddrs_sources,
     install: true,
     include_directories: liblxc_includes,
-    dependencies: [threads],
+    dependencies: [threads] + liblxc_dependency_headers,
     c_args: '-fvisibility=default')
 
 lxc_functions = configure_file(