-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathbuild.rs
More file actions
22 lines (18 loc) · 731 Bytes
/
build.rs
File metadata and controls
22 lines (18 loc) · 731 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
use std::process::Command;
fn main() {
// Capture git hash (short form)
let git_hash = Command::new("git")
.args(["rev-parse", "--short=7", "HEAD"])
.output()
.ok()
.and_then(|output| String::from_utf8(output.stdout).ok())
.map(|s| s.trim().to_string())
.unwrap_or_else(|| "unknown".to_string());
// Capture build date (YYYY-MM-DD format)
let build_date = chrono::Utc::now().format("%Y-%m-%d").to_string();
// Set environment variables for compile-time access
println!("cargo:rustc-env=GIT_HASH={}", git_hash);
println!("cargo:rustc-env=BUILD_DATE={}", build_date);
// Rerun if git HEAD changes
println!("cargo:rerun-if-changed=.git/HEAD");
}