Skip to content

Commit bf43053

Browse files
authored
feat: show extra build description from bootstrap (#15269)
### What does this PR try to resolve? `CFG_VER_DESCRIPTION` is descriptive string to be appended to version output. This is usually set by the bootstrap in rust-lang/rust. Useful for showing vendor build information. See <rust-lang/rust#137723>. ### How should we test and review this PR? ```bash CFG_VER_DESCRIPTION="My Awesome Rust Distribution" cargo b target/debug/cargo version ```
2 parents 15f315d + 7c0b2bd commit bf43053

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

src/cargo/version.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,18 @@ pub struct VersionInfo {
2121
///
2222
/// `None` if not built from a git repo.
2323
pub commit_info: Option<CommitInfo>,
24+
25+
/// A descriptive string to be appended to version output.
26+
///
27+
/// This is usually set by the bootstrap in rust-lang/rust
28+
/// via the `CFG_VER_DESCRIPTION` environment variable.
29+
/// Useful for showing vendor build information.
30+
/// For example,
31+
///
32+
/// ```text
33+
/// cargo 1.85.0 (d73d2caf9 2024-12-31) (MyCustomBuild 1.85.0-3)
34+
/// ```
35+
pub description: Option<String>,
2436
}
2537

2638
impl fmt::Display for VersionInfo {
@@ -30,6 +42,10 @@ impl fmt::Display for VersionInfo {
3042
if let Some(ref ci) = self.commit_info {
3143
write!(f, " ({} {})", ci.short_commit_hash, ci.commit_date)?;
3244
};
45+
46+
if let Some(description) = self.description.as_ref().filter(|d| !d.is_empty()) {
47+
write!(f, " ({description})")?;
48+
};
3349
Ok(())
3450
}
3551
}
@@ -71,10 +87,12 @@ pub fn version() -> VersionInfo {
7187
commit_hash,
7288
commit_date: option_env_str!("CARGO_COMMIT_DATE").unwrap(),
7389
});
90+
let description = option_env_str!("CFG_VER_DESCRIPTION");
7491

7592
VersionInfo {
7693
version,
7794
release_channel,
7895
commit_info,
96+
description,
7997
}
8098
}

0 commit comments

Comments
 (0)