use std::process::Command; // Embeds the short git hash and the HEAD commit's date into the binary via // env!() in src/lib.rs. Using the commit date (not the wall-clock build // time) keeps this a pure function of the git commit being built, so the // build stays reproducible. fn main() { let git_hash = Command::new("git") .args(["rev-parse", "--short", "HEAD"]) .output() .ok() .filter(|output| output.status.success()) .and_then(|output| String::from_utf8(output.stdout).ok()) .map(|s| s.trim().to_string()) .unwrap_or_else(|| "unknown".to_string()); println!("cargo:rustc-env=GN4_GIT_HASH={git_hash}"); let commit_date = Command::new("git") .args(["show", "-s", "--format=%cd", "--date=format:%Y%m%d", "HEAD"]) .output() .ok() .filter(|output| output.status.success()) .and_then(|output| String::from_utf8(output.stdout).ok()) .map(|s| s.trim().to_string()) .unwrap_or_else(|| "unknown".to_string()); println!("cargo:rustc-env=GN4_COMMIT_DATE={commit_date}"); println!("cargo:rerun-if-changed=.git/HEAD"); }