about summary refs log tree commit diff
diff options
context:
space:
mode:
authorManish Goregaokar <manishsmail@gmail.com>2020-07-22 16:34:50 -0700
committerGitHub <noreply@github.com>2020-07-22 16:34:50 -0700
commitb32383ca901b01192e8110afab8421a20062caa4 (patch)
tree1fd7e116f0ca341d398fdf157cb5f2606791cfc2
parent7b28e7bf6bd209b76639748b1ab15ac65b586e22 (diff)
parent7be36a86f7b7798e662d844b33bd744a136b4f60 (diff)
downloadrust-b32383ca901b01192e8110afab8421a20062caa4.tar.gz
rust-b32383ca901b01192e8110afab8421a20062caa4.zip
Rollup merge of #74643 - petrochenkov:noenvrerun, r=Mark-Simulacrum
build: Remove unnecessary `cargo:rerun-if-env-changed` annotations

... and a couple of related cleanups.

rustc and cargo now track the majority of env var dependencies automatically (https://github.com/rust-lang/cargo/pull/8421), so the annotations are no longer necessary.
-rw-r--r--src/build_helper/lib.rs16
-rw-r--r--src/libprofiler_builtins/Cargo.toml1
-rw-r--r--src/libprofiler_builtins/build.rs2
-rw-r--r--src/librustc_ast/build.rs5
-rw-r--r--src/librustc_attr/Cargo.toml1
-rw-r--r--src/librustc_attr/build.rs5
-rw-r--r--src/librustc_codegen_llvm/build.rs6
-rw-r--r--src/librustc_codegen_ssa/build.rs4
-rw-r--r--src/librustc_driver/build.rs7
-rw-r--r--src/librustc_incremental/build.rs4
-rw-r--r--src/librustc_interface/build.rs4
-rw-r--r--src/librustc_llvm/Cargo.toml1
-rw-r--r--src/librustc_llvm/build.rs24
-rw-r--r--src/librustc_metadata/build.rs5
-rw-r--r--src/librustc_middle/build.rs12
-rw-r--r--src/librustc_session/session.rs2
-rw-r--r--src/librustc_target/build.rs4
-rw-r--r--src/libstd/Cargo.toml1
-rw-r--r--src/libstd/build.rs1
-rw-r--r--src/libunwind/Cargo.toml1
-rw-r--r--src/tools/error_index_generator/Cargo.toml1
21 files changed, 26 insertions, 81 deletions
diff --git a/src/build_helper/lib.rs b/src/build_helper/lib.rs
index 43c3c5773ce..e30da8d56e1 100644
--- a/src/build_helper/lib.rs
+++ b/src/build_helper/lib.rs
@@ -1,3 +1,5 @@
+use std::ffi::{OsStr, OsString};
+use std::fmt::Display;
 use std::path::{Path, PathBuf};
 use std::process::{Command, Stdio};
 use std::time::{SystemTime, UNIX_EPOCH};
@@ -28,6 +30,14 @@ macro_rules! t {
     };
 }
 
+/// Reads an environment variable and adds it to dependencies.
+/// Supposed to be used for all variables except those set for build scripts by cargo
+/// https://doc.rust-lang.org/cargo/reference/environment-variables.html#environment-variables-cargo-sets-for-build-scripts
+pub fn tracked_env_var_os<K: AsRef<OsStr> + Display>(key: K) -> Option<OsString> {
+    println!("cargo:rerun-if-env-changed={}", key);
+    env::var_os(key)
+}
+
 // Because Cargo adds the compiler's dylib path to our library search path, llvm-config may
 // break: the dylib path for the compiler, as of this writing, contains a copy of the LLVM
 // shared library, which means that when our freshly built llvm-config goes to load it's
