Skip to content

Commit 7f645ab

Browse files
Don't skip building LLVM if already built
1 parent 131e120 commit 7f645ab

File tree

3 files changed

+18
-6
lines changed

3 files changed

+18
-6
lines changed

src/bootstrap/builder.rs

+10-2
Original file line numberDiff line numberDiff line change
@@ -765,9 +765,17 @@ impl<'a> Builder<'a> {
765765
}
766766

767767
// Set a flag for `check`/`clippy`/`fix`, so that certain build
768-
// scripts can do less work (e.g. not building/requiring LLVM).
768+
// scripts can do less work (i.e. not building/requiring LLVM).
769769
if cmd == "check" || cmd == "clippy" || cmd == "fix" {
770-
cargo.env("RUST_CHECK", "1");
770+
// If we've not yet built LLVM, or it's stale, then bust
771+
// the librustc_llvm cache. That will always work, even though it
772+
// may mean that on the next non-check build we'll need to rebuild
773+
// librustc_llvm. But if LLVM is stale, that'll be a tiny amount
774+
// of work comparitively, and we'd likely need to rebuild it anyway,
775+
// so that's okay.
776+
if crate::native::prebuilt_llvm_config(self, target).is_err() {
777+
cargo.env("RUST_CHECK", "1");
778+
}
771779
}
772780

773781
let stage = if compiler.stage == 0 && self.local_rebuild {

src/bootstrap/compile.rs

+7-3
Original file line numberDiff line numberDiff line change
@@ -517,9 +517,13 @@ pub fn rustc_cargo_env(builder: &Builder<'_>, cargo: &mut Cargo, target: Interne
517517
// librustc_llvm and librustc_codegen_llvm.
518518
//
519519
// Note that this is disabled if LLVM itself is disabled or we're in a check
520-
// build, where if we're in a check build there's no need to build all of
521-
// LLVM and such.
522-
if builder.config.llvm_enabled() && builder.kind != Kind::Check {
520+
// build. If we are in a check build we still go ahead here presuming we've
521+
// detected that LLVM is alreay built and good to go which helps prevent
522+
// busting caches (e.g. like #71152).
523+
if builder.config.llvm_enabled()
524+
&& (builder.kind != Kind::Check
525+
|| crate::native::prebuilt_llvm_config(builder, target).is_ok())
526+
{
523527
if builder.is_rust_llvm(target) {
524528
cargo.env("LLVM_RUSTLLVM", "1");
525529
}

src/librustc_llvm/build.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ fn detect_llvm_link() -> (&'static str, &'static str) {
1515
}
1616

1717
fn main() {
18+
println!("cargo:rerun-if-env-changed=RUST_CHECK");
1819
if env::var_os("RUST_CHECK").is_some() {
1920
// If we're just running `check`, there's no need for LLVM to be built.
20-
println!("cargo:rerun-if-env-changed=RUST_CHECK");
2121
return;
2222
}
2323

0 commit comments

Comments
 (0)