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 <noreply@anthropic.com>
This commit is contained in:
12
build.rs
12
build.rs
@@ -5,7 +5,17 @@ fn main() {
|
|||||||
.ok()
|
.ok()
|
||||||
.and_then(|o| String::from_utf8(o.stdout).ok())
|
.and_then(|o| String::from_utf8(o.stdout).ok())
|
||||||
.unwrap_or_default();
|
.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/HEAD");
|
||||||
println!("cargo:rerun-if-changed=.git/refs/heads");
|
println!("cargo:rerun-if-changed=.git/refs/heads");
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user