Skip to content

Commit fba8dfd

Browse files
authored
Rollup merge of #98513 - ehuss:rebuild-llvm-download, r=Mark-Simulacrum
Fix LLVM rebuild with download-ci-llvm. This fixes an issue where updating a local checkout that includes a change in `src/version` causes a linking failure. The cause is that the `rustc_llvm` build script uses `rerun-if-changed` of `llvm-config` to know if it needs to rerun. Cargo only compares the timestamp of the last time the build script to the file. However, extracting the tar files retains the timestamps in the tarball which may be some time in the past. Since `src/version` is included in the LLVM `.so` filename, `rustc` attempts to load the wrong shared library since the `rustc_llvm` build script doesn't rerun. rust-lang/cargo#10791 contains a more detailed explanation. The solution here is a hack which updates the timestamp of `llvm-config` to the current time when it is extracted. This is a bit of a hack, but seems to be the best solution I can think of until rust-lang/cargo#10791 is fixed. There are likely several other situations where this is a problem (such as using system LLVM), and this isn't really a complete fix. Note that apple platforms are not directly affected by this problem because they don't have a version in the dylib filename. How to test this: 1. On a linux host, enable download-ci-llvm 2. Check out 7036449 (the commit just before the last version bump) 3. `./x.py build library/std` 4. Check out 5f015a2 (the commit that bumped the version) 5. `./x.py build library/std` Fixes #98495
2 parents c3b2291 + 418b1fa commit fba8dfd

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

src/bootstrap/native.rs

+13
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,19 @@ pub(crate) fn maybe_download_ci_llvm(builder: &Builder<'_>) {
150150
for binary in ["llvm-config", "FileCheck"] {
151151
builder.fix_bin_or_dylib(&llvm_root.join("bin").join(binary));
152152
}
153+
154+
// Update the timestamp of llvm-config to force rustc_llvm to be
155+
// rebuilt. This is a hacky workaround for a deficiency in Cargo where
156+
// the rerun-if-changed directive doesn't handle changes very well.
157+
// https://github.com/rust-lang/cargo/issues/10791
158+
// Cargo only compares the timestamp of the file relative to the last
159+
// time `rustc_llvm` build script ran. However, the timestamps of the
160+
// files in the tarball are in the past, so it doesn't trigger a
161+
// rebuild.
162+
let now = filetime::FileTime::from_system_time(std::time::SystemTime::now());
163+
let llvm_config = llvm_root.join("bin/llvm-config");
164+
t!(filetime::set_file_times(&llvm_config, now, now));
165+
153166
let llvm_lib = llvm_root.join("lib");
154167
for entry in t!(fs::read_dir(&llvm_lib)) {
155168
let lib = t!(entry).path();

0 commit comments

Comments
 (0)