use std::{env, error::Error, path::PathBuf, process::Command};
fn main() -> Result<(), Box<dyn Error>> {
let out_dir = PathBuf::from(env::var("OUT_DIR")?);
tonic_prost_build::configure()
.file_descriptor_set_path(out_dir.join("player_descriptor.bin"))
.compile_protos(&["src/proto/player/v1/player.proto"], &["src/proto"])?;
let git_hash = Command::new("git")
.args(["rev-parse", "--short", "HEAD"])
.output()
.ok()
.filter(|o| o.status.success())
.map(|o| String::from_utf8_lossy(&o.stdout).trim().to_string())
.unwrap_or_else(|| "unknown".to_string());
println!("cargo:rustc-env=MTRACK_GIT_HASH={git_hash}");
let build_time = jiff::Timestamp::now().strftime("%Y-%m-%dT%H:%M:%SZ");
println!("cargo:rustc-env=MTRACK_BUILD_TIME={build_time}");
println!("cargo:rerun-if-changed=.git/HEAD");
println!("cargo:rerun-if-changed=.git/refs");
Ok(())
}