Skip to content

Commit 2a8c87b

Browse files
committed
Rebuild llvm spuriously less frequently
I noticed that `x check` was rebuilding rustc_llvm basically every time I modified a source file. I tracked this down to the following env variable change: ``` cargo::core::compiler::fingerprint: dirty: EnvVarChanged { name: "REAL_LIBRARY_PATH", old_value: Some("/home/jyn/.local/lib/rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib"), new_value: None } ``` The problem was that I had installed rust-analyzer from rustup, not as a standalone tool. As a result, rustup sets `LD_LIBRARY_PATH=$(rustc --print target-libdir)` in the environment under the assumption that rust-analyzer needs it to link to rustc_private crates. This is not in fact the case; RA does not link to rustc_private. But rustup does not know this. Ideally we would make rustup smarter, but that takes a while because rustup has infrequent releases. In the meantime, as a workaround, be a little more selective about when we forward LD_LIBRARY_PATH. See the new comment for more details.
1 parent 385970f commit 2a8c87b

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

src/bootstrap/src/core/builder/cargo.rs

+13-1
Original file line numberDiff line numberDiff line change
@@ -511,7 +511,19 @@ impl Builder<'_> {
511511
// needs to not accidentally link to libLLVM in stage0/lib.
512512
cargo.env("REAL_LIBRARY_PATH_VAR", helpers::dylib_path_var());
513513
if let Some(e) = env::var_os(helpers::dylib_path_var()) {
514-
cargo.env("REAL_LIBRARY_PATH", e);
514+
// We only need the original LIBRARY_PATH when using system llvm. In all other cases, we can
515+
// just discard it. This is useful because rust-analyzer sometimes has a different
516+
// LIBRARY_PATH than a baseline environment, causing spurious rebuilds.
517+
let ci_llvm = self.config.llvm_from_ci && target == self.build.build;
518+
let prebuilt_llvm = self
519+
.config
520+
.target_config
521+
.get(&target)
522+
.and_then(|conf| conf.llvm_config.as_ref())
523+
.is_some();
524+
if prebuilt_llvm && !ci_llvm {
525+
cargo.env("REAL_LIBRARY_PATH", e);
526+
}
515527
}
516528

517529
// Set a flag for `check`/`clippy`/`fix`, so that certain build

0 commit comments

Comments
 (0)