From 2ed168666d72eb5260542eb7879c7a713884ed81 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Tue, 22 Apr 2025 09:26:48 -0700 Subject: [PATCH 1/3] Update WIT in tests with `async` This commit updates the WIT used in test to use the `async` keyword and generally try to avoid manually configuring what's async and what's not in the guest. This does not update the host's handling of the `async` keyword in WIT for `wasmtime::component::bindgen!`. Some assorted bindgen issues were fixed here and there and WASI WITs were updated as well with `async` where it seemed appropriate. I'll note that there are some usages of concurrent imports when there's no actual concurrency, it's just there for getting an `Accessor` and, for example, spawning tasks. In these situations we may want to explore possible modes of bindings generation on the host side of things which avoids the need for manual configuration. Coupled with bytecodealliance/wit-bindgen#1278 and bytecodealliance/wit-bindgen#1279. --- Cargo.lock | 123 +++++++--- Cargo.toml | 6 +- .../component-async-tests/http/src/lib.rs | 2 +- .../misc/component-async-tests/src/sleep.rs | 2 +- .../component-async-tests/src/yield_host.rs | 2 +- .../tests/scenario/round_trip.rs | 4 +- .../tests/scenario/round_trip_many.rs | 4 +- .../tests/scenario/transmit.rs | 6 +- .../wit/deps/http/handler.wit | 2 +- .../misc/component-async-tests/wit/test.wit | 30 +-- .../src/bin/async_backpressure_callee.rs | 5 - .../src/bin/async_backpressure_caller.rs | 8 - .../src/bin/async_borrowing_callee.rs | 6 - .../src/bin/async_borrowing_caller.rs | 8 - .../src/bin/async_cancel_callee.rs | 12 +- .../src/bin/async_cancel_caller.rs | 4 +- .../src/bin/async_error_context.rs | 5 - .../src/bin/async_error_context_callee.rs | 7 - .../src/bin/async_error_context_caller.rs | 8 - .../test-programs/src/bin/async_http_echo.rs | 8 - .../src/bin/async_http_middleware.rs | 8 - .../bin/async_http_middleware_with_chain.rs | 9 - .../src/bin/async_poll_stackless.rs | 8 +- .../src/bin/async_poll_synchronous.rs | 3 +- .../src/bin/async_post_return_callee.rs | 72 ++---- .../src/bin/async_post_return_caller.rs | 8 - .../src/bin/async_read_resource_stream.rs | 5 - .../src/bin/async_round_trip_many_stackful.rs | 6 +- .../bin/async_round_trip_many_synchronous.rs | 1 + .../src/bin/async_round_trip_many_wait.rs | 6 +- .../src/bin/async_round_trip_stackful.rs | 6 +- .../async_round_trip_stackless_sync_import.rs | 6 +- .../src/bin/async_round_trip_synchronous.rs | 1 + .../src/bin/async_round_trip_wait.rs | 6 +- .../src/bin/async_transmit_callee.rs | 5 - .../src/bin/async_transmit_caller.rs | 8 - .../src/bin/async_unit_stream_callee.rs | 5 - .../src/bin/async_unit_stream_caller.rs | 8 - .../src/bin/async_yield_callee_stackless.rs | 6 +- .../src/bin/async_yield_callee_synchronous.rs | 1 + .../src/bin/async_yield_caller.rs | 9 - .../src/bin/p3_filesystem_file_read_write.rs | 5 +- crates/test-programs/src/p3/mod.rs | 27 +-- crates/wasi-http/src/p3/bindings.rs | 2 +- .../p3/wit/deps/clocks/monotonic-clock.wit | 4 +- .../src/p3/wit/deps/filesystem/types.wit | 48 ++-- .../src/p3/wit/deps/http/handler.wit | 2 +- .../p3/wit/deps/sockets/ip-name-lookup.wit | 2 +- .../src/p3/wit/deps/sockets/types.wit | 12 +- crates/wasi/src/p3/bindings.rs | 211 +++--------------- .../p3/wit/deps/clocks/monotonic-clock.wit | 4 +- .../wasi/src/p3/wit/deps/filesystem/types.wit | 48 ++-- .../p3/wit/deps/sockets/ip-name-lookup.wit | 2 +- crates/wasi/src/p3/wit/deps/sockets/types.wit | 12 +- crates/wit-bindgen/src/lib.rs | 21 +- 55 files changed, 299 insertions(+), 540 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 4d76391168..155b117d33 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3456,7 +3456,7 @@ dependencies = [ "heck 0.5.0", "wasmparser 0.228.0", "wasmtime", - "wit-component", + "wit-component 0.228.0", ] [[package]] @@ -3993,7 +3993,7 @@ dependencies = [ "byte-array-literals", "object", "wasi 0.11.0+wasi-snapshot-preview1", - "wasm-encoder", + "wasm-encoder 0.228.0", "wit-bindgen-rust-macro", ] @@ -4067,7 +4067,7 @@ dependencies = [ "serde_derive", "serde_yaml", "smallvec", - "wasm-encoder", + "wasm-encoder 0.228.0", "wasmparser 0.228.0", "wat", ] @@ -4081,6 +4081,16 @@ dependencies = [ "wasmparser 0.228.0", ] +[[package]] +name = "wasm-encoder" +version = "0.229.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38ba1d491ecacb085a2552025c10a675a6fddcbd03b1fc9b36c536010ce265d2" +dependencies = [ + "leb128fmt", + "wasmparser 0.229.0", +] + [[package]] name = "wasm-metadata" version = "0.228.0" @@ -4088,10 +4098,22 @@ source = "git+https://github.com/bytecodealliance/wasm-tools#ffdf16c109ea99ff7c9 dependencies = [ "anyhow", "indexmap 2.7.0", - "wasm-encoder", + "wasm-encoder 0.228.0", "wasmparser 0.228.0", ] +[[package]] +name = "wasm-metadata" +version = "0.229.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78fdb7d29a79191ab363dc90c1ddd3a1e880ffd5348d92d48482393a9e6c5f4d" +dependencies = [ + "anyhow", + "indexmap 2.7.0", + "wasm-encoder 0.229.0", + "wasmparser 0.229.0", +] + [[package]] name = "wasm-mutate" version = "0.228.0" @@ -4101,7 +4123,7 @@ dependencies = [ "log", "rand", "thiserror 1.0.65", - "wasm-encoder", + "wasm-encoder 0.228.0", "wasmparser 0.228.0", ] @@ -4113,7 +4135,7 @@ dependencies = [ "anyhow", "arbitrary", "flagset", - "wasm-encoder", + "wasm-encoder 0.228.0", ] [[package]] @@ -4132,7 +4154,7 @@ dependencies = [ "indexmap 2.7.0", "logos", "thiserror 1.0.65", - "wit-parser", + "wit-parser 0.228.0", ] [[package]] @@ -4201,6 +4223,18 @@ dependencies = [ "serde", ] +[[package]] +name = "wasmparser" +version = "0.229.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0cc3b1f053f5d41aa55640a1fa9b6d1b8a9e4418d118ce308d20e24ff3575a8c" +dependencies = [ + "bitflags 2.6.0", + "hashbrown 0.15.2", + "indexmap 2.7.0", + "semver", +] + [[package]] name = "wasmprinter" version = "0.228.0" @@ -4256,7 +4290,7 @@ dependencies = [ "tempfile", "trait-variant", "wasi-common", - "wasm-encoder", + "wasm-encoder 0.228.0", "wasm-wave", "wasmparser 0.228.0", "wasmtime-asm-macros", @@ -4403,7 +4437,7 @@ dependencies = [ "trait-variant", "walkdir", "wasi-common", - "wasm-encoder", + "wasm-encoder 0.228.0", "wasmparser 0.228.0", "wasmtime", "wasmtime-cache", @@ -4425,7 +4459,7 @@ dependencies = [ "wast 228.0.0", "wat", "windows-sys 0.59.0", - "wit-component", + "wit-component 0.228.0", ] [[package]] @@ -4460,7 +4494,7 @@ dependencies = [ "wasmtime", "wasmtime-component-util", "wasmtime-wit-bindgen", - "wit-parser", + "wit-parser 0.228.0", ] [[package]] @@ -4512,7 +4546,7 @@ dependencies = [ "serde_derive", "smallvec", "target-lexicon", - "wasm-encoder", + "wasm-encoder 0.228.0", "wasmparser 0.228.0", "wasmprinter", "wasmtime-component-util", @@ -4605,7 +4639,7 @@ dependencies = [ "target-lexicon", "tempfile", "v8", - "wasm-encoder", + "wasm-encoder 0.228.0", "wasm-mutate", "wasm-smith", "wasm-spec-interpreter", @@ -4863,7 +4897,7 @@ dependencies = [ "anyhow", "heck 0.5.0", "indexmap 2.7.0", - "wit-parser", + "wit-parser 0.228.0", ] [[package]] @@ -4888,7 +4922,7 @@ dependencies = [ "leb128fmt", "memchr", "unicode-width 0.2.0", - "wasm-encoder", + "wasm-encoder 0.228.0", ] [[package]] @@ -5183,7 +5217,7 @@ dependencies = [ [[package]] name = "wit-bindgen" version = "0.41.0" -source = "git+https://github.com/bytecodealliance/witx-bindgen#be0de78ffb80ced696b29eefe6c3c45b913fb939" +source = "git+https://github.com/bytecodealliance/wit-bindgen#906e096d462160a1fd0554feebd2152b8393e99d" dependencies = [ "wit-bindgen-rt 0.41.0", "wit-bindgen-rust-macro", @@ -5192,11 +5226,11 @@ dependencies = [ [[package]] name = "wit-bindgen-core" version = "0.41.0" -source = "git+https://github.com/bytecodealliance/witx-bindgen#be0de78ffb80ced696b29eefe6c3c45b913fb939" +source = "git+https://github.com/bytecodealliance/wit-bindgen#906e096d462160a1fd0554feebd2152b8393e99d" dependencies = [ "anyhow", "heck 0.5.0", - "wit-parser", + "wit-parser 0.229.0", ] [[package]] @@ -5220,7 +5254,7 @@ dependencies = [ [[package]] name = "wit-bindgen-rt" version = "0.41.0" -source = "git+https://github.com/bytecodealliance/witx-bindgen#be0de78ffb80ced696b29eefe6c3c45b913fb939" +source = "git+https://github.com/bytecodealliance/wit-bindgen#906e096d462160a1fd0554feebd2152b8393e99d" dependencies = [ "bitflags 2.6.0", "futures", @@ -5230,22 +5264,22 @@ dependencies = [ [[package]] name = "wit-bindgen-rust" version = "0.41.0" -source = "git+https://github.com/bytecodealliance/witx-bindgen#be0de78ffb80ced696b29eefe6c3c45b913fb939" +source = "git+https://github.com/bytecodealliance/wit-bindgen#906e096d462160a1fd0554feebd2152b8393e99d" dependencies = [ "anyhow", "heck 0.5.0", "indexmap 2.7.0", "prettyplease", "syn 2.0.100", - "wasm-metadata", + "wasm-metadata 0.229.0", "wit-bindgen-core", - "wit-component", + "wit-component 0.229.0", ] [[package]] name = "wit-bindgen-rust-macro" version = "0.41.0" -source = "git+https://github.com/bytecodealliance/witx-bindgen#be0de78ffb80ced696b29eefe6c3c45b913fb939" +source = "git+https://github.com/bytecodealliance/wit-bindgen#906e096d462160a1fd0554feebd2152b8393e99d" dependencies = [ "anyhow", "prettyplease", @@ -5268,10 +5302,29 @@ dependencies = [ "serde", "serde_derive", "serde_json", - "wasm-encoder", - "wasm-metadata", + "wasm-encoder 0.228.0", + "wasm-metadata 0.228.0", "wasmparser 0.228.0", - "wit-parser", + "wit-parser 0.228.0", +] + +[[package]] +name = "wit-component" +version = "0.229.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f550067740e223bfe6c4878998e81cdbe2529dd9a793dc49248dd6613394e8b" +dependencies = [ + "anyhow", + "bitflags 2.6.0", + "indexmap 2.7.0", + "log", + "serde", + "serde_derive", + "serde_json", + "wasm-encoder 0.229.0", + "wasm-metadata 0.229.0", + "wasmparser 0.229.0", + "wit-parser 0.229.0", ] [[package]] @@ -5291,6 +5344,24 @@ dependencies = [ "wasmparser 0.228.0", ] +[[package]] +name = "wit-parser" +version = "0.229.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "459c6ba62bf511d6b5f2a845a2a736822e38059c1cfa0b644b467bbbfae4efa6" +dependencies = [ + "anyhow", + "id-arena", + "indexmap 2.7.0", + "log", + "semver", + "serde", + "serde_derive", + "serde_json", + "unicode-xid", + "wasmparser 0.229.0", +] + [[package]] name = "witx" version = "0.9.1" diff --git a/Cargo.toml b/Cargo.toml index 81fbe80b8e..bdafd8f436 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -608,9 +608,9 @@ wit-component = { git = "https://github.com/bytecodealliance/wasm-tools" } wasm-wave = { git = "https://github.com/bytecodealliance/wasm-tools" } wasm-compose = { git = "https://github.com/bytecodealliance/wasm-tools" } wasm-metadata = { git = "https://github.com/bytecodealliance/wasm-tools" } -wit-bindgen = { git = "https://github.com/bytecodealliance/witx-bindgen" } -wit-bindgen-rt = { git = "https://github.com/bytecodealliance/witx-bindgen" } -wit-bindgen-rust-macro = { git = "https://github.com/bytecodealliance/witx-bindgen" } +wit-bindgen = { git = "https://github.com/bytecodealliance/wit-bindgen" } +wit-bindgen-rt = { git = "https://github.com/bytecodealliance/wit-bindgen" } +wit-bindgen-rust-macro = { git = "https://github.com/bytecodealliance/wit-bindgen" } # wasmparser = { path = '../wasm-tools/crates/wasmparser' } # wat = { path = '../wasm-tools/crates/wat' } diff --git a/crates/misc/component-async-tests/http/src/lib.rs b/crates/misc/component-async-tests/http/src/lib.rs index 83be7ededc..75d35d9369 100644 --- a/crates/misc/component-async-tests/http/src/lib.rs +++ b/crates/misc/component-async-tests/http/src/lib.rs @@ -13,7 +13,7 @@ wasmtime::component::bindgen!({ "wasi:http/types@0.3.0-draft#[constructor]body", "wasi:http/types@0.3.0-draft#[static]body.new-with-trailers", "wasi:http/types@0.3.0-draft#[static]body.finish", - "wasi:http/handler@0.3.0-draft#handle", + "wasi:http/handler@0.3.0-draft#[async]handle", ] }, with: { diff --git a/crates/misc/component-async-tests/src/sleep.rs b/crates/misc/component-async-tests/src/sleep.rs index 303ecb78c4..933ba0d0c3 100644 --- a/crates/misc/component-async-tests/src/sleep.rs +++ b/crates/misc/component-async-tests/src/sleep.rs @@ -10,7 +10,7 @@ wasmtime::component::bindgen!({ concurrent_exports: true, async: { only_imports: [ - "local:local/sleep#sleep-millis", + "local:local/sleep#[async]sleep-millis", ] }, }); diff --git a/crates/misc/component-async-tests/src/yield_host.rs b/crates/misc/component-async-tests/src/yield_host.rs index c979012e04..2a3006ac7c 100644 --- a/crates/misc/component-async-tests/src/yield_host.rs +++ b/crates/misc/component-async-tests/src/yield_host.rs @@ -14,7 +14,7 @@ pub mod bindings { concurrent_exports: true, async: { only_imports: [ - "local:local/ready#when-ready", + "local:local/ready#[async]when-ready", ] }, }); diff --git a/crates/misc/component-async-tests/tests/scenario/round_trip.rs b/crates/misc/component-async-tests/tests/scenario/round_trip.rs index a7dd148576..08786083d1 100644 --- a/crates/misc/component-async-tests/tests/scenario/round_trip.rs +++ b/crates/misc/component-async-tests/tests/scenario/round_trip.rs @@ -347,7 +347,7 @@ pub async fn test_round_trip(component: &[u8], inputs_and_outputs: &[(&str, &str linker .root() .instance("local:local/baz")? - .func_new_concurrent("foo", |_, params| { + .func_new_concurrent("[async]foo", |_, params| { Box::pin(async move { tokio::time::sleep(Duration::from_millis(10)).await; let Some(Val::String(s)) = params.into_iter().next() else { @@ -366,7 +366,7 @@ pub async fn test_round_trip(component: &[u8], inputs_and_outputs: &[(&str, &str .get_export_index(&mut store, None, "local:local/baz") .ok_or_else(|| anyhow!("can't find `local:local/baz` in instance"))?; let foo_function = instance - .get_export_index(&mut store, Some(&baz_instance), "foo") + .get_export_index(&mut store, Some(&baz_instance), "[async]foo") .ok_or_else(|| anyhow!("can't find `foo` in instance"))?; let foo_function = instance .get_func(&mut store, foo_function) diff --git a/crates/misc/component-async-tests/tests/scenario/round_trip_many.rs b/crates/misc/component-async-tests/tests/scenario/round_trip_many.rs index 9d429f7644..47cb8e0aab 100644 --- a/crates/misc/component-async-tests/tests/scenario/round_trip_many.rs +++ b/crates/misc/component-async-tests/tests/scenario/round_trip_many.rs @@ -306,7 +306,7 @@ async fn test_round_trip_many(component: &[u8], inputs_and_outputs: &[(&str, &st linker .root() .instance("local:local/many")? - .func_new_concurrent("foo", |_, params| { + .func_new_concurrent("[async]foo", |_, params| { Box::pin(async move { tokio::time::sleep(Duration::from_millis(10)).await; let mut params = params.into_iter(); @@ -328,7 +328,7 @@ async fn test_round_trip_many(component: &[u8], inputs_and_outputs: &[(&str, &st .get_export_index(&mut store, None, "local:local/many") .ok_or_else(|| anyhow!("can't find `local:local/many` in instance"))?; let foo_function = instance - .get_export_index(&mut store, Some(&baz_instance), "foo") + .get_export_index(&mut store, Some(&baz_instance), "[async]foo") .ok_or_else(|| anyhow!("can't find `foo` in instance"))?; let foo_function = instance .get_func(&mut store, foo_function) diff --git a/crates/misc/component-async-tests/tests/scenario/transmit.rs b/crates/misc/component-async-tests/tests/scenario/transmit.rs index 70f06f7ac9..d136b3f4d0 100644 --- a/crates/misc/component-async-tests/tests/scenario/transmit.rs +++ b/crates/misc/component-async-tests/tests/scenario/transmit.rs @@ -241,7 +241,11 @@ impl TransmitTest for DynamicTransmitTest { .get_export_index(store.as_context_mut(), None, "local:local/transmit") .ok_or_else(|| anyhow!("can't find `local:local/transmit` in instance"))?; let exchange_function = instance - .get_export_index(store.as_context_mut(), Some(&transmit_instance), "exchange") + .get_export_index( + store.as_context_mut(), + Some(&transmit_instance), + "[async]exchange", + ) .ok_or_else(|| anyhow!("can't find `exchange` in instance"))?; instance .get_func(store.as_context_mut(), exchange_function) diff --git a/crates/misc/component-async-tests/wit/deps/http/handler.wit b/crates/misc/component-async-tests/wit/deps/http/handler.wit index bfe459f40b..e90b737596 100644 --- a/crates/misc/component-async-tests/wit/deps/http/handler.wit +++ b/crates/misc/component-async-tests/wit/deps/http/handler.wit @@ -11,7 +11,7 @@ interface handler { /// /// When imported, this function may be used to either send an outgoing /// request over the network or pass it to another component. - handle: func( + handle: async func( request: request, ) -> result; } diff --git a/crates/misc/component-async-tests/wit/test.wit b/crates/misc/component-async-tests/wit/test.wit index 4fe9c28151..b746dcc7bd 100644 --- a/crates/misc/component-async-tests/wit/test.wit +++ b/crates/misc/component-async-tests/wit/test.wit @@ -1,7 +1,7 @@ package local:local; interface baz { - foo: func(s: string) -> string; + foo: async func(s: string) -> string; } world round-trip { @@ -16,7 +16,7 @@ interface many { c: u64 } - foo: func(a: string, + foo: async func(a: string, b: u32, c: list, d: tuple, @@ -44,7 +44,7 @@ world round-trip-direct { interface ready { set-ready: func(ready: bool); - when-ready: func(); + when-ready: async func(); } interface continue { @@ -53,7 +53,7 @@ interface continue { } interface run { - run: func(); + run: async func(); } interface backpressure { @@ -70,14 +70,14 @@ interface transmit { write-future(string), } - exchange: func(control: stream, + exchange: async func(control: stream, caller-stream: stream, caller-future1: future, caller-future2: future) -> tuple, future, future>; } interface post-return { - foo: func(s: string) -> string; + foo: async func(s: string) -> string; get-post-return-value: func() -> string; } @@ -91,16 +91,16 @@ interface borrowing-types { interface borrowing { use borrowing-types.{x}; - foo: func(x: borrow, misbehave: bool); + foo: async func(x: borrow, misbehave: bool); } interface run-bool { - run: func(v: bool); + run: async func(v: bool); } interface run-result { - run-fail: func() -> result<_, error-context>; - run-pass: func() -> result<_, error-context>; + run-fail: async func() -> result<_, error-context>; + run-pass: async func() -> result<_, error-context>; } interface run-stream { @@ -112,7 +112,7 @@ interface run-future { } interface unit-stream { - run: func(count: u32) -> stream; + run: async func(count: u32) -> stream; } interface resource-stream { @@ -131,11 +131,11 @@ interface closed { interface chain-http { use wasi:http/types@0.3.0-draft.{request, response, error-code}; - handle: func(request: request) -> result; + handle: async func(request: request) -> result; } interface sleep { - sleep-millis: func(time-in-millis: u64); + sleep-millis: async func(time-in-millis: u64); } interface sleep-with-options { @@ -145,8 +145,8 @@ interface sleep-with-options { task-return, task-cancel } - - sleep-millis: func(time-in-millis: u64, on-cancel: on-cancel, on-cancel-delay-millis: u64, synchronous-delay: bool, mode: mode); + + sleep-millis: async func(time-in-millis: u64, on-cancel: on-cancel, on-cancel-delay-millis: u64, synchronous-delay: bool, mode: mode); } interface cancel { diff --git a/crates/test-programs/src/bin/async_backpressure_callee.rs b/crates/test-programs/src/bin/async_backpressure_callee.rs index 5da52502df..807b93ee0a 100644 --- a/crates/test-programs/src/bin/async_backpressure_callee.rs +++ b/crates/test-programs/src/bin/async_backpressure_callee.rs @@ -2,11 +2,6 @@ mod bindings { wit_bindgen::generate!({ path: "../misc/component-async-tests/wit", world: "backpressure-callee", - async: { - exports: [ - "local:local/run#run" - ] - } }); use super::Component; diff --git a/crates/test-programs/src/bin/async_backpressure_caller.rs b/crates/test-programs/src/bin/async_backpressure_caller.rs index 7ef6478be2..9beddba0eb 100644 --- a/crates/test-programs/src/bin/async_backpressure_caller.rs +++ b/crates/test-programs/src/bin/async_backpressure_caller.rs @@ -2,14 +2,6 @@ mod bindings { wit_bindgen::generate!({ path: "../misc/component-async-tests/wit", world: "backpressure-caller", - async: { - imports: [ - "local:local/run#run" - ], - exports: [ - "local:local/run#run" - ] - } }); use super::Component; diff --git a/crates/test-programs/src/bin/async_borrowing_callee.rs b/crates/test-programs/src/bin/async_borrowing_callee.rs index 9398ed9820..284727a7d1 100644 --- a/crates/test-programs/src/bin/async_borrowing_callee.rs +++ b/crates/test-programs/src/bin/async_borrowing_callee.rs @@ -2,12 +2,6 @@ mod bindings { wit_bindgen::generate!({ path: "../misc/component-async-tests/wit", world: "borrowing-callee", - async: { - exports: [ - "local:local/borrowing#foo", - "local:local/run-bool#run" - ] - } }); use super::Component; diff --git a/crates/test-programs/src/bin/async_borrowing_caller.rs b/crates/test-programs/src/bin/async_borrowing_caller.rs index a148e4188e..c8f573badc 100644 --- a/crates/test-programs/src/bin/async_borrowing_caller.rs +++ b/crates/test-programs/src/bin/async_borrowing_caller.rs @@ -2,14 +2,6 @@ mod bindings { wit_bindgen::generate!({ path: "../misc/component-async-tests/wit", world: "borrowing-caller", - async: { - imports: [ - "local:local/borrowing#foo" - ], - exports: [ - "local:local/run-bool#run" - ] - } }); use super::Component; diff --git a/crates/test-programs/src/bin/async_cancel_callee.rs b/crates/test-programs/src/bin/async_cancel_callee.rs index 2cbc4b21a0..c69f538230 100644 --- a/crates/test-programs/src/bin/async_cancel_callee.rs +++ b/crates/test-programs/src/bin/async_cancel_callee.rs @@ -19,7 +19,7 @@ use { #[cfg(target_arch = "wasm32")] #[link(wasm_import_module = "[export]local:local/sleep-with-options")] unsafe extern "C" { - #[link_name = "[task-return]sleep-millis"] + #[link_name = "[task-return][async]sleep-millis"] fn task_return_sleep_millis(); } #[cfg(not(target_arch = "wasm32"))] @@ -30,7 +30,7 @@ unsafe extern "C" fn task_return_sleep_millis() { #[cfg(target_arch = "wasm32")] #[link(wasm_import_module = "local:local/sleep")] unsafe extern "C" { - #[link_name = "sleep-millis"] + #[link_name = "[async]sleep-millis"] fn sleep_millis(_: u64); } #[cfg(not(target_arch = "wasm32"))] @@ -41,7 +41,7 @@ unsafe fn sleep_millis(_: u64) { #[cfg(target_arch = "wasm32")] #[link(wasm_import_module = "local:local/sleep")] unsafe extern "C" { - #[link_name = "[async-lower]sleep-millis"] + #[link_name = "[async-lower][async]sleep-millis"] fn sleep_millis_async(_: *mut u8, _: *mut u8) -> u32; } #[cfg(not(target_arch = "wasm32"))] @@ -89,14 +89,14 @@ unsafe extern "C" fn export_set_backpressure(enabled: bool) { async_support::backpressure_set(enabled); } -#[unsafe(export_name = "local:local/sleep#sleep-millis")] +#[unsafe(export_name = "local:local/sleep#[async]sleep-millis")] unsafe extern "C" fn export_sleep_sleep_millis(time_in_millis: u64) { unsafe { sleep_millis(time_in_millis); } } -#[unsafe(export_name = "[async-lift]local:local/sleep-with-options#sleep-millis")] +#[unsafe(export_name = "[async-lift]local:local/sleep-with-options#[async]sleep-millis")] unsafe extern "C" fn export_sleep_with_options_sleep_millis( time_in_millis: u64, on_cancel: u8, @@ -119,7 +119,7 @@ unsafe extern "C" fn export_sleep_with_options_sleep_millis( } } -#[unsafe(export_name = "[callback][async-lift]local:local/sleep-with-options#sleep-millis")] +#[unsafe(export_name = "[callback][async-lift]local:local/sleep-with-options#[async]sleep-millis")] unsafe extern "C" fn callback_sleep_with_options_sleep_millis( event0: u32, event1: u32, diff --git a/crates/test-programs/src/bin/async_cancel_caller.rs b/crates/test-programs/src/bin/async_cancel_caller.rs index 02a7565b08..01c88ee7a1 100644 --- a/crates/test-programs/src/bin/async_cancel_caller.rs +++ b/crates/test-programs/src/bin/async_cancel_caller.rs @@ -41,7 +41,7 @@ mod sleep { #[cfg(target_arch = "wasm32")] #[link(wasm_import_module = "local:local/sleep")] unsafe extern "C" { - #[link_name = "[async-lower]sleep-millis"] + #[link_name = "[async-lower][async]sleep-millis"] pub fn sleep_millis(_: *mut u8, _: *mut u8) -> u32; } #[cfg(not(target_arch = "wasm32"))] @@ -54,7 +54,7 @@ mod sleep_with_options { #[cfg(target_arch = "wasm32")] #[link(wasm_import_module = "local:local/sleep-with-options")] unsafe extern "C" { - #[link_name = "[async-lower]sleep-millis"] + #[link_name = "[async-lower][async]sleep-millis"] pub fn sleep_millis(_: *mut u8, _: *mut u8) -> u32; } #[cfg(not(target_arch = "wasm32"))] diff --git a/crates/test-programs/src/bin/async_error_context.rs b/crates/test-programs/src/bin/async_error_context.rs index f02ab5ece9..bb15f4b3de 100644 --- a/crates/test-programs/src/bin/async_error_context.rs +++ b/crates/test-programs/src/bin/async_error_context.rs @@ -2,11 +2,6 @@ mod bindings { wit_bindgen::generate!({ path: "../misc/component-async-tests/wit", world: "error-context-usage", - async: { - exports: [ - "local:local/run#run", - ], - } }); use super::Component; diff --git a/crates/test-programs/src/bin/async_error_context_callee.rs b/crates/test-programs/src/bin/async_error_context_callee.rs index de66a480a3..642ded28d7 100644 --- a/crates/test-programs/src/bin/async_error_context_callee.rs +++ b/crates/test-programs/src/bin/async_error_context_callee.rs @@ -2,13 +2,6 @@ mod bindings { wit_bindgen::generate!({ path: "../misc/component-async-tests/wit", world: "error-context-callee", - async: { - exports: [ - "local:local/run#run", - "local:local/run-result#run-pass", - "local:local/run-result#run-fail", - ], - } }); use super::Component; diff --git a/crates/test-programs/src/bin/async_error_context_caller.rs b/crates/test-programs/src/bin/async_error_context_caller.rs index 57cf72c2d6..405efc45b8 100644 --- a/crates/test-programs/src/bin/async_error_context_caller.rs +++ b/crates/test-programs/src/bin/async_error_context_caller.rs @@ -2,14 +2,6 @@ mod bindings { wit_bindgen::generate!({ path: "../misc/component-async-tests/wit", world: "error-context-caller", - async: { - imports: [ - "local:local/run-result#run-fail", - ], - exports: [ - "local:local/run#run", - ], - } }); use super::Component; diff --git a/crates/test-programs/src/bin/async_http_echo.rs b/crates/test-programs/src/bin/async_http_echo.rs index 7820609be2..d9f9a28d80 100644 --- a/crates/test-programs/src/bin/async_http_echo.rs +++ b/crates/test-programs/src/bin/async_http_echo.rs @@ -2,14 +2,6 @@ mod bindings { wit_bindgen::generate!({ path: "../misc/component-async-tests/wit", world: "wasi:http/proxy", - async: { - imports: [ - "wasi:http/handler@0.3.0-draft#handle", - ], - exports: [ - "wasi:http/handler@0.3.0-draft#handle", - ] - } }); use super::Component; diff --git a/crates/test-programs/src/bin/async_http_middleware.rs b/crates/test-programs/src/bin/async_http_middleware.rs index a2c0b5f7ff..829ae49af0 100644 --- a/crates/test-programs/src/bin/async_http_middleware.rs +++ b/crates/test-programs/src/bin/async_http_middleware.rs @@ -2,14 +2,6 @@ mod bindings { wit_bindgen::generate!({ path: "../misc/component-async-tests/wit", world: "wasi:http/proxy", - async: { - imports: [ - "wasi:http/handler@0.3.0-draft#handle", - ], - exports: [ - "wasi:http/handler@0.3.0-draft#handle", - ] - } }); use super::Component; diff --git a/crates/test-programs/src/bin/async_http_middleware_with_chain.rs b/crates/test-programs/src/bin/async_http_middleware_with_chain.rs index 7c99cc16fe..b392887071 100644 --- a/crates/test-programs/src/bin/async_http_middleware_with_chain.rs +++ b/crates/test-programs/src/bin/async_http_middleware_with_chain.rs @@ -2,15 +2,6 @@ mod bindings { wit_bindgen::generate!({ path: "../misc/component-async-tests/wit", world: "middleware-with-chain", - async: { - imports: [ - "local:local/chain-http#handle", - "local:local/sleep#sleep-millis" - ], - exports: [ - "wasi:http/handler@0.3.0-draft#handle", - ] - }, generate_all, }); diff --git a/crates/test-programs/src/bin/async_poll_stackless.rs b/crates/test-programs/src/bin/async_poll_stackless.rs index 3e6790ca71..2c6f363066 100644 --- a/crates/test-programs/src/bin/async_poll_stackless.rs +++ b/crates/test-programs/src/bin/async_poll_stackless.rs @@ -18,7 +18,7 @@ use { #[cfg(target_arch = "wasm32")] #[link(wasm_import_module = "[export]local:local/run")] unsafe extern "C" { - #[link_name = "[task-return]run"] + #[link_name = "[task-return][async]run"] fn task_return_run(); } #[cfg(not(target_arch = "wasm32"))] @@ -36,7 +36,7 @@ fn async_when_ready() -> u32 { { #[link(wasm_import_module = "local:local/ready")] unsafe extern "C" { - #[link_name = "[async-lower]when-ready"] + #[link_name = "[async-lower][async]when-ready"] fn call_when_ready(_: *mut u8, _: *mut u8) -> u32; } unsafe { call_when_ready(std::ptr::null_mut(), std::ptr::null_mut()) } @@ -52,13 +52,13 @@ enum State { S5 { set: u32 }, } -#[unsafe(export_name = "[async-lift]local:local/run#run")] +#[unsafe(export_name = "[async-lift]local:local/run#[async]run")] unsafe extern "C" fn export_run() -> u32 { context_set(u32::try_from(Box::into_raw(Box::new(State::S0)) as usize).unwrap()); callback_run(EVENT_NONE, 0, 0) } -#[unsafe(export_name = "[callback][async-lift]local:local/run#run")] +#[unsafe(export_name = "[callback][async-lift]local:local/run#[async]run")] unsafe extern "C" fn callback_run(event0: u32, event1: u32, event2: u32) -> u32 { let state = &mut *(usize::try_from(context_get()).unwrap() as *mut State); match state { diff --git a/crates/test-programs/src/bin/async_poll_synchronous.rs b/crates/test-programs/src/bin/async_poll_synchronous.rs index 148912a065..d5450e932a 100644 --- a/crates/test-programs/src/bin/async_poll_synchronous.rs +++ b/crates/test-programs/src/bin/async_poll_synchronous.rs @@ -2,6 +2,7 @@ mod bindings { wit_bindgen::generate!({ path: "../misc/component-async-tests/wit", world: "poll", + async: false, }); use super::Component; @@ -26,7 +27,7 @@ fn async_when_ready() -> u32 { { #[link(wasm_import_module = "local:local/ready")] unsafe extern "C" { - #[link_name = "[async-lower]when-ready"] + #[link_name = "[async-lower][async]when-ready"] fn call_when_ready(_: *mut u8, _: *mut u8) -> u32; } unsafe { call_when_ready(std::ptr::null_mut(), std::ptr::null_mut()) } diff --git a/crates/test-programs/src/bin/async_post_return_callee.rs b/crates/test-programs/src/bin/async_post_return_callee.rs index 82a6473882..deb803cf24 100644 --- a/crates/test-programs/src/bin/async_post_return_callee.rs +++ b/crates/test-programs/src/bin/async_post_return_callee.rs @@ -1,17 +1,28 @@ #![expect(unsafe_op_in_unsafe_fn, reason = "old code, not worth updating yet")] -// Here we avoid using wit-bindgen so that we can export our own post-return -// function and keep track of whether it was called. - use std::{ alloc::{self, Layout}, - mem::ManuallyDrop, sync::Mutex, }; static POST_RETURN_VALUE: Mutex> = Mutex::new(None); -#[unsafe(export_name = "local:local/post-return#foo")] +mod bindings { + wit_bindgen::generate!({ + path: "../misc/component-async-tests/wit", + world: "post-return-callee", + // Here we avoid using wit-bindgen so that we can export our own + // post-return function and keep track of whether it was called. + skip: ["[async]foo"], + }); + + use super::Component; + export!(Component); +} + +struct Component; + +#[unsafe(export_name = "local:local/post-return#[async]foo")] unsafe extern "C" fn export_foo(ptr: *mut u8, len: usize) -> *mut u8 { let result = alloc::alloc(Layout::from_size_align(8, 4).unwrap()); *result.cast::<*mut u8>() = ptr; @@ -19,7 +30,7 @@ unsafe extern "C" fn export_foo(ptr: *mut u8, len: usize) -> *mut u8 { result } -#[unsafe(export_name = "cabi_post_local:local/post-return#foo")] +#[unsafe(export_name = "cabi_post_local:local/post-return#[async]foo")] unsafe extern "C" fn export_post_return_foo(ptr: *mut u8) { let s_ptr = *ptr.cast::<*mut u8>(); let s_len = *ptr.add(4).cast::(); @@ -29,51 +40,10 @@ unsafe extern "C" fn export_post_return_foo(ptr: *mut u8) { Some(String::from_utf8(Vec::from_raw_parts(s_ptr, s_len, s_len)).unwrap()); } -#[unsafe(export_name = "local:local/post-return#get-post-return-value")] -unsafe extern "C" fn export_get_post_return_value() -> *mut u8 { - let s = ManuallyDrop::new(POST_RETURN_VALUE.lock().unwrap().take().unwrap()); - let result = alloc::alloc(Layout::from_size_align(8, 4).unwrap()); - *result.cast::<*mut u8>() = s.as_ptr().cast_mut(); - *result.add(4).cast::() = s.len(); - result -} - -#[unsafe(export_name = "cabi_post_local:local/post-return#get-post-return-value")] -unsafe extern "C" fn export_post_return_get_post_return_value(ptr: *mut u8) { - let s_ptr = *ptr.cast::<*mut u8>(); - let s_len = *ptr.add(4).cast::(); - alloc::dealloc(ptr, Layout::from_size_align(8, 4).unwrap()); - - drop(String::from_utf8(Vec::from_raw_parts(s_ptr, s_len, s_len)).unwrap()); -} - -#[cfg(target_arch = "wasm32")] -#[unsafe(link_section = "component-type:wit-bindgen:0.37.0:local:local:post-return-callee:encoded world")] -#[doc(hidden)] -#[allow( - clippy::octal_escapes, - reason = "this is a machine-generated binary blob" -)] -pub static __WIT_BINDGEN_COMPONENT_TYPE: [u8; 255] = *b"\ -\0asm\x0d\0\x01\0\0\x19\x16wit-component-encoding\x04\0\x07w\x01A\x02\x01A\x02\x01\ -B\x04\x01@\x01\x01ss\0s\x04\0\x03foo\x01\0\x01@\0\0s\x04\0\x15get-post-return-va\ -lue\x01\x01\x04\0\x17local:local/post-return\x05\0\x04\0\x1elocal:local/post-ret\ -urn-callee\x04\0\x0b\x18\x01\0\x12post-return-callee\x03\0\0\0G\x09producers\x01\ -\x0cprocessed-by\x02\x0dwit-component\x070.223.0\x10wit-bindgen-rust\x060.37.0"; - -/// # Safety -/// TODO -#[unsafe(export_name = "cabi_realloc")] -pub unsafe extern "C" fn cabi_realloc( - old_ptr: *mut u8, - old_len: usize, - align: usize, - new_size: usize, -) -> *mut u8 { - assert!(old_ptr.is_null()); - assert!(old_len == 0); - - alloc::alloc(Layout::from_size_align(new_size, align).unwrap()) +impl bindings::exports::local::local::post_return::Guest for Component { + fn get_post_return_value() -> String { + POST_RETURN_VALUE.lock().unwrap().take().unwrap() + } } // Unused function; required since this file is built as a `bin`: diff --git a/crates/test-programs/src/bin/async_post_return_caller.rs b/crates/test-programs/src/bin/async_post_return_caller.rs index d5419cddce..13e5c7c515 100644 --- a/crates/test-programs/src/bin/async_post_return_caller.rs +++ b/crates/test-programs/src/bin/async_post_return_caller.rs @@ -2,14 +2,6 @@ mod bindings { wit_bindgen::generate!({ path: "../misc/component-async-tests/wit", world: "post-return-caller", - async: { - imports: [ - "local:local/post-return#foo" - ], - exports: [ - "local:local/run#run" - ] - } }); use super::Component; diff --git a/crates/test-programs/src/bin/async_read_resource_stream.rs b/crates/test-programs/src/bin/async_read_resource_stream.rs index 59f2447941..089f634c47 100644 --- a/crates/test-programs/src/bin/async_read_resource_stream.rs +++ b/crates/test-programs/src/bin/async_read_resource_stream.rs @@ -2,11 +2,6 @@ mod bindings { wit_bindgen::generate!({ path: "../misc/component-async-tests/wit", world: "read-resource-stream", - async: { - exports: [ - "local:local/run#run" - ] - } }); use super::Component; diff --git a/crates/test-programs/src/bin/async_round_trip_many_stackful.rs b/crates/test-programs/src/bin/async_round_trip_many_stackful.rs index dd22b88705..c50824a409 100644 --- a/crates/test-programs/src/bin/async_round_trip_many_stackful.rs +++ b/crates/test-programs/src/bin/async_round_trip_many_stackful.rs @@ -31,7 +31,7 @@ use { #[cfg(target_arch = "wasm32")] #[link(wasm_import_module = "[export]local:local/many")] unsafe extern "C" { - #[link_name = "[task-return]foo"] + #[link_name = "[task-return][async]foo"] fn task_return_foo(ptr: *mut u8); } #[cfg(not(target_arch = "wasm32"))] @@ -42,7 +42,7 @@ unsafe extern "C" fn task_return_foo(_ptr: *mut u8) { #[cfg(target_arch = "wasm32")] #[link(wasm_import_module = "local:local/many")] unsafe extern "C" { - #[link_name = "[async-lower]foo"] + #[link_name = "[async-lower][async]foo"] fn import_foo(params: *mut u8, results: *mut u8) -> u32; } #[cfg(not(target_arch = "wasm32"))] @@ -50,7 +50,7 @@ unsafe extern "C" fn import_foo(_params: *mut u8, _results: *mut u8) -> u32 { unreachable!() } -#[unsafe(export_name = "[async-lift-stackful]local:local/many#foo")] +#[unsafe(export_name = "[async-lift-stackful]local:local/many#[async]foo")] unsafe extern "C" fn export_foo(args: *mut u8) { // Note that we're careful not to take the address of any stack-allocated // value here. We need to avoid relying on the LLVM-generated shadow stack diff --git a/crates/test-programs/src/bin/async_round_trip_many_synchronous.rs b/crates/test-programs/src/bin/async_round_trip_many_synchronous.rs index 48318fce44..db06b84e84 100644 --- a/crates/test-programs/src/bin/async_round_trip_many_synchronous.rs +++ b/crates/test-programs/src/bin/async_round_trip_many_synchronous.rs @@ -2,6 +2,7 @@ mod bindings { wit_bindgen::generate!({ path: "../misc/component-async-tests/wit", world: "round-trip-many", + async: false, }); use super::Component; diff --git a/crates/test-programs/src/bin/async_round_trip_many_wait.rs b/crates/test-programs/src/bin/async_round_trip_many_wait.rs index f7e13ebc0f..82bed97d5d 100644 --- a/crates/test-programs/src/bin/async_round_trip_many_wait.rs +++ b/crates/test-programs/src/bin/async_round_trip_many_wait.rs @@ -2,11 +2,7 @@ mod bindings { wit_bindgen::generate!({ path: "../misc/component-async-tests/wit", world: "round-trip-many", - async: { - imports: [ - "local:local/many#foo", - ] - } + async: ["-export:local:local/many#[async]foo"], }); use super::Component; diff --git a/crates/test-programs/src/bin/async_round_trip_stackful.rs b/crates/test-programs/src/bin/async_round_trip_stackful.rs index ea2af222a8..9b0243be4f 100644 --- a/crates/test-programs/src/bin/async_round_trip_stackful.rs +++ b/crates/test-programs/src/bin/async_round_trip_stackful.rs @@ -31,7 +31,7 @@ use { #[cfg(target_arch = "wasm32")] #[link(wasm_import_module = "[export]local:local/baz")] unsafe extern "C" { - #[link_name = "[task-return]foo"] + #[link_name = "[task-return][async]foo"] fn task_return_foo(ptr: *mut u8, len: usize); } #[cfg(not(target_arch = "wasm32"))] @@ -42,7 +42,7 @@ unsafe extern "C" fn task_return_foo(_ptr: *mut u8, _len: usize) { #[cfg(target_arch = "wasm32")] #[link(wasm_import_module = "local:local/baz")] unsafe extern "C" { - #[link_name = "[async-lower]foo"] + #[link_name = "[async-lower][async]foo"] fn import_foo(params: *mut u8, results: *mut u8) -> u32; } #[cfg(not(target_arch = "wasm32"))] @@ -50,7 +50,7 @@ unsafe extern "C" fn import_foo(_params: *mut u8, _results: *mut u8) -> u32 { unreachable!() } -#[unsafe(export_name = "[async-lift-stackful]local:local/baz#foo")] +#[unsafe(export_name = "[async-lift-stackful]local:local/baz#[async]foo")] unsafe extern "C" fn export_foo(ptr: *mut u8, len: usize) { // Note that we're careful not to take the address of any stack-allocated // value here. We need to avoid relying on the LLVM-generated shadow stack diff --git a/crates/test-programs/src/bin/async_round_trip_stackless_sync_import.rs b/crates/test-programs/src/bin/async_round_trip_stackless_sync_import.rs index 79556848fe..b62853406e 100644 --- a/crates/test-programs/src/bin/async_round_trip_stackless_sync_import.rs +++ b/crates/test-programs/src/bin/async_round_trip_stackless_sync_import.rs @@ -2,11 +2,7 @@ mod bindings { wit_bindgen::generate!({ path: "../misc/component-async-tests/wit", world: "round-trip", - async: { - exports: [ - "local:local/baz#foo" - ], - } + async: ["-import:local:local/baz#[async]foo"], }); use super::Component; diff --git a/crates/test-programs/src/bin/async_round_trip_synchronous.rs b/crates/test-programs/src/bin/async_round_trip_synchronous.rs index bcf4ccae21..98fe60a22b 100644 --- a/crates/test-programs/src/bin/async_round_trip_synchronous.rs +++ b/crates/test-programs/src/bin/async_round_trip_synchronous.rs @@ -2,6 +2,7 @@ mod bindings { wit_bindgen::generate!({ path: "../misc/component-async-tests/wit", world: "round-trip", + async: false, }); use super::Component; diff --git a/crates/test-programs/src/bin/async_round_trip_wait.rs b/crates/test-programs/src/bin/async_round_trip_wait.rs index 13e73cde2f..04be105b8b 100644 --- a/crates/test-programs/src/bin/async_round_trip_wait.rs +++ b/crates/test-programs/src/bin/async_round_trip_wait.rs @@ -2,11 +2,7 @@ mod bindings { wit_bindgen::generate!({ path: "../misc/component-async-tests/wit", world: "round-trip", - async: { - imports: [ - "local:local/baz#foo", - ] - } + async: ["-export:local:local/baz#[async]foo"], }); use super::Component; diff --git a/crates/test-programs/src/bin/async_transmit_callee.rs b/crates/test-programs/src/bin/async_transmit_callee.rs index 8e831e0583..9d884583db 100644 --- a/crates/test-programs/src/bin/async_transmit_callee.rs +++ b/crates/test-programs/src/bin/async_transmit_callee.rs @@ -2,11 +2,6 @@ mod bindings { wit_bindgen::generate!({ path: "../misc/component-async-tests/wit", world: "transmit-callee", - async: { - exports: [ - "local:local/transmit#exchange", - ], - } }); use super::Component; diff --git a/crates/test-programs/src/bin/async_transmit_caller.rs b/crates/test-programs/src/bin/async_transmit_caller.rs index 833c57d1de..c617fe1fd5 100644 --- a/crates/test-programs/src/bin/async_transmit_caller.rs +++ b/crates/test-programs/src/bin/async_transmit_caller.rs @@ -2,14 +2,6 @@ mod bindings { wit_bindgen::generate!({ path: "../misc/component-async-tests/wit", world: "transmit-caller", - async: { - imports: [ - "local:local/transmit#exchange", - ], - exports: [ - "local:local/run#run", - ], - } }); use super::Component; diff --git a/crates/test-programs/src/bin/async_unit_stream_callee.rs b/crates/test-programs/src/bin/async_unit_stream_callee.rs index 27e972d6a4..064b4df2fe 100644 --- a/crates/test-programs/src/bin/async_unit_stream_callee.rs +++ b/crates/test-programs/src/bin/async_unit_stream_callee.rs @@ -2,11 +2,6 @@ mod bindings { wit_bindgen::generate!({ path: "../misc/component-async-tests/wit", world: "unit-stream-callee", - async: { - exports: [ - "local:local/unit-stream#run", - ], - } }); use super::Component; diff --git a/crates/test-programs/src/bin/async_unit_stream_caller.rs b/crates/test-programs/src/bin/async_unit_stream_caller.rs index 0ab5d6c3ef..a562cd5007 100644 --- a/crates/test-programs/src/bin/async_unit_stream_caller.rs +++ b/crates/test-programs/src/bin/async_unit_stream_caller.rs @@ -2,14 +2,6 @@ mod bindings { wit_bindgen::generate!({ path: "../misc/component-async-tests/wit", world: "unit-stream-caller", - async: { - imports: [ - "local:local/unit-stream#run", - ], - exports: [ - "local:local/run#run", - ], - } }); use super::Component; diff --git a/crates/test-programs/src/bin/async_yield_callee_stackless.rs b/crates/test-programs/src/bin/async_yield_callee_stackless.rs index ef92be188f..fb8123f484 100644 --- a/crates/test-programs/src/bin/async_yield_callee_stackless.rs +++ b/crates/test-programs/src/bin/async_yield_callee_stackless.rs @@ -15,7 +15,7 @@ use { #[cfg(target_arch = "wasm32")] #[link(wasm_import_module = "[export]local:local/run")] unsafe extern "C" { - #[link_name = "[task-return]run"] + #[link_name = "[task-return][async]run"] fn task_return_run(); } #[cfg(not(target_arch = "wasm32"))] @@ -23,12 +23,12 @@ unsafe extern "C" fn task_return_run() { unreachable!() } -#[unsafe(export_name = "[async-lift]local:local/run#run")] +#[unsafe(export_name = "[async-lift]local:local/run#[async]run")] unsafe extern "C" fn export_run() -> u32 { callback_run(EVENT_NONE, 0, 0) } -#[unsafe(export_name = "[callback][async-lift]local:local/run#run")] +#[unsafe(export_name = "[callback][async-lift]local:local/run#[async]run")] unsafe extern "C" fn callback_run(event0: u32, _event1: u32, _event2: u32) -> u32 { assert_eq!(event0, EVENT_NONE); diff --git a/crates/test-programs/src/bin/async_yield_callee_synchronous.rs b/crates/test-programs/src/bin/async_yield_callee_synchronous.rs index 4274546ce3..236da44c91 100644 --- a/crates/test-programs/src/bin/async_yield_callee_synchronous.rs +++ b/crates/test-programs/src/bin/async_yield_callee_synchronous.rs @@ -2,6 +2,7 @@ mod bindings { wit_bindgen::generate!({ path: "../misc/component-async-tests/wit", world: "yield-callee", + async: ["-local:local/run#[async]run"], }); use super::Component; diff --git a/crates/test-programs/src/bin/async_yield_caller.rs b/crates/test-programs/src/bin/async_yield_caller.rs index 3cdd13ade1..a297250d24 100644 --- a/crates/test-programs/src/bin/async_yield_caller.rs +++ b/crates/test-programs/src/bin/async_yield_caller.rs @@ -2,15 +2,6 @@ mod bindings { wit_bindgen::generate!({ path: "../misc/component-async-tests/wit", world: "yield-caller", - async: { - imports: [ - "local:local/ready#when-ready", - "local:local/run#run", - ], - exports: [ - "local:local/run#run", - ], - } }); use super::Component; diff --git a/crates/test-programs/src/bin/p3_filesystem_file_read_write.rs b/crates/test-programs/src/bin/p3_filesystem_file_read_write.rs index 1d7cfe90b1..9023ec2bfe 100644 --- a/crates/test-programs/src/bin/p3_filesystem_file_read_write.rs +++ b/crates/test-programs/src/bin/p3_filesystem_file_read_write.rs @@ -15,10 +15,11 @@ impl test_programs::p3::exports::wasi::cli::run::Guest for Component { let file = dir .open_at( PathFlags::empty(), - filename, + filename.to_string(), OpenFlags::CREATE, DescriptorFlags::READ | DescriptorFlags::WRITE, ) + .await .unwrap(); let (mut data_tx, data_rx) = wit_stream::new(); join!( @@ -47,7 +48,7 @@ impl test_programs::p3::exports::wasi::cli::run::Guest for Component { data_fut.await.unwrap().unwrap(); assert_eq!(String::from_utf8_lossy(&contents), "Hello, World!"); - dir.unlink_file_at(filename).unwrap(); + dir.unlink_file_at(filename.to_string()).await.unwrap(); Ok(()) } } diff --git a/crates/test-programs/src/p3/mod.rs b/crates/test-programs/src/p3/mod.rs index 1514ac276d..d316259a13 100644 --- a/crates/test-programs/src/p3/mod.rs +++ b/crates/test-programs/src/p3/mod.rs @@ -16,22 +16,9 @@ wit_bindgen::generate!({ world: "wasmtime:test/testp3", default_bindings_module: "test_programs::p3", pub_export_macro: true, - async: { - imports: [ - "wasi:clocks/monotonic-clock@0.3.0#wait-for", - "wasi:clocks/monotonic-clock@0.3.0#wait-until", - "wasi:filesystem/types@0.3.0#[method]descriptor.write-via-stream", - "wasi:http/handler@0.3.0-draft#handle", - "wasi:sockets/ip-name-lookup@0.3.0#resolve-addresses", - "wasi:sockets/types@0.3.0#[method]tcp-socket.connect", - "wasi:sockets/types@0.3.0#[method]tcp-socket.send", - "wasi:sockets/types@0.3.0#[method]udp-socket.receive", - "wasi:sockets/types@0.3.0#[method]udp-socket.send", - ], - exports: [ - "wasi:cli/run@0.3.0#run", - ], - }, + async: [ + "wasi:cli/run@0.3.0#run", + ], generate_all }); @@ -48,14 +35,6 @@ pub mod proxy { world: "wasmtime:test/proxyp3", default_bindings_module: "test_programs::p3::proxy", pub_export_macro: true, - async: { - imports: [ - "wasi:http/handler@0.3.0-draft#handle", - ], - exports: [ - "wasi:http/handler@0.3.0-draft#handle", - ], - }, with: { "wasi:http/handler@0.3.0-draft": generate, "wasi:http/types@0.3.0-draft": crate::p3::wasi::http::types, diff --git a/crates/wasi-http/src/p3/bindings.rs b/crates/wasi-http/src/p3/bindings.rs index 76cae7a519..9afdfe8fe8 100644 --- a/crates/wasi-http/src/p3/bindings.rs +++ b/crates/wasi-http/src/p3/bindings.rs @@ -11,7 +11,7 @@ mod generated { concurrent_imports: true, async: { only_imports: [ - "wasi:http/handler@0.3.0-draft#handle", + "wasi:http/handler@0.3.0-draft#[async]handle", "wasi:http/types@0.3.0-draft#[method]request.body", "wasi:http/types@0.3.0-draft#[method]response.body", "wasi:http/types@0.3.0-draft#[static]request.new", diff --git a/crates/wasi-http/src/p3/wit/deps/clocks/monotonic-clock.wit b/crates/wasi-http/src/p3/wit/deps/clocks/monotonic-clock.wit index 87ebdaac51..809fc446ea 100644 --- a/crates/wasi-http/src/p3/wit/deps/clocks/monotonic-clock.wit +++ b/crates/wasi-http/src/p3/wit/deps/clocks/monotonic-clock.wit @@ -33,13 +33,13 @@ interface monotonic-clock { /// Wait until the specified instant has occurred. @since(version = 0.3.0) - wait-until: func( + wait-until: async func( when: instant, ); /// Wait for the specified duration has elapsed. @since(version = 0.3.0) - wait-for: func( + wait-for: async func( how-long: duration, ); } diff --git a/crates/wasi-http/src/p3/wit/deps/filesystem/types.wit b/crates/wasi-http/src/p3/wit/deps/filesystem/types.wit index af3cb254cc..03958752c6 100644 --- a/crates/wasi-http/src/p3/wit/deps/filesystem/types.wit +++ b/crates/wasi-http/src/p3/wit/deps/filesystem/types.wit @@ -320,7 +320,7 @@ interface types { /// /// Note: This is similar to `pwrite` in POSIX. @since(version = 0.3.0) - write-via-stream: func( + write-via-stream: async func( /// Data to write data: stream, /// The offset within the file at which to start writing. @@ -336,13 +336,13 @@ interface types { /// /// Note: This is similar to `write` with `O_APPEND` in POSIX. @since(version = 0.3.0) - append-via-stream: func(data: stream) -> result<_, error-code>; + append-via-stream: async func(data: stream) -> result<_, error-code>; /// Provide file advisory information on a descriptor. /// /// This is similar to `posix_fadvise` in POSIX. @since(version = 0.3.0) - advise: func( + advise: async func( /// The offset within the file to which the advisory applies. offset: filesize, /// The length of the region to which the advisory applies. @@ -358,7 +358,7 @@ interface types { /// /// Note: This is similar to `fdatasync` in POSIX. @since(version = 0.3.0) - sync-data: func() -> result<_, error-code>; + sync-data: async func() -> result<_, error-code>; /// Get flags associated with a descriptor. /// @@ -367,7 +367,7 @@ interface types { /// Note: This returns the value that was the `fs_flags` value returned /// from `fdstat_get` in earlier versions of WASI. @since(version = 0.3.0) - get-flags: func() -> result; + get-flags: async func() -> result; /// Get the dynamic type of a descriptor. /// @@ -380,14 +380,14 @@ interface types { /// Note: This returns the value that was the `fs_filetype` value returned /// from `fdstat_get` in earlier versions of WASI. @since(version = 0.3.0) - get-type: func() -> result; + get-type: async func() -> result; /// Adjust the size of an open file. If this increases the file's size, the /// extra bytes are filled with zeros. /// /// Note: This was called `fd_filestat_set_size` in earlier versions of WASI. @since(version = 0.3.0) - set-size: func(size: filesize) -> result<_, error-code>; + set-size: async func(size: filesize) -> result<_, error-code>; /// Adjust the timestamps of an open file or directory. /// @@ -395,7 +395,7 @@ interface types { /// /// Note: This was called `fd_filestat_set_times` in earlier versions of WASI. @since(version = 0.3.0) - set-times: func( + set-times: async func( /// The desired values of the data access timestamp. data-access-timestamp: new-timestamp, /// The desired values of the data modification timestamp. @@ -415,7 +415,7 @@ interface types { /// This function returns a future, which will resolve to an error code if /// reading full contents of the directory fails. @since(version = 0.3.0) - read-directory: func() -> tuple, future>>; + read-directory: async func() -> tuple, future>>; /// Synchronize the data and metadata of a file to disk. /// @@ -424,13 +424,13 @@ interface types { /// /// Note: This is similar to `fsync` in POSIX. @since(version = 0.3.0) - sync: func() -> result<_, error-code>; + sync: async func() -> result<_, error-code>; /// Create a directory. /// /// Note: This is similar to `mkdirat` in POSIX. @since(version = 0.3.0) - create-directory-at: func( + create-directory-at: async func( /// The relative path at which to create the directory. path: string, ) -> result<_, error-code>; @@ -445,7 +445,7 @@ interface types { /// /// Note: This was called `fd_filestat_get` in earlier versions of WASI. @since(version = 0.3.0) - stat: func() -> result; + stat: async func() -> result; /// Return the attributes of a file or directory. /// @@ -455,7 +455,7 @@ interface types { /// /// Note: This was called `path_filestat_get` in earlier versions of WASI. @since(version = 0.3.0) - stat-at: func( + stat-at: async func( /// Flags determining the method of how the path is resolved. path-flags: path-flags, /// The relative path of the file or directory to inspect. @@ -469,7 +469,7 @@ interface types { /// Note: This was called `path_filestat_set_times` in earlier versions of /// WASI. @since(version = 0.3.0) - set-times-at: func( + set-times-at: async func( /// Flags determining the method of how the path is resolved. path-flags: path-flags, /// The relative path of the file or directory to operate on. @@ -488,7 +488,7 @@ interface types { /// /// Note: This is similar to `linkat` in POSIX. @since(version = 0.3.0) - link-at: func( + link-at: async func( /// Flags determining the method of how the path is resolved. old-path-flags: path-flags, /// The relative source path from which to link. @@ -512,7 +512,7 @@ interface types { /// /// Note: This is similar to `openat` in POSIX. @since(version = 0.3.0) - open-at: func( + open-at: async func( /// Flags determining the method of how the path is resolved. path-flags: path-flags, /// The relative path of the object to open. @@ -530,7 +530,7 @@ interface types { /// /// Note: This is similar to `readlinkat` in POSIX. @since(version = 0.3.0) - readlink-at: func( + readlink-at: async func( /// The relative path of the symbolic link from which to read. path: string, ) -> result; @@ -541,7 +541,7 @@ interface types { /// /// Note: This is similar to `unlinkat(fd, path, AT_REMOVEDIR)` in POSIX. @since(version = 0.3.0) - remove-directory-at: func( + remove-directory-at: async func( /// The relative path to a directory to remove. path: string, ) -> result<_, error-code>; @@ -550,7 +550,7 @@ interface types { /// /// Note: This is similar to `renameat` in POSIX. @since(version = 0.3.0) - rename-at: func( + rename-at: async func( /// The relative source path of the file or directory to rename. old-path: string, /// The base directory for `new-path`. @@ -566,7 +566,7 @@ interface types { /// /// Note: This is similar to `symlinkat` in POSIX. @since(version = 0.3.0) - symlink-at: func( + symlink-at: async func( /// The contents of the symbolic link. old-path: string, /// The relative destination path at which to create the symbolic link. @@ -578,7 +578,7 @@ interface types { /// Return `error-code::is-directory` if the path refers to a directory. /// Note: This is similar to `unlinkat(fd, path, 0)` in POSIX. @since(version = 0.3.0) - unlink-file-at: func( + unlink-file-at: async func( /// The relative path to a file to unlink. path: string, ) -> result<_, error-code>; @@ -590,7 +590,7 @@ interface types { /// wasi-filesystem does not expose device and inode numbers, so this function /// may be used instead. @since(version = 0.3.0) - is-same-object: func(other: borrow) -> bool; + is-same-object: async func(other: borrow) -> bool; /// Return a hash of the metadata associated with a filesystem object referred /// to by a descriptor. @@ -612,14 +612,14 @@ interface types { /// /// However, none of these is required. @since(version = 0.3.0) - metadata-hash: func() -> result; + metadata-hash: async func() -> result; /// Return a hash of the metadata associated with a filesystem object referred /// to by a directory descriptor and a relative path. /// /// This performs the same hash computation as `metadata-hash`. @since(version = 0.3.0) - metadata-hash-at: func( + metadata-hash-at: async func( /// Flags determining the method of how the path is resolved. path-flags: path-flags, /// The relative path of the file or directory to inspect. diff --git a/crates/wasi-http/src/p3/wit/deps/http/handler.wit b/crates/wasi-http/src/p3/wit/deps/http/handler.wit index 099d094c7f..e4446cbecf 100644 --- a/crates/wasi-http/src/p3/wit/deps/http/handler.wit +++ b/crates/wasi-http/src/p3/wit/deps/http/handler.wit @@ -11,7 +11,7 @@ interface handler { /// /// When imported, this function may be used to either send an outgoing /// request over the network or pass it to another component. - handle: func( + handle: async func( request: request, ) -> result; } diff --git a/crates/wasi-http/src/p3/wit/deps/sockets/ip-name-lookup.wit b/crates/wasi-http/src/p3/wit/deps/sockets/ip-name-lookup.wit index 7cc8b03e35..73b4b201f2 100644 --- a/crates/wasi-http/src/p3/wit/deps/sockets/ip-name-lookup.wit +++ b/crates/wasi-http/src/p3/wit/deps/sockets/ip-name-lookup.wit @@ -58,5 +58,5 @@ interface ip-name-lookup { /// - /// - @since(version = 0.3.0) - resolve-addresses: func(name: string) -> result, error-code>; + resolve-addresses: async func(name: string) -> result, error-code>; } diff --git a/crates/wasi-http/src/p3/wit/deps/sockets/types.wit b/crates/wasi-http/src/p3/wit/deps/sockets/types.wit index 456d4e5ccf..7cfb739596 100644 --- a/crates/wasi-http/src/p3/wit/deps/sockets/types.wit +++ b/crates/wasi-http/src/p3/wit/deps/sockets/types.wit @@ -174,10 +174,10 @@ interface types { /// - `address-in-use`: No ephemeral ports available. (EADDRINUSE, ENOBUFS on Windows) /// - `address-in-use`: Address is already in use. (EADDRINUSE) /// - `address-not-bindable`: `local-address` is not an address that can be bound to. (EADDRNOTAVAIL) - /// + /// /// # Implementors note /// When binding to a non-zero port, this bind operation shouldn't be affected by the TIME_WAIT - /// state of a recently closed socket on the same local address. In practice this means that the SO_REUSEADDR + /// state of a recently closed socket on the same local address. In practice this means that the SO_REUSEADDR /// socket option should be set implicitly on all platforms, except on Windows where this is the default behavior /// and SO_REUSEADDR performs something different entirely. /// @@ -219,7 +219,7 @@ interface types { /// - /// - @since(version = 0.3.0) - connect: func(remote-address: ip-socket-address) -> result<_, error-code>; + connect: async func(remote-address: ip-socket-address) -> result<_, error-code>; /// Start listening return a stream of new inbound connections. /// @@ -309,7 +309,7 @@ interface types { /// - /// - @since(version = 0.3.0) - send: func(data: stream) -> result<_, error-code>; + send: async func(data: stream) -> result<_, error-code>; /// Read data from peer. /// @@ -624,7 +624,7 @@ interface types { /// - /// - @since(version = 0.3.0) - send: func(data: list, remote-address: option) -> result<_, error-code>; + send: async func(data: list, remote-address: option) -> result<_, error-code>; /// Receive a message on the socket. /// @@ -650,7 +650,7 @@ interface types { /// - /// - @since(version = 0.3.0) - receive: func() -> result, ip-socket-address>, error-code>; + receive: async func() -> result, ip-socket-address>, error-code>; /// Get the current bound address. /// diff --git a/crates/wasi/src/p3/bindings.rs b/crates/wasi/src/p3/bindings.rs index b91fc8fc60..b76e315f9d 100644 --- a/crates/wasi/src/p3/bindings.rs +++ b/crates/wasi/src/p3/bindings.rs @@ -7,144 +7,7 @@ //! //! # Examples //! -//! If you have a WIT world which refers to `wasi:cli` interfaces you probably want to -//! use this crate's bindings rather than generate fresh bindings. That can be -//! done using the `with` option to [`bindgen!`]: -//! -//! ```rust -//! use core::future::Future; -//! -//! use wasmtime_wasi::p3::cli::{WasiCliCtx, WasiCliView}; -//! use wasmtime_wasi::p3::clocks::{WasiClocksCtx, WasiClocksView}; -//! use wasmtime_wasi::p3::filesystem::{WasiFilesystemCtx, WasiFilesystemView}; -//! use wasmtime_wasi::p3::random::{WasiRandomCtx, WasiRandomView}; -//! use wasmtime_wasi::p3::sockets::{WasiSocketsCtx, WasiSocketsView}; -//! use wasmtime_wasi::p3::ResourceView; -//! use wasmtime::{Result, StoreContextMut, Engine, Config}; -//! use wasmtime::component::{Accessor, Linker, ResourceTable}; -//! -//! wasmtime::component::bindgen!({ -//! world: "example:wasi/my-world", -//! inline: " -//! package example:wasi; -//! -//! // An example of extending the `wasi:cli/imports` world with a -//! // custom host interface. -//! world my-world { -//! include wasi:cli/imports@0.3.0; -//! -//! import custom-host; -//! } -//! -//! interface custom-host { -//! my-custom-function: func(); -//! } -//! ", -//! path: "src/p3/wit", -//! with: { -//! "wasi": wasmtime_wasi::p3::bindings, -//! }, -//! concurrent_exports: true, -//! concurrent_imports: true, -//! async: { -//! only_imports: [ -//! "example:wasi/custom-host#my-custom-function", -//! "wasi:cli/stdin@0.3.0#get-stdin", -//! "wasi:cli/stdout@0.3.0#set-stdout", -//! "wasi:cli/stderr@0.3.0#set-stderr", -//! "wasi:clocks/monotonic-clock@0.3.0#wait-for", -//! "wasi:clocks/monotonic-clock@0.3.0#wait-until", -//! "wasi:filesystem/types@0.3.0#[method]descriptor.read-via-stream", -//! "wasi:filesystem/types@0.3.0#[method]descriptor.write-via-stream", -//! "wasi:filesystem/types@0.3.0#[method]descriptor.append-via-stream", -//! "wasi:filesystem/types@0.3.0#[method]descriptor.advise", -//! "wasi:filesystem/types@0.3.0#[method]descriptor.sync-data", -//! "wasi:filesystem/types@0.3.0#[method]descriptor.get-flags", -//! "wasi:filesystem/types@0.3.0#[method]descriptor.get-type", -//! "wasi:filesystem/types@0.3.0#[method]descriptor.set-size", -//! "wasi:filesystem/types@0.3.0#[method]descriptor.set-times", -//! "wasi:filesystem/types@0.3.0#[method]descriptor.read-directory", -//! "wasi:filesystem/types@0.3.0#[method]descriptor.sync", -//! "wasi:filesystem/types@0.3.0#[method]descriptor.create-directory-at", -//! "wasi:filesystem/types@0.3.0#[method]descriptor.stat", -//! "wasi:filesystem/types@0.3.0#[method]descriptor.stat-at", -//! "wasi:filesystem/types@0.3.0#[method]descriptor.set-times-at", -//! "wasi:filesystem/types@0.3.0#[method]descriptor.link-at", -//! "wasi:filesystem/types@0.3.0#[method]descriptor.open-at", -//! "wasi:filesystem/types@0.3.0#[method]descriptor.readlink-at", -//! "wasi:filesystem/types@0.3.0#[method]descriptor.remove-directory-at", -//! "wasi:filesystem/types@0.3.0#[method]descriptor.rename-at", -//! "wasi:filesystem/types@0.3.0#[method]descriptor.symlink-at", -//! "wasi:filesystem/types@0.3.0#[method]descriptor.unlink-file-at", -//! "wasi:filesystem/types@0.3.0#[method]descriptor.is-same-object", -//! "wasi:filesystem/types@0.3.0#[method]descriptor.metadata-hash", -//! "wasi:filesystem/types@0.3.0#[method]descriptor.metadata-hash-at", -//! "wasi:sockets/ip-name-lookup@0.3.0#resolve-addresses", -//! "wasi:sockets/types@0.3.0#[method]tcp-socket.bind", -//! "wasi:sockets/types@0.3.0#[method]tcp-socket.connect", -//! "wasi:sockets/types@0.3.0#[method]tcp-socket.listen", -//! "wasi:sockets/types@0.3.0#[method]tcp-socket.receive", -//! "wasi:sockets/types@0.3.0#[method]tcp-socket.send", -//! "wasi:sockets/types@0.3.0#[method]udp-socket.bind", -//! "wasi:sockets/types@0.3.0#[method]udp-socket.connect", -//! "wasi:sockets/types@0.3.0#[method]udp-socket.receive", -//! "wasi:sockets/types@0.3.0#[method]udp-socket.send", -//! ], -//! }, -//! }); -//! -//! struct MyState { -//! cli: WasiCliCtx, -//! clocks: WasiClocksCtx, -//! filesystem: WasiFilesystemCtx, -//! random: WasiRandomCtx, -//! sockets: WasiSocketsCtx, -//! table: ResourceTable, -//! } -//! -//! impl example::wasi::custom_host::Host for MyState { -//! async fn my_custom_function(_store: &mut Accessor) { -//! // .. -//! } -//! } -//! -//! impl ResourceView for MyState { -//! fn table(&mut self) -> &mut ResourceTable { &mut self.table } -//! } -//! -//! impl WasiCliView for MyState { -//! fn cli(&mut self) -> &WasiCliCtx { &self.cli } -//! } -//! -//! impl WasiClocksView for MyState { -//! fn clocks(&mut self) -> &WasiClocksCtx { &self.clocks } -//! } -//! -//! impl WasiFilesystemView for MyState { -//! fn filesystem(&self) -> &WasiFilesystemCtx { &self.filesystem } -//! } -//! -//! impl WasiRandomView for MyState { -//! fn random(&mut self) -> &mut WasiRandomCtx { &mut self.random } -//! } -//! -//! impl WasiSocketsView for MyState { -//! fn sockets(&self) -> &WasiSocketsCtx { &self.sockets } -//! } -//! -//! fn main() -> Result<()> { -//! let mut config = Config::default(); -//! config.async_support(true); -//! let engine = Engine::new(&config)?; -//! let mut linker: Linker = Linker::new(&engine); -//! wasmtime_wasi::p3::add_to_linker(&mut linker)?; -//! //example::wasi::custom_host::add_to_linker(&mut linker, |state| state)?; -//! -//! // .. use `Linker` to instantiate component ... -//! -//! Ok(()) -//! } -//! ``` +//! TODO: fill this back in mod generated { wasmtime::component::bindgen!({ @@ -159,43 +22,43 @@ mod generated { "wasi:cli/stdin@0.3.0#get-stdin", "wasi:cli/stdout@0.3.0#set-stdout", "wasi:cli/stderr@0.3.0#set-stderr", - "wasi:clocks/monotonic-clock@0.3.0#wait-for", - "wasi:clocks/monotonic-clock@0.3.0#wait-until", + "wasi:clocks/monotonic-clock@0.3.0#[async]wait-for", + "wasi:clocks/monotonic-clock@0.3.0#[async]wait-until", "wasi:filesystem/types@0.3.0#[method]descriptor.read-via-stream", - "wasi:filesystem/types@0.3.0#[method]descriptor.write-via-stream", - "wasi:filesystem/types@0.3.0#[method]descriptor.append-via-stream", - "wasi:filesystem/types@0.3.0#[method]descriptor.advise", - "wasi:filesystem/types@0.3.0#[method]descriptor.sync-data", - "wasi:filesystem/types@0.3.0#[method]descriptor.get-flags", - "wasi:filesystem/types@0.3.0#[method]descriptor.get-type", - "wasi:filesystem/types@0.3.0#[method]descriptor.set-size", - "wasi:filesystem/types@0.3.0#[method]descriptor.set-times", - "wasi:filesystem/types@0.3.0#[method]descriptor.read-directory", - "wasi:filesystem/types@0.3.0#[method]descriptor.sync", - "wasi:filesystem/types@0.3.0#[method]descriptor.create-directory-at", - "wasi:filesystem/types@0.3.0#[method]descriptor.stat", - "wasi:filesystem/types@0.3.0#[method]descriptor.stat-at", - "wasi:filesystem/types@0.3.0#[method]descriptor.set-times-at", - "wasi:filesystem/types@0.3.0#[method]descriptor.link-at", - "wasi:filesystem/types@0.3.0#[method]descriptor.open-at", - "wasi:filesystem/types@0.3.0#[method]descriptor.readlink-at", - "wasi:filesystem/types@0.3.0#[method]descriptor.remove-directory-at", - "wasi:filesystem/types@0.3.0#[method]descriptor.rename-at", - "wasi:filesystem/types@0.3.0#[method]descriptor.symlink-at", - "wasi:filesystem/types@0.3.0#[method]descriptor.unlink-file-at", - "wasi:filesystem/types@0.3.0#[method]descriptor.is-same-object", - "wasi:filesystem/types@0.3.0#[method]descriptor.metadata-hash", - "wasi:filesystem/types@0.3.0#[method]descriptor.metadata-hash-at", - "wasi:sockets/ip-name-lookup@0.3.0#resolve-addresses", - "wasi:sockets/types@0.3.0#[method]tcp-socket.bind", - "wasi:sockets/types@0.3.0#[method]tcp-socket.connect", - "wasi:sockets/types@0.3.0#[method]tcp-socket.listen", - "wasi:sockets/types@0.3.0#[method]tcp-socket.receive", - "wasi:sockets/types@0.3.0#[method]tcp-socket.send", - "wasi:sockets/types@0.3.0#[method]udp-socket.bind", - "wasi:sockets/types@0.3.0#[method]udp-socket.connect", - "wasi:sockets/types@0.3.0#[method]udp-socket.receive", - "wasi:sockets/types@0.3.0#[method]udp-socket.send", + "wasi:filesystem/types@0.3.0#[async method]descriptor.write-via-stream", + "wasi:filesystem/types@0.3.0#[async method]descriptor.append-via-stream", + "wasi:filesystem/types@0.3.0#[async method]descriptor.advise", + "wasi:filesystem/types@0.3.0#[async method]descriptor.sync-data", + "wasi:filesystem/types@0.3.0#[async method]descriptor.get-flags", + "wasi:filesystem/types@0.3.0#[async method]descriptor.get-type", + "wasi:filesystem/types@0.3.0#[async method]descriptor.set-size", + "wasi:filesystem/types@0.3.0#[async method]descriptor.set-times", + "wasi:filesystem/types@0.3.0#[async method]descriptor.read-directory", + "wasi:filesystem/types@0.3.0#[async method]descriptor.sync", + "wasi:filesystem/types@0.3.0#[async method]descriptor.create-directory-at", + "wasi:filesystem/types@0.3.0#[async method]descriptor.stat", + "wasi:filesystem/types@0.3.0#[async method]descriptor.stat-at", + "wasi:filesystem/types@0.3.0#[async method]descriptor.set-times-at", + "wasi:filesystem/types@0.3.0#[async method]descriptor.link-at", + "wasi:filesystem/types@0.3.0#[async method]descriptor.open-at", + "wasi:filesystem/types@0.3.0#[async method]descriptor.readlink-at", + "wasi:filesystem/types@0.3.0#[async method]descriptor.remove-directory-at", + "wasi:filesystem/types@0.3.0#[async method]descriptor.rename-at", + "wasi:filesystem/types@0.3.0#[async method]descriptor.symlink-at", + "wasi:filesystem/types@0.3.0#[async method]descriptor.unlink-file-at", + "wasi:filesystem/types@0.3.0#[async method]descriptor.is-same-object", + "wasi:filesystem/types@0.3.0#[async method]descriptor.metadata-hash", + "wasi:filesystem/types@0.3.0#[async method]descriptor.metadata-hash-at", + "wasi:sockets/ip-name-lookup@0.3.0#[async]resolve-addresses", + "[method]tcp-socket.bind", + "[async method]tcp-socket.connect", + "[method]tcp-socket.listen", + "[method]tcp-socket.receive", + "[async method]tcp-socket.send", + "[method]udp-socket.bind", + "[method]udp-socket.connect", + "[async method]udp-socket.receive", + "[async method]udp-socket.send", ], }, with: { diff --git a/crates/wasi/src/p3/wit/deps/clocks/monotonic-clock.wit b/crates/wasi/src/p3/wit/deps/clocks/monotonic-clock.wit index 87ebdaac51..809fc446ea 100644 --- a/crates/wasi/src/p3/wit/deps/clocks/monotonic-clock.wit +++ b/crates/wasi/src/p3/wit/deps/clocks/monotonic-clock.wit @@ -33,13 +33,13 @@ interface monotonic-clock { /// Wait until the specified instant has occurred. @since(version = 0.3.0) - wait-until: func( + wait-until: async func( when: instant, ); /// Wait for the specified duration has elapsed. @since(version = 0.3.0) - wait-for: func( + wait-for: async func( how-long: duration, ); } diff --git a/crates/wasi/src/p3/wit/deps/filesystem/types.wit b/crates/wasi/src/p3/wit/deps/filesystem/types.wit index af3cb254cc..03958752c6 100644 --- a/crates/wasi/src/p3/wit/deps/filesystem/types.wit +++ b/crates/wasi/src/p3/wit/deps/filesystem/types.wit @@ -320,7 +320,7 @@ interface types { /// /// Note: This is similar to `pwrite` in POSIX. @since(version = 0.3.0) - write-via-stream: func( + write-via-stream: async func( /// Data to write data: stream, /// The offset within the file at which to start writing. @@ -336,13 +336,13 @@ interface types { /// /// Note: This is similar to `write` with `O_APPEND` in POSIX. @since(version = 0.3.0) - append-via-stream: func(data: stream) -> result<_, error-code>; + append-via-stream: async func(data: stream) -> result<_, error-code>; /// Provide file advisory information on a descriptor. /// /// This is similar to `posix_fadvise` in POSIX. @since(version = 0.3.0) - advise: func( + advise: async func( /// The offset within the file to which the advisory applies. offset: filesize, /// The length of the region to which the advisory applies. @@ -358,7 +358,7 @@ interface types { /// /// Note: This is similar to `fdatasync` in POSIX. @since(version = 0.3.0) - sync-data: func() -> result<_, error-code>; + sync-data: async func() -> result<_, error-code>; /// Get flags associated with a descriptor. /// @@ -367,7 +367,7 @@ interface types { /// Note: This returns the value that was the `fs_flags` value returned /// from `fdstat_get` in earlier versions of WASI. @since(version = 0.3.0) - get-flags: func() -> result; + get-flags: async func() -> result; /// Get the dynamic type of a descriptor. /// @@ -380,14 +380,14 @@ interface types { /// Note: This returns the value that was the `fs_filetype` value returned /// from `fdstat_get` in earlier versions of WASI. @since(version = 0.3.0) - get-type: func() -> result; + get-type: async func() -> result; /// Adjust the size of an open file. If this increases the file's size, the /// extra bytes are filled with zeros. /// /// Note: This was called `fd_filestat_set_size` in earlier versions of WASI. @since(version = 0.3.0) - set-size: func(size: filesize) -> result<_, error-code>; + set-size: async func(size: filesize) -> result<_, error-code>; /// Adjust the timestamps of an open file or directory. /// @@ -395,7 +395,7 @@ interface types { /// /// Note: This was called `fd_filestat_set_times` in earlier versions of WASI. @since(version = 0.3.0) - set-times: func( + set-times: async func( /// The desired values of the data access timestamp. data-access-timestamp: new-timestamp, /// The desired values of the data modification timestamp. @@ -415,7 +415,7 @@ interface types { /// This function returns a future, which will resolve to an error code if /// reading full contents of the directory fails. @since(version = 0.3.0) - read-directory: func() -> tuple, future>>; + read-directory: async func() -> tuple, future>>; /// Synchronize the data and metadata of a file to disk. /// @@ -424,13 +424,13 @@ interface types { /// /// Note: This is similar to `fsync` in POSIX. @since(version = 0.3.0) - sync: func() -> result<_, error-code>; + sync: async func() -> result<_, error-code>; /// Create a directory. /// /// Note: This is similar to `mkdirat` in POSIX. @since(version = 0.3.0) - create-directory-at: func( + create-directory-at: async func( /// The relative path at which to create the directory. path: string, ) -> result<_, error-code>; @@ -445,7 +445,7 @@ interface types { /// /// Note: This was called `fd_filestat_get` in earlier versions of WASI. @since(version = 0.3.0) - stat: func() -> result; + stat: async func() -> result; /// Return the attributes of a file or directory. /// @@ -455,7 +455,7 @@ interface types { /// /// Note: This was called `path_filestat_get` in earlier versions of WASI. @since(version = 0.3.0) - stat-at: func( + stat-at: async func( /// Flags determining the method of how the path is resolved. path-flags: path-flags, /// The relative path of the file or directory to inspect. @@ -469,7 +469,7 @@ interface types { /// Note: This was called `path_filestat_set_times` in earlier versions of /// WASI. @since(version = 0.3.0) - set-times-at: func( + set-times-at: async func( /// Flags determining the method of how the path is resolved. path-flags: path-flags, /// The relative path of the file or directory to operate on. @@ -488,7 +488,7 @@ interface types { /// /// Note: This is similar to `linkat` in POSIX. @since(version = 0.3.0) - link-at: func( + link-at: async func( /// Flags determining the method of how the path is resolved. old-path-flags: path-flags, /// The relative source path from which to link. @@ -512,7 +512,7 @@ interface types { /// /// Note: This is similar to `openat` in POSIX. @since(version = 0.3.0) - open-at: func( + open-at: async func( /// Flags determining the method of how the path is resolved. path-flags: path-flags, /// The relative path of the object to open. @@ -530,7 +530,7 @@ interface types { /// /// Note: This is similar to `readlinkat` in POSIX. @since(version = 0.3.0) - readlink-at: func( + readlink-at: async func( /// The relative path of the symbolic link from which to read. path: string, ) -> result; @@ -541,7 +541,7 @@ interface types { /// /// Note: This is similar to `unlinkat(fd, path, AT_REMOVEDIR)` in POSIX. @since(version = 0.3.0) - remove-directory-at: func( + remove-directory-at: async func( /// The relative path to a directory to remove. path: string, ) -> result<_, error-code>; @@ -550,7 +550,7 @@ interface types { /// /// Note: This is similar to `renameat` in POSIX. @since(version = 0.3.0) - rename-at: func( + rename-at: async func( /// The relative source path of the file or directory to rename. old-path: string, /// The base directory for `new-path`. @@ -566,7 +566,7 @@ interface types { /// /// Note: This is similar to `symlinkat` in POSIX. @since(version = 0.3.0) - symlink-at: func( + symlink-at: async func( /// The contents of the symbolic link. old-path: string, /// The relative destination path at which to create the symbolic link. @@ -578,7 +578,7 @@ interface types { /// Return `error-code::is-directory` if the path refers to a directory. /// Note: This is similar to `unlinkat(fd, path, 0)` in POSIX. @since(version = 0.3.0) - unlink-file-at: func( + unlink-file-at: async func( /// The relative path to a file to unlink. path: string, ) -> result<_, error-code>; @@ -590,7 +590,7 @@ interface types { /// wasi-filesystem does not expose device and inode numbers, so this function /// may be used instead. @since(version = 0.3.0) - is-same-object: func(other: borrow) -> bool; + is-same-object: async func(other: borrow) -> bool; /// Return a hash of the metadata associated with a filesystem object referred /// to by a descriptor. @@ -612,14 +612,14 @@ interface types { /// /// However, none of these is required. @since(version = 0.3.0) - metadata-hash: func() -> result; + metadata-hash: async func() -> result; /// Return a hash of the metadata associated with a filesystem object referred /// to by a directory descriptor and a relative path. /// /// This performs the same hash computation as `metadata-hash`. @since(version = 0.3.0) - metadata-hash-at: func( + metadata-hash-at: async func( /// Flags determining the method of how the path is resolved. path-flags: path-flags, /// The relative path of the file or directory to inspect. diff --git a/crates/wasi/src/p3/wit/deps/sockets/ip-name-lookup.wit b/crates/wasi/src/p3/wit/deps/sockets/ip-name-lookup.wit index 7cc8b03e35..73b4b201f2 100644 --- a/crates/wasi/src/p3/wit/deps/sockets/ip-name-lookup.wit +++ b/crates/wasi/src/p3/wit/deps/sockets/ip-name-lookup.wit @@ -58,5 +58,5 @@ interface ip-name-lookup { /// - /// - @since(version = 0.3.0) - resolve-addresses: func(name: string) -> result, error-code>; + resolve-addresses: async func(name: string) -> result, error-code>; } diff --git a/crates/wasi/src/p3/wit/deps/sockets/types.wit b/crates/wasi/src/p3/wit/deps/sockets/types.wit index 456d4e5ccf..7cfb739596 100644 --- a/crates/wasi/src/p3/wit/deps/sockets/types.wit +++ b/crates/wasi/src/p3/wit/deps/sockets/types.wit @@ -174,10 +174,10 @@ interface types { /// - `address-in-use`: No ephemeral ports available. (EADDRINUSE, ENOBUFS on Windows) /// - `address-in-use`: Address is already in use. (EADDRINUSE) /// - `address-not-bindable`: `local-address` is not an address that can be bound to. (EADDRNOTAVAIL) - /// + /// /// # Implementors note /// When binding to a non-zero port, this bind operation shouldn't be affected by the TIME_WAIT - /// state of a recently closed socket on the same local address. In practice this means that the SO_REUSEADDR + /// state of a recently closed socket on the same local address. In practice this means that the SO_REUSEADDR /// socket option should be set implicitly on all platforms, except on Windows where this is the default behavior /// and SO_REUSEADDR performs something different entirely. /// @@ -219,7 +219,7 @@ interface types { /// - /// - @since(version = 0.3.0) - connect: func(remote-address: ip-socket-address) -> result<_, error-code>; + connect: async func(remote-address: ip-socket-address) -> result<_, error-code>; /// Start listening return a stream of new inbound connections. /// @@ -309,7 +309,7 @@ interface types { /// - /// - @since(version = 0.3.0) - send: func(data: stream) -> result<_, error-code>; + send: async func(data: stream) -> result<_, error-code>; /// Read data from peer. /// @@ -624,7 +624,7 @@ interface types { /// - /// - @since(version = 0.3.0) - send: func(data: list, remote-address: option) -> result<_, error-code>; + send: async func(data: list, remote-address: option) -> result<_, error-code>; /// Receive a message on the socket. /// @@ -650,7 +650,7 @@ interface types { /// - /// - @since(version = 0.3.0) - receive: func() -> result, ip-socket-address>, error-code>; + receive: async func() -> result, ip-socket-address>, error-code>; /// Get the current bound address. /// diff --git a/crates/wit-bindgen/src/lib.rs b/crates/wit-bindgen/src/lib.rs index 70b43f4f11..0d72168fa3 100644 --- a/crates/wit-bindgen/src/lib.rs +++ b/crates/wit-bindgen/src/lib.rs @@ -237,6 +237,7 @@ pub enum AsyncConfig { OnlyImports(HashSet), } +#[derive(Debug, Copy, Clone)] pub enum CallStyle { Sync, Async, @@ -508,7 +509,7 @@ impl Wasmtime { // Only generate a trait signature for free functions since // resource-related functions get their trait signatures // during `type_resource`. - let sig = if let FunctionKind::Freestanding = func.kind { + let sig = if func.kind.resource().is_none() { generator.generate_function_trait_sig(func, false); let without_sugar = mem::take(&mut generator.src).into(); generator.generate_function_trait_sig(func, true); @@ -1144,7 +1145,6 @@ impl<_T> {camel}Pre<_T> {{ ); if !unused_imports.is_empty() { - dbg!(&self.used_trappable_imports_opts); unused_imports.sort(); anyhow::bail!("names specified in the `trappable_imports` config option but are not referenced in the target world: {unused_imports:?}"); } @@ -2552,9 +2552,8 @@ impl<'a> InterfaceGenerator<'a> { uwriteln!(self.src, " {{"); for (_, func) in iface.functions.iter() { - match func.kind { - FunctionKind::Freestanding => {} - _ => continue, + if func.kind.resource().is_some() { + continue; } self.generate_function_trait_sig(func, false); self.push_str(";\n"); @@ -2730,9 +2729,8 @@ impl<'a> InterfaceGenerator<'a> { // Forward each method call to &mut T for (_, func) in iface.functions.iter() { - match func.kind { - FunctionKind::Freestanding => {} - _ => continue, + if func.kind.resource().is_some() { + continue; } let call_style = self .generator @@ -3223,9 +3221,10 @@ impl<'a> InterfaceGenerator<'a> { "{wt}::component::TypedFunc::<{}>", self.typedfunc_sig(func, param_mode) ); - let projection_to_func = match &func.kind { - FunctionKind::Freestanding => "", - _ => ".funcs", + let projection_to_func = if func.kind.resource().is_some() { + ".funcs" + } else { + "" }; uwriteln!( self.src, From bfa956b93905ec3bf1cb4e865967970066a8e88f Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Wed, 23 Apr 2025 11:10:01 -0700 Subject: [PATCH 2/3] Disable WIT vendoring --- ci/vendor-wit.sh | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/ci/vendor-wit.sh b/ci/vendor-wit.sh index 36467b0b2b..fdaada09f1 100755 --- a/ci/vendor-wit.sh +++ b/ci/vendor-wit.sh @@ -68,22 +68,23 @@ make_vendor "wasi-config" "config@f4d699b" make_vendor "wasi-keyvalue" "keyvalue@219ea36" -make_vendor "wasi/src/p3" " - cli@82b86d9@wit-0.3.0-draft - clocks@646092f@wit-0.3.0-draft - filesystem@740cd76@wit-0.3.0-draft - random@9499404@wit-0.3.0-draft - sockets@41d7079@wit-0.3.0-draft -" +# TODO: upstream `async` changes and eventually re-enable this +# make_vendor "wasi/src/p3" " +# cli@82b86d9@wit-0.3.0-draft +# clocks@646092f@wit-0.3.0-draft +# filesystem@740cd76@wit-0.3.0-draft +# random@9499404@wit-0.3.0-draft +# sockets@41d7079@wit-0.3.0-draft +# " # `wasi:http` from https://github.com/WebAssembly/wasi-http/pull/158 -make_vendor "wasi-http/src/p3" " - cli@82b86d9@wit-0.3.0-draft - clocks@646092f@wit-0.3.0-draft - filesystem@740cd76@wit-0.3.0-draft - random@9499404@wit-0.3.0-draft - sockets@41d7079@wit-0.3.0-draft - http@ae89575@wit-0.3.0-draft -" +# make_vendor "wasi-http/src/p3" " +# cli@82b86d9@wit-0.3.0-draft +# clocks@646092f@wit-0.3.0-draft +# filesystem@740cd76@wit-0.3.0-draft +# random@9499404@wit-0.3.0-draft +# sockets@41d7079@wit-0.3.0-draft +# http@ae89575@wit-0.3.0-draft +# " rm -rf $cache_dir From d98654e06961bbdc238dbfb600e4b23e91dcc8b8 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Wed, 23 Apr 2025 13:40:52 -0500 Subject: [PATCH 3/3] Update cargo-deny used in CI (#10655) Our pinned version is pretty out-of-date and seems like it's having difficulty parsing more recent Cargo syntax in the wasip3-prototyping fork. --- .github/workflows/main.yml | 2 +- deny.toml | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index b59832c60c..4cada4946c 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -103,7 +103,7 @@ jobs: - uses: ./.github/actions/install-rust - run: | set -e - curl -L https://github.com/EmbarkStudios/cargo-deny/releases/download/0.14.5/cargo-deny-0.14.5-x86_64-unknown-linux-musl.tar.gz | tar xzf - + curl -L https://github.com/EmbarkStudios/cargo-deny/releases/download/0.18.2/cargo-deny-0.18.2-x86_64-unknown-linux-musl.tar.gz | tar xzf - mv cargo-deny-*-x86_64-unknown-linux-musl/cargo-deny cargo-deny echo `pwd` >> $GITHUB_PATH - run: cargo deny check bans licenses diff --git a/deny.toml b/deny.toml index 1ecdf0cbea..78ce843135 100644 --- a/deny.toml +++ b/deny.toml @@ -1,6 +1,7 @@ # Documentation for this configuration file can be found here # https://embarkstudios.github.io/cargo-deny/checks/cfg.html +[graph] targets = [ { triple = "x86_64-unknown-linux-gnu" }, { triple = "x86_64-apple-darwin" }, @@ -13,14 +14,13 @@ targets = [ allow = [ "Apache-2.0 WITH LLVM-exception", "Apache-2.0", - "BSD-2-Clause", "BSD-3-Clause", "ISC", "MIT", "MPL-2.0", - "OpenSSL", "Unicode-DFS-2016", "Zlib", + "Unicode-3.0", ] [[licenses.clarify]]