use std::process::Command; fn main() { let output = Command::new("git") .args(["rev-parse", "HEAD"]) .output() .unwrap(); let git_hash: String = String::from_utf8(output.stdout).unwrap(); let git_short_hash = match git_hash.is_empty() { true => "".to_owned(), false => format!("_{}", git_hash.clone().chars().take(8).collect::()), }; let output_status = Command::new("git") .args(["status", "--porcelain"]) .output() .unwrap(); let version_suffix = match !output_status.stdout.is_empty() { true => "_dirty", false => "", }; println!("cargo:rustc-env=GIT_HASH={}", git_hash); println!( "cargo:rustc-env=GIT_SHORT_HASH={}", git_short_hash + version_suffix ); // println!( // "cargo:rustc-env=GIT_VERSION_SUFFIX={}", // git_short_hash + version_suffix // ); }