Skip to content

Commit 4c8b7b3

Browse files
authored
Rollup merge of #104375 - RalfJung:rustc_llvm_rebuild, r=jyn514,Mark-Simulacrum
avoid rustc_llvm rebuilds when LD_LIBRARY_PATH changes Currently the fairly slow rustc_llvm build script gets rerun every time LD_LIBRARY_PATH changes. So if one has an IDE setup where LD_LIBRARY_PATH inside the IDE differs from the one on the host, rebuilds happen all the time. With LLVM being downloaded from CI, this REAL_LIBRARY_PATH stuff does not seem needed any more, at least not on my system. But I also don't really understand what happens here. Does a patch like this make sense? r? `@jyn514` `@Mark-Simulacrum` Cc `@bjorn3`
2 parents 7bb7bf7 + d634c1c commit 4c8b7b3

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

compiler/rustc_llvm/build.rs

Lines changed: 6 additions & 5 deletions
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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1110,9 +1110,11 @@ impl<'a> Builder<'a> {
11101110

11111111
// See comment in rustc_llvm/build.rs for why this is necessary, largely llvm-config
11121112
// needs to not accidentally link to libLLVM in stage0/lib.
1113-
cargo.env("REAL_LIBRARY_PATH_VAR", &util::dylib_path_var());
1114-
if let Some(e) = env::var_os(util::dylib_path_var()) {
1115-
cargo.env("REAL_LIBRARY_PATH", e);
1113+
if !self.config.llvm_from_ci {
1114+
cargo.env("REAL_LIBRARY_PATH_VAR", &util::dylib_path_var());
1115+
if let Some(e) = env::var_os(util::dylib_path_var()) {
1116+
cargo.env("REAL_LIBRARY_PATH", e);
1117+
}
11161118
}
11171119

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

0 commit comments

Comments
 (0)