-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.rs
More file actions
48 lines (41 loc) · 1.34 KB
/
build.rs
File metadata and controls
48 lines (41 loc) · 1.34 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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
use std::process::Command;
fn main() {
// Try to get git describe output for detailed version
let git_describe = Command::new("git")
.args(["describe", "--tags", "--always", "--dirty"])
.output()
.ok()
.and_then(|output| {
if output.status.success() {
String::from_utf8(output.stdout).ok()
} else {
None
}
})
.map(|s| s.trim().to_string());
// Try to get git commit hash
let git_hash = Command::new("git")
.args(["rev-parse", "--short", "HEAD"])
.output()
.ok()
.and_then(|output| {
if output.status.success() {
String::from_utf8(output.stdout).ok()
} else {
None
}
})
.map(|s| s.trim().to_string());
// Get build timestamp
let build_timestamp = chrono::Utc::now().to_rfc3339();
// Export the values as environment variables for use in the code
if let Some(describe) = git_describe {
println!("cargo:rustc-env=GIT_DESCRIBE={}", describe);
}
if let Some(hash) = git_hash {
println!("cargo:rustc-env=GIT_HASH={}", hash);
}
println!("cargo:rustc-env=BUILD_TIMESTAMP={}", build_timestamp);
// Rebuild if git HEAD changes
println!("cargo:rerun-if-changed=.git/HEAD");
}