@@ -168,8 +168,6 @@ pub fn phase_cargo_miri(mut args: impl Iterator<Item = String>) {
168168 // Forward all further arguments (not consumed by `ArgSplitFlagValue`) to cargo.
169169 cmd. args ( args) ;
170170
171- // Let it know where the Miri sysroot lives.
172- cmd. env ( "MIRI_SYSROOT" , miri_sysroot) ;
173171 // Set `RUSTC_WRAPPER` to ourselves. Cargo will prepend that binary to its usual invocation,
174172 // i.e., the first argument is `rustc` -- which is what we use in `main` to distinguish
175173 // 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>) {
196194 // always applied. However, buggy build scripts (https://github.com/eyre-rs/eyre/issues/84) and
197195 // also cargo (https://github.com/rust-lang/cargo/issues/10885) will invoke `rustc` even when
198196 // `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.
203198 //
204199 // In `main`, we need the value of `RUSTC` to distinguish RUSTC_WRAPPER invocations from rustdoc
205200 // or TARGET_RUNNER invocations, so we canonicalize it here to make it exceedingly unlikely that
@@ -208,11 +203,16 @@ pub fn phase_cargo_miri(mut args: impl Iterator<Item = String>) {
208203 // bootstrap `rustc` thing in our way! Instead, we have MIRI_HOST_SYSROOT to use for host
209204 // builds.
210205 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!
212210
213211 // Set rustdoc to us as well, so we can run doctests.
214212 cmd. env ( "RUSTDOC" , & cargo_miri_path) ;
215213
214+ // Forward some crucial information to our own re-invocations.
215+ cmd. env ( "MIRI_SYSROOT" , miri_sysroot) ;
216216 cmd. env ( "MIRI_LOCAL_CRATES" , local_crates ( & metadata) ) ;
217217 if verbose > 0 {
218218 cmd. env ( "MIRI_VERBOSE" , verbose. to_string ( ) ) ; // This makes the other phases verbose.
@@ -410,6 +410,8 @@ pub fn phase_rustc(mut args: impl Iterator<Item = String>, phase: RustcPhase) {
410410 // Arguments are treated very differently depending on whether this crate is
411411 // for interpretation by Miri, or for use by a build script / proc macro.
412412 if target_crate {
413+ // Set the sysroot.
414+ cmd. arg ( "--sysroot" ) . arg ( env:: var_os ( "MIRI_SYSROOT" ) . unwrap ( ) ) ;
413415 // Forward arguments, but remove "link" from "--emit" to make this a check-only build.
414416 let emit_flag = "--emit" ;
415417 while let Some ( arg) = args. next ( ) {
@@ -543,6 +545,12 @@ pub fn phase_runner(mut binary_args: impl Iterator<Item = String>, phase: Runner
543545 cmd. env ( name, val) ;
544546 }
545547
548+ if phase != RunnerPhase :: Rustdoc {
549+ // Set the sysroot. Not necessary in rustdoc, where we already set the sysroot when invoking
550+ // rustdoc itself, which will forward that flag when invoking rustc (i.e., us), so the flag
551+ // is present in `info.args`.
552+ cmd. arg ( "--sysroot" ) . arg ( env:: var_os ( "MIRI_SYSROOT" ) . unwrap ( ) ) ;
553+ }
546554 // Forward rustc arguments.
547555 // We need to patch "--extern" filenames because we forced a check-only
548556 // build without cargo knowing about that: replace `.rlib` suffix by
0 commit comments