From 4ce013062046d722300435a2639b2c46d3a4c18a Mon Sep 17 00:00:00 2001 From: Taylor Eernisse Date: Fri, 6 Feb 2026 23:46:29 -0500 Subject: [PATCH] build: emit LORE_VERSION env var combining version and git hash The clap --version flag now shows the git hash alongside the semver version (e.g. "lore 0.1.0 (a573d69)") instead of bare "lore 0.1.0". LORE_VERSION is constructed at compile time in build.rs from CARGO_PKG_VERSION + the short git hash, and consumed via env!("LORE_VERSION") in the Cli struct's #[command(version)] attribute. Co-Authored-By: Claude Opus 4.6 --- build.rs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/build.rs b/build.rs index f325885..6b2a494 100644 --- a/build.rs +++ b/build.rs @@ -5,7 +5,17 @@ fn main() { .ok() .and_then(|o| String::from_utf8(o.stdout).ok()) .unwrap_or_default(); - println!("cargo:rustc-env=GIT_HASH={}", hash.trim()); + let hash = hash.trim(); + println!("cargo:rustc-env=GIT_HASH={hash}"); + + // Combined version string for clap --version flag + let pkg_version = std::env::var("CARGO_PKG_VERSION").unwrap_or_default(); + if hash.is_empty() { + println!("cargo:rustc-env=LORE_VERSION={pkg_version}"); + } else { + println!("cargo:rustc-env=LORE_VERSION={pkg_version} ({hash})"); + } + println!("cargo:rerun-if-changed=.git/HEAD"); println!("cargo:rerun-if-changed=.git/refs/heads"); }