@@ -263,7 +263,7 @@ impl Step for Cargotest {
263
263
264
264
let _time = helpers:: timeit ( builder) ;
265
265
let mut cmd = builder. tool_cmd ( Tool :: CargoTest ) ;
266
- cmd. arg ( & cargo. tool_path )
266
+ cmd. arg ( & cargo)
267
267
. arg ( & out_dir)
268
268
. args ( builder. config . test_args ( ) )
269
269
. env ( "RUSTC" , builder. rustc ( compiler) )
@@ -298,16 +298,9 @@ impl Step for Cargo {
298
298
299
299
/// Runs `cargo test` for `cargo` packaged with Rust.
300
300
fn run ( self , builder : & Builder < ' _ > ) {
301
- if self . stage < 2 {
302
- eprintln ! ( "WARNING: cargo tests on stage {} may not behave well." , self . stage) ;
303
- eprintln ! ( "HELP: consider using stage 2" ) ;
304
- }
305
-
306
301
let compiler = builder. compiler ( self . stage , self . host ) ;
307
302
308
- let cargo = builder. ensure ( tool:: Cargo { compiler, target : self . host } ) ;
309
- let compiler = cargo. build_compiler ;
310
-
303
+ builder. ensure ( tool:: Cargo { compiler, target : self . host } ) ;
311
304
let cargo = tool:: prepare_tool_cargo (
312
305
builder,
313
306
compiler,
@@ -374,7 +367,6 @@ impl Step for RustAnalyzer {
374
367
let stage = self . stage ;
375
368
let host = self . host ;
376
369
let compiler = builder. compiler ( stage, host) ;
377
- let compiler = tool:: get_tool_rustc_compiler ( builder, compiler) ;
378
370
379
371
// We don't need to build the whole Rust Analyzer for the proc-macro-srv test suite,
380
372
// but we do need the standard library to be present.
@@ -435,8 +427,7 @@ impl Step for Rustfmt {
435
427
let host = self . host ;
436
428
let compiler = builder. compiler ( stage, host) ;
437
429
438
- let tool_result = builder. ensure ( tool:: Rustfmt { compiler, target : self . host } ) ;
439
- let compiler = tool_result. build_compiler ;
430
+ builder. ensure ( tool:: Rustfmt { compiler, target : self . host } ) ;
440
431
441
432
let mut cargo = tool:: prepare_tool_cargo (
442
433
builder,
@@ -531,11 +522,16 @@ impl Step for Miri {
531
522
532
523
// This compiler runs on the host, we'll just use it for the target.
533
524
let target_compiler = builder. compiler ( stage, host) ;
525
+ // Similar to `compile::Assemble`, build with the previous stage's compiler. Otherwise
526
+ // we'd have stageN/bin/rustc and stageN/bin/rustdoc be effectively different stage
527
+ // compilers, which isn't what we want. Rustdoc should be linked in the same way as the
528
+ // rustc compiler it's paired with, so it must be built with the previous stage compiler.
529
+ let host_compiler = builder. compiler ( stage - 1 , host) ;
534
530
535
531
// Build our tools.
536
- let miri = builder. ensure ( tool:: Miri { compiler : target_compiler , target : host } ) ;
532
+ let miri = builder. ensure ( tool:: Miri { compiler : host_compiler , target : host } ) ;
537
533
// the ui tests also assume cargo-miri has been built
538
- builder. ensure ( tool:: CargoMiri { compiler : target_compiler , target : host } ) ;
534
+ builder. ensure ( tool:: CargoMiri { compiler : host_compiler , target : host } ) ;
539
535
540
536
// We also need sysroots, for Miri and for the host (the latter for build scripts).
541
537
// This is for the tests so everything is done with the target compiler.
@@ -546,8 +542,7 @@ impl Step for Miri {
546
542
// Miri has its own "target dir" for ui test dependencies. Make sure it gets cleared when
547
543
// the sysroot gets rebuilt, to avoid "found possibly newer version of crate `std`" errors.
548
544
if !builder. config . dry_run ( ) {
549
- let ui_test_dep_dir =
550
- builder. stage_out ( miri. build_compiler , Mode :: ToolStd ) . join ( "miri_ui" ) ;
545
+ let ui_test_dep_dir = builder. stage_out ( host_compiler, Mode :: ToolStd ) . join ( "miri_ui" ) ;
551
546
// The mtime of `miri_sysroot` changes when the sysroot gets rebuilt (also see
552
547
// <https://github.com/RalfJung/rustc-build-sysroot/commit/10ebcf60b80fe2c3dc765af0ff19fdc0da4b7466>).
553
548
// We can hence use that directly as a signal to clear the ui test dir.
@@ -558,7 +553,7 @@ impl Step for Miri {
558
553
// This is with the Miri crate, so it uses the host compiler.
559
554
let mut cargo = tool:: prepare_tool_cargo (
560
555
builder,
561
- miri . build_compiler ,
556
+ host_compiler ,
562
557
Mode :: ToolRustc ,
563
558
host,
564
559
Kind :: Test ,
@@ -576,7 +571,7 @@ impl Step for Miri {
576
571
// miri tests need to know about the stage sysroot
577
572
cargo. env ( "MIRI_SYSROOT" , & miri_sysroot) ;
578
573
cargo. env ( "MIRI_HOST_SYSROOT" , & host_sysroot) ;
579
- cargo. env ( "MIRI" , & miri. tool_path ) ;
574
+ cargo. env ( "MIRI" , & miri) ;
580
575
581
576
// Set the target.
582
577
cargo. env ( "MIRI_TEST_TARGET" , target. rustc_target_arg ( ) ) ;
@@ -748,13 +743,7 @@ impl Step for Clippy {
748
743
let host = self . host ;
749
744
let compiler = builder. compiler ( stage, host) ;
750
745
751
- if stage < 2 {
752
- eprintln ! ( "WARNING: clippy tests on stage {stage} may not behave well." ) ;
753
- eprintln ! ( "HELP: consider using stage 2" ) ;
754
- }
755
-
756
- let tool_result = builder. ensure ( tool:: Clippy { compiler, target : self . host } ) ;
757
- let compiler = tool_result. build_compiler ;
746
+ builder. ensure ( tool:: Clippy { compiler, target : self . host } ) ;
758
747
let mut cargo = tool:: prepare_tool_cargo (
759
748
builder,
760
749
compiler,
@@ -1739,7 +1728,18 @@ NOTE: if you're sure you want to do this, please open an issue as to why. In the
1739
1728
// If we're using `--stage 0`, we should provide the bootstrap cargo.
1740
1729
builder. initial_cargo . clone ( )
1741
1730
} else {
1742
- builder. ensure ( tool:: Cargo { compiler, target : compiler. host } ) . tool_path
1731
+ // We need to properly build cargo using the suitable stage compiler.
1732
+
1733
+ let compiler = builder. download_rustc ( ) . then_some ( compiler) . unwrap_or_else ( ||
1734
+ // HACK: currently tool stages are off-by-one compared to compiler stages, i.e. if
1735
+ // you give `tool::Cargo` a stage 1 rustc, it will cause stage 2 rustc to be built
1736
+ // and produce a cargo built with stage 2 rustc. To fix this, we need to chop off
1737
+ // the compiler stage by 1 to align with expected `./x test run-make --stage N`
1738
+ // behavior, i.e. we need to pass `N - 1` compiler stage to cargo. See also Miri
1739
+ // which does a similar hack.
1740
+ builder. compiler ( builder. top_stage - 1 , compiler. host ) ) ;
1741
+
1742
+ builder. ensure ( tool:: Cargo { compiler, target : compiler. host } )
1743
1743
} ;
1744
1744
1745
1745
cmd. arg ( "--cargo-path" ) . arg ( cargo_path) ;
@@ -1760,10 +1760,9 @@ NOTE: if you're sure you want to do this, please open an issue as to why. In the
1760
1760
// Use the beta compiler for jsondocck
1761
1761
let json_compiler = compiler. with_stage ( 0 ) ;
1762
1762
cmd. arg ( "--jsondocck-path" )
1763
- . arg ( builder. ensure ( tool:: JsonDocCk { compiler : json_compiler, target } ) . tool_path ) ;
1764
- cmd. arg ( "--jsondoclint-path" ) . arg (
1765
- builder. ensure ( tool:: JsonDocLint { compiler : json_compiler, target } ) . tool_path ,
1766
- ) ;
1763
+ . arg ( builder. ensure ( tool:: JsonDocCk { compiler : json_compiler, target } ) ) ;
1764
+ cmd. arg ( "--jsondoclint-path" )
1765
+ . arg ( builder. ensure ( tool:: JsonDocLint { compiler : json_compiler, target } ) ) ;
1767
1766
}
1768
1767
1769
1768
if matches ! ( mode, "coverage-map" | "coverage-run" ) {
@@ -3000,15 +2999,12 @@ impl Step for RemoteCopyLibs {
3000
2999
3001
3000
builder. info ( & format ! ( "REMOTE copy libs to emulator ({target})" ) ) ;
3002
3001
3003
- let remote_test_server = builder. ensure ( tool:: RemoteTestServer { compiler, target } ) ;
3002
+ let server = builder. ensure ( tool:: RemoteTestServer { compiler, target } ) ;
3004
3003
3005
3004
// Spawn the emulator and wait for it to come online
3006
3005
let tool = builder. tool_exe ( Tool :: RemoteTestClient ) ;
3007
3006
let mut cmd = command ( & tool) ;
3008
- cmd. arg ( "spawn-emulator" )
3009
- . arg ( target. triple )
3010
- . arg ( & remote_test_server. tool_path )
3011
- . arg ( builder. tempdir ( ) ) ;
3007
+ cmd. arg ( "spawn-emulator" ) . arg ( target. triple ) . arg ( & server) . arg ( builder. tempdir ( ) ) ;
3012
3008
if let Some ( rootfs) = builder. qemu_rootfs ( target) {
3013
3009
cmd. arg ( rootfs) ;
3014
3010
}
0 commit comments