diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 20d51b4..cb84814 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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 diff --git a/rftrace/build.rs b/rftrace/build.rs index ffeb479..b560168 100755 --- a/rftrace/build.rs +++ b/rftrace/build.rs @@ -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!"); @@ -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()); @@ -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.