@@ -18,7 +18,8 @@ use crate::core::build_steps::llvm::get_llvm_version;
1818use crate :: core:: build_steps:: run:: get_completion_paths;
1919use crate :: core:: build_steps:: synthetic_targets:: MirOptPanicAbortSyntheticTarget ;
2020use crate :: core:: build_steps:: tool:: {
21- self , COMPILETEST_ALLOW_FEATURES , RustcPrivateCompilers , SourceType , Tool ,
21+ self , COMPILETEST_ALLOW_FEATURES , RustcPrivateCompilers , SourceType , Tool , ToolTargetBuildMode ,
22+ get_tool_target_compiler,
2223} ;
2324use crate :: core:: build_steps:: toolstate:: ToolState ;
2425use crate :: core:: build_steps:: { compile, dist, llvm} ;
@@ -293,7 +294,7 @@ impl Step for Cargotest {
293294/// Runs `cargo test` for cargo itself.
294295#[ derive( Debug , Clone , PartialEq , Eq , Hash ) ]
295296pub struct Cargo {
296- stage : u32 ,
297+ build_compiler : Compiler ,
297298 host : TargetSelection ,
298299}
299300
@@ -310,35 +311,29 @@ impl Step for Cargo {
310311 }
311312
312313 fn make_run ( run : RunConfig < ' _ > ) {
313- // If stage is explicitly set or not lower than 2, keep it. Otherwise, make sure it's at least 2
314- // as tests for this step don't work with a lower stage.
315- let stage = if run. builder . config . is_explicit_stage ( ) || run. builder . top_stage >= 2 {
316- run. builder . top_stage
317- } else {
318- 2
319- } ;
320-
321- run. builder . ensure ( Cargo { stage, host : run. target } ) ;
314+ run. builder . ensure ( Cargo {
315+ build_compiler : get_tool_target_compiler (
316+ run. builder ,
317+ ToolTargetBuildMode :: Build ( run. target ) ,
318+ ) ,
319+ host : run. target ,
320+ } ) ;
322321 }
323322
324323 /// Runs `cargo test` for `cargo` packaged with Rust.
325324 fn run ( self , builder : & Builder < ' _ > ) {
326- let stage = self . stage ;
327-
328- if stage < 2 {
329- eprintln ! ( "WARNING: cargo tests on stage {stage} may not behave well." ) ;
330- eprintln ! ( "HELP: consider using stage 2" ) ;
331- }
332-
333- let compiler = builder. compiler ( stage, self . host ) ;
334-
335- let cargo = builder. ensure ( tool:: Cargo :: from_build_compiler ( compiler, self . host ) ) ;
336- let compiler = cargo. build_compiler ;
325+ // FIXME: we now use the same compiler to build cargo and then we also test that compiler
326+ // using cargo.
327+ // We could build cargo using a different compiler, but that complicates some things,
328+ // because when we run cargo tests, the crates that are being compiled are accessing the
329+ // sysroot of the build compiler, rather than the compiler being tested.
330+ // Since these two compilers are currently the same, it works.
331+ builder. ensure ( tool:: Cargo :: from_build_compiler ( self . build_compiler , self . host ) ) ;
337332
338333 let cargo = tool:: prepare_tool_cargo (
339334 builder,
340- compiler ,
341- Mode :: ToolRustc ,
335+ self . build_compiler ,
336+ Mode :: ToolTarget ,
342337 self . host ,
343338 Kind :: Test ,
344339 Self :: CRATE_PATH ,
@@ -355,7 +350,7 @@ impl Step for Cargo {
355350 // Forcibly disable tests using nightly features since any changes to
356351 // those features won't be able to land.
357352 cargo. env ( "CARGO_TEST_DISABLE_NIGHTLY" , "1" ) ;
358- cargo. env ( "PATH" , path_for_cargo ( builder, compiler ) ) ;
353+ cargo. env ( "PATH" , path_for_cargo ( builder, self . build_compiler ) ) ;
359354 // Cargo's test suite uses `CARGO_RUSTC_CURRENT_DIR` to determine the path that `file!` is
360355 // relative to. Cargo no longer sets this env var, so we have to do that. This has to be the
361356 // same value as `-Zroot-dir`.
@@ -367,7 +362,7 @@ impl Step for Cargo {
367362 crates : vec ! [ "cargo" . into( ) ] ,
368363 target : self . host . triple . to_string ( ) ,
369364 host : self . host . triple . to_string ( ) ,
370- stage,
365+ stage : self . build_compiler . stage + 1 ,
371366 } ,
372367 builder,
373368 ) ;
0 commit comments