@@ -661,14 +661,17 @@ fn phase_cargo_miri(mut args: env::Args) {
661
661
) ;
662
662
}
663
663
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`.
666
665
if env:: var_os ( "RUSTC" ) . is_some ( ) && env:: var_os ( "MIRI" ) . is_none ( ) {
667
666
println ! (
668
667
"WARNING: Ignoring `RUSTC` environment variable; set `MIRI` if you want to control the binary used as the driver."
669
668
) ;
670
669
}
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 ( ) ) ;
672
675
673
676
let runner_env_name =
674
677
|triple : & str | format ! ( "CARGO_TARGET_{}_RUNNER" , triple. to_uppercase( ) . replace( '-' , "_" ) ) ;
@@ -1173,8 +1176,14 @@ fn main() {
1173
1176
1174
1177
match args. next ( ) . as_deref ( ) {
1175
1178
Some ( "miri" ) => phase_cargo_miri ( args) ,
1176
- Some ( "rustc" ) => phase_rustc ( args, RustcPhase :: Build ) ,
1177
1179
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
+ }
1178
1187
// We have to distinguish the "runner" and "rustdoc" cases.
1179
1188
// As runner, the first argument is the binary (a file that should exist, with an absolute path);
1180
1189
// as rustdoc, the first argument is a flag (`--something`).
0 commit comments