From a8658fe0ccbefc68be96058bf2c8d8c08f25fdc9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Kr=C3=B6ning?= Date: Fri, 11 Oct 2024 10:13:22 +0200 Subject: [PATCH] fix(build.rs): keep `CARGO_HOME` and `RUSTUP_HOME` MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Martin Kröning --- rftrace/build.rs | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/rftrace/build.rs b/rftrace/build.rs index 15f0a5a..b560168 100755 --- a/rftrace/build.rs +++ b/rftrace/build.rs @@ -90,9 +90,13 @@ fn main() { /// Returns the Rustup proxy for Cargo. // Adapted from Hermit. -fn cargo() -> Command { - let cargo = { - let exe = format!("cargo{}", env::consts::EXE_SUFFIX); +pub fn cargo() -> Command { + sanitize("cargo") +} + +fn sanitize(cmd: &str) -> Command { + let cmd = { + let exe = format!("{cmd}{}", env::consts::EXE_SUFFIX); // On windows, the userspace toolchain ends up in front of the rustup proxy in $PATH. // To reach the rustup proxy nonetheless, we explicitly query $CARGO_HOME. let mut cargo_home = PathBuf::from(env::var_os("CARGO_HOME").unwrap()); @@ -105,17 +109,22 @@ fn cargo() -> Command { } }; - let mut cargo = Command::new(cargo); + let mut cmd = Command::new(cmd); + + cmd.current_dir(env::var_os("CARGO_MANIFEST_DIR").unwrap()); // Remove rust-toolchain-specific environment variables from kernel cargo - cargo.env_remove("LD_LIBRARY_PATH"); + cmd.env_remove("LD_LIBRARY_PATH"); env::vars() - .filter(|(key, _value)| key.starts_with("CARGO") || key.starts_with("RUST")) + .filter(|(key, _value)| { + key.starts_with("CARGO") && !key.starts_with("CARGO_HOME") + || key.starts_with("RUST") && !key.starts_with("RUSTUP_HOME") + }) .for_each(|(key, _value)| { - cargo.env_remove(&key); + cmd.env_remove(&key); }); - cargo + cmd } /// Makes all internal symbols private to avoid duplicated symbols.