use std::process::Command; fn get_git_hash() -> Option { let output = Command::new("git") .args(&["rev-parse", "--short", "HEAD"]) .output() .ok()?; String::from_utf8(output.stdout).ok() } fn main() { if let Some(hash) = get_git_hash() { println!("cargo:rustc-env=GIT_HASH={}", hash); } }