@@ -37,10 +47,8 @@ macro_rules! t {
 // perfect -- we might actually want to see something from Cargo's added library paths -- but
 // for now it works.
 pub fn restore_library_path() {
-    println!("cargo:rerun-if-env-changed=REAL_LIBRARY_PATH_VAR");
-    println!("cargo:rerun-if-env-changed=REAL_LIBRARY_PATH");
-    let key = env::var_os("REAL_LIBRARY_PATH_VAR").expect("REAL_LIBRARY_PATH_VAR");
-    if let Some(env) = env::var_os("REAL_LIBRARY_PATH") {
+    let key = tracked_env_var_os("REAL_LIBRARY_PATH_VAR").expect("REAL_LIBRARY_PATH_VAR");
+    if let Some(env) = tracked_env_var_os("REAL_LIBRARY_PATH") {
         env::set_var(&key, &env);
     } else {
         env::remove_var(&key);
diff --git a/src/libprofiler_builtins/Cargo.toml b/src/libprofiler_builtins/Cargo.toml
index 0d36bd0b39d..899f923b957 100644
--- a/src/libprofiler_builtins/Cargo.toml
+++ b/src/libprofiler_builtins/Cargo.toml
@@ -1,6 +1,5 @@
 [package]
 authors = ["The Rust Project Developers"]
-build = "build.rs"
 name = "profiler_builtins"
 version = "0.0.0"
 edition = "2018"
diff --git a/src/libprofiler_builtins/build.rs b/src/libprofiler_builtins/build.rs
index bb7d59e113c..d2cb873058c 100644
--- a/src/libprofiler_builtins/build.rs
+++ b/src/libprofiler_builtins/build.rs
@@ -9,6 +9,8 @@ fn main() {
     let target = env::var("TARGET").expect("TARGET was not set");
     let cfg = &mut cc::Build::new();
 
+    // FIXME: `rerun-if-changed` directives are not currently emitted and the build script
+    // will not rerun on changes in these source files or headers included into them.
     let mut profile_sources = vec![
         "GCDAProfiling.c",
         "InstrProfiling.c",
diff --git a/src/librustc_ast/build.rs b/src/librustc_ast/build.rs
deleted file mode 100644
index 9b861f96409..00000000000
--- a/src/librustc_ast/build.rs
+++ /dev/null
@@ -1,5 +0,0 @@
-fn main() {
-    println!("cargo:rerun-if-changed=build.rs");
-    println!("cargo:rerun-if-env-changed=CFG_RELEASE_CHANNEL");
-    println!("cargo:rerun-if-env-changed=CFG_DISABLE_UNSTABLE_FEATURES");
-}
diff --git a/src/librustc_attr/Cargo.toml b/src/librustc_attr/Cargo.toml
index 677796a8df0..496becb8f1b 100644
--- a/src/librustc_attr/Cargo.toml
+++ b/src/librustc_attr/Cargo.toml
@@ -3,7 +3,6 @@ authors = ["The Rust Project Developers"]
 name = "rustc_attr"
 version = "0.0.0"
 edition = "2018"
-build = "build.rs"
 
 [lib]
 name = "rustc_attr"
diff --git a/src/librustc_attr/build.rs b/src/librustc_attr/build.rs
deleted file mode 100644
index 863f2b7337b..00000000000
--- a/src/librustc_attr/build.rs
+++ /dev/null
@@ -1,5 +0,0 @@
-fn main() {
-    println!("cargo:rerun-if-changed=build.rs");
-    println!("cargo:rerun-if-env-changed=CFG_RELEASE");
-    println!("cargo:rerun-if-env-changed=CFG_RELEASE_CHANNEL");
-}
diff --git a/src/librustc_codegen_llvm/build.rs b/src/librustc_codegen_llvm/build.rs
deleted file mode 100644
index d1fc624c689..00000000000
--- a/src/librustc_codegen_llvm/build.rs
+++ /dev/null
@@ -1,6 +0,0 @@
-fn main() {
-    println!("cargo:rerun-if-changed=build.rs");
-    println!("cargo:rerun-if-env-changed=CFG_VERSION");
-    println!("cargo:rerun-if-env-changed=CFG_PREFIX");
-    println!("cargo:rerun-if-env-changed=CFG_LLVM_ROOT");
-}
diff --git a/src/librustc_codegen_ssa/build.rs b/src/librustc_codegen_ssa/build.rs
deleted file mode 100644
index ea2af6e192e..00000000000
--- a/src/librustc_codegen_ssa/build.rs
+++ /dev/null
@@ -1,4 +0,0 @@
-fn main() {
-    println!("cargo:rerun-if-changed=build.rs");
-    println!("cargo:rerun-if-env-changed=CFG_RELEASE_CHANNEL");
-}
diff --git a/src/librustc_driver/build.rs b/src/librustc_driver/build.rs
deleted file mode 100644
index 414d13445f0..00000000000
--- a/src/librustc_driver/build.rs
+++ /dev/null
@@ -1,7 +0,0 @@
-fn main() {
-    println!("cargo:rerun-if-changed=build.rs");
-    println!("cargo:rerun-if-env-changed=CFG_RELEASE");
-    println!("cargo:rerun-if-env-changed=CFG_VERSION");
-    println!("cargo:rerun-if-env-changed=CFG_VER_DATE");
-    println!("cargo:rerun-if-env-changed=CFG_VER_HASH");
-}
diff --git a/src/librustc_incremental/build.rs b/src/librustc_incremental/build.rs
deleted file mode 100644
index d230ba91039..00000000000
--- a/src/librustc_incremental/build.rs
+++ /dev/null
@@ -1,4 +0,0 @@
-fn main() {
-    println!("cargo:rerun-if-changed=build.rs");
-    println!("cargo:rerun-if-env-changed=CFG_VERSION");
-}
diff --git a/src/librustc_interface/build.rs b/src/librustc_interface/build.rs
deleted file mode 100644
index 79a343e0fee..00000000000
--- a/src/librustc_interface/build.rs
+++ /dev/null
@@ -1,4 +0,0 @@
-fn main() {
-    println!("cargo:rerun-if-changed=build.rs");
-    println!("cargo:rerun-if-env-changed=RUSTC_INSTALL_BINDIR");
-}
diff --git a/src/librustc_llvm/Cargo.toml b/src/librustc_llvm/Cargo.toml
index 1a034294cd8..9f2711eec10 100644
--- a/src/librustc_llvm/Cargo.toml
+++ b/src/librustc_llvm/Cargo.toml
@@ -2,7 +2,6 @@
 authors = ["The Rust Project Developers"]
 name = "rustc_llvm"
 version = "0.0.0"
-build = "build.rs"
 edition = "2018"
 
 [lib]
diff --git a/src/librustc_llvm/build.rs b/src/librustc_llvm/build.rs
index 78e27b10ec6..21b8080714c 100644
--- a/src/librustc_llvm/build.rs
+++ b/src/librustc_llvm/build.rs
@@ -2,12 +2,12 @@ use std::env;
 use std::path::{Path, PathBuf};
 use std::process::Command;
 
-use build_helper::output;
+use build_helper::{output, tracked_env_var_os};
 
 fn detect_llvm_link() -> (&'static str, &'static str) {
     // Force the link mode we want, preferring static by default, but
     // possibly overridden by `configure --enable-llvm-link-shared`.
-    if env::var_os("LLVM_LINK_SHARED").is_some() {
+    if tracked_env_var_os("LLVM_LINK_SHARED").is_some() {
         ("dylib", "--link-shared")
     } else {
         ("static", "--link-static")
@@ -15,8 +15,7 @@ fn detect_llvm_link() -> (&'static str, &'static str) {
 }
 
 fn main() {
-    println!("cargo:rerun-if-env-changed=RUST_CHECK");
-    if env::var_os("RUST_CHECK").is_some() {
+    if tracked_env_var_os("RUST_CHECK").is_some() {
         // If we're just running `check`, there's no need for LLVM to be built.
         return;
     }
@@ -25,8 +24,8 @@ fn main() {
 
     let target = env::var("TARGET").expect("TARGET was not set");
     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) {
+        tracked_env_var_os("LLVM_CONFIG").map(|x| Some(PathBuf::from(x))).unwrap_or_else(|| {
+            if let Some(dir) = tracked_env_var_os("CARGO_TARGET_DIR").map(PathBuf::from) {
                 let to_test = dir
                     .parent()
                     .unwrap()
@@ -46,8 +45,6 @@ fn main() {
     }
     let llvm_config = llvm_config.unwrap_or_else(|| PathBuf::from("llvm-config"));
 
-    println!("cargo:rerun-if-env-changed=LLVM_CONFIG");
-
     // Test whether we're cross-compiling LLVM. This is a pretty rare case
     // currently where we're producing an LLVM for a different platform than
     // what this build script is currently running on.
@@ -163,12 +160,11 @@ fn main() {
         cfg.define(&flag, None);
     }
 
-    println!("cargo:rerun-if-changed-env=LLVM_RUSTLLVM");
-    if env::var_os("LLVM_RUSTLLVM").is_some() {
+    if tracked_env_var_os("LLVM_RUSTLLVM").is_some() {
         cfg.define("LLVM_RUSTLLVM", None);
     }
 
-    if env::var_os("LLVM_NDEBUG").is_some() {
+    if tracked_env_var_os("LLVM_NDEBUG").is_some() {
         cfg.define("NDEBUG", None);
         cfg.debug(false);
     }
@@ -255,7 +251,7 @@ fn main() {
     // librustc_llvm, for example when using static libc++, we may need to
     // manually specify the library search path and -ldl -lpthread as link
     // dependencies.
-    let llvm_linker_flags = env::var_os("LLVM_LINKER_FLAGS");
+    let llvm_linker_flags = tracked_env_var_os("LLVM_LINKER_FLAGS");
     if let Some(s) = llvm_linker_flags {
         for lib in s.into_string().unwrap().split_whitespace() {
             if lib.starts_with("-l") {
@@ -266,8 +262,8 @@ fn main() {
         }
     }
 
-    let llvm_static_stdcpp = env::var_os("LLVM_STATIC_STDCPP");
-    let llvm_use_libcxx = env::var_os("LLVM_USE_LIBCXX");
+    let llvm_static_stdcpp = tracked_env_var_os("LLVM_STATIC_STDCPP");
+    let llvm_use_libcxx = tracked_env_var_os("LLVM_USE_LIBCXX");
 
     let stdcppname = if target.contains("openbsd") {
         if target.contains("sparc64") { "estdc++" } else { "c++" }
diff --git a/src/librustc_metadata/build.rs b/src/librustc_metadata/build.rs
deleted file mode 100644
index 7d5c58ecea2..00000000000
--- a/src/librustc_metadata/build.rs
+++ /dev/null
@@ -1,5 +0,0 @@
-fn main() {
-    println!("cargo:rerun-if-changed=build.rs");
-    println!("cargo:rerun-if-env-changed=CFG_VERSION");
-    println!("cargo:rerun-if-env-changed=CFG_VIRTUAL_RUST_SOURCE_BASE_DIR");
-}
diff --git a/src/librustc_middle/build.rs b/src/librustc_middle/build.rs
deleted file mode 100644
index af7723aea34..00000000000
--- a/src/librustc_middle/build.rs
+++ /dev/null
@@ -1,12 +0,0 @@
-use std::env;
-
-fn main() {
-    println!("cargo:rerun-if-changed=build.rs");
-    println!("cargo:rerun-if-env-changed=CFG_LIBDIR_RELATIVE");
-    println!("cargo:rerun-if-env-changed=CFG_COMPILER_HOST_TRIPLE");
-    println!("cargo:rerun-if-env-changed=RUSTC_VERIFY_LLVM_IR");
-
-    if env::var_os("RUSTC_VERIFY_LLVM_IR").is_some() {
-        println!("cargo:rustc-cfg=always_verify_llvm_ir");
-    }
-}
diff --git a/src/librustc_session/session.rs b/src/librustc_session/session.rs
index 4ad95e95e9a..1b8f6cdd8be 100644
--- a/src/librustc_session/session.rs
+++ b/src/librustc_session/session.rs
@@ -548,7 +548,7 @@ impl Session {
         self.opts.debugging_opts.asm_comments
     }
     pub fn verify_llvm_ir(&self) -> bool {
-        self.opts.debugging_opts.verify_llvm_ir || cfg!(always_verify_llvm_ir)
+        self.opts.debugging_opts.verify_llvm_ir || option_env!("RUSTC_VERIFY_LLVM_IR").is_some()
     }
     pub fn borrowck_stats(&self) -> bool {
         self.opts.debugging_opts.borrowck_stats
diff --git a/src/librustc_target/build.rs b/src/librustc_target/build.rs
deleted file mode 100644
index 368200b776d..00000000000
--- a/src/librustc_target/build.rs
+++ /dev/null
@@ -1,4 +0,0 @@
-fn main() {
-    println!("cargo:rerun-if-changed=build.rs");
-    println!("cargo:rerun-if-env-changed=CFG_DEFAULT_LINKER");
-}
diff --git a/src/libstd/Cargo.toml b/src/libstd/Cargo.toml
index 42403bdb1bc..f5d8119f711 100644
--- a/src/libstd/Cargo.toml
+++ b/src/libstd/Cargo.toml
@@ -2,7 +2,6 @@
 authors = ["The Rust Project Developers"]
 name = "std"
 version = "0.0.0"
-build = "build.rs"
 license = "MIT OR Apache-2.0"
 repository = "https://github.com/rust-lang/rust.git"
 description = "The Rust Standard Library"
diff --git a/src/libstd/build.rs b/src/libstd/build.rs
index 58fb6fda19a..83073cc77dd 100644
--- a/src/libstd/build.rs
+++ b/src/libstd/build.rs
@@ -1,6 +1,7 @@
 use std::env;
 
 fn main() {
+    println!("cargo:rerun-if-changed=build.rs");
     let target = env::var("TARGET").expect("TARGET was not set");
     if target.contains("linux") {
         if target.contains("android") {
diff --git a/src/libunwind/Cargo.toml b/src/libunwind/Cargo.toml
index 77bcfffd506..b6baa9a8c6b 100644
--- a/src/libunwind/Cargo.toml
+++ b/src/libunwind/Cargo.toml
@@ -2,7 +2,6 @@
 authors = ["The Rust Project Developers"]
 name = "unwind"
 version = "0.0.0"
-build = "build.rs"
 edition = "2018"
 include = [
   '/libunwind/*',
diff --git a/src/tools/error_index_generator/Cargo.toml b/src/tools/error_index_generator/Cargo.toml
index 992af261b83..787e08404e1 100644
--- a/src/tools/error_index_generator/Cargo.toml
+++ b/src/tools/error_index_generator/Cargo.toml
@@ -3,7 +3,6 @@ authors = ["The Rust Project Developers"]
 name = "error_index_generator"
 version = "0.0.0"
 edition = "2018"
-build = "build.rs"
 
 [dependencies]
 rustdoc = { path = "../../librustdoc" }