ic-wasm metadata simply attaches the exact content to the designated metadata section. ic-wasm does not handle the candid:service section specially; it has no Candid-related logic, such as parsing or resolving import service statements.
In my opinion, the candid:service section should contain a self-contained Candid interface without referring to other Candid files. Ideally, a tool would convert a Candid file with import statements into one without them. Unfortunately, I don’t believe such a tool currently exists, and we should definitely consider creating one.
use std::path::Path;
use candid::{TypeEnv, pretty::candid::compile};
use candid_parser::{IDLProg, check_file, check_prog};
const FILE_PATH: &str = "./a.did";
fn main() {
let (env, actor) = check_file(Path::new(FILE_PATH)).unwrap();
let content = compile(&env, &actor);
// This block checks that the output is valid candid, can be skipped
{
let ast = content.parse::<IDLProg>().unwrap();
check_prog(&mut TypeEnv::new(), &ast).unwrap();
}
println!("{content}");
}
Amazing @ilbert! This does indeed seem to be exactly what I need. Plus, I already have a custom wrapper around didc — junobuild-didc — which I use to generate TypeScript and JavaScript with the Juno CLI (mainly because I wanted something installable via cargo install, which isn’t the case with didc, and tailored arguments).
Long story short, I can extend it with your suggested code, as I just did in the following PR!
As a side question, I’m interested in this choice: was it too complicated to contribute to the original didc tool to add such features? If yes, what made them so complicated?
More broadly, I think the IC ecosystem would benefit a lot if we all contributed together to making the dev experience better and better, by improving the existing tools and libraries as much as we can. Plus, your contributions are always so valuable!
I’m not sure if it was too complicated, but I definitely didn’t have the time to discuss, (try to) argue, or wait for the feature to be potentially prioritized when I needed those capabilities for a broader implementation — so I went with a custom-tailored wrapper.
The IC ecosystem benefits from it too: it’s available out of the box for anyone using Juno, and it’s open source.