use std::{env, fs, path::PathBuf};
const GLOBAL_HOME_ENV: &str = "DHTTP_GLOBAL_HOME";
fn main() {
let out_dir = PathBuf::from(env::var("OUT_DIR").expect("OUT_DIR is set by cargo"));
let bootstrap = format!(
"// @generated by build.rs; do not edit.\n\
pub const DHTTP_GLOBAL_HOME: Option<&str> = {};\n",
option_expr(env::var(GLOBAL_HOME_ENV).ok().as_deref())
);
fs::write(out_dir.join("bootstrap.rs"), bootstrap)
.expect("failed to write generated dhttp-home bootstrap constants");
println!("cargo::rerun-if-env-changed={GLOBAL_HOME_ENV}");
}
fn option_expr(value: Option<&str>) -> String {
match value {
Some(value) => format!("Some({value:?})"),
None => "None".to_owned(),
}
}