use std::{env, fs, path::Path};

fn main() {
	let out_dir = env::var_os("OUT_DIR").unwrap();

	let path = Path::new(&out_dir).join("git_hash.rs");

	let git_output = std::process::Command::new("git")
		.args(["rev-parse", "--short", "HEAD"])
		.output()
		.unwrap()
		.stdout;

	let last_hash = String::from_utf8(git_output).unwrap();
	let last_hash = last_hash.trim();

	fs::write(
		&path,
		format!("pub const GIT_HASH: &str = \"{last_hash}\";"),
	)
	.unwrap();
}
