-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathbuild.rs
More file actions
34 lines (30 loc) · 1.04 KB
/
build.rs
File metadata and controls
34 lines (30 loc) · 1.04 KB
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
28
29
30
31
32
33
34
use std::process::Command;
fn main() {
let git_hash = Command::new("git")
.args(["describe", "--always", "--dirty"])
.output()
.map(|output| {
if output.status.success() {
String::from_utf8_lossy(&output.stdout).trim().to_string()
} else {
"unknown".to_string()
}
})
.unwrap_or_else(|_| "unknown".to_string());
let git_date = Command::new("git")
.args(["log", "-1", "--format=%cs"])
.output()
.map(|output| {
if output.status.success() {
String::from_utf8_lossy(&output.stdout).trim().to_string()
} else {
"unknown".to_string()
}
})
.unwrap_or_else(|_| "unknown".to_string());
// Make the git info available to the program
println!("cargo:rustc-env=GIT_HASH={}", git_hash);
println!("cargo:rustc-env=GIT_DATE={}", git_date);
// Re-run build script if git HEAD changes
println!("cargo:rerun-if-changed=.git/HEAD");
}