Skip to content

Commit 8d675dc

Browse files
committed
Split the bootstrap Step trait into multiple traits
Steps that can be selected from the command-line implement the full `CommandLineStep` trait, which also provides an implementation of `Step`. Helper tasks implement the smaller `Step` trait directly. They still participate in step-caching and step-tracing, but don't interact with command-line selectors.
1 parent 87e5904 commit 8d675dc

22 files changed

Lines changed: 238 additions & 298 deletions

File tree

src/bootstrap/src/core/build_steps/check.rs

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ use crate::core::build_steps::tool::{
1313
prepare_tool_cargo,
1414
};
1515
use crate::core::builder::{
16-
self, Alias, Builder, Cargo, Kind, RunConfig, ShouldRun, Step, StepMetadata, crate_description,
16+
self, Alias, Builder, Cargo, CommandLineStep, Kind, RunConfig, ShouldRun, Step, StepMetadata,
17+
crate_description,
1718
};
1819
use crate::core::config::TargetSelection;
1920
use crate::utils::build_stamp::{self, BuildStamp};
@@ -36,7 +37,7 @@ impl Std {
3637
const CRATE_OR_DEPS: &[&str] = &["sysroot", "coretests", "alloctests"];
3738
}
3839

39-
impl Step for Std {
40+
impl CommandLineStep for Std {
4041
type Output = BuildStamp;
4142

4243
fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
@@ -222,10 +223,6 @@ impl PrepareRustcRmetaSysroot {
222223
impl Step for PrepareRustcRmetaSysroot {
223224
type Output = RmetaSysroot;
224225

225-
fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
226-
run.never()
227-
}
228-
229226
fn run(self, builder: &Builder<'_>) -> Self::Output {
230227
// Check rustc
231228
let stamp = builder.ensure(Rustc::from_build_compiler(
@@ -266,10 +263,6 @@ impl PrepareStdRmetaSysroot {
266263
impl Step for PrepareStdRmetaSysroot {
267264
type Output = RmetaSysroot;
268265

269-
fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
270-
run.never()
271-
}
272-
273266
fn run(self, builder: &Builder<'_>) -> Self::Output {
274267
// Check std
275268
let stamp = builder.ensure(Std {
@@ -317,7 +310,7 @@ impl Rustc {
317310
}
318311
}
319312

320-
impl Step for Rustc {
313+
impl CommandLineStep for Rustc {
321314
type Output = BuildStamp;
322315
const IS_HOST: bool = true;
323316

@@ -528,7 +521,7 @@ pub struct CraneliftCodegenBackend {
528521
target: TargetSelection,
529522
}
530523

531-
impl Step for CraneliftCodegenBackend {
524+
impl CommandLineStep for CraneliftCodegenBackend {
532525
type Output = ();
533526
const IS_HOST: bool = true;
534527

@@ -607,7 +600,7 @@ pub struct GccCodegenBackend {
607600
target: TargetSelection,
608601
}
609602

610-
impl Step for GccCodegenBackend {
603+
impl CommandLineStep for GccCodegenBackend {
611604
type Output = ();
612605
const IS_HOST: bool = true;
613606

@@ -701,7 +694,7 @@ macro_rules! tool_check_step {
701694
target: TargetSelection,
702695
}
703696

704-
impl Step for $name {
697+
impl CommandLineStep for $name {
705698
type Output = ();
706699
const IS_HOST: bool = true;
707700

src/bootstrap/src/core/build_steps/clean.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,21 @@ use std::fs;
99
use std::io::{self, ErrorKind};
1010
use std::path::Path;
1111

12-
use crate::core::builder::{Builder, RunConfig, ShouldRun, Step, crate_description};
12+
use crate::core::builder::{Builder, CommandLineStep, RunConfig, ShouldRun, crate_description};
1313
use crate::utils::build_stamp::BuildStamp;
1414
use crate::utils::helpers::t;
1515
use crate::{Build, Compiler, Kind, Mode, Subcommand};
1616

1717
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1818
pub struct CleanAll {}
1919

20-
impl Step for CleanAll {
20+
impl CommandLineStep for CleanAll {
2121
type Output = ();
2222

2323
fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
24-
// Only runs as the default `./x clean` step; cannot be selected explicitly.
25-
run.never()
24+
// Normally this step is invoked implicitly via `./x clean`, but all
25+
// steps are required to register at least one explicit path/alias.
26+
run.alias("default")
2627
}
2728

2829
fn is_default_step(_builder: &Builder<'_>) -> bool {
@@ -54,7 +55,7 @@ macro_rules! clean_crate_tree {
5455
crates: Vec<String>,
5556
}
5657

57-
impl Step for $name {
58+
impl CommandLineStep for $name {
5859
type Output = ();
5960

6061
fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {

src/bootstrap/src/core/build_steps/clippy.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@ use crate::core::build_steps::compile::{
2020
ArtifactKeepMode, run_cargo, rustc_cargo, std_cargo, std_crates_for_make_run,
2121
};
2222
use crate::core::builder;
23-
use crate::core::builder::{Alias, Kind, RunConfig, Step, StepMetadata, crate_description};
23+
use crate::core::builder::{
24+
Alias, CommandLineStep, Kind, RunConfig, StepMetadata, crate_description,
25+
};
2426
use crate::utils::build_stamp::{self, BuildStamp};
2527
use crate::{Compiler, Mode, Subcommand, TargetSelection, exit};
2628

@@ -167,7 +169,7 @@ impl Std {
167169
}
168170
}
169171

170-
impl Step for Std {
172+
impl CommandLineStep for Std {
171173
type Output = ();
172174

173175
fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
@@ -251,7 +253,7 @@ impl Rustc {
251253
}
252254
}
253255

254-
impl Step for Rustc {
256+
impl CommandLineStep for Rustc {
255257
type Output = ();
256258
const IS_HOST: bool = true;
257259

@@ -336,7 +338,7 @@ impl CodegenGcc {
336338
}
337339
}
338340

339-
impl Step for CodegenGcc {
341+
impl CommandLineStep for CodegenGcc {
340342
type Output = ();
341343

342344
fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
@@ -422,7 +424,7 @@ macro_rules! lint_any {
422424
config: LintConfig,
423425
}
424426

425-
impl Step for $name {
427+
impl CommandLineStep for $name {
426428
type Output = ();
427429

428430
fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
@@ -522,7 +524,7 @@ pub struct CI {
522524
config: LintConfig,
523525
}
524526

525-
impl Step for CI {
527+
impl CommandLineStep for CI {
526528
type Output = ();
527529

528530
fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {

src/bootstrap/src/core/build_steps/compile.rs

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ use tracing::span;
2222
use crate::core::build_steps::gcc::{Gcc, GccOutput, GccTargetPair};
2323
use crate::core::build_steps::tool::{RustcPrivateCompilers, SourceType, copy_lld_artifacts};
2424
use crate::core::build_steps::{dist, llvm};
25-
use crate::core::builder;
2625
use crate::core::builder::{
27-
Builder, Cargo, Kind, RunConfig, ShouldRun, Step, StepMetadata, apply_pgo, crate_description,
26+
self, Builder, Cargo, CommandLineStep, Kind, RunConfig, ShouldRun, Step, StepMetadata,
27+
apply_pgo, crate_description,
2828
};
2929
use crate::core::config::toml::target::DefaultLinuxLinkerOverride;
3030
use crate::core::config::{
@@ -109,7 +109,7 @@ impl Std {
109109
}
110110
}
111111

112-
impl Step for Std {
112+
impl CommandLineStep for Std {
113113
/// Build stamp of std, if it was indeed built or uplifted.
114114
type Output = Option<BuildStamp>;
115115

@@ -743,10 +743,6 @@ impl StdLink {
743743
impl Step for StdLink {
744744
type Output = ();
745745

746-
fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
747-
run.never()
748-
}
749-
750746
/// Link all libstd rlibs/dylibs into the sysroot location.
751747
///
752748
/// Links those artifacts generated by `compiler` to the `stage` compiler's
@@ -900,7 +896,7 @@ pub struct StartupObjects {
900896
pub target: TargetSelection,
901897
}
902898

903-
impl Step for StartupObjects {
899+
impl CommandLineStep for StartupObjects {
904900
type Output = Vec<(PathBuf, DependencyType)>;
905901

906902
fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
@@ -1013,7 +1009,7 @@ impl Rustc {
10131009
}
10141010
}
10151011

1016-
impl Step for Rustc {
1012+
impl CommandLineStep for Rustc {
10171013
type Output = BuiltRustc;
10181014
const IS_HOST: bool = true;
10191015

@@ -1533,10 +1529,6 @@ impl RustcLink {
15331529
impl Step for RustcLink {
15341530
type Output = ();
15351531

1536-
fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
1537-
run.never()
1538-
}
1539-
15401532
/// Same as `StdLink`, only for librustc
15411533
fn run(self, builder: &Builder<'_>) {
15421534
let build_compiler = self.build_compiler;
@@ -1657,7 +1649,7 @@ impl GccCodegenBackend {
16571649
}
16581650
}
16591651

1660-
impl Step for GccCodegenBackend {
1652+
impl CommandLineStep for GccCodegenBackend {
16611653
type Output = GccCodegenBackendOutput;
16621654

16631655
const IS_HOST: bool = true;
@@ -1726,7 +1718,7 @@ pub struct CraneliftCodegenBackend {
17261718
pub compilers: RustcPrivateCompilers,
17271719
}
17281720

1729-
impl Step for CraneliftCodegenBackend {
1721+
impl CommandLineStep for CraneliftCodegenBackend {
17301722
type Output = BuildStamp;
17311723
const IS_HOST: bool = true;
17321724

@@ -1907,10 +1899,6 @@ impl Sysroot {
19071899
impl Step for Sysroot {
19081900
type Output = PathBuf;
19091901

1910-
fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
1911-
run.never()
1912-
}
1913-
19141902
/// Returns the sysroot that `compiler` is supposed to use.
19151903
/// For the stage0 compiler, this is stage0-sysroot (because of the initial std build).
19161904
/// For all other stages, it's the same stage directory that the compiler lives in.
@@ -2076,7 +2064,7 @@ pub struct Assemble {
20762064
pub target_compiler: Compiler,
20772065
}
20782066

2079-
impl Step for Assemble {
2067+
impl CommandLineStep for Assemble {
20802068
type Output = Compiler;
20812069
const IS_HOST: bool = true;
20822070

0 commit comments

Comments
 (0)