-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.rs
More file actions
27 lines (25 loc) · 840 Bytes
/
build.rs
File metadata and controls
27 lines (25 loc) · 840 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
25
26
27
use std::env;
use std::process::Command;
fn main() {
let git_hash = env::var("NIX_UPDATE_GIT_HASH")
.ok()
.or_else(|| {
Command::new("git")
.args(["rev-parse", "--short", "HEAD"])
.output()
.ok()
.and_then(|out| {
if out.status.success() {
String::from_utf8(out.stdout)
.ok()
.map(|s| s.trim().to_string())
} else {
None
}
})
})
.unwrap_or_else(|| "unknown".to_string());
println!("cargo::rustc-env=GIT_HASH={}", git_hash);
println!("cargo::rerun-if-env-changed=NIX_UPDATE_GIT_HASH");
println!("cargo::rerun-if-changed=.git/HEAD");
}