Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support multiple documents with a single default world. #494

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 15 additions & 9 deletions src/bin/wit-bindgen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,16 +162,22 @@ fn gen_world(
}
}
None => {
let mut docs = resolve.packages[pkg].documents.iter();
let (_, doc) = docs
.next()
.ok_or_else(|| anyhow!("no documents found in package"))?;
if docs.next().is_some() {
bail!("multiple documents found in package, specify which to bind with `--world` argument")
if resolve.packages[pkg].documents.is_empty() {
bail!("no documents found in package")
}
resolve.documents[*doc]
.default_world
.ok_or_else(|| anyhow!("no default world in document"))?

let mut unique_default_world = None;
for (_name, doc) in &resolve.documents {
if let Some(default_world) = doc.default_world {
if unique_default_world.is_some() {
bail!("multiple default worlds found in package, specify which to bind with `--world` argument")
} else {
unique_default_world = Some(default_world);
}
}
}

unique_default_world.ok_or_else(|| anyhow!("no default world in package"))?
}
};
generator.generate(&resolve, world, files);
Expand Down