diff --git a/src/bootstrap/src/core/build_steps/compile.rs b/src/bootstrap/src/core/build_steps/compile.rs index b475c9c81494c..0db47ad82990a 100644 --- a/src/bootstrap/src/core/build_steps/compile.rs +++ b/src/bootstrap/src/core/build_steps/compile.rs @@ -1393,7 +1393,7 @@ pub fn rustc_cargo_env(builder: &Builder<'_>, cargo: &mut Cargo, target: TargetS if builder.config.llvm_enabled(target) { let building_llvm_is_expensive = prebuilt_llvm_output(builder, target).is_none(); - let skip_llvm = (builder.kind == Kind::Check) && building_llvm_is_expensive; + let skip_llvm = (cargo.kind() == Kind::Check) && building_llvm_is_expensive; if !skip_llvm { rustc_llvm_env(builder, cargo, target) } diff --git a/src/bootstrap/src/core/build_steps/llvm.rs b/src/bootstrap/src/core/build_steps/llvm.rs index 5d188bcd25570..0dd384c73962a 100644 --- a/src/bootstrap/src/core/build_steps/llvm.rs +++ b/src/bootstrap/src/core/build_steps/llvm.rs @@ -168,7 +168,13 @@ pub fn prebuilt_llvm_output(builder: &Builder<'_>, target: TargetSelection) -> O kind: LlvmKind::External, }); } - None + + // If LLVM is not available from CI, not externally, it is still possible that it was already + // built locally before. In that case we still treat it as prebuilt config. + match get_locally_built_llvm_build_status(builder, target) { + LlvmBuildStatus::AlreadyBuilt(output) => Some(output), + LlvmBuildStatus::ShouldBuild(_) => None, + } } /// This returns whether we've already previously built LLVM. @@ -186,6 +192,16 @@ pub fn get_llvm_build_status(builder: &Builder<'_>, target: TargetSelection) -> // If submodules are disabled, this does nothing. builder.config.update_submodule("src/llvm-project"); + get_locally_built_llvm_build_status(builder, target) +} + +/// Return build status of LLVM, considering only the (possibly) locally built LLVM. +/// +/// Calling this function should never attempt to checkout the LLVM submodule. +fn get_locally_built_llvm_build_status( + builder: &Builder<'_>, + target: TargetSelection, +) -> LlvmBuildStatus { let out_dir = builder.llvm_out(target); let build_llvm_config = if let Some(build_llvm_config) = builder diff --git a/src/bootstrap/src/core/builder/cargo.rs b/src/bootstrap/src/core/builder/cargo.rs index 93ec4a11f9083..8b92efa8b08c4 100644 --- a/src/bootstrap/src/core/builder/cargo.rs +++ b/src/bootstrap/src/core/builder/cargo.rs @@ -152,6 +152,7 @@ pub(crate) struct Cargo { build_compiler_stage: u32, extra_rustflags: Vec, profile: Option<&'static str>, + kind: Kind, } impl Cargo { @@ -203,6 +204,10 @@ impl Cargo { self.into() } + pub(crate) fn kind(&self) -> Kind { + self.kind + } + /// Same as [`Cargo::new`] except this one doesn't configure the linker with /// [`Cargo::configure_linker`]. #[track_caller] @@ -1530,6 +1535,7 @@ impl Builder<'_> { build_compiler_stage, extra_rustflags, profile, + kind: cmd_kind, } } } diff --git a/src/bootstrap/src/core/builder/tests.rs b/src/bootstrap/src/core/builder/tests.rs index 465c7d8a82726..293e9c29d719b 100644 --- a/src/bootstrap/src/core/builder/tests.rs +++ b/src/bootstrap/src/core/builder/tests.rs @@ -2704,8 +2704,7 @@ mod snapshot { ctx.config("clippy") .path("miri") .stage(1) - .render_steps(), @r" - [build] llvm + .render_steps(), @" [check] rustc 0 -> rustc 1 [clippy] rustc 0 -> miri 1 ");