22 lines
631 B
Rust
22 lines
631 B
Rust
use std::process::Command;
|
|
|
|
const F_COMMIT :&str = ".commit";
|
|
|
|
fn main()
|
|
{
|
|
let output = Command::new("git")
|
|
.args(&["rev-parse", "HEAD"])
|
|
.output()
|
|
.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);
|
|
}
|