From f2c878a2c175d0bece4571df691a8af02e7a3ab7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barnab=C3=A1s=20P=C5=91cze?= Date: Sat, 10 May 2025 17:43:28 +0200 Subject: [PATCH] meson.build: rework `systemd` related options One issues is that the `systemd-{system,user}-service` feature options do not anything without the `systemd` option. This makes it more complicated to arrive at the desired build configuration since there are 3^3 = 27 possible ways to set each of them, but if `systemd=disabled`, then the other two are just ignored. Secondly, the `systemd` option also influences whether or not libsystemd will be used or not. This is not strictly necessary, since the "systemd" and "libsystemd" pkg-config files might be split, and one might wish to disable any kind of service file generation, but use libsystemd. Solve the first issues by using the `systemd-{system,user}-service` options when looking up the "systemd" dependency for generating service files. This means that the corresponding option is in full control, no secondary options are necessary. This means that the "systemd" dependency is looked up potentially twice, but that should not be a significant issue since meson caches dependecy lookups. And solve the second issue by renaming the now unused `systemd` option to `libsystemd` and using it solely to control whether or not libsystemd will be used. Furthermore, the default value of `systemd-user-service` is set to "auto" to prevent the dependency lookup from failing on non-systemd systemd out of the box. And the journal tests in "test-support" are extended to return "skip" if `sd_journal_open()` returns `ENOSYS`, which is needed because "elogind" ships the systemd pkg-config files and headers. --- meson.build | 6 ++---- meson_options.txt | 8 ++++---- src/daemon/meson.build | 4 +--- src/daemon/systemd/meson.build | 8 ++------ src/daemon/systemd/system/meson.build | 5 +++++ src/daemon/systemd/user/meson.build | 5 +++++ test/test-logger.c | 6 ++++++ 7 files changed, 25 insertions(+), 17 deletions(-) diff --git a/meson.build b/meson.build index 0ba5c57a8..472b97705 100644 --- a/meson.build +++ b/meson.build @@ -277,11 +277,9 @@ endforeach cdata.set('HAVE_PIDFD_OPEN', cc.get_define('SYS_pidfd_open', prefix: '#include ') != '') -systemd = dependency('systemd', required: get_option('systemd')) -systemd_dep = dependency('libsystemd',required: get_option('systemd')) -summary({'systemd conf data': systemd.found()}, bool_yn: true) +systemd_dep = dependency('libsystemd', required: get_option('libsystemd')) summary({'libsystemd': systemd_dep.found()}, bool_yn: true) -cdata.set('HAVE_SYSTEMD', systemd.found() and systemd_dep.found()) +cdata.set('HAVE_SYSTEMD', systemd_dep.found()) logind_dep = dependency(get_option('logind-provider'), required: get_option('logind')) summary({'logind': logind_dep.found()}, bool_yn: true) diff --git a/meson_options.txt b/meson_options.txt index c5464e063..206d68659 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -30,8 +30,8 @@ option('gstreamer-device-provider', description: 'Build GStreamer device provider plugin', type: 'feature', value: 'auto') -option('systemd', - description: 'Enable systemd integration', +option('libsystemd', + description: 'Enable code that depends on libsystemd', type: 'feature', value: 'auto') option('logind', @@ -48,9 +48,9 @@ option('systemd-system-service', type: 'feature', value: 'disabled') option('systemd-user-service', - description: 'Install systemd user service file (ignored without systemd)', + description: 'Install systemd user service file', type: 'feature', - value: 'enabled') + value: 'auto') option('selinux', description: 'Enable SELinux integration', type: 'feature', diff --git a/src/daemon/meson.build b/src/daemon/meson.build index b2ebb9375..e7e482f73 100644 --- a/src/daemon/meson.build +++ b/src/daemon/meson.build @@ -161,6 +161,4 @@ custom_target('pipewire-uninstalled', #endif subdir('filter-chain') -if systemd.found() - subdir('systemd') -endif +subdir('systemd') diff --git a/src/daemon/systemd/meson.build b/src/daemon/systemd/meson.build index 482a44c4b..e07449c00 100644 --- a/src/daemon/systemd/meson.build +++ b/src/daemon/systemd/meson.build @@ -1,6 +1,2 @@ -if get_option('systemd-system-service').allowed() - subdir('system') -endif -if get_option('systemd-user-service').allowed() - subdir('user') -endif +subdir('system') +subdir('user') diff --git a/src/daemon/systemd/system/meson.build b/src/daemon/systemd/system/meson.build index 0cc17670e..02efc7a41 100644 --- a/src/daemon/systemd/system/meson.build +++ b/src/daemon/systemd/system/meson.build @@ -1,3 +1,8 @@ +systemd = dependency('systemd', required : get_option('systemd-system-service')) +if not systemd.found() + subdir_done() +endif + systemd_system_services_dir = systemd.get_variable('systemdsystemunitdir', pkgconfig_define : [ 'rootprefix', prefix]) if get_option('systemd-system-unit-dir') != '' systemd_system_services_dir = get_option('systemd-system-unit-dir') diff --git a/src/daemon/systemd/user/meson.build b/src/daemon/systemd/user/meson.build index a96409f2b..1b65d5f7a 100644 --- a/src/daemon/systemd/user/meson.build +++ b/src/daemon/systemd/user/meson.build @@ -1,3 +1,8 @@ +systemd = dependency('systemd', required : get_option('systemd-user-service')) +if not systemd.found() + subdir_done() +endif + systemd_user_services_dir = systemd.get_variable('systemduserunitdir', pkgconfig_define : [ 'prefix', prefix]) if get_option('systemd-user-unit-dir') != '' systemd_user_services_dir = get_option('systemd-user-unit-dir') diff --git a/test/test-logger.c b/test/test-logger.c index 81132bffa..178263ada 100644 --- a/test/test-logger.c +++ b/test/test-logger.c @@ -496,6 +496,9 @@ PWTEST(logger_journal) pwtest_ptr_notnull(iface); rc = sd_journal_open(&journal, SD_JOURNAL_LOCAL_ONLY|SD_JOURNAL_CURRENT_USER); + if (rc == -ENOSYS) + return PWTEST_SKIP; + pwtest_neg_errno_ok(rc); sd_journal_seek_head(journal); @@ -565,6 +568,9 @@ PWTEST(logger_journal_chain) pwtest_ptr_notnull(iface); rc = sd_journal_open(&journal, SD_JOURNAL_LOCAL_ONLY); + if (rc == -ENOSYS) + return PWTEST_SKIP; + pwtest_neg_errno_ok(rc); sd_journal_seek_head(journal); if (sd_journal_next(journal) == 0) { /* No entries? We don't have a journal */