@@ -475,6 +475,9 @@ impl Step for Miri {
475475 let stage = self . stage ;
476476 let host = self . host ;
477477 let compiler = builder. compiler ( stage, host) ;
478+ // We need the stdlib for the *next* stage, as it was built with this compiler that also built Miri.
479+ // Except if we are at stage 2, the bootstrap loop is complete and we can stick with our current stage.
480+ let compiler_std = builder. compiler ( if stage < 2 { stage + 1 } else { stage } , host) ;
478481
479482 let miri =
480483 builder. ensure ( tool:: Miri { compiler, target : self . host , extra_features : Vec :: new ( ) } ) ;
@@ -483,6 +486,10 @@ impl Step for Miri {
483486 target : self . host ,
484487 extra_features : Vec :: new ( ) ,
485488 } ) ;
489+ // The stdlib we need might be at a different stage. And just asking for the
490+ // sysroot does not seem to populate it, so we do that first.
491+ builder. ensure ( compile:: Std :: new ( compiler_std, host) ) ;
492+ let sysroot = builder. sysroot ( compiler_std) ;
486493 if let ( Some ( miri) , Some ( _cargo_miri) ) = ( miri, cargo_miri) {
487494 let mut cargo =
488495 builder. cargo ( compiler, Mode :: ToolRustc , SourceType :: Submodule , host, "install" ) ;
@@ -562,6 +569,7 @@ impl Step for Miri {
562569
563570 // miri tests need to know about the stage sysroot
564571 cargo. env ( "MIRI_SYSROOT" , miri_sysroot) ;
572+ cargo. env ( "MIRI_HOST_SYSROOT" , sysroot) ;
565573 cargo. env ( "RUSTC_LIB_PATH" , builder. rustc_libdir ( compiler) ) ;
566574 cargo. env ( "MIRI" , miri) ;
567575
0 commit comments