Skip to content

Commit

Permalink
fix(xtask): properly use cargo proxy for foreign toolchains
Browse files Browse the repository at this point in the history
Signed-off-by: Martin Kröning <[email protected]>
  • Loading branch information
mkroening committed Apr 9, 2024
1 parent 9b89f2c commit 2239624
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 11 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,8 @@ jobs:
with:
components: rust-src
- uses: mkroening/rust-toolchain-toml@main
- run: rustup component add llvm-tools
working-directory: .
- uses: mkroening/rust-toolchain-toml@main
with:
toolchain-file: 'kernel/rust-toolchain.toml'
Expand Down
53 changes: 42 additions & 11 deletions xtask/src/ci/build.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use std::env;
use std::path::PathBuf;
use std::process::Command;

use anyhow::Result;
use clap::Args;
use xshell::cmd;

use crate::cargo_build::CargoBuild;

Expand All @@ -24,23 +25,25 @@ impl Build {
eprintln!("::group::cargo build")
}

let sh = crate::sh()?;
let mut cargo = cargo();

let _push_env = if self.package.contains("rftrace") {
Some(sh.push_env(
if self.package.contains("rftrace") {
cargo.env(
"RUSTFLAGS",
"-Zinstrument-mcount -Cpasses=ee-instrument<post-inline>",
))
} else {
None
);
};

sh.change_dir("..");
cmd!(sh, "cargo build")
cargo
.current_dir("..")
.arg("build")
.args(self.cargo_build.artifact.arch.ci_cargo_args())
.args(self.cargo_build.cargo_build_args())
.args(&["--package", self.package.as_str()])
.run()?;
.args(["--package", self.package.as_str()]);

eprintln!("$ {cargo:?}");
let status = cargo.status()?;
assert!(status.success());

if super::in_ci() {
eprintln!("::endgroup::")
Expand All @@ -53,3 +56,31 @@ impl Build {
self.cargo_build.artifact.ci_image(&self.package)
}
}

fn cargo() -> Command {
let cargo = {
let exe = format!("cargo{}", 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());
cargo_home.push("bin");
cargo_home.push(&exe);
if cargo_home.exists() {
cargo_home
} else {
PathBuf::from(exe)
}
};

let mut cargo = Command::new(cargo);

// Remove rust-toolchain-specific environment variables from kernel cargo
cargo.env_remove("LD_LIBRARY_PATH");
env::vars()
.filter(|(key, _value)| key.starts_with("CARGO") || key.starts_with("RUST"))
.for_each(|(key, _value)| {
cargo.env_remove(&key);
});

cargo
}

0 comments on commit 2239624

Please sign in to comment.