forked from containers/netavark
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.rs
26 lines (22 loc) · 810 Bytes
/
build.rs
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
use chrono::Utc;
use std::process::Command;
fn main() {
// Generate the default 'cargo:' instruction output
println!("cargo:rerun-if-changed=build.rs");
// get timestamp
let now = Utc::now();
println!("cargo:rustc-env=BUILD_TIMESTAMP={}", now.to_rfc3339());
// get rust target triple from TARGET env
println!(
"cargo:rustc-env=BUILD_TARGET={}",
std::env::var("TARGET").unwrap()
);
// get git commit
let command = Command::new("git").args(&["rev-parse", "HEAD"]).output();
let commit = match command {
Ok(output) => String::from_utf8(output.stdout).unwrap(),
// if error, e.g. build from source with git repo, just show empty string
Err(_) => "".to_string(),
};
println!("cargo:rustc-env=GIT_COMMIT={}", commit);
}