@@ -493,7 +493,6 @@ impl Step for RustDemangler {
493
493
494
494
#[ derive( Debug , Clone , PartialEq , Eq , Hash ) ]
495
495
pub struct Miri {
496
- stage : u32 ,
497
496
host : TargetSelection ,
498
497
target : TargetSelection ,
499
498
}
@@ -502,41 +501,31 @@ impl Miri {
502
501
/// Run `cargo miri setup` for the given target, return where the Miri sysroot was put.
503
502
pub fn build_miri_sysroot (
504
503
builder : & Builder < ' _ > ,
505
- compiler : Compiler ,
506
- miri : & Path ,
504
+ compiler_std : Compiler ,
507
505
target : TargetSelection ,
508
506
) -> String {
509
- let miri_sysroot = builder. out . join ( compiler . host . triple ) . join ( "miri-sysroot" ) ;
510
- let mut cargo = tool :: prepare_tool_cargo (
507
+ let miri_sysroot = builder. out . join ( compiler_std . host . triple ) . join ( "miri-sysroot" ) ;
508
+ let mut cargo = builder :: Cargo :: new (
511
509
builder,
512
- compiler,
513
- Mode :: ToolRustc ,
514
- compiler. host ,
515
- "run" ,
516
- "src/tools/miri/cargo-miri" ,
517
- SourceType :: InTree ,
518
- & [ ] ,
510
+ compiler_std, // this is compiler+1; cargo_miri_cmd will do -1 again
511
+ Mode :: Std ,
512
+ SourceType :: Submodule ,
513
+ target,
514
+ "miri-setup" ,
519
515
) ;
520
- cargo. add_rustc_lib_path ( builder) ;
521
- cargo. arg ( "--" ) . arg ( "miri" ) . arg ( "setup" ) ;
522
- cargo. arg ( "--target" ) . arg ( target. rustc_target_arg ( ) ) ;
523
516
524
517
// Tell `cargo miri setup` where to find the sources.
525
518
cargo. env ( "MIRI_LIB_SRC" , builder. src . join ( "library" ) ) ;
526
- // Tell it where to find Miri.
527
- cargo. env ( "MIRI" , miri) ;
528
519
// Tell it where to put the sysroot.
529
520
cargo. env ( "MIRI_SYSROOT" , & miri_sysroot) ;
530
- // Debug things.
531
- cargo. env ( "RUST_BACKTRACE" , "1" ) ;
532
521
533
522
let mut cargo = Command :: from ( cargo) ;
534
523
let _guard = builder. msg (
535
524
Kind :: Build ,
536
- compiler . stage + 1 ,
525
+ compiler_std . stage ,
537
526
"miri sysroot" ,
538
- compiler . host ,
539
- compiler . host ,
527
+ compiler_std . host ,
528
+ compiler_std . host ,
540
529
) ;
541
530
builder. run ( & mut cargo) ;
542
531
@@ -574,16 +563,12 @@ impl Step for Miri {
574
563
}
575
564
576
565
fn make_run ( run : RunConfig < ' _ > ) {
577
- run. builder . ensure ( Miri {
578
- stage : run. builder . top_stage ,
579
- host : run. build_triple ( ) ,
580
- target : run. target ,
581
- } ) ;
566
+ run. builder . ensure ( Miri { host : run. build_triple ( ) , target : run. target } ) ;
582
567
}
583
568
584
569
/// Runs `cargo test` for miri.
585
570
fn run ( self , builder : & Builder < ' _ > ) {
586
- let stage = self . stage ;
571
+ let stage = builder . top_stage ;
587
572
let host = self . host ;
588
573
let target = self . target ;
589
574
let compiler = builder. compiler ( stage, host) ;
@@ -592,18 +577,15 @@ impl Step for Miri {
592
577
let compiler_std = builder. compiler ( if stage < 2 { stage + 1 } else { stage } , host) ;
593
578
594
579
let miri =
595
- builder. ensure ( tool:: Miri { compiler, target : self . host , extra_features : Vec :: new ( ) } ) ;
596
- let _cargo_miri = builder. ensure ( tool:: CargoMiri {
597
- compiler,
598
- target : self . host ,
599
- extra_features : Vec :: new ( ) ,
600
- } ) ;
580
+ builder. ensure ( tool:: Miri { compiler, target : host, extra_features : Vec :: new ( ) } ) ;
581
+ // the ui tests also assume cargo-miri has been built
582
+ builder. ensure ( tool:: CargoMiri { compiler, target : host, extra_features : Vec :: new ( ) } ) ;
601
583
// The stdlib we need might be at a different stage. And just asking for the
602
584
// sysroot does not seem to populate it, so we do that first.
603
585
builder. ensure ( compile:: Std :: new ( compiler_std, host) ) ;
604
586
let sysroot = builder. sysroot ( compiler_std) ;
605
587
// We also need a Miri sysroot.
606
- let miri_sysroot = Miri :: build_miri_sysroot ( builder, compiler , & miri , target) ;
588
+ let miri_sysroot = Miri :: build_miri_sysroot ( builder, compiler_std , target) ;
607
589
608
590
// # Run `cargo test`.
609
591
let mut cargo = tool:: prepare_tool_cargo (
@@ -616,10 +598,13 @@ impl Step for Miri {
616
598
SourceType :: InTree ,
617
599
& [ ] ,
618
600
) ;
619
- let _guard = builder. msg_sysroot_tool ( Kind :: Test , compiler. stage , "miri" , host, target) ;
620
601
621
602
cargo. add_rustc_lib_path ( builder) ;
622
603
604
+ // We can NOT use `run_cargo_test` since Miri's integration tests do not use the usual test
605
+ // 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) ;
607
+
623
608
// miri tests need to know about the stage sysroot
624
609
cargo. env ( "MIRI_SYSROOT" , & miri_sysroot) ;
625
610
cargo. env ( "MIRI_HOST_SYSROOT" , & sysroot) ;
@@ -632,10 +617,8 @@ impl Step for Miri {
632
617
// Set the target.
633
618
cargo. env ( "MIRI_TEST_TARGET" , target. rustc_target_arg ( ) ) ;
634
619
635
- // This can NOT be `run_cargo_test` since the Miri test runner
636
- // does not understand the flags added by `add_flags_and_try_run_test`.
637
- let mut cargo = prepare_cargo_test ( cargo, & [ ] , & [ ] , "miri" , compiler, target, builder) ;
638
620
{
621
+ let _guard = builder. msg_sysroot_tool ( Kind :: Test , compiler. stage , "miri" , host, target) ;
639
622
let _time = helpers:: timeit ( builder) ;
640
623
builder. run ( & mut cargo) ;
641
624
}
@@ -650,8 +633,14 @@ impl Step for Miri {
650
633
// Optimizations can change error locations and remove UB so don't run `fail` tests.
651
634
cargo. args ( [ "tests/pass" , "tests/panic" ] ) ;
652
635
653
- let mut cargo = prepare_cargo_test ( cargo, & [ ] , & [ ] , "miri" , compiler, target, builder) ;
654
636
{
637
+ let _guard = builder. msg_sysroot_tool (
638
+ Kind :: Test ,
639
+ compiler. stage ,
640
+ "miri (mir-opt-level 4)" ,
641
+ host,
642
+ target,
643
+ ) ;
655
644
let _time = helpers:: timeit ( builder) ;
656
645
builder. run ( & mut cargo) ;
657
646
}
@@ -660,28 +649,20 @@ impl Step for Miri {
660
649
// # Run `cargo miri test`.
661
650
// This is just a smoke test (Miri's own CI invokes this in a bunch of different ways and ensures
662
651
// that we get the desired output), but that is sufficient to make sure that the libtest harness
663
- // itself executes properly under Miri.
652
+ // 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
654
let mut cargo = tool:: prepare_tool_cargo (
665
655
builder,
666
- compiler ,
667
- Mode :: ToolRustc ,
668
- host ,
669
- "run " ,
670
- "src/tools/miri/cargo-miri" ,
656
+ compiler_std , // this is compiler+1; cargo_miri_cmd will do -1 again
657
+ Mode :: ToolStd , // it's unclear what to use here, we're not building anything just doing a smoke test!
658
+ target ,
659
+ "miri-test " ,
660
+ "src/tools/miri/test- cargo-miri" ,
671
661
SourceType :: Submodule ,
672
662
& [ ] ,
673
663
) ;
674
- cargo. add_rustc_lib_path ( builder) ;
675
- cargo. arg ( "--" ) . arg ( "miri" ) . arg ( "test" ) ;
676
- if builder. config . locked_deps {
677
- cargo. arg ( "--locked" ) ;
678
- }
679
- cargo
680
- . arg ( "--manifest-path" )
681
- . arg ( builder. src . join ( "src/tools/miri/test-cargo-miri/Cargo.toml" ) ) ;
682
- cargo. arg ( "--target" ) . arg ( target. rustc_target_arg ( ) ) ;
683
664
684
- // `prepare_tool_cargo` sets RUSTDOC to the bootstrap wrapper and RUSTDOC_REAL to a dummy path as this is a "run ", not a "test".
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".
685
666
// Also, we want the rustdoc from the "next" stage for the same reason that we build a std from the next stage.
686
667
// So let's just set that here, and bypass bootstrap's RUSTDOC (just like cargo-miri already ignores bootstrap's RUSTC_WRAPPER).
687
668
if builder. doc_tests != DocTests :: No {
@@ -697,17 +678,16 @@ impl Step for Miri {
697
678
}
698
679
}
699
680
700
- // Tell `cargo miri` where to find things .
681
+ // Tell `cargo miri` where to find the sysroots .
701
682
cargo. env ( "MIRI_SYSROOT" , & miri_sysroot) ;
702
683
cargo. env ( "MIRI_HOST_SYSROOT" , sysroot) ;
703
- cargo. env ( "MIRI" , & miri) ;
704
- // Debug things.
705
- cargo. env ( "RUST_BACKTRACE" , "1" ) ;
706
684
707
685
// Finally, pass test-args and run everything.
708
686
cargo. arg ( "--" ) . args ( builder. config . test_args ( ) ) ;
709
687
let mut cargo = Command :: from ( cargo) ;
710
688
{
689
+ let _guard =
690
+ builder. msg_sysroot_tool ( Kind :: Test , compiler. stage , "cargo-miri" , host, target) ;
711
691
let _time = helpers:: timeit ( builder) ;
712
692
builder. run ( & mut cargo) ;
713
693
}
0 commit comments