From d8def5dc8745c3d77cf49ad5abbb6719ffd94035 Mon Sep 17 00:00:00 2001 From: Daan De Meyer Date: Sun, 11 May 2025 09:42:28 +0200 Subject: [PATCH 1/4] meson: Stop doing nested build when fuzzers are enabled Currently, when fuzzers are enabled, we run meson from within meson to build the fuzzer executables with sanitizers. The idea is that we can build the fuzzers with different kinds of sanitizers independently from the main build. The issue with this setup is that we don't actually make use of it. We only build the fuzzers with one set of sanitizers (address,undefined) so we're adding a bunch of extra complexity without any benefit as we can just setup the top level meson build with these sanitizers and get the same result. The other issue with this setup is that we don't pass on all the options passed to the top level meson build to the nested meson build. The only things we pass on are extra compiler arguments and the value of the auto_features option, but none of the individual feature options if overridden are passed on, which can lead to very hard to debug issues as an option enabled in the top level build is not enabled in the nested build. Since we're not getting anything useful out of this setup, let's simplify and get rid of the nested meson build. Instead, sanitizers should be enabled for the top level meson.build. This currently didn't work as we were overriding the sanitizers passed to the meson build with the fuzzer sanitizer, so we fix that as well by making sure we combine the fuzzer sanitizer with the ones passed in by the user. We also drop support for looking up libFuzzer as a separate library as it has been shipped builtin in clang since clang 6.0, so we can assume that -fsanitize=fuzzer is available. To make sure we still run the fuzzing tests, we enable the fuzz-tests option by default now to make sure they still always run (without instrumentation unless one of llvm-fuzz or oss-fuzz is enabled). --- meson.build | 65 +++++--------------------------- meson_options.txt | 4 +- test/fuzz/meson.build | 33 ---------------- test/integration-tests/README.md | 3 +- 4 files changed, 12 insertions(+), 93 deletions(-) diff --git a/meson.build b/meson.build index b3cf5f1744..e64e289d58 100644 --- a/meson.build +++ b/meson.build @@ -356,13 +356,10 @@ else endif if want_libfuzzer - fuzzing_engine = meson.get_compiler('cpp').find_library('Fuzzer', required : false) - if fuzzing_engine.found() - userspace_c_args += '-fsanitize-coverage=trace-pc-guard,trace-cmp' - elif cc.has_argument('-fsanitize=fuzzer-no-link') + if cc.has_argument('-fsanitize=fuzzer-no-link') userspace_c_args += '-fsanitize=fuzzer-no-link' else - error('Looks like neither libFuzzer nor -fsanitize=fuzzer-no-link is supported') + error('Looks like -fsanitize=fuzzer-no-link is not supported') endif elif want_ossfuzz fuzzing_engine = meson.get_compiler('cpp').find_library('FuzzingEngine') @@ -2207,11 +2204,11 @@ fuzz_template = executable_template + { 'install' : false, } -if want_ossfuzz or (want_libfuzzer and fuzzing_engine.found()) +if want_ossfuzz fuzz_additional_kwargs = { 'dependencies' : fuzzing_engine, } -elif want_libfuzzer and not fuzzing_engine.found() +elif want_libfuzzer fuzz_additional_kwargs = { 'link_args' : ['-fsanitize=fuzzer'], } @@ -2499,9 +2496,7 @@ foreach dict : executables if is_fuzz fuzzer_exes += exe - if want_tests != 'false' - # Run the fuzz regression tests without any sanitizers enabled. - # Additional invocations with sanitizers may get added below. + if want_tests != 'false' and want_fuzz_tests fuzz_ins = fuzz_regression_tests.get(name, {}) foreach directive : fuzz_ins.get('directives', []) tt = '@0@_@1@'.format(name, fs.name(directive.full_path())) @@ -2513,6 +2508,8 @@ foreach dict : executables exe, suite : 'fuzz', args : directive.full_path(), + env : ['UBSAN_OPTIONS=print_stacktrace=1:print_summary=1:halt_on_error=1'], + timeout : 60, depends : directive) endforeach foreach file : fuzz_ins.get('files', []) @@ -2524,6 +2521,8 @@ foreach dict : executables test(tt, exe, suite : 'fuzz', + env : ['UBSAN_OPTIONS=print_stacktrace=1:print_summary=1:halt_on_error=1'], + timeout : 60, args : file) endforeach endif @@ -2760,52 +2759,6 @@ foreach exec : public_programs endif endforeach -# Enable tests for all supported sanitizers -foreach tuple : fuzz_sanitizers - sanitizer = tuple[0] - build = tuple[1] - - if cc.has_link_argument('-fsanitize=@0@'.format(sanitizer)) - foreach fuzzer, fuzz_ins : fuzz_regression_tests - name = '@0@:@1@'.format(fuzzer, sanitizer) - if want_tests == 'false' - message('Not compiling @0@ because tests is set to false'.format(name)) - continue - endif - if not want_fuzz_tests - message('Not compiling @0@ because fuzz-tests is set to false'.format(name)) - continue - endif - exe = custom_target( - name, - output : name, - depends : build, - command : [ln, '-fs', - build.full_path() / fuzzer, - '@OUTPUT@'], - build_by_default : true) - - foreach directive : fuzz_ins.get('directives', []) - test('@0@_@1@_@2@'.format(fuzzer, fs.name(directive.full_path()), sanitizer), - env, - suite : 'fuzz+san', - env : ['UBSAN_OPTIONS=print_stacktrace=1:print_summary=1:halt_on_error=1'], - timeout : 60, - args : [exe.full_path(), directive.full_path()], - depends : directive) - endforeach - foreach file : fuzz_ins.get('files', []) - test('@0@_@1@_@2@'.format(fuzzer, fs.name(file), sanitizer), - env, - suite : 'fuzz+san', - env : ['UBSAN_OPTIONS=print_stacktrace=1:print_summary=1:halt_on_error=1'], - timeout : 60, - args : [exe.full_path(), file]) - endforeach - endforeach - endif -endforeach - ##################################################################### if git.found() diff --git a/meson_options.txt b/meson_options.txt index 72bf6a5f83..7ef03f4679 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -503,8 +503,8 @@ option('tests', type : 'combo', choices : ['true', 'unsafe', 'false'], description : 'enable extra tests with =unsafe') option('slow-tests', type : 'boolean', value : false, description : 'run the slow tests by default') -option('fuzz-tests', type : 'boolean', value : false, - description : 'run the fuzzer regression tests by default (with sanitizers)') +option('fuzz-tests', type : 'boolean', value : true, + description : 'run the fuzzer regression tests') option('install-tests', type : 'boolean', value : false, description : 'install test executables') option('log-message-verification', type : 'feature', deprecated : { 'true' : 'enabled', 'false' : 'disabled' }, diff --git a/test/fuzz/meson.build b/test/fuzz/meson.build index db1dcb291c..54115909a2 100644 --- a/test/fuzz/meson.build +++ b/test/fuzz/meson.build @@ -36,39 +36,6 @@ fuzz_regression_tests += { 'fuzz-unit-file' : dict } ############################################################ -if meson.version().version_compare('>=1.3.0') - sanitize_auto_features = '@0@'.format(get_option('auto_features')) -else - if get_option('auto_features').enabled() - sanitize_auto_features = 'enabled' - elif get_option('auto_features').disabled() - sanitize_auto_features = 'disabled' - else - sanitize_auto_features = 'auto' - endif -endif - -fuzz_c_args = get_option('c_args') -fuzz_cpp_args = cxx_cmd != '' ? get_option('cpp_args') : [] - -sanitize_address_undefined = custom_target( - 'sanitize-address-undefined-fuzzers', - output : 'sanitize-address-undefined-fuzzers', - command : [meson_build_sh, - meson.project_source_root(), - '@OUTPUT@', - 'fuzzers', - ' '.join(fuzz_c_args + '-DFUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION'), - ' '.join(fuzz_cpp_args + '-DFUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION'), - '-Dfuzz-tests=true -Db_lundef=false -Db_sanitize=address,undefined --optimization=@0@ @1@ --auto-features=@2@'.format( - get_option('optimization'), - get_option('werror') ? '--werror' : '', - sanitize_auto_features - ), - ' '.join(cc.cmd_array()), - cxx_cmd]) - -fuzz_sanitizers = [['address,undefined', sanitize_address_undefined]] fuzz_testsdir = 'test/fuzz' if git.found() and fs.is_dir(meson.project_source_root() / '.git') diff --git a/test/integration-tests/README.md b/test/integration-tests/README.md index ef9dbdc1c9..66f1a314be 100644 --- a/test/integration-tests/README.md +++ b/test/integration-tests/README.md @@ -497,8 +497,7 @@ fuzz targets. The dictionary should be named `src/fuzz/fuzz-foo.dict` and the seed corpus should be built and exported as `$OUT/fuzz-foo_seed_corpus.zip` in `tools/oss-fuzz.sh`. -The fuzzers can be built locally if you have libFuzzer installed by running -`tools/oss-fuzz.sh`, or by running: +The fuzzers can be built locally by running `tools/oss-fuzz.sh`, or by running: ```sh CC=clang CXX=clang++ \ From 6350d2dbd97746440b9c8303ddc140ffda568732 Mon Sep 17 00:00:00 2001 From: Daan De Meyer Date: Wed, 7 May 2025 22:55:15 +0200 Subject: [PATCH 2/4] meson: Extract objects instead of creating intermediate static libraries Currently, when we want to add unit tests for code that is compiled into an executable, we either compile the code at least twice (once for the executable, and once for each test that uses it) or we create a static library which is then used by both the executable and all the tests. Both of these options are not ideal, compiling source files more than once slows down the build for no reason and creating the intermediate static libraries takes a lot of boilerplate. Instead, let's use the extract_objects() method that meson exposes on build targets. This allows us to extract the objects corresponding to specific source files and use them in other executables. Because we define all executables upfront into a dictionary, we integrate this into the dictionary approach by adding two new fields: - 'extract' takes a list of files for which objects should be extracted. The extracted objects are stored in a dict keyed by the executable name from which they were extracted. - 'objects' takes the name of an executable from which the extracted objects should be added to the current executable. One side effect of this approach is that we can't build test executables anymore without building the main executable, so we stop building test executables unless we're also building the main executable. This allows us to switch to using subdir_done() in all of these subdirectories to skip parsing them if the corresponding component is disabled. These changes get me down from 2439 => 2403 ninja targets on a full rebuild from scratch. --- meson.build | 24 ++++++- rules.d/meson.build | 8 +-- src/analyze/meson.build | 13 ++-- src/busctl/meson.build | 13 ++-- src/coredump/meson.build | 19 +++--- src/home/meson.build | 78 +++++++++++----------- src/import/meson.build | 58 +++++------------ src/journal-remote/meson.build | 76 ++++++++-------------- src/journal/meson.build | 86 ++++++++----------------- src/locale/meson.build | 40 ++++++------ src/login/meson.build | 80 ++++++++--------------- src/machine/meson.build | 45 +++++-------- src/network/meson.build | 45 ++++++------- src/nspawn/meson.build | 47 +++++++------- src/nsresourced/meson.build | 45 +++++++------ src/oom/meson.build | 33 +++++----- src/resolve/meson.build | 82 ++++++++++------------- src/shutdown/meson.build | 16 ++--- src/sleep/meson.build | 20 +++--- src/timesync/meson.build | 59 +++++++---------- src/tmpfiles/meson.build | 19 +++--- src/udev/meson.build | 55 +++++++--------- src/vmspawn/meson.build | 30 +++------ src/xdg-autostart-generator/meson.build | 26 ++++---- tools/oss-fuzz.sh | 2 +- 25 files changed, 442 insertions(+), 577 deletions(-) diff --git a/meson.build b/meson.build index e64e289d58..a10a103871 100644 --- a/meson.build +++ b/meson.build @@ -2004,6 +2004,7 @@ catalogs = [] modules = [] # nss, pam, and other plugins executables = [] executables_by_name = {} +objects_by_name = {} fuzzer_exes = [] generated_sources = [version_h, vmlinux_h_dependency] @@ -2430,7 +2431,8 @@ foreach dict : executables kwargs = {} foreach key, val : dict if key in ['name', 'dbus', 'public', 'conditions', - 'type', 'suite', 'timeout', 'parallel'] + 'type', 'suite', 'timeout', 'parallel', + 'objects', 'extract'] continue endif @@ -2441,6 +2443,17 @@ foreach dict : executables kwargs += { key : [ kwargs.get(key, []), val ]} endforeach + foreach val : dict.get('objects', []) + obj = objects_by_name[val] + kwargs += { + 'objects' : obj['objects'], + 'include_directories' : [ + kwargs.get('include_directories', []), + obj['include_directories'], + ], + } + endforeach + if is_test kwargs += { 'install_dir' : kwargs.get('install_dir') / dict.get('type', '') } foreach key, val : test_additional_kwargs @@ -2461,6 +2474,15 @@ foreach dict : executables executables_by_name += { name : exe } + if dict.has_key('extract') + objects_by_name += { + name : { + 'objects' : exe.extract_objects(dict['extract']), + 'include_directories' : fs.parent(dict['extract'][0]), + } + } + endif + if dict.get('build_by_default', true) if dict.get('dbus', false) dbus_programs += exe diff --git a/rules.d/meson.build b/rules.d/meson.build index 997cab8699..0f808b0fd1 100644 --- a/rules.d/meson.build +++ b/rules.d/meson.build @@ -43,7 +43,7 @@ rules = [ conf.get('HAVE_DMI') == 1], [files('70-power-switch.rules'), - enable_logind], + conf.get('ENABLE_LOGIND') == 1] ] all_rules = [] @@ -65,9 +65,9 @@ rules_in = [ ['64-btrfs.rules'], ['99-systemd.rules'], - ['70-uaccess.rules', enable_logind and conf.get('HAVE_ACL') == 1], - ['71-seat.rules', enable_logind], - ['73-seat-late.rules', enable_logind], + ['70-uaccess.rules', conf.get('ENABLE_LOGIND') == 1 and conf.get('HAVE_ACL') == 1], + ['71-seat.rules', conf.get('ENABLE_LOGIND') == 1], + ['73-seat-late.rules', conf.get('ENABLE_LOGIND') == 1], ['90-vconsole.rules', conf.get('ENABLE_VCONSOLE') == 1], ] diff --git a/src/analyze/meson.build b/src/analyze/meson.build index 5a7c6c9285..b84d064d33 100644 --- a/src/analyze/meson.build +++ b/src/analyze/meson.build @@ -34,15 +34,18 @@ systemd_analyze_sources = files( 'analyze-unit-files.c', 'analyze-unit-paths.c', 'analyze-verify.c', - 'analyze-verify-util.c', 'analyze.c', ) +systemd_analyze_extract_sources = files( + 'analyze-verify-util.c' +) executables += [ executable_template + { 'name' : 'systemd-analyze', 'public' : conf.get('ENABLE_ANALYZE') == 1, - 'sources' : systemd_analyze_sources, + 'sources' : [systemd_analyze_sources, systemd_analyze_extract_sources], + 'extract' : systemd_analyze_extract_sources, 'include_directories' : core_includes, 'link_with' : [ libcore, @@ -52,9 +55,7 @@ executables += [ 'install' : conf.get('ENABLE_ANALYZE') == 1, }, core_test_template + { - 'sources' : files( - 'test-verify.c', - 'analyze-verify-util.c', - ), + 'sources' : files('test-verify.c'), + 'objects' : ['systemd-analyze'], }, ] diff --git a/src/busctl/meson.build b/src/busctl/meson.build index 6b3a479b21..8c8e110360 100644 --- a/src/busctl/meson.build +++ b/src/busctl/meson.build @@ -1,20 +1,21 @@ # SPDX-License-Identifier: LGPL-2.1-or-later busctl_sources = files( - 'busctl-introspect.c', 'busctl.c', ) +busctl_extract_sources = files( + 'busctl-introspect.c', +) executables += [ executable_template + { 'name' : 'busctl', 'public' : true, - 'sources' : busctl_sources, + 'sources' : [busctl_sources, busctl_extract_sources], + 'extract' : busctl_extract_sources, }, test_template + { - 'sources' : files( - 'test-busctl-introspect.c', - 'busctl-introspect.c', - ) + 'sources' : files('test-busctl-introspect.c'), + 'objects' : ['busctl'], }, ] diff --git a/src/coredump/meson.build b/src/coredump/meson.build index bb81149b60..e1667e19a9 100644 --- a/src/coredump/meson.build +++ b/src/coredump/meson.build @@ -1,7 +1,13 @@ # SPDX-License-Identifier: LGPL-2.1-or-later +if conf.get('ENABLE_COREDUMP') != 1 + subdir_done() +endif + systemd_coredump_sources = files( 'coredump.c', +) +systemd_coredump_extract_sources = files( 'coredump-vacuum.c', ) @@ -15,29 +21,26 @@ common_dependencies = [ executables += [ libexec_template + { 'name' : 'systemd-coredump', - 'conditions' : ['ENABLE_COREDUMP'], - 'sources' : systemd_coredump_sources, + 'sources' : [systemd_coredump_sources, systemd_coredump_extract_sources], + 'extract' : systemd_coredump_extract_sources, 'link_with' : [libshared], 'dependencies' : common_dependencies + [libacl], }, executable_template + { 'name' : 'coredumpctl', 'public' : true, - 'conditions' : ['ENABLE_COREDUMP'], 'sources' : files('coredumpctl.c'), 'link_with' : [libshared], 'dependencies' : common_dependencies, }, test_template + { - 'sources' : files( - 'test-coredump-vacuum.c', - 'coredump-vacuum.c', - ), + 'sources' : files('test-coredump-vacuum.c'), + 'objects' : ['systemd-coredump'], 'type' : 'manual', }, ] -if conf.get('ENABLE_COREDUMP') == 1 and install_sysconfdir_samples +if install_sysconfdir_samples install_data('coredump.conf', install_dir : pkgconfigfiledir) endif diff --git a/src/home/meson.build b/src/home/meson.build index 7e267dadd3..acbefef054 100644 --- a/src/home/meson.build +++ b/src/home/meson.build @@ -4,29 +4,7 @@ if conf.get('ENABLE_HOMED') != 1 subdir_done() endif -systemd_homework_sources = files( - 'home-util.c', - 'homework-blob.c', - 'homework-cifs.c', - 'homework-directory.c', - 'homework-fscrypt.c', - 'homework-luks.c', - 'homework-mount.c', - 'homework-password-cache.c', - 'homework-quota.c', - 'homework.c', - 'user-record-util.c', -) - -if conf.get('HAVE_P11KIT') == 1 - systemd_homework_sources += files('homework-pkcs11.c') -endif -if conf.get('HAVE_LIBFIDO2') == 1 - systemd_homework_sources += files('homework-fido2.c') -endif - systemd_homed_sources = files( - 'home-util.c', 'homed-bus.c', 'homed-conf.c', 'homed-home-bus.c', @@ -36,11 +14,33 @@ systemd_homed_sources = files( 'homed-operation.c', 'homed-varlink.c', 'homed.c', - 'user-record-password-quality.c', 'user-record-sign.c', +) +systemd_homed_extract_sources = files( + 'home-util.c', + 'user-record-password-quality.c', 'user-record-util.c', ) +systemd_homework_sources = files( + 'homework-blob.c', + 'homework-cifs.c', + 'homework-directory.c', + 'homework-fscrypt.c', + 'homework-luks.c', + 'homework-mount.c', + 'homework-password-cache.c', + 'homework-quota.c', + 'homework.c', +) + +if conf.get('HAVE_P11KIT') == 1 + systemd_homework_sources += files('homework-pkcs11.c') +endif +if conf.get('HAVE_LIBFIDO2') == 1 + systemd_homework_sources += files('homework-fido2.c') +endif + homed_gperf_c = custom_target( 'homed_gperf.c', input : 'homed-gperf.gperf', @@ -51,13 +51,10 @@ generated_sources += [homed_gperf_c] systemd_homed_sources += [homed_gperf_c] homectl_sources = files( - 'home-util.c', 'homectl-fido2.c', 'homectl-pkcs11.c', 'homectl-recovery-key.c', 'homectl.c', - 'user-record-password-quality.c', - 'user-record-util.c', ) pam_systemd_home_sources = files( @@ -67,9 +64,24 @@ pam_systemd_home_sources = files( ) executables += [ + libexec_template + { + 'name' : 'systemd-homed', + 'dbus' : true, + 'sources' : [systemd_homed_sources, systemd_homed_extract_sources], + 'include_directories' : includes + + include_directories('.'), + 'extract' : systemd_homed_extract_sources, + 'dependencies' : [ + libcrypt, + libm, + libopenssl, + threads, + ], + }, libexec_template + { 'name' : 'systemd-homework', 'sources' : systemd_homework_sources, + 'objects' : ['systemd-homed'], 'link_with' : [ libshared, libshared_fdisk @@ -83,23 +95,11 @@ executables += [ threads, ], }, - libexec_template + { - 'name' : 'systemd-homed', - 'dbus' : true, - 'sources' : systemd_homed_sources, - 'include_directories' : includes + - include_directories('.'), - 'dependencies' : [ - libcrypt, - libm, - libopenssl, - threads, - ], - }, executable_template + { 'name' : 'homectl', 'public' : true, 'sources' : homectl_sources, + 'objects' : ['systemd-homed'], 'dependencies' : [ libcrypt, libdl, diff --git a/src/import/meson.build b/src/import/meson.build index 3cee46e58c..65e1ff2e12 100644 --- a/src/import/meson.build +++ b/src/import/meson.build @@ -7,6 +7,11 @@ endif systemd_importd_sources = files( 'importd.c', ) +systemd_importd_extract_sources = files( + 'import-common.c', + 'import-compress.c', + 'qcow2-util.c', +) systemd_pull_sources = files( 'pull.c', @@ -33,30 +38,6 @@ systemd_export_sources = files( 'export-raw.c', ) -importd_common_sources = files( - 'import-common.c', - 'import-compress.c', - 'qcow2-util.c', -) - -lib_import_common = static_library( - 'import-common', - sources : importd_common_sources, - include_directories : includes, - dependencies : [ - libbzip2, - libxz, - libz, - libzstd, - userspace, - ], - build_by_default : false) - -common_libs = [ - lib_import_common, - libshared, -] - common_deps = [ libbzip2, libcurl, @@ -69,16 +50,15 @@ executables += [ libexec_template + { 'name' : 'systemd-importd', 'dbus' : true, - 'conditions' : ['ENABLE_IMPORTD'], - 'sources' : systemd_importd_sources, - 'dependencies' : threads, + 'sources' : [systemd_importd_sources, systemd_importd_extract_sources], + 'extract' : systemd_importd_extract_sources, + 'dependencies' : [common_deps, threads], }, libexec_template + { 'name' : 'systemd-pull', 'public' : true, - 'conditions' : ['ENABLE_IMPORTD'], 'sources' : systemd_pull_sources, - 'link_with' : common_libs, + 'objects' : ['systemd-importd'], 'dependencies' : common_deps + [ libopenssl, ], @@ -86,43 +66,37 @@ executables += [ libexec_template + { 'name' : 'systemd-import', 'public' : true, - 'conditions' : ['ENABLE_IMPORTD'], 'sources' : systemd_import_sources, - 'link_with' : common_libs, + 'objects' : ['systemd-importd'], 'dependencies' : common_deps, }, libexec_template + { 'name' : 'systemd-import-fs', 'public' : true, - 'conditions' : ['ENABLE_IMPORTD'], 'sources' : systemd_import_fs_sources, - 'link_with' : common_libs, + 'objects' : ['systemd-importd'], + 'dependencies' : common_deps, }, libexec_template + { 'name' : 'systemd-export', 'public' : true, - 'conditions' : ['ENABLE_IMPORTD'], 'sources' : systemd_export_sources, - 'link_with' : common_libs, + 'objects' : ['systemd-importd'], 'dependencies' : common_deps, }, executable_template + { 'name' : 'importctl', 'public' : true, - 'conditions' : ['ENABLE_IMPORTD'], 'sources' : files('importctl.c'), }, generator_template + { 'name' : 'systemd-import-generator', 'sources' : files('import-generator.c'), - 'conditions' : ['ENABLE_IMPORTD'], }, test_template + { - 'sources' : files( - 'test-qcow2.c', - 'qcow2-util.c', - ), - 'dependencies' : libz, + 'sources' : files('test-qcow2.c'), + 'objects' : ['systemd-importd'], + 'dependencies' : common_deps, 'conditions' : ['HAVE_ZLIB'], 'type' : 'manual', }, diff --git a/src/journal-remote/meson.build b/src/journal-remote/meson.build index 12d7633364..7ccf060dce 100644 --- a/src/journal-remote/meson.build +++ b/src/journal-remote/meson.build @@ -1,13 +1,20 @@ # SPDX-License-Identifier: LGPL-2.1-or-later +if conf.get('ENABLE_REMOTE') != 1 + subdir_done() +endif + systemd_journal_upload_sources = files( 'journal-compression-util.c', - 'journal-header-util.c', 'journal-upload-journal.c', 'journal-upload.c', ) +systemd_journal_upload_extract_sources = files( + 'journal-header-util.c', +) -libsystemd_journal_remote_sources = files( +systemd_journal_remote_sources = files('journal-remote-main.c') +systemd_journal_remote_extract_sources = files( 'journal-compression-util.c', 'journal-remote-parse.c', 'journal-remote-write.c', @@ -15,25 +22,11 @@ libsystemd_journal_remote_sources = files( ) if conf.get('HAVE_MICROHTTPD') == 1 - libsystemd_journal_remote_sources += files( + systemd_journal_remote_extract_sources += files( 'microhttpd-util.c', ) endif -libsystemd_journal_remote = static_library( - 'systemd-journal-remote', - libsystemd_journal_remote_sources, - include_directories : includes, - dependencies : [libgnutls, - liblz4_cflags, - libmicrohttpd, - libxz_cflags, - threads, - userspace], - build_by_default : false) - -systemd_journal_remote_sources = files('journal-remote-main.c') - systemd_journal_gatewayd_sources = files( 'journal-gatewayd.c', 'microhttpd-util.c', @@ -51,57 +44,40 @@ executables += [ libexec_template + { 'name' : 'systemd-journal-upload', 'public' : true, - 'conditions' : [ - 'ENABLE_REMOTE', - 'HAVE_LIBCURL', - ], - 'sources' : systemd_journal_upload_sources, + 'conditions' : ['HAVE_LIBCURL'], + 'sources' : [systemd_journal_upload_sources, systemd_journal_upload_extract_sources], + 'extract' : systemd_journal_upload_extract_sources, 'dependencies' : common_deps + [libcurl], }, libexec_template + { 'name' : 'systemd-journal-remote', 'public' : true, - 'conditions' : [ - 'ENABLE_REMOTE', - 'HAVE_MICROHTTPD', - ], - 'sources' : systemd_journal_remote_sources, - 'link_with' : [ - libshared, - libsystemd_journal_remote, - ], + 'conditions' : ['HAVE_MICROHTTPD'], + 'sources' : [systemd_journal_remote_sources, systemd_journal_remote_extract_sources], + 'extract' : systemd_journal_remote_extract_sources, 'dependencies' : common_deps + [libmicrohttpd], }, libexec_template + { 'name' : 'systemd-journal-gatewayd', 'public' : true, - 'conditions' : [ - 'ENABLE_REMOTE', - 'HAVE_MICROHTTPD', - ], + 'conditions' : ['HAVE_MICROHTTPD'], 'sources' : systemd_journal_gatewayd_sources, 'dependencies' : common_deps + [libmicrohttpd], }, + test_template + { + 'sources' : files('test-journal-header-util.c'), + 'objects' : ['systemd-journal-upload'], + }, fuzz_template + { 'sources' : files('fuzz-journal-remote.c'), - 'link_with' : [ - libshared, - libsystemd_journal_remote, - ], - }, -] - -executables += [ - test_template + { - 'sources' : files('test-journal-header-util.c', 'journal-header-util.c'), + 'objects' : ['systemd-journal-remote'], + 'dependencies' : common_deps + [libmicrohttpd], }, ] in_files = [ - ['journal-upload.conf', - conf.get('ENABLE_REMOTE') == 1 and conf.get('HAVE_LIBCURL') == 1 and install_sysconfdir_samples], - ['journal-remote.conf', - conf.get('ENABLE_REMOTE') == 1 and conf.get('HAVE_MICROHTTPD') == 1 and install_sysconfdir_samples]] + ['journal-upload.conf', conf.get('HAVE_LIBCURL') == 1 and install_sysconfdir_samples], + ['journal-remote.conf', conf.get('HAVE_MICROHTTPD') == 1 and install_sysconfdir_samples]] foreach tuple : in_files file = tuple[0] @@ -114,7 +90,7 @@ foreach tuple : in_files install_dir : pkgconfigfiledir) endforeach -if conf.get('ENABLE_REMOTE') == 1 and conf.get('HAVE_MICROHTTPD') == 1 +if conf.get('HAVE_MICROHTTPD') == 1 install_data('browse.html', install_dir : pkgdatadir / 'gatewayd') diff --git a/src/journal/meson.build b/src/journal/meson.build index c672cbe327..a7fcd9a41f 100644 --- a/src/journal/meson.build +++ b/src/journal/meson.build @@ -1,6 +1,9 @@ # SPDX-License-Identifier: LGPL-2.1-or-later -sources = files( +systemd_journald_sources = files( + 'journald.c', +) +systemd_journald_extract_sources = files( 'journald-audit.c', 'journald-client.c', 'journald-console.c', @@ -14,6 +17,9 @@ sources = files( 'journald-syslog.c', 'journald-varlink.c', 'journald-wall.c', + # Build fuzz-journald.c as part of systemd-journald so we only compile it once instead of once per + # fuzz test. + 'fuzz-journald.c', ) journald_gperf_c = custom_target( @@ -23,15 +29,7 @@ journald_gperf_c = custom_target( command : [gperf, '@INPUT@', '--output-file', '@OUTPUT@']) generated_sources += journald_gperf_c -sources += journald_gperf_c - -libjournal_core = static_library( - 'journal-core', - sources, - include_directories : includes, - dependencies: [threads, - userspace], - build_by_default : false) +systemd_journald_extract_sources += journald_gperf_c journalctl_sources = files( 'journalctl.c', @@ -54,28 +52,20 @@ else endif journal_test_template = test_template + { - 'link_with' : [ - libjournal_core, - libshared, - ], + 'objects' : ['systemd-journald'], } journal_fuzz_template = fuzz_template + { - 'link_with' : [ - libjournal_core, - libshared, - ], + 'objects' : ['systemd-journald'], 'dependencies' : libselinux, } executables += [ libexec_template + { 'name' : 'systemd-journald', - 'sources' : files('journald.c'), - 'link_with' : [ - libjournal_core, - libshared, - ], + 'sources' : [systemd_journald_sources, systemd_journald_extract_sources], + 'include_directories' : [libexec_template['include_directories'], include_directories('.')], + 'extract' : systemd_journald_extract_sources, 'dependencies' : [ liblz4_cflags, libselinux, @@ -89,18 +79,14 @@ executables += [ 'public' : true, 'conditions' : ['HAVE_QRENCODE'], 'sources' : files('bsod.c'), - 'link_with' : libshared, 'dependencies' : libqrencode, }, executable_template + { 'name' : 'systemd-cat', 'public' : true, 'sources' : files('cat.c'), - 'link_with' : [ - libjournal_core, - libshared, - ], - 'dependencies' : threads, + 'objects' : ['systemd-journald'], + 'dependencies' : [libselinux, threads], }, executable_template + { 'name' : 'journalctl', @@ -123,11 +109,13 @@ executables += [ libxz_cflags, ], }, - test_template + { - 'sources' : files( - 'test-journald-rate-limit.c', - 'journald-rate-limit.c', - ), + journal_test_template + { + 'sources' : files('test-journald-rate-limit.c'), + 'dependencies' : [ + liblz4_cflags, + libselinux, + libxz_cflags, + ], }, journal_test_template + { 'sources' : files('test-journald-syslog.c'), @@ -145,40 +133,22 @@ executables += [ ], }, journal_fuzz_template + { - 'sources' : files( - 'fuzz-journald-audit.c', - 'fuzz-journald.c', - ), + 'sources' : files('fuzz-journald-audit.c'), }, journal_fuzz_template + { - 'sources' : files( - 'fuzz-journald-kmsg.c', - 'fuzz-journald.c', - ), + 'sources' : files('fuzz-journald-kmsg.c'), }, journal_fuzz_template + { - 'sources' : files( - 'fuzz-journald-native.c', - 'fuzz-journald.c', - ), + 'sources' : files('fuzz-journald-native.c'), }, journal_fuzz_template + { - 'sources' : files( - 'fuzz-journald-native-fd.c', - 'fuzz-journald.c', - ), + 'sources' : files('fuzz-journald-native-fd.c'), }, journal_fuzz_template + { - 'sources' : files( - 'fuzz-journald-stream.c', - 'fuzz-journald.c', - ), + 'sources' : files('fuzz-journald-stream.c'), }, journal_fuzz_template + { - 'sources' : files( - 'fuzz-journald-syslog.c', - 'fuzz-journald.c', - ), + 'sources' : files('fuzz-journald-syslog.c'), }, ] diff --git a/src/locale/meson.build b/src/locale/meson.build index 3d3aa589c3..e9c61f49b3 100644 --- a/src/locale/meson.build +++ b/src/locale/meson.build @@ -1,8 +1,14 @@ # SPDX-License-Identifier: LGPL-2.1-or-later +if conf.get('ENABLE_LOCALED') != 1 + subdir_done() +endif + systemd_localed_sources = files( + 'localed.c' +) +systemd_localed_extract_sources = files( 'localed-util.c', - 'localed.c', 'xkbcommon-util.c', ) @@ -23,22 +29,18 @@ executables += [ libexec_template + { 'name' : 'systemd-localed', 'dbus' : true, - 'conditions' : ['ENABLE_LOCALED'], - 'sources' : systemd_localed_sources, + 'sources' : [systemd_localed_sources, systemd_localed_extract_sources], + 'extract' : systemd_localed_extract_sources, 'dependencies' : libxkbcommon_deps, }, executable_template + { 'name' : 'localectl', 'public' : true, - 'conditions' : ['ENABLE_LOCALED'], 'sources' : files('localectl.c'), }, test_template + { - 'sources' : files( - 'test-localed-util.c', - 'localed-util.c', - 'xkbcommon-util.c', - ), + 'sources' : files('test-localed-util.c'), + 'objects' : ['systemd-localed'], 'dependencies' : libxkbcommon_deps, }, ] @@ -49,14 +51,12 @@ executables += [ kbd_model_map = meson.current_source_dir() / 'kbd-model-map' language_fallback_map = meson.current_source_dir() / 'language-fallback-map' -if conf.get('ENABLE_LOCALED') == 1 - install_data('org.freedesktop.locale1.conf', - install_dir : dbuspolicydir) - install_data('org.freedesktop.locale1.service', - install_dir : dbussystemservicedir) - install_data('org.freedesktop.locale1.policy', - install_dir : polkitpolicydir) - install_data('kbd-model-map', - 'language-fallback-map', - install_dir : pkgdatadir) -endif +install_data('org.freedesktop.locale1.conf', + install_dir : dbuspolicydir) +install_data('org.freedesktop.locale1.service', + install_dir : dbussystemservicedir) +install_data('org.freedesktop.locale1.policy', + install_dir : polkitpolicydir) +install_data('kbd-model-map', + 'language-fallback-map', + install_dir : pkgdatadir) diff --git a/src/login/meson.build b/src/login/meson.build index 6b617ca448..99096c4c29 100644 --- a/src/login/meson.build +++ b/src/login/meson.build @@ -1,18 +1,13 @@ # SPDX-License-Identifier: LGPL-2.1-or-later +if conf.get('ENABLE_LOGIND') != 1 + subdir_done() +endif + systemd_logind_sources = files( 'logind.c', ) - -logind_gperf_c = custom_target( - 'logind_gperf.c', - input : 'logind-gperf.gperf', - output : 'logind-gperf.c', - command : [gperf, '@INPUT@', '--output-file', '@OUTPUT@']) - -generated_sources += logind_gperf_c - -liblogind_core_sources = files( +systemd_logind_extract_sources = files( 'logind-action.c', 'logind-brightness.c', 'logind-button.c', @@ -33,15 +28,14 @@ liblogind_core_sources = files( 'logind-wall.c', ) -liblogind_core_sources += [logind_gperf_c] +logind_gperf_c = custom_target( + 'logind_gperf.c', + input : 'logind-gperf.gperf', + output : 'logind-gperf.c', + command : [gperf, '@INPUT@', '--output-file', '@OUTPUT@']) -liblogind_core = static_library( - 'logind-core', - liblogind_core_sources, - include_directories : includes, - dependencies : [libacl, - userspace], - build_by_default : false) +generated_sources += logind_gperf_c +systemd_logind_extract_sources += [logind_gperf_c] loginctl_sources = files( 'loginctl.c', @@ -52,12 +46,9 @@ executables += [ libexec_template + { 'name' : 'systemd-logind', 'dbus' : true, - 'conditions' : ['ENABLE_LOGIND'], - 'sources' : systemd_logind_sources, - 'link_with' : [ - liblogind_core, - libshared, - ], + 'sources' : [systemd_logind_sources, systemd_logind_extract_sources], + 'include_directories' : [libexec_template['include_directories'], include_directories('.')], + 'extract' : systemd_logind_extract_sources, 'dependencies' : [ libacl, threads, @@ -66,7 +57,6 @@ executables += [ executable_template + { 'name' : 'loginctl', 'public' : true, - 'conditions' : ['ENABLE_LOGIND'], 'sources' : loginctl_sources, 'dependencies' : [ liblz4_cflags, @@ -78,12 +68,10 @@ executables += [ executable_template + { 'name' : 'systemd-inhibit', 'public' : true, - 'conditions' : ['ENABLE_LOGIND'], 'sources' : files('inhibit.c'), }, libexec_template + { 'name' : 'systemd-user-runtime-dir', - 'conditions' : ['ENABLE_LOGIND'], 'sources' : files('user-runtime-dir.c'), }, test_template + { @@ -92,10 +80,7 @@ executables += [ }, test_template + { 'sources' : files('test-login-tables.c'), - 'link_with' : [ - liblogind_core, - libshared, - ], + 'objects' : ['systemd-logind'], 'dependencies' : threads, }, test_template + { @@ -111,31 +96,24 @@ simple_tests += files( modules += [ pam_template + { 'name' : 'pam_systemd', - 'conditions' : [ - 'ENABLE_LOGIND', - 'HAVE_PAM', - ], + 'conditions' : ['HAVE_PAM'], 'sources' : files('pam_systemd.c'), 'version-script' : meson.current_source_dir() / 'pam_systemd.sym', }, pam_template + { 'name' : 'pam_systemd_loadkey', - 'conditions' : [ - 'HAVE_PAM', - ], + 'conditions' : ['HAVE_PAM'], 'sources' : files('pam_systemd_loadkey.c'), 'version-script' : meson.current_source_dir() / 'pam_systemd_loadkey.sym', }, ] -enable_logind = conf.get('ENABLE_LOGIND') == 1 - custom_target( 'logind.conf', input : 'logind.conf.in', output : 'logind.conf', command : [jinja2_cmdline, '@INPUT@', '@OUTPUT@'], - install : enable_logind and install_sysconfdir_samples and pkgsysconfdir != 'no', + install : install_sysconfdir_samples and pkgsysconfdir != 'no', install_dir : pkgconfigfiledir) custom_target( @@ -143,16 +121,14 @@ custom_target( input : 'systemd-user.in', output : 'systemd-user', command : [jinja2_cmdline, '@INPUT@', '@OUTPUT@'], - install : enable_logind and pamconfdir != 'no', + install : pamconfdir != 'no', install_dir : pamconfdir) -if enable_logind - install_data('org.freedesktop.login1.conf', - install_dir : dbuspolicydir) - install_data('org.freedesktop.login1.service', - install_dir : dbussystemservicedir) - install_data('org.freedesktop.login1.policy', - install_dir : polkitpolicydir) - install_data('10-systemd-logind-root-ignore-inhibitors.rules.example', - install_dir : polkitrulesdir) -endif +install_data('org.freedesktop.login1.conf', + install_dir : dbuspolicydir) +install_data('org.freedesktop.login1.service', + install_dir : dbussystemservicedir) +install_data('org.freedesktop.login1.policy', + install_dir : polkitpolicydir) +install_data('10-systemd-logind-root-ignore-inhibitors.rules.example', + install_dir : polkitrulesdir) diff --git a/src/machine/meson.build b/src/machine/meson.build index c596f71b5d..19ab1fa8f7 100644 --- a/src/machine/meson.build +++ b/src/machine/meson.build @@ -1,6 +1,13 @@ # SPDX-License-Identifier: LGPL-2.1-or-later -libmachine_core_sources = files( +if conf.get('ENABLE_MACHINED') != 1 + subdir_done() +endif + +systemd_machined_sources = files( + 'machined.c' +) +systemd_machined_extract_sources = files( 'image.c', 'image-dbus.c', 'image-varlink.c', @@ -13,29 +20,16 @@ libmachine_core_sources = files( 'operation.c', ) -libmachine_core = static_library( - 'machine-core', - libmachine_core_sources, - include_directories : includes, - dependencies : [threads, - userspace], - build_by_default : false) - executables += [ libexec_template + { 'name' : 'systemd-machined', 'dbus' : true, - 'conditions' : ['ENABLE_MACHINED'], - 'sources' : files('machined.c'), - 'link_with' : [ - libmachine_core, - libshared, - ], + 'sources' : [systemd_machined_sources, systemd_machined_extract_sources], + 'extract' : systemd_machined_extract_sources, }, executable_template + { 'name' : 'machinectl', 'public' : true, - 'conditions' : ['ENABLE_MACHINED'], 'sources' : files('machinectl.c'), 'dependencies' : [ liblz4_cflags, @@ -46,19 +40,14 @@ executables += [ }, test_template + { 'sources' : files('test-machine-tables.c'), - 'link_with': [ - libmachine_core, - libshared - ], + 'objects' : ['systemd-machined'], 'dependencies': threads, }, ] -if conf.get('ENABLE_MACHINED') == 1 - install_data('org.freedesktop.machine1.conf', - install_dir : dbuspolicydir) - install_data('org.freedesktop.machine1.service', - install_dir : dbussystemservicedir) - install_data('org.freedesktop.machine1.policy', - install_dir : polkitpolicydir) -endif +install_data('org.freedesktop.machine1.conf', + install_dir : dbuspolicydir) +install_data('org.freedesktop.machine1.service', + install_dir : dbussystemservicedir) +install_data('org.freedesktop.machine1.policy', + install_dir : polkitpolicydir) diff --git a/src/network/meson.build b/src/network/meson.build index 5d6fc9a806..990dac2283 100644 --- a/src/network/meson.build +++ b/src/network/meson.build @@ -2,7 +2,10 @@ subdir('bpf/sysctl_monitor') -sources = files( +systemd_networkd_sources = files( + 'networkd.c' +) +systemd_networkd_extract_sources = files( 'netdev/bareudp.c', 'netdev/batadv.c', 'netdev/bond.c', @@ -111,8 +114,6 @@ sources = files( 'tc/teql.c', ) -systemd_networkd_sources = files('networkd.c') - systemd_networkd_wait_online_sources = files( 'wait-online/dns-configuration.c', 'wait-online/link.c', @@ -136,16 +137,11 @@ networkctl_sources = files( 'networkctl-util.c', ) -network_generator_sources = files( - 'generator/main.c', - 'generator/network-generator.c', -) - networkd_network_gperf_gperf = files('networkd-network-gperf.gperf') networkd_netdev_gperf_gperf = files('netdev/netdev-gperf.gperf') if conf.get('HAVE_VMLINUX_H') == 1 - sources += sysctl_monitor_skel_h + systemd_networkd_extract_sources += sysctl_monitor_skel_h endif networkd_gperf_c = custom_target( @@ -167,7 +163,7 @@ netdev_gperf_c = custom_target( command : [gperf, '@INPUT@', '--output-file', '@OUTPUT@']) generated_sources += [networkd_gperf_c, networkd_network_gperf_c, netdev_gperf_c] -sources += [networkd_gperf_c, networkd_network_gperf_c, netdev_gperf_c] +systemd_networkd_extract_sources += [networkd_gperf_c, networkd_network_gperf_c, netdev_gperf_c] if get_option('link-networkd-shared') networkd_link_with = [libshared] @@ -178,27 +174,23 @@ endif network_includes = [libsystemd_network_includes, include_directories(['.', 'netdev', 'tc'])] -libnetworkd_core = static_library( - 'networkd-core', - sources, - include_directories : network_includes, - dependencies : userspace, - link_with : networkd_link_with, - build_by_default : false) - network_test_template = test_template + { + 'conditions' : ['ENABLE_NETWORKD'], 'link_with' : [ - libnetworkd_core, + networkd_link_with, libsystemd_network, ], + 'objects' : ['systemd-networkd'], 'include_directories' : network_includes, } network_fuzz_template = fuzz_template + { + 'conditions' : ['ENABLE_NETWORKD'], 'link_with' : [ - libnetworkd_core, + networkd_link_with, libsystemd_network, ], + 'objects' : ['systemd-networkd'], 'dependencies' : threads, 'include_directories' : network_includes, } @@ -208,10 +200,10 @@ executables += [ 'name' : 'systemd-networkd', 'dbus' : true, 'conditions' : ['ENABLE_NETWORKD'], - 'sources' : systemd_networkd_sources, + 'sources' : [systemd_networkd_sources, systemd_networkd_extract_sources], + 'extract' : systemd_networkd_extract_sources, 'include_directories' : network_includes, 'link_with' : [ - libnetworkd_core, libsystemd_network, networkd_link_with, ], @@ -237,14 +229,13 @@ executables += [ }, libexec_template + { 'name' : 'systemd-network-generator', - 'sources' : network_generator_sources, + 'sources' : files('generator/network-generator.c', 'generator/main.c'), + 'extract' : files('generator/network-generator.c'), 'link_with' : networkd_link_with, }, test_template + { - 'sources' : files( - 'generator/test-network-generator.c', - 'generator/network-generator.c', - ), + 'sources' : files('generator/test-network-generator.c'), + 'objects' : ['systemd-network-generator'], 'suite' : 'network', }, network_test_template + { diff --git a/src/nspawn/meson.build b/src/nspawn/meson.build index f7fa908806..b59017c15e 100644 --- a/src/nspawn/meson.build +++ b/src/nspawn/meson.build @@ -1,17 +1,25 @@ # SPDX-License-Identifier: LGPL-2.1-or-later -libnspawn_core_sources = files( +if conf.get('ENABLE_NSPAWN') != 1 + subdir_done() +endif + +nspawn_sources = files( + 'nspawn.c', 'nspawn-bind-user.c', 'nspawn-cgroup.c', + 'nspawn-network.c', + 'nspawn-register.c', + 'nspawn-seccomp.c', + 'nspawn-setuid.c', + 'nspawn-stub-pid1.c', +) +nspawn_extract_sources = files( 'nspawn-expose-ports.c', 'nspawn-mount.c', 'nspawn-network.c', 'nspawn-oci.c', - 'nspawn-register.c', - 'nspawn-seccomp.c', 'nspawn-settings.c', - 'nspawn-setuid.c', - 'nspawn-stub-pid1.c', ) nspawn_gperf_c = custom_target( @@ -21,26 +29,11 @@ nspawn_gperf_c = custom_target( command : [gperf, '@INPUT@', '--output-file', '@OUTPUT@']) generated_sources += nspawn_gperf_c -libnspawn_core_sources += nspawn_gperf_c - -libnspawn_core = static_library( - 'nspawn-core', - libnspawn_core_sources, - include_directories : includes, - dependencies : [libacl, - libseccomp, - libselinux, - userspace], - build_by_default : false) - -nspawn_libs = [ - libnspawn_core, - libshared, -] +nspawn_extract_sources += nspawn_gperf_c nspawn_common_template = { - 'link_with' : nspawn_libs, 'dependencies' : libseccomp, + 'objects' : ['systemd-nspawn'], } nspawn_test_template = test_template + nspawn_common_template nspawn_fuzz_template = fuzz_template + nspawn_common_template @@ -49,12 +42,16 @@ executables += [ executable_template + { 'name' : 'systemd-nspawn', 'public' : true, - 'conditions' : ['ENABLE_NSPAWN'], - 'sources' : files('nspawn.c'), - 'link_with' : nspawn_libs, + 'sources' : [nspawn_sources, nspawn_extract_sources], + 'include_directories' : [ + executable_template['include_directories'], + include_directories('.') + ], + 'extract' : nspawn_extract_sources, 'dependencies' : [ libblkid, libseccomp, + libselinux, ], }, nspawn_test_template + { diff --git a/src/nsresourced/meson.build b/src/nsresourced/meson.build index b80d6b2a34..85ebf6a021 100644 --- a/src/nsresourced/meson.build +++ b/src/nsresourced/meson.build @@ -6,46 +6,45 @@ endif subdir('bpf/userns_restrict') -systemd_nsresourcework_sources = files( - 'nsresourcework.c', - 'userns-restrict.c', - 'userns-registry.c', -) - systemd_nsresourced_sources = files( 'nsresourced-manager.c', 'nsresourced.c', +) +systemd_nsresourced_extract_sources = files( 'userns-restrict.c', 'userns-registry.c', ) - -userns_restrict_include = include_directories('.') +systemd_nsresourcework_sources = files( + 'nsresourcework.c' +) +test_userns_restrict_sources = files( + 'test-userns-restrict.c' +) if conf.get('HAVE_VMLINUX_H') == 1 - systemd_nsresourcework_sources += userns_restrict_skel_h systemd_nsresourced_sources += userns_restrict_skel_h - - executables += [ - test_template + { - 'sources' : files('test-userns-restrict.c', 'userns-restrict.c') + userns_restrict_skel_h, - 'conditions' : ['HAVE_VMLINUX_H'], - 'include_directories' : [ includes, userns_restrict_include ], - }, - ] + systemd_nsresourcework_sources += userns_restrict_skel_h + test_userns_restrict_sources += userns_restrict_skel_h endif executables += [ + libexec_template + { + 'name' : 'systemd-nsresourced', + 'sources' : [systemd_nsresourced_sources, systemd_nsresourced_extract_sources], + 'include_directories' : [libexec_template['include_directories'], include_directories('.')], + 'extract' : systemd_nsresourced_extract_sources, + 'dependencies' : threads, + }, libexec_template + { 'name' : 'systemd-nsresourcework', 'sources' : systemd_nsresourcework_sources, 'dependencies' : threads, - 'include_directories' : [ includes, userns_restrict_include ], + 'objects' : ['systemd-nsresourced'], }, - libexec_template + { - 'name' : 'systemd-nsresourced', - 'sources' : systemd_nsresourced_sources, - 'dependencies' : threads, - 'include_directories' : [ includes, userns_restrict_include ], + test_template + { + 'sources' : test_userns_restrict_sources, + 'conditions' : ['HAVE_VMLINUX_H'], + 'objects' : ['systemd-nsresourced'], }, ] diff --git a/src/oom/meson.build b/src/oom/meson.build index bd4b734e0f..1d0880e3f2 100644 --- a/src/oom/meson.build +++ b/src/oom/meson.build @@ -1,10 +1,16 @@ # SPDX-License-Identifier: LGPL-2.1-or-later +if conf.get('ENABLE_OOMD') != 1 + subdir_done() +endif + systemd_oomd_sources = files( 'oomd.c', 'oomd-conf.c', 'oomd-manager.c', 'oomd-manager-bus.c', +) +systemd_oomd_extract_sources = files( 'oomd-util.c', ) @@ -12,34 +18,29 @@ executables += [ libexec_template + { 'name' : 'systemd-oomd', 'dbus' : true, - 'conditions' : ['ENABLE_OOMD'], - 'sources' : systemd_oomd_sources, + 'sources' : [systemd_oomd_sources, systemd_oomd_extract_sources], + 'extract' : systemd_oomd_extract_sources, 'dependencies' : libatomic, }, executable_template + { 'name' : 'oomctl', 'public' : true, - 'conditions' : ['ENABLE_OOMD'], 'sources' : files('oomctl.c'), }, test_template + { - 'sources' : files( - 'test-oomd-util.c', - 'oomd-util.c', - ), + 'sources' : files('test-oomd-util.c'), + 'objects' : ['systemd-oomd'], 'dependencies' : libatomic, }, ] -if conf.get('ENABLE_OOMD') == 1 - install_data('org.freedesktop.oom1.conf', - install_dir : dbuspolicydir) +install_data('org.freedesktop.oom1.conf', + install_dir : dbuspolicydir) - install_data('org.freedesktop.oom1.service', - install_dir : dbussystemservicedir) +install_data('org.freedesktop.oom1.service', + install_dir : dbussystemservicedir) - if install_sysconfdir_samples - install_data('oomd.conf', - install_dir : pkgconfigfiledir) - endif +if install_sysconfdir_samples + install_data('oomd.conf', + install_dir : pkgconfigfiledir) endif diff --git a/src/resolve/meson.build b/src/resolve/meson.build index 9461d6a862..57edb6508f 100644 --- a/src/resolve/meson.build +++ b/src/resolve/meson.build @@ -1,6 +1,13 @@ # SPDX-License-Identifier: LGPL-2.1-or-later +if conf.get('ENABLE_RESOLVE') != 1 + subdir_done() +endif + systemd_resolved_sources = files( + 'resolved.c', +) +systemd_resolved_extract_sources = files( 'dns-type.c', 'resolved-bus.c', 'resolved-conf.c', @@ -84,26 +91,15 @@ resolved_dnssd_gperf_c = custom_target( command : [gperf, '@INPUT@', '--output-file', '@OUTPUT@']) generated_sources += [dns_type_from_name_h, dns_type_to_name_h, resolved_gperf_c, resolved_dnssd_gperf_c] -systemd_resolved_sources += [dns_type_from_name_h, dns_type_to_name_h, resolved_gperf_c, resolved_dnssd_gperf_c] +systemd_resolved_extract_sources += [dns_type_from_name_h, dns_type_to_name_h, resolved_gperf_c, resolved_dnssd_gperf_c] if conf.get('ENABLE_DNS_OVER_TLS') == 1 - systemd_resolved_sources += files( + systemd_resolved_extract_sources += files( 'resolved-dnstls.c', ) endif -resolved_core = static_library( - 'systemd-resolved-core', - systemd_resolved_sources, - include_directories : includes, - dependencies : userspace, - build_by_default : false) - resolve_common_template = { - 'link_with' : [ - libshared, - resolved_core, - ], 'dependencies' : [ libopenssl, libm, @@ -111,20 +107,20 @@ resolve_common_template = { ], } -resolve_test_template = test_template + resolve_common_template -resolve_fuzz_template = fuzz_template + resolve_common_template +resolve_test_template = test_template + resolve_common_template + {'objects' : ['systemd-resolved']} +resolve_fuzz_template = fuzz_template + resolve_common_template + {'objects' : ['systemd-resolved']} executables += [ libexec_template + resolve_common_template + { 'name' : 'systemd-resolved', 'dbus' : true, - 'conditions' : ['ENABLE_RESOLVE'], - 'sources' : files('resolved.c'), + 'sources' : [systemd_resolved_sources, systemd_resolved_extract_sources], + 'include_directories' : [libexec_template['include_directories'], include_directories('.')], + 'extract' : systemd_resolved_extract_sources, }, executable_template + resolve_common_template + { 'name' : 'resolvectl', 'public' : true, - 'conditions' : ['ENABLE_RESOLVE'], 'sources' : files( 'resolvconf-compat.c', 'resolvectl.c', @@ -132,6 +128,7 @@ executables += [ 'dependencies' : resolve_common_template['dependencies'] + [ libidn, ], + 'objects' : ['systemd-resolved'], }, resolve_test_template + { 'sources' : files('test-resolve-tables.c'), @@ -140,10 +137,7 @@ executables += [ 'sources' : files('test-dns-answer.c'), }, resolve_test_template + { - 'sources' : files( - 'test-dns-cache.c', - 'resolved-dns-cache.c' - ), + 'sources' : files('test-dns-cache.c'), }, resolve_test_template + { 'sources' : files('test-dns-packet.c'), @@ -161,10 +155,7 @@ executables += [ 'sources' : files('test-dns-question.c'), }, resolve_test_template + { - 'sources' : files( - 'test-resolved-etc-hosts.c', - 'resolved-etc-hosts.c', - ), + 'sources' : files('test-resolved-etc-hosts.c'), }, resolve_test_template + { 'sources' : files('test-resolved-packet.c'), @@ -203,40 +194,35 @@ executables += [ 'sources' : files('fuzz-dns-packet.c'), }, resolve_fuzz_template + { - 'sources' : files( - 'fuzz-etc-hosts.c', - 'resolved-etc-hosts.c', - ), + 'sources' : files('fuzz-etc-hosts.c'), }, resolve_fuzz_template + { 'sources' : files('fuzz-resource-record.c'), }, ] -if conf.get('ENABLE_RESOLVE') == 1 - install_data('org.freedesktop.resolve1.conf', - install_dir : dbuspolicydir) - install_data('org.freedesktop.resolve1.service', - install_dir : dbussystemservicedir) - install_data('org.freedesktop.resolve1.policy', - install_dir : polkitpolicydir) - install_data('resolv.conf', - install_dir : libexecdir) +install_data('org.freedesktop.resolve1.conf', + install_dir : dbuspolicydir) +install_data('org.freedesktop.resolve1.service', + install_dir : dbussystemservicedir) +install_data('org.freedesktop.resolve1.policy', + install_dir : polkitpolicydir) +install_data('resolv.conf', + install_dir : libexecdir) - install_symlink('resolvconf', - pointing_to : sbin_to_bin + 'resolvectl', - install_dir : sbindir) +install_symlink('resolvconf', + pointing_to : sbin_to_bin + 'resolvectl', + install_dir : sbindir) - # symlink for backwards compatibility after rename - install_symlink('systemd-resolve', - pointing_to : 'resolvectl', - install_dir : bindir) -endif +# symlink for backwards compatibility after rename +install_symlink('systemd-resolve', + pointing_to : 'resolvectl', + install_dir : bindir) custom_target( 'resolved.conf', input : 'resolved.conf.in', output : 'resolved.conf', command : [jinja2_cmdline, '@INPUT@', '@OUTPUT@'], - install : conf.get('ENABLE_RESOLVE') == 1 and install_sysconfdir_samples, + install : install_sysconfdir_samples, install_dir : pkgconfigfiledir) diff --git a/src/shutdown/meson.build b/src/shutdown/meson.build index 9bc60f83e5..5fc896c000 100644 --- a/src/shutdown/meson.build +++ b/src/shutdown/meson.build @@ -4,20 +4,23 @@ systemd_shutdown_sources = files( 'detach-dm.c', 'detach-loopback.c', 'detach-md.c', - 'detach-swap.c', 'shutdown.c', +) +systemd_shutdown_extract_sources = files( + 'detach-swap.c', 'umount.c', ) executables += [ libexec_template + { 'name' : 'systemd-shutdown', - 'sources' : systemd_shutdown_sources, + 'sources' : [systemd_shutdown_sources, systemd_shutdown_extract_sources], + 'extract' : systemd_shutdown_extract_sources, 'dependencies' : libmount, }, libexec_template + { 'name' : 'systemd-shutdown.standalone', - 'sources' : systemd_shutdown_sources, + 'sources' : [systemd_shutdown_sources, systemd_shutdown_extract_sources], 'c_args' : '-DSTANDALONE', 'link_with' : [ libbasic_static, @@ -29,11 +32,8 @@ executables += [ 'install' : have_standalone_binaries, }, test_template + { - 'sources' : files( - 'test-umount.c', - 'detach-swap.c', - 'umount.c', - ), + 'sources' : files('test-umount.c'), + 'objects' : ['systemd-shutdown'], 'dependencies' : libmount, }, ] diff --git a/src/sleep/meson.build b/src/sleep/meson.build index fc0037e387..03fc9f1ab5 100644 --- a/src/sleep/meson.build +++ b/src/sleep/meson.build @@ -1,18 +1,22 @@ # SPDX-License-Identifier: LGPL-2.1-or-later +sleep_sources = files( + 'sleep.c', +) +sleep_extract_sources = files( + 'battery-capacity.c', +) + executables += [ libexec_template + { 'name' : 'systemd-sleep', - 'sources' : files( - 'sleep.c', - 'battery-capacity.c', - ), + 'sources' : [sleep_sources, sleep_extract_sources], + 'include_directories' : [libexec_template['include_directories'], include_directories('.')], + 'extract' : sleep_extract_sources, }, test_template + { - 'sources' : files( - 'test-battery-capacity.c', - 'battery-capacity.c', - ), + 'sources' : files('test-battery-capacity.c'), + 'objects' : ['systemd-sleep'], }, ] diff --git a/src/timesync/meson.build b/src/timesync/meson.build index 19437ee927..d32e32dcbc 100644 --- a/src/timesync/meson.build +++ b/src/timesync/meson.build @@ -1,16 +1,19 @@ # SPDX-License-Identifier: LGPL-2.1-or-later -sources = files( +if conf.get('ENABLE_TIMESYNCD') != 1 + subdir_done() +endif + +timesyncd_sources = files( + 'timesyncd.c', + 'timesyncd-bus.c', +) +timesyncd_extract_sources = files( 'timesyncd-conf.c', 'timesyncd-manager.c', 'timesyncd-server.c', ) -systemd_timesyncd_sources = files( - 'timesyncd.c', - 'timesyncd-bus.c', -) - timesyncd_gperf_c = custom_target( 'timesyncd-gperf.c', input : 'timesyncd-gperf.gperf', @@ -18,7 +21,7 @@ timesyncd_gperf_c = custom_target( command : [gperf, '@INPUT@', '--output-file', '@OUTPUT@']) generated_sources += timesyncd_gperf_c -sources += timesyncd_gperf_c +timesyncd_extract_sources += timesyncd_gperf_c if get_option('link-timesyncd-shared') timesyncd_link_with = [libshared] @@ -27,20 +30,13 @@ else libshared_static] endif -libtimesyncd_core = static_library( - 'timesyncd-core', - sources, - include_directories : includes, - dependencies : userspace, - link_with : timesyncd_link_with, - build_by_default : false) - executables += [ libexec_template + { 'name' : 'systemd-timesyncd', - 'conditions' : ['ENABLE_TIMESYNCD'], - 'sources' : systemd_timesyncd_sources, - 'link_with' : libtimesyncd_core, + 'sources' : [timesyncd_sources, timesyncd_extract_sources], + 'include_directories' : [libexec_template['include_directories'], include_directories('.')], + 'extract' : timesyncd_extract_sources, + 'link_with' : timesyncd_link_with, 'dependencies' : [ libm, threads, @@ -48,16 +44,13 @@ executables += [ }, libexec_template + { 'name' : 'systemd-time-wait-sync', - 'conditions' : ['ENABLE_TIMESYNCD'], 'sources' : files('wait-sync.c'), - 'link_with' : libtimesyncd_core, + 'objects' : ['systemd-timesyncd'], + 'dependencies' : libm, }, test_template + { 'sources' : files('test-timesync.c'), - 'link_with' : [ - libshared, - libtimesyncd_core, - ], + 'objects' : ['systemd-timesyncd'], 'dependencies' : libm, }, ] @@ -70,13 +63,11 @@ custom_target( install : conf.get('ENABLE_TIMESYNCD') == 1 and install_sysconfdir_samples, install_dir : pkgconfigfiledir) -if conf.get('ENABLE_TIMESYNCD') == 1 - install_data('org.freedesktop.timesync1.conf', - install_dir : dbuspolicydir) - install_data('org.freedesktop.timesync1.service', - install_dir : dbussystemservicedir) - install_data('80-systemd-timesync.list', - install_dir : ntpservicelistdir) - install_data('org.freedesktop.timesync1.policy', - install_dir : polkitpolicydir) -endif +install_data('org.freedesktop.timesync1.conf', + install_dir : dbuspolicydir) +install_data('org.freedesktop.timesync1.service', + install_dir : dbussystemservicedir) +install_data('80-systemd-timesync.list', + install_dir : ntpservicelistdir) +install_data('org.freedesktop.timesync1.policy', + install_dir : polkitpolicydir) diff --git a/src/tmpfiles/meson.build b/src/tmpfiles/meson.build index 09ad839586..e035d5f03d 100644 --- a/src/tmpfiles/meson.build +++ b/src/tmpfiles/meson.build @@ -1,7 +1,13 @@ # SPDX-License-Identifier: LGPL-2.1-or-later +if conf.get('ENABLE_TMPFILES') != 1 + subdir_done() +endif + systemd_tmpfiles_sources = files( 'tmpfiles.c', +) +systemd_tmpfiles_extract_sources = files( 'offline-passwd.c', ) @@ -9,15 +15,14 @@ executables += [ executable_template + { 'name' : 'systemd-tmpfiles', 'public' : true, - 'conditions' : ['ENABLE_TMPFILES'], - 'sources' : systemd_tmpfiles_sources, + 'sources' : [systemd_tmpfiles_sources, systemd_tmpfiles_extract_sources], + 'extract' : systemd_tmpfiles_extract_sources, 'dependencies' : libacl, }, executable_template + { 'name' : 'systemd-tmpfiles.standalone', 'public' : have_standalone_binaries, - 'conditions' : ['ENABLE_TMPFILES'], - 'sources' : systemd_tmpfiles_sources, + 'sources' : [systemd_tmpfiles_sources, systemd_tmpfiles_extract_sources], 'c_args' : '-DSTANDALONE', 'link_with' : [ libbasic_static, @@ -29,9 +34,7 @@ executables += [ 'install' : have_standalone_binaries, }, test_template + { - 'sources' : files( - 'test-offline-passwd.c', - 'offline-passwd.c', - ), + 'sources' : files('test-offline-passwd.c'), + 'objects' : ['systemd-tmpfiles'], }, ] diff --git a/src/udev/meson.build b/src/udev/meson.build index 412f5729d4..ba0a6b14ff 100644 --- a/src/udev/meson.build +++ b/src/udev/meson.build @@ -17,8 +17,7 @@ udevadm_sources = files( 'udevadm.c', 'udevd.c', ) - -libudevd_core_sources = files( +udevadm_extract_sources = files( 'net/link-config.c', 'udev-builtin.c', 'udev-builtin-btrfs.c', @@ -49,15 +48,15 @@ libudevd_core_sources = files( ) if conf.get('HAVE_KMOD') == 1 - libudevd_core_sources += files('udev-builtin-kmod.c') + udevadm_extract_sources += files('udev-builtin-kmod.c') endif if conf.get('HAVE_BLKID') == 1 - libudevd_core_sources += files('udev-builtin-blkid.c') + udevadm_extract_sources += files('udev-builtin-blkid.c') endif if conf.get('HAVE_ACL') == 1 - libudevd_core_sources += files('udev-builtin-uaccess.c') + udevadm_extract_sources += files('udev-builtin-uaccess.c') endif ############################################################ @@ -104,6 +103,7 @@ link_config_gperf_c = custom_target( output : 'link-config-gperf.c', command : [gperf, '@INPUT@', '--output-file', '@OUTPUT@']) +udevadm_extract_sources += link_config_gperf_c generated_sources += link_config_gperf_c ############################################################ @@ -119,18 +119,6 @@ endif ############################################################ -libudevd_core = static_library( - 'udev-core', - libudevd_core_sources, - link_config_gperf_c, - keyboard_keys_from_name_h, - include_directories : includes + include_directories('net'), - link_with : udev_link_with, - dependencies : [libblkid, - libkmod_cflags, - userspace], - build_by_default : false) - udev_dependencies = [ libacl, libblkid, @@ -147,12 +135,10 @@ udev_plugin_template = executable_template + { } udev_common_template = { - 'link_with' : [ - libshared, - libudevd_core, - ], + 'objects' : ['udevadm'], 'dependencies' : [ libacl, + libblkid, threads, ], } @@ -163,11 +149,19 @@ udev_binaries_dict = [ executable_template + { 'name' : 'udevadm', 'public' : true, - 'sources' : udevadm_sources, - 'link_with' : [libudevd_core], + 'sources' : [ + udevadm_sources, + udevadm_extract_sources, + keyboard_keys_from_name_h, + ], + 'include_directories' : [ + libexec_template['include_directories'], + include_directories('.', 'net'), + ], 'dependencies' : udev_dependencies, 'install_rpath' : udev_rpath, 'install_tag' : 'udev', + 'extract' : udevadm_extract_sources, }, udev_plugin_template + { 'name' : 'ata_id', @@ -188,6 +182,7 @@ udev_binaries_dict = [ 'fido_id/fido_id.c', 'fido_id/fido_id_desc.c', ), + 'extract' : files('fido_id/fido_id_desc.c'), }, udev_plugin_template + { 'name' : 'iocost', @@ -221,15 +216,12 @@ endforeach executables += udev_binaries_dict executables += [ test_template + { - 'sources' : files( - 'fido_id/test-fido-id-desc.c', - 'fido_id/fido_id_desc.c', - ), + 'sources' : files('fido_id/test-fido-id-desc.c'), + 'objects' : ['fido_id'], 'suite' : 'udev', }, udev_test_template + { 'sources' : files('net/test-link-config-tables.c'), - 'include_directories' : includes + include_directories('.'), 'suite' : 'udev', }, udev_test_template + { @@ -258,14 +250,11 @@ executables += [ 'sources' : files('test-udev-spawn.c'), }, fuzz_template + { - 'sources' : files( - 'fido_id/fuzz-fido-id-desc.c', - 'fido_id/fido_id_desc.c', - ), + 'sources' : files('fido_id/fuzz-fido-id-desc.c'), + 'objects' : ['fido_id'], }, udev_fuzz_template + { 'sources' : files('net/fuzz-link-parser.c'), - 'include_directories' : includes + include_directories('.'), }, udev_fuzz_template + { 'sources' : files('fuzz-udev-rule-parse-value.c'), diff --git a/src/vmspawn/meson.build b/src/vmspawn/meson.build index c4decd8434..eefe81c870 100644 --- a/src/vmspawn/meson.build +++ b/src/vmspawn/meson.build @@ -4,39 +4,27 @@ if conf.get('ENABLE_VMSPAWN') != 1 subdir_done() endif -libvmspawn_core_sources = files( +vmspawn_sources = files( + 'vmspawn.c', 'vmspawn-settings.c', - 'vmspawn-util.c', 'vmspawn-scope.c', 'vmspawn-mount.c', 'vmspawn-register.c', ) - -libvmspawn_core = static_library( - 'vmspawn-core', - libvmspawn_core_sources, - include_directories : includes, - dependencies : [userspace], - build_by_default : false) - -vmspawn_libs = [ - libvmspawn_core, - libshared, -] - -vmspawn_test_template = test_template + { - 'link_with' : [vmspawn_libs], -} +vmspawn_extract_sources = files( + 'vmspawn-util.c', +) executables += [ executable_template + { 'name' : 'systemd-vmspawn', 'public' : true, - 'sources' : files('vmspawn.c'), - 'link_with' : vmspawn_libs, + 'sources' : [vmspawn_sources, vmspawn_extract_sources], + 'extract' : vmspawn_extract_sources, 'dependencies' : [libblkid] }, - vmspawn_test_template + { + test_template + { 'sources' : files('test-vmspawn-util.c'), + 'objects' : ['systemd-vmspawn'], }, ] diff --git a/src/xdg-autostart-generator/meson.build b/src/xdg-autostart-generator/meson.build index c938932c62..58620b5dcd 100644 --- a/src/xdg-autostart-generator/meson.build +++ b/src/xdg-autostart-generator/meson.build @@ -1,32 +1,36 @@ # SPDX-License-Identifier: LGPL-2.1-or-later +if conf.get('ENABLE_XDG_AUTOSTART') != 1 + subdir_done() +endif + systemd_xdg_autostart_generator_sources = files( 'xdg-autostart-generator.c', +) +systemd_xdg_autostart_generator_extract_sources = files( 'xdg-autostart-service.c', ) executables += [ executable_template + { 'name' : 'systemd-xdg-autostart-generator', - 'conditions' : ['ENABLE_XDG_AUTOSTART'], - 'sources' : systemd_xdg_autostart_generator_sources, + 'sources' : [ + systemd_xdg_autostart_generator_sources, + systemd_xdg_autostart_generator_extract_sources, + ], + 'extract' : systemd_xdg_autostart_generator_extract_sources, 'install_dir' : usergeneratordir, }, libexec_template + { 'name' : 'systemd-xdg-autostart-condition', - 'conditions' : ['ENABLE_XDG_AUTOSTART'], 'sources' : files('xdg-autostart-condition.c'), }, test_template + { - 'sources' : files( - 'test-xdg-autostart.c', - 'xdg-autostart-service.c', - ), + 'sources' : files('test-xdg-autostart.c'), + 'objects' : ['systemd-xdg-autostart-generator'], }, fuzz_template + { - 'sources' : files( - 'fuzz-xdg-desktop.c', - 'xdg-autostart-service.c', - ), + 'sources' : files('fuzz-xdg-desktop.c'), + 'objects' : ['systemd-xdg-autostart-generator'], }, ] diff --git a/tools/oss-fuzz.sh b/tools/oss-fuzz.sh index df3d39eba6..05f9191fb6 100755 --- a/tools/oss-fuzz.sh +++ b/tools/oss-fuzz.sh @@ -32,7 +32,7 @@ meson_args=("-Db_lundef=false") if [ -z "$FUZZING_ENGINE" ]; then meson_args+=("-Dllvm-fuzz=true") else - meson_args+=("-Doss-fuzz=true" "--auto-features=disabled") + meson_args+=("-Doss-fuzz=true" "--auto-features=disabled" "-Dnspawn=enabled" "-Dresolve=true") apt-get update apt-get install -y gperf m4 gettext python3-pip \ From 30d20907bddfe064cc3437a888dd8f00d14929e4 Mon Sep 17 00:00:00 2001 From: Daan De Meyer Date: Fri, 9 May 2025 20:48:51 +0200 Subject: [PATCH 3/4] meson: Remove unneeded include directories meson by default adds the current source and build directory as include directories. Because we structure our meson code by gathering a giant dict of everything we want to do and then doing all the actual target generation in the top level meson.build, this behavior does not make sense at all because we end up adding the top level repository directory as an include directory which is never what we want. At the same time, let's also make sure the top level directory of the build directory is not an include directory, by moving the version.h generation into the src/version subdirectory and then adding the src/version subdirectory of the build directory as an include directory instead of the top level repository directory. Making this change means that language servers such as clangd can't get confused when they automatically insert an #include line and insert "#include "src/basic/fs-util.h" instead of "#include "fs-util.h". --- meson.build | 19 +++++------ src/basic/meson.build | 1 + src/boot/meson.build | 5 ++- src/core/meson.build | 4 ++- src/cryptsetup/cryptsetup-tokens/meson.build | 1 + src/libsystemd-network/meson.build | 1 + src/libsystemd/meson.build | 22 ++----------- src/libsystemd/sd-journal/meson.build | 34 ++++++++++++++++++++ src/libudev/meson.build | 1 + src/shared/meson.build | 3 ++ src/version/meson.build | 11 +++++++ 11 files changed, 69 insertions(+), 33 deletions(-) create mode 100644 src/libsystemd/sd-journal/meson.build create mode 100644 src/version/meson.build diff --git a/meson.build b/meson.build index a10a103871..65b77c5214 100644 --- a/meson.build +++ b/meson.build @@ -1957,14 +1957,7 @@ endif conf.set_quoted('VERSION_TAG', version_tag) -vcs_tag = get_option('vcs-tag') -version_h = custom_target('version', - build_always_stale : vcs_tag, - input : 'src/version/version.h.in', - output : 'version.h', - capture : true, - command : ['tools/vcs-tag.sh', '@INPUT@', get_option('mode'), vcs_tag ? '1' : '0'], -) +subdir('src/version') shared_lib_tag = get_option('shared-lib-tag') if shared_lib_tag == '' @@ -2018,19 +2011,17 @@ dbus_programs = [] # A list of boot stubs. Required for testing of ukify. boot_stubs = [] -build_dir_include = include_directories('.') - basic_includes = [ include_directories( 'src/basic', 'src/fundamental', 'src/systemd', - '.', ), include_directories( 'src/basic/include', is_system : true, ), + version_include, ] libsystemd_includes = [basic_includes, include_directories( @@ -2061,6 +2052,7 @@ libsystemd = shared_library( 'systemd', version : libsystemd_version, include_directories : libsystemd_includes, + implicit_include_directories : false, link_args : ['-shared', # Make sure our library is never deleted from memory, so that our open logging fds don't leak on dlopen/dlclose cycles. '-z', 'nodelete', @@ -2081,6 +2073,7 @@ install_libsystemd_static = static_library( basic_sources, fundamental_sources, include_directories : libsystemd_includes, + implicit_include_directories : false, build_by_default : static_libsystemd != 'false', install : static_libsystemd != 'false', install_tag: 'libsystemd', @@ -2111,6 +2104,7 @@ libudev = shared_library( 'udev', version : libudev_version, include_directories : includes, + implicit_include_directories : false, link_args : ['-shared', '-Wl,--version-script=' + libudev_sym_path], link_with : [libsystemd_static, libshared_static], @@ -2130,6 +2124,7 @@ install_libudev_static = static_library( libsystemd_sources, libudev_sources, include_directories : includes, + implicit_include_directories : false, build_by_default : static_libudev != 'false', install : static_libudev != 'false', install_tag: 'libudev', @@ -2470,6 +2465,7 @@ foreach dict : executables exe = executable( name, kwargs : kwargs, + implicit_include_directories : false, ) executables_by_name += { name : exe } @@ -2600,6 +2596,7 @@ foreach dict : modules lib = shared_library( name, kwargs : kwargs, + implicit_include_directories : false, ) if is_nss diff --git a/src/basic/meson.build b/src/basic/meson.build index 4588a9a6e8..a2ac978a20 100644 --- a/src/basic/meson.build +++ b/src/basic/meson.build @@ -290,6 +290,7 @@ libbasic_static = static_library( basic_sources, fundamental_sources, include_directories : basic_includes, + implicit_include_directories : false, dependencies : [libcap, libdl, libgcrypt_cflags, diff --git a/src/boot/meson.build b/src/boot/meson.build index c2a894d323..098f9435b8 100644 --- a/src/boot/meson.build +++ b/src/boot/meson.build @@ -15,6 +15,7 @@ libefitest = static_library( basic_includes, include_directories('.'), ], + implicit_include_directories : false, dependencies : userspace) efitest_base = { @@ -153,9 +154,9 @@ configure_file( ############################################################ efi_includes = [ - build_dir_include, fundamental_include, include_directories('.'), + version_include, ] efi_c_args = [ @@ -380,6 +381,7 @@ foreach archspec : efi_archspecs libefi_sources, version_h, include_directories : efi_includes, + implicit_include_directories : false, c_args : archspec['c_args'], gnu_symbol_visibility : 'hidden', override_options : efi_override_options, @@ -387,6 +389,7 @@ foreach archspec : efi_archspecs kwargs = { 'include_directories' : efi_includes, + 'implicit_include_directories' : false, 'c_args' : archspec['c_args'], 'link_args' : archspec['link_args'], 'gnu_symbol_visibility' : 'hidden', diff --git a/src/core/meson.build b/src/core/meson.build index 0a135171fc..500fb13f9b 100644 --- a/src/core/meson.build +++ b/src/core/meson.build @@ -105,7 +105,8 @@ libcore_static = static_library( libcore_sources, load_fragment_gperf_c, load_fragment_gperf_nulstr_c, - include_directories : includes, + include_directories : [includes, include_directories('.')], + implicit_include_directories : false, c_args : ['-fvisibility=default'], dependencies : [libacl, libaudit, @@ -123,6 +124,7 @@ libcore_static = static_library( libcore = shared_library( libcore_name, c_args : ['-fvisibility=default'], + implicit_include_directories : false, link_args : ['-shared', '-Wl,--version-script=' + libshared_sym_path], link_depends : libshared_sym_path, diff --git a/src/cryptsetup/cryptsetup-tokens/meson.build b/src/cryptsetup/cryptsetup-tokens/meson.build index b26940c6a3..804e18bc67 100644 --- a/src/cryptsetup/cryptsetup-tokens/meson.build +++ b/src/cryptsetup/cryptsetup-tokens/meson.build @@ -4,6 +4,7 @@ lib_cryptsetup_token_common = static_library( 'cryptsetup-token-common', 'cryptsetup-token-util.c', include_directories : includes, + implicit_include_directories : false, dependencies : userspace, link_with : libshared, build_by_default : false) diff --git a/src/libsystemd-network/meson.build b/src/libsystemd-network/meson.build index 262ce9c4ef..333b3e0541 100644 --- a/src/libsystemd-network/meson.build +++ b/src/libsystemd-network/meson.build @@ -40,6 +40,7 @@ libsystemd_network = static_library( 'systemd-network', sources, include_directories : includes, + implicit_include_directories : false, dependencies : userspace, build_by_default : false) diff --git a/src/libsystemd/meson.build b/src/libsystemd/meson.build index 9558bfb4ab..988e5e0ce7 100644 --- a/src/libsystemd/meson.build +++ b/src/libsystemd/meson.build @@ -14,26 +14,7 @@ sd_journal_sources = files( 'sd-journal/sd-journal.c', ) -audit_type_includes = [config_h, - missing_audit_h, - 'linux/audit.h'] -if conf.get('HAVE_AUDIT') == 1 - audit_type_includes += 'libaudit.h' -endif - -generate_audit_type_list = find_program('sd-journal/generate-audit_type-list.sh') -audit_type_list_txt = custom_target( - 'audit_type-list.txt', - output : 'audit_type-list.txt', - command : [generate_audit_type_list, cpp] + audit_type_includes, - capture : true) - -audit_type_to_name = custom_target( - 'audit_type-to-name.h', - input : ['sd-journal/audit_type-to-name.awk', audit_type_list_txt], - output : 'audit_type-to-name.h', - command : [awk, '-f', '@INPUT0@', '@INPUT1@'], - capture : true) +subdir('sd-journal') generated_sources += audit_type_to_name sd_journal_sources += audit_type_to_name @@ -160,6 +141,7 @@ libsystemd_static = static_library( 'systemd_static', libsystemd_sources, include_directories : libsystemd_includes, + implicit_include_directories : false, c_args : libsystemd_c_args, link_with : [libbasic_static], dependencies : [threads, diff --git a/src/libsystemd/sd-journal/meson.build b/src/libsystemd/sd-journal/meson.build new file mode 100644 index 0000000000..5b8b582f27 --- /dev/null +++ b/src/libsystemd/sd-journal/meson.build @@ -0,0 +1,34 @@ +# SPDX-License-Identifier: LGPL-2.1-or-later + +# We're generating a header file here intended to be included +# by audit-type.c. To make that work, we have to add the generated +# header file's directory to the include directories for libsystemd. +# In meson, adding include directories is done via include_directories(), +# which always adds two include directories for each argument, one relative to +# the source directory and one relative to the build directory. We don't +# want to add src/libsystemd to the include directories, yet custom_target() +# does not allow path segments in its output argument, so to make sure the +# generated header is written to src/libsystemd/sd-journal in the build directory, +# the custom_target() has to be defined here in src/libsystemd/sd-journal +# in the source directory. + +audit_type_includes = [config_h, + missing_audit_h, + 'linux/audit.h'] +if conf.get('HAVE_AUDIT') == 1 + audit_type_includes += 'libaudit.h' +endif + +generate_audit_type_list = find_program('generate-audit_type-list.sh') +audit_type_list_txt = custom_target( + 'audit_type-list.txt', + output : 'audit_type-list.txt', + command : [generate_audit_type_list, cpp] + audit_type_includes, + capture : true) + +audit_type_to_name = custom_target( + 'audit_type-to-name.h', + input : ['audit_type-to-name.awk', audit_type_list_txt], + output : 'audit_type-to-name.h', + command : [awk, '-f', '@INPUT0@', '@INPUT1@'], + capture : true) diff --git a/src/libudev/meson.build b/src/libudev/meson.build index 7f999197af..e5c0c8361b 100644 --- a/src/libudev/meson.build +++ b/src/libudev/meson.build @@ -27,6 +27,7 @@ libudev_basic = static_library( 'udev-basic', libudev_sources, include_directories : includes, + implicit_include_directories : false, dependencies : userspace, c_args : ['-fvisibility=default'], build_by_default : false) diff --git a/src/shared/meson.build b/src/shared/meson.build index 0a514dec7d..c25715c71d 100644 --- a/src/shared/meson.build +++ b/src/shared/meson.build @@ -360,6 +360,7 @@ libshared_static = static_library( libshared_name, shared_sources, include_directories : includes, + implicit_include_directories : false, dependencies : [libshared_deps, userspace], c_args : ['-fvisibility=default'], @@ -368,6 +369,7 @@ libshared_static = static_library( libshared = shared_library( libshared_name, include_directories : includes, + implicit_include_directories : false, c_args : ['-fvisibility=default'], link_args : ['-shared', '-Wl,--version-script=' + libshared_sym_path], @@ -386,6 +388,7 @@ libshared_fdisk = static_library( 'shared-fdisk', shared_fdisk_sources, include_directories : includes, + implicit_include_directories : false, dependencies : [libfdisk, userspace], c_args : ['-fvisibility=default'], diff --git a/src/version/meson.build b/src/version/meson.build new file mode 100644 index 0000000000..3526723af0 --- /dev/null +++ b/src/version/meson.build @@ -0,0 +1,11 @@ +# SPDX-License-Identifier: LGPL-2.1-or-later + +vcs_tag = get_option('vcs-tag') +version_h = custom_target('version', + build_always_stale : vcs_tag, + input : 'version.h.in', + output : 'version.h', + capture : true, + command : [meson.project_source_root() / 'tools/vcs-tag.sh', '@INPUT@', get_option('mode'), vcs_tag ? '1' : '0'], +) +version_include = include_directories('.') From 1fbaabf9ec3a733702b3f8be8ddf77977bde4e70 Mon Sep 17 00:00:00 2001 From: Daan De Meyer Date: Sat, 10 May 2025 22:19:22 +0200 Subject: [PATCH 4/4] meson: Don't create static library target unless option is enabled While we don't build these by default, all the source files still get added to the compile_commands.json file by meson, which can confuse tools as they might end up analyzing the source files twice or analyzing the wrong one. To avoid this issue, only define the static library target if the corresponding option is enabled. --- meson.build | 92 ++++++++++++++++++++++---------------------- src/test/meson.build | 46 +++++++++++++--------- 2 files changed, 73 insertions(+), 65 deletions(-) diff --git a/meson.build b/meson.build index 65b77c5214..48b8b05834 100644 --- a/meson.build +++ b/meson.build @@ -2067,34 +2067,33 @@ libsystemd = shared_library( install_tag: 'libsystemd', install_dir : libdir) -install_libsystemd_static = static_library( - 'systemd', - libsystemd_sources, - basic_sources, - fundamental_sources, - include_directories : libsystemd_includes, - implicit_include_directories : false, - build_by_default : static_libsystemd != 'false', - install : static_libsystemd != 'false', - install_tag: 'libsystemd', - install_dir : libdir, - pic : static_libsystemd_pic, - dependencies : [libblkid, - libcap, - libdl, - libgcrypt_cflags, - liblz4_cflags, - libm, - libmount, - libopenssl, - librt, - libxz_cflags, - libzstd_cflags, - threads, - userspace], - c_args : libsystemd_c_args + (static_libsystemd_pic ? [] : ['-fno-PIC'])) - if static_libsystemd != 'false' + install_libsystemd_static = static_library( + 'systemd', + libsystemd_sources, + basic_sources, + fundamental_sources, + include_directories : libsystemd_includes, + implicit_include_directories : false, + install : true, + install_tag: 'libsystemd', + install_dir : libdir, + pic : static_libsystemd_pic, + dependencies : [libblkid, + libcap, + libdl, + libgcrypt_cflags, + liblz4_cflags, + libm, + libmount, + libopenssl, + librt, + libxz_cflags, + libzstd_cflags, + threads, + userspace], + c_args : libsystemd_c_args + (static_libsystemd_pic ? [] : ['-fno-PIC'])) + alias_target('libsystemd', libsystemd, install_libsystemd_static) else alias_target('libsystemd', libsystemd) @@ -2116,27 +2115,26 @@ libudev = shared_library( install_tag: 'libudev', install_dir : libdir) -install_libudev_static = static_library( - 'udev', - basic_sources, - fundamental_sources, - shared_sources, - libsystemd_sources, - libudev_sources, - include_directories : includes, - implicit_include_directories : false, - build_by_default : static_libudev != 'false', - install : static_libudev != 'false', - install_tag: 'libudev', - install_dir : libdir, - link_depends : libudev_sym, - dependencies : [libmount, - libshared_deps, - userspace], - c_args : static_libudev_pic ? [] : ['-fno-PIC'], - pic : static_libudev_pic) - if static_libudev != 'false' + install_libudev_static = static_library( + 'udev', + basic_sources, + fundamental_sources, + shared_sources, + libsystemd_sources, + libudev_sources, + include_directories : includes, + implicit_include_directories : false, + install : true, + install_tag: 'libudev', + install_dir : libdir, + link_depends : libudev_sym, + dependencies : [libmount, + libshared_deps, + userspace], + c_args : static_libudev_pic ? [] : ['-fno-PIC'], + pic : static_libudev_pic) + alias_target('libudev', libudev, install_libudev_static) else alias_target('libudev', libudev) diff --git a/src/test/meson.build b/src/test/meson.build index 8640932d67..24d0dca2ee 100644 --- a/src/test/meson.build +++ b/src/test/meson.build @@ -461,14 +461,6 @@ executables += [ 'link_with' : libsystemd, 'suite' : 'libsystemd', }, - test_template + { - 'name' : 'test-libsystemd-static-sym', - 'sources' : test_libsystemd_sym_c, - 'link_with' : install_libsystemd_static, - 'build_by_default' : want_tests != 'false' and static_libsystemd != 'false', - 'install' : install_tests and static_libsystemd != 'false', - 'suite' : 'libsystemd', - }, test_template + { 'name' : 'test-libudev-sym', 'sources' : test_libudev_sym_c, @@ -477,16 +469,6 @@ executables += [ 'link_with' : libudev, 'suite' : 'libudev', }, - test_template + { - 'name' : 'test-libudev-static-sym', - 'sources' : test_libudev_sym_c, - 'include_directories' : libudev_includes, - 'c_args' : ['-Wno-deprecated-declarations'] + test_cflags, - 'link_with' : install_libudev_static, - 'build_by_default' : want_tests != 'false' and static_libudev != 'false', - 'install' : install_tests and static_libudev != 'false', - 'suite' : 'libudev', - }, # Tests that link to libcore, i.e. tests for pid1 code. core_test_template + { @@ -627,3 +609,31 @@ executables += [ ], }, ] + +if static_libsystemd != 'false' + executables += [ + test_template + { + 'name' : 'test-libsystemd-static-sym', + 'sources' : test_libsystemd_sym_c, + 'link_with' : install_libsystemd_static, + 'build_by_default' : want_tests != 'false', + 'install' : install_tests, + 'suite' : 'libsystemd', + }, + ] +endif + +if static_libudev != 'false' + executables += [ + test_template + { + 'name' : 'test-libudev-static-sym', + 'sources' : test_libudev_sym_c, + 'include_directories' : libudev_includes, + 'c_args' : ['-Wno-deprecated-declarations'] + test_cflags, + 'link_with' : install_libudev_static, + 'build_by_default' : want_tests != 'false', + 'install' : install_tests, + 'suite' : 'libudev', + }, + ] +endif