@@ -9,7 +9,7 @@ use crate::core::builder::{
9
9
} ;
10
10
use crate :: core:: config:: TargetSelection ;
11
11
use crate :: utils:: build_stamp:: { self , BuildStamp } ;
12
- use crate :: { Mode , Subcommand } ;
12
+ use crate :: { Compiler , Mode , Subcommand } ;
13
13
14
14
#[ derive( Debug , Clone , PartialEq , Eq , Hash ) ]
15
15
pub struct Std {
@@ -27,17 +27,25 @@ pub struct Std {
27
27
/// passing `Builder::kind` to cargo invocations would run clippy on the entire compiler and library,
28
28
/// which is not useful if we only want to lint a few crates with specific rules.
29
29
override_build_kind : Option < Kind > ,
30
+
31
+ override_compiler : Option < Compiler > ,
30
32
}
31
33
32
34
impl Std {
33
35
pub fn new ( target : TargetSelection ) -> Self {
34
- Self { target, crates : vec ! [ ] , override_build_kind : None }
36
+ Self { target, crates : vec ! [ ] , override_build_kind : None , override_compiler : None }
35
37
}
36
38
37
39
pub fn build_kind ( mut self , kind : Option < Kind > ) -> Self {
38
40
self . override_build_kind = kind;
39
41
self
40
42
}
43
+
44
+ /// Override the compiler used. Needed when checking tools that use [`Mode::ToolStd`].
45
+ pub fn with_compiler ( mut self , compiler : Compiler ) -> Self {
46
+ self . override_compiler = Some ( compiler) ;
47
+ self
48
+ }
41
49
}
42
50
43
51
impl Step for Std {
@@ -53,14 +61,21 @@ impl Step for Std {
53
61
54
62
fn make_run ( run : RunConfig < ' _ > ) {
55
63
let crates = std_crates_for_run_make ( & run) ;
56
- run. builder . ensure ( Std { target : run. target , crates, override_build_kind : None } ) ;
64
+ run. builder . ensure ( Std {
65
+ target : run. target ,
66
+ crates,
67
+ override_build_kind : None ,
68
+ override_compiler : None ,
69
+ } ) ;
57
70
}
58
71
59
72
fn run ( self , builder : & Builder < ' _ > ) {
60
73
builder. require_submodule ( "library/stdarch" , None ) ;
61
74
62
75
let target = self . target ;
63
- let compiler = builder. compiler ( builder. top_stage , builder. config . build ) ;
76
+ let compiler = self
77
+ . override_compiler
78
+ . unwrap_or_else ( || builder. compiler ( builder. top_stage , builder. config . build ) ) ;
64
79
65
80
let mut cargo = builder:: Cargo :: new (
66
81
builder,
@@ -375,6 +390,8 @@ macro_rules! tool_check_step {
375
390
// The part of this path after the final '/' is also used as a display name.
376
391
path: $path: literal
377
392
$( , alt_path: $alt_path: literal ) *
393
+ , mode: $mode: path
394
+ $( , allow_features: $allow_features: expr ) ?
378
395
$( , default : $default: literal ) ?
379
396
$( , ) ?
380
397
}
@@ -400,7 +417,14 @@ macro_rules! tool_check_step {
400
417
401
418
fn run( self , builder: & Builder <' _>) {
402
419
let Self { target } = self ;
403
- run_tool_check_step( builder, target, stringify!( $name) , $path) ;
420
+
421
+ let allow_features = {
422
+ let mut _value: & [ & str ] = & [ ] ;
423
+ $( _value = $allow_features; ) ?
424
+ _value
425
+ } ;
426
+
427
+ run_tool_check_step( builder, target, $path, $mode, allow_features) ;
404
428
}
405
429
}
406
430
}
@@ -410,18 +434,34 @@ macro_rules! tool_check_step {
410
434
fn run_tool_check_step (
411
435
builder : & Builder < ' _ > ,
412
436
target : TargetSelection ,
413
- step_type_name : & str ,
414
437
path : & str ,
438
+ mode : Mode ,
439
+ allow_features : & [ & str ] ,
415
440
) {
416
441
let display_name = path. rsplit ( '/' ) . next ( ) . unwrap ( ) ;
417
- let compiler = builder. compiler ( builder. top_stage , builder. config . build ) ;
418
442
419
- builder. ensure ( Rustc :: new ( target, builder) ) ;
443
+ let host = builder. config . build ;
444
+ let compiler;
445
+
446
+ match mode {
447
+ Mode :: ToolBootstrap => {
448
+ compiler = builder. compiler ( 0 , host) ;
449
+ }
450
+ Mode :: ToolStd => {
451
+ compiler = builder. compiler ( 0 , host) ;
452
+ builder. ensure ( Std :: new ( target) . with_compiler ( compiler) ) ;
453
+ }
454
+ Mode :: ToolRustc => {
455
+ compiler = builder. compiler ( builder. top_stage , host) ;
456
+ builder. ensure ( Rustc :: new ( target, builder) ) ;
457
+ }
458
+ _ => panic ! ( "unexpected mode for tool check step: {mode:?}" ) ,
459
+ }
420
460
421
461
let mut cargo = prepare_tool_cargo (
422
462
builder,
423
463
compiler,
424
- Mode :: ToolRustc ,
464
+ mode ,
425
465
target,
426
466
builder. kind ,
427
467
path,
@@ -432,39 +472,62 @@ fn run_tool_check_step(
432
472
SourceType :: InTree ,
433
473
& [ ] ,
434
474
) ;
475
+ cargo. allow_features ( & allow_features. join ( "," ) ) ;
435
476
436
477
// For ./x.py clippy, don't run with --all-targets because
437
478
// linting tests and benchmarks can produce very noisy results
438
479
if builder. kind != Kind :: Clippy {
439
480
cargo. arg ( "--all-targets" ) ;
440
481
}
441
482
442
- let stamp = BuildStamp :: new ( & builder. cargo_out ( compiler, Mode :: ToolRustc , target) )
443
- . with_prefix ( & format ! ( "{}-check" , step_type_name . to_lowercase ( ) ) ) ;
483
+ let stamp = BuildStamp :: new ( & builder. cargo_out ( compiler, mode , target) )
484
+ . with_prefix ( & format ! ( "{display_name }-check" ) ) ;
444
485
445
- let _guard = builder. msg_check ( format ! ( "{display_name} artifacts" ) , target) ;
486
+ let _guard =
487
+ builder. msg_tool ( builder. kind , mode, display_name, compiler. stage , & compiler. host , & target) ;
446
488
run_cargo ( builder, cargo, builder. config . free_args . clone ( ) , & stamp, vec ! [ ] , true , false ) ;
447
489
}
448
490
449
- tool_check_step ! ( Rustdoc { path: "src/tools/rustdoc" , alt_path: "src/librustdoc" } ) ;
491
+ // FIXME: Some of these `Mode::ToolRustc` values might be wrong.
492
+ // (Historically, all tools were hardcoded to use `Mode::ToolRustc`.)
493
+
494
+ tool_check_step ! ( Rustdoc {
495
+ path: "src/tools/rustdoc" ,
496
+ alt_path: "src/librustdoc" ,
497
+ mode: Mode :: ToolRustc ,
498
+ } ) ;
450
499
// Clippy, miri and Rustfmt are hybrids. They are external tools, but use a git subtree instead
451
500
// of a submodule. Since the SourceType only drives the deny-warnings
452
501
// behavior, treat it as in-tree so that any new warnings in clippy will be
453
502
// rejected.
454
- tool_check_step ! ( Clippy { path: "src/tools/clippy" } ) ;
455
- tool_check_step ! ( Miri { path: "src/tools/miri" } ) ;
456
- tool_check_step ! ( CargoMiri { path: "src/tools/miri/cargo-miri" } ) ;
457
- tool_check_step ! ( Rustfmt { path: "src/tools/rustfmt" } ) ;
458
- tool_check_step ! ( MiroptTestTools { path: "src/tools/miropt-test-tools" } ) ;
459
- tool_check_step ! ( TestFloatParse { path: "src/etc/test-float-parse" } ) ;
460
- tool_check_step ! ( FeaturesStatusDump { path: "src/tools/features-status-dump" } ) ;
461
-
462
- tool_check_step ! ( Bootstrap { path: "src/bootstrap" , default : false } ) ;
503
+ tool_check_step ! ( Clippy { path: "src/tools/clippy" , mode: Mode :: ToolRustc } ) ;
504
+ tool_check_step ! ( Miri { path: "src/tools/miri" , mode: Mode :: ToolRustc } ) ;
505
+ tool_check_step ! ( CargoMiri { path: "src/tools/miri/cargo-miri" , mode: Mode :: ToolRustc } ) ;
506
+ tool_check_step ! ( Rustfmt { path: "src/tools/rustfmt" , mode: Mode :: ToolRustc } ) ;
507
+ tool_check_step ! ( MiroptTestTools { path: "src/tools/miropt-test-tools" , mode: Mode :: ToolRustc } ) ;
508
+ tool_check_step ! ( TestFloatParse { path: "src/etc/test-float-parse" , mode: Mode :: ToolRustc } ) ;
509
+ tool_check_step ! ( FeaturesStatusDump {
510
+ path: "src/tools/features-status-dump" ,
511
+ mode: Mode :: ToolRustc ,
512
+ } ) ;
513
+
514
+ tool_check_step ! ( Bootstrap { path: "src/bootstrap" , mode: Mode :: ToolBootstrap , default : false } ) ;
463
515
464
516
// `run-make-support` will be built as part of suitable run-make compiletest test steps, but support
465
517
// check to make it easier to work on.
466
- tool_check_step ! ( RunMakeSupport { path: "src/tools/run-make-support" , default : false } ) ;
518
+ tool_check_step ! ( RunMakeSupport {
519
+ path: "src/tools/run-make-support" ,
520
+ mode: Mode :: ToolBootstrap ,
521
+ default : false ,
522
+ } ) ;
467
523
468
524
// Compiletest is implicitly "checked" when it gets built in order to run tests,
469
525
// so this is mainly for people working on compiletest to run locally.
470
- tool_check_step ! ( Compiletest { path: "src/tools/compiletest" , default : false } ) ;
526
+ //
527
+ // Compiletest uses libtest internally, so it needs `Mode::ToolStd` and `#![feature(test)]`.
528
+ tool_check_step ! ( Compiletest {
529
+ path: "src/tools/compiletest" ,
530
+ mode: Mode :: ToolStd ,
531
+ allow_features: & [ "test" ] ,
532
+ default : false ,
533
+ } ) ;
0 commit comments