fix: build when git not installed

When the git binary is not available, emit an empty git_hash
so that the build continues instead of aborting due to an
unset environment variable
This commit is contained in:
steven-omaha
2023-05-15 15:58:57 +02:00
parent af9550bbe5
commit 34d7b5d9de
+6 -3
View File
@@ -1,10 +1,13 @@
use std::process::Command; use std::process::Command;
fn main() { fn main() {
let output = Command::new("git") let git_hash = match Command::new("git")
.args(["rev-parse", "--short", "HEAD"]) .args(["rev-parse", "--short", "HEAD"])
.output() .output()
.unwrap(); {
let git_hash = String::from_utf8(output.stdout).unwrap(); Ok(output) => String::from_utf8(output.stdout).expect("git output is utf-8"),
_ => String::new(),
};
println!("cargo:rustc-env=GIT_HASH={git_hash}"); println!("cargo:rustc-env=GIT_HASH={git_hash}");
} }