use std::path::PathBuf;
fn main() {
println!("cargo:rustc-check-cfg=cfg(canic_accepts_delegation_signer_proof)");
println!("cargo:rustc-check-cfg=cfg(canic_accepts_delegation_verifier_proof)");
println!("cargo:rustc-check-cfg=cfg(canic_delegated_tokens_enabled)");
println!("cargo:rustc-check-cfg=cfg(canic_icrc21_enabled)");
println!("cargo:rustc-check-cfg=cfg(canic_is_root)");
println!("cargo:rustc-check-cfg=cfg(canic_has_scaling)");
println!("cargo:rustc-check-cfg=cfg(canic_has_sharding)");
println!("cargo:rustc-check-cfg=cfg(canic_disable_bundle_standards_icrc)");
println!("cargo:rustc-check-cfg=cfg(canic_disable_bundle_standards_canic)");
println!("cargo:rustc-check-cfg=cfg(canic_disable_bundle_observability_memory)");
println!("cargo:rustc-check-cfg=cfg(canic_disable_bundle_observability_env)");
println!("cargo:rustc-check-cfg=cfg(canic_disable_bundle_observability_log)");
println!("cargo:rustc-check-cfg=cfg(canic_disable_bundle_metrics)");
println!("cargo:rustc-check-cfg=cfg(canic_disable_bundle_auth_attestation)");
println!("cargo:rustc-check-cfg=cfg(canic_disable_bundle_topology_state)");
println!("cargo:rustc-check-cfg=cfg(canic_disable_bundle_topology_directory)");
println!("cargo:rustc-check-cfg=cfg(canic_disable_bundle_topology_children)");
println!("cargo:rustc-check-cfg=cfg(canic_disable_bundle_topology_cycles)");
println!("cargo:rustc-check-cfg=cfg(canic_disable_bundle_topology_placement)");
println!("cargo:rustc-check-cfg=cfg(canic_disable_bundle_nonroot_sync_topology)");
println!("cargo:rerun-if-env-changed=CANIC_CONFIG_PATH");
let manifest_dir =
PathBuf::from(std::env::var("CARGO_MANIFEST_DIR").expect("CARGO_MANIFEST_DIR must be set"));
let repo_cfg = manifest_dir.join("../canisters/canic.toml");
let env_cfg = std::env::var("CANIC_CONFIG_PATH").ok();
let cfg_path = env_cfg.as_ref().map_or(repo_cfg, |val| {
let path = PathBuf::from(val);
if path.is_relative() {
manifest_dir.join(path)
} else {
path
}
});
if env_cfg.is_some() {
assert!(
cfg_path.exists(),
"Missing Canic config at {}",
cfg_path.display()
);
} else if !cfg_path.exists() {
println!(
"cargo:warning=CANIC_CONFIG_PATH not set and default config not found at {}; \
skipping config validation (likely a packaged build)",
cfg_path.display()
);
return;
}
println!("cargo:rerun-if-changed={}", cfg_path.display());
if let Some(parent) = cfg_path.parent() {
println!("cargo:rerun-if-changed={}", parent.display());
}
let config_str = std::fs::read_to_string(&cfg_path).expect("read canic config for validation");
canic_core::bootstrap::init_config(&config_str).expect("invalid canic config");
println!(
"cargo:rustc-env=CANIC_CONFIG_PATH={}",
cfg_path
.canonicalize()
.expect("canonicalize canic config path")
.display()
);
}