@@ -168,8 +168,6 @@ pub fn phase_cargo_miri(mut args: impl Iterator<Item = String>) {
168
168
// Forward all further arguments (not consumed by `ArgSplitFlagValue`) to cargo.
169
169
cmd. args ( args) ;
170
170
171
- // Let it know where the Miri sysroot lives.
172
- cmd. env ( "MIRI_SYSROOT" , miri_sysroot) ;
173
171
// Set `RUSTC_WRAPPER` to ourselves. Cargo will prepend that binary to its usual invocation,
174
172
// i.e., the first argument is `rustc` -- which is what we use in `main` to distinguish
175
173
// the two codepaths. (That extra argument is why we prefer this over setting `RUSTC`.)
@@ -196,10 +194,7 @@ pub fn phase_cargo_miri(mut args: impl Iterator<Item = String>) {
196
194
// always applied. However, buggy build scripts (https://github.com/eyre-rs/eyre/issues/84) and
197
195
// also cargo (https://github.com/rust-lang/cargo/issues/10885) will invoke `rustc` even when
198
196
// `RUSTC_WRAPPER` is set, bypassing the wrapper. To make sure everything is coherent, we want
199
- // that to be the Miri driver, but acting as rustc, on the target level. (Target, rather than
200
- // host, is needed for cross-interpretation situations.) This is not a perfect emulation of real
201
- // rustc (it might be unable to produce binaries since the sysroot is check-only), but it's as
202
- // close as we can get, and it's good enough for autocfg.
197
+ // that to be the Miri driver, but acting as rustc, on the target level.
203
198
//
204
199
// In `main`, we need the value of `RUSTC` to distinguish RUSTC_WRAPPER invocations from rustdoc
205
200
// or TARGET_RUNNER invocations, so we canonicalize it here to make it exceedingly unlikely that
@@ -208,14 +203,19 @@ pub fn phase_cargo_miri(mut args: impl Iterator<Item = String>) {
208
203
// bootstrap `rustc` thing in our way! Instead, we have MIRI_HOST_SYSROOT to use for host
209
204
// builds.
210
205
cmd. env ( "RUSTC" , fs:: canonicalize ( find_miri ( ) ) . unwrap ( ) ) ;
211
- cmd. env ( "MIRI_BE_RUSTC" , "target" ) ; // we better remember to *unset* this in the other phases!
206
+ // In case we get invoked as RUSTC without the wrapper, let's be a host rustc. This makes no
207
+ // sense for cross-interpretation situations, but without the wrapper, this will use the host
208
+ // sysroot, so asking it to behave like a target build makes even less sense.
209
+ cmd. env ( "MIRI_BE_RUSTC" , "host" ) ; // we better remember to *unset* this in the other phases!
212
210
213
211
// Set rustdoc to us as well, so we can run doctests.
214
212
if let Some ( orig_rustdoc) = env:: var_os ( "RUSTDOC" ) {
215
213
cmd. env ( "MIRI_ORIG_RUSTDOC" , orig_rustdoc) ;
216
214
}
217
215
cmd. env ( "RUSTDOC" , & cargo_miri_path) ;
218
216
217
+ // Forward some crucial information to our own re-invocations.
218
+ cmd. env ( "MIRI_SYSROOT" , miri_sysroot) ;
219
219
cmd. env ( "MIRI_LOCAL_CRATES" , local_crates ( & metadata) ) ;
220
220
if verbose > 0 {
221
221
cmd. env ( "MIRI_VERBOSE" , verbose. to_string ( ) ) ; // This makes the other phases verbose.
@@ -408,6 +408,8 @@ pub fn phase_rustc(mut args: impl Iterator<Item = String>, phase: RustcPhase) {
408
408
// Arguments are treated very differently depending on whether this crate is
409
409
// for interpretation by Miri, or for use by a build script / proc macro.
410
410
if target_crate {
411
+ // Set the sysroot.
412
+ cmd. arg ( "--sysroot" ) . arg ( env:: var_os ( "MIRI_SYSROOT" ) . unwrap ( ) ) ;
411
413
// Forward arguments, but remove "link" from "--emit" to make this a check-only build.
412
414
let emit_flag = "--emit" ;
413
415
while let Some ( arg) = args. next ( ) {
@@ -536,6 +538,12 @@ pub fn phase_runner(mut binary_args: impl Iterator<Item = String>, phase: Runner
536
538
cmd. env ( name, val) ;
537
539
}
538
540
541
+ if phase != RunnerPhase :: Rustdoc {
542
+ // Set the sysroot. Not necessary in rustdoc, where we already set the sysroot when invoking
543
+ // rustdoc itself, which will forward that flag when invoking rustc (i.e., us), so the flag
544
+ // is present in `info.args`.
545
+ cmd. arg ( "--sysroot" ) . arg ( env:: var_os ( "MIRI_SYSROOT" ) . unwrap ( ) ) ;
546
+ }
539
547
// Forward rustc arguments.
540
548
// We need to patch "--extern" filenames because we forced a check-only
541
549
// build without cargo knowing about that: replace `.rlib` suffix by
0 commit comments