about summary refs log tree commit diff
diff options
context:
space:
mode:
authorLuca Barbieri <luca@luca-barbieri.com>2020-04-10 22:42:19 +0200
committerMark Rousskov <mark.simulacrum@gmail.com>2020-04-11 17:49:16 -0400
commit3dd500de373757fd2b118db0c999e48dd01ff894 (patch)
tree435d7c6cba1f13f63078e02b7bbacf9872f88d3f
parent53d58dbf5f8a65189e5f97ef46da6593484a9e79 (diff)
downloadrust-3dd500de373757fd2b118db0c999e48dd01ff894.tar.gz
rust-3dd500de373757fd2b118db0c999e48dd01ff894.zip
Don't emit rerun-if-changed on llvm-config if using system LLVM
The code was broken because it printed "llvm-config" instead of the
absolute path to the llvm-config executable, causing Cargo to always
rebuild librustc_llvm if using system LLVM.

Also, it's not the build system's job to rebuild when a system library
changes, so we simply don't emit "rerun-if-changed" if a path to LLVM
was not explicitly provided.
-rw-r--r--src/librustc_llvm/build.rs30
1 files changed, 20 insertions, 10 deletions
diff --git a/src/librustc_llvm/build.rs b/src/librustc_llvm/build.rs
index fcaeaf2e4b0..f14fc9fc2eb 100644
--- a/src/librustc_llvm/build.rs
+++ b/src/librustc_llvm/build.rs
@@ -24,18 +24,28 @@ fn main() {
     build_helper::restore_library_path();
 
     let target = env::var("TARGET").expect("TARGET was not set");
-    let llvm_config = env::var_os("LLVM_CONFIG").map(PathBuf::from).unwrap_or_else(|| {
-        if let Some(dir) = env::var_os("CARGO_TARGET_DIR").map(PathBuf::from) {
-            let to_test =
-                dir.parent().unwrap().parent().unwrap().join(&target).join("llvm/bin/llvm-config");
-            if Command::new(&to_test).output().is_ok() {
-                return to_test;
+    let llvm_config =
+        env::var_os("LLVM_CONFIG").map(|x| Some(PathBuf::from(x))).unwrap_or_else(|| {
+            if let Some(dir) = env::var_os("CARGO_TARGET_DIR").map(PathBuf::from) {
+                let to_test = dir
+                    .parent()
+                    .unwrap()
+                    .parent()
+                    .unwrap()
+                    .join(&target)
+                    .join("llvm/bin/llvm-config");
+                if Command::new(&to_test).output().is_ok() {
+                    return Some(to_test);
+                }
             }
-        }
-        PathBuf::from("llvm-config")
-    });
+            None
+        });
+
+    if let Some(llvm_config) = &llvm_config {
+        println!("cargo:rerun-if-changed={}", llvm_config.display());
+    }
+    let llvm_config = llvm_config.unwrap_or_else(|| PathBuf::from("llvm-config"));
 
-    println!("cargo:rerun-if-changed={}", llvm_config.display());
     println!("cargo:rerun-if-env-changed=LLVM_CONFIG");
 
     // Test whether we're cross-compiling LLVM. This is a pretty rare case