feat: --version output now includes Git commit

Signed-off-by: Lars Wirzenius <liw@liw.fi>
This commit is contained in:
Lars Wirzenius
2025-07-30 13:57:55 +03:00
parent 1d209f79c1
commit 758dde8f5c
2 changed files with 28 additions and 1 deletions
+27
View File
@@ -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");
}
+1 -1
View File
@@ -55,7 +55,7 @@ fn fallible_main() -> Result<bool, EngineError> {
} 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());