use std::process::Command;
fn main() {
let git_describe = Command::new("git")
.args(["describe", "--tags", "--always", "--dirty"])
.output()
.ok()
.and_then(|output| {
if output.status.success() {
String::from_utf8(output.stdout).ok()
} else {
None
}
})
.map(|s| s.trim().to_string());
let git_hash = Command::new("git")
.args(["rev-parse", "--short", "HEAD"])
.output()
.ok()
.and_then(|output| {
if output.status.success() {
String::from_utf8(output.stdout).ok()
} else {
None
}
})
.map(|s| s.trim().to_string());
let build_timestamp = chrono::Utc::now().to_rfc3339();
if let Some(describe) = git_describe {
println!("cargo:rustc-env=GIT_DESCRIBE={}", describe);
}
if let Some(hash) = git_hash {
println!("cargo:rustc-env=GIT_HASH={}", hash);
}
println!("cargo:rustc-env=BUILD_TIMESTAMP={}", build_timestamp);
println!("cargo:rerun-if-changed=.git/HEAD");
}