-
Notifications
You must be signed in to change notification settings - Fork 52
Expand file tree
/
Copy pathbuild.rs
More file actions
30 lines (26 loc) · 911 Bytes
/
build.rs
File metadata and controls
30 lines (26 loc) · 911 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
28
29
30
use chrono::Utc;
use std::process::Command;
fn main() {
// Get git hash
let git_hash = Command::new("git")
.args(["rev-parse", "--short", "HEAD"])
.output()
.map(|output| {
if output.status.success() {
String::from_utf8(output.stdout)
.unwrap_or_else(|_| "unknown".to_string())
.trim()
.to_string()
} else {
"unknown".to_string()
}
})
.unwrap_or_else(|_| "unknown".to_string());
// Get current UTC time
let build_date = Utc::now().format("%Y-%m-%d %H:%M:%S UTC").to_string();
println!("cargo:rustc-env=GIT_HASH={git_hash}");
println!("cargo:rustc-env=BUILD_DATE={build_date}");
// Rerun if git changes
println!("cargo:rerun-if-changed=.git/HEAD");
println!("cargo:rerun-if-changed=.git/refs/heads/");
}