use chrono::Utc;
use std::process::Command;
use std::str;
fn main() {
let git_hash = get_command_output("git", &["rev-parse", "--short", "HEAD"]);
println!("cargo:rustc-env=GIT_COMMIT_SHORT={}", git_hash);
let rustc_version = get_command_output("rustc", &["--version"]);
println!("cargo:rustc-env=RUSTC_FULL_VERSION={}", rustc_version);
let cargo_version = get_command_output("cargo", &["--version"]);
println!("cargo:rustc-env=CARGO_FULL_VERSION={}", cargo_version);
let build_date = Utc::now().format("%Y-%m-%d").to_string();
println!("cargo:rustc-env=BUILD_DATE={}", build_date);
println!("cargo:rerun-if-changed=.git/HEAD");
}
fn get_command_output(cmd: &str, args: &[&str]) -> String {
let output = Command::new(cmd)
.args(args)
.output()
.unwrap_or_else(|e| panic!("Failed to execute command '{}': {}", cmd, e));
str::from_utf8(&output.stdout)
.unwrap_or("unknown")
.trim()
.to_string()
}