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

Configure WIT feature gates at runtime & implement wasi-cli exit-with-code #9381

Merged
merged 15 commits into from
Oct 7, 2024

Conversation

badeend
Copy link
Contributor

@badeend badeend commented Oct 6, 2024

For extra context, see: #9276


This PR adds the ability to enable/disable WIT APIs gated by @unstable(feature = ...) at link-time.

Previously, unstable features could only be controlled at compile-time through the features option of wasmtime::component::bindgen!. That option has been removed. Bindings for unstable APIs are now generated unconditionally. Instead, the generated add_to_linker*** functions take an additional LinkOptions parameter if the world/interface has any unstable features. The availability of unstable features is now controlled through that.

The component bindgen generates a fresh LinkOptions type for each interface that needs it and a single LinkOptions type for the entire world, which is a union of all the options contained in that world. An example is included in the component-macro tests: unstable-features.wit produces:
https://github.com/badeend/wasmtime/compare/245dcab34c2fcae69e0f6c3f2daa15837ea6ff61..4fcfe6f866f36ed663f24199e1744bed3cf0bc2c#diff-ad635965474c257cbafce510463aaf52c1ac813f22168045ae22546d3b3ebfc6


A happy coincidence is that WASI-0.2.1 already includes a tiny but practical first use case: exit-with-code.
I've implemented that function and is gated behind the -Scli-exit-with-code CLI flag.

@sunfishcode, if I interpret WebAssembly/wasi-cli#11 correctly, you were OK with removing the Windows-specific restriction, right? See: badeend@2f48c77

@badeend badeend requested a review from a team as a code owner October 6, 2024 10:40
@badeend badeend requested review from fitzgen and removed request for a team October 6, 2024 10:40
@github-actions github-actions bot added the wasi Issues pertaining to WASI label Oct 6, 2024
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.

This looks great to me, thanks for this!

In retrospect though given the large number of changes related to add_to_linker what do you think about:

  • Interface/world-level add_to_linker retains the LinkOptions parameter
  • Top-level add_to_linker loses the LinkOptions parameter, and there's a new top-level add_to_linker_with_options function?

Or perhaps this would only affect the helpers we have in wasmtime-wasi and wasmtime-wasi-http? Basically it looks like there should be a convenience function for "default options" rather than requiring all callers to call it.

crates/wit-bindgen/src/lib.rs Outdated Show resolved Hide resolved
@badeend
Copy link
Contributor Author

badeend commented Oct 7, 2024

  • Interface/world-level add_to_linker retains the LinkOptions parameter
  • Top-level add_to_linker loses the LinkOptions parameter, and there's a new top-level add_to_linker_with_options function?

Don't know what top-level function you're referring to. I think the Interface/world-level add_to_linker functions are the only ones generated by the bindgen?

I have just updated the wasmtime-wasi's functions back to their old signature and added an extra set of _with_options variants. I didn't touch the add_to_linker functions generated by bindgen.

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.

Ah sorry for my rambling, this is exactly what I was thinking 👍

@alexcrichton alexcrichton added this pull request to the merge queue Oct 7, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Oct 7, 2024
@badeend
Copy link
Contributor Author

badeend commented Oct 7, 2024

Try again please

@alexcrichton alexcrichton added this pull request to the merge queue Oct 7, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Oct 7, 2024
@badeend
Copy link
Contributor Author

badeend commented Oct 7, 2024

Sigh.

Try again, again?

@alexcrichton alexcrichton added this pull request to the merge queue Oct 7, 2024
Merged via the queue into bytecodealliance:main with commit c230353 Oct 7, 2024
39 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
wasi Issues pertaining to WASI
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants