Skip to content

Commit 456e995

Browse files
committed
Add support for async/streams/futures to Rust generator
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 <joel.dice@fermyon.com> 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 <joel.dice@fermyon.com> add codegen tests for futures, streams, and error-contexts Signed-off-by: Joel Dice <joel.dice@fermyon.com>
1 parent 563956d commit 456e995

39 files changed

+3064
-303
lines changed

Cargo.lock

Lines changed: 110 additions & 28 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,13 @@ clap = { version = "4.3.19", features = ["derive"] }
3131
indexmap = "2.0.0"
3232
prettyplease = "0.2.20"
3333
syn = { version = "2.0", features = ["printing"] }
34+
futures = "0.3.31"
3435

35-
wasmparser = "0.220.0"
36-
wasm-encoder = "0.220.0"
37-
wasm-metadata = "0.220.0"
38-
wit-parser = "0.220.0"
39-
wit-component = "0.220.0"
36+
wasmparser = { git = "https://github.com/dicej/wasm-tools", branch = "async" }
37+
wasm-encoder = { git = "https://github.com/dicej/wasm-tools", branch = "async" }
38+
wasm-metadata = { git = "https://github.com/dicej/wasm-tools", branch = "async" }
39+
wit-parser = { git = "https://github.com/dicej/wasm-tools", branch = "async" }
40+
wit-component = { git = "https://github.com/dicej/wasm-tools", branch = "async" }
4041

4142
wit-bindgen-core = { path = 'crates/core', version = '0.35.0' }
4243
wit-bindgen-c = { path = 'crates/c', version = '0.35.0' }
@@ -74,6 +75,7 @@ default = [
7475
'go',
7576
'csharp',
7677
'moonbit',
78+
'async',
7779
]
7880
c = ['dep:wit-bindgen-c']
7981
rust = ['dep:wit-bindgen-rust']
@@ -83,6 +85,7 @@ go = ['dep:wit-bindgen-go']
8385
csharp = ['dep:wit-bindgen-csharp']
8486
csharp-mono = ['csharp']
8587
moonbit = ['dep:wit-bindgen-moonbit']
88+
async = ["wit-bindgen-rust/async"]
8689

8790
[dev-dependencies]
8891
heck = { workspace = true }

0 commit comments

Comments
 (0)