@@ -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`.)
@@ -204,6 +202,8 @@ pub fn phase_cargo_miri(mut args: impl Iterator<Item = String>) {
204202 // Set rustdoc to us as well, so we can run doctests.
205203 cmd. env ( "RUSTDOC" , & cargo_miri_path) ;
206204
205+ // Forward some crucial information to our own re-invocations.
206+ cmd. env ( "MIRI_SYSROOT" , miri_sysroot) ;
207207 cmd. env ( "MIRI_LOCAL_CRATES" , local_crates ( & metadata) ) ;
208208 if verbose > 0 {
209209 cmd. env ( "MIRI_VERBOSE" , verbose. to_string ( ) ) ; // This makes the other phases verbose.
@@ -393,6 +393,8 @@ pub fn phase_rustc(mut args: impl Iterator<Item = String>, phase: RustcPhase) {
393393 // Arguments are treated very differently depending on whether this crate is
394394 // for interpretation by Miri, or for use by a build script / proc macro.
395395 if !info_query && target_crate {
396+ // Set the sysroot.
397+ cmd. arg ( "--sysroot" ) . arg ( env:: var_os ( "MIRI_SYSROOT" ) . unwrap ( ) ) ;
396398 // Forward arguments, but remove "link" from "--emit" to make this a check-only build.
397399 let emit_flag = "--emit" ;
398400 while let Some ( arg) = args. next ( ) {
@@ -531,6 +533,12 @@ pub fn phase_runner(mut binary_args: impl Iterator<Item = String>, phase: Runner
531533 cmd. env ( name, val) ;
532534 }
533535
536+ if phase != RunnerPhase :: Rustdoc {
537+ // Set the sysroot. Not necessary in rustdoc, where we already set the sysroot when invoking
538+ // rustdoc itself, which will forward that flag when invoking rustc (i.e., us), so the flag
539+ // is present in `info.args`.
540+ cmd. arg ( "--sysroot" ) . arg ( env:: var_os ( "MIRI_SYSROOT" ) . unwrap ( ) ) ;
541+ }
534542 // Forward rustc arguments.
535543 // We need to patch "--extern" filenames because we forced a check-only
536544 // build without cargo knowing about that: replace `.rlib` suffix by
0 commit comments