Add Git commit hash to version string

Fixes #1348
This commit is contained in:
Henrik Friedrichsen
2023-12-16 18:29:56 +01:00
parent 87f05e430d
commit ea36d2d42a
3 changed files with 21 additions and 1 deletions

19
build.rs Normal file
View File

@@ -0,0 +1,19 @@
use std::process::Command;
fn main() {
let mut version = String::from(env!("CARGO_PKG_VERSION"));
if let Some(commit_hash) = commit_hash() {
version = format!("{version} ({commit_hash})");
}
println!("cargo:rustc-env=VERSION={version}");
}
fn commit_hash() -> Option<String> {
Command::new("git")
.args(["rev-parse", "--short", "HEAD"])
.output()
.ok()
.filter(|output| output.status.success())
.and_then(|output| String::from_utf8(output.stdout).ok())
.map(|hash| hash.trim().into())
}