Skip to content

Commit 4655100

Browse files
authored
Merge pull request #41 from hermit-os/docker
fix(build.rs): keep `CARGO_HOME` and `RUSTUP_HOME`
2 parents a845cca + a8658fe commit 4655100

File tree

2 files changed

+20
-12
lines changed

2 files changed

+20
-12
lines changed

.github/workflows/ci.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ jobs:
1616
- uses: dtolnay/rust-toolchain@nightly
1717
with:
1818
components: rustfmt
19-
- run: cargo fmt -- --check
19+
- run: cargo fmt --all -- --check
2020

2121
c:
2222
name: C

rftrace/build.rs

+19-11
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
use std::collections::HashSet;
2-
use std::env;
3-
use std::fs;
42
use std::path::{Path, PathBuf};
53
use std::process::{Command, Stdio};
4+
use std::{env, fs};
65

76
fn build_backend() {
87
println!("Building Backend!");
@@ -85,15 +84,19 @@ fn main() {
8584
if env::var_os("CARGO_FEATURE_STATICLIB").is_some() {
8685
return;
8786
}
88-
87+
8988
build_backend();
9089
}
9190

9291
/// Returns the Rustup proxy for Cargo.
9392
// Adapted from Hermit.
94-
fn cargo() -> Command {
95-
let cargo = {
96-
let exe = format!("cargo{}", env::consts::EXE_SUFFIX);
93+
pub fn cargo() -> Command {
94+
sanitize("cargo")
95+
}
96+
97+
fn sanitize(cmd: &str) -> Command {
98+
let cmd = {
99+
let exe = format!("{cmd}{}", env::consts::EXE_SUFFIX);
97100
// On windows, the userspace toolchain ends up in front of the rustup proxy in $PATH.
98101
// To reach the rustup proxy nonetheless, we explicitly query $CARGO_HOME.
99102
let mut cargo_home = PathBuf::from(env::var_os("CARGO_HOME").unwrap());
@@ -106,17 +109,22 @@ fn cargo() -> Command {
106109
}
107110
};
108111

109-
let mut cargo = Command::new(cargo);
112+
let mut cmd = Command::new(cmd);
113+
114+
cmd.current_dir(env::var_os("CARGO_MANIFEST_DIR").unwrap());
110115

111116
// Remove rust-toolchain-specific environment variables from kernel cargo
112-
cargo.env_remove("LD_LIBRARY_PATH");
117+
cmd.env_remove("LD_LIBRARY_PATH");
113118
env::vars()
114-
.filter(|(key, _value)| key.starts_with("CARGO") || key.starts_with("RUST"))
119+
.filter(|(key, _value)| {
120+
key.starts_with("CARGO") && !key.starts_with("CARGO_HOME")
121+
|| key.starts_with("RUST") && !key.starts_with("RUSTUP_HOME")
122+
})
115123
.for_each(|(key, _value)| {
116-
cargo.env_remove(&key);
124+
cmd.env_remove(&key);
117125
});
118126

119-
cargo
127+
cmd
120128
}
121129

122130
/// Makes all internal symbols private to avoid duplicated symbols.

0 commit comments

Comments
 (0)