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

Always generate the same output structure with bindgen! #8721

Conversation

alexcrichton
Copy link
Member

Currently with the bindgen! macro when the with key is used then the generated bindings are different than if the with key was not used. Not only for replacement purposes but the generated bindings are missing two key pieces:

  • In the generated add_to_linker functions bounds and invocations of with-overridden interfaces are all missing. This means that the generated add_to_linker functions don't actually represent the full world.

  • The generated module hierarchy has "holes" for all the modules that are overridden. While it's mostly a minor inconvenience it's also easy enough to generate everything via pub use to have everything hooked up correctly.

After this PR it means that each bindgen! macro should, in isolation, work for any other bindgen! macro invocation. It shouldn't be necessary to weave things together and remember how each macro was invoked along the way. This is primarily to unblock #8715 which is running into a case where tcp/udp are generated as sync but their dependency, wasi:sockets/network, is used from an upstream async version. The generated add_to_linker does not compile because tcp/udp depend on wasi:sockets/network isn't added to the linker. After fixing that it then required more modules to be generated, hence this PR.

Currently with the `bindgen!` macro when the `with` key is used then the
generated bindings are different than if the `with` key was not used.
Not only for replacement purposes but the generated bindings are missing
two key pieces:

* In the generated `add_to_linker` functions bounds and invocations of
  `with`-overridden interfaces are all missing. This means that the
  generated `add_to_linker` functions don't actually represent the full
  world.

* The generated module hierarchy has "holes" for all the modules that
  are overridden. While it's mostly a minor inconvenience it's also easy
  enough to generate everything via `pub use` to have everything hooked
  up correctly.

After this PR it means that each `bindgen!` macro should, in isolation,
work for any other `bindgen!` macro invocation. It shouldn't be
necessary to weave things together and remember how each macro was
invoked along the way. This is primarily to unblock bytecodealliance#8715 which is
running into a case where tcp/udp are generated as sync but their
dependency, `wasi:sockets/network`, is used from an upstream async
version. The generated `add_to_linker` does not compile because tcp/udp
depend on `wasi:sockets/network` isn't added to the linker. After fixing
that it then required more modules to be generated, hence this PR.
@alexcrichton alexcrichton requested a review from a team as a code owner May 31, 2024 16:02
@alexcrichton alexcrichton requested review from pchickey and removed request for a team May 31, 2024 16:02
@@ -136,9 +136,10 @@ pub mod sync {
async: false,
with: {
"wasi:http": crate::bindings::http, // http is in this crate
"wasi:io": wasmtime_wasi::bindings::sync, // io is sync
"wasi:io": wasmtime_wasi::bindings::sync::io, // io is sync
Copy link
Member Author

Choose a reason for hiding this comment

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

This was a bug from before this PR and probably shouldn't have ever worked...

@alexcrichton alexcrichton enabled auto-merge May 31, 2024 17:23
@github-actions github-actions bot added wasi Issues pertaining to WASI wasmtime:api Related to the API of the `wasmtime` crate itself labels May 31, 2024
Copy link
Contributor

@pchickey pchickey left a comment

Choose a reason for hiding this comment

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

cc @MendyBerger can you see if this improves any of the code we looked at together earlier this week?

@alexcrichton alexcrichton added this pull request to the merge queue May 31, 2024
Merged via the queue into bytecodealliance:main with commit 54d3695 May 31, 2024
36 checks passed
@alexcrichton alexcrichton deleted the full-bindings-generation-each-time branch May 31, 2024 20:07
@MendyBerger
Copy link

MendyBerger commented Jun 10, 2024

@pchickey I'm unable to get the code to compile when I rebase on top of this git rev.
Let me know if it's important that I test it. If so, I'll spend some more time on it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
wasi Issues pertaining to WASI wasmtime:api Related to the API of the `wasmtime` crate itself
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants