From a77c85dc66dd58ff315e1855f4d64bfd8a759bd6 Mon Sep 17 00:00:00 2001 From: Mats Willemsen <60099717+ma-ts@users.noreply.github.com> Date: Sat, 26 Jul 2025 08:15:58 +0200 Subject: [PATCH] fix: set default hash in case git is not available Signed-off-by: Mats Willemsen <60099717+ma-ts@users.noreply.github.com> --- build.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/build.rs b/build.rs index 6fa5c076..e5dddc93 100644 --- a/build.rs +++ b/build.rs @@ -18,12 +18,12 @@ fn main() -> Result<()> { // Supply information as compile-time environment variables. #[cfg(feature = "opa-runtime")] { - let output = std::process::Command::new("git") + let git_hash = std::process::Command::new("git") .args(["rev-parse", "HEAD"]) .output() - .expect("`git rev-parse HEAD` failed."); - let git_hash = String::from_utf8(output.stdout).unwrap(); - println!("cargo:rustc-env=GIT_HASH={git_hash}"); + .map(|output| String::from_utf8_lossy(&output.stdout).trim().to_string()) + .unwrap_or_else(|_| "unknown".to_string()); + println!("cargo:rustc-env=GIT_HASH={}", git_hash); } // Rerun only if build.rs changes.