-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathbuild.rs
More file actions
32 lines (28 loc) · 1005 Bytes
/
build.rs
File metadata and controls
32 lines (28 loc) · 1005 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
31
32
use std::process::Command;
fn main() {
// 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())
.unwrap_or_else(|| "unknown".to_string());
// Get build timestamp
let build_date = chrono::Utc::now()
.format("%Y-%m-%d %H:%M:%S UTC")
.to_string();
// Get build target
let build_target = std::env::var("TARGET").unwrap_or_else(|_| "unknown".to_string());
// Set environment variables for compile-time inclusion
println!("cargo:rerun-if-changed=.git/HEAD");
println!("cargo:rustc-env=GIT_COMMIT={}", git_hash);
println!("cargo:rustc-env=BUILD_DATE={}", build_date);
println!("cargo:rustc-env=BUILD_TARGET={}", build_target);
}