zenyx-engine-telemetry/subcrates/telemetry/build.rs
2025-04-28 15:40:48 -04:00

33 lines
900 B
Rust

use std::{env, fs::File, io::Write, process::Command};
fn main() {
let out_dir = env::var("OUT_DIR").unwrap();
let mut f = File::create(format!("{}/built.rs", out_dir)).unwrap();
let commit_hash = Command::new("git")
.args(["rev-parse", "HEAD"])
.output()
.ok()
.and_then(|o| String::from_utf8(o.stdout).ok())
.unwrap_or_else(|| "unknown".into());
let commit_short_hash = Command::new("git")
.args(["rev-parse", "--short", "HEAD"])
.output()
.ok()
.and_then(|o| String::from_utf8(o.stdout).ok())
.unwrap_or_else(|| "unknown".into());
writeln!(
f,
"pub const GIT_COMMIT_HASH: &str = \"{}\";",
commit_hash.trim()
)
.unwrap();
writeln!(
f,
"pub const GIT_COMMIT_SHORT_HASH: &str = \"{}\";",
commit_short_hash.trim()
)
.unwrap();
}