use std::process::Command;
fn main() {
let git_hash = git_output(&["rev-parse", "HEAD"]).unwrap_or_else(|| "unknown".into());
let build_date = git_output(&["log", "-1", "--format=%cI"]).unwrap_or_else(|| "unknown".into());
println!("cargo:rustc-env=GIT_HASH={git_hash}");
println!("cargo:rustc-env=BUILD_DATE={build_date}");
println!("cargo:rerun-if-changed=.git/HEAD");
println!("cargo:rerun-if-changed=.git/refs/");
println!("cargo:rerun-if-changed=.git/packed-refs");
}
fn git_output(args: &[&str]) -> Option<String> {
Command::new("git")
.args(args)
.output()
.ok()
.filter(|o| o.status.success())
.and_then(|o| String::from_utf8(o.stdout).ok())
.map(|s| s.trim().to_string())
.filter(|s| !s.is_empty())
}