use std::env;
use std::process::Command;
use std::time::{SystemTime, UNIX_EPOCH};
fn git_commit_hash() -> String {
if let Ok(output) = Command::new("git")
.args(["rev-parse", "--short", "HEAD"])
.output()
{
if let Ok(commit) = String::from_utf8(output.stdout) {
return commit.trim().to_string();
}
}
"unknown".to_string()
}
fn main() {
println!("cargo:rustc-env=GIT_VERSION={}", env!("CARGO_PKG_VERSION"));
println!("cargo:rustc-env=GIT_COMMIT={}", git_commit_hash());
if let Ok(target) = env::var("TARGET") {
println!("cargo:rustc-env=BUILD_PLATFORM={}", target);
}
if let Ok(build_time) = SystemTime::now().duration_since(UNIX_EPOCH) {
println!("cargo:rustc-env=BUILD_TIMESTAMP={}", build_time.as_secs());
}
}