about summary refs log tree commit diff
path: root/src/bootstrap
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2020-05-03 02:58:00 +0000
committerbors <bors@rust-lang.org>2020-05-03 02:58:00 +0000
commit0a675c5e02e6ecfda7d4e04aabd23a9935e0c4bf (patch)
treea0682bf671337ddecfb6ac5752d6fad393bbb2b4 /src/bootstrap
parentc1e05528696ca523055b0f7ce94b8033dcbaa39e (diff)
parent7f645aba107e4b952c1ed47178ff74c5976b2663 (diff)
downloadrust-0a675c5e02e6ecfda7d4e04aabd23a9935e0c4bf.tar.gz
rust-0a675c5e02e6ecfda7d4e04aabd23a9935e0c4bf.zip
Auto merge of #71815 - Mark-Simulacrum:no-llvm-rebuild, r=jonas-schievink
Don't bust caches on x.py check/build switches

Fixes #71152
Diffstat (limited to 'src/bootstrap')
-rw-r--r--src/bootstrap/builder.rs12
-rw-r--r--src/bootstrap/compile.rs10
-rw-r--r--src/bootstrap/native.rs116
3 files changed, 88 insertions, 50 deletions
diff --git a/src/bootstrap/builder.rs b/src/bootstrap/builder.rs
index a897daf446d..028623aa7aa 100644
--- a/src/bootstrap/builder.rs
+++ b/src/bootstrap/builder.rs
@@ -765,9 +765,17 @@ impl<'a> Builder<'a> {
         }
 
         // Set a flag for `check`/`clippy`/`fix`, so that certain build
