use std::process::Command; /// Exposes the current commit and the crate name to the code through `env!()` fn main() { let git_hash = Command::new("git") .args(["rev-parse", "HEAD"]) .output() .ok() .filter(|output| output.status.success()) .and_then(|output| String::from_utf8(output.stdout).ok()) .map(|hash| hash.trim().chars().take(8).collect::()) .unwrap_or_else(|| "unknown".to_owned()); println!("cargo:rustc-env=GIT_HASH={git_hash}"); println!( "cargo:rustc-env=CRATE_NAME={}", env!("CARGO_PKG_NAME").replace("-", "_") ); println!("cargo:rerun-if-changed=.git/HEAD"); }