feat: add detailed --version output with build-time version injection

This commit is contained in:
2026-06-22 13:42:52 +08:00
parent eb05e27655
commit 0a138f6f11
5 changed files with 35 additions and 3 deletions
+19
View File
@@ -0,0 +1,19 @@
use std::process::Command;
fn main() {
let version = std::env::var("CCSM_VERSION")
.unwrap_or_else(|_| env!("CARGO_PKG_VERSION").to_string());
let commit = Command::new("git")
.args(["rev-parse", "--short", "HEAD"])
.output()
.ok()
.and_then(|o| String::from_utf8(o.stdout).ok())
.map(|s| s.trim().to_string())
.unwrap_or_else(|| "unknown".to_string());
println!("cargo:rustc-env=CCSM_VERSION={version}");
println!("cargo:rustc-env=GIT_COMMIT_SHORT={commit}");
println!("cargo:rerun-if-changed=.git/HEAD");
println!("cargo:rerun-if-env-changed=CCSM_VERSION");
}