-        // scripts can do less work (e.g. not building/requiring LLVM).
+        // scripts can do less work (i.e. not building/requiring LLVM).
         if cmd == "check" || cmd == "clippy" || cmd == "fix" {
-            cargo.env("RUST_CHECK", "1");
+            // If we've not yet built LLVM, or it's stale, then bust
+            // the librustc_llvm cache. That will always work, even though it
+            // may mean that on the next non-check build we'll need to rebuild
+            // librustc_llvm. But if LLVM is stale, that'll be a tiny amount
+            // of work comparitively, and we'd likely need to rebuild it anyway,
+            // so that's okay.
+            if crate::native::prebuilt_llvm_config(self, target).is_err() {
+                cargo.env("RUST_CHECK", "1");
+            }
         }
 
         let stage = if compiler.stage == 0 && self.local_rebuild {
diff --git a/src/bootstrap/compile.rs b/src/bootstrap/compile.rs
index 0a193d91244..0c754936bc2 100644
--- a/src/bootstrap/compile.rs
+++ b/src/bootstrap/compile.rs
@@ -517,9 +517,13 @@ pub fn rustc_cargo_env(builder: &Builder<'_>, cargo: &mut Cargo, target: Interne
     // librustc_llvm and librustc_codegen_llvm.
     //
     // Note that this is disabled if LLVM itself is disabled or we're in a check
-    // build, where if we're in a check build there's no need to build all of
-    // LLVM and such.
-    if builder.config.llvm_enabled() && builder.kind != Kind::Check {
+    // build. If we are in a check build we still go ahead here presuming we've
+    // detected that LLVM is alreay built and good to go which helps prevent
+    // busting caches (e.g. like #71152).
+    if builder.config.llvm_enabled()
+        && (builder.kind != Kind::Check
+            || crate::native::prebuilt_llvm_config(builder, target).is_ok())
+    {
         if builder.is_rust_llvm(target) {
             cargo.env("LLVM_RUSTLLVM", "1");
         }
diff --git a/src/bootstrap/native.rs b/src/bootstrap/native.rs
index 0f39e33c5f4..bcd79a49ece 100644
--- a/src/bootstrap/native.rs
+++ b/src/bootstrap/native.rs
@@ -24,6 +24,72 @@ use crate::util::{self, exe};
 use crate::GitRepo;
 use build_helper::up_to_date;
 
+pub struct Meta {
+    stamp: HashStamp,
+    build_llvm_config: PathBuf,
+    out_dir: PathBuf,
+    root: String,
+}
+
+// This returns whether we've already previously built LLVM.
+//
+// It's used to avoid busting caches during x.py check -- if we've already built
+// LLVM, it's fine for us to not try to avoid doing so.
+//
+// This will return the llvm-config if it can get it (but it will not build it
+// if not).
+pub fn prebuilt_llvm_config(
+    builder: &Builder<'_>,
+    target: Interned<String>,
+) -> Result<PathBuf, Meta> {
+    // If we're using a custom LLVM bail out here, but we can only use a
+    // custom LLVM for the build triple.
+    if let Some(config) = builder.config.target_config.get(&target) {
+        if let Some(ref s) = config.llvm_config {
+            check_llvm_version(builder, s);
+            return Ok(s.to_path_buf());
+        }
+    }
+
+    let root = "src/llvm-project/llvm";
+    let out_dir = builder.llvm_out(target);
+    let mut llvm_config_ret_dir = builder.llvm_out(builder.config.build);
+    if !builder.config.build.contains("msvc") || builder.config.ninja {
+        llvm_config_ret_dir.push("build");
+    }
+    llvm_config_ret_dir.push("bin");
+
+    let build_llvm_config = llvm_config_ret_dir.join(exe("llvm-config", &*builder.config.build));
+
+    let stamp = out_dir.join("llvm-finished-building");
+    let stamp = HashStamp::new(stamp, builder.in_tree_llvm_info.sha());
+
+    if builder.config.llvm_skip_rebuild && stamp.path.exists() {
+        builder.info(
+            "Warning: \
+                Using a potentially stale build of LLVM; \
+                This may not behave well.",
+        );
+        return Ok(build_llvm_config);
+    }
+
+    if stamp.is_done() {
+        if stamp.hash.is_none() {
+            builder.info(
+                "Could not determine the LLVM submodule commit hash. \
+                     Assuming that an LLVM rebuild is not necessary.",
+            );
+            builder.info(&format!(
+                "To force LLVM to rebuild, remove the file `{}`",
+                stamp.path.display()
+            ));
+        }
+        return Ok(build_llvm_config);
+    }
+
+    Err(Meta { stamp, build_llvm_config, out_dir, root: root.into() })
+}
+
 #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
 pub struct Llvm {
     pub target: Interned<String>,
@@ -46,51 +112,11 @@ impl Step for Llvm {
     fn run(self, builder: &Builder<'_>) -> PathBuf {
         let target = self.target;
 
-        // If we're using a custom LLVM bail out here, but we can only use a
-        // custom LLVM for the build triple.
-        if let Some(config) = builder.config.target_config.get(&target) {
-            if let Some(ref s) = config.llvm_config {
-                check_llvm_version(builder, s);
-                return s.to_path_buf();
-            }
-        }
-
-        let root = "src/llvm-project/llvm";
-        let out_dir = builder.llvm_out(target);
-        let mut llvm_config_ret_dir = builder.llvm_out(builder.config.build);
-        if !builder.config.build.contains("msvc") || builder.config.ninja {
-            llvm_config_ret_dir.push("build");
-        }
-        llvm_config_ret_dir.push("bin");
-
-        let build_llvm_config =
-            llvm_config_ret_dir.join(exe("llvm-config", &*builder.config.build));
-
-        let stamp = out_dir.join("llvm-finished-building");
-        let stamp = HashStamp::new(stamp, builder.in_tree_llvm_info.sha());
-
-        if builder.config.llvm_skip_rebuild && stamp.path.exists() {
-            builder.info(
-                "Warning: \
-                Using a potentially stale build of LLVM; \
-                This may not behave well.",
-            );
-            return build_llvm_config;
-        }
-
-        if stamp.is_done() {
-            if stamp.hash.is_none() {
-                builder.info(
-                    "Could not determine the LLVM submodule commit hash. \
-                     Assuming that an LLVM rebuild is not necessary.",
-                );
-                builder.info(&format!(
-                    "To force LLVM to rebuild, remove the file `{}`",
-                    stamp.path.display()
-                ));
-            }
-            return build_llvm_config;
-        }
+        let Meta { stamp, build_llvm_config, out_dir, root } =
+            match prebuilt_llvm_config(builder, target) {
+                Ok(p) => return p,
+                Err(m) => m,
+            };
 
         builder.info(&format!("Building LLVM for {}", target));
         t!(stamp.remove());