From 9e104bd3aa93fe6ff01385da98c03aba620ba0b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Sat, 6 Dec 2025 12:44:26 +0100 Subject: [PATCH 1/5] meson: put src/import source lists directly in templates The indirection through variables doesn't seem that useful here: OTOH, the lists are short, and OTOH, there is a bunch of different programs with similar names. Overall, it's all easier to follow if the lists are inline. --- src/import/meson.build | 69 ++++++++++++++++++------------------------ 1 file changed, 29 insertions(+), 40 deletions(-) diff --git a/src/import/meson.build b/src/import/meson.build index 029d4047263..46333fb15fe 100644 --- a/src/import/meson.build +++ b/src/import/meson.build @@ -4,40 +4,6 @@ if conf.get('ENABLE_IMPORTD') != 1 subdir_done() 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', - 'pull-raw.c', - 'pull-tar.c', - 'pull-job.c', - 'pull-common.c', - 'curl-util.c', -) - -systemd_import_sources = files( - 'import.c', - 'import-raw.c', - 'import-tar.c', -) - -systemd_import_fs_sources = files( - 'import-fs.c', -) - -systemd_export_sources = files( - 'export.c', - 'export-tar.c', - 'export-raw.c', -) - common_deps = [ libbzip2, libcurl, @@ -50,14 +16,27 @@ executables += [ libexec_template + { 'name' : 'systemd-importd', 'dbus' : true, - 'sources' : systemd_importd_sources, - 'extract' : systemd_importd_extract_sources, + 'sources' : files( + 'importd.c', + ), + 'extract' : files( + 'import-common.c', + 'import-compress.c', + 'qcow2-util.c', + ), 'dependencies' : [common_deps, threads], }, libexec_template + { 'name' : 'systemd-pull', 'public' : true, - 'sources' : systemd_pull_sources, + 'sources' : files( + 'pull.c', + 'pull-raw.c', + 'pull-tar.c', + 'pull-job.c', + 'pull-common.c', + 'curl-util.c', + ), 'objects' : ['systemd-importd'], 'dependencies' : common_deps + [ libopenssl, @@ -66,21 +45,31 @@ executables += [ libexec_template + { 'name' : 'systemd-import', 'public' : true, - 'sources' : systemd_import_sources, + 'sources' : files( + 'import.c', + 'import-raw.c', + 'import-tar.c', + ), 'objects' : ['systemd-importd'], 'dependencies' : common_deps, }, libexec_template + { 'name' : 'systemd-import-fs', 'public' : true, - 'sources' : systemd_import_fs_sources, + 'sources' : files( + 'import-fs.c', + ), 'objects' : ['systemd-importd'], 'dependencies' : common_deps, }, libexec_template + { 'name' : 'systemd-export', 'public' : true, - 'sources' : systemd_export_sources, + 'sources' : files( + 'export.c', + 'export-tar.c', + 'export-raw.c', + ), 'objects' : ['systemd-importd'], 'dependencies' : common_deps, }, From 54492552a1ba96e5160a8e9f867e1c49ffc87bc0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Tue, 16 Dec 2025 16:55:55 +0100 Subject: [PATCH 2/5] meson: allow .standalone version to be always built Allow .standalone version to be built on-demand, even if -Dstandalone=false is configured. In other words, this changes the meson option from a hard disablement to a soft "build is on/off by default". The meson config was originally written in this way but we lost this feature after the transition to templates. It is nice to build additional targets on demand during development, so add this back. --- meson.build | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/meson.build b/meson.build index 4746146a986..37ee1c81ebe 100644 --- a/meson.build +++ b/meson.build @@ -2517,6 +2517,7 @@ foreach dict : executables is_test = name.startswith('test-') is_fuzz = name.startswith('fuzz-') + is_standalone = name.endswith('.standalone') build = true foreach cond : dict.get('conditions', []) @@ -2529,17 +2530,13 @@ foreach dict : executables continue endif - if name.endswith('.standalone') and not have_standalone_binaries - continue - endif - exe_sources = dict.get('sources', []) + dict.get('extract', []) kwargs = {} foreach key, val : dict if key in ['name', 'dbus', 'public', 'conditions', 'type', 'suite', 'timeout', 'parallel', 'objects', 'sources', 'extract', - 'include_directories'] + 'include_directories', 'build_by_default'] continue endif @@ -2579,17 +2576,21 @@ foreach dict : executables endforeach endif + build_by_default = dict.get('build_by_default', + have_standalone_binaries or not is_standalone) + exe = executable( name, sources : exe_sources, kwargs : kwargs, implicit_include_directories : false, include_directories : include_directories, + build_by_default: build_by_default, ) executables_by_name += { name : exe } - if not name.endswith('.standalone') + if not is_standalone sources += exe_sources endif @@ -2602,7 +2603,7 @@ foreach dict : executables } endif - if dict.get('build_by_default', true) + if build_by_default if dict.get('dbus', false) dbus_programs += exe endif From 795e066d2247bf298272105287c608cf6ae430d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Tue, 16 Dec 2025 17:18:40 +0100 Subject: [PATCH 3/5] sysusers,tmpfiles: make standalone versions full-featured This effectively reverts 3537577c37d2c23a518540d36884a127aab944f8. Originally, the #ifdefs were added because we didn't want to pull in the whole tree of libmount and other dependencies in standalone versions. But dependencies are now loaded through dlopen(), so this is not needed anymore. (And doesn't even make much of a difference.) --- src/sysusers/sysusers.c | 11 ----------- src/tmpfiles/tmpfiles.c | 12 +----------- 2 files changed, 1 insertion(+), 22 deletions(-) diff --git a/src/sysusers/sysusers.c b/src/sysusers/sysusers.c index 9d46fbc5e53..3350826780f 100644 --- a/src/sysusers/sysusers.c +++ b/src/sysusers/sysusers.c @@ -2151,15 +2151,10 @@ static int parse_argv(int argc, char *argv[]) { break; case ARG_IMAGE: -#ifdef STANDALONE - return log_error_errno(SYNTHETIC_ERRNO(EOPNOTSUPP), - "This systemd-sysusers version is compiled without support for --image=."); -#else r = parse_path_argument(optarg, /* suppress_root= */ false, &arg_image); if (r < 0) return r; break; -#endif case ARG_IMAGE_POLICY: r = parse_image_policy_argument(optarg, &arg_image_policy); @@ -2283,10 +2278,8 @@ static int read_credential_lines(Context *c) { } static int run(int argc, char *argv[]) { -#ifndef STANDALONE _cleanup_(loop_device_unrefp) LoopDevice *loop_device = NULL; _cleanup_(umount_and_freep) char *mounted_dir = NULL; -#endif _cleanup_close_ int lock = -EBADF; _cleanup_(context_done) Context c = { .audit_fd = -EBADF, @@ -2314,7 +2307,6 @@ static int run(int argc, char *argv[]) { if (r < 0) return r; -#ifndef STANDALONE if (arg_image) { assert(!arg_root); @@ -2338,9 +2330,6 @@ static int run(int argc, char *argv[]) { if (!arg_root) return log_oom(); } -#else - assert(!arg_image); -#endif /* Prepare to emit audit events, but only if we're operating on the host system. */ if (!arg_root) diff --git a/src/tmpfiles/tmpfiles.c b/src/tmpfiles/tmpfiles.c index a458f3ad901..90fe4b3d75c 100644 --- a/src/tmpfiles/tmpfiles.c +++ b/src/tmpfiles/tmpfiles.c @@ -4316,14 +4316,10 @@ static int parse_argv(int argc, char *argv[]) { break; case ARG_IMAGE: -#ifdef STANDALONE - return log_error_errno(SYNTHETIC_ERRNO(EOPNOTSUPP), - "This systemd-tmpfiles version is compiled without support for --image=."); -#else r = parse_path_argument(optarg, /* suppress_root= */ false, &arg_image); if (r < 0) return r; -#endif + /* Imply -E here since it makes little sense to create files persistently in the /run mountpoint of a disk image */ _fallthrough_; @@ -4560,10 +4556,8 @@ DEFINE_PRIVATE_HASH_OPS_WITH_VALUE_DESTRUCTOR(item_array_hash_ops, char, string_ ItemArray, item_array_free); static int run(int argc, char *argv[]) { -#ifndef STANDALONE _cleanup_(loop_device_unrefp) LoopDevice *loop_device = NULL; _cleanup_(umount_and_freep) char *mounted_dir = NULL; -#endif _cleanup_strv_free_ char **config_dirs = NULL; _cleanup_(context_done) Context c = {}; bool invalid_config = false; @@ -4642,7 +4636,6 @@ static int run(int argc, char *argv[]) { if (r < 0) return r; -#ifndef STANDALONE if (arg_image) { assert(!arg_root); @@ -4666,9 +4659,6 @@ static int run(int argc, char *argv[]) { if (!arg_root) return log_oom(); } -#else - assert(!arg_image); -#endif c.items = ordered_hashmap_new(&item_array_hash_ops); c.globs = ordered_hashmap_new(&item_array_hash_ops); From b6c86e145a0070aa19f6b1b0d2820079cadc01a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Tue, 16 Dec 2025 17:21:34 +0100 Subject: [PATCH 4/5] meson: drop now-unused -DSTANDALONE If we ever want to add it back, it should be with -DSTANDALONE=0|1, so that #if instead of #ifdef can be used. We generally converted our internal defines to that form. --- src/repart/meson.build | 1 - src/shutdown/meson.build | 1 - src/sysusers/meson.build | 1 - src/tmpfiles/meson.build | 1 - 4 files changed, 4 deletions(-) diff --git a/src/repart/meson.build b/src/repart/meson.build index b922ecb7130..de0c8902d9f 100644 --- a/src/repart/meson.build +++ b/src/repart/meson.build @@ -25,7 +25,6 @@ executables += [ 'name' : 'systemd-repart.standalone', 'public' : true, 'sources' : files('repart.c'), - 'c_args' : '-DSTANDALONE', 'link_with' : [ libc_wrapper_static, libbasic_static, diff --git a/src/shutdown/meson.build b/src/shutdown/meson.build index 60b66a87d54..f5ccdbd8dd6 100644 --- a/src/shutdown/meson.build +++ b/src/shutdown/meson.build @@ -25,7 +25,6 @@ executables += [ libexec_template + { 'name' : 'systemd-shutdown.standalone', 'sources' : systemd_shutdown_sources + systemd_shutdown_extract_sources, - 'c_args' : '-DSTANDALONE', 'link_with' : [ libc_wrapper_static, libbasic_static, diff --git a/src/sysusers/meson.build b/src/sysusers/meson.build index f286ce8a20f..bbfd846e329 100644 --- a/src/sysusers/meson.build +++ b/src/sysusers/meson.build @@ -15,7 +15,6 @@ executables += [ 'name' : 'systemd-sysusers.standalone', 'public' : true, 'sources' : files('sysusers.c'), - 'c_args' : '-DSTANDALONE', 'link_with' : [ libc_wrapper_static, libbasic_static, diff --git a/src/tmpfiles/meson.build b/src/tmpfiles/meson.build index 9abe0a0c8e2..05a3171c2d0 100644 --- a/src/tmpfiles/meson.build +++ b/src/tmpfiles/meson.build @@ -23,7 +23,6 @@ executables += [ 'name' : 'systemd-tmpfiles.standalone', 'public' : true, 'sources' : systemd_tmpfiles_sources + systemd_tmpfiles_extract_sources, - 'c_args' : '-DSTANDALONE', 'link_with' : [ libc_wrapper_static, libbasic_static, From 736fc4b479b33699fe74ada31c1e36fbf77dd4c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Tue, 16 Dec 2025 17:38:44 +0100 Subject: [PATCH 5/5] meson: avoid double compilation for standalone progs So far we compiled the normal and standalone versions completely independently. Let's use the 'extract' template pattern to avoid any additional compilation and only require an single link to produce the .standalone variants. Unfortunately, as designed, the 'extract' framework only allows one set of object files to be extracted. Since we need all the files for the .standalone version, we cannot use 'extract' for other purposes. Thus, in the two cases where 'extract' was used for the test binaries, this is now changed to compile the files a second time. But the number of files in that list is small, so this seems like a better option. (If we weren't using the template system, we could easily extract just the objects we need. But with the current system, at the point of the definition, the binaries are not defined yet. We'd need to handle all of this through sets of dictionaries, and that just seems like too much trouble to avoid double compilation of a few small files.) --- meson.build | 2 +- src/repart/meson.build | 4 ++-- src/shutdown/meson.build | 22 ++++++++++------------ src/sysusers/meson.build | 4 ++-- src/tmpfiles/meson.build | 17 ++++++----------- 5 files changed, 21 insertions(+), 28 deletions(-) diff --git a/meson.build b/meson.build index 37ee1c81ebe..5f9f8adb9ba 100644 --- a/meson.build +++ b/meson.build @@ -2548,7 +2548,7 @@ foreach dict : executables endforeach include_directories = dict['include_directories'] - if not is_test + if not is_test and exe_sources.length() > 0 include_directories += fs.parent(exe_sources[0]) endif diff --git a/src/repart/meson.build b/src/repart/meson.build index de0c8902d9f..e6e32f54c7a 100644 --- a/src/repart/meson.build +++ b/src/repart/meson.build @@ -8,7 +8,7 @@ executables += [ executable_template + { 'name' : 'systemd-repart', 'public' : true, - 'sources' : files('repart.c'), + 'extract' : files('repart.c'), 'link_with' : [ libshared, libshared_fdisk, @@ -24,7 +24,7 @@ executables += [ executable_template + { 'name' : 'systemd-repart.standalone', 'public' : true, - 'sources' : files('repart.c'), + 'objects' : ['systemd-repart'], 'link_with' : [ libc_wrapper_static, libbasic_static, diff --git a/src/shutdown/meson.build b/src/shutdown/meson.build index f5ccdbd8dd6..709b0fa6925 100644 --- a/src/shutdown/meson.build +++ b/src/shutdown/meson.build @@ -4,13 +4,7 @@ if conf.get('HAVE_LIBMOUNT') != 1 subdir_done() endif -systemd_shutdown_sources = files( - 'detach-dm.c', - 'detach-loopback.c', - 'detach-md.c', - 'shutdown.c', -) -systemd_shutdown_extract_sources = files( +shutdown_detach_sources = files( 'detach-swap.c', 'umount.c', ) @@ -18,13 +12,17 @@ systemd_shutdown_extract_sources = files( executables += [ libexec_template + { 'name' : 'systemd-shutdown', - 'sources' : systemd_shutdown_sources, - 'extract' : systemd_shutdown_extract_sources, + 'extract' : files( + 'detach-dm.c', + 'detach-loopback.c', + 'detach-md.c', + 'shutdown.c', + ) + shutdown_detach_sources, 'dependencies' : libmount_cflags, }, libexec_template + { 'name' : 'systemd-shutdown.standalone', - 'sources' : systemd_shutdown_sources + systemd_shutdown_extract_sources, + 'objects' : ['systemd-shutdown'], 'link_with' : [ libc_wrapper_static, libbasic_static, @@ -34,8 +32,8 @@ executables += [ 'dependencies' : libmount_cflags, }, test_template + { - 'sources' : files('test-umount.c'), - 'objects' : ['systemd-shutdown'], + 'sources' : files('test-umount.c') + + shutdown_detach_sources, 'dependencies' : libmount_cflags, }, ] diff --git a/src/sysusers/meson.build b/src/sysusers/meson.build index bbfd846e329..b74ac6aa1a8 100644 --- a/src/sysusers/meson.build +++ b/src/sysusers/meson.build @@ -8,13 +8,13 @@ executables += [ executable_template + { 'name' : 'systemd-sysusers', 'public' : true, - 'sources' : files('sysusers.c'), + 'extract' : files('sysusers.c'), 'dependencies' : libaudit_cflags, }, executable_template + { 'name' : 'systemd-sysusers.standalone', 'public' : true, - 'sources' : files('sysusers.c'), + 'objects' : ['systemd-sysusers'], 'link_with' : [ libc_wrapper_static, libbasic_static, diff --git a/src/tmpfiles/meson.build b/src/tmpfiles/meson.build index 05a3171c2d0..2a7728c2955 100644 --- a/src/tmpfiles/meson.build +++ b/src/tmpfiles/meson.build @@ -4,25 +4,20 @@ if conf.get('ENABLE_TMPFILES') != 1 subdir_done() endif -systemd_tmpfiles_sources = files( - 'tmpfiles.c', -) -systemd_tmpfiles_extract_sources = files( - 'offline-passwd.c', -) +offline_passwd_c = files('offline-passwd.c') executables += [ executable_template + { 'name' : 'systemd-tmpfiles', 'public' : true, - 'sources' : systemd_tmpfiles_sources, - 'extract' : systemd_tmpfiles_extract_sources, + 'extract' : files('tmpfiles.c') + + offline_passwd_c, 'dependencies' : libacl_cflags, }, executable_template + { 'name' : 'systemd-tmpfiles.standalone', 'public' : true, - 'sources' : systemd_tmpfiles_sources + systemd_tmpfiles_extract_sources, + 'objects' : ['systemd-tmpfiles'], 'link_with' : [ libc_wrapper_static, libbasic_static, @@ -32,7 +27,7 @@ executables += [ 'dependencies' : libacl_cflags, }, test_template + { - 'sources' : files('test-offline-passwd.c'), - 'objects' : ['systemd-tmpfiles'], + 'sources' : files('test-offline-passwd.c') + + offline_passwd_c, }, ]