Skip to content

Conversation

@sunfishcode
Copy link
Member

This extends Resolve::select_world to be usable for lists of WITs. One such example is wit-bindgen's generate macro's path: parameter, which can take a list of WIT paths. It currently uses a custom select_world implementation, but with this patch in wit-parser, it would be able to use Resolve::select_world instead.

I'm also considering extending the wit-bindgen CLI to accept multiple WIT paths; with this patch, it could use Resolve::select_world as well.

Specifically, this PR makes the package argument to Resolve::select_world an Option, and adds code to handle the case where it's None. A None means the caller has a list of WITs and as such doesn't have a single main package.

This also rewrites the documentation for select_world to clean up already-obsolete references to the packages array argument, and to hopefully make it more clear how select_world makes its choice.

This extends `Resolve::select_world` to be usable for lists of WITs. One
such example is wit-bindgen's `generate` macro's `path:` parameter,
which can take a list of WIT paths. It currently uses a
[custom `select_world` implementation], but with this patch in wit-parser,
it would be able to use `Resolve::select_world` instead.

I'm also considering extending the wit-bindgen CLI to accept multiple WIT
paths; with this patch, it could use `Resolve::select_world` as well.

[custom `select_world` implementation]: https://github.com/bytecodealliance/wit-bindgen/blob/0e2201b8629b4144f45867161de7bc1fe26133bb/crates/guest-rust/macro/src/lib.rs#L191

Specifically, this PR makes the package argument to `Resolve::select_world`
an `Option`, and adds code to handle the case where it's `None`. A
`None` means the caller has a list of WITs and as such doesn't have a
single main package.

This also rewrites the documentation for `select_world` to clean up
already-obsolete references to the `packages` array argument, and to
hopefully make it more clear how `select_world` makes its choice.
@sunfishcode sunfishcode requested a review from a team as a code owner August 25, 2025 14:00
@sunfishcode sunfishcode requested review from fitzgen and removed request for a team August 25, 2025 14:00
@alexcrichton alexcrichton requested review from alexcrichton and removed request for fitzgen August 25, 2025 14:54
@alexcrichton
Copy link
Member

I know that this function has a long and storied history of flip-flopping between various signatures and semantics, and I also don't remember everything as well. WIth this PR though it has a subtly different semantics than the generate! macro where a world name isn't specified where with generate! it works if only one of the "main packages" has a world where with this PR it only works if there's one world in the entire Resolve. I can't quite place my finger on why but that feels like a crucial difference to me where, for example, WASI APIs might frequently be deps of custom WITs which always have worlds but maybe the custom WITs wouldn't have such a world?

Basically: do you think the "main package" argument should be a "main packages" list instead of Option<PackageId>? I forget where that lands on "yes we tried this a year ago and moved away from it" spectrum but it would solve what I'm thinking here because the "no world specified, multiple packages, check for just one world" part of this selection would only consult the list of packages provided, no others.

@sunfishcode
Copy link
Member Author

Going by the git logs, the switch to using one main package was in #1700, which introduced the idea of requiring a single root package, which I think still makes sense within a given WIT directory.

I think what's new now is that we're also supporting lists of independent WIT directories, and at this level, there may not be a single root package connecting them all. With that understanding, I think it makes sense to switch back to a list of main packages, so I've now updated the patch to do this.

Copy link
Member

@alexcrichton alexcrichton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for digging that up!

@alexcrichton alexcrichton added this pull request to the merge queue Aug 25, 2025
@alexcrichton
Copy link
Member

Oh I should also mention:

I'm also considering extending the wit-bindgen CLI to accept multiple WIT paths

Sounds reasonable to me!

Merged via the queue into bytecodealliance:main with commit 46f768a Aug 25, 2025
34 checks passed
sunfishcode added a commit to sunfishcode/wit-bindgen that referenced this pull request Aug 26, 2025
Accept multiple WIT paths in the wit-bindgen CLI, using the same logic
as the multiple WIT paths accepted by the `path` parameter in the
Rust bindgen macro.

This depends on bytecodealliance/wasm-tools#2288, which is not yet
released.
sunfishcode added a commit to sunfishcode/wit-bindgen that referenced this pull request Aug 26, 2025
Accept multiple WIT paths in the wit-bindgen CLI, using the same logic
as the multiple WIT paths accepted by the `path` parameter in the
Rust bindgen macro.

This depends on bytecodealliance/wasm-tools#2288, which is not yet
released.
sunfishcode added a commit to sunfishcode/wit-bindgen that referenced this pull request Aug 26, 2025
Accept multiple WIT paths in the wit-bindgen CLI, using the same logic
as the multiple WIT paths accepted by the `path` parameter in the
Rust bindgen macro.

This depends on bytecodealliance/wasm-tools#2288, which is not yet
released.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants