lix-rs: link cpp also when building tests

Co-authored-by: eldritch horrors <pennae@lix.systems>
Change-Id: I656a2f1b6999395c421f9a5b301b324c77f8ac52
This commit is contained in:
rootile
2026-07-17 10:27:39 +00:00
committed by Rutile
co-authored by eldritch horrors
parent 4c4d8b8ccd
commit ece46d54c7
7 changed files with 81 additions and 16 deletions
Generated
+7
View File
@@ -451,6 +451,7 @@ name = "lix"
version = "0.0.0"
dependencies = [
"lix-doc",
"pkg-config",
"regex",
"rootcause",
"rustyline",
@@ -568,6 +569,12 @@ version = "2.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9b4f627cb1b25917193a259e49bdad08f671f8d9708acfd5fe0a8c1455d87220"
[[package]]
name = "pkg-config"
version = "0.3.33"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "19f132c84eca552bf34cab8ec81f1c1dcc229b811638f9d283dceabe58c5569e"
[[package]]
name = "proc-macro2"
version = "1.0.106"
+1
View File
@@ -17,6 +17,7 @@ rustyline = "18"
rustyline-derive = "0.12"
syn = "2.0"
zngur = "0.10"
pkg-config = "0.3.33"
[profile.dev]
opt-level = 1
+6
View File
@@ -56,6 +56,12 @@ test-integration *OPTIONS: (test "--suite" "installcheck" OPTIONS)
test-functional2 *OPTIONS:
cd tests/functional2 && python -m pytest -v "$@"
# special target for cargo because meson cannot be convinced to not mangle cargo test output,
# and getting properly colored test output any other way also doesn't look all that possible.
[positional-arguments]
test-rs *OPTIONS:
meson test -C {{ builddir }} --interactive lix-rs-tests "$@"
# Lint with `clang-tidy`
lint:
ninja -C build clang-tidy
+1
View File
@@ -19,3 +19,4 @@ rustyline-derive.workspace = true
[build-dependencies]
zngur.workspace = true
pkg-config.workspace = true
+30
View File
@@ -13,4 +13,34 @@ fn main() {
.expect("read main.zng.rs"),
)
.expect("write generated.rs");
println!("cargo::rerun-if-env-changed=CXX_LINK_DIR_FOR_TEST");
if let Some(dir) = env::var("CXX_LINK_DIR_FOR_TEST").ok() {
println!("cargo::rustc-link-search={}", dir);
println!("cargo::rustc-link-lib=static=lix_cpp_static");
}
// pull link args for each dependency we'll need to fully link.
println!("cargo::rerun-if-env-changed=CXX_LINK_LIBS_FOR_TEST");
for dep in env::var("CXX_LINK_LIBS_FOR_TEST")
.ok()
.into_iter()
.flat_map(|s| s.split(':').map(|s| s.to_string()).collect::<Vec<_>>())
{
// meson has already checked that everything we need exists
let _ = pkg_config::probe_library(&dep);
}
// explicitly pass sanitizer args. we can't use -Zsanitizer or -Zexternal-clangrt
// even with RUSTC_BOOTSTRAP because that will confuse the hell out of dependency
// crate tests when they're run. since we only need this for our own tests we can
// be quite careless about unnecessary dependencies, so just splat all arguments.
println!("cargo::rerun-if-env-changed=CXX_TEST_SANITIZERS");
for arg in env::var("CXX_TEST_SANITIZERS")
.ok()
.iter()
.flat_map(|s| s.split(':'))
{
println!("cargo::rustc-link-arg={arg}");
}
}
+28 -16
View File
@@ -176,22 +176,6 @@ lixrs = custom_target(
env : lixrs_cargo_env,
)
if meson.can_run_host_binaries()
test(
'lix-rs-tests',
cargo,
args : [
'test',
'--all', '--all-targets',
'--no-fail-fast',
cargo_jobs_args,
],
suite : 'check',
env : lixrs_cargo_env,
timeout : 300,
)
endif
liblix_cpp_static = static_library(
'lix_cpp_static',
liblix_sources,
@@ -204,6 +188,34 @@ liblix_cpp_static = static_library(
cpp_pch : cpp_pch,
)
if meson.can_run_host_binaries()
lixrs_test_deps = []
foreach dep : dependencies.flatten()
lixrs_test_deps += dep.name()
endforeach
test(
'lix-rs-tests',
cargo,
args : [
'test',
'--all', '--all-targets',
'--no-fail-fast',
cargo_jobs_args,
],
depends : [
liblix_cpp_static,
],
suite : 'check',
env : lixrs_cargo_env + {
'CXX_LINK_DIR_FOR_TEST': meson.current_build_dir(),
'CXX_LINK_LIBS_FOR_TEST': lixrs_test_deps,
'CXX_TEST_SANITIZERS': cargo_sanitizer_args,
},
timeout : 300,
)
endif
if is_darwin
lixrs_link_args = [ '-Wl,-force_load,lix/liblixrs.a' ]
else
+8
View File
@@ -687,6 +687,9 @@ add_project_arguments(
language : 'cpp',
)
sanitize_args = []
cargo_sanitizer_args = []
# 2024-03-24: jade benchmarked the default sanitize reporting in clang and got
# a regression of about 10% on hackage-packages.nix with clang. So if the
# signed-integer-overflow sanitizer is requested (our default), we trap instead.
@@ -703,6 +706,11 @@ endif
# GCC defaults to shared libsan so is fine.
if cxx.get_id() == 'clang' and get_option('b_sanitize') != ''
add_project_link_arguments('-shared-libsan', language : 'cpp')
cargo_sanitizer_args = [
'-shared-libsan',
'-fsanitize=' + get_option('b_sanitize'),
sanitize_args,
]
endif
# Clang gets grumpy about missing libasan symbols if -shared-libasan is not