Skip to content

Commit 0f3bced

Browse files
committed
Convert a bunch of steps to is_supported
1 parent 640e87c commit 0f3bced

11 files changed

Lines changed: 355 additions & 228 deletions

File tree

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

Lines changed: 31 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, Kind, RunConfig, ShouldRun, Step, StepMetadata, SupportedConfig,
17+
Unsupported, crate_description,
1718
};
1819
use crate::core::config::TargetSelection;
1920
use crate::utils::build_stamp::{self, BuildStamp};
@@ -52,19 +53,30 @@ impl Step for Std {
5253
true
5354
}
5455

55-
fn make_run(run: RunConfig<'_>) {
56-
if !run.builder.download_rustc() && run.builder.config.skip_std_check_if_no_download_rustc {
57-
eprintln!(
58-
"WARNING: `--skip-std-check-if-no-download-rustc` flag was passed and `rust.download-rustc` is not available. Skipping."
59-
);
60-
return;
56+
fn is_supported(config: SupportedConfig<'_, Self>) -> Result<(), Unsupported<Self::Output>> {
57+
let dummy_stamp = BuildStamp::new(Path::new("/dev/null"));
58+
59+
if !config.builder.download_rustc()
60+
&& config.builder.config.skip_std_check_if_no_download_rustc
61+
{
62+
return Err(Unsupported::Skip(
63+
"`--skip-std-check-if-no-download-rustc` flag was passed and `rust.download-rustc` is not available".into(),
64+
dummy_stamp,
65+
));
6166
}
6267

63-
if run.builder.config.compile_time_deps {
64-
// libstd doesn't have any important build scripts and can't have any proc macros
65-
return;
68+
if config.builder.config.compile_time_deps {
69+
return Err(Unsupported::Skip(
70+
"libstd doesn't have any important build scripts and can't have any proc macros"
71+
.into(),
72+
dummy_stamp,
73+
));
6674
}
6775

76+
Ok(())
77+
}
78+
79+
fn make_run(run: RunConfig<'_>) {
6880
// Explicitly pass -p for all dependencies crates -- this will force cargo
6981
// to also check the tests/benches/examples for these crates, rather
7082
// than just the leaf crate.
@@ -626,13 +638,18 @@ impl Step for GccCodegenBackend {
626638
});
627639
}
628640

629-
fn run(self, builder: &Builder<'_>) {
641+
fn is_supported(config: SupportedConfig<'_, Self>) -> Result<(), Unsupported> {
630642
// FIXME: remove once https://github.com/rust-lang/rust/issues/112393 is resolved
631-
if builder.build.config.vendor {
632-
println!("Skipping checking of `rustc_codegen_gcc` with vendoring enabled.");
633-
return;
643+
if config.builder.build.config.vendor {
644+
Unsupported::skip(
645+
"`rustc_codegen_gcc` does not currently support vendoring, see #112393",
646+
)
647+
} else {
648+
Ok(())
634649
}
650+
}
635651

652+
fn run(self, builder: &Builder<'_>) {
636653
let build_compiler = self.build_compiler.build_compiler();
637654
let target = self.target;
638655

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

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,15 @@
1313
//! to pass a prebuilt Clippy from the outside when running `cargo clippy`, but that would be
1414
//! (as usual) a massive undertaking/refactoring.
1515
16-
use build_helper::exit;
17-
1816
use super::compile::{ArtifactKeepMode, run_cargo, rustc_cargo, std_cargo};
1917
use super::tool::{SourceType, prepare_tool_cargo};
2018
use crate::builder::{Builder, ShouldRun};
2119
use crate::core::build_steps::check::{CompilerForCheck, prepare_compiler_for_check};
2220
use crate::core::build_steps::compile::std_crates_for_run_make;
23-
use crate::core::builder;
24-
use crate::core::builder::{Alias, Kind, RunConfig, Step, StepMetadata, crate_description};
21+
use crate::core::builder::{
22+
self, Alias, Kind, RunConfig, Step, StepMetadata, SupportedConfig, Unsupported,
23+
crate_description,
24+
};
2525
use crate::utils::build_stamp::{self, BuildStamp};
2626
use crate::{Compiler, Mode, Subcommand, TargetSelection};
2727

@@ -534,17 +534,20 @@ impl Step for CI {
534534
false
535535
}
536536

537+
fn is_supported(config: SupportedConfig<'_, Self>) -> Result<(), Unsupported> {
538+
if config.builder.top_stage != 2 {
539+
Unsupported::fatal("`x clippy ci` should always be executed with --stage 2")
540+
} else {
541+
Ok(())
542+
}
543+
}
544+
537545
fn make_run(run: RunConfig<'_>) {
538546
let config = LintConfig::new(run.builder);
539547
run.builder.ensure(CI { target: run.target, config });
540548
}
541549

542550
fn run(self, builder: &Builder<'_>) -> Self::Output {
543-
if builder.top_stage != 2 {
544-
eprintln!("ERROR: `x clippy ci` should always be executed with --stage 2");
545-
exit!(1);
546-
}
547-
548551
// We want to check in-tree source using in-tree clippy. However, if we naively did
549552
// a stage 2 `x clippy ci`, it would *build* a stage 2 rustc, in order to lint stage 2
550553
// std, which is wasteful.

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

Lines changed: 20 additions & 7 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, crate_description,
26+
self, Builder, Cargo, Kind, MakeOrEnsure, RunConfig, ShouldRun, Step, StepMetadata,
27+
SupportedConfig, Unsupported, crate_description,
2828
};
2929
use crate::core::config::toml::target::DefaultLinuxLinkerOverride;
3030
use crate::core::config::{
@@ -901,6 +901,22 @@ impl Step for StartupObjects {
901901
});
902902
}
903903

904+
fn is_supported(config: SupportedConfig<'_, Self>) -> Result<(), Unsupported<Self::Output>> {
905+
let target = match config.extra {
906+
MakeOrEnsure::Run(run) => run.target,
907+
MakeOrEnsure::Step(this) => this.target,
908+
};
909+
// Even though no longer necessary on x86_64, they are kept for now to
910+
// avoid potential issues in downstream crates.
911+
if target.is_windows_gnu() {
912+
Ok(())
913+
} else {
914+
Unsupported::skip(
915+
"outside windows-gnu platforms, startup objects are handled by the platform C compiler",
916+
)
917+
}
918+
}
919+
904920
/// Builds and prepare startup objects like rsbegin.o and rsend.o
905921
///
906922
/// These are primarily used on Windows right now for linking executables/dlls.
@@ -910,11 +926,6 @@ impl Step for StartupObjects {
910926
fn run(self, builder: &Builder<'_>) -> Vec<(PathBuf, DependencyType)> {
911927
let for_compiler = self.compiler;
912928
let target = self.target;
913-
// Even though no longer necessary on x86_64, they are kept for now to
914-
// avoid potential issues in downstream crates.
915-
if !target.is_windows_gnu() {
916-
return vec![];
917-
}
918929

919930
let mut target_deps = vec![];
920931

@@ -1024,6 +1035,8 @@ impl Step for Rustc {
10241035
fn make_run(run: RunConfig<'_>) {
10251036
// If only `compiler` was passed, do not run this step.
10261037
// Instead the `Assemble` step will take care of compiling Rustc.
1038+
// NOTE: this doesn't use `is_supported` because the fact that `Rustc` is different
1039+
// from `Assemble` is an implementation detail.
10271040
if run.builder.paths == vec![PathBuf::from("compiler")] {
10281041
return;
10291042
}

src/bootstrap/src/core/build_steps/dist.rs

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,15 @@ use crate::core::build_steps::tool::{
2929
};
3030
use crate::core::build_steps::vendor::{VENDOR_DIR, Vendor};
3131
use crate::core::build_steps::{compile, llvm};
32-
use crate::core::builder::{Builder, Kind, RunConfig, ShouldRun, Step, StepMetadata};
32+
use crate::core::builder::{
33+
Builder, Kind, MakeOrEnsure, RunConfig, ShouldRun, Step, StepMetadata, SupportedConfig,
34+
Unsupported,
35+
};
3336
use crate::core::config::{GccCiMode, TargetSelection};
3437
use crate::utils::build_stamp::{self, BuildStamp};
3538
use crate::utils::channel::{self, Info};
3639
use crate::utils::exec::{BootstrapCommand, command};
37-
use crate::utils::helpers::{
38-
exe, is_dylib, move_file, t, target_supports_cranelift_backend, timeit,
39-
};
40+
use crate::utils::helpers::{exe, is_dylib, move_file, t, timeit};
4041
use crate::utils::tarball::{GeneratedTarball, OverlayKind, Tarball};
4142
use crate::{CodegenBackendKind, Compiler, DependencyType, FileType, LLVM_TOOLS, Mode, trace};
4243

@@ -432,12 +433,20 @@ impl Step for Mingw {
432433
run.builder.ensure(Mingw { target: run.target });
433434
}
434435

435-
fn run(self, builder: &Builder<'_>) -> Option<GeneratedTarball> {
436-
let target = self.target;
437-
if !target.contains("pc-windows-gnu") || !builder.config.dist_include_mingw_linker {
438-
return None;
436+
fn is_supported(config: SupportedConfig<'_, Self>) -> Result<(), Unsupported<Self::Output>> {
437+
let target = match config.extra {
438+
MakeOrEnsure::Run(run) => run.target,
439+
MakeOrEnsure::Step(this) => this.target,
440+
};
441+
if !target.contains("pc-windows-gnu") || !config.builder.config.dist_include_mingw_linker {
442+
Unsupported::skip("not a windows-gnu and `dist.include_mingw_linker` not enabled")
443+
} else {
444+
Ok(())
439445
}
446+
}
440447

448+
fn run(self, builder: &Builder<'_>) -> Option<GeneratedTarball> {
449+
let target = self.target;
441450
let mut tarball = Tarball::new(builder, "rust-mingw", &target.triple);
442451
tarball.set_product_name("Rust MinGW");
443452

@@ -1571,14 +1580,18 @@ impl Step for Miri {
15711580
});
15721581
}
15731582

1574-
fn run(self, builder: &Builder<'_>) -> Option<GeneratedTarball> {
1583+
fn is_supported(config: SupportedConfig<'_, Self>) -> Result<(), Unsupported<Self::Output>> {
15751584
// This prevents miri from being built for "dist" or "install"
15761585
// on the stable/beta channels. It is a nightly-only tool and should
15771586
// not be included.
1578-
if !builder.build.unstable_features() {
1579-
return None;
1587+
if !config.builder.unstable_features() {
1588+
Unsupported::skip("miri is nightly-only and is not shipped on beta or stable")
1589+
} else {
1590+
Ok(())
15801591
}
1592+
}
15811593

1594+
fn run(self, builder: &Builder<'_>) -> Option<GeneratedTarball> {
15821595
let miri = builder.ensure(tool::Miri::from_compilers(self.compilers));
15831596
let cargomiri = builder.ensure(tool::CargoMiri::from_compilers(self.compilers));
15841597

@@ -1637,7 +1650,7 @@ impl Step for CraneliftCodegenBackend {
16371650
}
16381651

16391652
let target = self.target;
1640-
if !target_supports_cranelift_backend(target) {
1653+
if !CodegenBackendKind::Cranelift.supports_target(target) {
16411654
builder.info("target not supported by rustc_codegen_cranelift. skipping");
16421655
return None;
16431656
}

src/bootstrap/src/core/build_steps/doc.rs

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ use crate::core::build_steps::tool::{
1616
self, RustcPrivateCompilers, SourceType, Tool, prepare_tool_cargo,
1717
};
1818
use crate::core::builder::{
19-
self, Builder, Compiler, Kind, RunConfig, ShouldRun, Step, StepMetadata, crate_description,
19+
self, Builder, Compiler, Kind, MakeOrEnsure, RunConfig, ShouldRun, Step, StepMetadata,
20+
SupportedConfig, Unsupported, crate_description,
2021
};
2122
use crate::core::config::{Config, TargetSelection};
2223
use crate::helpers::{submodule_path_of, symlink_dir, t, up_to_date};
@@ -652,12 +653,24 @@ impl Step for Std {
652653
builder.config.docs
653654
}
654655

655-
fn make_run(run: RunConfig<'_>) {
656-
let crates = compile::std_crates_for_run_make(&run);
657-
let target_is_no_std = run.builder.no_std(run.target).unwrap_or(false);
656+
fn is_supported(config: SupportedConfig<'_, Self>) -> Result<(), Unsupported<Self::Output>> {
657+
let crates_buf;
658+
let (crates, target) = match config.extra {
659+
MakeOrEnsure::Run(run) => {
660+
crates_buf = compile::std_crates_for_run_make(run);
661+
(&crates_buf, run.target)
662+
}
663+
MakeOrEnsure::Step(this) => (&this.crates, this.target),
664+
};
665+
let target_is_no_std = config.builder.no_std(target).unwrap_or(false);
658666
if crates.is_empty() && target_is_no_std {
659-
return;
667+
Unsupported::skip("no standard library crates supported for this no_std target")
668+
} else {
669+
Ok(())
660670
}
671+
}
672+
673+
fn make_run(run: RunConfig<'_>) {
661674
run.builder.ensure(Std {
662675
build_compiler: run.builder.compiler_for_std(run.builder.top_stage),
663676
target: run.target,
@@ -666,7 +679,7 @@ impl Step for Std {
666679
} else {
667680
DocumentationFormat::Html
668681
},
669-
crates,
682+
crates: compile::std_crates_for_run_make(&run),
670683
});
671684
}
672685

src/bootstrap/src/core/build_steps/llvm.rs

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ use build_helper::exit;
1818
use build_helper::git::PathFreshness;
1919

2020
use crate::core::build_steps::llvm;
21-
use crate::core::builder::{Builder, RunConfig, ShouldRun, Step, StepMetadata};
21+
use crate::core::builder::{
22+
Builder, MakeOrEnsure, RunConfig, ShouldRun, Step, StepMetadata, SupportedConfig, Unsupported,
23+
};
2224
use crate::core::config::{Config, TargetSelection};
2325
use crate::utils::build_stamp::{BuildStamp, generate_smart_stamp_hash};
2426
use crate::utils::exec::command;
@@ -1351,17 +1353,21 @@ impl Step for Sanitizers {
13511353
run.alias("sanitizers")
13521354
}
13531355

1356+
fn is_supported(config: SupportedConfig<'_, Self>) -> Result<(), Unsupported<Self::Output>> {
1357+
let compiler_rt_dir = config.builder.src.join("src/llvm-project/compiler-rt");
1358+
if !compiler_rt_dir.exists() {
1359+
Unsupported::skip("need llvm/compiler-rt checked out on disk to build sanitizers")
1360+
} else {
1361+
Ok(())
1362+
}
1363+
}
1364+
13541365
fn make_run(run: RunConfig<'_>) {
13551366
run.builder.ensure(Sanitizers { target: run.target });
13561367
}
13571368

13581369
/// Builds sanitizer runtime libraries.
13591370
fn run(self, builder: &Builder<'_>) -> Self::Output {
1360-
let compiler_rt_dir = builder.src.join("src/llvm-project/compiler-rt");
1361-
if !compiler_rt_dir.exists() {
1362-
return Vec::new();
1363-
}
1364-
13651371
let out_dir = builder.native_dir(self.target).join("sanitizers");
13661372
let runtimes = supported_sanitizers(&out_dir, self.target, &builder.config.channel);
13671373

@@ -1398,6 +1404,7 @@ impl Step for Sanitizers {
13981404
t!(stamp.remove());
13991405
let _time = helpers::timeit(builder);
14001406

1407+
let compiler_rt_dir = builder.src.join("src/llvm-project/compiler-rt");
14011408
let mut cfg = cmake::Config::new(&compiler_rt_dir);
14021409
cfg.profile("Release");
14031410
cfg.define("CMAKE_C_COMPILER_TARGET", self.target.triple);
@@ -1545,12 +1552,22 @@ impl Step for CrtBeginEnd {
15451552
run.path("src/llvm-project/compiler-rt/lib/crt")
15461553
}
15471554

1548-
fn make_run(run: RunConfig<'_>) {
1549-
if run.target.needs_crt_begin_end() {
1550-
run.builder.ensure(CrtBeginEnd { target: run.target });
1555+
fn is_supported(config: SupportedConfig<'_, Self>) -> Result<(), Unsupported<Self::Output>> {
1556+
let target = match config.extra {
1557+
MakeOrEnsure::Run(run) => run.target,
1558+
MakeOrEnsure::Step(this) => this.target,
1559+
};
1560+
if !target.needs_crt_begin_end() {
1561+
Unsupported::skip("no self-contained C runtime necessary for this target")
1562+
} else {
1563+
Ok(())
15511564
}
15521565
}
15531566

1567+
fn make_run(run: RunConfig<'_>) {
1568+
run.builder.ensure(CrtBeginEnd { target: run.target });
1569+
}
1570+
15541571
/// Build crtbegin.o/crtend.o for musl target.
15551572
fn run(self, builder: &Builder<'_>) -> Self::Output {
15561573
builder.require_submodule(

0 commit comments

Comments
 (0)