feat: add COMMIT_HASH build time env var

This commit is contained in:
Tamipes 2025-11-25 16:27:43 +01:00
parent e7d06a45f6
commit 3b7e976deb
3 changed files with 22 additions and 0 deletions

17
build.rs Normal file
View file

@ -0,0 +1,17 @@
use std::process::Command;
fn main() {
let commit_hash = match std::env::var("COMMIT_HASH") {
Ok(commit_hash_string) => commit_hash_string,
Err(_) => {
match Command::new("git")
.args(vec!["rev-parse", "--short", "HEAD"])
.output()
{
Ok(x) => String::from_utf8_lossy(x.stdout.trim_ascii_end()).into_owned(),
Err(_) => "no hash :(".to_string(),
}
}
};
println!("cargo::rustc-env=COMMIT_HASH=\"{}\"", commit_hash);
}