Skip to content

Commit faaf3ad

Browse files
committed
feat(rustc): parse and store commit-hash
The rustc commit hash is required as we'll need it to remap sysroot path to `/rustc/<commit-hash>`, as rustc bootstrap does. See <https://github.com/rust-lang/rust/blob/c2ef3516/src/bootstrap/src/lib.rs#L1113-L1116>. This is optional as the compiler it may be built without a Git repository.
1 parent e2c4cda commit faaf3ad

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

src/cargo/util/rustc.rs

+14
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ pub struct Rustc {
2828
pub version: semver::Version,
2929
/// The host triple (arch-platform-OS), this comes from verbose_version.
3030
pub host: InternedString,
31+
/// The rustc full commit hash, this comes from `verbose_version`.
32+
pub commit_hash: Option<String>,
3133
cache: Mutex<Cache>,
3234
}
3335

@@ -80,6 +82,17 @@ impl Rustc {
8082
verbose_version
8183
)
8284
})?;
85+
let commit_hash = extract("commit-hash: ").ok().map(|hash| {
86+
debug_assert!(
87+
hash.chars().all(|ch| ch.is_ascii_hexdigit()),
88+
"commit hash must be a hex string"
89+
);
90+
debug_assert!(
91+
hash.len() == 40 || hash.len() == 64,
92+
"hex string must be generated from sha1 or sha256"
93+
);
94+
hash.to_string()
95+
});
8396

8497
Ok(Rustc {
8598
path,
@@ -88,6 +101,7 @@ impl Rustc {
88101
verbose_version,
89102
version,
90103
host,
104+
commit_hash,
91105
cache: Mutex::new(cache),
92106
})
93107
}

0 commit comments

Comments
 (0)