Skip to content

Commit d634c1c

Browse files
committed
avoid rustc_llvm rebuilds when LD_LIBRARY_PATH changes
1 parent e4d6307 commit d634c1c

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

compiler/rustc_llvm/build.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,12 @@ fn detect_llvm_link() -> (&'static str, &'static str) {
4646
// perfect -- we might actually want to see something from Cargo's added library paths -- but
4747
// for now it works.
4848
fn restore_library_path() {
49-
let key = tracked_env_var_os("REAL_LIBRARY_PATH_VAR").expect("REAL_LIBRARY_PATH_VAR");
50-
if let Some(env) = tracked_env_var_os("REAL_LIBRARY_PATH") {
51-
env::set_var(&key, &env);
52-
} else {
53-
env::remove_var(&key);
49+
if let Some(key) = tracked_env_var_os("REAL_LIBRARY_PATH_VAR") {
50+
if let Some(env) = tracked_env_var_os("REAL_LIBRARY_PATH") {
51+
env::set_var(&key, &env);
52+
} else {
53+
env::remove_var(&key);
54+
}
5455
}
5556
}
5657

src/bootstrap/builder.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -1361,9 +1361,11 @@ impl<'a> Builder<'a> {
13611361

13621362
// See comment in rustc_llvm/build.rs for why this is necessary, largely llvm-config
13631363
// needs to not accidentally link to libLLVM in stage0/lib.
1364-
cargo.env("REAL_LIBRARY_PATH_VAR", &util::dylib_path_var());
1365-
if let Some(e) = env::var_os(util::dylib_path_var()) {
1366-
cargo.env("REAL_LIBRARY_PATH", e);
1364+
if !self.config.llvm_from_ci {
1365+
cargo.env("REAL_LIBRARY_PATH_VAR", &util::dylib_path_var());
1366+
if let Some(e) = env::var_os(util::dylib_path_var()) {
1367+
cargo.env("REAL_LIBRARY_PATH", e);
1368+
}
13671369
}
13681370

13691371
// Found with `rg "init_env_logger\("`. If anyone uses `init_env_logger`

0 commit comments

Comments
 (0)