From 1d21a7bd99513afa07ee73989d71d1b0b9b03565 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Fri, 23 Jun 2023 11:00:17 +0900 Subject: [PATCH 1/5] meson: move declarations of arrays --- meson.build | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/meson.build b/meson.build index 19a441bfb7..379eeda9e4 100644 --- a/meson.build +++ b/meson.build @@ -1919,14 +1919,6 @@ conf.set10('SYSTEMD_SLOW_TESTS_DEFAULT', slow_tests) ############################################################ -tests = [] -simple_tests = [] -fuzzers = [] -simple_fuzzers = [] -catalogs = [] - -############################################################ - pymod = import('python') python = pymod.find_installation('python3', required : true, modules : ['jinja2']) python_39 = python.language_version().version_compare('>=3.9') @@ -2177,6 +2169,12 @@ man_page_depends = [] ############################################################ +tests = [] +simple_tests = [] +fuzzers = [] +simple_fuzzers = [] +catalogs = [] + # binaries that have --help and are intended for use by humans, # usually, but not always, installed in /bin. public_programs = [] From c335921e136d9bf4c2ae90c3c16ab8bb045b5a57 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Fri, 23 Jun 2023 11:09:10 +0900 Subject: [PATCH 2/5] meson: introduce infra to build executables and shared libraries by using dictionary That is not used yet. It will be used later. --- meson.build | 166 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 166 insertions(+) diff --git a/meson.build b/meson.build index 379eeda9e4..3753d19094 100644 --- a/meson.build +++ b/meson.build @@ -2174,6 +2174,9 @@ simple_tests = [] fuzzers = [] simple_fuzzers = [] catalogs = [] +modules = [] # nss, pam, and other plugins +executables = [] +executables_by_name = {} # binaries that have --help and are intended for use by humans, # usually, but not always, installed in /bin. @@ -2355,6 +2358,68 @@ endif ############################################################ +executable_template = { + 'include_directories' : includes, + 'link_with' : libshared, + 'install_rpath' : pkglibdir, + 'install' : true, +} + +generator_template = executable_template + { + 'install_dir' : systemgeneratordir, +} + +libexec_template = executable_template + { + 'install_dir' : libexecdir, +} + +executable_additional_kwargs = { + 'dependencies' : userspace, +} + +nss_template = { + 'version' : '2', + 'include_directories' : includes, + # Note that we link NSS modules with '-z nodelete' so that mempools never get orphaned + 'link_args' : ['-z', 'nodelete'], + 'link_with' : [ + libsystemd_static, + libshared_static, + libbasic, + ], + 'dependencies' : [ + librt, + threads, + ], + 'install' : true, + 'install_tag' : 'nss', + 'install_dir' : libdir, +} + +pam_template = { + 'name_prefix' : '', + 'include_directories' : includes, + 'link_with' : [ + libsystemd_static, + libshared_static, + ], + 'dependencies' : [ + libpam_misc, + libpam, + threads, + ], + 'install' : true, + 'install_tag' : 'pam', + 'install_dir' : pamlibdir, +} + +module_additional_kwargs = { + 'link_args' : ['-shared'], + 'dependencies' : userspace, +} + +############################################################ + # systemd-analyze requires 'libcore' subdir('src/core') # systemd-journal-remote requires 'libjournal_core' @@ -2407,6 +2472,51 @@ alias_target('devel', libsystemd_pc, libudev_pc, systemd_pc, udev_pc) ############################################################ +foreach dict : executables + name = dict.get('name') + + build = true + foreach cond : dict.get('conditions', []) + if conf.get(cond) != 1 + build = false + break + endif + endforeach + if not build + continue + endif + + kwargs = {} + foreach key, val : dict + if key in ['name', 'dbus', 'public', 'conditions'] + continue + endif + kwargs += { key : val } + endforeach + + foreach key, val : executable_additional_kwargs + kwargs += { key : [ kwargs.get(key, []), val ]} + endforeach + + exe = executable( + name, + kwargs : kwargs, + ) + + executables_by_name += { name : exe } + + if dict.get('build_by_default', true) + if dict.get('dbus', false) + dbus_programs += exe + endif + if dict.get('public', false) + public_programs += exe + endif + endif +endforeach + +############################################################ + # only static linking apart from libdl, to make sure that the # module is linked to all libraries that it uses. test_dlopen = executable( @@ -2477,6 +2587,62 @@ foreach tuple : [['myhostname', 'ENABLE_NSS_MYHOSTNAME'], endif endforeach +foreach dict : modules + name = dict.get('name') + is_nss = name.startswith('nss_') + is_pam = name.startswith('pam_') + + build = true + foreach cond : dict.get('conditions', []) + if conf.get(cond) != 1 + build = false + break + endif + endforeach + if not build + continue + endif + + kwargs = {} + foreach key, val : dict + if key in ['name', 'conditions'] + continue + endif + kwargs += { key : val } + endforeach + + sym = meson.current_source_dir() / '@0@'.format(dict.get('link_depends')[0]) + kwargs += { + 'link_args' : [ + kwargs.get('link_args', []), + '-Wl,--version-script=' + sym, + ], + } + foreach key, val : module_additional_kwargs + kwargs += { key : [ kwargs.get(key, []), val ]} + endforeach + + lib = shared_library( + name, + kwargs : kwargs, + ) + + if is_nss + # We cannot use shared_module because it does not support version suffix. + # Unfortunately shared_library insists on creating the symlink… + meson.add_install_script('sh', '-c', 'rm $DESTDIR@0@/lib@1@.so'.format(libdir, name), + install_tag : 'nss') + endif + + if want_tests != 'false' and (is_nss or is_pam) + test('dlopen-' + name, + test_dlopen, + # path to dlopen must include a slash + args : lib.full_path(), + depends : lib) + endif +endforeach + ############################################################ exe = executable( From 07e43306b365150a07a5637786a2514ed3f711f4 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Fri, 23 Jun 2023 11:21:40 +0900 Subject: [PATCH 3/5] meson: move declaration of cryptsetup token modules --- meson.build | 57 -------------------- src/cryptsetup/cryptsetup-tokens/meson.build | 54 +++++++++++++++++-- src/cryptsetup/meson.build | 2 + 3 files changed, 53 insertions(+), 60 deletions(-) diff --git a/meson.build b/meson.build index 3753d19094..48fda2a225 100644 --- a/meson.build +++ b/meson.build @@ -2215,7 +2215,6 @@ subdir('src/libsystemd') subdir('src/shared') subdir('src/udev') subdir('src/libudev') -subdir('src/cryptsetup/cryptsetup-tokens') libsystemd = shared_library( 'systemd', @@ -2300,62 +2299,6 @@ install_libudev_static = static_library( c_args : static_libudev_pic ? [] : ['-fno-PIC'], pic : static_libudev_pic) -if conf.get('HAVE_LIBCRYPTSETUP_PLUGINS') == 1 - if conf.get('HAVE_TPM2') == 1 - shared_library( - 'cryptsetup-token-systemd-tpm2', - cryptsetup_token_systemd_tpm2_sources, - include_directories : includes, - link_args : ['-shared', - '-Wl,--version-script=' + cryptsetup_token_sym_path], - link_with : [lib_cryptsetup_token_common, - libshared], - dependencies : [libcryptsetup, - tpm2, - userspace], - link_depends : cryptsetup_token_sym, - install_rpath : pkglibdir, - install : true, - install_dir : libcryptsetup_plugins_dir) - endif - - if conf.get('HAVE_LIBFIDO2') == 1 - shared_library( - 'cryptsetup-token-systemd-fido2', - cryptsetup_token_systemd_fido2_sources, - include_directories : includes, - link_args : ['-shared', - '-Wl,--version-script=' + cryptsetup_token_sym_path], - link_with : [lib_cryptsetup_token_common, - libshared], - dependencies : [libcryptsetup, - libfido2, - userspace], - link_depends : cryptsetup_token_sym, - install_rpath : pkglibdir, - install : true, - install_dir : libcryptsetup_plugins_dir) - endif - - if conf.get('HAVE_P11KIT') == 1 - shared_library( - 'cryptsetup-token-systemd-pkcs11', - cryptsetup_token_systemd_pkcs11_sources, - include_directories : includes, - link_args : ['-shared', - '-Wl,--version-script=' + cryptsetup_token_sym_path], - link_with : [lib_cryptsetup_token_common, - libshared], - dependencies : [libcryptsetup, - libp11kit, - userspace], - link_depends : cryptsetup_token_sym, - install_rpath : pkglibdir, - install : true, - install_dir : libcryptsetup_plugins_dir) - endif -endif - ############################################################ executable_template = { diff --git a/src/cryptsetup/cryptsetup-tokens/meson.build b/src/cryptsetup/cryptsetup-tokens/meson.build index e7b7fbab11..120621eaee 100644 --- a/src/cryptsetup/cryptsetup-tokens/meson.build +++ b/src/cryptsetup/cryptsetup-tokens/meson.build @@ -1,8 +1,5 @@ # SPDX-License-Identifier: LGPL-2.1-or-later -cryptsetup_token_sym = files('cryptsetup-token.sym') -cryptsetup_token_sym_path = meson.current_source_dir() / 'cryptsetup-token.sym' - lib_cryptsetup_token_common = static_library( 'cryptsetup-token-common', 'cryptsetup-token-util.c', @@ -25,3 +22,54 @@ cryptsetup_token_systemd_pkcs11_sources = files( 'cryptsetup-token-systemd-pkcs11.c', 'luks2-pkcs11.c', ) + +template = { + 'include_directories' : includes, + 'link_with' : [ + lib_cryptsetup_token_common, + libshared, + ], + 'link_depends' : files('cryptsetup-token.sym'), + 'install_rpath' : pkglibdir, + 'install' : true, + 'install_dir' : libcryptsetup_plugins_dir, +} + +modules += [ + template + { + 'name' : 'cryptsetup-token-systemd-tpm2', + 'conditions' : [ + 'HAVE_LIBCRYPTSETUP_PLUGINS', + 'HAVE_TPM2', + ], + 'sources' : cryptsetup_token_systemd_tpm2_sources, + 'dependencies' : [ + libcryptsetup, + tpm2, + ], + }, + template + { + 'name' : 'cryptsetup-token-systemd-fido2', + 'conditions' : [ + 'HAVE_LIBCRYPTSETUP_PLUGINS', + 'HAVE_LIBFIDO2', + ], + 'sources' : cryptsetup_token_systemd_fido2_sources, + 'dependencies' : [ + libcryptsetup, + libfido2, + ], + }, + template + { + 'name' : 'cryptsetup-token-systemd-pkcs11', + 'conditions' : [ + 'HAVE_LIBCRYPTSETUP_PLUGINS', + 'HAVE_P11KIT', + ], + 'sources' : cryptsetup_token_systemd_pkcs11_sources, + 'dependencies' : [ + libcryptsetup, + libp11kit, + ], + }, +] diff --git a/src/cryptsetup/meson.build b/src/cryptsetup/meson.build index 45c4154c95..2a8e43a33a 100644 --- a/src/cryptsetup/meson.build +++ b/src/cryptsetup/meson.build @@ -1,5 +1,7 @@ # SPDX-License-Identifier: LGPL-2.1-or-later +subdir('cryptsetup-tokens') + systemd_cryptsetup_sources = files( 'cryptsetup-keyfile.c', 'cryptsetup.c', From 2080c0978d90e1d5989b091df1f3be3926384bd4 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Fri, 23 Jun 2023 11:28:22 +0900 Subject: [PATCH 4/5] meson: move declarations of nss modules --- meson.build | 63 +++------------------------------- src/nss-myhostname/meson.build | 10 ++++++ src/nss-mymachines/meson.build | 10 ++++++ src/nss-resolve/meson.build | 12 +++++++ src/nss-systemd/meson.build | 13 +++++++ 5 files changed, 49 insertions(+), 59 deletions(-) create mode 100644 src/nss-myhostname/meson.build create mode 100644 src/nss-mymachines/meson.build create mode 100644 src/nss-resolve/meson.build create mode 100644 src/nss-systemd/meson.build diff --git a/meson.build b/meson.build index 48fda2a225..bd62198ef0 100644 --- a/meson.build +++ b/meson.build @@ -2387,6 +2387,10 @@ subdir('src/login') subdir('src/machine') subdir('src/network') subdir('src/nspawn') +subdir('src/nss-myhostname') +subdir('src/nss-mymachines') +subdir('src/nss-resolve') +subdir('src/nss-systemd') subdir('src/oom') subdir('src/partition') subdir('src/portable') @@ -2471,65 +2475,6 @@ test_dlopen = executable( userspace], build_by_default : want_tests != 'false') -foreach tuple : [['myhostname', 'ENABLE_NSS_MYHOSTNAME'], - ['systemd', 'ENABLE_NSS_SYSTEMD', ['nss-systemd.h', 'userdb-glue.c', 'userdb-glue.h']], - ['mymachines', 'ENABLE_NSS_MYMACHINES'], - ['resolve', 'ENABLE_NSS_RESOLVE', [], resolve_includes]] - - condition = tuple[1] == '' or conf.get(tuple[1]) == 1 - if condition - module = tuple[0] - - sym = 'src/nss-@0@/nss-@0@.sym'.format(module) - version_script_arg = project_source_root / sym - - sources = ['src/nss-@0@/nss-@0@.c'.format(module)] - if tuple.length() > 2 - foreach s : tuple[2] - sources += ['src/nss-@0@/@1@'.format(module, s)] - endforeach - endif - - incs = tuple.length() > 3 ? tuple[3] : includes - - nss = shared_library( - 'nss_' + module, - sources, - version : '2', - include_directories : incs, - # Note that we link NSS modules with '-z nodelete' so that mempools never get orphaned - link_args : ['-Wl,-z,nodelete', - '-shared', - '-Wl,--version-script=' + version_script_arg], - link_with : [libsystemd_static, - libshared_static, - libbasic], - dependencies : [librt, - threads, - userspace], - link_depends : sym, - install : true, - install_tag : 'nss', - install_dir : libdir) - - # We cannot use shared_module because it does not support version suffix. - # Unfortunately shared_library insists on creating the symlink… - meson.add_install_script('sh', '-c', - 'rm $DESTDIR@0@/libnss_@1@.so' - .format(libdir, module), - install_tag : 'nss' - ) - - if want_tests != 'false' - test('dlopen-nss_' + module, - test_dlopen, - # path to dlopen must include a slash - args : nss.full_path(), - depends : nss) - endif - endif -endforeach - foreach dict : modules name = dict.get('name') is_nss = name.startswith('nss_') diff --git a/src/nss-myhostname/meson.build b/src/nss-myhostname/meson.build new file mode 100644 index 0000000000..c53ab22dbc --- /dev/null +++ b/src/nss-myhostname/meson.build @@ -0,0 +1,10 @@ +# SPDX-License-Identifier: LGPL-2.1-or-later + +modules += [ + nss_template + { + 'name' : 'nss_myhostname', + 'conditions' : ['ENABLE_NSS_MYHOSTNAME'], + 'sources' : files('nss-myhostname.c'), + 'link_depends' : files('nss-myhostname.sym'), + }, +] diff --git a/src/nss-mymachines/meson.build b/src/nss-mymachines/meson.build new file mode 100644 index 0000000000..7b8198fe37 --- /dev/null +++ b/src/nss-mymachines/meson.build @@ -0,0 +1,10 @@ +# SPDX-License-Identifier: LGPL-2.1-or-later + +modules += [ + nss_template + { + 'name' : 'nss_mymachines', + 'conditions' : ['ENABLE_NSS_MYMACHINES'], + 'sources' : files('nss-mymachines.c'), + 'link_depends' : files('nss-mymachines.sym'), + }, +] diff --git a/src/nss-resolve/meson.build b/src/nss-resolve/meson.build new file mode 100644 index 0000000000..e5b65d256a --- /dev/null +++ b/src/nss-resolve/meson.build @@ -0,0 +1,12 @@ +# SPDX-License-Identifier: LGPL-2.1-or-later + +modules += [ + nss_template + { + 'name' : 'nss_resolve', + 'conditions' : ['ENABLE_NSS_RESOLVE'], + 'sources' : files('nss-resolve.c'), + 'link_depends' : files('nss-resolve.sym'), + 'include_directories' : includes + + include_directories('../resolve'), + }, +] diff --git a/src/nss-systemd/meson.build b/src/nss-systemd/meson.build new file mode 100644 index 0000000000..1bea17156e --- /dev/null +++ b/src/nss-systemd/meson.build @@ -0,0 +1,13 @@ +# SPDX-License-Identifier: LGPL-2.1-or-later + +modules += [ + nss_template + { + 'name' : 'nss_systemd', + 'conditions' : ['ENABLE_NSS_SYSTEMD'], + 'sources' : files( + 'nss-systemd.c', + 'userdb-glue.c', + ), + 'link_depends' : files('nss-systemd.sym'), + }, +] From 6d06af80d008c78e132daaaa075599a5b0995567 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Sun, 25 Jun 2023 15:13:25 +0900 Subject: [PATCH 5/5] meson: move declaration of PID1 --- meson.build | 18 ------------------ src/core/meson.build | 18 ++++++++++++++++++ 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/meson.build b/meson.build index bd62198ef0..4b68ccfedd 100644 --- a/meson.build +++ b/meson.build @@ -2533,24 +2533,6 @@ endforeach ############################################################ -exe = executable( - 'systemd', - systemd_sources, - include_directories : includes, - link_with : [libcore, - libshared], - dependencies : [libseccomp, - userspace], - install_rpath : pkglibdir, - install : true, - install_dir : libexecdir) -dbus_programs += exe -public_programs += exe - -meson.add_install_script(meson_make_symlink, - libexecdir / 'systemd', - sbindir / 'init') - exe = executable( 'systemd-analyze', systemd_analyze_sources, diff --git a/src/core/meson.build b/src/core/meson.build index c3a45dc3b1..9f04a9e019 100644 --- a/src/core/meson.build +++ b/src/core/meson.build @@ -141,6 +141,20 @@ systemd_sources = files( 'crash-handler.c', ) +executables += [ + libexec_template + { + 'name' : 'systemd', + 'dbus' : true, + 'public' : true, + 'sources' : systemd_sources, + 'link_with' : [ + libcore, + libshared, + ], + 'dependencies' : libseccomp, + }, +] + in_files = [['system.conf', pkgsysconfdir], ['user.conf', pkgsysconfdir], ['org.freedesktop.systemd1.policy', polkitpolicydir]] @@ -183,6 +197,10 @@ if install_sysconfdir meson.add_install_script('sh', '-c', mkdir_p.format(sysconfdir / 'xdg/systemd')) endif +meson.add_install_script(meson_make_symlink, + libexecdir / 'systemd', + sbindir / 'init') + ############################################################ test_core_base = {