Skip to content

Commit

Permalink
Add support for async/streams/futures to Rust generator
Browse files Browse the repository at this point in the history
This adds support for generating bindings which use the [Async
ABI](https://github.com/WebAssembly/component-model/blob/main/design/mvp/Async.md)
along with the [`stream`, `future`, and
`error-context`](WebAssembly/component-model#405) types.

By default, normal synchronous bindings are generated, but the user may opt-in
to async bindings for all or some of the imported and/or exported functions in
the target world and interfaces -- provided the default-enabled `async` feature
is enabled.

In addition, we generate `StreamPayload` and/or `FuturePayload` trait
implementations for any types appearing as the `T` in `stream<T>` or `future<T>`
in the WIT files, respectively.  That enables user code to call `new_stream` or
`new_future` to create `stream`s or `future`s with those payload types, then
write to them, read from them, and/or pass the readable end as a parameter to a
component import or return value of a component export.

Note that I've added new `core::abi::Instruction` enum variants to handle async
lifting and lowering, but they're currently tailored to the Rust generator and
will probably change somewhat as we add support for other languages.

This does not include any new tests; I'll add those in a follow-up commit.

Signed-off-by: Joel Dice <[email protected]>

add `async: true` case to Rust `codegen_tests`

This ensures that all the codegen test WIT files produce compile-able bindings
with `async: true` (i.e. all imports lowered and all exports lifted using the
async ABI).  That revealed some issues involving resource methods and
constructors, as well as missing stub support, which I've resolved.

Signed-off-by: Joel Dice <[email protected]>

add codegen tests for futures, streams, and error-contexts

Signed-off-by: Joel Dice <[email protected]>
  • Loading branch information
dicej committed Nov 20, 2024
1 parent 563956d commit 456e995
Show file tree
Hide file tree
Showing 39 changed files with 3,064 additions and 303 deletions.
138 changes: 110 additions & 28 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 8 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,13 @@ clap = { version = "4.3.19", features = ["derive"] }
indexmap = "2.0.0"
prettyplease = "0.2.20"
syn = { version = "2.0", features = ["printing"] }
futures = "0.3.31"

wasmparser = "0.220.0"
wasm-encoder = "0.220.0"
wasm-metadata = "0.220.0"
wit-parser = "0.220.0"
wit-component = "0.220.0"
wasmparser = { git = "https://github.com/dicej/wasm-tools", branch = "async" }
wasm-encoder = { git = "https://github.com/dicej/wasm-tools", branch = "async" }
wasm-metadata = { git = "https://github.com/dicej/wasm-tools", branch = "async" }
wit-parser = { git = "https://github.com/dicej/wasm-tools", branch = "async" }
wit-component = { git = "https://github.com/dicej/wasm-tools", branch = "async" }

wit-bindgen-core = { path = 'crates/core', version = '0.35.0' }
wit-bindgen-c = { path = 'crates/c', version = '0.35.0' }
Expand Down Expand Up @@ -74,6 +75,7 @@ default = [
'go',
'csharp',
'moonbit',
'async',
]
c = ['dep:wit-bindgen-c']
rust = ['dep:wit-bindgen-rust']
Expand All @@ -83,6 +85,7 @@ go = ['dep:wit-bindgen-go']
csharp = ['dep:wit-bindgen-csharp']
csharp-mono = ['csharp']
moonbit = ['dep:wit-bindgen-moonbit']
async = ["wit-bindgen-rust/async"]

[dev-dependencies]
heck = { workspace = true }
Expand Down
Loading

0 comments on commit 456e995

Please sign in to comment.