-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.rs
More file actions
24 lines (22 loc) · 751 Bytes
/
Copy pathbuild.rs
File metadata and controls
24 lines (22 loc) · 751 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
fn main() {
env_git_hash();
println!("cargo:rerun-if-changed=../.git/HEAD");
println!("cargo:rerun-if-changed=../.git/refs");
println!("cargo:rerun-if-changed=build.rs");
}
fn env_git_hash() {
let output = std::process::Command::new("git")
.args(["rev-parse", "HEAD"])
.output()
.expect("Failed to execute git command to get the hash");
if output.status.success() {
let hash = String::from_utf8_lossy(&output.stdout);
println!("cargo:rustc-env=GIT_HASH={}", hash.trim());
println!(
"cargo:rustc-env=GIT_HASH_SHORT={}",
hash.trim().chars().take(7).collect::<String>()
);
} else {
println!("cargo:rustc-env=GIT_HASH=unknown");
}
}