From 758dde8f5cdd6d622a76eae097710cf4555fd627 Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Wed, 30 Jul 2025 13:57:55 +0300 Subject: [PATCH] feat: --version output now includes Git commit Signed-off-by: Lars Wirzenius --- build.rs | 27 +++++++++++++++++++++++++++ src/bin/radicle-native-ci.rs | 2 +- 2 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 build.rs diff --git a/build.rs b/build.rs new file mode 100644 index 0000000..1aec33b --- /dev/null +++ b/build.rs @@ -0,0 +1,27 @@ +use std::process::Command; + +fn main() { + // Set a build-time `GIT_HEAD` env var which includes the commit id; + // such that we can tell which code is running. + let hash = Command::new("git") + .arg("rev-parse") + .arg("--short") + .arg("HEAD") + .output() + .ok() + .and_then(|output| { + if output.status.success() { + String::from_utf8(output.stdout).ok() + } else { + None + } + }) + .unwrap_or_else(|| String::from("unknown")); + + println!("cargo:rustc-env=GIT_HEAD={hash}"); + println!( + "cargo:rustc-env=VERSION={}@{hash}", + env!("CARGO_PKG_VERSION") + ); + println!("cargo:rustc-rerun-if-changed=.git/HEAD"); +} diff --git a/src/bin/radicle-native-ci.rs b/src/bin/radicle-native-ci.rs index c19c7c1..df3b469 100644 --- a/src/bin/radicle-native-ci.rs +++ b/src/bin/radicle-native-ci.rs @@ -55,7 +55,7 @@ fn fallible_main() -> Result { } else { for arg in args.iter() { match arg.as_str() { - "--version" => println!("{} {}", env!("CARGO_PKG_NAME"), env!("CARGO_PKG_VERSION")), + "--version" => println!("{} {}", env!("CARGO_PKG_NAME"), env!("VERSION")), "--show-config" => { let engine = Engine::new()?; println!("{}", engine.config().as_json());