From 3c7674e7c2022603375809a9562d6dd2da8898ce Mon Sep 17 00:00:00 2001 From: Anand Krishnamoorthi <35780660+anakrish@users.noreply.github.com> Date: Wed, 3 Apr 2024 10:17:51 +0530 Subject: [PATCH] Build dependency on git only if opa.runtime feature is enabled. (#194) Signed-off-by: Anand Krishnamoorthi --- build.rs | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/build.rs b/build.rs index ad7214c..a26f4e9 100644 --- a/build.rs +++ b/build.rs @@ -3,7 +3,6 @@ use anyhow::Result; use std::path::Path; -use std::process::Command; fn main() -> Result<()> { // Copy hooks to appropriate location so that git will run them. @@ -14,12 +13,15 @@ fn main() -> Result<()> { } // Supply information as compile-time environment variables. - let output = Command::new("git") - .args(["rev-parse", "HEAD"]) - .output() - .unwrap(); - let git_hash = String::from_utf8(output.stdout).unwrap(); - println!("cargo:rustc-env=GIT_HASH={}", git_hash); + #[cfg(feature = "opa-runtime")] + { + let output = 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); + } Ok(()) }