mirror of
https://github.com/systemd/systemd.git
synced 2026-11-06 13:27:45 +00:00
meson: hand the config.h conditions to Rust code
C code uses #if HAVE_FOO and Rust code uses #[cfg(HAVE_FOO)]. Turn every HAVE_* and ENABLE_* key of config.h into a cfg that is set when the key is 1. All of them are declared with --check-cfg so a misspelled condition is reported instead of silently compiling the code out. Programs get them through the rust_executables template and the systemd_shared crate from the same list. Signed-off-by: Christian Brauner (Amutable) <brauner@kernel.org>
This commit is contained in:
1 parent
8d0c48fe98
commit
dddae0a7eb
2 files changed
+19
No files matched your search
@@ -2278,6 +2278,7 @@ if have_rust
|
||||
# Nothing from the crates is exported. The linker exports what a DSO in the link also defines,
|
||||
# and a stub of the crates would then preempt it for the libraries a program loads.
|
||||
'link_args' : ['-Wl,--exclude-libs,ALL'],
|
||||
'rust_args' : rust_cfg_args,
|
||||
}
|
||||
|
||||
rust_test_template = rust_executable_template + {
|
||||
|
||||
@@ -6,6 +6,23 @@ endif
|
||||
|
||||
rust = import('rust')
|
||||
|
||||
# The config.h conditions, so that Rust code says #[cfg(HAVE_FOO)] where C code says #if HAVE_FOO, and a
|
||||
# misspelled one is reported.
|
||||
rust_cfg_args = []
|
||||
foreach key : conf.keys()
|
||||
if key.startswith('HAVE_') or key.startswith('ENABLE_')
|
||||
rust_cfg_args += '--check-cfg=cfg(@0@)'.format(key)
|
||||
if '@0@'.format(conf.get(key)) == '1'
|
||||
rust_cfg_args += '--cfg=' + key
|
||||
endif
|
||||
endif
|
||||
endforeach
|
||||
# And the one C code gets from the compiler.
|
||||
rust_cfg_args += '--check-cfg=cfg(HAS_FEATURE_ADDRESS_SANITIZER)'
|
||||
if get_option('b_sanitize').contains('address')
|
||||
rust_cfg_args += '--cfg=HAS_FEATURE_ADDRESS_SANITIZER'
|
||||
endif
|
||||
|
||||
# Everything Rust code needs to use libsystemd-shared.
|
||||
shared_dep = declare_dependency(
|
||||
link_with : libshared,
|
||||
@@ -159,4 +176,5 @@ libsystemd_shared_rs = static_library(
|
||||
'systemd_shared',
|
||||
systemd_shared_sources,
|
||||
rust_abi : 'rust',
|
||||
rust_args : rust_cfg_args,
|
||||
link_with : [libsystemd_shared_sys])
|
||||
Reference in new issue
Block a user