use std::process::Command; fn main() { // Re-run if git HEAD changes (new commit) println!("cargo:rerun-if-changed=.git/HEAD"); println!("cargo:rerun-if-changed=.git/refs/heads/"); let version = env!("CARGO_PKG_VERSION"); let short_sha = Command::new("git") .args(["rev-parse", "--short", "HEAD"]) .output() .ok() .filter(|o| o.status.success()) .and_then(|o| String::from_utf8(o.stdout).ok()) .map(|s| s.trim().to_string()); let full_version = match short_sha { Some(sha) => format!("{}-{}", version, sha), None => version.to_string(), }; println!("cargo:rustc-env=GRAIN_VERSION={}", full_version); }