Rebuild on commit change.

This commit is contained in:
yukirij 2024-10-03 12:42:22 -07:00
parent c882bbd7fd
commit 9d9e4837da
2 changed files with 10 additions and 0 deletions

1
.gitignore vendored
View File

@ -2,3 +2,4 @@
/data
Cargo.lock
*.pem
.commit

View File

@ -1,5 +1,7 @@
use std::process::Command;
const F_COMMIT :&str = ".commit";
fn main()
{
let output = Command::new("git")
@ -8,5 +10,12 @@ fn main()
.expect("Failed to acquire git HEAD");
let git_hash = String::from_utf8(output.stdout).expect("Invalid UTF-8 output from git HEAD");
let git_hash = git_hash.trim();
let previous_hash = std::fs::read_to_string(F_COMMIT).unwrap_or_default();
if git_hash != previous_hash {
std::fs::write(F_COMMIT, &git_hash).ok();
}
println!("cargo:rerun-if-changed={}", F_COMMIT);
println!("cargo:rustc-env=GIT_HASH={}", git_hash);
}