@@ -15,7 +15,8 @@ use crate::core::build_steps::llvm::get_llvm_version;
1515use crate :: core:: build_steps:: run:: get_completion_paths;
1616use crate :: core:: build_steps:: synthetic_targets:: MirOptPanicAbortSyntheticTarget ;
1717use crate :: core:: build_steps:: tool:: {
18- self , COMPILETEST_ALLOW_FEATURES , RustcPrivateCompilers , SourceType , Tool ,
18+ self , COMPILETEST_ALLOW_FEATURES , RustcPrivateCompilers , SourceType , Tool , ToolTargetBuildMode ,
19+ get_tool_target_compiler,
1920} ;
2021use crate :: core:: build_steps:: toolstate:: ToolState ;
2122use crate :: core:: build_steps:: { compile, dist, llvm} ;
@@ -290,7 +291,7 @@ impl Step for Cargotest {
290291/// Runs `cargo test` for cargo itself.
291292#[ derive( Debug , Clone , PartialEq , Eq , Hash ) ]
292293pub struct Cargo {
293- stage : u32 ,
294+ build_compiler : Compiler ,
294295 host : TargetSelection ,
295296}
296297
@@ -307,35 +308,29 @@ impl Step for Cargo {
307308 }
308309
309310 fn make_run ( run : RunConfig < ' _ > ) {
310- // If stage is explicitly set or not lower than 2, keep it. Otherwise, make sure it's at least 2
311- // as tests for this step don't work with a lower stage.
312- let stage = if run. builder . config . is_explicit_stage ( ) || run. builder . top_stage >= 2 {
313- run. builder . top_stage
314- } else {
315- 2
316- } ;
317-
318- run. builder . ensure ( Cargo { stage, host : run. target } ) ;
311+ run. builder . ensure ( Cargo {
312+ build_compiler : get_tool_target_compiler (
313+ run. builder ,
314+ ToolTargetBuildMode :: Build ( run. target ) ,
315+ ) ,
316+ host : run. target ,
317+ } ) ;
319318 }
320319
321320 /// Runs `cargo test` for `cargo` packaged with Rust.
322321 fn run ( self , builder : & Builder < ' _ > ) {
323- let stage = self . stage ;
324-
325- if stage < 2 {
326- eprintln ! ( "WARNING: cargo tests on stage {stage} may not behave well." ) ;
327- eprintln ! ( "HELP: consider using stage 2" ) ;
328- }
329-
330- let compiler = builder. compiler ( stage, self . host ) ;
331-
332- let cargo = builder. ensure ( tool:: Cargo :: from_build_compiler ( compiler, self . host ) ) ;
333- let compiler = cargo. build_compiler ;
322+ // FIXME: we now use the same compiler to build cargo and then we also test that compiler
323+ // using cargo.
324+ // We could build cargo using a different compiler, but that complicates some things,
325+ // because when we run cargo tests, the crates that are being compiled are accessing the
326+ // sysroot of the build compiler, rather than the compiler being tested.
327+ // Since these two compilers are currently the same, it works.
328+ builder. ensure ( tool:: Cargo :: from_build_compiler ( self . build_compiler , self . host ) ) ;
334329
335330 let cargo = tool:: prepare_tool_cargo (
336331 builder,
337- compiler ,
338- Mode :: ToolRustc ,
332+ self . build_compiler ,
333+ Mode :: ToolTarget ,
339334 self . host ,
340335 Kind :: Test ,
341336 Self :: CRATE_PATH ,
@@ -352,7 +347,7 @@ impl Step for Cargo {
352347 // Forcibly disable tests using nightly features since any changes to
353348 // those features won't be able to land.
354349 cargo. env ( "CARGO_TEST_DISABLE_NIGHTLY" , "1" ) ;
355- cargo. env ( "PATH" , path_for_cargo ( builder, compiler ) ) ;
350+ cargo. env ( "PATH" , path_for_cargo ( builder, self . build_compiler ) ) ;
356351 // Cargo's test suite uses `CARGO_RUSTC_CURRENT_DIR` to determine the path that `file!` is
357352 // relative to. Cargo no longer sets this env var, so we have to do that. This has to be the
358353 // same value as `-Zroot-dir`.
0 commit comments