include!("shared/splice_crates.rs");
fn main() -> Result<(), Box<dyn std::error::Error>> {
if std::env::var_os("SPLICE_DARS").is_none() {
return Err("set SPLICE_DARS to the directory holding the Splice DARs".into());
}
let root = concat!(env!("CARGO_MANIFEST_DIR"), "/../..");
for (crate_name, source, externals, emits) in CRATES {
let Some(path) = dar_path(*source) else {
println!("{crate_name:<52} skipped — its DAR is not configured");
continue;
};
let (krate, skipped) = canton_codegen::lower_packages_selecting(
&packages(*source, &path)?,
&selection_for(*emits),
&externals_for(externals, *emits),
);
if krate.packages.is_empty() {
return Err(format!(
"{crate_name}: the selection matched no package in {path} — check the names in \
examples/shared/splice_crates.rs against the DAR"
)
.into());
}
let source = canton_codegen::generate_crate(&krate)?;
let out = format!("{root}/crates/{crate_name}/src");
std::fs::create_dir_all(&out)?;
std::fs::write(format!("{out}/lib.rs"), &source)?;
println!(
"{crate_name:<52} {:>2} packages {:>4} KB {} skipped",
krate.packages.len(),
source.len() / 1024,
skipped.len()
);
if std::env::var_os("SHOW_SKIPPED").is_some() {
for s in &skipped {
println!(" skipped: {s}");
}
}
}
Ok(())
}