@@ -18,7 +18,8 @@ use crate::core::build_steps::llvm::get_llvm_version;
18
18
use crate :: core:: build_steps:: run:: get_completion_paths;
19
19
use crate :: core:: build_steps:: synthetic_targets:: MirOptPanicAbortSyntheticTarget ;
20
20
use 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,
22
23
} ;
23
24
use crate :: core:: build_steps:: toolstate:: ToolState ;
24
25
use crate :: core:: build_steps:: { compile, dist, llvm} ;
@@ -293,7 +294,7 @@ impl Step for Cargotest {
293
294
/// Runs `cargo test` for cargo itself.
294
295
#[ derive( Debug , Clone , PartialEq , Eq , Hash ) ]
295
296
pub struct Cargo {
296
- stage : u32 ,
297
+ build_compiler : Compiler ,
297
298
host : TargetSelection ,
298
299
}
299
300
@@ -310,35 +311,29 @@ impl Step for Cargo {
310
311
}
311
312
312
313
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
+ } ) ;
322
321
}
323
322
324
323
/// Runs `cargo test` for `cargo` packaged with Rust.
325
324
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 ) ) ;
337
332
338
333
let cargo = tool:: prepare_tool_cargo (
339
334
builder,
340
- compiler ,
341
- Mode :: ToolRustc ,
335
+ self . build_compiler ,
336
+ Mode :: ToolTarget ,
342
337
self . host ,
343
338
Kind :: Test ,
344
339
Self :: CRATE_PATH ,
@@ -355,7 +350,7 @@ impl Step for Cargo {
355
350
// Forcibly disable tests using nightly features since any changes to
356
351
// those features won't be able to land.
357
352
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 ) ) ;
359
354
// Cargo's test suite uses `CARGO_RUSTC_CURRENT_DIR` to determine the path that `file!` is
360
355
// relative to. Cargo no longer sets this env var, so we have to do that. This has to be the
361
356
// same value as `-Zroot-dir`.
@@ -367,7 +362,7 @@ impl Step for Cargo {
367
362
crates : vec ! [ "cargo" . into( ) ] ,
368
363
target : self . host . triple . to_string ( ) ,
369
364
host : self . host . triple . to_string ( ) ,
370
- stage,
365
+ stage : self . build_compiler . stage + 1 ,
371
366
} ,
372
367
builder,
373
368
) ;
0 commit comments