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>
22 lines
728 B
Rust
22 lines
728 B
Rust
fn main() {
|
|
let hash = std::process::Command::new("git")
|
|
.args(["rev-parse", "--short", "HEAD"])
|
|
.output()
|
|
.ok()
|
|
.and_then(|o| String::from_utf8(o.stdout).ok())
|
|
.unwrap_or_default();
|
|
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");
|
|
}
|