@@ -172,8 +172,6 @@ pub fn phase_cargo_miri(mut args: impl Iterator<Item = String>) {
172
172
// Forward all further arguments (not consumed by `ArgSplitFlagValue`) to cargo.
173
173
cmd. args ( args) ;
174
174
175
- // Let it know where the Miri sysroot lives.
176
- cmd. env ( "MIRI_SYSROOT" , miri_sysroot) ;
177
175
// Set `RUSTC_WRAPPER` to ourselves. Cargo will prepend that binary to its usual invocation,
178
176
// i.e., the first argument is `rustc` -- which is what we use in `main` to distinguish
179
177
// the two codepaths. (That extra argument is why we prefer this over setting `RUSTC`.)
@@ -200,10 +198,7 @@ pub fn phase_cargo_miri(mut args: impl Iterator<Item = String>) {
200
198
// always applied. However, buggy build scripts (https://github.com/eyre-rs/eyre/issues/84) and
201
199
// also cargo (https://github.com/rust-lang/cargo/issues/10885) will invoke `rustc` even when
202
200
// `RUSTC_WRAPPER` is set, bypassing the wrapper. To make sure everything is coherent, we want
203
- // that to be the Miri driver, but acting as rustc, on the target level. (Target, rather than
204
- // host, is needed for cross-interpretation situations.) This is not a perfect emulation of real
205
- // rustc (it might be unable to produce binaries since the sysroot is check-only), but it's as
206
- // close as we can get, and it's good enough for autocfg.
201
+ // that to be the Miri driver, but acting as rustc, in host mode.
207
202
//
208
203
// In `main`, we need the value of `RUSTC` to distinguish RUSTC_WRAPPER invocations from rustdoc
209
204
// or TARGET_RUNNER invocations, so we canonicalize it here to make it exceedingly unlikely that
@@ -212,14 +207,19 @@ pub fn phase_cargo_miri(mut args: impl Iterator<Item = String>) {
212
207
// bootstrap `rustc` thing in our way! Instead, we have MIRI_HOST_SYSROOT to use for host
213
208
// builds.
214
209
cmd. env ( "RUSTC" , fs:: canonicalize ( find_miri ( ) ) . unwrap ( ) ) ;
215
- cmd. env ( "MIRI_BE_RUSTC" , "target" ) ; // we better remember to *unset* this in the other phases!
210
+ // In case we get invoked as RUSTC without the wrapper, let's be a host rustc. This makes no
211
+ // sense for cross-interpretation situations, but without the wrapper, this will use the host
212
+ // sysroot, so asking it to behave like a target build makes even less sense.
213
+ cmd. env ( "MIRI_BE_RUSTC" , "host" ) ; // we better remember to *unset* this in the other phases!
216
214
217
215
// Set rustdoc to us as well, so we can run doctests.
218
216
if let Some ( orig_rustdoc) = env:: var_os ( "RUSTDOC" ) {
219
217
cmd. env ( "MIRI_ORIG_RUSTDOC" , orig_rustdoc) ;
220
218
}
221
219
cmd. env ( "RUSTDOC" , & cargo_miri_path) ;
222
220
221
+ // Forward some crucial information to our own re-invocations.
222
+ cmd. env ( "MIRI_SYSROOT" , miri_sysroot) ;
223
223
cmd. env ( "MIRI_LOCAL_CRATES" , local_crates ( & metadata) ) ;
224
224
if verbose > 0 {
225
225
cmd. env ( "MIRI_VERBOSE" , verbose. to_string ( ) ) ; // This makes the other phases verbose.
@@ -412,6 +412,12 @@ pub fn phase_rustc(mut args: impl Iterator<Item = String>, phase: RustcPhase) {
412
412
// Arguments are treated very differently depending on whether this crate is
413
413
// for interpretation by Miri, or for use by a build script / proc macro.
414
414
if target_crate {
415
+ if phase != RustcPhase :: Setup {
416
+ // Set the sysroot -- except during setup, where we don't have an existing sysroot yet
417
+ // and where the bootstrap wrapper adds its own `--sysroot` flag so we can't set ours.
418
+ cmd. arg ( "--sysroot" ) . arg ( env:: var_os ( "MIRI_SYSROOT" ) . unwrap ( ) ) ;
419
+ }
420
+
415
421
// Forward arguments, but patched.
416
422
let emit_flag = "--emit" ;
417
423
// This hack helps bootstrap run standard library tests in Miri. The issue is as follows:
@@ -574,6 +580,12 @@ pub fn phase_runner(mut binary_args: impl Iterator<Item = String>, phase: Runner
574
580
cmd. env ( name, val) ;
575
581
}
576
582
583
+ if phase != RunnerPhase :: Rustdoc {
584
+ // Set the sysroot. Not necessary in rustdoc, where we already set the sysroot in
585
+ // `phase_rustdoc`. rustdoc will forward that flag when invoking rustc (i.e., us), so the
586
+ // flag is present in `info.args`.
587
+ cmd. arg ( "--sysroot" ) . arg ( env:: var_os ( "MIRI_SYSROOT" ) . unwrap ( ) ) ;
588
+ }
577
589
// Forward rustc arguments.
578
590
// We need to patch "--extern" filenames because we forced a check-only
579
591
// build without cargo knowing about that: replace `.rlib` suffix by
0 commit comments