Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 800273c

Browse files
committed
cargo-miri: set RUSTC to us
1 parent 3800933 commit 800273c

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

cargo-miri/bin.rs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -661,14 +661,17 @@ fn phase_cargo_miri(mut args: env::Args) {
661661
);
662662
}
663663
cmd.env("RUSTC_WRAPPER", &cargo_miri_path);
664-
// Having both `RUSTC_WRAPPER` and `RUSTC` set does some odd things, so let's avoid that.
665-
// See <https://github.com/rust-lang/miri/issues/2238>.
664+
// We are going to invoke `MIRI` for everything, not `RUSTC`.
666665
if env::var_os("RUSTC").is_some() && env::var_os("MIRI").is_none() {
667666
println!(
668667
"WARNING: Ignoring `RUSTC` environment variable; set `MIRI` if you want to control the binary used as the driver."
669668
);
670669
}
671-
cmd.env_remove("RUSTC");
670+
// We'd prefer to just clear this env var, but cargo does not always honor `RUSTC_WRAPPER`
671+
// (https://github.com/rust-lang/cargo/issues/10885). There is no good way to single out these invocations;
672+
// some build scripts use the RUSTC env var as well. So we set it directly to the `miri` driver and
673+
// hope that all they do is ask for the version number -- things could quickly go downhill from here.
674+
cmd.env("RUSTC", &find_miri());
672675

673676
let runner_env_name =
674677
|triple: &str| format!("CARGO_TARGET_{}_RUNNER", triple.to_uppercase().replace('-', "_"));
@@ -1173,8 +1176,14 @@ fn main() {
11731176

11741177
match args.next().as_deref() {
11751178
Some("miri") => phase_cargo_miri(args),
1176-
Some("rustc") => phase_rustc(args, RustcPhase::Build),
11771179
Some(arg) => {
1180+
// If the first arg is equal to the RUSTC variable (which should be set at this point),
1181+
// then we need to behave as rustc. This is the somewhat counter-intuitive behavior of
1182+
// having both RUSTC and RUSTC_WRAPPER set (see
1183+
// https://github.com/rust-lang/cargo/issues/10886).
1184+
if arg == env::var_os("RUSTC").unwrap() {
1185+
return phase_rustc(args, RustcPhase::Build);
1186+
}
11781187
// We have to distinguish the "runner" and "rustdoc" cases.
11791188
// As runner, the first argument is the binary (a file that should exist, with an absolute path);
11801189
// as rustdoc, the first argument is a flag (`--something`).

0 commit comments

Comments
 (0)