use std::fs;
use std::path::PathBuf;
fn main() {
println!("cargo:rerun-if-env-changed=DEGENBOT_BUILD_NUMBER_FILE");
let crate_dir = PathBuf::from(std::env::var("CARGO_MANIFEST_DIR").unwrap_or_default());
let receipt = std::env::var_os("DEGENBOT_BUILD_NUMBER_FILE")
.map(PathBuf::from)
.or_else(|| {
crate_dir
.ancestors()
.find(|ancestor| ancestor.join("rust/Cargo.toml").is_file())
.map(|root| root.join(".build-number"))
})
.unwrap_or_else(|| PathBuf::from(".build-number"));
println!("cargo:rerun-if-changed={}", receipt.display());
let text = fs::read_to_string(&receipt).unwrap_or_default();
let mut parts = text.split_whitespace();
let count = parts.next().unwrap_or("0");
let fingerprint = parts.next().unwrap_or("unknown");
println!("cargo:rustc-env=DEGENBOT_CLI_BUILD_NUMBER={count}");
println!("cargo:rustc-env=DEGENBOT_CLI_BUILD_FINGERPRINT={fingerprint}");
}