-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
wiggle: support for Rust async #2701
Conversation
Subscribe to Label Actioncc @kubkon
This issue or pull request has been labeled: "wasi"
Thus the following users have been cc'd because of the following labels:
To subscribe or unsubscribe from this label, edit the |
Subscribe to Label Actioncc @peterhuene
This issue or pull request has been labeled: "wasmtime:api"
Thus the following users have been cc'd because of the following labels:
To subscribe or unsubscribe from this label, edit the |
e54e76c
to
1e4cde6
Compare
* ctx parameter no longer accepted by wiggle::from_witx macro. * optional async_ parameter specifies which functions are async. * re-export async_trait::async_trait, so users don't have to take a dep.
wiggle-macro doc tests weren't being run, so docs had gotten out of sync.
1e4cde6
to
af49505
Compare
crates/wiggle/generate/src/config.rs
Outdated
} else if lookahead.peek(kw::errors) { | ||
input.parse::<kw::errors>()?; | ||
input.parse::<Token![:]>()?; | ||
Ok(ConfigField::Error(input.parse()?)) | ||
} else if lookahead.peek(kw::async_) { | ||
input.parse::<kw::async_>()?; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could this parse the async
keyword itself to avoid the underscore? (given this is a macro I'd assume we could do whatever syntax we wanted here)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure. I don't know why I never thought of that.
Following #2434, wiggle now supports async functions. Users of the wiggle macro can specify which functions should be async with a new
async_
section of the settings.The new integration test of wasmtime-wiggle shows async support working end-to-end: https://github.com/bytecodealliance/wasmtime/pull/2701/files#diff-9b1eee5f3bd355b0c43aa2ec5d647ddcc085d50f81324540cdbbce39ca6de21b
I rewrote a bunch of the doc test to document the new functionality, plus other earlier changes that had been left out: https://github.com/bytecodealliance/wasmtime/blob/1e4cde62ab510f6c5b551ab73203b48bff707635/crates/wiggle/macro/src/lib.rs
During this work I realized that the wiggle::from_witx macro did not need to take the user's so-called
ctx
type as an argument to the macro. Instead, all code generated bywiggle
is generic - it will accept any type which implements the required traits. (Async lifetime issues meant it was easier to make this particular type generic rather than concrete, because lifetime parameters can't be elided in some async fn contexts.) Thewasmtime-wiggle
integration does still require the user to specify a concrete ctx type.Over in
crates/wasmtime
, I added a missing functionLinker::instantiate_async
, for use with async stores.