fn main() {
if let Ok(s) = std::env::var("DECK_GIT_SHA") {
let s = s.trim();
if !s.is_empty() {
println!("cargo:rustc-env=DECK_GIT_SHA={s}");
return;
}
}
let sha = std::process::Command::new("git")
.args(["rev-parse", "--short=8", "HEAD"])
.output()
.ok()
.and_then(|o| {
if o.status.success() {
String::from_utf8(o.stdout).ok()
} else {
None
}
})
.map(|s| s.trim().to_string())
.filter(|s| !s.is_empty())
.unwrap_or_else(|| "dev".to_string());
println!("cargo:rustc-env=DECK_GIT_SHA={sha}");
let head_path = std::path::Path::new(env!("CARGO_MANIFEST_DIR"))
.join("..")
.join("..")
.join("..")
.join(".git")
.join("HEAD");
if head_path.exists() {
println!("cargo:rerun-if-changed={}", head_path.display());
}
println!("cargo:rerun-if-env-changed=DECK_GIT_SHA");
}