Run the debug CLI without Cargo loader paths
Some checks failed
Weekly OSV dependency audit / dependency-audit (push) Failing after 6s
Some checks failed
Weekly OSV dependency audit / dependency-audit (push) Failing after 6s
- Add the Rust target library directory to the Linux debug CLI rpath - Test that the built CLI runs without `LD_LIBRARY_PATH`
This commit is contained in:
30
crates/bds-cli/build.rs
Normal file
30
crates/bds-cli/build.rs
Normal file
@@ -0,0 +1,30 @@
|
||||
use std::{env, process::Command};
|
||||
|
||||
fn main() {
|
||||
println!("cargo:rerun-if-env-changed=RUSTC");
|
||||
|
||||
if env::var("CARGO_CFG_TARGET_OS").as_deref() != Ok("linux")
|
||||
|| env::var("PROFILE").as_deref() != Ok("debug")
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
let rustc = env::var_os("RUSTC").unwrap_or_else(|| "rustc".into());
|
||||
let target = env::var("TARGET").expect("Cargo must provide the build target");
|
||||
let output = Command::new(rustc)
|
||||
.args(["--target", &target, "--print", "target-libdir"])
|
||||
.output()
|
||||
.expect("query Rust target library directory");
|
||||
assert!(
|
||||
output.status.success(),
|
||||
"rustc --print target-libdir failed: {}",
|
||||
String::from_utf8_lossy(&output.stderr)
|
||||
);
|
||||
let target_libdir =
|
||||
String::from_utf8(output.stdout).expect("Rust target library directory must be UTF-8");
|
||||
|
||||
println!(
|
||||
"cargo:rustc-link-arg-bin=bds-cli=-Wl,-rpath,{}",
|
||||
target_libdir.trim()
|
||||
);
|
||||
}
|
||||
@@ -8,6 +8,23 @@ fn cli(home: &std::path::Path, args: &[&str]) -> std::process::Output {
|
||||
.unwrap()
|
||||
}
|
||||
|
||||
#[cfg(target_os = "linux")]
|
||||
#[test]
|
||||
fn built_cli_runs_without_cargo_loader_paths() {
|
||||
let output = Command::new(env!("CARGO_BIN_EXE_bds-cli"))
|
||||
.env_remove("LD_LIBRARY_PATH")
|
||||
.arg("--help")
|
||||
.output()
|
||||
.unwrap();
|
||||
|
||||
assert!(
|
||||
output.status.success(),
|
||||
"{}",
|
||||
String::from_utf8_lossy(&output.stderr)
|
||||
);
|
||||
assert!(String::from_utf8_lossy(&output.stdout).contains("rebuild"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn process_exit_codes_help_and_shared_state_roundtrip() {
|
||||
let root = tempfile::tempdir().unwrap();
|
||||
|
||||
Reference in New Issue
Block a user