Skip to content

Commit

Permalink
Merge pull request #41 from hermit-os/docker
Browse files Browse the repository at this point in the history
fix(build.rs): keep `CARGO_HOME` and `RUSTUP_HOME`
  • Loading branch information
mkroening authored Oct 11, 2024
2 parents a845cca + a8658fe commit 4655100
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 12 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
- uses: dtolnay/rust-toolchain@nightly
with:
components: rustfmt
- run: cargo fmt -- --check
- run: cargo fmt --all -- --check

c:
name: C
Expand Down
30 changes: 19 additions & 11 deletions rftrace/build.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
use std::collections::HashSet;
use std::env;
use std::fs;
use std::path::{Path, PathBuf};
use std::process::{Command, Stdio};
use std::{env, fs};

fn build_backend() {
println!("Building Backend!");
Expand Down Expand Up @@ -85,15 +84,19 @@ fn main() {
if env::var_os("CARGO_FEATURE_STATICLIB").is_some() {
return;
}

build_backend();
}

/// 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 @@ -106,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 4655100

Please sign in to comment.