@@ -493,21 +493,20 @@ impl Step for RustDemangler {
493
493
494
494
#[ derive( Debug , Clone , PartialEq , Eq , Hash ) ]
495
495
pub struct Miri {
496
- host : TargetSelection ,
497
496
target : TargetSelection ,
498
497
}
499
498
500
499
impl Miri {
501
500
/// Run `cargo miri setup` for the given target, return where the Miri sysroot was put.
502
501
pub fn build_miri_sysroot (
503
502
builder : & Builder < ' _ > ,
504
- compiler_std : Compiler ,
503
+ compiler : Compiler ,
505
504
target : TargetSelection ,
506
505
) -> String {
507
- let miri_sysroot = builder. out . join ( compiler_std . host . triple ) . join ( "miri-sysroot" ) ;
506
+ let miri_sysroot = builder. out . join ( compiler . host . triple ) . join ( "miri-sysroot" ) ;
508
507
let mut cargo = builder:: Cargo :: new (
509
508
builder,
510
- compiler_std , // this is compiler+1; cargo_miri_cmd will do -1 again
509
+ compiler,
511
510
Mode :: Std ,
512
511
SourceType :: Submodule ,
513
512
target,
@@ -520,13 +519,8 @@ impl Miri {
520
519
cargo. env ( "MIRI_SYSROOT" , & miri_sysroot) ;
521
520
522
521
let mut cargo = Command :: from ( cargo) ;
523
- let _guard = builder. msg (
524
- Kind :: Build ,
525
- compiler_std. stage ,
526
- "miri sysroot" ,
527
- compiler_std. host ,
528
- compiler_std. host ,
529
- ) ;
522
+ let _guard =
523
+ builder. msg ( Kind :: Build , compiler. stage , "miri sysroot" , compiler. host , target) ;
530
524
builder. run ( & mut cargo) ;
531
525
532
526
// # Determine where Miri put its sysroot.
@@ -563,34 +557,51 @@ impl Step for Miri {
563
557
}
564
558
565
559
fn make_run ( run : RunConfig < ' _ > ) {
566
- run. builder . ensure ( Miri { host : run . build_triple ( ) , target : run. target } ) ;
560
+ run. builder . ensure ( Miri { target : run. target } ) ;
567
561
}
568
562
569
563
/// Runs `cargo test` for miri.
570
564
fn run ( self , builder : & Builder < ' _ > ) {
571
- let stage = builder. top_stage ;
572
- let host = self . host ;
565
+ let host = builder. build . build ;
573
566
let target = self . target ;
574
- let compiler = builder. compiler ( stage, host) ;
575
- // We need the stdlib for the *next* stage, as it was built with this compiler that also built Miri.
576
- // Except if we are at stage 2, the bootstrap loop is complete and we can stick with our current stage.
577
- let compiler_std = builder. compiler ( if stage < 2 { stage + 1 } else { stage } , host) ;
578
-
579
- let miri =
580
- builder. ensure ( tool:: Miri { compiler, target : host, extra_features : Vec :: new ( ) } ) ;
567
+ let stage = builder. top_stage ;
568
+ if stage == 0 {
569
+ eprintln ! ( "miri cannot be tested at stage 0" ) ;
570
+ std:: process:: exit ( 1 ) ;
571
+ }
572
+
573
+ // This compiler runs on the host, we'll just use it for the target.
574
+ let target_compiler = builder. compiler ( stage, host) ;
575
+ // Similar to `compile::Assemble`, build with the previous stage's compiler. Otherwise
576
+ // we'd have stageN/bin/rustc and stageN/bin/rustdoc be effectively different stage
577
+ // compilers, which isn't what we want. Rustdoc should be linked in the same way as the
578
+ // rustc compiler it's paired with, so it must be built with the previous stage compiler.
579
+ let host_compiler = builder. compiler ( stage - 1 , host) ;
580
+
581
+ // Build our tools.
582
+ let miri = builder. ensure ( tool:: Miri {
583
+ compiler : host_compiler,
584
+ target : host,
585
+ extra_features : Vec :: new ( ) ,
586
+ } ) ;
581
587
// the ui tests also assume cargo-miri has been built
582
- builder. ensure ( tool:: CargoMiri { compiler, target : host, extra_features : Vec :: new ( ) } ) ;
583
- // The stdlib we need might be at a different stage. And just asking for the
584
- // sysroot does not seem to populate it, so we do that first.
585
- builder. ensure ( compile:: Std :: new ( compiler_std, host) ) ;
586
- let sysroot = builder. sysroot ( compiler_std) ;
587
- // We also need a Miri sysroot.
588
- let miri_sysroot = Miri :: build_miri_sysroot ( builder, compiler_std, target) ;
588
+ builder. ensure ( tool:: CargoMiri {
589
+ compiler : host_compiler,
590
+ target : host,
591
+ extra_features : Vec :: new ( ) ,
592
+ } ) ;
593
+
594
+ // We also need sysroots, for Miri and for the host (the latter for build scripts).
595
+ // This is for the tests so everything is done with the target compiler.
596
+ let miri_sysroot = Miri :: build_miri_sysroot ( builder, target_compiler, target) ;
597
+ builder. ensure ( compile:: Std :: new ( target_compiler, host) ) ;
598
+ let sysroot = builder. sysroot ( target_compiler) ;
589
599
590
600
// # Run `cargo test`.
601
+ // This is with the Miri crate, so it uses the host compiler.
591
602
let mut cargo = tool:: prepare_tool_cargo (
592
603
builder,
593
- compiler ,
604
+ host_compiler ,
594
605
Mode :: ToolRustc ,
595
606
host,
596
607
"test" ,
@@ -603,7 +614,7 @@ impl Step for Miri {
603
614
604
615
// We can NOT use `run_cargo_test` since Miri's integration tests do not use the usual test
605
616
// harness and therefore do not understand the flags added by `add_flags_and_try_run_test`.
606
- let mut cargo = prepare_cargo_test ( cargo, & [ ] , & [ ] , "miri" , compiler , target , builder) ;
617
+ let mut cargo = prepare_cargo_test ( cargo, & [ ] , & [ ] , "miri" , host_compiler , host , builder) ;
607
618
608
619
// miri tests need to know about the stage sysroot
609
620
cargo. env ( "MIRI_SYSROOT" , & miri_sysroot) ;
@@ -618,7 +629,7 @@ impl Step for Miri {
618
629
cargo. env ( "MIRI_TEST_TARGET" , target. rustc_target_arg ( ) ) ;
619
630
620
631
{
621
- let _guard = builder. msg_sysroot_tool ( Kind :: Test , compiler . stage , "miri" , host, target) ;
632
+ let _guard = builder. msg_sysroot_tool ( Kind :: Test , stage, "miri" , host, target) ;
622
633
let _time = helpers:: timeit ( builder) ;
623
634
builder. run ( & mut cargo) ;
624
635
}
@@ -636,7 +647,7 @@ impl Step for Miri {
636
647
{
637
648
let _guard = builder. msg_sysroot_tool (
638
649
Kind :: Test ,
639
- compiler . stage ,
650
+ stage,
640
651
"miri (mir-opt-level 4)" ,
641
652
host,
642
653
target,
@@ -650,10 +661,10 @@ impl Step for Miri {
650
661
// This is just a smoke test (Miri's own CI invokes this in a bunch of different ways and ensures
651
662
// that we get the desired output), but that is sufficient to make sure that the libtest harness
652
663
// itself executes properly under Miri, and that all the logic in `cargo-miri` does not explode.
653
- // Everything here needs `compiler_std` to be actually testing the Miri in the current stage .
664
+ // This is running the build `cargo-miri` for the given target, so we need the target compiler .
654
665
let mut cargo = tool:: prepare_tool_cargo (
655
666
builder,
656
- compiler_std , // this is compiler+1; cargo_miri_cmd will do -1 again
667
+ target_compiler ,
657
668
Mode :: ToolStd , // it's unclear what to use here, we're not building anything just doing a smoke test!
658
669
target,
659
670
"miri-test" ,
@@ -662,16 +673,12 @@ impl Step for Miri {
662
673
& [ ] ,
663
674
) ;
664
675
665
- // `prepare_tool_cargo` sets RUSTDOC to the bootstrap wrapper and RUSTDOC_REAL to a dummy path as this is a "miri", not a "test".
666
- // Also, we want the rustdoc from the "next" stage for the same reason that we build a std from the next stage.
667
- // So let's just set that here, and bypass bootstrap's RUSTDOC (just like cargo-miri already ignores bootstrap's RUSTC_WRAPPER).
668
- if builder. doc_tests != DocTests :: No {
669
- cargo. env ( "RUSTDOC" , builder. rustdoc ( compiler_std) ) ;
670
- }
676
+ // We're not using `prepare_cargo_test` so we have to do this ourselves.
677
+ // (We're not using that as the test-cargo-miri crate is not known to bootstrap.)
671
678
match builder. doc_tests {
672
679
DocTests :: Yes => { }
673
680
DocTests :: No => {
674
- cargo. arg ( "--tests" ) ;
681
+ cargo. args ( [ "--lib" , "--bins" , "--examples" , "-- tests", "--benches" ] ) ;
675
682
}
676
683
DocTests :: Only => {
677
684
cargo. arg ( "--doc" ) ;
@@ -686,8 +693,7 @@ impl Step for Miri {
686
693
cargo. arg ( "--" ) . args ( builder. config . test_args ( ) ) ;
687
694
let mut cargo = Command :: from ( cargo) ;
688
695
{
689
- let _guard =
690
- builder. msg_sysroot_tool ( Kind :: Test , compiler. stage , "cargo-miri" , host, target) ;
696
+ let _guard = builder. msg_sysroot_tool ( Kind :: Test , stage, "cargo-miri" , host, target) ;
691
697
let _time = helpers:: timeit ( builder) ;
692
698
builder. run ( & mut cargo) ;
693
699
}
0 commit comments