diff --git a/meson.build b/meson.build index 585f484d2ce..db4219b6511 100644 --- a/meson.build +++ b/meson.build @@ -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 + { diff --git a/src/rust/systemd-shared/meson.build b/src/rust/systemd-shared/meson.build index eeb1ea09e7f..01dee171eda 100644 --- a/src/rust/systemd-shared/meson.build +++ b/src/rust/systemd-shared/meson.build @@ -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])