use std::process::Command;
fn main() {
emit_build_metadata();
}
fn emit_build_metadata() {
let git_hash = Command::new("git")
.args(["rev-parse", "--short=12", "HEAD"])
.output()
.ok()
.and_then(|o| String::from_utf8(o.stdout).ok())
.map(|s| s.trim().to_string())
.unwrap_or_else(|| "unknown".to_string());
println!("cargo:rustc-env=GIT_COMMIT_HASH={git_hash}");
let git_dirty = Command::new("git")
.args(["status", "--porcelain"])
.output()
.ok()
.map(|o| !o.stdout.is_empty())
.unwrap_or(false);
let dirty_suffix = if git_dirty { "-dirty" } else { "" };
println!("cargo:rustc-env=GIT_DIRTY={dirty_suffix}");
let timestamp = chrono::Utc::now().format("%Y-%m-%dT%H:%M:%SZ").to_string();
println!("cargo:rustc-env=BUILD_TIMESTAMP={timestamp}");
println!("cargo:rerun-if-changed=.git/HEAD");
println!("cargo:rerun-if-changed=.git/index");
}