use chrono::{DateTime, NaiveDateTime, Utc};
use std::env;
use std::process::Command;
fn main() {
println!("cargo:rerun-if-changed=build.rs");
let now = match env::var("SOURCE_DATE_EPOCH") {
Ok(val) => {
let naive = match NaiveDateTime::from_timestamp_opt(val.parse::<i64>().unwrap(), 0) {
Some(n) => n,
None => Utc::now().naive_utc(),
};
let datetime: DateTime<Utc> = DateTime::from_utc(naive, Utc);
datetime
}
Err(_) => Utc::now(),
};
println!("cargo:rustc-env=BUILD_TIMESTAMP={}", now.to_rfc3339());
println!(
"cargo:rustc-env=BUILD_TARGET={}",
std::env::var("TARGET").unwrap()
);
let command = Command::new("git").args(["rev-parse", "HEAD"]).output();
let commit = match command {
Ok(output) => String::from_utf8(output.stdout).unwrap(),
Err(_) => "".to_string(),
};
println!("cargo:rustc-env=GIT_COMMIT={}", commit);
}