@@ -475,6 +475,9 @@ impl Step for Miri {
475
475
let stage = self . stage ;
476
476
let host = self . host ;
477
477
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) ;
478
481
479
482
let miri =
480
483
builder. ensure ( tool:: Miri { compiler, target : self . host , extra_features : Vec :: new ( ) } ) ;
@@ -483,6 +486,10 @@ impl Step for Miri {
483
486
target : self . host ,
484
487
extra_features : Vec :: new ( ) ,
485
488
} ) ;
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) ;
486
493
if let ( Some ( miri) , Some ( _cargo_miri) ) = ( miri, cargo_miri) {
487
494
let mut cargo =
488
495
builder. cargo ( compiler, Mode :: ToolRustc , SourceType :: Submodule , host, "install" ) ;
@@ -562,6 +569,7 @@ impl Step for Miri {
562
569
563
570
// miri tests need to know about the stage sysroot
564
571
cargo. env ( "MIRI_SYSROOT" , miri_sysroot) ;
572
+ cargo. env ( "MIRI_HOST_SYSROOT" , sysroot) ;
565
573
cargo. env ( "RUSTC_LIB_PATH" , builder. rustc_libdir ( compiler) ) ;
566
574
cargo. env ( "MIRI" , miri) ;
567
575
0 commit comments