Skip to content

Commit b32383c

Browse files
authored
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 (rust-lang/cargo#8421), so the annotations are no longer necessary.
2 parents 7b28e7b + 7be36a8 commit b32383c

File tree

21 files changed

+26
-81
lines changed

21 files changed

+26
-81
lines changed

src/build_helper/lib.rs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
use std::ffi::{OsStr, OsString};
2+
use std::fmt::Display;
13
use std::path::{Path, PathBuf};
24
use std::process::{Command, Stdio};
35
use std::time::{SystemTime, UNIX_EPOCH};
@@ -28,6 +30,14 @@ macro_rules! t {
2830
};
2931
}
3032

33+
/// Reads an environment variable and adds it to dependencies.
34+
/// Supposed to be used for all variables except those set for build scripts by cargo
35+
/// https://doc.rust-lang.org/cargo/reference/environment-variables.html#environment-variables-cargo-sets-for-build-scripts
36+
pub fn tracked_env_var_os<K: AsRef<OsStr> + Display>(key: K) -> Option<OsString> {
37+
println!("cargo:rerun-if-env-changed={}", key);
38+
env::var_os(key)
39+
}
40+
3141
// Because Cargo adds the compiler's dylib path to our library search path, llvm-config may
3242
// break: the dylib path for the compiler, as of this writing, contains a copy of the LLVM
3343
// shared library, which means that when our freshly built llvm-config goes to load it's
@@ -37,10 +47,8 @@ macro_rules! t {
3747
// perfect -- we might actually want to see something from Cargo's added library paths -- but
3848
// for now it works.
3949
pub fn restore_library_path() {
40-
println!("cargo:rerun-if-env-changed=REAL_LIBRARY_PATH_VAR");
41-
println!("cargo:rerun-if-env-changed=REAL_LIBRARY_PATH");
42-
let key = env::var_os("REAL_LIBRARY_PATH_VAR").expect("REAL_LIBRARY_PATH_VAR");
43-
if let Some(env) = env::var_os("REAL_LIBRARY_PATH") {
50+
let key = tracked_env_var_os("REAL_LIBRARY_PATH_VAR").expect("REAL_LIBRARY_PATH_VAR");
51+
if let Some(env) = tracked_env_var_os("REAL_LIBRARY_PATH") {
4452
env::set_var(&key, &env);
4553
} else {
4654
env::remove_var(&key);

src/libprofiler_builtins/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
[package]
22
authors = ["The Rust Project Developers"]
3-
build = "build.rs"
43
name = "profiler_builtins"
54
version = "0.0.0"
65
edition = "2018"

src/libprofiler_builtins/build.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ fn main() {
99
let target = env::var("TARGET").expect("TARGET was not set");
1010
let cfg = &mut cc::Build::new();
1111

12+
// FIXME: `rerun-if-changed` directives are not currently emitted and the build script
13+
// will not rerun on changes in these source files or headers included into them.
1214
let mut profile_sources = vec![
1315
"GCDAProfiling.c",
1416
"InstrProfiling.c",

src/librustc_ast/build.rs

Lines changed: 0 additions & 5 deletions
This file was deleted.

src/librustc_attr/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ authors = ["The Rust Project Developers"]
33
name = "rustc_attr"
44
version = "0.0.0"
55
edition = "2018"
6-
build = "build.rs"
76

87
[lib]
98
name = "rustc_attr"

src/librustc_attr/build.rs

Lines changed: 0 additions & 5 deletions
This file was deleted.

src/librustc_codegen_llvm/build.rs

Lines changed: 0 additions & 6 deletions
This file was deleted.

src/librustc_codegen_ssa/build.rs

Lines changed: 0 additions & 4 deletions
This file was deleted.

src/librustc_driver/build.rs

Lines changed: 0 additions & 7 deletions
This file was deleted.

src/librustc_incremental/build.rs

Lines changed: 0 additions & 4 deletions
This file was deleted.

0 commit comments

Comments
 (0)