use std::process::Command;
fn main() {
let sha = Command::new("git")
.args(["rev-parse", "--short", "HEAD"])
.output()
.ok()
.and_then(|o| String::from_utf8(o.stdout).ok())
.map(|s| s.trim().to_string())
.unwrap_or_else(|| "unknown".into());
println!("cargo:rustc-env=GIT_SHA={}", sha);
let build_date = Command::new("date")
.args(["-u", "+%Y-%m-%d"])
.output()
.ok()
.and_then(|o| String::from_utf8(o.stdout).ok())
.map(|s| s.trim().to_string())
.unwrap_or_else(|| "unknown".into());
println!("cargo:rustc-env=BUILD_DATE={}", build_date);
let rustc_version = Command::new("rustc")
.args(["--version"])
.output()
.ok()
.and_then(|o| String::from_utf8(o.stdout).ok())
.map(|s| s.trim().to_string())
.unwrap_or_else(|| "unknown".into());
println!("cargo:rustc-env=RUSTC_VERSION={}", rustc_version);
let profile = std::env::var("PROFILE").unwrap_or_else(|_| "unknown".into());
println!("cargo:rustc-env=BUILD_PROFILE={}", profile);
}