@@ -144,7 +144,7 @@ fn default_compiler_for_checking_rustc(builder: &Builder<'_>) -> Compiler {
144
144
}
145
145
146
146
/// Checks rustc using `build_compiler` and copies the built
147
- /// .rmeta files into the sysroot of `build_copoiler `.
147
+ /// .rmeta files into the sysroot of `build_compiler `.
148
148
#[ derive( Debug , Clone , PartialEq , Eq , Hash ) ]
149
149
pub struct Rustc {
150
150
/// Compiler that will check this rustc.
@@ -249,8 +249,19 @@ impl Step for Rustc {
249
249
}
250
250
}
251
251
252
+ /// Prepares a build compiler sysroot that will check a `Mode::ToolRustc` tool.
253
+ /// Also checks rustc using this compiler, to prepare .rmetas that the tool will link to.
254
+ fn prepare_compiler_for_tool_rustc ( builder : & Builder < ' _ > , target : TargetSelection ) -> Compiler {
255
+ // When we check tool stage N, we check it with compiler stage N-1
256
+ let build_compiler = builder. compiler ( builder. top_stage - 1 , builder. config . host_target ) ;
257
+ builder. ensure ( Rustc :: new ( builder, build_compiler, target) ) ;
258
+ build_compiler
259
+ }
260
+
261
+ /// Checks a single codegen backend.
252
262
#[ derive( Debug , Clone , PartialEq , Eq , Hash ) ]
253
263
pub struct CodegenBackend {
264
+ pub build_compiler : Compiler ,
254
265
pub target : TargetSelection ,
255
266
pub backend : & ' static str ,
256
267
}
@@ -265,8 +276,10 @@ impl Step for CodegenBackend {
265
276
}
266
277
267
278
fn make_run ( run : RunConfig < ' _ > ) {
279
+ // FIXME: only check the backend(s) that were actually selected in run.paths
280
+ let build_compiler = prepare_compiler_for_tool_rustc ( run. builder , run. target ) ;
268
281
for & backend in & [ "cranelift" , "gcc" ] {
269
- run. builder . ensure ( CodegenBackend { target : run. target , backend } ) ;
282
+ run. builder . ensure ( CodegenBackend { build_compiler , target : run. target , backend } ) ;
270
283
}
271
284
}
272
285
@@ -277,15 +290,13 @@ impl Step for CodegenBackend {
277
290
return ;
278
291
}
279
292
280
- let compiler = builder . compiler ( builder . top_stage , builder . config . host_target ) ;
293
+ let build_compiler = self . build_compiler ;
281
294
let target = self . target ;
282
295
let backend = self . backend ;
283
296
284
- builder. ensure ( Rustc :: new ( target, builder) ) ;
285
-
286
297
let mut cargo = builder:: Cargo :: new (
287
298
builder,
288
- compiler ,
299
+ build_compiler ,
289
300
Mode :: Codegen ,
290
301
SourceType :: InTree ,
291
302
target,
@@ -295,23 +306,25 @@ impl Step for CodegenBackend {
295
306
cargo
296
307
. arg ( "--manifest-path" )
297
308
. arg ( builder. src . join ( format ! ( "compiler/rustc_codegen_{backend}/Cargo.toml" ) ) ) ;
298
- rustc_cargo_env ( builder, & mut cargo, target, compiler . stage ) ;
309
+ rustc_cargo_env ( builder, & mut cargo, target, build_compiler . stage ) ;
299
310
300
- let _guard = builder. msg_check ( backend, target, None ) ;
311
+ let _guard = builder. msg_check ( & format ! ( "rustc_codegen_{ backend}" ) , target, None ) ;
301
312
302
- let stamp = build_stamp:: codegen_backend_stamp ( builder, compiler , target, backend)
313
+ let stamp = build_stamp:: codegen_backend_stamp ( builder, build_compiler , target, backend)
303
314
. with_prefix ( "check" ) ;
304
315
305
316
run_cargo ( builder, cargo, builder. config . free_args . clone ( ) , & stamp, vec ! [ ] , true , false ) ;
306
317
}
307
318
308
319
fn metadata ( & self ) -> Option < StepMetadata > {
309
- Some ( StepMetadata :: check ( self . backend , self . target ) )
320
+ Some ( StepMetadata :: check ( self . backend , self . target ) . built_by ( self . build_compiler ) )
310
321
}
311
322
}
312
323
324
+ /// Checks Rust analyzer that links to .rmetas from a checked rustc.
313
325
#[ derive( Debug , Clone , PartialEq , Eq , Hash ) ]
314
326
pub struct RustAnalyzer {
327
+ pub build_compiler : Compiler ,
315
328
pub target : TargetSelection ,
316
329
}
317
330
@@ -332,18 +345,17 @@ impl Step for RustAnalyzer {
332
345
}
333
346
334
347
fn make_run ( run : RunConfig < ' _ > ) {
335
- run. builder . ensure ( RustAnalyzer { target : run. target } ) ;
348
+ let build_compiler = prepare_compiler_for_tool_rustc ( run. builder , run. target ) ;
349
+ run. builder . ensure ( RustAnalyzer { build_compiler, target : run. target } ) ;
336
350
}
337
351
338
352
fn run ( self , builder : & Builder < ' _ > ) {
339
- let compiler = builder . compiler ( builder . top_stage , builder . config . host_target ) ;
353
+ let build_compiler = self . build_compiler ;
340
354
let target = self . target ;
341
355
342
- builder. ensure ( Rustc :: new ( target, builder) ) ;
343
-
344
356
let mut cargo = prepare_tool_cargo (
345
357
builder,
346
- compiler ,
358
+ build_compiler ,
347
359
Mode :: ToolRustc ,
348
360
target,
349
361
builder. kind ,
@@ -360,15 +372,15 @@ impl Step for RustAnalyzer {
360
372
361
373
// Cargo's output path in a given stage, compiled by a particular
362
374
// compiler for the specified target.
363
- let stamp = BuildStamp :: new ( & builder. cargo_out ( compiler , Mode :: ToolRustc , target) )
375
+ let stamp = BuildStamp :: new ( & builder. cargo_out ( build_compiler , Mode :: ToolRustc , target) )
364
376
. with_prefix ( "rust-analyzer-check" ) ;
365
377
366
378
let _guard = builder. msg_check ( "rust-analyzer artifacts" , target, None ) ;
367
379
run_cargo ( builder, cargo, builder. config . free_args . clone ( ) , & stamp, vec ! [ ] , true , false ) ;
368
380
}
369
381
370
382
fn metadata ( & self ) -> Option < StepMetadata > {
371
- Some ( StepMetadata :: check ( "rust-analyzer" , self . target ) )
383
+ Some ( StepMetadata :: check ( "rust-analyzer" , self . target ) . built_by ( self . build_compiler ) )
372
384
}
373
385
}
374
386
@@ -405,7 +417,7 @@ impl Step for Compiletest {
405
417
) ;
406
418
407
419
if mode != Mode :: ToolBootstrap {
408
- builder. ensure ( Rustc :: new ( self . target , builder ) ) ;
420
+ builder. std ( compiler , self . target ) ;
409
421
}
410
422
411
423
let mut cargo = prepare_tool_cargo (
@@ -441,12 +453,14 @@ macro_rules! tool_check_step {
441
453
// The part of this path after the final '/' is also used as a display name.
442
454
path: $path: literal
443
455
$( , alt_path: $alt_path: literal ) *
456
+ , mode: $mode: path
444
457
$( , default : $default: literal ) ?
445
458
$( , ) ?
446
459
}
447
460
) => {
448
461
#[ derive( Debug , Clone , PartialEq , Eq , Hash ) ]
449
462
pub struct $name {
463
+ pub build_compiler: Compiler ,
450
464
pub target: TargetSelection ,
451
465
}
452
466
@@ -461,16 +475,33 @@ macro_rules! tool_check_step {
461
475
}
462
476
463
477
fn make_run( run: RunConfig <' _>) {
464
- run. builder. ensure( $name { target: run. target } ) ;
478
+ let host = run. builder. config. host_target;
479
+ let target = run. target;
480
+ let build_compiler = match $mode {
481
+ Mode :: ToolBootstrap => run. builder. compiler( 0 , host) ,
482
+ Mode :: ToolStd => {
483
+ // A small number of tools rely on in-tree standard
484
+ // library crates (e.g. compiletest needs libtest).
485
+ let build_compiler = run. builder. compiler( run. builder. top_stage, host) ;
486
+ run. builder. std( build_compiler, host) ;
487
+ run. builder. std( build_compiler, target) ;
488
+ build_compiler
489
+ }
490
+ Mode :: ToolRustc => {
491
+ prepare_compiler_for_tool_rustc( run. builder, target)
492
+ }
493
+ _ => panic!( "unexpected mode for tool check step: {:?}" , $mode) ,
494
+ } ;
495
+ run. builder. ensure( $name { target, build_compiler } ) ;
465
496
}
466
497
467
498
fn run( self , builder: & Builder <' _>) {
468
- let Self { target } = self ;
469
- run_tool_check_step( builder, target, stringify! ( $name ) , $path ) ;
499
+ let Self { target, build_compiler } = self ;
500
+ run_tool_check_step( builder, build_compiler , target, $path , $mode ) ;
470
501
}
471
502
472
503
fn metadata( & self ) -> Option <StepMetadata > {
473
- Some ( StepMetadata :: check( stringify!( $name) , self . target) )
504
+ Some ( StepMetadata :: check( stringify!( $name) , self . target) . built_by ( self . build_compiler ) )
474
505
}
475
506
}
476
507
}
@@ -479,19 +510,17 @@ macro_rules! tool_check_step {
479
510
/// Used by the implementation of `Step::run` in `tool_check_step!`.
480
511
fn run_tool_check_step (
481
512
builder : & Builder < ' _ > ,
513
+ build_compiler : Compiler ,
482
514
target : TargetSelection ,
483
- step_type_name : & str ,
484
515
path : & str ,
516
+ mode : Mode ,
485
517
) {
486
518
let display_name = path. rsplit ( '/' ) . next ( ) . unwrap ( ) ;
487
- let compiler = builder. compiler ( builder. top_stage , builder. config . host_target ) ;
488
-
489
- builder. ensure ( Rustc :: new ( builder, compiler, target) ) ;
490
519
491
520
let mut cargo = prepare_tool_cargo (
492
521
builder,
493
- compiler ,
494
- Mode :: ToolRustc ,
522
+ build_compiler ,
523
+ mode ,
495
524
target,
496
525
builder. kind ,
497
526
path,
@@ -503,33 +532,56 @@ fn run_tool_check_step(
503
532
& [ ] ,
504
533
) ;
505
534
535
+ // FIXME: check bootstrap doesn't currently work with --all-targets
506
536
cargo. arg ( "--all-targets" ) ;
507
537
508
- let stamp = BuildStamp :: new ( & builder. cargo_out ( compiler, Mode :: ToolRustc , target) )
509
- . with_prefix ( & format ! ( "{}-check" , step_type_name. to_lowercase( ) ) ) ;
538
+ let stamp = BuildStamp :: new ( & builder. cargo_out ( build_compiler, mode, target) )
539
+ . with_prefix ( & format ! ( "{display_name}-check" ) ) ;
540
+
541
+ let stage = match mode {
542
+ // Mode::ToolRustc is included here because of how msg_sysroot_tool prints stages
543
+ Mode :: Std | Mode :: ToolRustc => build_compiler. stage ,
544
+ _ => build_compiler. stage + 1 ,
545
+ } ;
510
546
511
- let _guard = builder. msg_check ( format ! ( "{display_name} artifacts" ) , target, None ) ;
547
+ let _guard =
548
+ builder. msg_tool ( builder. kind , mode, display_name, stage, & build_compiler. host , & target) ;
512
549
run_cargo ( builder, cargo, builder. config . free_args . clone ( ) , & stamp, vec ! [ ] , true , false ) ;
513
550
}
514
551
515
- tool_check_step ! ( Rustdoc { path: "src/tools/rustdoc" , alt_path: "src/librustdoc" } ) ;
552
+ tool_check_step ! ( Rustdoc {
553
+ path: "src/tools/rustdoc" ,
554
+ alt_path: "src/librustdoc" ,
555
+ mode: Mode :: ToolRustc
556
+ } ) ;
516
557
// Clippy, miri and Rustfmt are hybrids. They are external tools, but use a git subtree instead
517
558
// of a submodule. Since the SourceType only drives the deny-warnings
518
559
// behavior, treat it as in-tree so that any new warnings in clippy will be
519
560
// rejected.
520
- tool_check_step ! ( Clippy { path: "src/tools/clippy" } ) ;
521
- tool_check_step ! ( Miri { path: "src/tools/miri" } ) ;
522
- tool_check_step ! ( CargoMiri { path: "src/tools/miri/cargo-miri" } ) ;
523
- tool_check_step ! ( Rustfmt { path: "src/tools/rustfmt" } ) ;
524
- tool_check_step ! ( MiroptTestTools { path: "src/tools/miropt-test-tools" } ) ;
525
- tool_check_step ! ( TestFloatParse { path: "src/tools/test-float-parse" } ) ;
526
- tool_check_step ! ( FeaturesStatusDump { path: "src/tools/features-status-dump" } ) ;
527
-
528
- tool_check_step ! ( Bootstrap { path: "src/bootstrap" , default : false } ) ;
561
+ tool_check_step ! ( Clippy { path: "src/tools/clippy" , mode: Mode :: ToolRustc } ) ;
562
+ tool_check_step ! ( Miri { path: "src/tools/miri" , mode: Mode :: ToolRustc } ) ;
563
+ tool_check_step ! ( CargoMiri { path: "src/tools/miri/cargo-miri" , mode: Mode :: ToolRustc } ) ;
564
+ tool_check_step ! ( Rustfmt { path: "src/tools/rustfmt" , mode: Mode :: ToolRustc } ) ;
565
+ tool_check_step ! ( MiroptTestTools {
566
+ path: "src/tools/miropt-test-tools" ,
567
+ mode: Mode :: ToolBootstrap
568
+ } ) ;
569
+ // We want to test the local std
570
+ tool_check_step ! ( TestFloatParse { path: "src/tools/test-float-parse" , mode: Mode :: ToolStd } ) ;
571
+ tool_check_step ! ( FeaturesStatusDump {
572
+ path: "src/tools/features-status-dump" ,
573
+ mode: Mode :: ToolBootstrap
574
+ } ) ;
575
+
576
+ tool_check_step ! ( Bootstrap { path: "src/bootstrap" , mode: Mode :: ToolBootstrap , default : false } ) ;
529
577
530
578
// `run-make-support` will be built as part of suitable run-make compiletest test steps, but support
531
579
// check to make it easier to work on.
532
- tool_check_step ! ( RunMakeSupport { path: "src/tools/run-make-support" , default : false } ) ;
580
+ tool_check_step ! ( RunMakeSupport {
581
+ path: "src/tools/run-make-support" ,
582
+ mode: Mode :: ToolBootstrap ,
583
+ default : false
584
+ } ) ;
533
585
534
586
/// Check step for the `coverage-dump` bootstrap tool. The coverage-dump tool
535
587
/// is used internally by coverage tests.
0 commit comments