Skip to content

Commit

Permalink
fix(build.rs): keep CARGO_HOME and RUSTUP_HOME
Browse files Browse the repository at this point in the history
Signed-off-by: Martin Kröning <martin.kroening@eonerc.rwth-aachen.de>
  • Loading branch information
mkroening committed Oct 11, 2024
1 parent 72023fd commit a8658fe
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions rftrace/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand All @@ -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.
Expand Down

0 comments on commit a8658fe

Please sign in to comment.