diff --git a/src/cargo/version.rs b/src/cargo/version.rs index a1e4d3e46a4..ca5bb8b2e7c 100644 --- a/src/cargo/version.rs +++ b/src/cargo/version.rs @@ -21,6 +21,18 @@ pub struct VersionInfo { /// /// `None` if not built from a git repo. pub commit_info: Option, + + /// A descriptive string to be appended to version output. + /// + /// This is usually set by the bootstrap in rust-lang/rust + /// via the `CFG_VER_DESCRIPTION` environment variable. + /// Useful for showing vendor build information. + /// For example, + /// + /// ```text + /// cargo 1.85.0 (d73d2caf9 2024-12-31) (MyCustomBuild 1.85.0-3) + /// ``` + pub description: Option, } impl fmt::Display for VersionInfo { @@ -30,6 +42,10 @@ impl fmt::Display for VersionInfo { if let Some(ref ci) = self.commit_info { write!(f, " ({} {})", ci.short_commit_hash, ci.commit_date)?; }; + + if let Some(description) = self.description.as_ref().filter(|d| !d.is_empty()) { + write!(f, " ({description})")?; + }; Ok(()) } } @@ -71,10 +87,12 @@ pub fn version() -> VersionInfo { commit_hash, commit_date: option_env_str!("CARGO_COMMIT_DATE").unwrap(), }); + let description = option_env_str!("CFG_VER_DESCRIPTION"); VersionInfo { version, release_channel, commit_info, + description, } }