Skip to content

Commit 0310497

Browse files
committed
Auto merge of #14761 - cuviper:rustc-meta, r=epage
Add more metadata to `rustc_fingerprint` Previously, `rustc_fingerprint` was only using the path and mtime for each executable, but this is not always sufficient. For example, Fedora will [clamp mtimes] to help reproducible builds, so Rust 1.82 looks like `/usr/bin/rustc` and `2024-10-17 00:00:00` across all builds in Fedora 39 through 42 (rawhide), even though they are different in their full version strings, LLVM, etc. [clamp mtimes]: https://fedoraproject.org/wiki/Changes/ReproducibleBuildsClampMtimes If the target directory (including `.rustc_info.json`) is shared across such systems, the fingerprint wouldn't notice the difference, and cargo would try to use artifacts that aren't actually compatible, like: ``` error[E0514]: found crate `autocfg` compiled by an incompatible version of rustc --> build.rs:2:14 | 2 | let ac = autocfg::new(); | ^^^^^^^ | = note: the following crate versions were found: crate `autocfg` compiled by rustc 1.82.0 (f6e511eec 2024-10-15) (Fedora 1.82.0-1.fc42): [...]/target/debug/deps/libautocfg-589c41db1eea6297.rlib = help: please recompile that crate using this compiler (rustc 1.82.0 (f6e511eec 2024-10-15) (Fedora 1.82.0-1.fc40)) (consider running `cargo clean` first) ``` We can improve this situation by adding the file length, although that could also happen to be the same, and the creation date that will match when the file was installed, though not all filesystems support that. All of this comes from a single metadata call, so it shouldn't have any noticeable slowdown that would hurt the caching effort.
2 parents 40d6078 + b5acf4c commit 0310497

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/cargo/util/rustc.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use std::sync::Mutex;
66

77
use anyhow::Context as _;
88
use cargo_util::{paths, ProcessBuilder, ProcessError};
9+
use filetime::FileTime;
910
use serde::{Deserialize, Serialize};
1011
use tracing::{debug, info, warn};
1112

@@ -329,7 +330,13 @@ fn rustc_fingerprint(
329330
let path = paths::resolve_executable(path)?;
330331
path.hash(hasher);
331332

332-
paths::mtime(&path)?.hash(hasher);
333+
let meta = paths::metadata(&path)?;
334+
meta.len().hash(hasher);
335+
336+
// Often created and modified are the same, but not all filesystems support the former,
337+
// and distro reproducible builds may clamp the latter, so we try to use both.
338+
FileTime::from_creation_time(&meta).hash(hasher);
339+
FileTime::from_last_modification_time(&meta).hash(hasher);
333340
Ok(())
334341
};
335342

0 commit comments

Comments
 (0)