use std::env;
use std::fs;
use std::path::{Path, PathBuf};
use std::time::{SystemTime, UNIX_EPOCH};
pub fn inject_build_metadata(project_dest_path: PathBuf) {
let manifest_dir = env::var("CARGO_MANIFEST_DIR").expect("CARGO_MANIFEST_DIR not set");
let dest_path: PathBuf = Path::new(&manifest_dir).join(project_dest_path);
let destination_dir = dest_path.parent().unwrap();
fs::create_dir_all(&destination_dir).expect("Failed to create generated directory");
let build_target = env::var("TARGET").unwrap();
println!("cargo:rustc-env=BUILD_TARGET={}", build_target);
let build_time_utc = SystemTime::now()
.duration_since(UNIX_EPOCH)
.expect("Time went backwards")
.as_secs()
.to_string();
println!("cargo:rustc-env=BUILD_TIME_UTC={}", build_time_utc);
const CONTENTS: &[u8] = include_bytes!("inject.rs");
fs::write(&dest_path, CONTENTS).expect("Failed to write metadata file");
println!("cargo:rerun-if-changed=Cargo.toml");
println!("cargo:rerun-if-changed=inject.rs");
}