make git hash embedding more reliable

This commit is contained in:
2025-11-06 03:06:25 +00:00
parent bf086d0442
commit 560d9659f4
+6 -6
View File
@@ -8,16 +8,16 @@ fn main() {
.set_icon("assets/icon.ico") .set_icon("assets/icon.ico")
.compile() .compile()
.unwrap(); .unwrap();
println!( embed_latest_git_hash();
"cargo:rustc-env=LATEST_GIT_COMMIT_HASH={}",
latest_git_commit_hash()
)
} }
fn latest_git_commit_hash() -> String { fn embed_latest_git_hash() {
let git_rev_parse = std::process::Command::new("git") let git_rev_parse = std::process::Command::new("git")
.args(&["rev-parse", "--short=8", "HEAD"]) .args(&["rev-parse", "--short=8", "HEAD"])
.output() .output()
.unwrap(); .unwrap();
String::from_utf8(git_rev_parse.stdout).unwrap() let git_hash = String::from_utf8(git_rev_parse.stdout).unwrap();
println!("cargo:rustc-env=LATEST_GIT_COMMIT_HASH={git_hash}");
println!("cargo:rerun-if-changed=.git/refs/heads/main");
println!("cargo:rerun-if-changed=.git/HEAD");
} }