#[derive(Copy, Clone, Debug)]
pub struct BuildInfo {
pub crate_name: &'static str,
pub version: super::CrateVersion,
pub rustc_version: &'static str,
pub llvm_version: &'static str,
pub git_hash: &'static str,
pub git_branch: &'static str,
pub is_in_rerun_workspace: bool,
pub target_triple: &'static str,
pub datetime: &'static str,
}
impl BuildInfo {
pub fn git_hash_or_tag(&self) -> String {
if self.git_hash.is_empty() {
format!("v{}", self.version)
} else {
self.git_hash.to_owned()
}
}
}
impl std::fmt::Display for BuildInfo {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let Self {
crate_name,
version,
rustc_version,
llvm_version,
git_hash,
git_branch,
is_in_rerun_workspace: _,
target_triple,
datetime,
} = self;
let rustc_version = (!rustc_version.is_empty()).then(|| format!("rustc {rustc_version}"));
let llvm_version = (!llvm_version.is_empty()).then(|| format!("LLVM {llvm_version}"));
write!(f, "{crate_name} {version}")?;
if let Some(rustc_version) = rustc_version {
write!(f, " [{rustc_version}")?;
if let Some(llvm_version) = llvm_version {
write!(f, ", {llvm_version}")?;
}
write!(f, "]")?;
}
write!(f, " {target_triple}")?;
if !git_branch.is_empty() {
write!(f, " {git_branch}")?;
}
if !git_hash.is_empty() {
let git_hash: String = git_hash.chars().take(7).collect(); write!(f, " {git_hash}")?;
}
write!(f, ", built {datetime}")?;
Ok(())
}
}