@@ -465,49 +465,20 @@ pub struct Miri {
465
465
target : TargetSelection ,
466
466
}
467
467
468
- impl Step for Miri {
469
- type Output = ( ) ;
470
- const ONLY_HOSTS : bool = false ;
471
-
472
- fn should_run ( run : ShouldRun < ' _ > ) -> ShouldRun < ' _ > {
473
- run. path ( "src/tools/miri" )
474
- }
475
-
476
- fn make_run ( run : RunConfig < ' _ > ) {
477
- run. builder . ensure ( Miri {
478
- stage : run. builder . top_stage ,
479
- host : run. build_triple ( ) ,
480
- target : run. target ,
481
- } ) ;
482
- }
483
-
484
- /// Runs `cargo test` for miri.
485
- fn run ( self , builder : & Builder < ' _ > ) {
486
- let stage = self . stage ;
487
- let host = self . host ;
488
- let target = self . target ;
489
- let compiler = builder. compiler ( stage, host) ;
490
- // We need the stdlib for the *next* stage, as it was built with this compiler that also built Miri.
491
- // Except if we are at stage 2, the bootstrap loop is complete and we can stick with our current stage.
492
- let compiler_std = builder. compiler ( if stage < 2 { stage + 1 } else { stage } , host) ;
493
-
494
- let miri = builder
495
- . ensure ( tool:: Miri { compiler, target : self . host , extra_features : Vec :: new ( ) } )
496
- . expect ( "in-tree tool" ) ;
497
- let _cargo_miri = builder
498
- . ensure ( tool:: CargoMiri { compiler, target : self . host , extra_features : Vec :: new ( ) } )
499
- . expect ( "in-tree tool" ) ;
500
- // The stdlib we need might be at a different stage. And just asking for the
501
- // sysroot does not seem to populate it, so we do that first.
502
- builder. ensure ( compile:: Std :: new ( compiler_std, host) ) ;
503
- let sysroot = builder. sysroot ( compiler_std) ;
504
-
505
- // # Run `cargo miri setup` for the given target.
468
+ impl Miri {
469
+ /// Run `cargo miri setup` for the given target, return where the Miri sysroot was put.
470
+ pub fn build_miri_sysroot (
471
+ builder : & Builder < ' _ > ,
472
+ compiler : Compiler ,
473
+ miri : & Path ,
474
+ target : TargetSelection ,
475
+ ) -> String {
476
+ let miri_sysroot = builder. out . join ( compiler. host . triple ) . join ( "miri-sysrot" ) ;
506
477
let mut cargo = tool:: prepare_tool_cargo (
507
478
builder,
508
479
compiler,
509
480
Mode :: ToolRustc ,
510
- host,
481
+ compiler . host ,
511
482
"run" ,
512
483
"src/tools/miri/cargo-miri" ,
513
484
SourceType :: InTree ,
@@ -521,6 +492,8 @@ impl Step for Miri {
521
492
cargo. env ( "MIRI_LIB_SRC" , builder. src . join ( "library" ) ) ;
522
493
// Tell it where to find Miri.
523
494
cargo. env ( "MIRI" , & miri) ;
495
+ // Tell it where to put the sysroot.
496
+ cargo. env ( "MIRI_SYSROOT" , & miri_sysroot) ;
524
497
// Debug things.
525
498
cargo. env ( "RUST_BACKTRACE" , "1" ) ;
526
499
@@ -535,7 +508,7 @@ impl Step for Miri {
535
508
cargo. arg ( "--print-sysroot" ) ;
536
509
537
510
// FIXME: Is there a way in which we can re-use the usual `run` helpers?
538
- let miri_sysroot = if builder. config . dry_run {
511
+ if builder. config . dry_run {
539
512
String :: new ( )
540
513
} else {
541
514
builder. verbose ( & format ! ( "running: {:?}" , cargo) ) ;
@@ -548,7 +521,48 @@ impl Step for Miri {
548
521
let sysroot = stdout. trim_end ( ) ;
549
522
builder. verbose ( & format ! ( "`cargo miri setup --print-sysroot` said: {:?}" , sysroot) ) ;
550
523
sysroot. to_owned ( )
551
- } ;
524
+ }
525
+ }
526
+ }
527
+
528
+ impl Step for Miri {
529
+ type Output = ( ) ;
530
+ const ONLY_HOSTS : bool = false ;
531
+
532
+ fn should_run ( run : ShouldRun < ' _ > ) -> ShouldRun < ' _ > {
533
+ run. path ( "src/tools/miri" )
534
+ }
535
+
536
+ fn make_run ( run : RunConfig < ' _ > ) {
537
+ run. builder . ensure ( Miri {
538
+ stage : run. builder . top_stage ,
539
+ host : run. build_triple ( ) ,
540
+ target : run. target ,
541
+ } ) ;
542
+ }
543
+
544
+ /// Runs `cargo test` for miri.
545
+ fn run ( self , builder : & Builder < ' _ > ) {
546
+ let stage = self . stage ;
547
+ let host = self . host ;
548
+ let target = self . target ;
549
+ let compiler = builder. compiler ( stage, host) ;
550
+ // We need the stdlib for the *next* stage, as it was built with this compiler that also built Miri.
551
+ // Except if we are at stage 2, the bootstrap loop is complete and we can stick with our current stage.
552
+ let compiler_std = builder. compiler ( if stage < 2 { stage + 1 } else { stage } , host) ;
553
+
554
+ let miri = builder
555
+ . ensure ( tool:: Miri { compiler, target : self . host , extra_features : Vec :: new ( ) } )
556
+ . expect ( "in-tree tool" ) ;
557
+ let _cargo_miri = builder
558
+ . ensure ( tool:: CargoMiri { compiler, target : self . host , extra_features : Vec :: new ( ) } )
559
+ . expect ( "in-tree tool" ) ;
560
+ // The stdlib we need might be at a different stage. And just asking for the
561
+ // sysroot does not seem to populate it, so we do that first.
562
+ builder. ensure ( compile:: Std :: new ( compiler_std, host) ) ;
563
+ let sysroot = builder. sysroot ( compiler_std) ;
564
+ // We also need a Miri sysroot.
565
+ let miri_sysroot = Miri :: build_miri_sysroot ( builder, compiler, & miri, target) ;
552
566
553
567
// # Run `cargo test`.
554
568
let mut cargo = tool:: prepare_tool_cargo (
@@ -566,7 +580,6 @@ impl Step for Miri {
566
580
// miri tests need to know about the stage sysroot
567
581
cargo. env ( "MIRI_SYSROOT" , & miri_sysroot) ;
568
582
cargo. env ( "MIRI_HOST_SYSROOT" , sysroot) ;
569
- cargo. env ( "RUSTC_LIB_PATH" , builder. rustc_libdir ( compiler) ) ;
570
583
cargo. env ( "MIRI" , & miri) ;
571
584
// propagate --bless
572
585
if builder. config . cmd . bless ( ) {
@@ -607,7 +620,6 @@ impl Step for Miri {
607
620
// Tell `cargo miri` where to find things.
608
621
cargo. env ( "MIRI_SYSROOT" , & miri_sysroot) ;
609
622
cargo. env ( "MIRI_HOST_SYSROOT" , sysroot) ;
610
- cargo. env ( "RUSTC_LIB_PATH" , builder. rustc_libdir ( compiler) ) ;
611
623
cargo. env ( "MIRI" , & miri) ;
612
624
// Debug things.
613
625
cargo. env ( "RUST_BACKTRACE" , "1" ) ;
0 commit comments