From ecc7dde80aeee02c6915057620739a2cea3c3e23 Mon Sep 17 00:00:00 2001 From: onur-ozkan Date: Mon, 2 Jun 2025 16:40:10 +0300 Subject: [PATCH] handle stage0 on `Std::check` Signed-off-by: onur-ozkan --- src/bootstrap/src/core/build_steps/check.rs | 27 +++++++++++++++++---- src/bootstrap/src/core/config/config.rs | 8 ++---- 2 files changed, 24 insertions(+), 11 deletions(-) diff --git a/src/bootstrap/src/core/build_steps/check.rs b/src/bootstrap/src/core/build_steps/check.rs index 922578f309a7..b64f0658c0ef 100644 --- a/src/bootstrap/src/core/build_steps/check.rs +++ b/src/bootstrap/src/core/build_steps/check.rs @@ -31,6 +31,8 @@ pub struct Std { } impl Std { + const CRATE_OR_DEPS: &[&str] = &["sysroot", "coretests", "alloctests"]; + pub fn new(target: TargetSelection) -> Self { Self { target, crates: vec![], override_build_kind: None } } @@ -47,11 +49,13 @@ impl Step for Std { fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> { let stage = run.builder.top_stage; - run.crate_or_deps("sysroot") - .crate_or_deps("coretests") - .crate_or_deps("alloctests") - .path("library") - .default_condition(stage != 0) + + let mut run = run; + for c in Std::CRATE_OR_DEPS { + run = run.crate_or_deps(c); + } + + run.path("library").default_condition(stage != 0) } fn make_run(run: RunConfig<'_>) { @@ -66,6 +70,19 @@ impl Step for Std { let compiler = builder.compiler(builder.top_stage, builder.config.build); if builder.top_stage == 0 { + let mut is_explicitly_called = + builder.paths.iter().any(|p| p.starts_with("library") || p.starts_with("std")); + + if !is_explicitly_called { + for c in Std::CRATE_OR_DEPS { + is_explicitly_called = builder.paths.iter().any(|p| p.starts_with(c)); + } + } + + if is_explicitly_called { + eprintln!("WARNING: stage 0 std is precompiled and does nothing during `x check`."); + } + // Reuse the stage0 libstd builder.ensure(compile::Std::new(compiler, target)); return; diff --git a/src/bootstrap/src/core/config/config.rs b/src/bootstrap/src/core/config/config.rs index 99e82ba7658c..03044d4fc804 100644 --- a/src/bootstrap/src/core/config/config.rs +++ b/src/bootstrap/src/core/config/config.rs @@ -2531,12 +2531,8 @@ impl Config { || bench_stage.is_some(); // See https://github.com/rust-lang/compiler-team/issues/326 config.stage = match config.cmd { - Subcommand::Check { .. } => { - flags.stage.or(check_stage).unwrap_or(0) - } - Subcommand::Clippy { .. } | Subcommand::Fix => { - flags.stage.or(check_stage).unwrap_or(1) - } + Subcommand::Check { .. } => flags.stage.or(check_stage).unwrap_or(0), + Subcommand::Clippy { .. } | Subcommand::Fix => flags.stage.or(check_stage).unwrap_or(1), // `download-rustc` only has a speed-up for stage2 builds. Default to stage2 unless explicitly overridden. Subcommand::Doc { .. } => { flags.stage.or(doc_stage).unwrap_or(if download_rustc { 2 } else { 1 })