@@ -661,14 +661,20 @@ 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
+ // In `main`, we need the value of `RUSTC` to distinguish RUSTC_WRAPPER invocations from rustdoc
675
+ // or TARGET_RUNNER invocations, so we canonicalize it here to make it exceedingly unlikely that
676
+ // there would be a collision.
677
+ cmd. env ( "RUSTC" , & fs:: canonicalize ( find_miri ( ) ) . unwrap ( ) ) ;
672
678
673
679
let runner_env_name =
674
680
|triple : & str | format ! ( "CARGO_TARGET_{}_RUNNER" , triple. to_uppercase( ) . replace( '-' , "_" ) ) ;
@@ -814,10 +820,10 @@ fn phase_rustc(mut args: env::Args, phase: RustcPhase) {
814
820
815
821
if verbose > 0 {
816
822
eprintln ! (
817
- "[cargo-miri rustc] captured input:\n {}" ,
823
+ "[cargo-miri rustc inside rustdoc ] captured input:\n {}" ,
818
824
std:: str :: from_utf8( & env. stdin) . unwrap( )
819
825
) ;
820
- eprintln ! ( "[cargo-miri rustc] {:?}" , cmd) ;
826
+ eprintln ! ( "[cargo-miri rustc inside rustdoc] going to run: \n {:?}" , cmd) ;
821
827
}
822
828
823
829
exec_with_pipe ( cmd, & env. stdin ) ;
@@ -900,7 +906,10 @@ fn phase_rustc(mut args: env::Args, phase: RustcPhase) {
900
906
901
907
// Run it.
902
908
if verbose > 0 {
903
- eprint ! ( "[cargo-miri rustc] " ) ;
909
+ eprintln ! (
910
+ "[cargo-miri rustc] target_crate={target_crate} runnable_crate={runnable_crate} print={print}"
911
+ ) ;
912
+ eprintln ! ( "[cargo-miri rustc] going to run:" ) ;
904
913
if verbose > 1 {
905
914
for ( key, value) in env_vars_from_cmd ( & cmd) {
906
915
eprintln ! ( "{key}={value:?} \\ " ) ;
@@ -1173,8 +1182,14 @@ fn main() {
1173
1182
1174
1183
match args. next ( ) . as_deref ( ) {
1175
1184
Some ( "miri" ) => phase_cargo_miri ( args) ,
1176
- Some ( "rustc" ) => phase_rustc ( args, RustcPhase :: Build ) ,
1177
1185
Some ( arg) => {
1186
+ // If the first arg is equal to the RUSTC variable (which should be set at this point),
1187
+ // then we need to behave as rustc. This is the somewhat counter-intuitive behavior of
1188
+ // having both RUSTC and RUSTC_WRAPPER set (see
1189
+ // https://github.com/rust-lang/cargo/issues/10886).
1190
+ if arg == env:: var_os ( "RUSTC" ) . unwrap ( ) {
1191
+ return phase_rustc ( args, RustcPhase :: Build ) ;
1192
+ }
1178
1193
// We have to distinguish the "runner" and "rustdoc" cases.
1179
1194
// As runner, the first argument is the binary (a file that should exist, with an absolute path);
1180
1195
// as rustdoc, the first argument is a flag (`--something`).
0 commit comments