From cec8cbbfbb690267d93a3b79d0714d507ec1a922 Mon Sep 17 00:00:00 2001 From: Roman Volosatovs Date: Tue, 17 Sep 2024 17:22:13 +0200 Subject: [PATCH] feat: integrate `wasi-passthrough` Signed-off-by: Roman Volosatovs --- Cargo.lock | 14 +- Cargo.toml | 25 +- bindings/bindings.go | 268 +- .../wasi/cli/environment/environment.wit.go | 10 +- bindings/wasi/cli/exit/exit.wit.go | 30 +- bindings/wasi/cli/imports/imports.wit.go | 2 +- bindings/wasi/cli/stderr/stderr.wit.go | 6 +- bindings/wasi/cli/stdin/stdin.wit.go | 6 +- bindings/wasi/cli/stdout/stdout.wit.go | 6 +- .../cli/terminal-input/terminal-input.wit.go | 8 +- .../terminal-output/terminal-output.wit.go | 8 +- .../terminal-stderr/terminal-stderr.wit.go | 6 +- .../cli/terminal-stdin/terminal-stdin.wit.go | 6 +- .../terminal-stdout/terminal-stdout.wit.go | 6 +- bindings/wasi/clocks/imports/imports.wit.go | 2 +- .../monotonic-clock/monotonic-clock.wit.go | 25 +- bindings/wasi/clocks/timezone/abi.go | 13 + .../clocks/timezone}/empty.s | 0 bindings/wasi/clocks/timezone/timezone.wit.go | 90 + .../wasi/clocks/wall-clock/wall-clock.wit.go | 8 +- .../wasi/filesystem/imports/imports.wit.go | 2 +- .../wasi/filesystem/preopens/preopens.wit.go | 6 +- bindings/wasi/filesystem/types/abi.go | 2 +- bindings/wasi/filesystem/types/types.wit.go | 96 +- bindings/wasi/http/imports/imports.wit.go | 7 + bindings/wasi/http/outgoing-handler/abi.go | 24 + bindings/wasi/http/outgoing-handler/empty.s | 3 + .../outgoing-handler/outgoing-handler.wit.go | 40 + bindings/wasi/http/types/abi.go | 2 +- bindings/wasi/http/types/types.wit.go | 229 +- bindings/wasi/io/error/error.wit.go | 22 +- bindings/wasi/io/imports/imports.wit.go | 2 +- bindings/wasi/io/poll/poll.wit.go | 21 +- bindings/wasi/io/streams/streams.wit.go | 52 +- bindings/wasi/random/imports/imports.wit.go | 2 +- .../random/insecure-seed/insecure-seed.wit.go | 4 +- bindings/wasi/random/insecure/insecure.wit.go | 8 +- bindings/wasi/random/random/random.wit.go | 8 +- bindings/wasi/sockets/imports/imports.wit.go | 2 +- .../instance-network/instance-network.wit.go | 6 +- bindings/wasi/sockets/ip-name-lookup/abi.go | 2 +- .../ip-name-lookup/ip-name-lookup.wit.go | 14 +- bindings/wasi/sockets/network/network.wit.go | 24 +- .../tcp-create-socket.wit.go | 6 +- bindings/wasi/sockets/tcp/abi.go | 2 +- bindings/wasi/sockets/tcp/tcp.wit.go | 78 +- .../udp-create-socket.wit.go | 6 +- bindings/wasi/sockets/udp/abi.go | 2 +- bindings/wasi/sockets/udp/udp.wit.go | 56 +- bindings/wasiext/http/ext/empty.s | 3 + .../http/ext/ext.wit.go} | 10 +- bindings/wasiext/http/imports/imports.wit.go | 4 + bindings/west.go | 4 +- .../{test => west}/imports/imports.wit.go | 2 +- build.go | 15 + build_dev.go | 10 + crates/passthrough/Cargo.toml | 4 +- crates/passthrough/src/bindings.rs | 94 - crates/passthrough/src/cli.rs | 74 - crates/passthrough/src/clocks.rs | 24 - crates/passthrough/src/filesystem.rs | 253 -- crates/passthrough/src/http.rs | 611 ----- crates/passthrough/src/io.rs | 148 -- crates/passthrough/src/lib.rs | 11 +- crates/passthrough/src/sockets.rs | 284 --- crates/passthrough/src/west.rs | 25 - crates/passthrough/wit | 1 - crates/sys/Cargo.toml | 2 +- .../go/http}/bindings/.gitkeep | 0 .../bindings/wasi/cli/environment/empty.s | 3 + .../wasi/cli/environment/environment.wit.go | 64 + .../go/http/bindings/wasi/cli/exit/empty.s | 3 + .../http/bindings/wasi/cli/exit/exit.wit.go | 49 + .../go/http/bindings/wasi/cli/stderr/empty.s | 3 + .../bindings/wasi/cli/stderr/stderr.wit.go | 24 + .../go/http/bindings/wasi/cli/stdin/empty.s | 3 + .../http/bindings/wasi/cli/stdin/stdin.wit.go | 24 + .../go/http/bindings/wasi/cli/stdout/empty.s | 3 + .../bindings/wasi/cli/stdout/stdout.wit.go | 24 + .../bindings/wasi/cli/terminal-input/empty.s | 3 + .../cli/terminal-input/terminal-input.wit.go | 36 + .../bindings/wasi/cli/terminal-output/empty.s | 3 + .../terminal-output/terminal-output.wit.go | 36 + .../bindings/wasi/cli/terminal-stderr/empty.s | 3 + .../terminal-stderr/terminal-stderr.wit.go | 29 + .../bindings/wasi/cli/terminal-stdin/empty.s | 3 + .../cli/terminal-stdin/terminal-stdin.wit.go | 29 + .../bindings/wasi/cli/terminal-stdout/empty.s | 3 + .../terminal-stdout/terminal-stdout.wit.go | 29 + .../wasi/clocks/monotonic-clock/empty.s | 3 + .../monotonic-clock/monotonic-clock.wit.go | 110 + .../http/bindings/wasi/clocks/timezone/abi.go | 13 + .../bindings/wasi/clocks/timezone/empty.s | 3 + .../wasi/clocks/timezone/timezone.wit.go | 90 + .../bindings/wasi/clocks/wall-clock/empty.s | 3 + .../wasi/clocks/wall-clock/wall-clock.wit.go | 78 + .../bindings/wasi/filesystem/preopens/empty.s | 3 + .../wasi/filesystem/preopens/preopens.wit.go | 25 + .../bindings/wasi/filesystem/types/abi.go | 51 + .../bindings/wasi/filesystem/types/empty.s | 3 + .../wasi/filesystem/types/types.wit.go | 1357 +++++++++++ .../wasi/http/incoming-handler/empty.s | 3 + .../incoming-handler.exports.go | 26 + .../incoming-handler/incoming-handler.wit.go | 21 + .../wasi/http/outgoing-handler/abi.go | 24 + .../wasi/http/outgoing-handler/empty.s | 3 + .../outgoing-handler/outgoing-handler.wit.go | 40 + .../go/http/bindings/wasi/http/types/abi.go | 273 +++ .../go/http/bindings/wasi/http/types/empty.s | 3 + .../bindings/wasi/http/types/types.wit.go | 2148 +++++++++++++++++ .../go/http/bindings/wasi/io/error/empty.s | 3 + .../http/bindings/wasi/io/error/error.wit.go | 69 + .../go/http/bindings/wasi/io/poll/empty.s | 3 + .../go/http/bindings/wasi/io/poll/poll.wit.go | 109 + .../go/http/bindings/wasi/io/streams/abi.go | 12 + .../go/http/bindings/wasi/io/streams/empty.s | 3 + .../bindings/wasi/io/streams/streams.wit.go | 523 ++++ .../wasi/random/insecure-seed/empty.s | 3 + .../random/insecure-seed/insecure-seed.wit.go | 41 + .../bindings/wasi/random/insecure/empty.s | 3 + .../wasi/random/insecure/insecure.wit.go | 57 + .../http/bindings/wasi/random/random/empty.s | 3 + .../bindings/wasi/random/random/random.wit.go | 61 + .../wasi/sockets/instance-network/empty.s | 3 + .../instance-network/instance-network.wit.go | 28 + .../wasi/sockets/ip-name-lookup/abi.go | 14 + .../wasi/sockets/ip-name-lookup/empty.s | 3 + .../ip-name-lookup/ip-name-lookup.wit.go | 121 + .../http/bindings/wasi/sockets/network/abi.go | 12 + .../bindings/wasi/sockets/network/empty.s | 3 + .../wasi/sockets/network/network.wit.go | 315 +++ .../wasi/sockets/tcp-create-socket/empty.s | 3 + .../tcp-create-socket.wit.go | 52 + .../go/http/bindings/wasi/sockets/tcp/abi.go | 86 + .../go/http/bindings/wasi/sockets/tcp/empty.s | 3 + .../http/bindings/wasi/sockets/tcp/tcp.wit.go | 848 +++++++ .../wasi/sockets/udp-create-socket/empty.s | 3 + .../udp-create-socket.wit.go | 52 + .../go/http/bindings/wasi/sockets/udp/abi.go | 101 + .../go/http/bindings/wasi/sockets/udp/empty.s | 3 + .../http/bindings/wasi/sockets/udp/udp.wit.go | 641 +++++ .../west-examples/http/app/app.wit.go | 4 + examples/go/http/http.go | 64 + examples/go/http/http_test.go | 102 + examples/go/http/wit/app.wit | 8 + examples/go/http/wit/deps.lock | 29 + examples/go/http/wit/deps.toml | 1 + examples/go/http/wit/deps/cli/command.wit | 10 + examples/go/http/wit/deps/cli/environment.wit | 22 + examples/go/http/wit/deps/cli/exit.wit | 17 + examples/go/http/wit/deps/cli/imports.wit | 36 + examples/go/http/wit/deps/cli/run.wit | 6 + examples/go/http/wit/deps/cli/stdio.wit | 26 + examples/go/http/wit/deps/cli/terminal.wit | 62 + .../http/wit/deps/clocks/monotonic-clock.wit | 50 + examples/go/http/wit/deps/clocks/timezone.wit | 55 + .../go/http/wit/deps/clocks/wall-clock.wit | 46 + examples/go/http/wit/deps/clocks/world.wit | 11 + .../go/http/wit/deps/filesystem/preopens.wit | 11 + .../go/http/wit/deps/filesystem/types.wit | 678 ++++++ .../go/http/wit/deps/filesystem/world.wit | 9 + examples/go/http/wit/deps/http/handler.wit | 49 + examples/go/http/wit/deps/http/proxy.wit | 50 + examples/go/http/wit/deps/http/types.wit | 655 +++++ examples/go/http/wit/deps/io/error.wit | 34 + examples/go/http/wit/deps/io/poll.wit | 47 + examples/go/http/wit/deps/io/streams.wit | 286 +++ examples/go/http/wit/deps/io/world.wit | 10 + .../go/http/wit/deps/random/insecure-seed.wit | 27 + examples/go/http/wit/deps/random/insecure.wit | 25 + examples/go/http/wit/deps/random/random.wit | 29 + examples/go/http/wit/deps/random/world.wit | 13 + .../wit/deps/sockets/instance-network.wit | 11 + .../http/wit/deps/sockets/ip-name-lookup.wit | 56 + examples/go/http/wit/deps/sockets/network.wit | 153 ++ .../wit/deps/sockets/tcp-create-socket.wit | 30 + examples/go/http/wit/deps/sockets/tcp.wit | 387 +++ .../wit/deps/sockets/udp-create-socket.wit | 30 + examples/go/http/wit/deps/sockets/udp.wit | 288 +++ examples/go/http/wit/deps/sockets/world.wit | 19 + go.mod | 6 +- go.sum | 8 +- go.work.sum | 4 +- .../lib_windows_arm64.go} | 0 lib/x86_64-linux/lib_linux_amd64.go | 1 + src/lib.rs | 19 +- tests/components/wasi/Cargo.toml | 2 +- tests/components/wasi/src/lib.rs | 46 +- tests/components/wasi/wit/deps/fib | 1 + tests/components/wasi/wit/deps/io | 1 + tests/components/wasi/wit/deps/leftpad | 1 + tests/components/wasi/wit/harness.wit | 10 + .../sync/bindings/west-test/sync/sync/abi.go | 2 +- .../bindings/west-test/sync/sync/sync.wit.go | 2 +- tests/go/sync/sync.go | 2 +- tests/go/sync/sync_test.go | 21 +- .../wasi/cli/environment/environment.wit.go | 10 +- .../wasi/bindings/wasi/cli/exit/exit.wit.go | 30 +- .../bindings/wasi/cli/stderr/stderr.wit.go | 6 +- .../wasi/bindings/wasi/cli/stdin/stdin.wit.go | 6 +- .../bindings/wasi/cli/stdout/stdout.wit.go | 6 +- .../cli/terminal-input/terminal-input.wit.go | 8 +- .../terminal-output/terminal-output.wit.go | 8 +- .../terminal-stderr/terminal-stderr.wit.go | 6 +- .../cli/terminal-stdin/terminal-stdin.wit.go | 6 +- .../terminal-stdout/terminal-stdout.wit.go | 6 +- .../monotonic-clock/monotonic-clock.wit.go | 25 +- .../wasi/bindings/wasi/clocks/timezone/abi.go | 13 + .../bindings/wasi/clocks/timezone/empty.s | 3 + .../wasi/clocks/timezone/timezone.wit.go | 90 + .../wasi/clocks/wall-clock/wall-clock.wit.go | 8 +- .../wasi/filesystem/preopens/preopens.wit.go | 6 +- .../bindings/wasi/filesystem/types/abi.go | 2 +- .../wasi/filesystem/types/types.wit.go | 96 +- .../incoming-handler.exports.go | 2 +- .../incoming-handler/incoming-handler.wit.go | 8 +- tests/go/wasi/bindings/wasi/http/types/abi.go | 2 +- .../bindings/wasi/http/types/types.wit.go | 229 +- .../wasi/bindings/wasi/io/error/error.wit.go | 22 +- .../go/wasi/bindings/wasi/io/poll/poll.wit.go | 21 +- .../bindings/wasi/io/streams/streams.wit.go | 52 +- .../random/insecure-seed/insecure-seed.wit.go | 4 +- .../wasi/random/insecure/insecure.wit.go | 8 +- .../bindings/wasi/random/random/random.wit.go | 8 +- .../instance-network/instance-network.wit.go | 6 +- .../wasi/sockets/ip-name-lookup/abi.go | 2 +- .../ip-name-lookup/ip-name-lookup.wit.go | 14 +- .../wasi/sockets/network/network.wit.go | 24 +- .../tcp-create-socket.wit.go | 6 +- .../go/wasi/bindings/wasi/sockets/tcp/abi.go | 2 +- .../wasi/bindings/wasi/sockets/tcp/tcp.wit.go | 78 +- .../udp-create-socket.wit.go | 6 +- .../go/wasi/bindings/wasi/sockets/udp/abi.go | 2 +- .../wasi/bindings/wasi/sockets/udp/udp.wit.go | 56 +- .../bindings/west-test/leftpad/leftpad/abi.go | 13 + .../west-test/leftpad/leftpad/empty.s | 3 + .../west-test/leftpad/leftpad/leftpad.wit.go | 28 + tests/go/wasi/wasi.go | 80 +- tests/go/wasi/wasi_test.go | 103 +- tests/go/wasi/wit/app.wit | 7 +- tests/go/wasi/wit/deps.lock | 38 +- tests/go/wasi/wit/deps.toml | 5 +- tests/go/wasi/wit/deps/cli/command.wit | 5 +- tests/go/wasi/wit/deps/cli/environment.wit | 4 + tests/go/wasi/wit/deps/cli/exit.wit | 13 + tests/go/wasi/wit/deps/cli/imports.wit | 28 +- tests/go/wasi/wit/deps/cli/run.wit | 2 + tests/go/wasi/wit/deps/cli/stdio.wit | 15 +- tests/go/wasi/wit/deps/cli/terminal.wit | 13 + .../wasi/wit/deps/clocks/monotonic-clock.wit | 21 +- tests/go/wasi/wit/deps/clocks/timezone.wit | 55 + tests/go/wasi/wit/deps/clocks/wall-clock.wit | 6 +- tests/go/wasi/wit/deps/clocks/world.wit | 7 +- .../go/wasi/wit/deps/filesystem/preopens.wit | 5 +- tests/go/wasi/wit/deps/filesystem/types.wit | 52 +- tests/go/wasi/wit/deps/filesystem/world.wit | 5 +- tests/go/wasi/wit/deps/http/handler.wit | 6 + tests/go/wasi/wit/deps/http/proxy.wit | 40 +- tests/go/wasi/wit/deps/http/types.wit | 147 +- tests/go/wasi/wit/deps/io/error.wit | 18 +- tests/go/wasi/wit/deps/io/poll.wit | 14 +- tests/go/wasi/wit/deps/io/streams.wit | 30 +- tests/go/wasi/wit/deps/io/world.wit | 6 +- tests/go/wasi/wit/deps/leftpad/leftpad.wit | 15 + .../go/wasi/wit/deps/random/insecure-seed.wit | 4 +- tests/go/wasi/wit/deps/random/insecure.wit | 5 +- tests/go/wasi/wit/deps/random/random.wit | 5 +- tests/go/wasi/wit/deps/random/world.wit | 8 +- .../wit/deps/sockets/instance-network.wit | 4 +- .../wasi/wit/deps/sockets/ip-name-lookup.wit | 11 +- tests/go/wasi/wit/deps/sockets/network.wit | 12 +- .../wit/deps/sockets/tcp-create-socket.wit | 5 +- tests/go/wasi/wit/deps/sockets/tcp.wit | 54 +- .../wit/deps/sockets/udp-create-socket.wit | 5 +- tests/go/wasi/wit/deps/sockets/udp.wit | 30 +- tests/go/wasi/wit/deps/sockets/world.wit | 10 +- tests/wit/leftpad/deps/io | 1 + tests/wit/leftpad/leftpad.wit | 15 + west.go | 10 +- west_darwin_amd64.go | 2 + west_darwin_arm64.go | 2 + west_linux_amd64.go | 2 + west_linux_arm64.go | 2 + west_windows_amd64.go | 2 + west_windows_arm64.go | 5 + wit/deps.lock | 40 +- wit/deps.toml | 2 +- wit/deps/cli/command.wit | 5 +- wit/deps/cli/environment.wit | 4 + wit/deps/cli/exit.wit | 13 + wit/deps/cli/imports.wit | 28 +- wit/deps/cli/run.wit | 2 + wit/deps/cli/stdio.wit | 15 +- wit/deps/cli/terminal.wit | 13 + wit/deps/clocks/monotonic-clock.wit | 21 +- wit/deps/clocks/timezone.wit | 55 + wit/deps/clocks/wall-clock.wit | 6 +- wit/deps/clocks/world.wit | 7 +- wit/deps/filesystem/preopens.wit | 5 +- wit/deps/filesystem/types.wit | 52 +- wit/deps/filesystem/world.wit | 5 +- wit/deps/http/handler.wit | 6 + wit/deps/http/proxy.wit | 40 +- wit/deps/http/types.wit | 147 +- wit/deps/httpext/http.wit | 17 + wit/deps/io/error.wit | 18 +- wit/deps/io/poll.wit | 14 +- wit/deps/io/streams.wit | 30 +- wit/deps/io/world.wit | 6 +- wit/deps/passthrough/passthrough.wit | 61 + wit/deps/random/insecure-seed.wit | 4 +- wit/deps/random/insecure.wit | 5 +- wit/deps/random/random.wit | 5 +- wit/deps/random/world.wit | 8 +- wit/deps/sockets/instance-network.wit | 4 +- wit/deps/sockets/ip-name-lookup.wit | 11 +- wit/deps/sockets/network.wit | 12 +- wit/deps/sockets/tcp-create-socket.wit | 5 +- wit/deps/sockets/tcp.wit | 54 +- wit/deps/sockets/udp-create-socket.wit | 5 +- wit/deps/sockets/udp.wit | 30 +- wit/deps/sockets/world.wit | 10 +- wit/west.wit | 107 +- 323 files changed, 14112 insertions(+), 2878 deletions(-) create mode 100644 bindings/wasi/clocks/timezone/abi.go rename bindings/{west/test/http-test => wasi/clocks/timezone}/empty.s (100%) create mode 100644 bindings/wasi/clocks/timezone/timezone.wit.go create mode 100644 bindings/wasi/http/imports/imports.wit.go create mode 100644 bindings/wasi/http/outgoing-handler/abi.go create mode 100644 bindings/wasi/http/outgoing-handler/empty.s create mode 100644 bindings/wasi/http/outgoing-handler/outgoing-handler.wit.go create mode 100644 bindings/wasiext/http/ext/empty.s rename bindings/{west/test/http-test/http-test.wit.go => wasiext/http/ext/ext.wit.go} (80%) create mode 100644 bindings/wasiext/http/imports/imports.wit.go rename bindings/west/{test => west}/imports/imports.wit.go (52%) create mode 100644 build.go create mode 100644 build_dev.go delete mode 100644 crates/passthrough/src/bindings.rs delete mode 100644 crates/passthrough/src/cli.rs delete mode 100644 crates/passthrough/src/clocks.rs delete mode 100644 crates/passthrough/src/filesystem.rs delete mode 100644 crates/passthrough/src/http.rs delete mode 100644 crates/passthrough/src/io.rs delete mode 100644 crates/passthrough/src/sockets.rs delete mode 100644 crates/passthrough/src/west.rs delete mode 120000 crates/passthrough/wit rename {tests/go/sync => examples/go/http}/bindings/.gitkeep (100%) create mode 100644 examples/go/http/bindings/wasi/cli/environment/empty.s create mode 100644 examples/go/http/bindings/wasi/cli/environment/environment.wit.go create mode 100644 examples/go/http/bindings/wasi/cli/exit/empty.s create mode 100644 examples/go/http/bindings/wasi/cli/exit/exit.wit.go create mode 100644 examples/go/http/bindings/wasi/cli/stderr/empty.s create mode 100644 examples/go/http/bindings/wasi/cli/stderr/stderr.wit.go create mode 100644 examples/go/http/bindings/wasi/cli/stdin/empty.s create mode 100644 examples/go/http/bindings/wasi/cli/stdin/stdin.wit.go create mode 100644 examples/go/http/bindings/wasi/cli/stdout/empty.s create mode 100644 examples/go/http/bindings/wasi/cli/stdout/stdout.wit.go create mode 100644 examples/go/http/bindings/wasi/cli/terminal-input/empty.s create mode 100644 examples/go/http/bindings/wasi/cli/terminal-input/terminal-input.wit.go create mode 100644 examples/go/http/bindings/wasi/cli/terminal-output/empty.s create mode 100644 examples/go/http/bindings/wasi/cli/terminal-output/terminal-output.wit.go create mode 100644 examples/go/http/bindings/wasi/cli/terminal-stderr/empty.s create mode 100644 examples/go/http/bindings/wasi/cli/terminal-stderr/terminal-stderr.wit.go create mode 100644 examples/go/http/bindings/wasi/cli/terminal-stdin/empty.s create mode 100644 examples/go/http/bindings/wasi/cli/terminal-stdin/terminal-stdin.wit.go create mode 100644 examples/go/http/bindings/wasi/cli/terminal-stdout/empty.s create mode 100644 examples/go/http/bindings/wasi/cli/terminal-stdout/terminal-stdout.wit.go create mode 100644 examples/go/http/bindings/wasi/clocks/monotonic-clock/empty.s create mode 100644 examples/go/http/bindings/wasi/clocks/monotonic-clock/monotonic-clock.wit.go create mode 100644 examples/go/http/bindings/wasi/clocks/timezone/abi.go create mode 100644 examples/go/http/bindings/wasi/clocks/timezone/empty.s create mode 100644 examples/go/http/bindings/wasi/clocks/timezone/timezone.wit.go create mode 100644 examples/go/http/bindings/wasi/clocks/wall-clock/empty.s create mode 100644 examples/go/http/bindings/wasi/clocks/wall-clock/wall-clock.wit.go create mode 100644 examples/go/http/bindings/wasi/filesystem/preopens/empty.s create mode 100644 examples/go/http/bindings/wasi/filesystem/preopens/preopens.wit.go create mode 100644 examples/go/http/bindings/wasi/filesystem/types/abi.go create mode 100644 examples/go/http/bindings/wasi/filesystem/types/empty.s create mode 100644 examples/go/http/bindings/wasi/filesystem/types/types.wit.go create mode 100644 examples/go/http/bindings/wasi/http/incoming-handler/empty.s create mode 100644 examples/go/http/bindings/wasi/http/incoming-handler/incoming-handler.exports.go create mode 100644 examples/go/http/bindings/wasi/http/incoming-handler/incoming-handler.wit.go create mode 100644 examples/go/http/bindings/wasi/http/outgoing-handler/abi.go create mode 100644 examples/go/http/bindings/wasi/http/outgoing-handler/empty.s create mode 100644 examples/go/http/bindings/wasi/http/outgoing-handler/outgoing-handler.wit.go create mode 100644 examples/go/http/bindings/wasi/http/types/abi.go create mode 100644 examples/go/http/bindings/wasi/http/types/empty.s create mode 100644 examples/go/http/bindings/wasi/http/types/types.wit.go create mode 100644 examples/go/http/bindings/wasi/io/error/empty.s create mode 100644 examples/go/http/bindings/wasi/io/error/error.wit.go create mode 100644 examples/go/http/bindings/wasi/io/poll/empty.s create mode 100644 examples/go/http/bindings/wasi/io/poll/poll.wit.go create mode 100644 examples/go/http/bindings/wasi/io/streams/abi.go create mode 100644 examples/go/http/bindings/wasi/io/streams/empty.s create mode 100644 examples/go/http/bindings/wasi/io/streams/streams.wit.go create mode 100644 examples/go/http/bindings/wasi/random/insecure-seed/empty.s create mode 100644 examples/go/http/bindings/wasi/random/insecure-seed/insecure-seed.wit.go create mode 100644 examples/go/http/bindings/wasi/random/insecure/empty.s create mode 100644 examples/go/http/bindings/wasi/random/insecure/insecure.wit.go create mode 100644 examples/go/http/bindings/wasi/random/random/empty.s create mode 100644 examples/go/http/bindings/wasi/random/random/random.wit.go create mode 100644 examples/go/http/bindings/wasi/sockets/instance-network/empty.s create mode 100644 examples/go/http/bindings/wasi/sockets/instance-network/instance-network.wit.go create mode 100644 examples/go/http/bindings/wasi/sockets/ip-name-lookup/abi.go create mode 100644 examples/go/http/bindings/wasi/sockets/ip-name-lookup/empty.s create mode 100644 examples/go/http/bindings/wasi/sockets/ip-name-lookup/ip-name-lookup.wit.go create mode 100644 examples/go/http/bindings/wasi/sockets/network/abi.go create mode 100644 examples/go/http/bindings/wasi/sockets/network/empty.s create mode 100644 examples/go/http/bindings/wasi/sockets/network/network.wit.go create mode 100644 examples/go/http/bindings/wasi/sockets/tcp-create-socket/empty.s create mode 100644 examples/go/http/bindings/wasi/sockets/tcp-create-socket/tcp-create-socket.wit.go create mode 100644 examples/go/http/bindings/wasi/sockets/tcp/abi.go create mode 100644 examples/go/http/bindings/wasi/sockets/tcp/empty.s create mode 100644 examples/go/http/bindings/wasi/sockets/tcp/tcp.wit.go create mode 100644 examples/go/http/bindings/wasi/sockets/udp-create-socket/empty.s create mode 100644 examples/go/http/bindings/wasi/sockets/udp-create-socket/udp-create-socket.wit.go create mode 100644 examples/go/http/bindings/wasi/sockets/udp/abi.go create mode 100644 examples/go/http/bindings/wasi/sockets/udp/empty.s create mode 100644 examples/go/http/bindings/wasi/sockets/udp/udp.wit.go create mode 100644 examples/go/http/bindings/west-examples/http/app/app.wit.go create mode 100644 examples/go/http/http.go create mode 100644 examples/go/http/http_test.go create mode 100644 examples/go/http/wit/app.wit create mode 100644 examples/go/http/wit/deps.lock create mode 100644 examples/go/http/wit/deps.toml create mode 100644 examples/go/http/wit/deps/cli/command.wit create mode 100644 examples/go/http/wit/deps/cli/environment.wit create mode 100644 examples/go/http/wit/deps/cli/exit.wit create mode 100644 examples/go/http/wit/deps/cli/imports.wit create mode 100644 examples/go/http/wit/deps/cli/run.wit create mode 100644 examples/go/http/wit/deps/cli/stdio.wit create mode 100644 examples/go/http/wit/deps/cli/terminal.wit create mode 100644 examples/go/http/wit/deps/clocks/monotonic-clock.wit create mode 100644 examples/go/http/wit/deps/clocks/timezone.wit create mode 100644 examples/go/http/wit/deps/clocks/wall-clock.wit create mode 100644 examples/go/http/wit/deps/clocks/world.wit create mode 100644 examples/go/http/wit/deps/filesystem/preopens.wit create mode 100644 examples/go/http/wit/deps/filesystem/types.wit create mode 100644 examples/go/http/wit/deps/filesystem/world.wit create mode 100644 examples/go/http/wit/deps/http/handler.wit create mode 100644 examples/go/http/wit/deps/http/proxy.wit create mode 100644 examples/go/http/wit/deps/http/types.wit create mode 100644 examples/go/http/wit/deps/io/error.wit create mode 100644 examples/go/http/wit/deps/io/poll.wit create mode 100644 examples/go/http/wit/deps/io/streams.wit create mode 100644 examples/go/http/wit/deps/io/world.wit create mode 100644 examples/go/http/wit/deps/random/insecure-seed.wit create mode 100644 examples/go/http/wit/deps/random/insecure.wit create mode 100644 examples/go/http/wit/deps/random/random.wit create mode 100644 examples/go/http/wit/deps/random/world.wit create mode 100644 examples/go/http/wit/deps/sockets/instance-network.wit create mode 100644 examples/go/http/wit/deps/sockets/ip-name-lookup.wit create mode 100644 examples/go/http/wit/deps/sockets/network.wit create mode 100644 examples/go/http/wit/deps/sockets/tcp-create-socket.wit create mode 100644 examples/go/http/wit/deps/sockets/tcp.wit create mode 100644 examples/go/http/wit/deps/sockets/udp-create-socket.wit create mode 100644 examples/go/http/wit/deps/sockets/udp.wit create mode 100644 examples/go/http/wit/deps/sockets/world.wit rename lib/{amd64-linux/lib_linux_amd64.go => aarch64-windows/lib_windows_arm64.go} (100%) create mode 100644 lib/x86_64-linux/lib_linux_amd64.go create mode 120000 tests/components/wasi/wit/deps/fib create mode 120000 tests/components/wasi/wit/deps/io create mode 120000 tests/components/wasi/wit/deps/leftpad create mode 100644 tests/components/wasi/wit/harness.wit create mode 100644 tests/go/wasi/bindings/wasi/clocks/timezone/abi.go create mode 100644 tests/go/wasi/bindings/wasi/clocks/timezone/empty.s create mode 100644 tests/go/wasi/bindings/wasi/clocks/timezone/timezone.wit.go create mode 100644 tests/go/wasi/bindings/west-test/leftpad/leftpad/abi.go create mode 100644 tests/go/wasi/bindings/west-test/leftpad/leftpad/empty.s create mode 100644 tests/go/wasi/bindings/west-test/leftpad/leftpad/leftpad.wit.go create mode 100644 tests/go/wasi/wit/deps/clocks/timezone.wit create mode 100644 tests/go/wasi/wit/deps/leftpad/leftpad.wit create mode 120000 tests/wit/leftpad/deps/io create mode 100644 tests/wit/leftpad/leftpad.wit create mode 100644 west_windows_arm64.go create mode 100644 wit/deps/clocks/timezone.wit create mode 100644 wit/deps/httpext/http.wit create mode 100644 wit/deps/passthrough/passthrough.wit diff --git a/Cargo.lock b/Cargo.lock index 0080a9c..2c21875 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1588,6 +1588,15 @@ version = "0.11.0+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" +[[package]] +name = "wasi-passthrough" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "75af629a58d64296102af2854e9b37a9341efd21984c8277326f8e921ef354e0" +dependencies = [ + "wit-bindgen", +] + [[package]] name = "wasi-preview1-component-adapter-provider" version = "24.0.0" @@ -1598,7 +1607,7 @@ checksum = "36e6cadfa74538edd5409b6f8c79628436529138e9618b7373bec7aae7805835" name = "wasi-test-component" version = "0.1.0" dependencies = [ - "west-passthrough", + "wasi-passthrough", "wit-bindgen", ] @@ -2011,6 +2020,7 @@ dependencies = [ "anyhow", "http", "tokio", + "tracing", "wasi-preview1-component-adapter-provider", "wasmparser 0.217.0", "wasmtime", @@ -2023,7 +2033,7 @@ dependencies = [ name = "west-passthrough" version = "0.1.0-alpha.1" dependencies = [ - "wit-bindgen", + "wasi-passthrough", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index a0b8575..f8bb480 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,17 +9,6 @@ edition.workspace = true license.workspace = true repository.workspace = true -[profile.release.package.west-passthrough] -opt-level = 's' -strip = true - -[profile.release.package.west-sys] -opt-level = 's' -strip = true - -[profile.release] -lto = true - [workspace] members = ["crates/*", "tests/components/*"] @@ -31,10 +20,22 @@ homepage = "https://github.com/rvolosatovs/west" license = "Apache-2.0 WITH LLVM-exception" repository = "https://github.com/rvolosatovs/west" +[profile.release.package.west-passthrough] +opt-level = 's' +strip = true + +[profile.release.package.west-sys] +opt-level = 's' +strip = true + +[profile.release] +lto = true + [dependencies] anyhow = { workspace = true } http = { workspace = true } tokio = { workspace = true } +tracing = { workspace = true } wasi-preview1-component-adapter-provider = { workspace = true } wasmparser = { workspace = true } wasmtime = { workspace = true, features = ["cranelift"] } @@ -49,12 +50,12 @@ http = { version = "1", default-features = false } tokio = { version = "1", default-features = false } tracing = { version = "0.1", default-features = false } tracing-subscriber = { version = "0.3", default-features = false } +wasi-passthrough = { version = "0.1.1", default-features = false } wasi-preview1-component-adapter-provider = { version = "24", default-features = false } wasmparser = { version = "0.217", default-features = false } wasmtime = { version = "24", default-features = false } wasmtime-wasi = { version = "24", default-features = false } wasmtime-wasi-http = { version = "24", default-features = false } -west-passthrough = { version = "0.1.0-alpha.1", path = "./crates/passthrough" } west = { version = "0.1.0-alpha.2", path = "." } wit-bindgen = { version = "0.32", default-features = false } wit-component = { version = "0.217", default-features = false } diff --git a/bindings/bindings.go b/bindings/bindings.go index a122b7b..c105441 100644 --- a/bindings/bindings.go +++ b/bindings/bindings.go @@ -3,12 +3,12 @@ package bindings import ( + github_com__bytecodealliance__wasm___tools___go__cm "github.com/bytecodealliance/wasm-tools-go/cm" west "github.com/rvolosatovs/west" github_com__rvolosatovs__west__bindings__wasi__clocks__monotonic___clock "github.com/rvolosatovs/west/bindings/wasi/clocks/monotonic-clock" github_com__rvolosatovs__west__bindings__wasi__http__types "github.com/rvolosatovs/west/bindings/wasi/http/types" github_com__rvolosatovs__west__bindings__wasi__io__poll "github.com/rvolosatovs/west/bindings/wasi/io/poll" github_com__rvolosatovs__west__bindings__wasi__io__streams "github.com/rvolosatovs/west/bindings/wasi/io/streams" - github_com__ydnar__wasm___tools___go__cm "github.com/ydnar/wasm-tools-go/cm" "runtime" "unsafe" ) @@ -22,7 +22,7 @@ func wasmimport_Now() (result0 uint64) { var __p runtime.Pinner defer __p.Unpin() if __err := west.WithCurrentInstance(func(__instance *west.Instance) error { - return __instance.Call("wasi:clocks/monotonic-clock@0.2.0", "now", func() unsafe.Pointer { + return __instance.Call("wasi:clocks/monotonic-clock@0.2.1", "now", func() unsafe.Pointer { ptr := unsafe.Pointer(&result0) __p.Pin(ptr) return ptr @@ -38,7 +38,7 @@ func wasmimport_Resolution() (result0 uint64) { var __p runtime.Pinner defer __p.Unpin() if __err := west.WithCurrentInstance(func(__instance *west.Instance) error { - return __instance.Call("wasi:clocks/monotonic-clock@0.2.0", "resolution", func() unsafe.Pointer { + return __instance.Call("wasi:clocks/monotonic-clock@0.2.1", "resolution", func() unsafe.Pointer { ptr := unsafe.Pointer(&result0) __p.Pin(ptr) return ptr @@ -54,7 +54,7 @@ func wasmimport_SubscribeDuration(when0 uint64) (result0 uint32) { var __p runtime.Pinner defer __p.Unpin() if __err := west.WithCurrentInstance(func(__instance *west.Instance) error { - return __instance.Call("wasi:clocks/monotonic-clock@0.2.0", "subscribe-duration", func() unsafe.Pointer { + return __instance.Call("wasi:clocks/monotonic-clock@0.2.1", "subscribe-duration", func() unsafe.Pointer { ptr := unsafe.Pointer(&when0) __p.Pin(ptr) return ptr @@ -74,7 +74,7 @@ func wasmimport_SubscribeInstant(when0 uint64) (result0 uint32) { var __p runtime.Pinner defer __p.Unpin() if __err := west.WithCurrentInstance(func(__instance *west.Instance) error { - return __instance.Call("wasi:clocks/monotonic-clock@0.2.0", "subscribe-instant", func() unsafe.Pointer { + return __instance.Call("wasi:clocks/monotonic-clock@0.2.1", "subscribe-instant", func() unsafe.Pointer { ptr := unsafe.Pointer(&when0) __p.Pin(ptr) return ptr @@ -94,7 +94,7 @@ func wasmimport_NewFields() (result0 uint32) { var __p runtime.Pinner defer __p.Unpin() if __err := west.WithCurrentInstance(func(__instance *west.Instance) error { - return __instance.Call("wasi:http/types@0.2.0", "[constructor]fields", func() unsafe.Pointer { + return __instance.Call("wasi:http/types@0.2.1", "[constructor]fields", func() unsafe.Pointer { ptr := unsafe.Pointer(&result0) __p.Pin(ptr) return ptr @@ -110,7 +110,7 @@ func wasmimport_NewOutgoingRequest(headers0 uint32) (result0 uint32) { var __p runtime.Pinner defer __p.Unpin() if __err := west.WithCurrentInstance(func(__instance *west.Instance) error { - return __instance.Call("wasi:http/types@0.2.0", "[constructor]outgoing-request", func() unsafe.Pointer { + return __instance.Call("wasi:http/types@0.2.1", "[constructor]outgoing-request", func() unsafe.Pointer { ptr := unsafe.Pointer(&headers0) __p.Pin(ptr) return ptr @@ -130,7 +130,7 @@ func wasmimport_NewOutgoingResponse(headers0 uint32) (result0 uint32) { var __p runtime.Pinner defer __p.Unpin() if __err := west.WithCurrentInstance(func(__instance *west.Instance) error { - return __instance.Call("wasi:http/types@0.2.0", "[constructor]outgoing-response", func() unsafe.Pointer { + return __instance.Call("wasi:http/types@0.2.1", "[constructor]outgoing-response", func() unsafe.Pointer { ptr := unsafe.Pointer(&headers0) __p.Pin(ptr) return ptr @@ -150,7 +150,7 @@ func wasmimport_NewRequestOptions() (result0 uint32) { var __p runtime.Pinner defer __p.Unpin() if __err := west.WithCurrentInstance(func(__instance *west.Instance) error { - return __instance.Call("wasi:http/types@0.2.0", "[constructor]request-options", func() unsafe.Pointer { + return __instance.Call("wasi:http/types@0.2.1", "[constructor]request-options", func() unsafe.Pointer { ptr := unsafe.Pointer(&result0) __p.Pin(ptr) return ptr @@ -162,11 +162,11 @@ func wasmimport_NewRequestOptions() (result0 uint32) { } //go:linkname wasmimport_FieldsAppend github.com/rvolosatovs/west/bindings/wasi/http/types.wasmimport_FieldsAppend -func wasmimport_FieldsAppend(self0 uint32, name0 *uint8, name1 uint32, value0 *uint8, value1 uint32, result *github_com__ydnar__wasm___tools___go__cm.Result[github_com__rvolosatovs__west__bindings__wasi__http__types.HeaderError, struct{}, github_com__rvolosatovs__west__bindings__wasi__http__types.HeaderError]) { +func wasmimport_FieldsAppend(self0 uint32, name0 *uint8, name1 uint32, value0 *uint8, value1 uint32, result *github_com__bytecodealliance__wasm___tools___go__cm.Result[github_com__rvolosatovs__west__bindings__wasi__http__types.HeaderError, struct{}, github_com__rvolosatovs__west__bindings__wasi__http__types.HeaderError]) { var __p runtime.Pinner defer __p.Unpin() if __err := west.WithCurrentInstance(func(__instance *west.Instance) error { - return __instance.Call("wasi:http/types@0.2.0", "[method]fields.append", func() unsafe.Pointer { + return __instance.Call("wasi:http/types@0.2.1", "[method]fields.append", func() unsafe.Pointer { ptr := unsafe.Pointer(&self0) __p.Pin(ptr) return ptr @@ -202,7 +202,7 @@ func wasmimport_FieldsClone(self0 uint32) (result0 uint32) { var __p runtime.Pinner defer __p.Unpin() if __err := west.WithCurrentInstance(func(__instance *west.Instance) error { - return __instance.Call("wasi:http/types@0.2.0", "[method]fields.clone", func() unsafe.Pointer { + return __instance.Call("wasi:http/types@0.2.1", "[method]fields.clone", func() unsafe.Pointer { ptr := unsafe.Pointer(&self0) __p.Pin(ptr) return ptr @@ -218,11 +218,11 @@ func wasmimport_FieldsClone(self0 uint32) (result0 uint32) { } //go:linkname wasmimport_FieldsDelete github.com/rvolosatovs/west/bindings/wasi/http/types.wasmimport_FieldsDelete -func wasmimport_FieldsDelete(self0 uint32, name0 *uint8, name1 uint32, result *github_com__ydnar__wasm___tools___go__cm.Result[github_com__rvolosatovs__west__bindings__wasi__http__types.HeaderError, struct{}, github_com__rvolosatovs__west__bindings__wasi__http__types.HeaderError]) { +func wasmimport_FieldsDelete(self0 uint32, name0 *uint8, name1 uint32, result *github_com__bytecodealliance__wasm___tools___go__cm.Result[github_com__rvolosatovs__west__bindings__wasi__http__types.HeaderError, struct{}, github_com__rvolosatovs__west__bindings__wasi__http__types.HeaderError]) { var __p runtime.Pinner defer __p.Unpin() if __err := west.WithCurrentInstance(func(__instance *west.Instance) error { - return __instance.Call("wasi:http/types@0.2.0", "[method]fields.delete", func() unsafe.Pointer { + return __instance.Call("wasi:http/types@0.2.1", "[method]fields.delete", func() unsafe.Pointer { ptr := unsafe.Pointer(&self0) __p.Pin(ptr) return ptr @@ -246,11 +246,11 @@ func wasmimport_FieldsDelete(self0 uint32, name0 *uint8, name1 uint32, result *g } //go:linkname wasmimport_FieldsEntries github.com/rvolosatovs/west/bindings/wasi/http/types.wasmimport_FieldsEntries -func wasmimport_FieldsEntries(self0 uint32, result *github_com__ydnar__wasm___tools___go__cm.List[github_com__ydnar__wasm___tools___go__cm.Tuple[github_com__rvolosatovs__west__bindings__wasi__http__types.FieldKey, github_com__rvolosatovs__west__bindings__wasi__http__types.FieldValue]]) { +func wasmimport_FieldsEntries(self0 uint32, result *github_com__bytecodealliance__wasm___tools___go__cm.List[github_com__bytecodealliance__wasm___tools___go__cm.Tuple[github_com__rvolosatovs__west__bindings__wasi__http__types.FieldKey, github_com__rvolosatovs__west__bindings__wasi__http__types.FieldValue]]) { var __p runtime.Pinner defer __p.Unpin() if __err := west.WithCurrentInstance(func(__instance *west.Instance) error { - return __instance.Call("wasi:http/types@0.2.0", "[method]fields.entries", func() unsafe.Pointer { + return __instance.Call("wasi:http/types@0.2.1", "[method]fields.entries", func() unsafe.Pointer { ptr := unsafe.Pointer(&self0) __p.Pin(ptr) return ptr @@ -266,11 +266,11 @@ func wasmimport_FieldsEntries(self0 uint32, result *github_com__ydnar__wasm___to } //go:linkname wasmimport_FieldsGet github.com/rvolosatovs/west/bindings/wasi/http/types.wasmimport_FieldsGet -func wasmimport_FieldsGet(self0 uint32, name0 *uint8, name1 uint32, result *github_com__ydnar__wasm___tools___go__cm.List[github_com__rvolosatovs__west__bindings__wasi__http__types.FieldValue]) { +func wasmimport_FieldsGet(self0 uint32, name0 *uint8, name1 uint32, result *github_com__bytecodealliance__wasm___tools___go__cm.List[github_com__rvolosatovs__west__bindings__wasi__http__types.FieldValue]) { var __p runtime.Pinner defer __p.Unpin() if __err := west.WithCurrentInstance(func(__instance *west.Instance) error { - return __instance.Call("wasi:http/types@0.2.0", "[method]fields.get", func() unsafe.Pointer { + return __instance.Call("wasi:http/types@0.2.1", "[method]fields.get", func() unsafe.Pointer { ptr := unsafe.Pointer(&self0) __p.Pin(ptr) return ptr @@ -298,7 +298,7 @@ func wasmimport_FieldsHas(self0 uint32, name0 *uint8, name1 uint32) (result0 uin var __p runtime.Pinner defer __p.Unpin() if __err := west.WithCurrentInstance(func(__instance *west.Instance) error { - return __instance.Call("wasi:http/types@0.2.0", "[method]fields.has", func() unsafe.Pointer { + return __instance.Call("wasi:http/types@0.2.1", "[method]fields.has", func() unsafe.Pointer { ptr := unsafe.Pointer(&self0) __p.Pin(ptr) return ptr @@ -322,11 +322,11 @@ func wasmimport_FieldsHas(self0 uint32, name0 *uint8, name1 uint32) (result0 uin } //go:linkname wasmimport_FieldsSet github.com/rvolosatovs/west/bindings/wasi/http/types.wasmimport_FieldsSet -func wasmimport_FieldsSet(self0 uint32, name0 *uint8, name1 uint32, value0 *github_com__rvolosatovs__west__bindings__wasi__http__types.FieldValue, value1 uint32, result *github_com__ydnar__wasm___tools___go__cm.Result[github_com__rvolosatovs__west__bindings__wasi__http__types.HeaderError, struct{}, github_com__rvolosatovs__west__bindings__wasi__http__types.HeaderError]) { +func wasmimport_FieldsSet(self0 uint32, name0 *uint8, name1 uint32, value0 *github_com__rvolosatovs__west__bindings__wasi__http__types.FieldValue, value1 uint32, result *github_com__bytecodealliance__wasm___tools___go__cm.Result[github_com__rvolosatovs__west__bindings__wasi__http__types.HeaderError, struct{}, github_com__rvolosatovs__west__bindings__wasi__http__types.HeaderError]) { var __p runtime.Pinner defer __p.Unpin() if __err := west.WithCurrentInstance(func(__instance *west.Instance) error { - return __instance.Call("wasi:http/types@0.2.0", "[method]fields.set", func() unsafe.Pointer { + return __instance.Call("wasi:http/types@0.2.1", "[method]fields.set", func() unsafe.Pointer { ptr := unsafe.Pointer(&self0) __p.Pin(ptr) return ptr @@ -358,11 +358,11 @@ func wasmimport_FieldsSet(self0 uint32, name0 *uint8, name1 uint32, value0 *gith } //go:linkname wasmimport_FutureIncomingResponseGet github.com/rvolosatovs/west/bindings/wasi/http/types.wasmimport_FutureIncomingResponseGet -func wasmimport_FutureIncomingResponseGet(self0 uint32, result *github_com__ydnar__wasm___tools___go__cm.Option[github_com__ydnar__wasm___tools___go__cm.Result[github_com__ydnar__wasm___tools___go__cm.Result[github_com__rvolosatovs__west__bindings__wasi__http__types.ErrorCodeShape, github_com__rvolosatovs__west__bindings__wasi__http__types.IncomingResponse, github_com__rvolosatovs__west__bindings__wasi__http__types.ErrorCode], github_com__ydnar__wasm___tools___go__cm.Result[github_com__rvolosatovs__west__bindings__wasi__http__types.ErrorCodeShape, github_com__rvolosatovs__west__bindings__wasi__http__types.IncomingResponse, github_com__rvolosatovs__west__bindings__wasi__http__types.ErrorCode], struct{}]]) { +func wasmimport_FutureIncomingResponseGet(self0 uint32, result *github_com__bytecodealliance__wasm___tools___go__cm.Option[github_com__bytecodealliance__wasm___tools___go__cm.Result[github_com__bytecodealliance__wasm___tools___go__cm.Result[github_com__rvolosatovs__west__bindings__wasi__http__types.ErrorCodeShape, github_com__rvolosatovs__west__bindings__wasi__http__types.IncomingResponse, github_com__rvolosatovs__west__bindings__wasi__http__types.ErrorCode], github_com__bytecodealliance__wasm___tools___go__cm.Result[github_com__rvolosatovs__west__bindings__wasi__http__types.ErrorCodeShape, github_com__rvolosatovs__west__bindings__wasi__http__types.IncomingResponse, github_com__rvolosatovs__west__bindings__wasi__http__types.ErrorCode], struct{}]]) { var __p runtime.Pinner defer __p.Unpin() if __err := west.WithCurrentInstance(func(__instance *west.Instance) error { - return __instance.Call("wasi:http/types@0.2.0", "[method]future-incoming-response.get", func() unsafe.Pointer { + return __instance.Call("wasi:http/types@0.2.1", "[method]future-incoming-response.get", func() unsafe.Pointer { ptr := unsafe.Pointer(&self0) __p.Pin(ptr) return ptr @@ -382,7 +382,7 @@ func wasmimport_FutureIncomingResponseSubscribe(self0 uint32) (result0 uint32) { var __p runtime.Pinner defer __p.Unpin() if __err := west.WithCurrentInstance(func(__instance *west.Instance) error { - return __instance.Call("wasi:http/types@0.2.0", "[method]future-incoming-response.subscribe", func() unsafe.Pointer { + return __instance.Call("wasi:http/types@0.2.1", "[method]future-incoming-response.subscribe", func() unsafe.Pointer { ptr := unsafe.Pointer(&self0) __p.Pin(ptr) return ptr @@ -398,11 +398,11 @@ func wasmimport_FutureIncomingResponseSubscribe(self0 uint32) (result0 uint32) { } //go:linkname wasmimport_FutureTrailersGet github.com/rvolosatovs/west/bindings/wasi/http/types.wasmimport_FutureTrailersGet -func wasmimport_FutureTrailersGet(self0 uint32, result *github_com__ydnar__wasm___tools___go__cm.Option[github_com__ydnar__wasm___tools___go__cm.Result[github_com__ydnar__wasm___tools___go__cm.Result[github_com__rvolosatovs__west__bindings__wasi__http__types.ErrorCodeShape, github_com__ydnar__wasm___tools___go__cm.Option[github_com__rvolosatovs__west__bindings__wasi__http__types.Fields], github_com__rvolosatovs__west__bindings__wasi__http__types.ErrorCode], github_com__ydnar__wasm___tools___go__cm.Result[github_com__rvolosatovs__west__bindings__wasi__http__types.ErrorCodeShape, github_com__ydnar__wasm___tools___go__cm.Option[github_com__rvolosatovs__west__bindings__wasi__http__types.Fields], github_com__rvolosatovs__west__bindings__wasi__http__types.ErrorCode], struct{}]]) { +func wasmimport_FutureTrailersGet(self0 uint32, result *github_com__bytecodealliance__wasm___tools___go__cm.Option[github_com__bytecodealliance__wasm___tools___go__cm.Result[github_com__bytecodealliance__wasm___tools___go__cm.Result[github_com__rvolosatovs__west__bindings__wasi__http__types.ErrorCodeShape, github_com__bytecodealliance__wasm___tools___go__cm.Option[github_com__rvolosatovs__west__bindings__wasi__http__types.Fields], github_com__rvolosatovs__west__bindings__wasi__http__types.ErrorCode], github_com__bytecodealliance__wasm___tools___go__cm.Result[github_com__rvolosatovs__west__bindings__wasi__http__types.ErrorCodeShape, github_com__bytecodealliance__wasm___tools___go__cm.Option[github_com__rvolosatovs__west__bindings__wasi__http__types.Fields], github_com__rvolosatovs__west__bindings__wasi__http__types.ErrorCode], struct{}]]) { var __p runtime.Pinner defer __p.Unpin() if __err := west.WithCurrentInstance(func(__instance *west.Instance) error { - return __instance.Call("wasi:http/types@0.2.0", "[method]future-trailers.get", func() unsafe.Pointer { + return __instance.Call("wasi:http/types@0.2.1", "[method]future-trailers.get", func() unsafe.Pointer { ptr := unsafe.Pointer(&self0) __p.Pin(ptr) return ptr @@ -422,7 +422,7 @@ func wasmimport_FutureTrailersSubscribe(self0 uint32) (result0 uint32) { var __p runtime.Pinner defer __p.Unpin() if __err := west.WithCurrentInstance(func(__instance *west.Instance) error { - return __instance.Call("wasi:http/types@0.2.0", "[method]future-trailers.subscribe", func() unsafe.Pointer { + return __instance.Call("wasi:http/types@0.2.1", "[method]future-trailers.subscribe", func() unsafe.Pointer { ptr := unsafe.Pointer(&self0) __p.Pin(ptr) return ptr @@ -438,11 +438,11 @@ func wasmimport_FutureTrailersSubscribe(self0 uint32) (result0 uint32) { } //go:linkname wasmimport_IncomingBodyStream github.com/rvolosatovs/west/bindings/wasi/http/types.wasmimport_IncomingBodyStream -func wasmimport_IncomingBodyStream(self0 uint32, result *github_com__ydnar__wasm___tools___go__cm.Result[github_com__rvolosatovs__west__bindings__wasi__io__streams.InputStream, github_com__rvolosatovs__west__bindings__wasi__io__streams.InputStream, struct{}]) { +func wasmimport_IncomingBodyStream(self0 uint32, result *github_com__bytecodealliance__wasm___tools___go__cm.Result[github_com__rvolosatovs__west__bindings__wasi__io__streams.InputStream, github_com__rvolosatovs__west__bindings__wasi__io__streams.InputStream, struct{}]) { var __p runtime.Pinner defer __p.Unpin() if __err := west.WithCurrentInstance(func(__instance *west.Instance) error { - return __instance.Call("wasi:http/types@0.2.0", "[method]incoming-body.stream", func() unsafe.Pointer { + return __instance.Call("wasi:http/types@0.2.1", "[method]incoming-body.stream", func() unsafe.Pointer { ptr := unsafe.Pointer(&self0) __p.Pin(ptr) return ptr @@ -458,11 +458,11 @@ func wasmimport_IncomingBodyStream(self0 uint32, result *github_com__ydnar__wasm } //go:linkname wasmimport_IncomingRequestAuthority github.com/rvolosatovs/west/bindings/wasi/http/types.wasmimport_IncomingRequestAuthority -func wasmimport_IncomingRequestAuthority(self0 uint32, result *github_com__ydnar__wasm___tools___go__cm.Option[string]) { +func wasmimport_IncomingRequestAuthority(self0 uint32, result *github_com__bytecodealliance__wasm___tools___go__cm.Option[string]) { var __p runtime.Pinner defer __p.Unpin() if __err := west.WithCurrentInstance(func(__instance *west.Instance) error { - return __instance.Call("wasi:http/types@0.2.0", "[method]incoming-request.authority", func() unsafe.Pointer { + return __instance.Call("wasi:http/types@0.2.1", "[method]incoming-request.authority", func() unsafe.Pointer { ptr := unsafe.Pointer(&self0) __p.Pin(ptr) return ptr @@ -478,11 +478,11 @@ func wasmimport_IncomingRequestAuthority(self0 uint32, result *github_com__ydnar } //go:linkname wasmimport_IncomingRequestConsume github.com/rvolosatovs/west/bindings/wasi/http/types.wasmimport_IncomingRequestConsume -func wasmimport_IncomingRequestConsume(self0 uint32, result *github_com__ydnar__wasm___tools___go__cm.Result[github_com__rvolosatovs__west__bindings__wasi__http__types.IncomingBody, github_com__rvolosatovs__west__bindings__wasi__http__types.IncomingBody, struct{}]) { +func wasmimport_IncomingRequestConsume(self0 uint32, result *github_com__bytecodealliance__wasm___tools___go__cm.Result[github_com__rvolosatovs__west__bindings__wasi__http__types.IncomingBody, github_com__rvolosatovs__west__bindings__wasi__http__types.IncomingBody, struct{}]) { var __p runtime.Pinner defer __p.Unpin() if __err := west.WithCurrentInstance(func(__instance *west.Instance) error { - return __instance.Call("wasi:http/types@0.2.0", "[method]incoming-request.consume", func() unsafe.Pointer { + return __instance.Call("wasi:http/types@0.2.1", "[method]incoming-request.consume", func() unsafe.Pointer { ptr := unsafe.Pointer(&self0) __p.Pin(ptr) return ptr @@ -502,7 +502,7 @@ func wasmimport_IncomingRequestHeaders(self0 uint32) (result0 uint32) { var __p runtime.Pinner defer __p.Unpin() if __err := west.WithCurrentInstance(func(__instance *west.Instance) error { - return __instance.Call("wasi:http/types@0.2.0", "[method]incoming-request.headers", func() unsafe.Pointer { + return __instance.Call("wasi:http/types@0.2.1", "[method]incoming-request.headers", func() unsafe.Pointer { ptr := unsafe.Pointer(&self0) __p.Pin(ptr) return ptr @@ -522,7 +522,7 @@ func wasmimport_IncomingRequestMethod(self0 uint32, result *github_com__rvolosat var __p runtime.Pinner defer __p.Unpin() if __err := west.WithCurrentInstance(func(__instance *west.Instance) error { - return __instance.Call("wasi:http/types@0.2.0", "[method]incoming-request.method", func() unsafe.Pointer { + return __instance.Call("wasi:http/types@0.2.1", "[method]incoming-request.method", func() unsafe.Pointer { ptr := unsafe.Pointer(&self0) __p.Pin(ptr) return ptr @@ -538,11 +538,11 @@ func wasmimport_IncomingRequestMethod(self0 uint32, result *github_com__rvolosat } //go:linkname wasmimport_IncomingRequestPathWithQuery github.com/rvolosatovs/west/bindings/wasi/http/types.wasmimport_IncomingRequestPathWithQuery -func wasmimport_IncomingRequestPathWithQuery(self0 uint32, result *github_com__ydnar__wasm___tools___go__cm.Option[string]) { +func wasmimport_IncomingRequestPathWithQuery(self0 uint32, result *github_com__bytecodealliance__wasm___tools___go__cm.Option[string]) { var __p runtime.Pinner defer __p.Unpin() if __err := west.WithCurrentInstance(func(__instance *west.Instance) error { - return __instance.Call("wasi:http/types@0.2.0", "[method]incoming-request.path-with-query", func() unsafe.Pointer { + return __instance.Call("wasi:http/types@0.2.1", "[method]incoming-request.path-with-query", func() unsafe.Pointer { ptr := unsafe.Pointer(&self0) __p.Pin(ptr) return ptr @@ -558,11 +558,11 @@ func wasmimport_IncomingRequestPathWithQuery(self0 uint32, result *github_com__y } //go:linkname wasmimport_IncomingRequestScheme github.com/rvolosatovs/west/bindings/wasi/http/types.wasmimport_IncomingRequestScheme -func wasmimport_IncomingRequestScheme(self0 uint32, result *github_com__ydnar__wasm___tools___go__cm.Option[github_com__rvolosatovs__west__bindings__wasi__http__types.Scheme]) { +func wasmimport_IncomingRequestScheme(self0 uint32, result *github_com__bytecodealliance__wasm___tools___go__cm.Option[github_com__rvolosatovs__west__bindings__wasi__http__types.Scheme]) { var __p runtime.Pinner defer __p.Unpin() if __err := west.WithCurrentInstance(func(__instance *west.Instance) error { - return __instance.Call("wasi:http/types@0.2.0", "[method]incoming-request.scheme", func() unsafe.Pointer { + return __instance.Call("wasi:http/types@0.2.1", "[method]incoming-request.scheme", func() unsafe.Pointer { ptr := unsafe.Pointer(&self0) __p.Pin(ptr) return ptr @@ -578,11 +578,11 @@ func wasmimport_IncomingRequestScheme(self0 uint32, result *github_com__ydnar__w } //go:linkname wasmimport_IncomingResponseConsume github.com/rvolosatovs/west/bindings/wasi/http/types.wasmimport_IncomingResponseConsume -func wasmimport_IncomingResponseConsume(self0 uint32, result *github_com__ydnar__wasm___tools___go__cm.Result[github_com__rvolosatovs__west__bindings__wasi__http__types.IncomingBody, github_com__rvolosatovs__west__bindings__wasi__http__types.IncomingBody, struct{}]) { +func wasmimport_IncomingResponseConsume(self0 uint32, result *github_com__bytecodealliance__wasm___tools___go__cm.Result[github_com__rvolosatovs__west__bindings__wasi__http__types.IncomingBody, github_com__rvolosatovs__west__bindings__wasi__http__types.IncomingBody, struct{}]) { var __p runtime.Pinner defer __p.Unpin() if __err := west.WithCurrentInstance(func(__instance *west.Instance) error { - return __instance.Call("wasi:http/types@0.2.0", "[method]incoming-response.consume", func() unsafe.Pointer { + return __instance.Call("wasi:http/types@0.2.1", "[method]incoming-response.consume", func() unsafe.Pointer { ptr := unsafe.Pointer(&self0) __p.Pin(ptr) return ptr @@ -602,7 +602,7 @@ func wasmimport_IncomingResponseHeaders(self0 uint32) (result0 uint32) { var __p runtime.Pinner defer __p.Unpin() if __err := west.WithCurrentInstance(func(__instance *west.Instance) error { - return __instance.Call("wasi:http/types@0.2.0", "[method]incoming-response.headers", func() unsafe.Pointer { + return __instance.Call("wasi:http/types@0.2.1", "[method]incoming-response.headers", func() unsafe.Pointer { ptr := unsafe.Pointer(&self0) __p.Pin(ptr) return ptr @@ -622,7 +622,7 @@ func wasmimport_IncomingResponseStatus(self0 uint32) (result0 uint32) { var __p runtime.Pinner defer __p.Unpin() if __err := west.WithCurrentInstance(func(__instance *west.Instance) error { - return __instance.Call("wasi:http/types@0.2.0", "[method]incoming-response.status", func() unsafe.Pointer { + return __instance.Call("wasi:http/types@0.2.1", "[method]incoming-response.status", func() unsafe.Pointer { ptr := unsafe.Pointer(&self0) __p.Pin(ptr) return ptr @@ -638,11 +638,11 @@ func wasmimport_IncomingResponseStatus(self0 uint32) (result0 uint32) { } //go:linkname wasmimport_OutgoingBodyWrite github.com/rvolosatovs/west/bindings/wasi/http/types.wasmimport_OutgoingBodyWrite -func wasmimport_OutgoingBodyWrite(self0 uint32, result *github_com__ydnar__wasm___tools___go__cm.Result[github_com__rvolosatovs__west__bindings__wasi__io__streams.OutputStream, github_com__rvolosatovs__west__bindings__wasi__io__streams.OutputStream, struct{}]) { +func wasmimport_OutgoingBodyWrite(self0 uint32, result *github_com__bytecodealliance__wasm___tools___go__cm.Result[github_com__rvolosatovs__west__bindings__wasi__io__streams.OutputStream, github_com__rvolosatovs__west__bindings__wasi__io__streams.OutputStream, struct{}]) { var __p runtime.Pinner defer __p.Unpin() if __err := west.WithCurrentInstance(func(__instance *west.Instance) error { - return __instance.Call("wasi:http/types@0.2.0", "[method]outgoing-body.write", func() unsafe.Pointer { + return __instance.Call("wasi:http/types@0.2.1", "[method]outgoing-body.write", func() unsafe.Pointer { ptr := unsafe.Pointer(&self0) __p.Pin(ptr) return ptr @@ -658,11 +658,11 @@ func wasmimport_OutgoingBodyWrite(self0 uint32, result *github_com__ydnar__wasm_ } //go:linkname wasmimport_OutgoingRequestAuthority github.com/rvolosatovs/west/bindings/wasi/http/types.wasmimport_OutgoingRequestAuthority -func wasmimport_OutgoingRequestAuthority(self0 uint32, result *github_com__ydnar__wasm___tools___go__cm.Option[string]) { +func wasmimport_OutgoingRequestAuthority(self0 uint32, result *github_com__bytecodealliance__wasm___tools___go__cm.Option[string]) { var __p runtime.Pinner defer __p.Unpin() if __err := west.WithCurrentInstance(func(__instance *west.Instance) error { - return __instance.Call("wasi:http/types@0.2.0", "[method]outgoing-request.authority", func() unsafe.Pointer { + return __instance.Call("wasi:http/types@0.2.1", "[method]outgoing-request.authority", func() unsafe.Pointer { ptr := unsafe.Pointer(&self0) __p.Pin(ptr) return ptr @@ -678,11 +678,11 @@ func wasmimport_OutgoingRequestAuthority(self0 uint32, result *github_com__ydnar } //go:linkname wasmimport_OutgoingRequestBody github.com/rvolosatovs/west/bindings/wasi/http/types.wasmimport_OutgoingRequestBody -func wasmimport_OutgoingRequestBody(self0 uint32, result *github_com__ydnar__wasm___tools___go__cm.Result[github_com__rvolosatovs__west__bindings__wasi__http__types.OutgoingBody, github_com__rvolosatovs__west__bindings__wasi__http__types.OutgoingBody, struct{}]) { +func wasmimport_OutgoingRequestBody(self0 uint32, result *github_com__bytecodealliance__wasm___tools___go__cm.Result[github_com__rvolosatovs__west__bindings__wasi__http__types.OutgoingBody, github_com__rvolosatovs__west__bindings__wasi__http__types.OutgoingBody, struct{}]) { var __p runtime.Pinner defer __p.Unpin() if __err := west.WithCurrentInstance(func(__instance *west.Instance) error { - return __instance.Call("wasi:http/types@0.2.0", "[method]outgoing-request.body", func() unsafe.Pointer { + return __instance.Call("wasi:http/types@0.2.1", "[method]outgoing-request.body", func() unsafe.Pointer { ptr := unsafe.Pointer(&self0) __p.Pin(ptr) return ptr @@ -702,7 +702,7 @@ func wasmimport_OutgoingRequestHeaders(self0 uint32) (result0 uint32) { var __p runtime.Pinner defer __p.Unpin() if __err := west.WithCurrentInstance(func(__instance *west.Instance) error { - return __instance.Call("wasi:http/types@0.2.0", "[method]outgoing-request.headers", func() unsafe.Pointer { + return __instance.Call("wasi:http/types@0.2.1", "[method]outgoing-request.headers", func() unsafe.Pointer { ptr := unsafe.Pointer(&self0) __p.Pin(ptr) return ptr @@ -722,7 +722,7 @@ func wasmimport_OutgoingRequestMethod(self0 uint32, result *github_com__rvolosat var __p runtime.Pinner defer __p.Unpin() if __err := west.WithCurrentInstance(func(__instance *west.Instance) error { - return __instance.Call("wasi:http/types@0.2.0", "[method]outgoing-request.method", func() unsafe.Pointer { + return __instance.Call("wasi:http/types@0.2.1", "[method]outgoing-request.method", func() unsafe.Pointer { ptr := unsafe.Pointer(&self0) __p.Pin(ptr) return ptr @@ -738,11 +738,11 @@ func wasmimport_OutgoingRequestMethod(self0 uint32, result *github_com__rvolosat } //go:linkname wasmimport_OutgoingRequestPathWithQuery github.com/rvolosatovs/west/bindings/wasi/http/types.wasmimport_OutgoingRequestPathWithQuery -func wasmimport_OutgoingRequestPathWithQuery(self0 uint32, result *github_com__ydnar__wasm___tools___go__cm.Option[string]) { +func wasmimport_OutgoingRequestPathWithQuery(self0 uint32, result *github_com__bytecodealliance__wasm___tools___go__cm.Option[string]) { var __p runtime.Pinner defer __p.Unpin() if __err := west.WithCurrentInstance(func(__instance *west.Instance) error { - return __instance.Call("wasi:http/types@0.2.0", "[method]outgoing-request.path-with-query", func() unsafe.Pointer { + return __instance.Call("wasi:http/types@0.2.1", "[method]outgoing-request.path-with-query", func() unsafe.Pointer { ptr := unsafe.Pointer(&self0) __p.Pin(ptr) return ptr @@ -758,11 +758,11 @@ func wasmimport_OutgoingRequestPathWithQuery(self0 uint32, result *github_com__y } //go:linkname wasmimport_OutgoingRequestScheme github.com/rvolosatovs/west/bindings/wasi/http/types.wasmimport_OutgoingRequestScheme -func wasmimport_OutgoingRequestScheme(self0 uint32, result *github_com__ydnar__wasm___tools___go__cm.Option[github_com__rvolosatovs__west__bindings__wasi__http__types.Scheme]) { +func wasmimport_OutgoingRequestScheme(self0 uint32, result *github_com__bytecodealliance__wasm___tools___go__cm.Option[github_com__rvolosatovs__west__bindings__wasi__http__types.Scheme]) { var __p runtime.Pinner defer __p.Unpin() if __err := west.WithCurrentInstance(func(__instance *west.Instance) error { - return __instance.Call("wasi:http/types@0.2.0", "[method]outgoing-request.scheme", func() unsafe.Pointer { + return __instance.Call("wasi:http/types@0.2.1", "[method]outgoing-request.scheme", func() unsafe.Pointer { ptr := unsafe.Pointer(&self0) __p.Pin(ptr) return ptr @@ -782,7 +782,7 @@ func wasmimport_OutgoingRequestSetAuthority(self0 uint32, authority0 uint32, aut var __p runtime.Pinner defer __p.Unpin() if __err := west.WithCurrentInstance(func(__instance *west.Instance) error { - return __instance.Call("wasi:http/types@0.2.0", "[method]outgoing-request.set-authority", func() unsafe.Pointer { + return __instance.Call("wasi:http/types@0.2.1", "[method]outgoing-request.set-authority", func() unsafe.Pointer { ptr := unsafe.Pointer(&self0) __p.Pin(ptr) return ptr @@ -814,7 +814,7 @@ func wasmimport_OutgoingRequestSetMethod(self0 uint32, method0 uint32, method1 * var __p runtime.Pinner defer __p.Unpin() if __err := west.WithCurrentInstance(func(__instance *west.Instance) error { - return __instance.Call("wasi:http/types@0.2.0", "[method]outgoing-request.set-method", func() unsafe.Pointer { + return __instance.Call("wasi:http/types@0.2.1", "[method]outgoing-request.set-method", func() unsafe.Pointer { ptr := unsafe.Pointer(&self0) __p.Pin(ptr) return ptr @@ -846,7 +846,7 @@ func wasmimport_OutgoingRequestSetPathWithQuery(self0 uint32, pathWithQuery0 uin var __p runtime.Pinner defer __p.Unpin() if __err := west.WithCurrentInstance(func(__instance *west.Instance) error { - return __instance.Call("wasi:http/types@0.2.0", "[method]outgoing-request.set-path-with-query", func() unsafe.Pointer { + return __instance.Call("wasi:http/types@0.2.1", "[method]outgoing-request.set-path-with-query", func() unsafe.Pointer { ptr := unsafe.Pointer(&self0) __p.Pin(ptr) return ptr @@ -878,7 +878,7 @@ func wasmimport_OutgoingRequestSetScheme(self0 uint32, scheme0 uint32, scheme1 u var __p runtime.Pinner defer __p.Unpin() if __err := west.WithCurrentInstance(func(__instance *west.Instance) error { - return __instance.Call("wasi:http/types@0.2.0", "[method]outgoing-request.set-scheme", func() unsafe.Pointer { + return __instance.Call("wasi:http/types@0.2.1", "[method]outgoing-request.set-scheme", func() unsafe.Pointer { ptr := unsafe.Pointer(&self0) __p.Pin(ptr) return ptr @@ -910,11 +910,11 @@ func wasmimport_OutgoingRequestSetScheme(self0 uint32, scheme0 uint32, scheme1 u } //go:linkname wasmimport_OutgoingResponseBody github.com/rvolosatovs/west/bindings/wasi/http/types.wasmimport_OutgoingResponseBody -func wasmimport_OutgoingResponseBody(self0 uint32, result *github_com__ydnar__wasm___tools___go__cm.Result[github_com__rvolosatovs__west__bindings__wasi__http__types.OutgoingBody, github_com__rvolosatovs__west__bindings__wasi__http__types.OutgoingBody, struct{}]) { +func wasmimport_OutgoingResponseBody(self0 uint32, result *github_com__bytecodealliance__wasm___tools___go__cm.Result[github_com__rvolosatovs__west__bindings__wasi__http__types.OutgoingBody, github_com__rvolosatovs__west__bindings__wasi__http__types.OutgoingBody, struct{}]) { var __p runtime.Pinner defer __p.Unpin() if __err := west.WithCurrentInstance(func(__instance *west.Instance) error { - return __instance.Call("wasi:http/types@0.2.0", "[method]outgoing-response.body", func() unsafe.Pointer { + return __instance.Call("wasi:http/types@0.2.1", "[method]outgoing-response.body", func() unsafe.Pointer { ptr := unsafe.Pointer(&self0) __p.Pin(ptr) return ptr @@ -934,7 +934,7 @@ func wasmimport_OutgoingResponseHeaders(self0 uint32) (result0 uint32) { var __p runtime.Pinner defer __p.Unpin() if __err := west.WithCurrentInstance(func(__instance *west.Instance) error { - return __instance.Call("wasi:http/types@0.2.0", "[method]outgoing-response.headers", func() unsafe.Pointer { + return __instance.Call("wasi:http/types@0.2.1", "[method]outgoing-response.headers", func() unsafe.Pointer { ptr := unsafe.Pointer(&self0) __p.Pin(ptr) return ptr @@ -954,7 +954,7 @@ func wasmimport_OutgoingResponseSetStatusCode(self0 uint32, statusCode0 uint32) var __p runtime.Pinner defer __p.Unpin() if __err := west.WithCurrentInstance(func(__instance *west.Instance) error { - return __instance.Call("wasi:http/types@0.2.0", "[method]outgoing-response.set-status-code", func() unsafe.Pointer { + return __instance.Call("wasi:http/types@0.2.1", "[method]outgoing-response.set-status-code", func() unsafe.Pointer { ptr := unsafe.Pointer(&self0) __p.Pin(ptr) return ptr @@ -978,7 +978,7 @@ func wasmimport_OutgoingResponseStatusCode(self0 uint32) (result0 uint32) { var __p runtime.Pinner defer __p.Unpin() if __err := west.WithCurrentInstance(func(__instance *west.Instance) error { - return __instance.Call("wasi:http/types@0.2.0", "[method]outgoing-response.status-code", func() unsafe.Pointer { + return __instance.Call("wasi:http/types@0.2.1", "[method]outgoing-response.status-code", func() unsafe.Pointer { ptr := unsafe.Pointer(&self0) __p.Pin(ptr) return ptr @@ -994,11 +994,11 @@ func wasmimport_OutgoingResponseStatusCode(self0 uint32) (result0 uint32) { } //go:linkname wasmimport_RequestOptionsBetweenBytesTimeout github.com/rvolosatovs/west/bindings/wasi/http/types.wasmimport_RequestOptionsBetweenBytesTimeout -func wasmimport_RequestOptionsBetweenBytesTimeout(self0 uint32, result *github_com__ydnar__wasm___tools___go__cm.Option[github_com__rvolosatovs__west__bindings__wasi__clocks__monotonic___clock.Duration]) { +func wasmimport_RequestOptionsBetweenBytesTimeout(self0 uint32, result *github_com__bytecodealliance__wasm___tools___go__cm.Option[github_com__rvolosatovs__west__bindings__wasi__clocks__monotonic___clock.Duration]) { var __p runtime.Pinner defer __p.Unpin() if __err := west.WithCurrentInstance(func(__instance *west.Instance) error { - return __instance.Call("wasi:http/types@0.2.0", "[method]request-options.between-bytes-timeout", func() unsafe.Pointer { + return __instance.Call("wasi:http/types@0.2.1", "[method]request-options.between-bytes-timeout", func() unsafe.Pointer { ptr := unsafe.Pointer(&self0) __p.Pin(ptr) return ptr @@ -1014,11 +1014,11 @@ func wasmimport_RequestOptionsBetweenBytesTimeout(self0 uint32, result *github_c } //go:linkname wasmimport_RequestOptionsConnectTimeout github.com/rvolosatovs/west/bindings/wasi/http/types.wasmimport_RequestOptionsConnectTimeout -func wasmimport_RequestOptionsConnectTimeout(self0 uint32, result *github_com__ydnar__wasm___tools___go__cm.Option[github_com__rvolosatovs__west__bindings__wasi__clocks__monotonic___clock.Duration]) { +func wasmimport_RequestOptionsConnectTimeout(self0 uint32, result *github_com__bytecodealliance__wasm___tools___go__cm.Option[github_com__rvolosatovs__west__bindings__wasi__clocks__monotonic___clock.Duration]) { var __p runtime.Pinner defer __p.Unpin() if __err := west.WithCurrentInstance(func(__instance *west.Instance) error { - return __instance.Call("wasi:http/types@0.2.0", "[method]request-options.connect-timeout", func() unsafe.Pointer { + return __instance.Call("wasi:http/types@0.2.1", "[method]request-options.connect-timeout", func() unsafe.Pointer { ptr := unsafe.Pointer(&self0) __p.Pin(ptr) return ptr @@ -1034,11 +1034,11 @@ func wasmimport_RequestOptionsConnectTimeout(self0 uint32, result *github_com__y } //go:linkname wasmimport_RequestOptionsFirstByteTimeout github.com/rvolosatovs/west/bindings/wasi/http/types.wasmimport_RequestOptionsFirstByteTimeout -func wasmimport_RequestOptionsFirstByteTimeout(self0 uint32, result *github_com__ydnar__wasm___tools___go__cm.Option[github_com__rvolosatovs__west__bindings__wasi__clocks__monotonic___clock.Duration]) { +func wasmimport_RequestOptionsFirstByteTimeout(self0 uint32, result *github_com__bytecodealliance__wasm___tools___go__cm.Option[github_com__rvolosatovs__west__bindings__wasi__clocks__monotonic___clock.Duration]) { var __p runtime.Pinner defer __p.Unpin() if __err := west.WithCurrentInstance(func(__instance *west.Instance) error { - return __instance.Call("wasi:http/types@0.2.0", "[method]request-options.first-byte-timeout", func() unsafe.Pointer { + return __instance.Call("wasi:http/types@0.2.1", "[method]request-options.first-byte-timeout", func() unsafe.Pointer { ptr := unsafe.Pointer(&self0) __p.Pin(ptr) return ptr @@ -1058,7 +1058,7 @@ func wasmimport_RequestOptionsSetBetweenBytesTimeout(self0 uint32, duration0 uin var __p runtime.Pinner defer __p.Unpin() if __err := west.WithCurrentInstance(func(__instance *west.Instance) error { - return __instance.Call("wasi:http/types@0.2.0", "[method]request-options.set-between-bytes-timeout", func() unsafe.Pointer { + return __instance.Call("wasi:http/types@0.2.1", "[method]request-options.set-between-bytes-timeout", func() unsafe.Pointer { ptr := unsafe.Pointer(&self0) __p.Pin(ptr) return ptr @@ -1086,7 +1086,7 @@ func wasmimport_RequestOptionsSetConnectTimeout(self0 uint32, duration0 uint32, var __p runtime.Pinner defer __p.Unpin() if __err := west.WithCurrentInstance(func(__instance *west.Instance) error { - return __instance.Call("wasi:http/types@0.2.0", "[method]request-options.set-connect-timeout", func() unsafe.Pointer { + return __instance.Call("wasi:http/types@0.2.1", "[method]request-options.set-connect-timeout", func() unsafe.Pointer { ptr := unsafe.Pointer(&self0) __p.Pin(ptr) return ptr @@ -1114,7 +1114,7 @@ func wasmimport_RequestOptionsSetFirstByteTimeout(self0 uint32, duration0 uint32 var __p runtime.Pinner defer __p.Unpin() if __err := west.WithCurrentInstance(func(__instance *west.Instance) error { - return __instance.Call("wasi:http/types@0.2.0", "[method]request-options.set-first-byte-timeout", func() unsafe.Pointer { + return __instance.Call("wasi:http/types@0.2.1", "[method]request-options.set-first-byte-timeout", func() unsafe.Pointer { ptr := unsafe.Pointer(&self0) __p.Pin(ptr) return ptr @@ -1142,7 +1142,7 @@ func wasmimport_FieldsResourceDrop(self0 uint32) { var __p runtime.Pinner defer __p.Unpin() if __err := west.WithCurrentInstance(func(__instance *west.Instance) error { - return __instance.Call("wasi:http/types@0.2.0", "[resource-drop]fields", func() unsafe.Pointer { + return __instance.Call("wasi:http/types@0.2.1", "[resource-drop]fields", func() unsafe.Pointer { ptr := unsafe.Pointer(&self0) __p.Pin(ptr) return ptr @@ -1158,7 +1158,7 @@ func wasmimport_FutureIncomingResponseResourceDrop(self0 uint32) { var __p runtime.Pinner defer __p.Unpin() if __err := west.WithCurrentInstance(func(__instance *west.Instance) error { - return __instance.Call("wasi:http/types@0.2.0", "[resource-drop]future-incoming-response", func() unsafe.Pointer { + return __instance.Call("wasi:http/types@0.2.1", "[resource-drop]future-incoming-response", func() unsafe.Pointer { ptr := unsafe.Pointer(&self0) __p.Pin(ptr) return ptr @@ -1174,7 +1174,7 @@ func wasmimport_FutureTrailersResourceDrop(self0 uint32) { var __p runtime.Pinner defer __p.Unpin() if __err := west.WithCurrentInstance(func(__instance *west.Instance) error { - return __instance.Call("wasi:http/types@0.2.0", "[resource-drop]future-trailers", func() unsafe.Pointer { + return __instance.Call("wasi:http/types@0.2.1", "[resource-drop]future-trailers", func() unsafe.Pointer { ptr := unsafe.Pointer(&self0) __p.Pin(ptr) return ptr @@ -1190,7 +1190,7 @@ func wasmimport_IncomingBodyResourceDrop(self0 uint32) { var __p runtime.Pinner defer __p.Unpin() if __err := west.WithCurrentInstance(func(__instance *west.Instance) error { - return __instance.Call("wasi:http/types@0.2.0", "[resource-drop]incoming-body", func() unsafe.Pointer { + return __instance.Call("wasi:http/types@0.2.1", "[resource-drop]incoming-body", func() unsafe.Pointer { ptr := unsafe.Pointer(&self0) __p.Pin(ptr) return ptr @@ -1206,7 +1206,7 @@ func wasmimport_IncomingRequestResourceDrop(self0 uint32) { var __p runtime.Pinner defer __p.Unpin() if __err := west.WithCurrentInstance(func(__instance *west.Instance) error { - return __instance.Call("wasi:http/types@0.2.0", "[resource-drop]incoming-request", func() unsafe.Pointer { + return __instance.Call("wasi:http/types@0.2.1", "[resource-drop]incoming-request", func() unsafe.Pointer { ptr := unsafe.Pointer(&self0) __p.Pin(ptr) return ptr @@ -1222,7 +1222,7 @@ func wasmimport_IncomingResponseResourceDrop(self0 uint32) { var __p runtime.Pinner defer __p.Unpin() if __err := west.WithCurrentInstance(func(__instance *west.Instance) error { - return __instance.Call("wasi:http/types@0.2.0", "[resource-drop]incoming-response", func() unsafe.Pointer { + return __instance.Call("wasi:http/types@0.2.1", "[resource-drop]incoming-response", func() unsafe.Pointer { ptr := unsafe.Pointer(&self0) __p.Pin(ptr) return ptr @@ -1238,7 +1238,7 @@ func wasmimport_OutgoingBodyResourceDrop(self0 uint32) { var __p runtime.Pinner defer __p.Unpin() if __err := west.WithCurrentInstance(func(__instance *west.Instance) error { - return __instance.Call("wasi:http/types@0.2.0", "[resource-drop]outgoing-body", func() unsafe.Pointer { + return __instance.Call("wasi:http/types@0.2.1", "[resource-drop]outgoing-body", func() unsafe.Pointer { ptr := unsafe.Pointer(&self0) __p.Pin(ptr) return ptr @@ -1254,7 +1254,7 @@ func wasmimport_OutgoingRequestResourceDrop(self0 uint32) { var __p runtime.Pinner defer __p.Unpin() if __err := west.WithCurrentInstance(func(__instance *west.Instance) error { - return __instance.Call("wasi:http/types@0.2.0", "[resource-drop]outgoing-request", func() unsafe.Pointer { + return __instance.Call("wasi:http/types@0.2.1", "[resource-drop]outgoing-request", func() unsafe.Pointer { ptr := unsafe.Pointer(&self0) __p.Pin(ptr) return ptr @@ -1270,7 +1270,7 @@ func wasmimport_OutgoingResponseResourceDrop(self0 uint32) { var __p runtime.Pinner defer __p.Unpin() if __err := west.WithCurrentInstance(func(__instance *west.Instance) error { - return __instance.Call("wasi:http/types@0.2.0", "[resource-drop]outgoing-response", func() unsafe.Pointer { + return __instance.Call("wasi:http/types@0.2.1", "[resource-drop]outgoing-response", func() unsafe.Pointer { ptr := unsafe.Pointer(&self0) __p.Pin(ptr) return ptr @@ -1286,7 +1286,7 @@ func wasmimport_RequestOptionsResourceDrop(self0 uint32) { var __p runtime.Pinner defer __p.Unpin() if __err := west.WithCurrentInstance(func(__instance *west.Instance) error { - return __instance.Call("wasi:http/types@0.2.0", "[resource-drop]request-options", func() unsafe.Pointer { + return __instance.Call("wasi:http/types@0.2.1", "[resource-drop]request-options", func() unsafe.Pointer { ptr := unsafe.Pointer(&self0) __p.Pin(ptr) return ptr @@ -1302,7 +1302,7 @@ func wasmimport_ResponseOutparamResourceDrop(self0 uint32) { var __p runtime.Pinner defer __p.Unpin() if __err := west.WithCurrentInstance(func(__instance *west.Instance) error { - return __instance.Call("wasi:http/types@0.2.0", "[resource-drop]response-outparam", func() unsafe.Pointer { + return __instance.Call("wasi:http/types@0.2.1", "[resource-drop]response-outparam", func() unsafe.Pointer { ptr := unsafe.Pointer(&self0) __p.Pin(ptr) return ptr @@ -1314,11 +1314,11 @@ func wasmimport_ResponseOutparamResourceDrop(self0 uint32) { } //go:linkname wasmimport_FieldsFromList github.com/rvolosatovs/west/bindings/wasi/http/types.wasmimport_FieldsFromList -func wasmimport_FieldsFromList(entries0 *github_com__ydnar__wasm___tools___go__cm.Tuple[github_com__rvolosatovs__west__bindings__wasi__http__types.FieldKey, github_com__rvolosatovs__west__bindings__wasi__http__types.FieldValue], entries1 uint32, result *github_com__ydnar__wasm___tools___go__cm.Result[github_com__rvolosatovs__west__bindings__wasi__http__types.Fields, github_com__rvolosatovs__west__bindings__wasi__http__types.Fields, github_com__rvolosatovs__west__bindings__wasi__http__types.HeaderError]) { +func wasmimport_FieldsFromList(entries0 *github_com__bytecodealliance__wasm___tools___go__cm.Tuple[github_com__rvolosatovs__west__bindings__wasi__http__types.FieldKey, github_com__rvolosatovs__west__bindings__wasi__http__types.FieldValue], entries1 uint32, result *github_com__bytecodealliance__wasm___tools___go__cm.Result[github_com__rvolosatovs__west__bindings__wasi__http__types.Fields, github_com__rvolosatovs__west__bindings__wasi__http__types.Fields, github_com__rvolosatovs__west__bindings__wasi__http__types.HeaderError]) { var __p runtime.Pinner defer __p.Unpin() if __err := west.WithCurrentInstance(func(__instance *west.Instance) error { - return __instance.Call("wasi:http/types@0.2.0", "[static]fields.from-list", func() unsafe.Pointer { + return __instance.Call("wasi:http/types@0.2.1", "[static]fields.from-list", func() unsafe.Pointer { ptr := unsafe.Pointer(entries0) __p.Pin(ptr) return ptr @@ -1342,7 +1342,7 @@ func wasmimport_IncomingBodyFinish(this0 uint32) (result0 uint32) { var __p runtime.Pinner defer __p.Unpin() if __err := west.WithCurrentInstance(func(__instance *west.Instance) error { - return __instance.Call("wasi:http/types@0.2.0", "[static]incoming-body.finish", func() unsafe.Pointer { + return __instance.Call("wasi:http/types@0.2.1", "[static]incoming-body.finish", func() unsafe.Pointer { ptr := unsafe.Pointer(&this0) __p.Pin(ptr) return ptr @@ -1358,11 +1358,11 @@ func wasmimport_IncomingBodyFinish(this0 uint32) (result0 uint32) { } //go:linkname wasmimport_OutgoingBodyFinish github.com/rvolosatovs/west/bindings/wasi/http/types.wasmimport_OutgoingBodyFinish -func wasmimport_OutgoingBodyFinish(this0 uint32, trailers0 uint32, trailers1 uint32, result *github_com__ydnar__wasm___tools___go__cm.Result[github_com__rvolosatovs__west__bindings__wasi__http__types.ErrorCode, struct{}, github_com__rvolosatovs__west__bindings__wasi__http__types.ErrorCode]) { +func wasmimport_OutgoingBodyFinish(this0 uint32, trailers0 uint32, trailers1 uint32, result *github_com__bytecodealliance__wasm___tools___go__cm.Result[github_com__rvolosatovs__west__bindings__wasi__http__types.ErrorCode, struct{}, github_com__rvolosatovs__west__bindings__wasi__http__types.ErrorCode]) { var __p runtime.Pinner defer __p.Unpin() if __err := west.WithCurrentInstance(func(__instance *west.Instance) error { - return __instance.Call("wasi:http/types@0.2.0", "[static]outgoing-body.finish", func() unsafe.Pointer { + return __instance.Call("wasi:http/types@0.2.1", "[static]outgoing-body.finish", func() unsafe.Pointer { ptr := unsafe.Pointer(&this0) __p.Pin(ptr) return ptr @@ -1390,7 +1390,7 @@ func wasmimport_ResponseOutparamSet(param0 uint32, response0 uint32, response1 u var __p runtime.Pinner defer __p.Unpin() if __err := west.WithCurrentInstance(func(__instance *west.Instance) error { - return __instance.Call("wasi:http/types@0.2.0", "[static]response-outparam.set", func() unsafe.Pointer { + return __instance.Call("wasi:http/types@0.2.1", "[static]response-outparam.set", func() unsafe.Pointer { ptr := unsafe.Pointer(¶m0) __p.Pin(ptr) return ptr @@ -1434,11 +1434,11 @@ func wasmimport_ResponseOutparamSet(param0 uint32, response0 uint32, response1 u } //go:linkname wasmimport_HTTPErrorCode github.com/rvolosatovs/west/bindings/wasi/http/types.wasmimport_HTTPErrorCode -func wasmimport_HTTPErrorCode(err0 uint32, result *github_com__ydnar__wasm___tools___go__cm.Option[github_com__rvolosatovs__west__bindings__wasi__http__types.ErrorCode]) { +func wasmimport_HTTPErrorCode(err0 uint32, result *github_com__bytecodealliance__wasm___tools___go__cm.Option[github_com__rvolosatovs__west__bindings__wasi__http__types.ErrorCode]) { var __p runtime.Pinner defer __p.Unpin() if __err := west.WithCurrentInstance(func(__instance *west.Instance) error { - return __instance.Call("wasi:http/types@0.2.0", "http-error-code", func() unsafe.Pointer { + return __instance.Call("wasi:http/types@0.2.1", "http-error-code", func() unsafe.Pointer { ptr := unsafe.Pointer(&err0) __p.Pin(ptr) return ptr @@ -1458,7 +1458,7 @@ func wasmimport_ErrorToDebugString(self0 uint32, result *string) { var __p runtime.Pinner defer __p.Unpin() if __err := west.WithCurrentInstance(func(__instance *west.Instance) error { - return __instance.Call("wasi:io/error@0.2.0", "[method]error.to-debug-string", func() unsafe.Pointer { + return __instance.Call("wasi:io/error@0.2.1", "[method]error.to-debug-string", func() unsafe.Pointer { ptr := unsafe.Pointer(&self0) __p.Pin(ptr) return ptr @@ -1478,7 +1478,7 @@ func wasmimport_ErrorResourceDrop(self0 uint32) { var __p runtime.Pinner defer __p.Unpin() if __err := west.WithCurrentInstance(func(__instance *west.Instance) error { - return __instance.Call("wasi:io/error@0.2.0", "[resource-drop]error", func() unsafe.Pointer { + return __instance.Call("wasi:io/error@0.2.1", "[resource-drop]error", func() unsafe.Pointer { ptr := unsafe.Pointer(&self0) __p.Pin(ptr) return ptr @@ -1494,7 +1494,7 @@ func wasmimport_PollableBlock(self0 uint32) { var __p runtime.Pinner defer __p.Unpin() if __err := west.WithCurrentInstance(func(__instance *west.Instance) error { - return __instance.Call("wasi:io/poll@0.2.0", "[method]pollable.block", func() unsafe.Pointer { + return __instance.Call("wasi:io/poll@0.2.1", "[method]pollable.block", func() unsafe.Pointer { ptr := unsafe.Pointer(&self0) __p.Pin(ptr) return ptr @@ -1510,7 +1510,7 @@ func wasmimport_PollableReady(self0 uint32) (result0 uint32) { var __p runtime.Pinner defer __p.Unpin() if __err := west.WithCurrentInstance(func(__instance *west.Instance) error { - return __instance.Call("wasi:io/poll@0.2.0", "[method]pollable.ready", func() unsafe.Pointer { + return __instance.Call("wasi:io/poll@0.2.1", "[method]pollable.ready", func() unsafe.Pointer { ptr := unsafe.Pointer(&self0) __p.Pin(ptr) return ptr @@ -1530,7 +1530,7 @@ func wasmimport_PollableResourceDrop(self0 uint32) { var __p runtime.Pinner defer __p.Unpin() if __err := west.WithCurrentInstance(func(__instance *west.Instance) error { - return __instance.Call("wasi:io/poll@0.2.0", "[resource-drop]pollable", func() unsafe.Pointer { + return __instance.Call("wasi:io/poll@0.2.1", "[resource-drop]pollable", func() unsafe.Pointer { ptr := unsafe.Pointer(&self0) __p.Pin(ptr) return ptr @@ -1542,11 +1542,11 @@ func wasmimport_PollableResourceDrop(self0 uint32) { } //go:linkname wasmimport_Poll github.com/rvolosatovs/west/bindings/wasi/io/poll.wasmimport_Poll -func wasmimport_Poll(in0 *github_com__rvolosatovs__west__bindings__wasi__io__poll.Pollable, in1 uint32, result *github_com__ydnar__wasm___tools___go__cm.List[uint32]) { +func wasmimport_Poll(in0 *github_com__rvolosatovs__west__bindings__wasi__io__poll.Pollable, in1 uint32, result *github_com__bytecodealliance__wasm___tools___go__cm.List[uint32]) { var __p runtime.Pinner defer __p.Unpin() if __err := west.WithCurrentInstance(func(__instance *west.Instance) error { - return __instance.Call("wasi:io/poll@0.2.0", "poll", func() unsafe.Pointer { + return __instance.Call("wasi:io/poll@0.2.1", "poll", func() unsafe.Pointer { ptr := unsafe.Pointer(in0) __p.Pin(ptr) return ptr @@ -1566,11 +1566,11 @@ func wasmimport_Poll(in0 *github_com__rvolosatovs__west__bindings__wasi__io__pol } //go:linkname wasmimport_InputStreamBlockingRead github.com/rvolosatovs/west/bindings/wasi/io/streams.wasmimport_InputStreamBlockingRead -func wasmimport_InputStreamBlockingRead(self0 uint32, len0 uint64, result *github_com__ydnar__wasm___tools___go__cm.Result[github_com__ydnar__wasm___tools___go__cm.List[uint8], github_com__ydnar__wasm___tools___go__cm.List[uint8], github_com__rvolosatovs__west__bindings__wasi__io__streams.StreamError]) { +func wasmimport_InputStreamBlockingRead(self0 uint32, len0 uint64, result *github_com__bytecodealliance__wasm___tools___go__cm.Result[github_com__bytecodealliance__wasm___tools___go__cm.List[uint8], github_com__bytecodealliance__wasm___tools___go__cm.List[uint8], github_com__rvolosatovs__west__bindings__wasi__io__streams.StreamError]) { var __p runtime.Pinner defer __p.Unpin() if __err := west.WithCurrentInstance(func(__instance *west.Instance) error { - return __instance.Call("wasi:io/streams@0.2.0", "[method]input-stream.blocking-read", func() unsafe.Pointer { + return __instance.Call("wasi:io/streams@0.2.1", "[method]input-stream.blocking-read", func() unsafe.Pointer { ptr := unsafe.Pointer(&self0) __p.Pin(ptr) return ptr @@ -1590,11 +1590,11 @@ func wasmimport_InputStreamBlockingRead(self0 uint32, len0 uint64, result *githu } //go:linkname wasmimport_InputStreamBlockingSkip github.com/rvolosatovs/west/bindings/wasi/io/streams.wasmimport_InputStreamBlockingSkip -func wasmimport_InputStreamBlockingSkip(self0 uint32, len0 uint64, result *github_com__ydnar__wasm___tools___go__cm.Result[uint64, uint64, github_com__rvolosatovs__west__bindings__wasi__io__streams.StreamError]) { +func wasmimport_InputStreamBlockingSkip(self0 uint32, len0 uint64, result *github_com__bytecodealliance__wasm___tools___go__cm.Result[uint64, uint64, github_com__rvolosatovs__west__bindings__wasi__io__streams.StreamError]) { var __p runtime.Pinner defer __p.Unpin() if __err := west.WithCurrentInstance(func(__instance *west.Instance) error { - return __instance.Call("wasi:io/streams@0.2.0", "[method]input-stream.blocking-skip", func() unsafe.Pointer { + return __instance.Call("wasi:io/streams@0.2.1", "[method]input-stream.blocking-skip", func() unsafe.Pointer { ptr := unsafe.Pointer(&self0) __p.Pin(ptr) return ptr @@ -1614,11 +1614,11 @@ func wasmimport_InputStreamBlockingSkip(self0 uint32, len0 uint64, result *githu } //go:linkname wasmimport_InputStreamRead github.com/rvolosatovs/west/bindings/wasi/io/streams.wasmimport_InputStreamRead -func wasmimport_InputStreamRead(self0 uint32, len0 uint64, result *github_com__ydnar__wasm___tools___go__cm.Result[github_com__ydnar__wasm___tools___go__cm.List[uint8], github_com__ydnar__wasm___tools___go__cm.List[uint8], github_com__rvolosatovs__west__bindings__wasi__io__streams.StreamError]) { +func wasmimport_InputStreamRead(self0 uint32, len0 uint64, result *github_com__bytecodealliance__wasm___tools___go__cm.Result[github_com__bytecodealliance__wasm___tools___go__cm.List[uint8], github_com__bytecodealliance__wasm___tools___go__cm.List[uint8], github_com__rvolosatovs__west__bindings__wasi__io__streams.StreamError]) { var __p runtime.Pinner defer __p.Unpin() if __err := west.WithCurrentInstance(func(__instance *west.Instance) error { - return __instance.Call("wasi:io/streams@0.2.0", "[method]input-stream.read", func() unsafe.Pointer { + return __instance.Call("wasi:io/streams@0.2.1", "[method]input-stream.read", func() unsafe.Pointer { ptr := unsafe.Pointer(&self0) __p.Pin(ptr) return ptr @@ -1638,11 +1638,11 @@ func wasmimport_InputStreamRead(self0 uint32, len0 uint64, result *github_com__y } //go:linkname wasmimport_InputStreamSkip github.com/rvolosatovs/west/bindings/wasi/io/streams.wasmimport_InputStreamSkip -func wasmimport_InputStreamSkip(self0 uint32, len0 uint64, result *github_com__ydnar__wasm___tools___go__cm.Result[uint64, uint64, github_com__rvolosatovs__west__bindings__wasi__io__streams.StreamError]) { +func wasmimport_InputStreamSkip(self0 uint32, len0 uint64, result *github_com__bytecodealliance__wasm___tools___go__cm.Result[uint64, uint64, github_com__rvolosatovs__west__bindings__wasi__io__streams.StreamError]) { var __p runtime.Pinner defer __p.Unpin() if __err := west.WithCurrentInstance(func(__instance *west.Instance) error { - return __instance.Call("wasi:io/streams@0.2.0", "[method]input-stream.skip", func() unsafe.Pointer { + return __instance.Call("wasi:io/streams@0.2.1", "[method]input-stream.skip", func() unsafe.Pointer { ptr := unsafe.Pointer(&self0) __p.Pin(ptr) return ptr @@ -1666,7 +1666,7 @@ func wasmimport_InputStreamSubscribe(self0 uint32) (result0 uint32) { var __p runtime.Pinner defer __p.Unpin() if __err := west.WithCurrentInstance(func(__instance *west.Instance) error { - return __instance.Call("wasi:io/streams@0.2.0", "[method]input-stream.subscribe", func() unsafe.Pointer { + return __instance.Call("wasi:io/streams@0.2.1", "[method]input-stream.subscribe", func() unsafe.Pointer { ptr := unsafe.Pointer(&self0) __p.Pin(ptr) return ptr @@ -1682,11 +1682,11 @@ func wasmimport_InputStreamSubscribe(self0 uint32) (result0 uint32) { } //go:linkname wasmimport_OutputStreamBlockingFlush github.com/rvolosatovs/west/bindings/wasi/io/streams.wasmimport_OutputStreamBlockingFlush -func wasmimport_OutputStreamBlockingFlush(self0 uint32, result *github_com__ydnar__wasm___tools___go__cm.Result[github_com__rvolosatovs__west__bindings__wasi__io__streams.StreamError, struct{}, github_com__rvolosatovs__west__bindings__wasi__io__streams.StreamError]) { +func wasmimport_OutputStreamBlockingFlush(self0 uint32, result *github_com__bytecodealliance__wasm___tools___go__cm.Result[github_com__rvolosatovs__west__bindings__wasi__io__streams.StreamError, struct{}, github_com__rvolosatovs__west__bindings__wasi__io__streams.StreamError]) { var __p runtime.Pinner defer __p.Unpin() if __err := west.WithCurrentInstance(func(__instance *west.Instance) error { - return __instance.Call("wasi:io/streams@0.2.0", "[method]output-stream.blocking-flush", func() unsafe.Pointer { + return __instance.Call("wasi:io/streams@0.2.1", "[method]output-stream.blocking-flush", func() unsafe.Pointer { ptr := unsafe.Pointer(&self0) __p.Pin(ptr) return ptr @@ -1702,11 +1702,11 @@ func wasmimport_OutputStreamBlockingFlush(self0 uint32, result *github_com__ydna } //go:linkname wasmimport_OutputStreamBlockingSplice github.com/rvolosatovs/west/bindings/wasi/io/streams.wasmimport_OutputStreamBlockingSplice -func wasmimport_OutputStreamBlockingSplice(self0 uint32, src0 uint32, len0 uint64, result *github_com__ydnar__wasm___tools___go__cm.Result[uint64, uint64, github_com__rvolosatovs__west__bindings__wasi__io__streams.StreamError]) { +func wasmimport_OutputStreamBlockingSplice(self0 uint32, src0 uint32, len0 uint64, result *github_com__bytecodealliance__wasm___tools___go__cm.Result[uint64, uint64, github_com__rvolosatovs__west__bindings__wasi__io__streams.StreamError]) { var __p runtime.Pinner defer __p.Unpin() if __err := west.WithCurrentInstance(func(__instance *west.Instance) error { - return __instance.Call("wasi:io/streams@0.2.0", "[method]output-stream.blocking-splice", func() unsafe.Pointer { + return __instance.Call("wasi:io/streams@0.2.1", "[method]output-stream.blocking-splice", func() unsafe.Pointer { ptr := unsafe.Pointer(&self0) __p.Pin(ptr) return ptr @@ -1730,11 +1730,11 @@ func wasmimport_OutputStreamBlockingSplice(self0 uint32, src0 uint32, len0 uint6 } //go:linkname wasmimport_OutputStreamBlockingWriteAndFlush github.com/rvolosatovs/west/bindings/wasi/io/streams.wasmimport_OutputStreamBlockingWriteAndFlush -func wasmimport_OutputStreamBlockingWriteAndFlush(self0 uint32, contents0 *uint8, contents1 uint32, result *github_com__ydnar__wasm___tools___go__cm.Result[github_com__rvolosatovs__west__bindings__wasi__io__streams.StreamError, struct{}, github_com__rvolosatovs__west__bindings__wasi__io__streams.StreamError]) { +func wasmimport_OutputStreamBlockingWriteAndFlush(self0 uint32, contents0 *uint8, contents1 uint32, result *github_com__bytecodealliance__wasm___tools___go__cm.Result[github_com__rvolosatovs__west__bindings__wasi__io__streams.StreamError, struct{}, github_com__rvolosatovs__west__bindings__wasi__io__streams.StreamError]) { var __p runtime.Pinner defer __p.Unpin() if __err := west.WithCurrentInstance(func(__instance *west.Instance) error { - return __instance.Call("wasi:io/streams@0.2.0", "[method]output-stream.blocking-write-and-flush", func() unsafe.Pointer { + return __instance.Call("wasi:io/streams@0.2.1", "[method]output-stream.blocking-write-and-flush", func() unsafe.Pointer { ptr := unsafe.Pointer(&self0) __p.Pin(ptr) return ptr @@ -1758,11 +1758,11 @@ func wasmimport_OutputStreamBlockingWriteAndFlush(self0 uint32, contents0 *uint8 } //go:linkname wasmimport_OutputStreamBlockingWriteZeroesAndFlush github.com/rvolosatovs/west/bindings/wasi/io/streams.wasmimport_OutputStreamBlockingWriteZeroesAndFlush -func wasmimport_OutputStreamBlockingWriteZeroesAndFlush(self0 uint32, len0 uint64, result *github_com__ydnar__wasm___tools___go__cm.Result[github_com__rvolosatovs__west__bindings__wasi__io__streams.StreamError, struct{}, github_com__rvolosatovs__west__bindings__wasi__io__streams.StreamError]) { +func wasmimport_OutputStreamBlockingWriteZeroesAndFlush(self0 uint32, len0 uint64, result *github_com__bytecodealliance__wasm___tools___go__cm.Result[github_com__rvolosatovs__west__bindings__wasi__io__streams.StreamError, struct{}, github_com__rvolosatovs__west__bindings__wasi__io__streams.StreamError]) { var __p runtime.Pinner defer __p.Unpin() if __err := west.WithCurrentInstance(func(__instance *west.Instance) error { - return __instance.Call("wasi:io/streams@0.2.0", "[method]output-stream.blocking-write-zeroes-and-flush", func() unsafe.Pointer { + return __instance.Call("wasi:io/streams@0.2.1", "[method]output-stream.blocking-write-zeroes-and-flush", func() unsafe.Pointer { ptr := unsafe.Pointer(&self0) __p.Pin(ptr) return ptr @@ -1782,11 +1782,11 @@ func wasmimport_OutputStreamBlockingWriteZeroesAndFlush(self0 uint32, len0 uint6 } //go:linkname wasmimport_OutputStreamCheckWrite github.com/rvolosatovs/west/bindings/wasi/io/streams.wasmimport_OutputStreamCheckWrite -func wasmimport_OutputStreamCheckWrite(self0 uint32, result *github_com__ydnar__wasm___tools___go__cm.Result[uint64, uint64, github_com__rvolosatovs__west__bindings__wasi__io__streams.StreamError]) { +func wasmimport_OutputStreamCheckWrite(self0 uint32, result *github_com__bytecodealliance__wasm___tools___go__cm.Result[uint64, uint64, github_com__rvolosatovs__west__bindings__wasi__io__streams.StreamError]) { var __p runtime.Pinner defer __p.Unpin() if __err := west.WithCurrentInstance(func(__instance *west.Instance) error { - return __instance.Call("wasi:io/streams@0.2.0", "[method]output-stream.check-write", func() unsafe.Pointer { + return __instance.Call("wasi:io/streams@0.2.1", "[method]output-stream.check-write", func() unsafe.Pointer { ptr := unsafe.Pointer(&self0) __p.Pin(ptr) return ptr @@ -1802,11 +1802,11 @@ func wasmimport_OutputStreamCheckWrite(self0 uint32, result *github_com__ydnar__ } //go:linkname wasmimport_OutputStreamFlush github.com/rvolosatovs/west/bindings/wasi/io/streams.wasmimport_OutputStreamFlush -func wasmimport_OutputStreamFlush(self0 uint32, result *github_com__ydnar__wasm___tools___go__cm.Result[github_com__rvolosatovs__west__bindings__wasi__io__streams.StreamError, struct{}, github_com__rvolosatovs__west__bindings__wasi__io__streams.StreamError]) { +func wasmimport_OutputStreamFlush(self0 uint32, result *github_com__bytecodealliance__wasm___tools___go__cm.Result[github_com__rvolosatovs__west__bindings__wasi__io__streams.StreamError, struct{}, github_com__rvolosatovs__west__bindings__wasi__io__streams.StreamError]) { var __p runtime.Pinner defer __p.Unpin() if __err := west.WithCurrentInstance(func(__instance *west.Instance) error { - return __instance.Call("wasi:io/streams@0.2.0", "[method]output-stream.flush", func() unsafe.Pointer { + return __instance.Call("wasi:io/streams@0.2.1", "[method]output-stream.flush", func() unsafe.Pointer { ptr := unsafe.Pointer(&self0) __p.Pin(ptr) return ptr @@ -1822,11 +1822,11 @@ func wasmimport_OutputStreamFlush(self0 uint32, result *github_com__ydnar__wasm_ } //go:linkname wasmimport_OutputStreamSplice github.com/rvolosatovs/west/bindings/wasi/io/streams.wasmimport_OutputStreamSplice -func wasmimport_OutputStreamSplice(self0 uint32, src0 uint32, len0 uint64, result *github_com__ydnar__wasm___tools___go__cm.Result[uint64, uint64, github_com__rvolosatovs__west__bindings__wasi__io__streams.StreamError]) { +func wasmimport_OutputStreamSplice(self0 uint32, src0 uint32, len0 uint64, result *github_com__bytecodealliance__wasm___tools___go__cm.Result[uint64, uint64, github_com__rvolosatovs__west__bindings__wasi__io__streams.StreamError]) { var __p runtime.Pinner defer __p.Unpin() if __err := west.WithCurrentInstance(func(__instance *west.Instance) error { - return __instance.Call("wasi:io/streams@0.2.0", "[method]output-stream.splice", func() unsafe.Pointer { + return __instance.Call("wasi:io/streams@0.2.1", "[method]output-stream.splice", func() unsafe.Pointer { ptr := unsafe.Pointer(&self0) __p.Pin(ptr) return ptr @@ -1854,7 +1854,7 @@ func wasmimport_OutputStreamSubscribe(self0 uint32) (result0 uint32) { var __p runtime.Pinner defer __p.Unpin() if __err := west.WithCurrentInstance(func(__instance *west.Instance) error { - return __instance.Call("wasi:io/streams@0.2.0", "[method]output-stream.subscribe", func() unsafe.Pointer { + return __instance.Call("wasi:io/streams@0.2.1", "[method]output-stream.subscribe", func() unsafe.Pointer { ptr := unsafe.Pointer(&self0) __p.Pin(ptr) return ptr @@ -1870,11 +1870,11 @@ func wasmimport_OutputStreamSubscribe(self0 uint32) (result0 uint32) { } //go:linkname wasmimport_OutputStreamWrite github.com/rvolosatovs/west/bindings/wasi/io/streams.wasmimport_OutputStreamWrite -func wasmimport_OutputStreamWrite(self0 uint32, contents0 *uint8, contents1 uint32, result *github_com__ydnar__wasm___tools___go__cm.Result[github_com__rvolosatovs__west__bindings__wasi__io__streams.StreamError, struct{}, github_com__rvolosatovs__west__bindings__wasi__io__streams.StreamError]) { +func wasmimport_OutputStreamWrite(self0 uint32, contents0 *uint8, contents1 uint32, result *github_com__bytecodealliance__wasm___tools___go__cm.Result[github_com__rvolosatovs__west__bindings__wasi__io__streams.StreamError, struct{}, github_com__rvolosatovs__west__bindings__wasi__io__streams.StreamError]) { var __p runtime.Pinner defer __p.Unpin() if __err := west.WithCurrentInstance(func(__instance *west.Instance) error { - return __instance.Call("wasi:io/streams@0.2.0", "[method]output-stream.write", func() unsafe.Pointer { + return __instance.Call("wasi:io/streams@0.2.1", "[method]output-stream.write", func() unsafe.Pointer { ptr := unsafe.Pointer(&self0) __p.Pin(ptr) return ptr @@ -1898,11 +1898,11 @@ func wasmimport_OutputStreamWrite(self0 uint32, contents0 *uint8, contents1 uint } //go:linkname wasmimport_OutputStreamWriteZeroes github.com/rvolosatovs/west/bindings/wasi/io/streams.wasmimport_OutputStreamWriteZeroes -func wasmimport_OutputStreamWriteZeroes(self0 uint32, len0 uint64, result *github_com__ydnar__wasm___tools___go__cm.Result[github_com__rvolosatovs__west__bindings__wasi__io__streams.StreamError, struct{}, github_com__rvolosatovs__west__bindings__wasi__io__streams.StreamError]) { +func wasmimport_OutputStreamWriteZeroes(self0 uint32, len0 uint64, result *github_com__bytecodealliance__wasm___tools___go__cm.Result[github_com__rvolosatovs__west__bindings__wasi__io__streams.StreamError, struct{}, github_com__rvolosatovs__west__bindings__wasi__io__streams.StreamError]) { var __p runtime.Pinner defer __p.Unpin() if __err := west.WithCurrentInstance(func(__instance *west.Instance) error { - return __instance.Call("wasi:io/streams@0.2.0", "[method]output-stream.write-zeroes", func() unsafe.Pointer { + return __instance.Call("wasi:io/streams@0.2.1", "[method]output-stream.write-zeroes", func() unsafe.Pointer { ptr := unsafe.Pointer(&self0) __p.Pin(ptr) return ptr @@ -1926,7 +1926,7 @@ func wasmimport_InputStreamResourceDrop(self0 uint32) { var __p runtime.Pinner defer __p.Unpin() if __err := west.WithCurrentInstance(func(__instance *west.Instance) error { - return __instance.Call("wasi:io/streams@0.2.0", "[resource-drop]input-stream", func() unsafe.Pointer { + return __instance.Call("wasi:io/streams@0.2.1", "[resource-drop]input-stream", func() unsafe.Pointer { ptr := unsafe.Pointer(&self0) __p.Pin(ptr) return ptr @@ -1942,7 +1942,7 @@ func wasmimport_OutputStreamResourceDrop(self0 uint32) { var __p runtime.Pinner defer __p.Unpin() if __err := west.WithCurrentInstance(func(__instance *west.Instance) error { - return __instance.Call("wasi:io/streams@0.2.0", "[resource-drop]output-stream", func() unsafe.Pointer { + return __instance.Call("wasi:io/streams@0.2.1", "[resource-drop]output-stream", func() unsafe.Pointer { ptr := unsafe.Pointer(&self0) __p.Pin(ptr) return ptr @@ -1953,12 +1953,12 @@ func wasmimport_OutputStreamResourceDrop(self0 uint32) { return } -//go:linkname wasmimport_NewIncomingRequest github.com/rvolosatovs/west/bindings/west/test/http-test.wasmimport_NewIncomingRequest +//go:linkname wasmimport_NewIncomingRequest github.com/rvolosatovs/west/bindings/wasiext/http/ext.wasmimport_NewIncomingRequest func wasmimport_NewIncomingRequest(req0 uint32) (result0 uint32) { var __p runtime.Pinner defer __p.Unpin() if __err := west.WithCurrentInstance(func(__instance *west.Instance) error { - return __instance.Call("west:test/http-test@0.1.0", "new-incoming-request", func() unsafe.Pointer { + return __instance.Call("wasiext:http/ext@0.1.0", "new-incoming-request", func() unsafe.Pointer { ptr := unsafe.Pointer(&req0) __p.Pin(ptr) return ptr @@ -1973,12 +1973,12 @@ func wasmimport_NewIncomingRequest(req0 uint32) (result0 uint32) { return } -//go:linkname wasmimport_NewResponseOutparam github.com/rvolosatovs/west/bindings/west/test/http-test.wasmimport_NewResponseOutparam -func wasmimport_NewResponseOutparam(result *github_com__ydnar__wasm___tools___go__cm.Tuple[github_com__rvolosatovs__west__bindings__wasi__http__types.ResponseOutparam, github_com__rvolosatovs__west__bindings__wasi__http__types.FutureIncomingResponse]) { +//go:linkname wasmimport_NewResponseOutparam github.com/rvolosatovs/west/bindings/wasiext/http/ext.wasmimport_NewResponseOutparam +func wasmimport_NewResponseOutparam(result *github_com__bytecodealliance__wasm___tools___go__cm.Tuple[github_com__rvolosatovs__west__bindings__wasi__http__types.ResponseOutparam, github_com__rvolosatovs__west__bindings__wasi__http__types.FutureIncomingResponse]) { var __p runtime.Pinner defer __p.Unpin() if __err := west.WithCurrentInstance(func(__instance *west.Instance) error { - return __instance.Call("west:test/http-test@0.1.0", "new-response-outparam", func() unsafe.Pointer { + return __instance.Call("wasiext:http/ext@0.1.0", "new-response-outparam", func() unsafe.Pointer { ptr := unsafe.Pointer(result) __p.Pin(ptr) return ptr diff --git a/bindings/wasi/cli/environment/environment.wit.go b/bindings/wasi/cli/environment/environment.wit.go index a582bdf..19d95cf 100644 --- a/bindings/wasi/cli/environment/environment.wit.go +++ b/bindings/wasi/cli/environment/environment.wit.go @@ -1,10 +1,10 @@ // Code generated by wit-bindgen-go. DO NOT EDIT. -// Package environment represents the imported interface "wasi:cli/environment@0.2.0". +// Package environment represents the imported interface "wasi:cli/environment@0.2.1". package environment import ( - "github.com/ydnar/wasm-tools-go/cm" + "github.com/bytecodealliance/wasm-tools-go/cm" ) // GetEnvironment represents the imported function "get-environment". @@ -26,7 +26,7 @@ func GetEnvironment() (result cm.List[[2]string]) { return } -//go:wasmimport wasi:cli/environment@0.2.0 get-environment +//go:wasmimport wasi:cli/environment@0.2.1 get-environment //go:noescape func wasmimport_GetEnvironment(result *cm.List[[2]string]) @@ -42,7 +42,7 @@ func GetArguments() (result cm.List[string]) { return } -//go:wasmimport wasi:cli/environment@0.2.0 get-arguments +//go:wasmimport wasi:cli/environment@0.2.1 get-arguments //go:noescape func wasmimport_GetArguments(result *cm.List[string]) @@ -59,6 +59,6 @@ func InitialCWD() (result cm.Option[string]) { return } -//go:wasmimport wasi:cli/environment@0.2.0 initial-cwd +//go:wasmimport wasi:cli/environment@0.2.1 initial-cwd //go:noescape func wasmimport_InitialCWD(result *cm.Option[string]) diff --git a/bindings/wasi/cli/exit/exit.wit.go b/bindings/wasi/cli/exit/exit.wit.go index bf46d1b..7cf9449 100644 --- a/bindings/wasi/cli/exit/exit.wit.go +++ b/bindings/wasi/cli/exit/exit.wit.go @@ -1,10 +1,10 @@ // Code generated by wit-bindgen-go. DO NOT EDIT. -// Package exit represents the imported interface "wasi:cli/exit@0.2.0". +// Package exit represents the imported interface "wasi:cli/exit@0.2.1". package exit import ( - "github.com/ydnar/wasm-tools-go/cm" + "github.com/bytecodealliance/wasm-tools-go/cm" ) // Exit represents the imported function "exit". @@ -20,6 +20,30 @@ func Exit(status cm.BoolResult) { return } -//go:wasmimport wasi:cli/exit@0.2.0 exit +//go:wasmimport wasi:cli/exit@0.2.1 exit //go:noescape func wasmimport_Exit(status0 uint32) + +// ExitWithCode represents the imported function "exit-with-code". +// +// Exit the current instance and any linked instances, reporting the +// specified status code to the host. +// +// The meaning of the code depends on the context, with 0 usually meaning +// "success", and other values indicating various types of failure. +// +// This function does not return; the effect is analogous to a trap, but +// without the connotation that something bad has happened. +// +// exit-with-code: func(status-code: u8) +// +//go:nosplit +func ExitWithCode(statusCode uint8) { + statusCode0 := (uint32)(statusCode) + wasmimport_ExitWithCode((uint32)(statusCode0)) + return +} + +//go:wasmimport wasi:cli/exit@0.2.1 exit-with-code +//go:noescape +func wasmimport_ExitWithCode(statusCode0 uint32) diff --git a/bindings/wasi/cli/imports/imports.wit.go b/bindings/wasi/cli/imports/imports.wit.go index 84b4fd2..17a800d 100644 --- a/bindings/wasi/cli/imports/imports.wit.go +++ b/bindings/wasi/cli/imports/imports.wit.go @@ -1,4 +1,4 @@ // Code generated by wit-bindgen-go. DO NOT EDIT. -// Package imports represents the world "wasi:cli/imports@0.2.0". +// Package imports represents the world "wasi:cli/imports@0.2.1". package imports diff --git a/bindings/wasi/cli/stderr/stderr.wit.go b/bindings/wasi/cli/stderr/stderr.wit.go index da7dee1..c66388a 100644 --- a/bindings/wasi/cli/stderr/stderr.wit.go +++ b/bindings/wasi/cli/stderr/stderr.wit.go @@ -1,11 +1,11 @@ // Code generated by wit-bindgen-go. DO NOT EDIT. -// Package stderr represents the imported interface "wasi:cli/stderr@0.2.0". +// Package stderr represents the imported interface "wasi:cli/stderr@0.2.1". package stderr import ( + "github.com/bytecodealliance/wasm-tools-go/cm" "github.com/rvolosatovs/west/bindings/wasi/io/streams" - "github.com/ydnar/wasm-tools-go/cm" ) // GetStderr represents the imported function "get-stderr". @@ -19,6 +19,6 @@ func GetStderr() (result streams.OutputStream) { return } -//go:wasmimport wasi:cli/stderr@0.2.0 get-stderr +//go:wasmimport wasi:cli/stderr@0.2.1 get-stderr //go:noescape func wasmimport_GetStderr() (result0 uint32) diff --git a/bindings/wasi/cli/stdin/stdin.wit.go b/bindings/wasi/cli/stdin/stdin.wit.go index 6b36f2a..179bc41 100644 --- a/bindings/wasi/cli/stdin/stdin.wit.go +++ b/bindings/wasi/cli/stdin/stdin.wit.go @@ -1,11 +1,11 @@ // Code generated by wit-bindgen-go. DO NOT EDIT. -// Package stdin represents the imported interface "wasi:cli/stdin@0.2.0". +// Package stdin represents the imported interface "wasi:cli/stdin@0.2.1". package stdin import ( + "github.com/bytecodealliance/wasm-tools-go/cm" "github.com/rvolosatovs/west/bindings/wasi/io/streams" - "github.com/ydnar/wasm-tools-go/cm" ) // GetStdin represents the imported function "get-stdin". @@ -19,6 +19,6 @@ func GetStdin() (result streams.InputStream) { return } -//go:wasmimport wasi:cli/stdin@0.2.0 get-stdin +//go:wasmimport wasi:cli/stdin@0.2.1 get-stdin //go:noescape func wasmimport_GetStdin() (result0 uint32) diff --git a/bindings/wasi/cli/stdout/stdout.wit.go b/bindings/wasi/cli/stdout/stdout.wit.go index 139b848..43029bd 100644 --- a/bindings/wasi/cli/stdout/stdout.wit.go +++ b/bindings/wasi/cli/stdout/stdout.wit.go @@ -1,11 +1,11 @@ // Code generated by wit-bindgen-go. DO NOT EDIT. -// Package stdout represents the imported interface "wasi:cli/stdout@0.2.0". +// Package stdout represents the imported interface "wasi:cli/stdout@0.2.1". package stdout import ( + "github.com/bytecodealliance/wasm-tools-go/cm" "github.com/rvolosatovs/west/bindings/wasi/io/streams" - "github.com/ydnar/wasm-tools-go/cm" ) // GetStdout represents the imported function "get-stdout". @@ -19,6 +19,6 @@ func GetStdout() (result streams.OutputStream) { return } -//go:wasmimport wasi:cli/stdout@0.2.0 get-stdout +//go:wasmimport wasi:cli/stdout@0.2.1 get-stdout //go:noescape func wasmimport_GetStdout() (result0 uint32) diff --git a/bindings/wasi/cli/terminal-input/terminal-input.wit.go b/bindings/wasi/cli/terminal-input/terminal-input.wit.go index 9dca7df..42bf805 100644 --- a/bindings/wasi/cli/terminal-input/terminal-input.wit.go +++ b/bindings/wasi/cli/terminal-input/terminal-input.wit.go @@ -1,6 +1,6 @@ // Code generated by wit-bindgen-go. DO NOT EDIT. -// Package terminalinput represents the imported interface "wasi:cli/terminal-input@0.2.0". +// Package terminalinput represents the imported interface "wasi:cli/terminal-input@0.2.1". // // Terminal input. // @@ -10,10 +10,10 @@ package terminalinput import ( - "github.com/ydnar/wasm-tools-go/cm" + "github.com/bytecodealliance/wasm-tools-go/cm" ) -// TerminalInput represents the imported resource "wasi:cli/terminal-input@0.2.0#terminal-input". +// TerminalInput represents the imported resource "wasi:cli/terminal-input@0.2.1#terminal-input". // // The input side of a terminal. // @@ -31,6 +31,6 @@ func (self TerminalInput) ResourceDrop() { return } -//go:wasmimport wasi:cli/terminal-input@0.2.0 [resource-drop]terminal-input +//go:wasmimport wasi:cli/terminal-input@0.2.1 [resource-drop]terminal-input //go:noescape func wasmimport_TerminalInputResourceDrop(self0 uint32) diff --git a/bindings/wasi/cli/terminal-output/terminal-output.wit.go b/bindings/wasi/cli/terminal-output/terminal-output.wit.go index b6ff728..e266abc 100644 --- a/bindings/wasi/cli/terminal-output/terminal-output.wit.go +++ b/bindings/wasi/cli/terminal-output/terminal-output.wit.go @@ -1,6 +1,6 @@ // Code generated by wit-bindgen-go. DO NOT EDIT. -// Package terminaloutput represents the imported interface "wasi:cli/terminal-output@0.2.0". +// Package terminaloutput represents the imported interface "wasi:cli/terminal-output@0.2.1". // // Terminal output. // @@ -10,10 +10,10 @@ package terminaloutput import ( - "github.com/ydnar/wasm-tools-go/cm" + "github.com/bytecodealliance/wasm-tools-go/cm" ) -// TerminalOutput represents the imported resource "wasi:cli/terminal-output@0.2.0#terminal-output". +// TerminalOutput represents the imported resource "wasi:cli/terminal-output@0.2.1#terminal-output". // // The output side of a terminal. // @@ -31,6 +31,6 @@ func (self TerminalOutput) ResourceDrop() { return } -//go:wasmimport wasi:cli/terminal-output@0.2.0 [resource-drop]terminal-output +//go:wasmimport wasi:cli/terminal-output@0.2.1 [resource-drop]terminal-output //go:noescape func wasmimport_TerminalOutputResourceDrop(self0 uint32) diff --git a/bindings/wasi/cli/terminal-stderr/terminal-stderr.wit.go b/bindings/wasi/cli/terminal-stderr/terminal-stderr.wit.go index f5db3e6..89830bd 100644 --- a/bindings/wasi/cli/terminal-stderr/terminal-stderr.wit.go +++ b/bindings/wasi/cli/terminal-stderr/terminal-stderr.wit.go @@ -1,14 +1,14 @@ // Code generated by wit-bindgen-go. DO NOT EDIT. -// Package terminalstderr represents the imported interface "wasi:cli/terminal-stderr@0.2.0". +// Package terminalstderr represents the imported interface "wasi:cli/terminal-stderr@0.2.1". // // An interface providing an optional `terminal-output` for stderr as a // link-time authority. package terminalstderr import ( + "github.com/bytecodealliance/wasm-tools-go/cm" terminaloutput "github.com/rvolosatovs/west/bindings/wasi/cli/terminal-output" - "github.com/ydnar/wasm-tools-go/cm" ) // GetTerminalStderr represents the imported function "get-terminal-stderr". @@ -24,6 +24,6 @@ func GetTerminalStderr() (result cm.Option[terminaloutput.TerminalOutput]) { return } -//go:wasmimport wasi:cli/terminal-stderr@0.2.0 get-terminal-stderr +//go:wasmimport wasi:cli/terminal-stderr@0.2.1 get-terminal-stderr //go:noescape func wasmimport_GetTerminalStderr(result *cm.Option[terminaloutput.TerminalOutput]) diff --git a/bindings/wasi/cli/terminal-stdin/terminal-stdin.wit.go b/bindings/wasi/cli/terminal-stdin/terminal-stdin.wit.go index 607134c..1de4e70 100644 --- a/bindings/wasi/cli/terminal-stdin/terminal-stdin.wit.go +++ b/bindings/wasi/cli/terminal-stdin/terminal-stdin.wit.go @@ -1,14 +1,14 @@ // Code generated by wit-bindgen-go. DO NOT EDIT. -// Package terminalstdin represents the imported interface "wasi:cli/terminal-stdin@0.2.0". +// Package terminalstdin represents the imported interface "wasi:cli/terminal-stdin@0.2.1". // // An interface providing an optional `terminal-input` for stdin as a // link-time authority. package terminalstdin import ( + "github.com/bytecodealliance/wasm-tools-go/cm" terminalinput "github.com/rvolosatovs/west/bindings/wasi/cli/terminal-input" - "github.com/ydnar/wasm-tools-go/cm" ) // GetTerminalStdin represents the imported function "get-terminal-stdin". @@ -24,6 +24,6 @@ func GetTerminalStdin() (result cm.Option[terminalinput.TerminalInput]) { return } -//go:wasmimport wasi:cli/terminal-stdin@0.2.0 get-terminal-stdin +//go:wasmimport wasi:cli/terminal-stdin@0.2.1 get-terminal-stdin //go:noescape func wasmimport_GetTerminalStdin(result *cm.Option[terminalinput.TerminalInput]) diff --git a/bindings/wasi/cli/terminal-stdout/terminal-stdout.wit.go b/bindings/wasi/cli/terminal-stdout/terminal-stdout.wit.go index 88dc70b..d94ee07 100644 --- a/bindings/wasi/cli/terminal-stdout/terminal-stdout.wit.go +++ b/bindings/wasi/cli/terminal-stdout/terminal-stdout.wit.go @@ -1,14 +1,14 @@ // Code generated by wit-bindgen-go. DO NOT EDIT. -// Package terminalstdout represents the imported interface "wasi:cli/terminal-stdout@0.2.0". +// Package terminalstdout represents the imported interface "wasi:cli/terminal-stdout@0.2.1". // // An interface providing an optional `terminal-output` for stdout as a // link-time authority. package terminalstdout import ( + "github.com/bytecodealliance/wasm-tools-go/cm" terminaloutput "github.com/rvolosatovs/west/bindings/wasi/cli/terminal-output" - "github.com/ydnar/wasm-tools-go/cm" ) // GetTerminalStdout represents the imported function "get-terminal-stdout". @@ -24,6 +24,6 @@ func GetTerminalStdout() (result cm.Option[terminaloutput.TerminalOutput]) { return } -//go:wasmimport wasi:cli/terminal-stdout@0.2.0 get-terminal-stdout +//go:wasmimport wasi:cli/terminal-stdout@0.2.1 get-terminal-stdout //go:noescape func wasmimport_GetTerminalStdout(result *cm.Option[terminaloutput.TerminalOutput]) diff --git a/bindings/wasi/clocks/imports/imports.wit.go b/bindings/wasi/clocks/imports/imports.wit.go index a5a5c71..12d9c74 100644 --- a/bindings/wasi/clocks/imports/imports.wit.go +++ b/bindings/wasi/clocks/imports/imports.wit.go @@ -1,4 +1,4 @@ // Code generated by wit-bindgen-go. DO NOT EDIT. -// Package imports represents the world "wasi:clocks/imports@0.2.0". +// Package imports represents the world "wasi:clocks/imports@0.2.1". package imports diff --git a/bindings/wasi/clocks/monotonic-clock/monotonic-clock.wit.go b/bindings/wasi/clocks/monotonic-clock/monotonic-clock.wit.go index 0d55b04..62bbb8a 100644 --- a/bindings/wasi/clocks/monotonic-clock/monotonic-clock.wit.go +++ b/bindings/wasi/clocks/monotonic-clock/monotonic-clock.wit.go @@ -1,6 +1,6 @@ // Code generated by wit-bindgen-go. DO NOT EDIT. -// Package monotonicclock represents the imported interface "wasi:clocks/monotonic-clock@0.2.0". +// Package monotonicclock represents the imported interface "wasi:clocks/monotonic-clock@0.2.1". // // WASI Monotonic Clock is a clock API intended to let users measure elapsed // time. @@ -10,16 +10,14 @@ // // A monotonic clock is a clock which has an unspecified initial value, and // successive reads of the clock will produce non-decreasing values. -// -// It is intended for measuring elapsed time. package monotonicclock import ( + "github.com/bytecodealliance/wasm-tools-go/cm" "github.com/rvolosatovs/west/bindings/wasi/io/poll" - "github.com/ydnar/wasm-tools-go/cm" ) -// Instant represents the u64 "wasi:clocks/monotonic-clock@0.2.0#instant". +// Instant represents the u64 "wasi:clocks/monotonic-clock@0.2.1#instant". // // An instant in time, in nanoseconds. An instant is relative to an // unspecified initial value, and can only be compared to instances from @@ -28,7 +26,7 @@ import ( // type instant = u64 type Instant uint64 -// Duration represents the u64 "wasi:clocks/monotonic-clock@0.2.0#duration". +// Duration represents the u64 "wasi:clocks/monotonic-clock@0.2.1#duration". // // A duration of time, in nanoseconds. // @@ -51,7 +49,7 @@ func Now() (result Instant) { return } -//go:wasmimport wasi:clocks/monotonic-clock@0.2.0 now +//go:wasmimport wasi:clocks/monotonic-clock@0.2.1 now //go:noescape func wasmimport_Now() (result0 uint64) @@ -69,14 +67,14 @@ func Resolution() (result Duration) { return } -//go:wasmimport wasi:clocks/monotonic-clock@0.2.0 resolution +//go:wasmimport wasi:clocks/monotonic-clock@0.2.1 resolution //go:noescape func wasmimport_Resolution() (result0 uint64) // SubscribeInstant represents the imported function "subscribe-instant". // // Create a `pollable` which will resolve once the specified instant -// occured. +// has occurred. // // subscribe-instant: func(when: instant) -> pollable // @@ -88,15 +86,14 @@ func SubscribeInstant(when Instant) (result poll.Pollable) { return } -//go:wasmimport wasi:clocks/monotonic-clock@0.2.0 subscribe-instant +//go:wasmimport wasi:clocks/monotonic-clock@0.2.1 subscribe-instant //go:noescape func wasmimport_SubscribeInstant(when0 uint64) (result0 uint32) // SubscribeDuration represents the imported function "subscribe-duration". // -// Create a `pollable` which will resolve once the given duration has -// elapsed, starting at the time at which this function was called. -// occured. +// Create a `pollable` that will resolve after the specified duration has +// elapsed from the time this function is invoked. // // subscribe-duration: func(when: duration) -> pollable // @@ -108,6 +105,6 @@ func SubscribeDuration(when Duration) (result poll.Pollable) { return } -//go:wasmimport wasi:clocks/monotonic-clock@0.2.0 subscribe-duration +//go:wasmimport wasi:clocks/monotonic-clock@0.2.1 subscribe-duration //go:noescape func wasmimport_SubscribeDuration(when0 uint64) (result0 uint32) diff --git a/bindings/wasi/clocks/timezone/abi.go b/bindings/wasi/clocks/timezone/abi.go new file mode 100644 index 0000000..b6d9139 --- /dev/null +++ b/bindings/wasi/clocks/timezone/abi.go @@ -0,0 +1,13 @@ +// Code generated by wit-bindgen-go. DO NOT EDIT. + +package timezone + +import ( + wallclock "github.com/rvolosatovs/west/bindings/wasi/clocks/wall-clock" +) + +func lower_DateTime(v wallclock.DateTime) (f0 uint64, f1 uint32) { + f0 = (uint64)(v.Seconds) + f1 = (uint32)(v.Nanoseconds) + return +} diff --git a/bindings/west/test/http-test/empty.s b/bindings/wasi/clocks/timezone/empty.s similarity index 100% rename from bindings/west/test/http-test/empty.s rename to bindings/wasi/clocks/timezone/empty.s diff --git a/bindings/wasi/clocks/timezone/timezone.wit.go b/bindings/wasi/clocks/timezone/timezone.wit.go new file mode 100644 index 0000000..0ce6991 --- /dev/null +++ b/bindings/wasi/clocks/timezone/timezone.wit.go @@ -0,0 +1,90 @@ +// Code generated by wit-bindgen-go. DO NOT EDIT. + +// Package timezone represents the imported interface "wasi:clocks/timezone@0.2.1". +package timezone + +import ( + wallclock "github.com/rvolosatovs/west/bindings/wasi/clocks/wall-clock" +) + +// TimezoneDisplay represents the record "wasi:clocks/timezone@0.2.1#timezone-display". +// +// Information useful for displaying the timezone of a specific `datetime`. +// +// This information may vary within a single `timezone` to reflect daylight +// saving time adjustments. +// +// record timezone-display { +// utc-offset: s32, +// name: string, +// in-daylight-saving-time: bool, +// } +type TimezoneDisplay struct { + // The number of seconds difference between UTC time and the local + // time of the timezone. + // + // The returned value will always be less than 86400 which is the + // number of seconds in a day (24*60*60). + // + // In implementations that do not expose an actual time zone, this + // should return 0. + UtcOffset int32 + + // The abbreviated name of the timezone to display to a user. The name + // `UTC` indicates Coordinated Universal Time. Otherwise, this should + // reference local standards for the name of the time zone. + // + // In implementations that do not expose an actual time zone, this + // should be the string `UTC`. + // + // In time zones that do not have an applicable name, a formatted + // representation of the UTC offset may be returned, such as `-04:00`. + Name string + + // Whether daylight saving time is active. + // + // In implementations that do not expose an actual time zone, this + // should return false. + InDaylightSavingTime bool +} + +// Display represents the imported function "display". +// +// Return information needed to display the given `datetime`. This includes +// the UTC offset, the time zone name, and a flag indicating whether +// daylight saving time is active. +// +// If the timezone cannot be determined for the given `datetime`, return a +// `timezone-display` for `UTC` with a `utc-offset` of 0 and no daylight +// saving time. +// +// display: func(when: datetime) -> timezone-display +// +//go:nosplit +func Display(when wallclock.DateTime) (result TimezoneDisplay) { + when0, when1 := lower_DateTime(when) + wasmimport_Display((uint64)(when0), (uint32)(when1), &result) + return +} + +//go:wasmimport wasi:clocks/timezone@0.2.1 display +//go:noescape +func wasmimport_Display(when0 uint64, when1 uint32, result *TimezoneDisplay) + +// UtcOffset represents the imported function "utc-offset". +// +// The same as `display`, but only return the UTC offset. +// +// utc-offset: func(when: datetime) -> s32 +// +//go:nosplit +func UtcOffset(when wallclock.DateTime) (result int32) { + when0, when1 := lower_DateTime(when) + result0 := wasmimport_UtcOffset((uint64)(when0), (uint32)(when1)) + result = (int32)((uint32)(result0)) + return +} + +//go:wasmimport wasi:clocks/timezone@0.2.1 utc-offset +//go:noescape +func wasmimport_UtcOffset(when0 uint64, when1 uint32) (result0 uint32) diff --git a/bindings/wasi/clocks/wall-clock/wall-clock.wit.go b/bindings/wasi/clocks/wall-clock/wall-clock.wit.go index a59a313..20dd2bb 100644 --- a/bindings/wasi/clocks/wall-clock/wall-clock.wit.go +++ b/bindings/wasi/clocks/wall-clock/wall-clock.wit.go @@ -1,6 +1,6 @@ // Code generated by wit-bindgen-go. DO NOT EDIT. -// Package wallclock represents the imported interface "wasi:clocks/wall-clock@0.2.0". +// Package wallclock represents the imported interface "wasi:clocks/wall-clock@0.2.1". // // WASI Wall Clock is a clock API intended to let users query the current // time. The name "wall" makes an analogy to a "clock on the wall", which @@ -18,7 +18,7 @@ // It is intended for reporting the current date and time for humans. package wallclock -// DateTime represents the record "wasi:clocks/wall-clock@0.2.0#datetime". +// DateTime represents the record "wasi:clocks/wall-clock@0.2.1#datetime". // // A time and date in seconds plus nanoseconds. // @@ -55,7 +55,7 @@ func Now() (result DateTime) { return } -//go:wasmimport wasi:clocks/wall-clock@0.2.0 now +//go:wasmimport wasi:clocks/wall-clock@0.2.1 now //go:noescape func wasmimport_Now(result *DateTime) @@ -73,6 +73,6 @@ func Resolution() (result DateTime) { return } -//go:wasmimport wasi:clocks/wall-clock@0.2.0 resolution +//go:wasmimport wasi:clocks/wall-clock@0.2.1 resolution //go:noescape func wasmimport_Resolution(result *DateTime) diff --git a/bindings/wasi/filesystem/imports/imports.wit.go b/bindings/wasi/filesystem/imports/imports.wit.go index f39bdfc..3f63022 100644 --- a/bindings/wasi/filesystem/imports/imports.wit.go +++ b/bindings/wasi/filesystem/imports/imports.wit.go @@ -1,4 +1,4 @@ // Code generated by wit-bindgen-go. DO NOT EDIT. -// Package imports represents the world "wasi:filesystem/imports@0.2.0". +// Package imports represents the world "wasi:filesystem/imports@0.2.1". package imports diff --git a/bindings/wasi/filesystem/preopens/preopens.wit.go b/bindings/wasi/filesystem/preopens/preopens.wit.go index d46fb92..b1874e5 100644 --- a/bindings/wasi/filesystem/preopens/preopens.wit.go +++ b/bindings/wasi/filesystem/preopens/preopens.wit.go @@ -1,11 +1,11 @@ // Code generated by wit-bindgen-go. DO NOT EDIT. -// Package preopens represents the imported interface "wasi:filesystem/preopens@0.2.0". +// Package preopens represents the imported interface "wasi:filesystem/preopens@0.2.1". package preopens import ( + "github.com/bytecodealliance/wasm-tools-go/cm" "github.com/rvolosatovs/west/bindings/wasi/filesystem/types" - "github.com/ydnar/wasm-tools-go/cm" ) // GetDirectories represents the imported function "get-directories". @@ -20,6 +20,6 @@ func GetDirectories() (result cm.List[cm.Tuple[types.Descriptor, string]]) { return } -//go:wasmimport wasi:filesystem/preopens@0.2.0 get-directories +//go:wasmimport wasi:filesystem/preopens@0.2.1 get-directories //go:noescape func wasmimport_GetDirectories(result *cm.List[cm.Tuple[types.Descriptor, string]]) diff --git a/bindings/wasi/filesystem/types/abi.go b/bindings/wasi/filesystem/types/abi.go index 7379909..9822f10 100644 --- a/bindings/wasi/filesystem/types/abi.go +++ b/bindings/wasi/filesystem/types/abi.go @@ -3,8 +3,8 @@ package types import ( + "github.com/bytecodealliance/wasm-tools-go/cm" wallclock "github.com/rvolosatovs/west/bindings/wasi/clocks/wall-clock" - "github.com/ydnar/wasm-tools-go/cm" "unsafe" ) diff --git a/bindings/wasi/filesystem/types/types.wit.go b/bindings/wasi/filesystem/types/types.wit.go index 4777e30..4714a0e 100644 --- a/bindings/wasi/filesystem/types/types.wit.go +++ b/bindings/wasi/filesystem/types/types.wit.go @@ -1,6 +1,6 @@ // Code generated by wit-bindgen-go. DO NOT EDIT. -// Package types represents the imported interface "wasi:filesystem/types@0.2.0". +// Package types represents the imported interface "wasi:filesystem/types@0.2.1". // // WASI filesystem is a filesystem API primarily intended to let users run WASI // programs that access their files on their existing filesystems, without @@ -29,20 +29,20 @@ package types import ( + "github.com/bytecodealliance/wasm-tools-go/cm" wallclock "github.com/rvolosatovs/west/bindings/wasi/clocks/wall-clock" ioerror "github.com/rvolosatovs/west/bindings/wasi/io/error" "github.com/rvolosatovs/west/bindings/wasi/io/streams" - "github.com/ydnar/wasm-tools-go/cm" ) -// FileSize represents the u64 "wasi:filesystem/types@0.2.0#filesize". +// FileSize represents the u64 "wasi:filesystem/types@0.2.1#filesize". // // File size or length of a region within a file. // // type filesize = u64 type FileSize uint64 -// DescriptorType represents the enum "wasi:filesystem/types@0.2.0#descriptor-type". +// DescriptorType represents the enum "wasi:filesystem/types@0.2.1#descriptor-type". // // The type of a filesystem object referenced by a descriptor. // @@ -103,7 +103,7 @@ func (e DescriptorType) String() string { return stringsDescriptorType[e] } -// DescriptorFlags represents the flags "wasi:filesystem/types@0.2.0#descriptor-flags". +// DescriptorFlags represents the flags "wasi:filesystem/types@0.2.1#descriptor-flags". // // Descriptor flags. // @@ -144,7 +144,7 @@ const ( // requirement. DescriptorFlagsDataIntegritySync - // Requests that reads be performed at the same level of integrety + // Requests that reads be performed at the same level of integrity // requested for writes. This is similar to `O_RSYNC` in POSIX. // // The precise semantics of this operation have not yet been defined for @@ -164,7 +164,7 @@ const ( DescriptorFlagsMutateDirectory ) -// PathFlags represents the flags "wasi:filesystem/types@0.2.0#path-flags". +// PathFlags represents the flags "wasi:filesystem/types@0.2.1#path-flags". // // Flags determining the method of how paths are resolved. // @@ -179,7 +179,7 @@ const ( PathFlagsSymlinkFollow PathFlags = 1 << iota ) -// OpenFlags represents the flags "wasi:filesystem/types@0.2.0#open-flags". +// OpenFlags represents the flags "wasi:filesystem/types@0.2.1#open-flags". // // Open flags used by `open-at`. // @@ -205,14 +205,14 @@ const ( OpenFlagsTruncate ) -// LinkCount represents the u64 "wasi:filesystem/types@0.2.0#link-count". +// LinkCount represents the u64 "wasi:filesystem/types@0.2.1#link-count". // // Number of hard links to an inode. // // type link-count = u64 type LinkCount uint64 -// DescriptorStat represents the record "wasi:filesystem/types@0.2.0#descriptor-stat". +// DescriptorStat represents the record "wasi:filesystem/types@0.2.1#descriptor-stat". // // File attributes. // @@ -256,7 +256,7 @@ type DescriptorStat struct { StatusChangeTimestamp cm.Option[wallclock.DateTime] } -// NewTimestamp represents the variant "wasi:filesystem/types@0.2.0#new-timestamp". +// NewTimestamp represents the variant "wasi:filesystem/types@0.2.1#new-timestamp". // // When setting a timestamp, this gives the value to set it to. // @@ -306,7 +306,7 @@ func (self *NewTimestamp) Timestamp() *wallclock.DateTime { return cm.Case[wallclock.DateTime](self, 2) } -// DirectoryEntry represents the record "wasi:filesystem/types@0.2.0#directory-entry". +// DirectoryEntry represents the record "wasi:filesystem/types@0.2.1#directory-entry". // // A directory entry. // @@ -322,7 +322,7 @@ type DirectoryEntry struct { Name string } -// ErrorCode represents the enum "wasi:filesystem/types@0.2.0#error-code". +// ErrorCode represents the enum "wasi:filesystem/types@0.2.1#error-code". // // Error codes returned by functions, similar to `errno` in POSIX. // Not all of these error codes are returned by the functions provided by this @@ -529,7 +529,7 @@ func (e ErrorCode) String() string { return stringsErrorCode[e] } -// Advice represents the enum "wasi:filesystem/types@0.2.0#advice". +// Advice represents the enum "wasi:filesystem/types@0.2.1#advice". // // File or memory access pattern advisory information. // @@ -583,7 +583,7 @@ func (e Advice) String() string { return stringsAdvice[e] } -// MetadataHashValue represents the record "wasi:filesystem/types@0.2.0#metadata-hash-value". +// MetadataHashValue represents the record "wasi:filesystem/types@0.2.1#metadata-hash-value". // // A 128-bit hash value, split into parts because wasm doesn't have a // 128-bit integer type. @@ -600,7 +600,7 @@ type MetadataHashValue struct { Upper uint64 } -// Descriptor represents the imported resource "wasi:filesystem/types@0.2.0#descriptor". +// Descriptor represents the imported resource "wasi:filesystem/types@0.2.1#descriptor". // // A descriptor is a reference to a filesystem object, which may be a file, // directory, named pipe, special file, or other object on which filesystem @@ -620,7 +620,7 @@ func (self Descriptor) ResourceDrop() { return } -//go:wasmimport wasi:filesystem/types@0.2.0 [resource-drop]descriptor +//go:wasmimport wasi:filesystem/types@0.2.1 [resource-drop]descriptor //go:noescape func wasmimport_DescriptorResourceDrop(self0 uint32) @@ -642,7 +642,7 @@ func (self Descriptor) Advise(offset FileSize, length FileSize, advice Advice) ( return } -//go:wasmimport wasi:filesystem/types@0.2.0 [method]descriptor.advise +//go:wasmimport wasi:filesystem/types@0.2.1 [method]descriptor.advise //go:noescape func wasmimport_DescriptorAdvise(self0 uint32, offset0 uint64, length0 uint64, advice0 uint32, result *cm.Result[ErrorCode, struct{}, ErrorCode]) @@ -664,7 +664,7 @@ func (self Descriptor) AppendViaStream() (result cm.Result[streams.OutputStream, return } -//go:wasmimport wasi:filesystem/types@0.2.0 [method]descriptor.append-via-stream +//go:wasmimport wasi:filesystem/types@0.2.1 [method]descriptor.append-via-stream //go:noescape func wasmimport_DescriptorAppendViaStream(self0 uint32, result *cm.Result[streams.OutputStream, streams.OutputStream, ErrorCode]) @@ -684,7 +684,7 @@ func (self Descriptor) CreateDirectoryAt(path string) (result cm.Result[ErrorCod return } -//go:wasmimport wasi:filesystem/types@0.2.0 [method]descriptor.create-directory-at +//go:wasmimport wasi:filesystem/types@0.2.1 [method]descriptor.create-directory-at //go:noescape func wasmimport_DescriptorCreateDirectoryAt(self0 uint32, path0 *uint8, path1 uint32, result *cm.Result[ErrorCode, struct{}, ErrorCode]) @@ -706,7 +706,7 @@ func (self Descriptor) GetFlags() (result cm.Result[DescriptorFlags, DescriptorF return } -//go:wasmimport wasi:filesystem/types@0.2.0 [method]descriptor.get-flags +//go:wasmimport wasi:filesystem/types@0.2.1 [method]descriptor.get-flags //go:noescape func wasmimport_DescriptorGetFlags(self0 uint32, result *cm.Result[DescriptorFlags, DescriptorFlags, ErrorCode]) @@ -732,7 +732,7 @@ func (self Descriptor) GetType() (result cm.Result[DescriptorType, DescriptorTyp return } -//go:wasmimport wasi:filesystem/types@0.2.0 [method]descriptor.get-type +//go:wasmimport wasi:filesystem/types@0.2.1 [method]descriptor.get-type //go:noescape func wasmimport_DescriptorGetType(self0 uint32, result *cm.Result[DescriptorType, DescriptorType, ErrorCode]) @@ -756,7 +756,7 @@ func (self Descriptor) IsSameObject(other Descriptor) (result bool) { return } -//go:wasmimport wasi:filesystem/types@0.2.0 [method]descriptor.is-same-object +//go:wasmimport wasi:filesystem/types@0.2.1 [method]descriptor.is-same-object //go:noescape func wasmimport_DescriptorIsSameObject(self0 uint32, other0 uint32) (result0 uint32) @@ -780,7 +780,7 @@ func (self Descriptor) LinkAt(oldPathFlags PathFlags, oldPath string, newDescrip return } -//go:wasmimport wasi:filesystem/types@0.2.0 [method]descriptor.link-at +//go:wasmimport wasi:filesystem/types@0.2.1 [method]descriptor.link-at //go:noescape func wasmimport_DescriptorLinkAt(self0 uint32, oldPathFlags0 uint32, oldPath0 *uint8, oldPath1 uint32, newDescriptor0 uint32, newPath0 *uint8, newPath1 uint32, result *cm.Result[ErrorCode, struct{}, ErrorCode]) @@ -815,7 +815,7 @@ func (self Descriptor) MetadataHash() (result cm.Result[MetadataHashValueShape, return } -//go:wasmimport wasi:filesystem/types@0.2.0 [method]descriptor.metadata-hash +//go:wasmimport wasi:filesystem/types@0.2.1 [method]descriptor.metadata-hash //go:noescape func wasmimport_DescriptorMetadataHash(self0 uint32, result *cm.Result[MetadataHashValueShape, MetadataHashValue, ErrorCode]) @@ -838,7 +838,7 @@ func (self Descriptor) MetadataHashAt(pathFlags PathFlags, path string) (result return } -//go:wasmimport wasi:filesystem/types@0.2.0 [method]descriptor.metadata-hash-at +//go:wasmimport wasi:filesystem/types@0.2.1 [method]descriptor.metadata-hash-at //go:noescape func wasmimport_DescriptorMetadataHashAt(self0 uint32, pathFlags0 uint32, path0 *uint8, path1 uint32, result *cm.Result[MetadataHashValueShape, MetadataHashValue, ErrorCode]) @@ -877,7 +877,7 @@ func (self Descriptor) OpenAt(pathFlags PathFlags, path string, openFlags OpenFl return } -//go:wasmimport wasi:filesystem/types@0.2.0 [method]descriptor.open-at +//go:wasmimport wasi:filesystem/types@0.2.1 [method]descriptor.open-at //go:noescape func wasmimport_DescriptorOpenAt(self0 uint32, pathFlags0 uint32, path0 *uint8, path1 uint32, openFlags0 uint32, flags0 uint32, result *cm.Result[Descriptor, Descriptor, ErrorCode]) @@ -907,7 +907,7 @@ func (self Descriptor) Read(length FileSize, offset FileSize) (result cm.Result[ return } -//go:wasmimport wasi:filesystem/types@0.2.0 [method]descriptor.read +//go:wasmimport wasi:filesystem/types@0.2.1 [method]descriptor.read //go:noescape func wasmimport_DescriptorRead(self0 uint32, length0 uint64, offset0 uint64, result *cm.Result[TupleListU8BoolShape, cm.Tuple[cm.List[uint8], bool], ErrorCode]) @@ -932,7 +932,7 @@ func (self Descriptor) ReadDirectory() (result cm.Result[DirectoryEntryStream, D return } -//go:wasmimport wasi:filesystem/types@0.2.0 [method]descriptor.read-directory +//go:wasmimport wasi:filesystem/types@0.2.1 [method]descriptor.read-directory //go:noescape func wasmimport_DescriptorReadDirectory(self0 uint32, result *cm.Result[DirectoryEntryStream, DirectoryEntryStream, ErrorCode]) @@ -957,7 +957,7 @@ func (self Descriptor) ReadViaStream(offset FileSize) (result cm.Result[streams. return } -//go:wasmimport wasi:filesystem/types@0.2.0 [method]descriptor.read-via-stream +//go:wasmimport wasi:filesystem/types@0.2.1 [method]descriptor.read-via-stream //go:noescape func wasmimport_DescriptorReadViaStream(self0 uint32, offset0 uint64, result *cm.Result[streams.InputStream, streams.InputStream, ErrorCode]) @@ -980,7 +980,7 @@ func (self Descriptor) ReadLinkAt(path string) (result cm.Result[string, string, return } -//go:wasmimport wasi:filesystem/types@0.2.0 [method]descriptor.readlink-at +//go:wasmimport wasi:filesystem/types@0.2.1 [method]descriptor.readlink-at //go:noescape func wasmimport_DescriptorReadLinkAt(self0 uint32, path0 *uint8, path1 uint32, result *cm.Result[string, string, ErrorCode]) @@ -1002,7 +1002,7 @@ func (self Descriptor) RemoveDirectoryAt(path string) (result cm.Result[ErrorCod return } -//go:wasmimport wasi:filesystem/types@0.2.0 [method]descriptor.remove-directory-at +//go:wasmimport wasi:filesystem/types@0.2.1 [method]descriptor.remove-directory-at //go:noescape func wasmimport_DescriptorRemoveDirectoryAt(self0 uint32, path0 *uint8, path1 uint32, result *cm.Result[ErrorCode, struct{}, ErrorCode]) @@ -1025,7 +1025,7 @@ func (self Descriptor) RenameAt(oldPath string, newDescriptor Descriptor, newPat return } -//go:wasmimport wasi:filesystem/types@0.2.0 [method]descriptor.rename-at +//go:wasmimport wasi:filesystem/types@0.2.1 [method]descriptor.rename-at //go:noescape func wasmimport_DescriptorRenameAt(self0 uint32, oldPath0 *uint8, oldPath1 uint32, newDescriptor0 uint32, newPath0 *uint8, newPath1 uint32, result *cm.Result[ErrorCode, struct{}, ErrorCode]) @@ -1046,7 +1046,7 @@ func (self Descriptor) SetSize(size FileSize) (result cm.Result[ErrorCode, struc return } -//go:wasmimport wasi:filesystem/types@0.2.0 [method]descriptor.set-size +//go:wasmimport wasi:filesystem/types@0.2.1 [method]descriptor.set-size //go:noescape func wasmimport_DescriptorSetSize(self0 uint32, size0 uint64, result *cm.Result[ErrorCode, struct{}, ErrorCode]) @@ -1070,7 +1070,7 @@ func (self Descriptor) SetTimes(dataAccessTimestamp NewTimestamp, dataModificati return } -//go:wasmimport wasi:filesystem/types@0.2.0 [method]descriptor.set-times +//go:wasmimport wasi:filesystem/types@0.2.1 [method]descriptor.set-times //go:noescape func wasmimport_DescriptorSetTimes(self0 uint32, dataAccessTimestamp0 uint32, dataAccessTimestamp1 uint64, dataAccessTimestamp2 uint32, dataModificationTimestamp0 uint32, dataModificationTimestamp1 uint64, dataModificationTimestamp2 uint32, result *cm.Result[ErrorCode, struct{}, ErrorCode]) @@ -1097,7 +1097,7 @@ func (self Descriptor) SetTimesAt(pathFlags PathFlags, path string, dataAccessTi return } -//go:wasmimport wasi:filesystem/types@0.2.0 [method]descriptor.set-times-at +//go:wasmimport wasi:filesystem/types@0.2.1 [method]descriptor.set-times-at //go:noescape func wasmimport_DescriptorSetTimesAt(self0 uint32, pathFlags0 uint32, path0 *uint8, path1 uint32, dataAccessTimestamp0 uint32, dataAccessTimestamp1 uint64, dataAccessTimestamp2 uint32, dataModificationTimestamp0 uint32, dataModificationTimestamp1 uint64, dataModificationTimestamp2 uint32, result *cm.Result[ErrorCode, struct{}, ErrorCode]) @@ -1122,7 +1122,7 @@ func (self Descriptor) Stat() (result cm.Result[DescriptorStatShape, DescriptorS return } -//go:wasmimport wasi:filesystem/types@0.2.0 [method]descriptor.stat +//go:wasmimport wasi:filesystem/types@0.2.1 [method]descriptor.stat //go:noescape func wasmimport_DescriptorStat(self0 uint32, result *cm.Result[DescriptorStatShape, DescriptorStat, ErrorCode]) @@ -1148,7 +1148,7 @@ func (self Descriptor) StatAt(pathFlags PathFlags, path string) (result cm.Resul return } -//go:wasmimport wasi:filesystem/types@0.2.0 [method]descriptor.stat-at +//go:wasmimport wasi:filesystem/types@0.2.1 [method]descriptor.stat-at //go:noescape func wasmimport_DescriptorStatAt(self0 uint32, pathFlags0 uint32, path0 *uint8, path1 uint32, result *cm.Result[DescriptorStatShape, DescriptorStat, ErrorCode]) @@ -1172,7 +1172,7 @@ func (self Descriptor) SymlinkAt(oldPath string, newPath string) (result cm.Resu return } -//go:wasmimport wasi:filesystem/types@0.2.0 [method]descriptor.symlink-at +//go:wasmimport wasi:filesystem/types@0.2.1 [method]descriptor.symlink-at //go:noescape func wasmimport_DescriptorSymlinkAt(self0 uint32, oldPath0 *uint8, oldPath1 uint32, newPath0 *uint8, newPath1 uint32, result *cm.Result[ErrorCode, struct{}, ErrorCode]) @@ -1194,7 +1194,7 @@ func (self Descriptor) Sync() (result cm.Result[ErrorCode, struct{}, ErrorCode]) return } -//go:wasmimport wasi:filesystem/types@0.2.0 [method]descriptor.sync +//go:wasmimport wasi:filesystem/types@0.2.1 [method]descriptor.sync //go:noescape func wasmimport_DescriptorSync(self0 uint32, result *cm.Result[ErrorCode, struct{}, ErrorCode]) @@ -1216,7 +1216,7 @@ func (self Descriptor) SyncData() (result cm.Result[ErrorCode, struct{}, ErrorCo return } -//go:wasmimport wasi:filesystem/types@0.2.0 [method]descriptor.sync-data +//go:wasmimport wasi:filesystem/types@0.2.1 [method]descriptor.sync-data //go:noescape func wasmimport_DescriptorSyncData(self0 uint32, result *cm.Result[ErrorCode, struct{}, ErrorCode]) @@ -1237,7 +1237,7 @@ func (self Descriptor) UnlinkFileAt(path string) (result cm.Result[ErrorCode, st return } -//go:wasmimport wasi:filesystem/types@0.2.0 [method]descriptor.unlink-file-at +//go:wasmimport wasi:filesystem/types@0.2.1 [method]descriptor.unlink-file-at //go:noescape func wasmimport_DescriptorUnlinkFileAt(self0 uint32, path0 *uint8, path1 uint32, result *cm.Result[ErrorCode, struct{}, ErrorCode]) @@ -1264,7 +1264,7 @@ func (self Descriptor) Write(buffer cm.List[uint8], offset FileSize) (result cm. return } -//go:wasmimport wasi:filesystem/types@0.2.0 [method]descriptor.write +//go:wasmimport wasi:filesystem/types@0.2.1 [method]descriptor.write //go:noescape func wasmimport_DescriptorWrite(self0 uint32, buffer0 *uint8, buffer1 uint32, offset0 uint64, result *cm.Result[uint64, FileSize, ErrorCode]) @@ -1287,11 +1287,11 @@ func (self Descriptor) WriteViaStream(offset FileSize) (result cm.Result[streams return } -//go:wasmimport wasi:filesystem/types@0.2.0 [method]descriptor.write-via-stream +//go:wasmimport wasi:filesystem/types@0.2.1 [method]descriptor.write-via-stream //go:noescape func wasmimport_DescriptorWriteViaStream(self0 uint32, offset0 uint64, result *cm.Result[streams.OutputStream, streams.OutputStream, ErrorCode]) -// DirectoryEntryStream represents the imported resource "wasi:filesystem/types@0.2.0#directory-entry-stream". +// DirectoryEntryStream represents the imported resource "wasi:filesystem/types@0.2.1#directory-entry-stream". // // A stream of directory entries. // @@ -1309,7 +1309,7 @@ func (self DirectoryEntryStream) ResourceDrop() { return } -//go:wasmimport wasi:filesystem/types@0.2.0 [resource-drop]directory-entry-stream +//go:wasmimport wasi:filesystem/types@0.2.1 [resource-drop]directory-entry-stream //go:noescape func wasmimport_DirectoryEntryStreamResourceDrop(self0 uint32) @@ -1326,7 +1326,7 @@ func (self DirectoryEntryStream) ReadDirectoryEntry() (result cm.Result[OptionDi return } -//go:wasmimport wasi:filesystem/types@0.2.0 [method]directory-entry-stream.read-directory-entry +//go:wasmimport wasi:filesystem/types@0.2.1 [method]directory-entry-stream.read-directory-entry //go:noescape func wasmimport_DirectoryEntryStreamReadDirectoryEntry(self0 uint32, result *cm.Result[OptionDirectoryEntryShape, cm.Option[DirectoryEntry], ErrorCode]) @@ -1352,6 +1352,6 @@ func FilesystemErrorCode(err ioerror.Error) (result cm.Option[ErrorCode]) { return } -//go:wasmimport wasi:filesystem/types@0.2.0 filesystem-error-code +//go:wasmimport wasi:filesystem/types@0.2.1 filesystem-error-code //go:noescape func wasmimport_FilesystemErrorCode(err0 uint32, result *cm.Option[ErrorCode]) diff --git a/bindings/wasi/http/imports/imports.wit.go b/bindings/wasi/http/imports/imports.wit.go new file mode 100644 index 0000000..17b22c0 --- /dev/null +++ b/bindings/wasi/http/imports/imports.wit.go @@ -0,0 +1,7 @@ +// Code generated by wit-bindgen-go. DO NOT EDIT. + +// Package imports represents the world "wasi:http/imports@0.2.1". +// +// The `wasi:http/imports` world imports all the APIs for HTTP proxies. +// It is intended to be `include`d in other worlds. +package imports diff --git a/bindings/wasi/http/outgoing-handler/abi.go b/bindings/wasi/http/outgoing-handler/abi.go new file mode 100644 index 0000000..9c55aec --- /dev/null +++ b/bindings/wasi/http/outgoing-handler/abi.go @@ -0,0 +1,24 @@ +// Code generated by wit-bindgen-go. DO NOT EDIT. + +package outgoinghandler + +import ( + "github.com/bytecodealliance/wasm-tools-go/cm" + "github.com/rvolosatovs/west/bindings/wasi/http/types" + "unsafe" +) + +// ErrorCodeShape is used for storage in variant or result types. +type ErrorCodeShape struct { + shape [unsafe.Sizeof(types.ErrorCode{})]byte +} + +func lower_OptionRequestOptions(v cm.Option[types.RequestOptions]) (f0 uint32, f1 uint32) { + some := v.Some() + if some != nil { + f0 = 1 + v1 := cm.Reinterpret[uint32](*some) + f1 = (uint32)(v1) + } + return +} diff --git a/bindings/wasi/http/outgoing-handler/empty.s b/bindings/wasi/http/outgoing-handler/empty.s new file mode 100644 index 0000000..5444f20 --- /dev/null +++ b/bindings/wasi/http/outgoing-handler/empty.s @@ -0,0 +1,3 @@ +// This file exists for testing this package without WebAssembly, +// allowing empty function bodies with a //go:wasmimport directive. +// See https://pkg.go.dev/cmd/compile for more information. diff --git a/bindings/wasi/http/outgoing-handler/outgoing-handler.wit.go b/bindings/wasi/http/outgoing-handler/outgoing-handler.wit.go new file mode 100644 index 0000000..b9a320c --- /dev/null +++ b/bindings/wasi/http/outgoing-handler/outgoing-handler.wit.go @@ -0,0 +1,40 @@ +// Code generated by wit-bindgen-go. DO NOT EDIT. + +// Package outgoinghandler represents the imported interface "wasi:http/outgoing-handler@0.2.1". +// +// This interface defines a handler of outgoing HTTP Requests. It should be +// imported by components which wish to make HTTP Requests. +package outgoinghandler + +import ( + "github.com/bytecodealliance/wasm-tools-go/cm" + "github.com/rvolosatovs/west/bindings/wasi/http/types" +) + +// Handle represents the imported function "handle". +// +// This function is invoked with an outgoing HTTP Request, and it returns +// a resource `future-incoming-response` which represents an HTTP Response +// which may arrive in the future. +// +// The `options` argument accepts optional parameters for the HTTP +// protocol's transport layer. +// +// This function may return an error if the `outgoing-request` is invalid +// or not allowed to be made. Otherwise, protocol errors are reported +// through the `future-incoming-response`. +// +// handle: func(request: outgoing-request, options: option) -> result +// +//go:nosplit +func Handle(request types.OutgoingRequest, options cm.Option[types.RequestOptions]) (result cm.Result[ErrorCodeShape, types.FutureIncomingResponse, types.ErrorCode]) { + request0 := cm.Reinterpret[uint32](request) + options0, options1 := lower_OptionRequestOptions(options) + wasmimport_Handle((uint32)(request0), (uint32)(options0), (uint32)(options1), &result) + return +} + +//go:wasmimport wasi:http/outgoing-handler@0.2.1 handle +//go:noescape +func wasmimport_Handle(request0 uint32, options0 uint32, options1 uint32, result *cm.Result[ErrorCodeShape, types.FutureIncomingResponse, types.ErrorCode]) diff --git a/bindings/wasi/http/types/abi.go b/bindings/wasi/http/types/abi.go index 522754b..0262981 100644 --- a/bindings/wasi/http/types/abi.go +++ b/bindings/wasi/http/types/abi.go @@ -3,8 +3,8 @@ package types import ( + "github.com/bytecodealliance/wasm-tools-go/cm" monotonicclock "github.com/rvolosatovs/west/bindings/wasi/clocks/monotonic-clock" - "github.com/ydnar/wasm-tools-go/cm" "unsafe" ) diff --git a/bindings/wasi/http/types/types.wit.go b/bindings/wasi/http/types/types.wit.go index 27c1352..6ef0503 100644 --- a/bindings/wasi/http/types/types.wit.go +++ b/bindings/wasi/http/types/types.wit.go @@ -1,6 +1,6 @@ // Code generated by wit-bindgen-go. DO NOT EDIT. -// Package types represents the imported interface "wasi:http/types@0.2.0". +// Package types represents the imported interface "wasi:http/types@0.2.1". // // This interface defines all of the types and methods for implementing // HTTP Requests and Responses, both incoming and outgoing, as well as @@ -8,14 +8,14 @@ package types import ( + "github.com/bytecodealliance/wasm-tools-go/cm" monotonicclock "github.com/rvolosatovs/west/bindings/wasi/clocks/monotonic-clock" ioerror "github.com/rvolosatovs/west/bindings/wasi/io/error" "github.com/rvolosatovs/west/bindings/wasi/io/poll" "github.com/rvolosatovs/west/bindings/wasi/io/streams" - "github.com/ydnar/wasm-tools-go/cm" ) -// Method represents the variant "wasi:http/types@0.2.0#method". +// Method represents the variant "wasi:http/types@0.2.1#method". // // This type corresponds to HTTP standard Methods. // @@ -142,7 +142,7 @@ func (self *Method) Other() *string { return cm.Case[string](self, 9) } -// Scheme represents the variant "wasi:http/types@0.2.0#scheme". +// Scheme represents the variant "wasi:http/types@0.2.1#scheme". // // This type corresponds to HTTP standard Related Schemes. // @@ -185,7 +185,7 @@ func (self *Scheme) Other() *string { return cm.Case[string](self, 2) } -// DNSErrorPayload represents the record "wasi:http/types@0.2.0#DNS-error-payload". +// DNSErrorPayload represents the record "wasi:http/types@0.2.1#DNS-error-payload". // // Defines the case payload type for `DNS-error` above: // @@ -198,7 +198,7 @@ type DNSErrorPayload struct { InfoCode cm.Option[uint16] } -// TLSAlertReceivedPayload represents the record "wasi:http/types@0.2.0#TLS-alert-received-payload". +// TLSAlertReceivedPayload represents the record "wasi:http/types@0.2.1#TLS-alert-received-payload". // // Defines the case payload type for `TLS-alert-received` above: // @@ -211,7 +211,7 @@ type TLSAlertReceivedPayload struct { AlertMessage cm.Option[string] } -// FieldSizePayload represents the record "wasi:http/types@0.2.0#field-size-payload". +// FieldSizePayload represents the record "wasi:http/types@0.2.1#field-size-payload". // // Defines the case payload type for `HTTP-response-{header,trailer}-size` above: // @@ -224,7 +224,7 @@ type FieldSizePayload struct { FieldSize cm.Option[uint32] } -// ErrorCode represents the variant "wasi:http/types@0.2.0#error-code". +// ErrorCode represents the variant "wasi:http/types@0.2.1#error-code". // // These cases are inspired by the IANA HTTP Proxy Error Types: // https://www.iana.org/assignments/http-proxy-status/http-proxy-status.xhtml#table-http-proxy-error-types @@ -692,7 +692,7 @@ func (self *ErrorCode) InternalError() *cm.Option[string] { return cm.Case[cm.Option[string]](self, 38) } -// HeaderError represents the variant "wasi:http/types@0.2.0#header-error". +// HeaderError represents the variant "wasi:http/types@0.2.1#header-error". // // This type enumerates the different kinds of errors that may occur when // setting or appending to a `fields` resource. @@ -730,14 +730,14 @@ func (e HeaderError) String() string { return stringsHeaderError[e] } -// FieldKey represents the string "wasi:http/types@0.2.0#field-key". +// FieldKey represents the string "wasi:http/types@0.2.1#field-key". // // Field keys are always strings. // // type field-key = string type FieldKey string -// FieldValue represents the list "wasi:http/types@0.2.0#field-value". +// FieldValue represents the list "wasi:http/types@0.2.1#field-value". // // Field values should always be ASCII strings. However, in // reality, HTTP implementations often have to interpret malformed values, @@ -746,7 +746,7 @@ type FieldKey string // type field-value = list type FieldValue cm.List[uint8] -// Fields represents the imported resource "wasi:http/types@0.2.0#fields". +// Fields represents the imported resource "wasi:http/types@0.2.1#fields". // // This following block defines the `fields` resource which corresponds to // HTTP standard Fields. Fields are a common representation used for both @@ -773,7 +773,7 @@ func (self Fields) ResourceDrop() { return } -//go:wasmimport wasi:http/types@0.2.0 [resource-drop]fields +//go:wasmimport wasi:http/types@0.2.1 [resource-drop]fields //go:noescape func wasmimport_FieldsResourceDrop(self0 uint32) @@ -792,7 +792,7 @@ func NewFields() (result Fields) { return } -//go:wasmimport wasi:http/types@0.2.0 [constructor]fields +//go:wasmimport wasi:http/types@0.2.1 [constructor]fields //go:noescape func wasmimport_NewFields() (result0 uint32) @@ -807,12 +807,10 @@ func wasmimport_NewFields() (result0 uint32) // list with the same key. // // The tuple is a pair of the field key, represented as a string, and -// Value, represented as a list of bytes. In a valid Fields, all keys -// and values are valid UTF-8 strings. However, values are not always -// well-formed, so they are represented as a raw list of bytes. +// Value, represented as a list of bytes. // -// An error result will be returned if any header or value was -// syntactically invalid, or if a header was forbidden. +// An error result will be returned if any `field-key` or `field-value` is +// syntactically invalid, or if a field is forbidden. // // from-list: static func(entries: list>) -> result @@ -824,7 +822,7 @@ func FieldsFromList(entries cm.List[cm.Tuple[FieldKey, FieldValue]]) (result cm. return } -//go:wasmimport wasi:http/types@0.2.0 [static]fields.from-list +//go:wasmimport wasi:http/types@0.2.1 [static]fields.from-list //go:noescape func wasmimport_FieldsFromList(entries0 *cm.Tuple[FieldKey, FieldValue], entries1 uint32, result *cm.Result[Fields, Fields, HeaderError]) @@ -835,6 +833,9 @@ func wasmimport_FieldsFromList(entries0 *cm.Tuple[FieldKey, FieldValue], entries // // Fails with `header-error.immutable` if the `fields` are immutable. // +// Fails with `header-error.invalid-syntax` if the `field-key` or +// `field-value` are syntactically invalid. +// // append: func(name: field-key, value: field-value) -> result<_, header-error> // //go:nosplit @@ -846,13 +847,13 @@ func (self Fields) Append(name FieldKey, value FieldValue) (result cm.Result[Hea return } -//go:wasmimport wasi:http/types@0.2.0 [method]fields.append +//go:wasmimport wasi:http/types@0.2.1 [method]fields.append //go:noescape func wasmimport_FieldsAppend(self0 uint32, name0 *uint8, name1 uint32, value0 *uint8, value1 uint32, result *cm.Result[HeaderError, struct{}, HeaderError]) // Clone represents the imported method "clone". // -// Make a deep copy of the Fields. Equivelant in behavior to calling the +// Make a deep copy of the Fields. Equivalent in behavior to calling the // `fields` constructor on the return value of `entries`. The resulting // `fields` is mutable. // @@ -866,7 +867,7 @@ func (self Fields) Clone() (result Fields) { return } -//go:wasmimport wasi:http/types@0.2.0 [method]fields.clone +//go:wasmimport wasi:http/types@0.2.1 [method]fields.clone //go:noescape func wasmimport_FieldsClone(self0 uint32) (result0 uint32) @@ -877,6 +878,9 @@ func wasmimport_FieldsClone(self0 uint32) (result0 uint32) // // Fails with `header-error.immutable` if the `fields` are immutable. // +// Fails with `header-error.invalid-syntax` if the `field-key` is +// syntactically invalid. +// // delete: func(name: field-key) -> result<_, header-error> // //go:nosplit @@ -887,7 +891,7 @@ func (self Fields) Delete(name FieldKey) (result cm.Result[HeaderError, struct{} return } -//go:wasmimport wasi:http/types@0.2.0 [method]fields.delete +//go:wasmimport wasi:http/types@0.2.1 [method]fields.delete //go:noescape func wasmimport_FieldsDelete(self0 uint32, name0 *uint8, name1 uint32, result *cm.Result[HeaderError, struct{}, HeaderError]) @@ -909,16 +913,16 @@ func (self Fields) Entries() (result cm.List[cm.Tuple[FieldKey, FieldValue]]) { return } -//go:wasmimport wasi:http/types@0.2.0 [method]fields.entries +//go:wasmimport wasi:http/types@0.2.1 [method]fields.entries //go:noescape func wasmimport_FieldsEntries(self0 uint32, result *cm.List[cm.Tuple[FieldKey, FieldValue]]) // Get represents the imported method "get". // // Get all of the values corresponding to a key. If the key is not present -// in this `fields`, an empty list is returned. However, if the key is -// present but empty, this is represented by a list with one or more -// empty field-values present. +// in this `fields` or is syntactically invalid, an empty list is returned. +// However, if the key is present but empty, this is represented by a list +// with one or more empty field-values present. // // get: func(name: field-key) -> list // @@ -930,7 +934,7 @@ func (self Fields) Get(name FieldKey) (result cm.List[FieldValue]) { return } -//go:wasmimport wasi:http/types@0.2.0 [method]fields.get +//go:wasmimport wasi:http/types@0.2.1 [method]fields.get //go:noescape func wasmimport_FieldsGet(self0 uint32, name0 *uint8, name1 uint32, result *cm.List[FieldValue]) @@ -950,7 +954,7 @@ func (self Fields) Has(name FieldKey) (result bool) { return } -//go:wasmimport wasi:http/types@0.2.0 [method]fields.has +//go:wasmimport wasi:http/types@0.2.1 [method]fields.has //go:noescape func wasmimport_FieldsHas(self0 uint32, name0 *uint8, name1 uint32) (result0 uint32) @@ -961,6 +965,9 @@ func wasmimport_FieldsHas(self0 uint32, name0 *uint8, name1 uint32) (result0 uin // // Fails with `header-error.immutable` if the `fields` are immutable. // +// Fails with `header-error.invalid-syntax` if the `field-key` or any of +// the `field-value`s are syntactically invalid. +// // set: func(name: field-key, value: list) -> result<_, header-error> // //go:nosplit @@ -972,11 +979,11 @@ func (self Fields) Set(name FieldKey, value cm.List[FieldValue]) (result cm.Resu return } -//go:wasmimport wasi:http/types@0.2.0 [method]fields.set +//go:wasmimport wasi:http/types@0.2.1 [method]fields.set //go:noescape func wasmimport_FieldsSet(self0 uint32, name0 *uint8, name1 uint32, value0 *FieldValue, value1 uint32, result *cm.Result[HeaderError, struct{}, HeaderError]) -// IncomingRequest represents the imported resource "wasi:http/types@0.2.0#incoming-request". +// IncomingRequest represents the imported resource "wasi:http/types@0.2.1#incoming-request". // // Represents an incoming HTTP Request. // @@ -994,13 +1001,13 @@ func (self IncomingRequest) ResourceDrop() { return } -//go:wasmimport wasi:http/types@0.2.0 [resource-drop]incoming-request +//go:wasmimport wasi:http/types@0.2.1 [resource-drop]incoming-request //go:noescape func wasmimport_IncomingRequestResourceDrop(self0 uint32) // Authority represents the imported method "authority". // -// Returns the authority from the request, if it was present. +// Returns the authority of the Request's target URI, if present. // // authority: func() -> option // @@ -1011,7 +1018,7 @@ func (self IncomingRequest) Authority() (result cm.Option[string]) { return } -//go:wasmimport wasi:http/types@0.2.0 [method]incoming-request.authority +//go:wasmimport wasi:http/types@0.2.1 [method]incoming-request.authority //go:noescape func wasmimport_IncomingRequestAuthority(self0 uint32, result *cm.Option[string]) @@ -1029,7 +1036,7 @@ func (self IncomingRequest) Consume() (result cm.Result[IncomingBody, IncomingBo return } -//go:wasmimport wasi:http/types@0.2.0 [method]incoming-request.consume +//go:wasmimport wasi:http/types@0.2.1 [method]incoming-request.consume //go:noescape func wasmimport_IncomingRequestConsume(self0 uint32, result *cm.Result[IncomingBody, IncomingBody, struct{}]) @@ -1054,7 +1061,7 @@ func (self IncomingRequest) Headers() (result Fields) { return } -//go:wasmimport wasi:http/types@0.2.0 [method]incoming-request.headers +//go:wasmimport wasi:http/types@0.2.1 [method]incoming-request.headers //go:noescape func wasmimport_IncomingRequestHeaders(self0 uint32) (result0 uint32) @@ -1071,7 +1078,7 @@ func (self IncomingRequest) Method() (result Method) { return } -//go:wasmimport wasi:http/types@0.2.0 [method]incoming-request.method +//go:wasmimport wasi:http/types@0.2.1 [method]incoming-request.method //go:noescape func wasmimport_IncomingRequestMethod(self0 uint32, result *Method) @@ -1088,7 +1095,7 @@ func (self IncomingRequest) PathWithQuery() (result cm.Option[string]) { return } -//go:wasmimport wasi:http/types@0.2.0 [method]incoming-request.path-with-query +//go:wasmimport wasi:http/types@0.2.1 [method]incoming-request.path-with-query //go:noescape func wasmimport_IncomingRequestPathWithQuery(self0 uint32, result *cm.Option[string]) @@ -1105,11 +1112,11 @@ func (self IncomingRequest) Scheme() (result cm.Option[Scheme]) { return } -//go:wasmimport wasi:http/types@0.2.0 [method]incoming-request.scheme +//go:wasmimport wasi:http/types@0.2.1 [method]incoming-request.scheme //go:noescape func wasmimport_IncomingRequestScheme(self0 uint32, result *cm.Option[Scheme]) -// OutgoingRequest represents the imported resource "wasi:http/types@0.2.0#outgoing-request". +// OutgoingRequest represents the imported resource "wasi:http/types@0.2.1#outgoing-request". // // Represents an outgoing HTTP Request. // @@ -1127,7 +1134,7 @@ func (self OutgoingRequest) ResourceDrop() { return } -//go:wasmimport wasi:http/types@0.2.0 [resource-drop]outgoing-request +//go:wasmimport wasi:http/types@0.2.1 [resource-drop]outgoing-request //go:noescape func wasmimport_OutgoingRequestResourceDrop(self0 uint32) @@ -1154,14 +1161,14 @@ func NewOutgoingRequest(headers Fields) (result OutgoingRequest) { return } -//go:wasmimport wasi:http/types@0.2.0 [constructor]outgoing-request +//go:wasmimport wasi:http/types@0.2.1 [constructor]outgoing-request //go:noescape func wasmimport_NewOutgoingRequest(headers0 uint32) (result0 uint32) // Authority represents the imported method "authority". // -// Get the HTTP Authority for the Request. A value of `none` may be used -// with Related Schemes which do not require an Authority. The HTTP and +// Get the authority of the Request's target URI. A value of `none` may be used +// with Related Schemes which do not require an authority. The HTTP and // HTTPS schemes always require an authority. // // authority: func() -> option @@ -1173,7 +1180,7 @@ func (self OutgoingRequest) Authority() (result cm.Option[string]) { return } -//go:wasmimport wasi:http/types@0.2.0 [method]outgoing-request.authority +//go:wasmimport wasi:http/types@0.2.1 [method]outgoing-request.authority //go:noescape func wasmimport_OutgoingRequestAuthority(self0 uint32, result *cm.Option[string]) @@ -1195,7 +1202,7 @@ func (self OutgoingRequest) Body() (result cm.Result[OutgoingBody, OutgoingBody, return } -//go:wasmimport wasi:http/types@0.2.0 [method]outgoing-request.body +//go:wasmimport wasi:http/types@0.2.1 [method]outgoing-request.body //go:noescape func wasmimport_OutgoingRequestBody(self0 uint32, result *cm.Result[OutgoingBody, OutgoingBody, struct{}]) @@ -1207,7 +1214,7 @@ func wasmimport_OutgoingRequestBody(self0 uint32, result *cm.Result[OutgoingBody // `delete` operations will fail with `header-error.immutable`. // // This headers resource is a child: it must be dropped before the parent -// `outgoing-request` is dropped, or its ownership is transfered to +// `outgoing-request` is dropped, or its ownership is transferred to // another component by e.g. `outgoing-handler.handle`. // // headers: func() -> headers @@ -1220,7 +1227,7 @@ func (self OutgoingRequest) Headers() (result Fields) { return } -//go:wasmimport wasi:http/types@0.2.0 [method]outgoing-request.headers +//go:wasmimport wasi:http/types@0.2.1 [method]outgoing-request.headers //go:noescape func wasmimport_OutgoingRequestHeaders(self0 uint32) (result0 uint32) @@ -1237,7 +1244,7 @@ func (self OutgoingRequest) Method() (result Method) { return } -//go:wasmimport wasi:http/types@0.2.0 [method]outgoing-request.method +//go:wasmimport wasi:http/types@0.2.1 [method]outgoing-request.method //go:noescape func wasmimport_OutgoingRequestMethod(self0 uint32, result *Method) @@ -1255,7 +1262,7 @@ func (self OutgoingRequest) PathWithQuery() (result cm.Option[string]) { return } -//go:wasmimport wasi:http/types@0.2.0 [method]outgoing-request.path-with-query +//go:wasmimport wasi:http/types@0.2.1 [method]outgoing-request.path-with-query //go:noescape func wasmimport_OutgoingRequestPathWithQuery(self0 uint32, result *cm.Option[string]) @@ -1273,16 +1280,16 @@ func (self OutgoingRequest) Scheme() (result cm.Option[Scheme]) { return } -//go:wasmimport wasi:http/types@0.2.0 [method]outgoing-request.scheme +//go:wasmimport wasi:http/types@0.2.1 [method]outgoing-request.scheme //go:noescape func wasmimport_OutgoingRequestScheme(self0 uint32, result *cm.Option[Scheme]) // SetAuthority represents the imported method "set-authority". // -// Set the HTTP Authority for the Request. A value of `none` may be used -// with Related Schemes which do not require an Authority. The HTTP and +// Set the authority of the Request's target URI. A value of `none` may be used +// with Related Schemes which do not require an authority. The HTTP and // HTTPS schemes always require an authority. Fails if the string given is -// not a syntactically valid uri authority. +// not a syntactically valid URI authority. // // set-authority: func(authority: option) -> result // @@ -1295,7 +1302,7 @@ func (self OutgoingRequest) SetAuthority(authority cm.Option[string]) (result cm return } -//go:wasmimport wasi:http/types@0.2.0 [method]outgoing-request.set-authority +//go:wasmimport wasi:http/types@0.2.1 [method]outgoing-request.set-authority //go:noescape func wasmimport_OutgoingRequestSetAuthority(self0 uint32, authority0 uint32, authority1 *uint8, authority2 uint32) (result0 uint32) @@ -1315,7 +1322,7 @@ func (self OutgoingRequest) SetMethod(method Method) (result cm.BoolResult) { return } -//go:wasmimport wasi:http/types@0.2.0 [method]outgoing-request.set-method +//go:wasmimport wasi:http/types@0.2.1 [method]outgoing-request.set-method //go:noescape func wasmimport_OutgoingRequestSetMethod(self0 uint32, method0 uint32, method1 *uint8, method2 uint32) (result0 uint32) @@ -1336,7 +1343,7 @@ func (self OutgoingRequest) SetPathWithQuery(pathWithQuery cm.Option[string]) (r return } -//go:wasmimport wasi:http/types@0.2.0 [method]outgoing-request.set-path-with-query +//go:wasmimport wasi:http/types@0.2.1 [method]outgoing-request.set-path-with-query //go:noescape func wasmimport_OutgoingRequestSetPathWithQuery(self0 uint32, pathWithQuery0 uint32, pathWithQuery1 *uint8, pathWithQuery2 uint32) (result0 uint32) @@ -1357,11 +1364,11 @@ func (self OutgoingRequest) SetScheme(scheme cm.Option[Scheme]) (result cm.BoolR return } -//go:wasmimport wasi:http/types@0.2.0 [method]outgoing-request.set-scheme +//go:wasmimport wasi:http/types@0.2.1 [method]outgoing-request.set-scheme //go:noescape func wasmimport_OutgoingRequestSetScheme(self0 uint32, scheme0 uint32, scheme1 uint32, scheme2 *uint8, scheme3 uint32) (result0 uint32) -// RequestOptions represents the imported resource "wasi:http/types@0.2.0#request-options". +// RequestOptions represents the imported resource "wasi:http/types@0.2.1#request-options". // // Parameters for making an HTTP Request. Each of these parameters is // currently an optional timeout applicable to the transport layer of the @@ -1384,7 +1391,7 @@ func (self RequestOptions) ResourceDrop() { return } -//go:wasmimport wasi:http/types@0.2.0 [resource-drop]request-options +//go:wasmimport wasi:http/types@0.2.1 [resource-drop]request-options //go:noescape func wasmimport_RequestOptionsResourceDrop(self0 uint32) @@ -1401,7 +1408,7 @@ func NewRequestOptions() (result RequestOptions) { return } -//go:wasmimport wasi:http/types@0.2.0 [constructor]request-options +//go:wasmimport wasi:http/types@0.2.1 [constructor]request-options //go:noescape func wasmimport_NewRequestOptions() (result0 uint32) @@ -1419,7 +1426,7 @@ func (self RequestOptions) BetweenBytesTimeout() (result cm.Option[monotoniccloc return } -//go:wasmimport wasi:http/types@0.2.0 [method]request-options.between-bytes-timeout +//go:wasmimport wasi:http/types@0.2.1 [method]request-options.between-bytes-timeout //go:noescape func wasmimport_RequestOptionsBetweenBytesTimeout(self0 uint32, result *cm.Option[monotonicclock.Duration]) @@ -1436,7 +1443,7 @@ func (self RequestOptions) ConnectTimeout() (result cm.Option[monotonicclock.Dur return } -//go:wasmimport wasi:http/types@0.2.0 [method]request-options.connect-timeout +//go:wasmimport wasi:http/types@0.2.1 [method]request-options.connect-timeout //go:noescape func wasmimport_RequestOptionsConnectTimeout(self0 uint32, result *cm.Option[monotonicclock.Duration]) @@ -1453,7 +1460,7 @@ func (self RequestOptions) FirstByteTimeout() (result cm.Option[monotonicclock.D return } -//go:wasmimport wasi:http/types@0.2.0 [method]request-options.first-byte-timeout +//go:wasmimport wasi:http/types@0.2.1 [method]request-options.first-byte-timeout //go:noescape func wasmimport_RequestOptionsFirstByteTimeout(self0 uint32, result *cm.Option[monotonicclock.Duration]) @@ -1474,7 +1481,7 @@ func (self RequestOptions) SetBetweenBytesTimeout(duration cm.Option[monotoniccl return } -//go:wasmimport wasi:http/types@0.2.0 [method]request-options.set-between-bytes-timeout +//go:wasmimport wasi:http/types@0.2.1 [method]request-options.set-between-bytes-timeout //go:noescape func wasmimport_RequestOptionsSetBetweenBytesTimeout(self0 uint32, duration0 uint32, duration1 uint64) (result0 uint32) @@ -1494,7 +1501,7 @@ func (self RequestOptions) SetConnectTimeout(duration cm.Option[monotonicclock.D return } -//go:wasmimport wasi:http/types@0.2.0 [method]request-options.set-connect-timeout +//go:wasmimport wasi:http/types@0.2.1 [method]request-options.set-connect-timeout //go:noescape func wasmimport_RequestOptionsSetConnectTimeout(self0 uint32, duration0 uint32, duration1 uint64) (result0 uint32) @@ -1514,11 +1521,11 @@ func (self RequestOptions) SetFirstByteTimeout(duration cm.Option[monotonicclock return } -//go:wasmimport wasi:http/types@0.2.0 [method]request-options.set-first-byte-timeout +//go:wasmimport wasi:http/types@0.2.1 [method]request-options.set-first-byte-timeout //go:noescape func wasmimport_RequestOptionsSetFirstByteTimeout(self0 uint32, duration0 uint32, duration1 uint64) (result0 uint32) -// ResponseOutparam represents the imported resource "wasi:http/types@0.2.0#response-outparam". +// ResponseOutparam represents the imported resource "wasi:http/types@0.2.1#response-outparam". // // Represents the ability to send an HTTP Response. // @@ -1540,7 +1547,7 @@ func (self ResponseOutparam) ResourceDrop() { return } -//go:wasmimport wasi:http/types@0.2.0 [resource-drop]response-outparam +//go:wasmimport wasi:http/types@0.2.1 [resource-drop]response-outparam //go:noescape func wasmimport_ResponseOutparamResourceDrop(self0 uint32) @@ -1567,18 +1574,18 @@ func ResponseOutparamSet(param ResponseOutparam, response cm.Result[ErrorCodeSha return } -//go:wasmimport wasi:http/types@0.2.0 [static]response-outparam.set +//go:wasmimport wasi:http/types@0.2.1 [static]response-outparam.set //go:noescape func wasmimport_ResponseOutparamSet(param0 uint32, response0 uint32, response1 uint32, response2 uint32, response3 uint64, response4 uint32, response5 uint32, response6 uint32, response7 uint32) -// StatusCode represents the u16 "wasi:http/types@0.2.0#status-code". +// StatusCode represents the u16 "wasi:http/types@0.2.1#status-code". // // This type corresponds to the HTTP standard Status Code. // // type status-code = u16 type StatusCode uint16 -// IncomingResponse represents the imported resource "wasi:http/types@0.2.0#incoming-response". +// IncomingResponse represents the imported resource "wasi:http/types@0.2.1#incoming-response". // // Represents an incoming HTTP Response. // @@ -1596,7 +1603,7 @@ func (self IncomingResponse) ResourceDrop() { return } -//go:wasmimport wasi:http/types@0.2.0 [resource-drop]incoming-response +//go:wasmimport wasi:http/types@0.2.1 [resource-drop]incoming-response //go:noescape func wasmimport_IncomingResponseResourceDrop(self0 uint32) @@ -1614,7 +1621,7 @@ func (self IncomingResponse) Consume() (result cm.Result[IncomingBody, IncomingB return } -//go:wasmimport wasi:http/types@0.2.0 [method]incoming-response.consume +//go:wasmimport wasi:http/types@0.2.1 [method]incoming-response.consume //go:noescape func wasmimport_IncomingResponseConsume(self0 uint32, result *cm.Result[IncomingBody, IncomingBody, struct{}]) @@ -1638,7 +1645,7 @@ func (self IncomingResponse) Headers() (result Fields) { return } -//go:wasmimport wasi:http/types@0.2.0 [method]incoming-response.headers +//go:wasmimport wasi:http/types@0.2.1 [method]incoming-response.headers //go:noescape func wasmimport_IncomingResponseHeaders(self0 uint32) (result0 uint32) @@ -1656,11 +1663,11 @@ func (self IncomingResponse) Status() (result StatusCode) { return } -//go:wasmimport wasi:http/types@0.2.0 [method]incoming-response.status +//go:wasmimport wasi:http/types@0.2.1 [method]incoming-response.status //go:noescape func wasmimport_IncomingResponseStatus(self0 uint32) (result0 uint32) -// IncomingBody represents the imported resource "wasi:http/types@0.2.0#incoming-body". +// IncomingBody represents the imported resource "wasi:http/types@0.2.1#incoming-body". // // Represents an incoming HTTP Request or Response's Body. // @@ -1685,7 +1692,7 @@ func (self IncomingBody) ResourceDrop() { return } -//go:wasmimport wasi:http/types@0.2.0 [resource-drop]incoming-body +//go:wasmimport wasi:http/types@0.2.1 [resource-drop]incoming-body //go:noescape func wasmimport_IncomingBodyResourceDrop(self0 uint32) @@ -1704,7 +1711,7 @@ func IncomingBodyFinish(this IncomingBody) (result FutureTrailers) { return } -//go:wasmimport wasi:http/types@0.2.0 [static]incoming-body.finish +//go:wasmimport wasi:http/types@0.2.1 [static]incoming-body.finish //go:noescape func wasmimport_IncomingBodyFinish(this0 uint32) (result0 uint32) @@ -1735,13 +1742,13 @@ func (self IncomingBody) Stream() (result cm.Result[streams.InputStream, streams return } -//go:wasmimport wasi:http/types@0.2.0 [method]incoming-body.stream +//go:wasmimport wasi:http/types@0.2.1 [method]incoming-body.stream //go:noescape func wasmimport_IncomingBodyStream(self0 uint32, result *cm.Result[streams.InputStream, streams.InputStream, struct{}]) -// FutureTrailers represents the imported resource "wasi:http/types@0.2.0#future-trailers". +// FutureTrailers represents the imported resource "wasi:http/types@0.2.1#future-trailers". // -// Represents a future which may eventaully return trailers, or an error. +// Represents a future which may eventually return trailers, or an error. // // In the case that the incoming HTTP Request or Response did not have any // trailers, this future will resolve to the empty set of trailers once the @@ -1761,13 +1768,13 @@ func (self FutureTrailers) ResourceDrop() { return } -//go:wasmimport wasi:http/types@0.2.0 [resource-drop]future-trailers +//go:wasmimport wasi:http/types@0.2.1 [resource-drop]future-trailers //go:noescape func wasmimport_FutureTrailersResourceDrop(self0 uint32) // Get represents the imported method "get". // -// Returns the contents of the trailers, or an error which occured, +// Returns the contents of the trailers, or an error which occurred, // once the future is ready. // // The outer `option` represents future readiness. Users can wait on this @@ -1779,7 +1786,7 @@ func wasmimport_FutureTrailersResourceDrop(self0 uint32) // // The inner `result` represents that either the HTTP Request or Response // body, as well as any trailers, were received successfully, or that an -// error occured receiving them. The optional `trailers` indicates whether +// error occurred receiving them. The optional `trailers` indicates whether // or not trailers were present in the body. // // When some `trailers` are returned by this method, the `trailers` @@ -1796,14 +1803,14 @@ func (self FutureTrailers) Get() (result cm.Option[cm.Result[cm.Result[ErrorCode return } -//go:wasmimport wasi:http/types@0.2.0 [method]future-trailers.get +//go:wasmimport wasi:http/types@0.2.1 [method]future-trailers.get //go:noescape func wasmimport_FutureTrailersGet(self0 uint32, result *cm.Option[cm.Result[cm.Result[ErrorCodeShape, cm.Option[Fields], ErrorCode], cm.Result[ErrorCodeShape, cm.Option[Fields], ErrorCode], struct{}]]) // Subscribe represents the imported method "subscribe". // // Returns a pollable which becomes ready when either the trailers have -// been received, or an error has occured. When this pollable is ready, +// been received, or an error has occurred. When this pollable is ready, // the `get` method will return `some`. // // subscribe: func() -> pollable @@ -1816,11 +1823,11 @@ func (self FutureTrailers) Subscribe() (result poll.Pollable) { return } -//go:wasmimport wasi:http/types@0.2.0 [method]future-trailers.subscribe +//go:wasmimport wasi:http/types@0.2.1 [method]future-trailers.subscribe //go:noescape func wasmimport_FutureTrailersSubscribe(self0 uint32) (result0 uint32) -// OutgoingResponse represents the imported resource "wasi:http/types@0.2.0#outgoing-response". +// OutgoingResponse represents the imported resource "wasi:http/types@0.2.1#outgoing-response". // // Represents an outgoing HTTP Response. // @@ -1838,7 +1845,7 @@ func (self OutgoingResponse) ResourceDrop() { return } -//go:wasmimport wasi:http/types@0.2.0 [resource-drop]outgoing-response +//go:wasmimport wasi:http/types@0.2.1 [resource-drop]outgoing-response //go:noescape func wasmimport_OutgoingResponseResourceDrop(self0 uint32) @@ -1860,7 +1867,7 @@ func NewOutgoingResponse(headers Fields) (result OutgoingResponse) { return } -//go:wasmimport wasi:http/types@0.2.0 [constructor]outgoing-response +//go:wasmimport wasi:http/types@0.2.1 [constructor]outgoing-response //go:noescape func wasmimport_NewOutgoingResponse(headers0 uint32) (result0 uint32) @@ -1881,7 +1888,7 @@ func (self OutgoingResponse) Body() (result cm.Result[OutgoingBody, OutgoingBody return } -//go:wasmimport wasi:http/types@0.2.0 [method]outgoing-response.body +//go:wasmimport wasi:http/types@0.2.1 [method]outgoing-response.body //go:noescape func wasmimport_OutgoingResponseBody(self0 uint32, result *cm.Result[OutgoingBody, OutgoingBody, struct{}]) @@ -1893,7 +1900,7 @@ func wasmimport_OutgoingResponseBody(self0 uint32, result *cm.Result[OutgoingBod // `delete` operations will fail with `header-error.immutable`. // // This headers resource is a child: it must be dropped before the parent -// `outgoing-request` is dropped, or its ownership is transfered to +// `outgoing-request` is dropped, or its ownership is transferred to // another component by e.g. `outgoing-handler.handle`. // // headers: func() -> headers @@ -1906,7 +1913,7 @@ func (self OutgoingResponse) Headers() (result Fields) { return } -//go:wasmimport wasi:http/types@0.2.0 [method]outgoing-response.headers +//go:wasmimport wasi:http/types@0.2.1 [method]outgoing-response.headers //go:noescape func wasmimport_OutgoingResponseHeaders(self0 uint32) (result0 uint32) @@ -1926,7 +1933,7 @@ func (self OutgoingResponse) SetStatusCode(statusCode StatusCode) (result cm.Boo return } -//go:wasmimport wasi:http/types@0.2.0 [method]outgoing-response.set-status-code +//go:wasmimport wasi:http/types@0.2.1 [method]outgoing-response.set-status-code //go:noescape func wasmimport_OutgoingResponseSetStatusCode(self0 uint32, statusCode0 uint32) (result0 uint32) @@ -1944,11 +1951,11 @@ func (self OutgoingResponse) StatusCode() (result StatusCode) { return } -//go:wasmimport wasi:http/types@0.2.0 [method]outgoing-response.status-code +//go:wasmimport wasi:http/types@0.2.1 [method]outgoing-response.status-code //go:noescape func wasmimport_OutgoingResponseStatusCode(self0 uint32) (result0 uint32) -// OutgoingBody represents the imported resource "wasi:http/types@0.2.0#outgoing-body". +// OutgoingBody represents the imported resource "wasi:http/types@0.2.1#outgoing-body". // // Represents an outgoing HTTP Request or Response's Body. // @@ -1962,7 +1969,7 @@ func wasmimport_OutgoingResponseStatusCode(self0 uint32) (result0 uint32) // // If the user code drops this resource, as opposed to calling the static // method `finish`, the implementation should treat the body as incomplete, -// and that an error has occured. The implementation should propogate this +// and that an error has occurred. The implementation should propagate this // error to the HTTP protocol by whatever means it has available, // including: corrupting the body on the wire, aborting the associated // Request, or sending a late status code for the Response. @@ -1981,7 +1988,7 @@ func (self OutgoingBody) ResourceDrop() { return } -//go:wasmimport wasi:http/types@0.2.0 [resource-drop]outgoing-body +//go:wasmimport wasi:http/types@0.2.1 [resource-drop]outgoing-body //go:noescape func wasmimport_OutgoingBodyResourceDrop(self0 uint32) @@ -2008,7 +2015,7 @@ func OutgoingBodyFinish(this OutgoingBody, trailers cm.Option[Fields]) (result c return } -//go:wasmimport wasi:http/types@0.2.0 [static]outgoing-body.finish +//go:wasmimport wasi:http/types@0.2.1 [static]outgoing-body.finish //go:noescape func wasmimport_OutgoingBodyFinish(this0 uint32, trailers0 uint32, trailers1 uint32, result *cm.Result[ErrorCode, struct{}, ErrorCode]) @@ -2033,13 +2040,13 @@ func (self OutgoingBody) Write() (result cm.Result[streams.OutputStream, streams return } -//go:wasmimport wasi:http/types@0.2.0 [method]outgoing-body.write +//go:wasmimport wasi:http/types@0.2.1 [method]outgoing-body.write //go:noescape func wasmimport_OutgoingBodyWrite(self0 uint32, result *cm.Result[streams.OutputStream, streams.OutputStream, struct{}]) -// FutureIncomingResponse represents the imported resource "wasi:http/types@0.2.0#future-incoming-response". +// FutureIncomingResponse represents the imported resource "wasi:http/types@0.2.1#future-incoming-response". // -// Represents a future which may eventaully return an incoming HTTP +// Represents a future which may eventually return an incoming HTTP // Response, or an error. // // This resource is returned by the `wasi:http/outgoing-handler` interface to @@ -2059,7 +2066,7 @@ func (self FutureIncomingResponse) ResourceDrop() { return } -//go:wasmimport wasi:http/types@0.2.0 [resource-drop]future-incoming-response +//go:wasmimport wasi:http/types@0.2.1 [resource-drop]future-incoming-response //go:noescape func wasmimport_FutureIncomingResponseResourceDrop(self0 uint32) @@ -2075,8 +2082,8 @@ func wasmimport_FutureIncomingResponseResourceDrop(self0 uint32) // is `some`, and error on subsequent calls. // // The inner `result` represents that either the incoming HTTP Response -// status and headers have recieved successfully, or that an error -// occured. Errors may also occur while consuming the response body, +// status and headers have received successfully, or that an error +// occurred. Errors may also occur while consuming the response body, // but those will be reported by the `incoming-body` and its // `output-stream` child. // @@ -2089,14 +2096,14 @@ func (self FutureIncomingResponse) Get() (result cm.Option[cm.Result[cm.Result[E return } -//go:wasmimport wasi:http/types@0.2.0 [method]future-incoming-response.get +//go:wasmimport wasi:http/types@0.2.1 [method]future-incoming-response.get //go:noescape func wasmimport_FutureIncomingResponseGet(self0 uint32, result *cm.Option[cm.Result[cm.Result[ErrorCodeShape, IncomingResponse, ErrorCode], cm.Result[ErrorCodeShape, IncomingResponse, ErrorCode], struct{}]]) // Subscribe represents the imported method "subscribe". // // Returns a pollable which becomes ready when either the Response has -// been received, or an error has occured. When this pollable is ready, +// been received, or an error has occurred. When this pollable is ready, // the `get` method will return `some`. // // subscribe: func() -> pollable @@ -2109,7 +2116,7 @@ func (self FutureIncomingResponse) Subscribe() (result poll.Pollable) { return } -//go:wasmimport wasi:http/types@0.2.0 [method]future-incoming-response.subscribe +//go:wasmimport wasi:http/types@0.2.1 [method]future-incoming-response.subscribe //go:noescape func wasmimport_FutureIncomingResponseSubscribe(self0 uint32) (result0 uint32) @@ -2136,6 +2143,6 @@ func HTTPErrorCode(err ioerror.Error) (result cm.Option[ErrorCode]) { return } -//go:wasmimport wasi:http/types@0.2.0 http-error-code +//go:wasmimport wasi:http/types@0.2.1 http-error-code //go:noescape func wasmimport_HTTPErrorCode(err0 uint32, result *cm.Option[ErrorCode]) diff --git a/bindings/wasi/io/error/error.wit.go b/bindings/wasi/io/error/error.wit.go index 96d18cf..9571a52 100644 --- a/bindings/wasi/io/error/error.wit.go +++ b/bindings/wasi/io/error/error.wit.go @@ -1,13 +1,13 @@ // Code generated by wit-bindgen-go. DO NOT EDIT. -// Package ioerror represents the imported interface "wasi:io/error@0.2.0". +// Package ioerror represents the imported interface "wasi:io/error@0.2.1". package ioerror import ( - "github.com/ydnar/wasm-tools-go/cm" + "github.com/bytecodealliance/wasm-tools-go/cm" ) -// Error represents the imported resource "wasi:io/error@0.2.0#error". +// Error represents the imported resource "wasi:io/error@0.2.1#error". // // A resource which represents some error information. // @@ -18,13 +18,11 @@ import ( // `wasi:io/streams/stream-error` type. // // To provide more specific error information, other interfaces may -// provide functions to further "downcast" this error into more specific -// error information. For example, `error`s returned in streams derived -// from filesystem types to be described using the filesystem's own -// error-code type, using the function -// `wasi:filesystem/types/filesystem-error-code`, which takes a parameter -// `borrow` and returns -// `option`. +// offer functions to "downcast" this error into more specific types. For example, +// errors returned from streams derived from filesystem types can be described using +// the filesystem's own error-code type. This is done using the function +// `wasi:filesystem/types/filesystem-error-code`, which takes a `borrow` +// parameter and returns an `option`. // // The set of functions which can "downcast" an `error` into a more // concrete type is open. @@ -43,7 +41,7 @@ func (self Error) ResourceDrop() { return } -//go:wasmimport wasi:io/error@0.2.0 [resource-drop]error +//go:wasmimport wasi:io/error@0.2.1 [resource-drop]error //go:noescape func wasmimport_ErrorResourceDrop(self0 uint32) @@ -66,6 +64,6 @@ func (self Error) ToDebugString() (result string) { return } -//go:wasmimport wasi:io/error@0.2.0 [method]error.to-debug-string +//go:wasmimport wasi:io/error@0.2.1 [method]error.to-debug-string //go:noescape func wasmimport_ErrorToDebugString(self0 uint32, result *string) diff --git a/bindings/wasi/io/imports/imports.wit.go b/bindings/wasi/io/imports/imports.wit.go index dab34b9..4a868ba 100644 --- a/bindings/wasi/io/imports/imports.wit.go +++ b/bindings/wasi/io/imports/imports.wit.go @@ -1,4 +1,4 @@ // Code generated by wit-bindgen-go. DO NOT EDIT. -// Package imports represents the world "wasi:io/imports@0.2.0". +// Package imports represents the world "wasi:io/imports@0.2.1". package imports diff --git a/bindings/wasi/io/poll/poll.wit.go b/bindings/wasi/io/poll/poll.wit.go index ba22e54..89ed0b9 100644 --- a/bindings/wasi/io/poll/poll.wit.go +++ b/bindings/wasi/io/poll/poll.wit.go @@ -1,16 +1,16 @@ // Code generated by wit-bindgen-go. DO NOT EDIT. -// Package poll represents the imported interface "wasi:io/poll@0.2.0". +// Package poll represents the imported interface "wasi:io/poll@0.2.1". // // A poll API intended to let users wait for I/O events on multiple handles // at once. package poll import ( - "github.com/ydnar/wasm-tools-go/cm" + "github.com/bytecodealliance/wasm-tools-go/cm" ) -// Pollable represents the imported resource "wasi:io/poll@0.2.0#pollable". +// Pollable represents the imported resource "wasi:io/poll@0.2.1#pollable". // // `pollable` represents a single I/O event which may be ready, or not. // @@ -28,7 +28,7 @@ func (self Pollable) ResourceDrop() { return } -//go:wasmimport wasi:io/poll@0.2.0 [resource-drop]pollable +//go:wasmimport wasi:io/poll@0.2.1 [resource-drop]pollable //go:noescape func wasmimport_PollableResourceDrop(self0 uint32) @@ -49,7 +49,7 @@ func (self Pollable) Block() { return } -//go:wasmimport wasi:io/poll@0.2.0 [method]pollable.block +//go:wasmimport wasi:io/poll@0.2.1 [method]pollable.block //go:noescape func wasmimport_PollableBlock(self0 uint32) @@ -69,7 +69,7 @@ func (self Pollable) Ready() (result bool) { return } -//go:wasmimport wasi:io/poll@0.2.0 [method]pollable.ready +//go:wasmimport wasi:io/poll@0.2.1 [method]pollable.ready //go:noescape func wasmimport_PollableReady(self0 uint32) (result0 uint32) @@ -83,8 +83,9 @@ func wasmimport_PollableReady(self0 uint32) (result0 uint32) // The result `list` contains one or more indices of handles in the // argument list that is ready for I/O. // -// If the list contains more elements than can be indexed with a `u32` -// value, this function traps. +// This function traps if either: +// - the list is empty, or: +// - the list contains more elements than can be indexed with a `u32` value. // // A timeout can be implemented by adding a pollable from the // wasi-clocks API to the list. @@ -92,7 +93,7 @@ func wasmimport_PollableReady(self0 uint32) (result0 uint32) // This function does not return a `result`; polling in itself does not // do any I/O so it doesn't fail. If any of the I/O sources identified by // the pollables has an error, it is indicated by marking the source as -// being reaedy for I/O. +// being ready for I/O. // // poll: func(in: list>) -> list // @@ -103,6 +104,6 @@ func Poll(in cm.List[Pollable]) (result cm.List[uint32]) { return } -//go:wasmimport wasi:io/poll@0.2.0 poll +//go:wasmimport wasi:io/poll@0.2.1 poll //go:noescape func wasmimport_Poll(in0 *Pollable, in1 uint32, result *cm.List[uint32]) diff --git a/bindings/wasi/io/streams/streams.wit.go b/bindings/wasi/io/streams/streams.wit.go index cfd7bb3..cb6d77e 100644 --- a/bindings/wasi/io/streams/streams.wit.go +++ b/bindings/wasi/io/streams/streams.wit.go @@ -1,6 +1,6 @@ // Code generated by wit-bindgen-go. DO NOT EDIT. -// Package streams represents the imported interface "wasi:io/streams@0.2.0". +// Package streams represents the imported interface "wasi:io/streams@0.2.1". // // WASI I/O is an I/O abstraction API which is currently focused on providing // stream types. @@ -10,12 +10,12 @@ package streams import ( + "github.com/bytecodealliance/wasm-tools-go/cm" ioerror "github.com/rvolosatovs/west/bindings/wasi/io/error" "github.com/rvolosatovs/west/bindings/wasi/io/poll" - "github.com/ydnar/wasm-tools-go/cm" ) -// StreamError represents the imported variant "wasi:io/streams@0.2.0#stream-error". +// StreamError represents the imported variant "wasi:io/streams@0.2.1#stream-error". // // An error for input-stream and output-stream operations. // @@ -54,7 +54,7 @@ func (self *StreamError) Closed() bool { return self.Tag() == 1 } -// InputStream represents the imported resource "wasi:io/streams@0.2.0#input-stream". +// InputStream represents the imported resource "wasi:io/streams@0.2.1#input-stream". // // An input bytestream. // @@ -79,7 +79,7 @@ func (self InputStream) ResourceDrop() { return } -//go:wasmimport wasi:io/streams@0.2.0 [resource-drop]input-stream +//go:wasmimport wasi:io/streams@0.2.1 [resource-drop]input-stream //go:noescape func wasmimport_InputStreamResourceDrop(self0 uint32) @@ -98,7 +98,7 @@ func (self InputStream) BlockingRead(len_ uint64) (result cm.Result[cm.List[uint return } -//go:wasmimport wasi:io/streams@0.2.0 [method]input-stream.blocking-read +//go:wasmimport wasi:io/streams@0.2.1 [method]input-stream.blocking-read //go:noescape func wasmimport_InputStreamBlockingRead(self0 uint32, len0 uint64, result *cm.Result[cm.List[uint8], cm.List[uint8], StreamError]) @@ -117,7 +117,7 @@ func (self InputStream) BlockingSkip(len_ uint64) (result cm.Result[uint64, uint return } -//go:wasmimport wasi:io/streams@0.2.0 [method]input-stream.blocking-skip +//go:wasmimport wasi:io/streams@0.2.1 [method]input-stream.blocking-skip //go:noescape func wasmimport_InputStreamBlockingSkip(self0 uint32, len0 uint64, result *cm.Result[uint64, uint64, StreamError]) @@ -160,7 +160,7 @@ func (self InputStream) Read(len_ uint64) (result cm.Result[cm.List[uint8], cm.L return } -//go:wasmimport wasi:io/streams@0.2.0 [method]input-stream.read +//go:wasmimport wasi:io/streams@0.2.1 [method]input-stream.read //go:noescape func wasmimport_InputStreamRead(self0 uint32, len0 uint64, result *cm.Result[cm.List[uint8], cm.List[uint8], StreamError]) @@ -181,7 +181,7 @@ func (self InputStream) Skip(len_ uint64) (result cm.Result[uint64, uint64, Stre return } -//go:wasmimport wasi:io/streams@0.2.0 [method]input-stream.skip +//go:wasmimport wasi:io/streams@0.2.1 [method]input-stream.skip //go:noescape func wasmimport_InputStreamSkip(self0 uint32, len0 uint64, result *cm.Result[uint64, uint64, StreamError]) @@ -204,11 +204,11 @@ func (self InputStream) Subscribe() (result poll.Pollable) { return } -//go:wasmimport wasi:io/streams@0.2.0 [method]input-stream.subscribe +//go:wasmimport wasi:io/streams@0.2.1 [method]input-stream.subscribe //go:noescape func wasmimport_InputStreamSubscribe(self0 uint32) (result0 uint32) -// OutputStream represents the imported resource "wasi:io/streams@0.2.0#output-stream". +// OutputStream represents the imported resource "wasi:io/streams@0.2.1#output-stream". // // An output bytestream. // @@ -219,6 +219,10 @@ func wasmimport_InputStreamSubscribe(self0 uint32) (result0 uint32) // accept data, the `subscribe` function to obtain a `pollable` which can be // polled for using `wasi:io/poll`. // +// Dropping an `output-stream` while there's still an active write in +// progress may result in the data being lost. Before dropping the stream, +// be sure to fully flush your writes. +// // resource output-stream type OutputStream cm.Resource @@ -233,7 +237,7 @@ func (self OutputStream) ResourceDrop() { return } -//go:wasmimport wasi:io/streams@0.2.0 [resource-drop]output-stream +//go:wasmimport wasi:io/streams@0.2.1 [resource-drop]output-stream //go:noescape func wasmimport_OutputStreamResourceDrop(self0 uint32) @@ -251,7 +255,7 @@ func (self OutputStream) BlockingFlush() (result cm.Result[StreamError, struct{} return } -//go:wasmimport wasi:io/streams@0.2.0 [method]output-stream.blocking-flush +//go:wasmimport wasi:io/streams@0.2.1 [method]output-stream.blocking-flush //go:noescape func wasmimport_OutputStreamBlockingFlush(self0 uint32, result *cm.Result[StreamError, struct{}, StreamError]) @@ -274,7 +278,7 @@ func (self OutputStream) BlockingSplice(src InputStream, len_ uint64) (result cm return } -//go:wasmimport wasi:io/streams@0.2.0 [method]output-stream.blocking-splice +//go:wasmimport wasi:io/streams@0.2.1 [method]output-stream.blocking-splice //go:noescape func wasmimport_OutputStreamBlockingSplice(self0 uint32, src0 uint32, len0 uint64, result *cm.Result[uint64, uint64, StreamError]) @@ -313,7 +317,7 @@ func (self OutputStream) BlockingWriteAndFlush(contents cm.List[uint8]) (result return } -//go:wasmimport wasi:io/streams@0.2.0 [method]output-stream.blocking-write-and-flush +//go:wasmimport wasi:io/streams@0.2.1 [method]output-stream.blocking-write-and-flush //go:noescape func wasmimport_OutputStreamBlockingWriteAndFlush(self0 uint32, contents0 *uint8, contents1 uint32, result *cm.Result[StreamError, struct{}, StreamError]) @@ -352,7 +356,7 @@ func (self OutputStream) BlockingWriteZeroesAndFlush(len_ uint64) (result cm.Res return } -//go:wasmimport wasi:io/streams@0.2.0 [method]output-stream.blocking-write-zeroes-and-flush +//go:wasmimport wasi:io/streams@0.2.1 [method]output-stream.blocking-write-zeroes-and-flush //go:noescape func wasmimport_OutputStreamBlockingWriteZeroesAndFlush(self0 uint32, len0 uint64, result *cm.Result[StreamError, struct{}, StreamError]) @@ -377,7 +381,7 @@ func (self OutputStream) CheckWrite() (result cm.Result[uint64, uint64, StreamEr return } -//go:wasmimport wasi:io/streams@0.2.0 [method]output-stream.check-write +//go:wasmimport wasi:io/streams@0.2.1 [method]output-stream.check-write //go:noescape func wasmimport_OutputStreamCheckWrite(self0 uint32, result *cm.Result[uint64, uint64, StreamError]) @@ -403,7 +407,7 @@ func (self OutputStream) Flush() (result cm.Result[StreamError, struct{}, Stream return } -//go:wasmimport wasi:io/streams@0.2.0 [method]output-stream.flush +//go:wasmimport wasi:io/streams@0.2.1 [method]output-stream.flush //go:noescape func wasmimport_OutputStreamFlush(self0 uint32, result *cm.Result[StreamError, struct{}, StreamError]) @@ -411,7 +415,7 @@ func wasmimport_OutputStreamFlush(self0 uint32, result *cm.Result[StreamError, s // // Read from one stream and write to another. // -// The behavior of splice is equivelant to: +// The behavior of splice is equivalent to: // 1. calling `check-write` on the `output-stream` // 2. calling `read` on the `input-stream` with the smaller of the // `check-write` permitted length and the `len` provided to `splice` @@ -434,14 +438,14 @@ func (self OutputStream) Splice(src InputStream, len_ uint64) (result cm.Result[ return } -//go:wasmimport wasi:io/streams@0.2.0 [method]output-stream.splice +//go:wasmimport wasi:io/streams@0.2.1 [method]output-stream.splice //go:noescape func wasmimport_OutputStreamSplice(self0 uint32, src0 uint32, len0 uint64, result *cm.Result[uint64, uint64, StreamError]) // Subscribe represents the imported method "subscribe". // // Create a `pollable` which will resolve once the output-stream -// is ready for more writing, or an error has occured. When this +// is ready for more writing, or an error has occurred. When this // pollable is ready, `check-write` will return `ok(n)` with n>0, or an // error. // @@ -461,7 +465,7 @@ func (self OutputStream) Subscribe() (result poll.Pollable) { return } -//go:wasmimport wasi:io/streams@0.2.0 [method]output-stream.subscribe +//go:wasmimport wasi:io/streams@0.2.1 [method]output-stream.subscribe //go:noescape func wasmimport_OutputStreamSubscribe(self0 uint32) (result0 uint32) @@ -491,7 +495,7 @@ func (self OutputStream) Write(contents cm.List[uint8]) (result cm.Result[Stream return } -//go:wasmimport wasi:io/streams@0.2.0 [method]output-stream.write +//go:wasmimport wasi:io/streams@0.2.1 [method]output-stream.write //go:noescape func wasmimport_OutputStreamWrite(self0 uint32, contents0 *uint8, contents1 uint32, result *cm.Result[StreamError, struct{}, StreamError]) @@ -514,6 +518,6 @@ func (self OutputStream) WriteZeroes(len_ uint64) (result cm.Result[StreamError, return } -//go:wasmimport wasi:io/streams@0.2.0 [method]output-stream.write-zeroes +//go:wasmimport wasi:io/streams@0.2.1 [method]output-stream.write-zeroes //go:noescape func wasmimport_OutputStreamWriteZeroes(self0 uint32, len0 uint64, result *cm.Result[StreamError, struct{}, StreamError]) diff --git a/bindings/wasi/random/imports/imports.wit.go b/bindings/wasi/random/imports/imports.wit.go index 3f0247b..8bfa56f 100644 --- a/bindings/wasi/random/imports/imports.wit.go +++ b/bindings/wasi/random/imports/imports.wit.go @@ -1,4 +1,4 @@ // Code generated by wit-bindgen-go. DO NOT EDIT. -// Package imports represents the world "wasi:random/imports@0.2.0". +// Package imports represents the world "wasi:random/imports@0.2.1". package imports diff --git a/bindings/wasi/random/insecure-seed/insecure-seed.wit.go b/bindings/wasi/random/insecure-seed/insecure-seed.wit.go index 3b8f33c..fa25a3b 100644 --- a/bindings/wasi/random/insecure-seed/insecure-seed.wit.go +++ b/bindings/wasi/random/insecure-seed/insecure-seed.wit.go @@ -1,6 +1,6 @@ // Code generated by wit-bindgen-go. DO NOT EDIT. -// Package insecureseed represents the imported interface "wasi:random/insecure-seed@0.2.0". +// Package insecureseed represents the imported interface "wasi:random/insecure-seed@0.2.1". // // The insecure-seed interface for seeding hash-map DoS resistance. // @@ -36,6 +36,6 @@ func InsecureSeed() (result [2]uint64) { return } -//go:wasmimport wasi:random/insecure-seed@0.2.0 insecure-seed +//go:wasmimport wasi:random/insecure-seed@0.2.1 insecure-seed //go:noescape func wasmimport_InsecureSeed(result *[2]uint64) diff --git a/bindings/wasi/random/insecure/insecure.wit.go b/bindings/wasi/random/insecure/insecure.wit.go index 4f813bf..6235f33 100644 --- a/bindings/wasi/random/insecure/insecure.wit.go +++ b/bindings/wasi/random/insecure/insecure.wit.go @@ -1,6 +1,6 @@ // Code generated by wit-bindgen-go. DO NOT EDIT. -// Package insecure represents the imported interface "wasi:random/insecure@0.2.0". +// Package insecure represents the imported interface "wasi:random/insecure@0.2.1". // // The insecure interface for insecure pseudo-random numbers. // @@ -9,7 +9,7 @@ package insecure import ( - "github.com/ydnar/wasm-tools-go/cm" + "github.com/bytecodealliance/wasm-tools-go/cm" ) // GetInsecureRandomBytes represents the imported function "get-insecure-random-bytes". @@ -32,7 +32,7 @@ func GetInsecureRandomBytes(len_ uint64) (result cm.List[uint8]) { return } -//go:wasmimport wasi:random/insecure@0.2.0 get-insecure-random-bytes +//go:wasmimport wasi:random/insecure@0.2.1 get-insecure-random-bytes //go:noescape func wasmimport_GetInsecureRandomBytes(len0 uint64, result *cm.List[uint8]) @@ -52,6 +52,6 @@ func GetInsecureRandomU64() (result uint64) { return } -//go:wasmimport wasi:random/insecure@0.2.0 get-insecure-random-u64 +//go:wasmimport wasi:random/insecure@0.2.1 get-insecure-random-u64 //go:noescape func wasmimport_GetInsecureRandomU64() (result0 uint64) diff --git a/bindings/wasi/random/random/random.wit.go b/bindings/wasi/random/random/random.wit.go index 04b2319..fbdbdb2 100644 --- a/bindings/wasi/random/random/random.wit.go +++ b/bindings/wasi/random/random/random.wit.go @@ -1,6 +1,6 @@ // Code generated by wit-bindgen-go. DO NOT EDIT. -// Package random represents the imported interface "wasi:random/random@0.2.0". +// Package random represents the imported interface "wasi:random/random@0.2.1". // // WASI Random is a random data API. // @@ -9,7 +9,7 @@ package random import ( - "github.com/ydnar/wasm-tools-go/cm" + "github.com/bytecodealliance/wasm-tools-go/cm" ) // GetRandomBytes represents the imported function "get-random-bytes". @@ -36,7 +36,7 @@ func GetRandomBytes(len_ uint64) (result cm.List[uint8]) { return } -//go:wasmimport wasi:random/random@0.2.0 get-random-bytes +//go:wasmimport wasi:random/random@0.2.1 get-random-bytes //go:noescape func wasmimport_GetRandomBytes(len0 uint64, result *cm.List[uint8]) @@ -56,6 +56,6 @@ func GetRandomU64() (result uint64) { return } -//go:wasmimport wasi:random/random@0.2.0 get-random-u64 +//go:wasmimport wasi:random/random@0.2.1 get-random-u64 //go:noescape func wasmimport_GetRandomU64() (result0 uint64) diff --git a/bindings/wasi/sockets/imports/imports.wit.go b/bindings/wasi/sockets/imports/imports.wit.go index 1b52e62..52c845e 100644 --- a/bindings/wasi/sockets/imports/imports.wit.go +++ b/bindings/wasi/sockets/imports/imports.wit.go @@ -1,4 +1,4 @@ // Code generated by wit-bindgen-go. DO NOT EDIT. -// Package imports represents the world "wasi:sockets/imports@0.2.0". +// Package imports represents the world "wasi:sockets/imports@0.2.1". package imports diff --git a/bindings/wasi/sockets/instance-network/instance-network.wit.go b/bindings/wasi/sockets/instance-network/instance-network.wit.go index a27d546..11781cc 100644 --- a/bindings/wasi/sockets/instance-network/instance-network.wit.go +++ b/bindings/wasi/sockets/instance-network/instance-network.wit.go @@ -1,13 +1,13 @@ // Code generated by wit-bindgen-go. DO NOT EDIT. -// Package instancenetwork represents the imported interface "wasi:sockets/instance-network@0.2.0". +// Package instancenetwork represents the imported interface "wasi:sockets/instance-network@0.2.1". // // This interface provides a value-export of the default network handle.. package instancenetwork import ( + "github.com/bytecodealliance/wasm-tools-go/cm" "github.com/rvolosatovs/west/bindings/wasi/sockets/network" - "github.com/ydnar/wasm-tools-go/cm" ) // InstanceNetwork represents the imported function "instance-network". @@ -23,6 +23,6 @@ func InstanceNetwork() (result network.Network) { return } -//go:wasmimport wasi:sockets/instance-network@0.2.0 instance-network +//go:wasmimport wasi:sockets/instance-network@0.2.1 instance-network //go:noescape func wasmimport_InstanceNetwork() (result0 uint32) diff --git a/bindings/wasi/sockets/ip-name-lookup/abi.go b/bindings/wasi/sockets/ip-name-lookup/abi.go index 6eeb465..6958a58 100644 --- a/bindings/wasi/sockets/ip-name-lookup/abi.go +++ b/bindings/wasi/sockets/ip-name-lookup/abi.go @@ -3,8 +3,8 @@ package ipnamelookup import ( + "github.com/bytecodealliance/wasm-tools-go/cm" "github.com/rvolosatovs/west/bindings/wasi/sockets/network" - "github.com/ydnar/wasm-tools-go/cm" "unsafe" ) diff --git a/bindings/wasi/sockets/ip-name-lookup/ip-name-lookup.wit.go b/bindings/wasi/sockets/ip-name-lookup/ip-name-lookup.wit.go index 5ddc60b..88fdc76 100644 --- a/bindings/wasi/sockets/ip-name-lookup/ip-name-lookup.wit.go +++ b/bindings/wasi/sockets/ip-name-lookup/ip-name-lookup.wit.go @@ -1,15 +1,15 @@ // Code generated by wit-bindgen-go. DO NOT EDIT. -// Package ipnamelookup represents the imported interface "wasi:sockets/ip-name-lookup@0.2.0". +// Package ipnamelookup represents the imported interface "wasi:sockets/ip-name-lookup@0.2.1". package ipnamelookup import ( + "github.com/bytecodealliance/wasm-tools-go/cm" "github.com/rvolosatovs/west/bindings/wasi/io/poll" "github.com/rvolosatovs/west/bindings/wasi/sockets/network" - "github.com/ydnar/wasm-tools-go/cm" ) -// ResolveAddressStream represents the imported resource "wasi:sockets/ip-name-lookup@0.2.0#resolve-address-stream". +// ResolveAddressStream represents the imported resource "wasi:sockets/ip-name-lookup@0.2.1#resolve-address-stream". // // resource resolve-address-stream type ResolveAddressStream cm.Resource @@ -25,7 +25,7 @@ func (self ResolveAddressStream) ResourceDrop() { return } -//go:wasmimport wasi:sockets/ip-name-lookup@0.2.0 [resource-drop]resolve-address-stream +//go:wasmimport wasi:sockets/ip-name-lookup@0.2.1 [resource-drop]resolve-address-stream //go:noescape func wasmimport_ResolveAddressStreamResourceDrop(self0 uint32) @@ -57,7 +57,7 @@ func (self ResolveAddressStream) ResolveNextAddress() (result cm.Result[OptionIP return } -//go:wasmimport wasi:sockets/ip-name-lookup@0.2.0 [method]resolve-address-stream.resolve-next-address +//go:wasmimport wasi:sockets/ip-name-lookup@0.2.1 [method]resolve-address-stream.resolve-next-address //go:noescape func wasmimport_ResolveAddressStreamResolveNextAddress(self0 uint32, result *cm.Result[OptionIPAddressShape, cm.Option[network.IPAddress], network.ErrorCode]) @@ -78,7 +78,7 @@ func (self ResolveAddressStream) Subscribe() (result poll.Pollable) { return } -//go:wasmimport wasi:sockets/ip-name-lookup@0.2.0 [method]resolve-address-stream.subscribe +//go:wasmimport wasi:sockets/ip-name-lookup@0.2.1 [method]resolve-address-stream.subscribe //go:noescape func wasmimport_ResolveAddressStreamSubscribe(self0 uint32) (result0 uint32) @@ -116,6 +116,6 @@ func ResolveAddresses(network_ network.Network, name string) (result cm.Result[R return } -//go:wasmimport wasi:sockets/ip-name-lookup@0.2.0 resolve-addresses +//go:wasmimport wasi:sockets/ip-name-lookup@0.2.1 resolve-addresses //go:noescape func wasmimport_ResolveAddresses(network0 uint32, name0 *uint8, name1 uint32, result *cm.Result[ResolveAddressStream, ResolveAddressStream, network.ErrorCode]) diff --git a/bindings/wasi/sockets/network/network.wit.go b/bindings/wasi/sockets/network/network.wit.go index 4597e24..7d55115 100644 --- a/bindings/wasi/sockets/network/network.wit.go +++ b/bindings/wasi/sockets/network/network.wit.go @@ -1,13 +1,13 @@ // Code generated by wit-bindgen-go. DO NOT EDIT. -// Package network represents the imported interface "wasi:sockets/network@0.2.0". +// Package network represents the imported interface "wasi:sockets/network@0.2.1". package network import ( - "github.com/ydnar/wasm-tools-go/cm" + "github.com/bytecodealliance/wasm-tools-go/cm" ) -// Network represents the imported resource "wasi:sockets/network@0.2.0#network". +// Network represents the imported resource "wasi:sockets/network@0.2.1#network". // // An opaque resource that represents access to (a subset of) the network. // This enables context-based security for networking. @@ -27,11 +27,11 @@ func (self Network) ResourceDrop() { return } -//go:wasmimport wasi:sockets/network@0.2.0 [resource-drop]network +//go:wasmimport wasi:sockets/network@0.2.1 [resource-drop]network //go:noescape func wasmimport_NetworkResourceDrop(self0 uint32) -// ErrorCode represents the enum "wasi:sockets/network@0.2.0#error-code". +// ErrorCode represents the enum "wasi:sockets/network@0.2.1#error-code". // // Error codes. // @@ -186,7 +186,7 @@ func (e ErrorCode) String() string { return stringsErrorCode[e] } -// IPAddressFamily represents the enum "wasi:sockets/network@0.2.0#ip-address-family". +// IPAddressFamily represents the enum "wasi:sockets/network@0.2.1#ip-address-family". // // enum ip-address-family { // ipv4, @@ -212,17 +212,17 @@ func (e IPAddressFamily) String() string { return stringsIPAddressFamily[e] } -// IPv4Address represents the tuple "wasi:sockets/network@0.2.0#ipv4-address". +// IPv4Address represents the tuple "wasi:sockets/network@0.2.1#ipv4-address". // // type ipv4-address = tuple type IPv4Address [4]uint8 -// IPv6Address represents the tuple "wasi:sockets/network@0.2.0#ipv6-address". +// IPv6Address represents the tuple "wasi:sockets/network@0.2.1#ipv6-address". // // type ipv6-address = tuple type IPv6Address [8]uint16 -// IPAddress represents the variant "wasi:sockets/network@0.2.0#ip-address". +// IPAddress represents the variant "wasi:sockets/network@0.2.1#ip-address". // // variant ip-address { // ipv4(ipv4-address), @@ -250,7 +250,7 @@ func (self *IPAddress) IPv6() *IPv6Address { return cm.Case[IPv6Address](self, 1) } -// IPv4SocketAddress represents the record "wasi:sockets/network@0.2.0#ipv4-socket-address". +// IPv4SocketAddress represents the record "wasi:sockets/network@0.2.1#ipv4-socket-address". // // record ipv4-socket-address { // port: u16, @@ -264,7 +264,7 @@ type IPv4SocketAddress struct { Address IPv4Address } -// IPv6SocketAddress represents the record "wasi:sockets/network@0.2.0#ipv6-socket-address". +// IPv6SocketAddress represents the record "wasi:sockets/network@0.2.1#ipv6-socket-address". // // record ipv6-socket-address { // port: u16, @@ -286,7 +286,7 @@ type IPv6SocketAddress struct { ScopeID uint32 } -// IPSocketAddress represents the variant "wasi:sockets/network@0.2.0#ip-socket-address". +// IPSocketAddress represents the variant "wasi:sockets/network@0.2.1#ip-socket-address". // // variant ip-socket-address { // ipv4(ipv4-socket-address), diff --git a/bindings/wasi/sockets/tcp-create-socket/tcp-create-socket.wit.go b/bindings/wasi/sockets/tcp-create-socket/tcp-create-socket.wit.go index 4951d54..8a2b764 100644 --- a/bindings/wasi/sockets/tcp-create-socket/tcp-create-socket.wit.go +++ b/bindings/wasi/sockets/tcp-create-socket/tcp-create-socket.wit.go @@ -1,12 +1,12 @@ // Code generated by wit-bindgen-go. DO NOT EDIT. -// Package tcpcreatesocket represents the imported interface "wasi:sockets/tcp-create-socket@0.2.0". +// Package tcpcreatesocket represents the imported interface "wasi:sockets/tcp-create-socket@0.2.1". package tcpcreatesocket import ( + "github.com/bytecodealliance/wasm-tools-go/cm" "github.com/rvolosatovs/west/bindings/wasi/sockets/network" "github.com/rvolosatovs/west/bindings/wasi/sockets/tcp" - "github.com/ydnar/wasm-tools-go/cm" ) // CreateTCPSocket represents the imported function "create-tcp-socket". @@ -47,6 +47,6 @@ func CreateTCPSocket(addressFamily network.IPAddressFamily) (result cm.Result[tc return } -//go:wasmimport wasi:sockets/tcp-create-socket@0.2.0 create-tcp-socket +//go:wasmimport wasi:sockets/tcp-create-socket@0.2.1 create-tcp-socket //go:noescape func wasmimport_CreateTCPSocket(addressFamily0 uint32, result *cm.Result[tcp.TCPSocket, tcp.TCPSocket, network.ErrorCode]) diff --git a/bindings/wasi/sockets/tcp/abi.go b/bindings/wasi/sockets/tcp/abi.go index 36dd66a..a9f7508 100644 --- a/bindings/wasi/sockets/tcp/abi.go +++ b/bindings/wasi/sockets/tcp/abi.go @@ -3,9 +3,9 @@ package tcp import ( + "github.com/bytecodealliance/wasm-tools-go/cm" "github.com/rvolosatovs/west/bindings/wasi/io/streams" "github.com/rvolosatovs/west/bindings/wasi/sockets/network" - "github.com/ydnar/wasm-tools-go/cm" "unsafe" ) diff --git a/bindings/wasi/sockets/tcp/tcp.wit.go b/bindings/wasi/sockets/tcp/tcp.wit.go index 5f14861..1e01329 100644 --- a/bindings/wasi/sockets/tcp/tcp.wit.go +++ b/bindings/wasi/sockets/tcp/tcp.wit.go @@ -1,17 +1,17 @@ // Code generated by wit-bindgen-go. DO NOT EDIT. -// Package tcp represents the imported interface "wasi:sockets/tcp@0.2.0". +// Package tcp represents the imported interface "wasi:sockets/tcp@0.2.1". package tcp import ( + "github.com/bytecodealliance/wasm-tools-go/cm" monotonicclock "github.com/rvolosatovs/west/bindings/wasi/clocks/monotonic-clock" "github.com/rvolosatovs/west/bindings/wasi/io/poll" "github.com/rvolosatovs/west/bindings/wasi/io/streams" "github.com/rvolosatovs/west/bindings/wasi/sockets/network" - "github.com/ydnar/wasm-tools-go/cm" ) -// ShutdownType represents the enum "wasi:sockets/tcp@0.2.0#shutdown-type". +// ShutdownType represents the enum "wasi:sockets/tcp@0.2.1#shutdown-type". // // enum shutdown-type { // receive, @@ -42,7 +42,7 @@ func (e ShutdownType) String() string { return stringsShutdownType[e] } -// TCPSocket represents the imported resource "wasi:sockets/tcp@0.2.0#tcp-socket". +// TCPSocket represents the imported resource "wasi:sockets/tcp@0.2.1#tcp-socket". // // A TCP socket resource. // @@ -55,8 +55,8 @@ func (e ShutdownType) String() string { // - `connect-in-progress` // - `connected` // - `closed` -// See -// for a more information. +// See +// for more information. // // Note: Except where explicitly mentioned, whenever this documentation uses // the term "bound" without backticks it actually means: in the `bound` state *or @@ -81,7 +81,7 @@ func (self TCPSocket) ResourceDrop() { return } -//go:wasmimport wasi:sockets/tcp@0.2.0 [resource-drop]tcp-socket +//go:wasmimport wasi:sockets/tcp@0.2.1 [resource-drop]tcp-socket //go:noescape func wasmimport_TCPSocketResourceDrop(self0 uint32) @@ -126,7 +126,7 @@ func (self TCPSocket) Accept() (result cm.Result[TupleTCPSocketInputStreamOutput return } -//go:wasmimport wasi:sockets/tcp@0.2.0 [method]tcp-socket.accept +//go:wasmimport wasi:sockets/tcp@0.2.1 [method]tcp-socket.accept //go:noescape func wasmimport_TCPSocketAccept(self0 uint32, result *cm.Result[TupleTCPSocketInputStreamOutputStreamShape, cm.Tuple3[TCPSocket, streams.InputStream, streams.OutputStream], network.ErrorCode]) @@ -146,7 +146,7 @@ func (self TCPSocket) AddressFamily() (result network.IPAddressFamily) { return } -//go:wasmimport wasi:sockets/tcp@0.2.0 [method]tcp-socket.address-family +//go:wasmimport wasi:sockets/tcp@0.2.1 [method]tcp-socket.address-family //go:noescape func wasmimport_TCPSocketAddressFamily(self0 uint32) (result0 uint32) @@ -161,7 +161,7 @@ func (self TCPSocket) FinishBind() (result cm.Result[network.ErrorCode, struct{} return } -//go:wasmimport wasi:sockets/tcp@0.2.0 [method]tcp-socket.finish-bind +//go:wasmimport wasi:sockets/tcp@0.2.1 [method]tcp-socket.finish-bind //go:noescape func wasmimport_TCPSocketFinishBind(self0 uint32, result *cm.Result[network.ErrorCode, struct{}, network.ErrorCode]) @@ -176,7 +176,7 @@ func (self TCPSocket) FinishConnect() (result cm.Result[TupleInputStreamOutputSt return } -//go:wasmimport wasi:sockets/tcp@0.2.0 [method]tcp-socket.finish-connect +//go:wasmimport wasi:sockets/tcp@0.2.1 [method]tcp-socket.finish-connect //go:noescape func wasmimport_TCPSocketFinishConnect(self0 uint32, result *cm.Result[TupleInputStreamOutputStreamShape, cm.Tuple[streams.InputStream, streams.OutputStream], network.ErrorCode]) @@ -191,7 +191,7 @@ func (self TCPSocket) FinishListen() (result cm.Result[network.ErrorCode, struct return } -//go:wasmimport wasi:sockets/tcp@0.2.0 [method]tcp-socket.finish-listen +//go:wasmimport wasi:sockets/tcp@0.2.1 [method]tcp-socket.finish-listen //go:noescape func wasmimport_TCPSocketFinishListen(self0 uint32, result *cm.Result[network.ErrorCode, struct{}, network.ErrorCode]) @@ -213,7 +213,7 @@ func (self TCPSocket) HopLimit() (result cm.Result[uint8, uint8, network.ErrorCo return } -//go:wasmimport wasi:sockets/tcp@0.2.0 [method]tcp-socket.hop-limit +//go:wasmimport wasi:sockets/tcp@0.2.1 [method]tcp-socket.hop-limit //go:noescape func wasmimport_TCPSocketHopLimit(self0 uint32, result *cm.Result[uint8, uint8, network.ErrorCode]) @@ -233,7 +233,7 @@ func (self TCPSocket) IsListening() (result bool) { return } -//go:wasmimport wasi:sockets/tcp@0.2.0 [method]tcp-socket.is-listening +//go:wasmimport wasi:sockets/tcp@0.2.1 [method]tcp-socket.is-listening //go:noescape func wasmimport_TCPSocketIsListening(self0 uint32) (result0 uint32) @@ -261,7 +261,7 @@ func (self TCPSocket) KeepAliveCount() (result cm.Result[uint32, uint32, network return } -//go:wasmimport wasi:sockets/tcp@0.2.0 [method]tcp-socket.keep-alive-count +//go:wasmimport wasi:sockets/tcp@0.2.1 [method]tcp-socket.keep-alive-count //go:noescape func wasmimport_TCPSocketKeepAliveCount(self0 uint32, result *cm.Result[uint32, uint32, network.ErrorCode]) @@ -287,7 +287,7 @@ func (self TCPSocket) KeepAliveEnabled() (result cm.Result[bool, bool, network.E return } -//go:wasmimport wasi:sockets/tcp@0.2.0 [method]tcp-socket.keep-alive-enabled +//go:wasmimport wasi:sockets/tcp@0.2.1 [method]tcp-socket.keep-alive-enabled //go:noescape func wasmimport_TCPSocketKeepAliveEnabled(self0 uint32, result *cm.Result[bool, bool, network.ErrorCode]) @@ -316,7 +316,7 @@ func (self TCPSocket) KeepAliveIdleTime() (result cm.Result[uint64, monotonicclo return } -//go:wasmimport wasi:sockets/tcp@0.2.0 [method]tcp-socket.keep-alive-idle-time +//go:wasmimport wasi:sockets/tcp@0.2.1 [method]tcp-socket.keep-alive-idle-time //go:noescape func wasmimport_TCPSocketKeepAliveIdleTime(self0 uint32, result *cm.Result[uint64, monotonicclock.Duration, network.ErrorCode]) @@ -344,7 +344,7 @@ func (self TCPSocket) KeepAliveInterval() (result cm.Result[uint64, monotonicclo return } -//go:wasmimport wasi:sockets/tcp@0.2.0 [method]tcp-socket.keep-alive-interval +//go:wasmimport wasi:sockets/tcp@0.2.1 [method]tcp-socket.keep-alive-interval //go:noescape func wasmimport_TCPSocketKeepAliveInterval(self0 uint32, result *cm.Result[uint64, monotonicclock.Duration, network.ErrorCode]) @@ -377,7 +377,7 @@ func (self TCPSocket) LocalAddress() (result cm.Result[IPSocketAddressShape, net return } -//go:wasmimport wasi:sockets/tcp@0.2.0 [method]tcp-socket.local-address +//go:wasmimport wasi:sockets/tcp@0.2.1 [method]tcp-socket.local-address //go:noescape func wasmimport_TCPSocketLocalAddress(self0 uint32, result *cm.Result[IPSocketAddressShape, network.IPSocketAddress, network.ErrorCode]) @@ -405,7 +405,7 @@ func (self TCPSocket) ReceiveBufferSize() (result cm.Result[uint64, uint64, netw return } -//go:wasmimport wasi:sockets/tcp@0.2.0 [method]tcp-socket.receive-buffer-size +//go:wasmimport wasi:sockets/tcp@0.2.1 [method]tcp-socket.receive-buffer-size //go:noescape func wasmimport_TCPSocketReceiveBufferSize(self0 uint32, result *cm.Result[uint64, uint64, network.ErrorCode]) @@ -431,7 +431,7 @@ func (self TCPSocket) RemoteAddress() (result cm.Result[IPSocketAddressShape, ne return } -//go:wasmimport wasi:sockets/tcp@0.2.0 [method]tcp-socket.remote-address +//go:wasmimport wasi:sockets/tcp@0.2.1 [method]tcp-socket.remote-address //go:noescape func wasmimport_TCPSocketRemoteAddress(self0 uint32, result *cm.Result[IPSocketAddressShape, network.IPSocketAddress, network.ErrorCode]) @@ -446,7 +446,7 @@ func (self TCPSocket) SendBufferSize() (result cm.Result[uint64, uint64, network return } -//go:wasmimport wasi:sockets/tcp@0.2.0 [method]tcp-socket.send-buffer-size +//go:wasmimport wasi:sockets/tcp@0.2.1 [method]tcp-socket.send-buffer-size //go:noescape func wasmimport_TCPSocketSendBufferSize(self0 uint32, result *cm.Result[uint64, uint64, network.ErrorCode]) @@ -462,7 +462,7 @@ func (self TCPSocket) SetHopLimit(value uint8) (result cm.Result[network.ErrorCo return } -//go:wasmimport wasi:sockets/tcp@0.2.0 [method]tcp-socket.set-hop-limit +//go:wasmimport wasi:sockets/tcp@0.2.1 [method]tcp-socket.set-hop-limit //go:noescape func wasmimport_TCPSocketSetHopLimit(self0 uint32, value0 uint32, result *cm.Result[network.ErrorCode, struct{}, network.ErrorCode]) @@ -478,7 +478,7 @@ func (self TCPSocket) SetKeepAliveCount(value uint32) (result cm.Result[network. return } -//go:wasmimport wasi:sockets/tcp@0.2.0 [method]tcp-socket.set-keep-alive-count +//go:wasmimport wasi:sockets/tcp@0.2.1 [method]tcp-socket.set-keep-alive-count //go:noescape func wasmimport_TCPSocketSetKeepAliveCount(self0 uint32, value0 uint32, result *cm.Result[network.ErrorCode, struct{}, network.ErrorCode]) @@ -494,7 +494,7 @@ func (self TCPSocket) SetKeepAliveEnabled(value bool) (result cm.Result[network. return } -//go:wasmimport wasi:sockets/tcp@0.2.0 [method]tcp-socket.set-keep-alive-enabled +//go:wasmimport wasi:sockets/tcp@0.2.1 [method]tcp-socket.set-keep-alive-enabled //go:noescape func wasmimport_TCPSocketSetKeepAliveEnabled(self0 uint32, value0 uint32, result *cm.Result[network.ErrorCode, struct{}, network.ErrorCode]) @@ -510,7 +510,7 @@ func (self TCPSocket) SetKeepAliveIdleTime(value monotonicclock.Duration) (resul return } -//go:wasmimport wasi:sockets/tcp@0.2.0 [method]tcp-socket.set-keep-alive-idle-time +//go:wasmimport wasi:sockets/tcp@0.2.1 [method]tcp-socket.set-keep-alive-idle-time //go:noescape func wasmimport_TCPSocketSetKeepAliveIdleTime(self0 uint32, value0 uint64, result *cm.Result[network.ErrorCode, struct{}, network.ErrorCode]) @@ -526,7 +526,7 @@ func (self TCPSocket) SetKeepAliveInterval(value monotonicclock.Duration) (resul return } -//go:wasmimport wasi:sockets/tcp@0.2.0 [method]tcp-socket.set-keep-alive-interval +//go:wasmimport wasi:sockets/tcp@0.2.1 [method]tcp-socket.set-keep-alive-interval //go:noescape func wasmimport_TCPSocketSetKeepAliveInterval(self0 uint32, value0 uint64, result *cm.Result[network.ErrorCode, struct{}, network.ErrorCode]) @@ -555,7 +555,7 @@ func (self TCPSocket) SetListenBacklogSize(value uint64) (result cm.Result[netwo return } -//go:wasmimport wasi:sockets/tcp@0.2.0 [method]tcp-socket.set-listen-backlog-size +//go:wasmimport wasi:sockets/tcp@0.2.1 [method]tcp-socket.set-listen-backlog-size //go:noescape func wasmimport_TCPSocketSetListenBacklogSize(self0 uint32, value0 uint64, result *cm.Result[network.ErrorCode, struct{}, network.ErrorCode]) @@ -571,7 +571,7 @@ func (self TCPSocket) SetReceiveBufferSize(value uint64) (result cm.Result[netwo return } -//go:wasmimport wasi:sockets/tcp@0.2.0 [method]tcp-socket.set-receive-buffer-size +//go:wasmimport wasi:sockets/tcp@0.2.1 [method]tcp-socket.set-receive-buffer-size //go:noescape func wasmimport_TCPSocketSetReceiveBufferSize(self0 uint32, value0 uint64, result *cm.Result[network.ErrorCode, struct{}, network.ErrorCode]) @@ -587,7 +587,7 @@ func (self TCPSocket) SetSendBufferSize(value uint64) (result cm.Result[network. return } -//go:wasmimport wasi:sockets/tcp@0.2.0 [method]tcp-socket.set-send-buffer-size +//go:wasmimport wasi:sockets/tcp@0.2.1 [method]tcp-socket.set-send-buffer-size //go:noescape func wasmimport_TCPSocketSetSendBufferSize(self0 uint32, value0 uint64, result *cm.Result[network.ErrorCode, struct{}, network.ErrorCode]) @@ -603,7 +603,7 @@ func wasmimport_TCPSocketSetSendBufferSize(self0 uint32, value0 uint64, result * // associated with this socket will be closed and a FIN packet will be sent. // - `both`: Same effect as `receive` & `send` combined. // -// This function is idempotent. Shutting a down a direction more than once +// This function is idempotent; shutting down a direction more than once // has no effect and returns `ok`. // // The shutdown function does not close (drop) the socket. @@ -627,7 +627,7 @@ func (self TCPSocket) Shutdown(shutdownType ShutdownType) (result cm.Result[netw return } -//go:wasmimport wasi:sockets/tcp@0.2.0 [method]tcp-socket.shutdown +//go:wasmimport wasi:sockets/tcp@0.2.1 [method]tcp-socket.shutdown //go:noescape func wasmimport_TCPSocketShutdown(self0 uint32, shutdownType0 uint32, result *cm.Result[network.ErrorCode, struct{}, network.ErrorCode]) @@ -693,7 +693,7 @@ func (self TCPSocket) StartBind(network_ network.Network, localAddress network.I return } -//go:wasmimport wasi:sockets/tcp@0.2.0 [method]tcp-socket.start-bind +//go:wasmimport wasi:sockets/tcp@0.2.1 [method]tcp-socket.start-bind //go:noescape func wasmimport_TCPSocketStartBind(self0 uint32, network0 uint32, localAddress0 uint32, localAddress1 uint32, localAddress2 uint32, localAddress3 uint32, localAddress4 uint32, localAddress5 uint32, localAddress6 uint32, localAddress7 uint32, localAddress8 uint32, localAddress9 uint32, localAddress10 uint32, localAddress11 uint32, result *cm.Result[network.ErrorCode, struct{}, network.ErrorCode]) @@ -702,7 +702,7 @@ func wasmimport_TCPSocketStartBind(self0 uint32, network0 uint32, localAddress0 // Connect to a remote endpoint. // // On success: -// - the socket is transitioned into the `connection` state. +// - the socket is transitioned into the `connected` state. // - a pair of streams is returned that can be used to read & write to the connection // // After a failed connection attempt, the socket will be in the `closed` @@ -765,7 +765,7 @@ func (self TCPSocket) StartConnect(network_ network.Network, remoteAddress netwo return } -//go:wasmimport wasi:sockets/tcp@0.2.0 [method]tcp-socket.start-connect +//go:wasmimport wasi:sockets/tcp@0.2.1 [method]tcp-socket.start-connect //go:noescape func wasmimport_TCPSocketStartConnect(self0 uint32, network0 uint32, remoteAddress0 uint32, remoteAddress1 uint32, remoteAddress2 uint32, remoteAddress3 uint32, remoteAddress4 uint32, remoteAddress5 uint32, remoteAddress6 uint32, remoteAddress7 uint32, remoteAddress8 uint32, remoteAddress9 uint32, remoteAddress10 uint32, remoteAddress11 uint32, result *cm.Result[network.ErrorCode, struct{}, network.ErrorCode]) @@ -809,7 +809,7 @@ func (self TCPSocket) StartListen() (result cm.Result[network.ErrorCode, struct{ return } -//go:wasmimport wasi:sockets/tcp@0.2.0 [method]tcp-socket.start-listen +//go:wasmimport wasi:sockets/tcp@0.2.1 [method]tcp-socket.start-listen //go:noescape func wasmimport_TCPSocketStartListen(self0 uint32, result *cm.Result[network.ErrorCode, struct{}, network.ErrorCode]) @@ -827,8 +827,8 @@ func wasmimport_TCPSocketStartListen(self0 uint32, result *cm.Result[network.Err // `subscribe` only has to be called once per socket and can then be // (re)used for the remainder of the socket's lifetime. // -// See -// for a more information. +// See +// for more information. // // Note: this function is here for WASI Preview2 only. // It's planned to be removed when `future` is natively supported in Preview3. @@ -843,6 +843,6 @@ func (self TCPSocket) Subscribe() (result poll.Pollable) { return } -//go:wasmimport wasi:sockets/tcp@0.2.0 [method]tcp-socket.subscribe +//go:wasmimport wasi:sockets/tcp@0.2.1 [method]tcp-socket.subscribe //go:noescape func wasmimport_TCPSocketSubscribe(self0 uint32) (result0 uint32) diff --git a/bindings/wasi/sockets/udp-create-socket/udp-create-socket.wit.go b/bindings/wasi/sockets/udp-create-socket/udp-create-socket.wit.go index 719fa39..05474b1 100644 --- a/bindings/wasi/sockets/udp-create-socket/udp-create-socket.wit.go +++ b/bindings/wasi/sockets/udp-create-socket/udp-create-socket.wit.go @@ -1,12 +1,12 @@ // Code generated by wit-bindgen-go. DO NOT EDIT. -// Package udpcreatesocket represents the imported interface "wasi:sockets/udp-create-socket@0.2.0". +// Package udpcreatesocket represents the imported interface "wasi:sockets/udp-create-socket@0.2.1". package udpcreatesocket import ( + "github.com/bytecodealliance/wasm-tools-go/cm" "github.com/rvolosatovs/west/bindings/wasi/sockets/network" "github.com/rvolosatovs/west/bindings/wasi/sockets/udp" - "github.com/ydnar/wasm-tools-go/cm" ) // CreateUDPSocket represents the imported function "create-udp-socket". @@ -47,6 +47,6 @@ func CreateUDPSocket(addressFamily network.IPAddressFamily) (result cm.Result[ud return } -//go:wasmimport wasi:sockets/udp-create-socket@0.2.0 create-udp-socket +//go:wasmimport wasi:sockets/udp-create-socket@0.2.1 create-udp-socket //go:noescape func wasmimport_CreateUDPSocket(addressFamily0 uint32, result *cm.Result[udp.UDPSocket, udp.UDPSocket, network.ErrorCode]) diff --git a/bindings/wasi/sockets/udp/abi.go b/bindings/wasi/sockets/udp/abi.go index 75b46b8..a7e5ee7 100644 --- a/bindings/wasi/sockets/udp/abi.go +++ b/bindings/wasi/sockets/udp/abi.go @@ -3,8 +3,8 @@ package udp import ( + "github.com/bytecodealliance/wasm-tools-go/cm" "github.com/rvolosatovs/west/bindings/wasi/sockets/network" - "github.com/ydnar/wasm-tools-go/cm" "unsafe" ) diff --git a/bindings/wasi/sockets/udp/udp.wit.go b/bindings/wasi/sockets/udp/udp.wit.go index 2be6d6e..f104c6f 100644 --- a/bindings/wasi/sockets/udp/udp.wit.go +++ b/bindings/wasi/sockets/udp/udp.wit.go @@ -1,15 +1,15 @@ // Code generated by wit-bindgen-go. DO NOT EDIT. -// Package udp represents the imported interface "wasi:sockets/udp@0.2.0". +// Package udp represents the imported interface "wasi:sockets/udp@0.2.1". package udp import ( + "github.com/bytecodealliance/wasm-tools-go/cm" "github.com/rvolosatovs/west/bindings/wasi/io/poll" "github.com/rvolosatovs/west/bindings/wasi/sockets/network" - "github.com/ydnar/wasm-tools-go/cm" ) -// IncomingDatagram represents the record "wasi:sockets/udp@0.2.0#incoming-datagram". +// IncomingDatagram represents the record "wasi:sockets/udp@0.2.1#incoming-datagram". // // A received datagram. // @@ -32,7 +32,7 @@ type IncomingDatagram struct { RemoteAddress network.IPSocketAddress } -// OutgoingDatagram represents the record "wasi:sockets/udp@0.2.0#outgoing-datagram". +// OutgoingDatagram represents the record "wasi:sockets/udp@0.2.1#outgoing-datagram". // // A datagram to be sent out. // @@ -56,7 +56,7 @@ type OutgoingDatagram struct { RemoteAddress cm.Option[network.IPSocketAddress] } -// UDPSocket represents the imported resource "wasi:sockets/udp@0.2.0#udp-socket". +// UDPSocket represents the imported resource "wasi:sockets/udp@0.2.1#udp-socket". // // A UDP socket handle. // @@ -74,7 +74,7 @@ func (self UDPSocket) ResourceDrop() { return } -//go:wasmimport wasi:sockets/udp@0.2.0 [resource-drop]udp-socket +//go:wasmimport wasi:sockets/udp@0.2.1 [resource-drop]udp-socket //go:noescape func wasmimport_UDPSocketResourceDrop(self0 uint32) @@ -94,7 +94,7 @@ func (self UDPSocket) AddressFamily() (result network.IPAddressFamily) { return } -//go:wasmimport wasi:sockets/udp@0.2.0 [method]udp-socket.address-family +//go:wasmimport wasi:sockets/udp@0.2.1 [method]udp-socket.address-family //go:noescape func wasmimport_UDPSocketAddressFamily(self0 uint32) (result0 uint32) @@ -109,7 +109,7 @@ func (self UDPSocket) FinishBind() (result cm.Result[network.ErrorCode, struct{} return } -//go:wasmimport wasi:sockets/udp@0.2.0 [method]udp-socket.finish-bind +//go:wasmimport wasi:sockets/udp@0.2.1 [method]udp-socket.finish-bind //go:noescape func wasmimport_UDPSocketFinishBind(self0 uint32, result *cm.Result[network.ErrorCode, struct{}, network.ErrorCode]) @@ -142,7 +142,7 @@ func (self UDPSocket) LocalAddress() (result cm.Result[IPSocketAddressShape, net return } -//go:wasmimport wasi:sockets/udp@0.2.0 [method]udp-socket.local-address +//go:wasmimport wasi:sockets/udp@0.2.1 [method]udp-socket.local-address //go:noescape func wasmimport_UDPSocketLocalAddress(self0 uint32, result *cm.Result[IPSocketAddressShape, network.IPSocketAddress, network.ErrorCode]) @@ -170,7 +170,7 @@ func (self UDPSocket) ReceiveBufferSize() (result cm.Result[uint64, uint64, netw return } -//go:wasmimport wasi:sockets/udp@0.2.0 [method]udp-socket.receive-buffer-size +//go:wasmimport wasi:sockets/udp@0.2.1 [method]udp-socket.receive-buffer-size //go:noescape func wasmimport_UDPSocketReceiveBufferSize(self0 uint32, result *cm.Result[uint64, uint64, network.ErrorCode]) @@ -196,7 +196,7 @@ func (self UDPSocket) RemoteAddress() (result cm.Result[IPSocketAddressShape, ne return } -//go:wasmimport wasi:sockets/udp@0.2.0 [method]udp-socket.remote-address +//go:wasmimport wasi:sockets/udp@0.2.1 [method]udp-socket.remote-address //go:noescape func wasmimport_UDPSocketRemoteAddress(self0 uint32, result *cm.Result[IPSocketAddressShape, network.IPSocketAddress, network.ErrorCode]) @@ -211,7 +211,7 @@ func (self UDPSocket) SendBufferSize() (result cm.Result[uint64, uint64, network return } -//go:wasmimport wasi:sockets/udp@0.2.0 [method]udp-socket.send-buffer-size +//go:wasmimport wasi:sockets/udp@0.2.1 [method]udp-socket.send-buffer-size //go:noescape func wasmimport_UDPSocketSendBufferSize(self0 uint32, result *cm.Result[uint64, uint64, network.ErrorCode]) @@ -227,7 +227,7 @@ func (self UDPSocket) SetReceiveBufferSize(value uint64) (result cm.Result[netwo return } -//go:wasmimport wasi:sockets/udp@0.2.0 [method]udp-socket.set-receive-buffer-size +//go:wasmimport wasi:sockets/udp@0.2.1 [method]udp-socket.set-receive-buffer-size //go:noescape func wasmimport_UDPSocketSetReceiveBufferSize(self0 uint32, value0 uint64, result *cm.Result[network.ErrorCode, struct{}, network.ErrorCode]) @@ -243,7 +243,7 @@ func (self UDPSocket) SetSendBufferSize(value uint64) (result cm.Result[network. return } -//go:wasmimport wasi:sockets/udp@0.2.0 [method]udp-socket.set-send-buffer-size +//go:wasmimport wasi:sockets/udp@0.2.1 [method]udp-socket.set-send-buffer-size //go:noescape func wasmimport_UDPSocketSetSendBufferSize(self0 uint32, value0 uint64, result *cm.Result[network.ErrorCode, struct{}, network.ErrorCode]) @@ -259,7 +259,7 @@ func (self UDPSocket) SetUnicastHopLimit(value uint8) (result cm.Result[network. return } -//go:wasmimport wasi:sockets/udp@0.2.0 [method]udp-socket.set-unicast-hop-limit +//go:wasmimport wasi:sockets/udp@0.2.1 [method]udp-socket.set-unicast-hop-limit //go:noescape func wasmimport_UDPSocketSetUnicastHopLimit(self0 uint32, value0 uint32, result *cm.Result[network.ErrorCode, struct{}, network.ErrorCode]) @@ -309,7 +309,7 @@ func (self UDPSocket) StartBind(network_ network.Network, localAddress network.I return } -//go:wasmimport wasi:sockets/udp@0.2.0 [method]udp-socket.start-bind +//go:wasmimport wasi:sockets/udp@0.2.1 [method]udp-socket.start-bind //go:noescape func wasmimport_UDPSocketStartBind(self0 uint32, network0 uint32, localAddress0 uint32, localAddress1 uint32, localAddress2 uint32, localAddress3 uint32, localAddress4 uint32, localAddress5 uint32, localAddress6 uint32, localAddress7 uint32, localAddress8 uint32, localAddress9 uint32, localAddress10 uint32, localAddress11 uint32, result *cm.Result[network.ErrorCode, struct{}, network.ErrorCode]) @@ -377,7 +377,7 @@ func (self UDPSocket) Stream(remoteAddress cm.Option[network.IPSocketAddress]) ( return } -//go:wasmimport wasi:sockets/udp@0.2.0 [method]udp-socket.stream +//go:wasmimport wasi:sockets/udp@0.2.1 [method]udp-socket.stream //go:noescape func wasmimport_UDPSocketStream(self0 uint32, remoteAddress0 uint32, remoteAddress1 uint32, remoteAddress2 uint32, remoteAddress3 uint32, remoteAddress4 uint32, remoteAddress5 uint32, remoteAddress6 uint32, remoteAddress7 uint32, remoteAddress8 uint32, remoteAddress9 uint32, remoteAddress10 uint32, remoteAddress11 uint32, remoteAddress12 uint32, result *cm.Result[TupleIncomingDatagramStreamOutgoingDatagramStreamShape, cm.Tuple[IncomingDatagramStream, OutgoingDatagramStream], network.ErrorCode]) @@ -398,7 +398,7 @@ func (self UDPSocket) Subscribe() (result poll.Pollable) { return } -//go:wasmimport wasi:sockets/udp@0.2.0 [method]udp-socket.subscribe +//go:wasmimport wasi:sockets/udp@0.2.1 [method]udp-socket.subscribe //go:noescape func wasmimport_UDPSocketSubscribe(self0 uint32) (result0 uint32) @@ -420,11 +420,11 @@ func (self UDPSocket) UnicastHopLimit() (result cm.Result[uint8, uint8, network. return } -//go:wasmimport wasi:sockets/udp@0.2.0 [method]udp-socket.unicast-hop-limit +//go:wasmimport wasi:sockets/udp@0.2.1 [method]udp-socket.unicast-hop-limit //go:noescape func wasmimport_UDPSocketUnicastHopLimit(self0 uint32, result *cm.Result[uint8, uint8, network.ErrorCode]) -// IncomingDatagramStream represents the imported resource "wasi:sockets/udp@0.2.0#incoming-datagram-stream". +// IncomingDatagramStream represents the imported resource "wasi:sockets/udp@0.2.1#incoming-datagram-stream". // // resource incoming-datagram-stream type IncomingDatagramStream cm.Resource @@ -440,7 +440,7 @@ func (self IncomingDatagramStream) ResourceDrop() { return } -//go:wasmimport wasi:sockets/udp@0.2.0 [resource-drop]incoming-datagram-stream +//go:wasmimport wasi:sockets/udp@0.2.1 [resource-drop]incoming-datagram-stream //go:noescape func wasmimport_IncomingDatagramStreamResourceDrop(self0 uint32) @@ -482,7 +482,7 @@ func (self IncomingDatagramStream) Receive(maxResults uint64) (result cm.Result[ return } -//go:wasmimport wasi:sockets/udp@0.2.0 [method]incoming-datagram-stream.receive +//go:wasmimport wasi:sockets/udp@0.2.1 [method]incoming-datagram-stream.receive //go:noescape func wasmimport_IncomingDatagramStreamReceive(self0 uint32, maxResults0 uint64, result *cm.Result[cm.List[IncomingDatagram], cm.List[IncomingDatagram], network.ErrorCode]) @@ -503,11 +503,11 @@ func (self IncomingDatagramStream) Subscribe() (result poll.Pollable) { return } -//go:wasmimport wasi:sockets/udp@0.2.0 [method]incoming-datagram-stream.subscribe +//go:wasmimport wasi:sockets/udp@0.2.1 [method]incoming-datagram-stream.subscribe //go:noescape func wasmimport_IncomingDatagramStreamSubscribe(self0 uint32) (result0 uint32) -// OutgoingDatagramStream represents the imported resource "wasi:sockets/udp@0.2.0#outgoing-datagram-stream". +// OutgoingDatagramStream represents the imported resource "wasi:sockets/udp@0.2.1#outgoing-datagram-stream". // // resource outgoing-datagram-stream type OutgoingDatagramStream cm.Resource @@ -523,7 +523,7 @@ func (self OutgoingDatagramStream) ResourceDrop() { return } -//go:wasmimport wasi:sockets/udp@0.2.0 [resource-drop]outgoing-datagram-stream +//go:wasmimport wasi:sockets/udp@0.2.1 [resource-drop]outgoing-datagram-stream //go:noescape func wasmimport_OutgoingDatagramStreamResourceDrop(self0 uint32) @@ -550,7 +550,7 @@ func (self OutgoingDatagramStream) CheckSend() (result cm.Result[uint64, uint64, return } -//go:wasmimport wasi:sockets/udp@0.2.0 [method]outgoing-datagram-stream.check-send +//go:wasmimport wasi:sockets/udp@0.2.1 [method]outgoing-datagram-stream.check-send //go:noescape func wasmimport_OutgoingDatagramStreamCheckSend(self0 uint32, result *cm.Result[uint64, uint64, network.ErrorCode]) @@ -615,7 +615,7 @@ func (self OutgoingDatagramStream) Send(datagrams cm.List[OutgoingDatagram]) (re return } -//go:wasmimport wasi:sockets/udp@0.2.0 [method]outgoing-datagram-stream.send +//go:wasmimport wasi:sockets/udp@0.2.1 [method]outgoing-datagram-stream.send //go:noescape func wasmimport_OutgoingDatagramStreamSend(self0 uint32, datagrams0 *OutgoingDatagram, datagrams1 uint32, result *cm.Result[uint64, uint64, network.ErrorCode]) @@ -636,6 +636,6 @@ func (self OutgoingDatagramStream) Subscribe() (result poll.Pollable) { return } -//go:wasmimport wasi:sockets/udp@0.2.0 [method]outgoing-datagram-stream.subscribe +//go:wasmimport wasi:sockets/udp@0.2.1 [method]outgoing-datagram-stream.subscribe //go:noescape func wasmimport_OutgoingDatagramStreamSubscribe(self0 uint32) (result0 uint32) diff --git a/bindings/wasiext/http/ext/empty.s b/bindings/wasiext/http/ext/empty.s new file mode 100644 index 0000000..5444f20 --- /dev/null +++ b/bindings/wasiext/http/ext/empty.s @@ -0,0 +1,3 @@ +// This file exists for testing this package without WebAssembly, +// allowing empty function bodies with a //go:wasmimport directive. +// See https://pkg.go.dev/cmd/compile for more information. diff --git a/bindings/west/test/http-test/http-test.wit.go b/bindings/wasiext/http/ext/ext.wit.go similarity index 80% rename from bindings/west/test/http-test/http-test.wit.go rename to bindings/wasiext/http/ext/ext.wit.go index 5f8f7b7..3a2f4c5 100644 --- a/bindings/west/test/http-test/http-test.wit.go +++ b/bindings/wasiext/http/ext/ext.wit.go @@ -1,11 +1,11 @@ // Code generated by wit-bindgen-go. DO NOT EDIT. -// Package httptest represents the imported interface "west:test/http-test@0.1.0". -package httptest +// Package ext represents the imported interface "wasiext:http/ext@0.1.0". +package ext import ( + "github.com/bytecodealliance/wasm-tools-go/cm" "github.com/rvolosatovs/west/bindings/wasi/http/types" - "github.com/ydnar/wasm-tools-go/cm" ) // NewResponseOutparam represents the imported function "new-response-outparam". @@ -18,7 +18,7 @@ func NewResponseOutparam() (result cm.Tuple[types.ResponseOutparam, types.Future return } -//go:wasmimport west:test/http-test@0.1.0 new-response-outparam +//go:wasmimport wasiext:http/ext@0.1.0 new-response-outparam //go:noescape func wasmimport_NewResponseOutparam(result *cm.Tuple[types.ResponseOutparam, types.FutureIncomingResponse]) @@ -34,6 +34,6 @@ func NewIncomingRequest(req types.OutgoingRequest) (result types.IncomingRequest return } -//go:wasmimport west:test/http-test@0.1.0 new-incoming-request +//go:wasmimport wasiext:http/ext@0.1.0 new-incoming-request //go:noescape func wasmimport_NewIncomingRequest(req0 uint32) (result0 uint32) diff --git a/bindings/wasiext/http/imports/imports.wit.go b/bindings/wasiext/http/imports/imports.wit.go new file mode 100644 index 0000000..264ac0f --- /dev/null +++ b/bindings/wasiext/http/imports/imports.wit.go @@ -0,0 +1,4 @@ +// Code generated by wit-bindgen-go. DO NOT EDIT. + +// Package imports represents the world "wasiext:http/imports@0.1.0". +package imports diff --git a/bindings/west.go b/bindings/west.go index 4bdc1e5..907a833 100644 --- a/bindings/west.go +++ b/bindings/west.go @@ -1,7 +1,7 @@ -//go:generate go run ../cmd/west-bindgen-go -package bindings -output bindings.go +//go:generate go run github.com/rvolosatovs/west/cmd/west-bindgen-go -package bindings -output bindings.go package bindings import ( - _ "github.com/rvolosatovs/west/bindings/west/test/http-test" + _ "github.com/rvolosatovs/west/bindings/wasiext/http/ext" ) diff --git a/bindings/west/test/imports/imports.wit.go b/bindings/west/west/imports/imports.wit.go similarity index 52% rename from bindings/west/test/imports/imports.wit.go rename to bindings/west/west/imports/imports.wit.go index 7594946..b5c43fd 100644 --- a/bindings/west/test/imports/imports.wit.go +++ b/bindings/west/west/imports/imports.wit.go @@ -1,4 +1,4 @@ // Code generated by wit-bindgen-go. DO NOT EDIT. -// Package imports represents the world "west:test/imports@0.1.0". +// Package imports represents the world "west:west/imports@0.1.0". package imports diff --git a/build.go b/build.go new file mode 100644 index 0000000..2f5c2da --- /dev/null +++ b/build.go @@ -0,0 +1,15 @@ +//go:build !dev + +//go:generate cargo build -p west-sys --release +//go:generate cargo build -p west-passthrough --target wasm32-unknown-unknown --release +//go:generate wasm-tools component new target/wasm32-unknown-unknown/release/west_passthrough.wasm -o lib/passthrough.wasm + +package west + +// #cgo darwin,amd64 LDFLAGS: -L${SRCDIR}/lib/x86_64-darwin -lwest +// #cgo darwin,arm64 LDFLAGS: -L${SRCDIR}/lib/aarch64-darwin -lwest +// #cgo linux,amd64 LDFLAGS: -L${SRCDIR}/lib/x86_64-linux -lwest +// #cgo linux,arm64 LDFLAGS: -L${SRCDIR}/lib/aarch64-linux -lwest +// #cgo windows,amd64 LDFLAGS: -L${SRCDIR}/lib/x86_64-windows -lwest +// #cgo windows,arm64 LDFLAGS: -L${SRCDIR}/lib/aarch64-windows -lwest +import "C" diff --git a/build_dev.go b/build_dev.go new file mode 100644 index 0000000..44032ae --- /dev/null +++ b/build_dev.go @@ -0,0 +1,10 @@ +//go:build dev + +//go:generate cargo build -p west-sys +//go:generate cargo build -p west-passthrough --target wasm32-unknown-unknown +//go:generate wasm-tools component new target/wasm32-unknown-unknown/debug/west_passthrough.wasm -o lib/passthrough.wasm + +package west + +// #cgo LDFLAGS: -L${SRCDIR}/target/debug -lwest_sys +import "C" diff --git a/crates/passthrough/Cargo.toml b/crates/passthrough/Cargo.toml index 03092c7..c7dc2c9 100644 --- a/crates/passthrough/Cargo.toml +++ b/crates/passthrough/Cargo.toml @@ -10,7 +10,7 @@ license.workspace = true repository.workspace = true [lib] -crate-type = ["rlib", "cdylib"] +crate-type = ["cdylib"] [dependencies] -wit-bindgen = { workspace = true, features = ["realloc", "macros"] } +wasi-passthrough = { workspace = true } diff --git a/crates/passthrough/src/bindings.rs b/crates/passthrough/src/bindings.rs deleted file mode 100644 index 689dc4c..0000000 --- a/crates/passthrough/src/bindings.rs +++ /dev/null @@ -1,94 +0,0 @@ -use crate::Handler; - -wit_bindgen::generate!({ - world: "passthrough", - generate_all, -}); - -export!(Handler); - -//impl From for DescriptorType { -// fn from(value: wasi::filesystem::types::DescriptorType) -> Self { -// match value { -// wasi::filesystem::types::DescriptorType::Unknown => DescriptorType::Unknown, -// wasi::filesystem::types::DescriptorType::BlockDevice => DescriptorType::BlockDevice, -// wasi::filesystem::types::DescriptorType::CharacterDevice => { -// DescriptorType::CharacterDevice -// } -// wasi::filesystem::types::DescriptorType::Directory => DescriptorType::Directory, -// wasi::filesystem::types::DescriptorType::Fifo => DescriptorType::Fifo, -// wasi::filesystem::types::DescriptorType::SymbolicLink => DescriptorType::SymbolicLink, -// wasi::filesystem::types::DescriptorType::RegularFile => DescriptorType::RegularFile, -// wasi::filesystem::types::DescriptorType::Socket => DescriptorType::Socket, -// } -// } -//} -// -//impl From for ErrorCode { -// fn from(value: wasi::filesystem::types::ErrorCode) -> Self { -// match value { -// wasi::filesystem::types::ErrorCode::Access => ErrorCode::Access, -// wasi::filesystem::types::ErrorCode::WouldBlock => ErrorCode::WouldBlock, -// wasi::filesystem::types::ErrorCode::Already => ErrorCode::Already, -// wasi::filesystem::types::ErrorCode::BadDescriptor => ErrorCode::BadDescriptor, -// wasi::filesystem::types::ErrorCode::Busy => ErrorCode::Busy, -// wasi::filesystem::types::ErrorCode::Deadlock => ErrorCode::Deadlock, -// wasi::filesystem::types::ErrorCode::Quota => ErrorCode::Quota, -// wasi::filesystem::types::ErrorCode::Exist => ErrorCode::Exist, -// wasi::filesystem::types::ErrorCode::FileTooLarge => ErrorCode::FileTooLarge, -// wasi::filesystem::types::ErrorCode::IllegalByteSequence => { -// ErrorCode::IllegalByteSequence -// } -// wasi::filesystem::types::ErrorCode::InProgress => ErrorCode::InProgress, -// wasi::filesystem::types::ErrorCode::Interrupted => ErrorCode::Interrupted, -// wasi::filesystem::types::ErrorCode::Invalid => ErrorCode::Invalid, -// wasi::filesystem::types::ErrorCode::Io => ErrorCode::Io, -// wasi::filesystem::types::ErrorCode::IsDirectory => ErrorCode::IsDirectory, -// wasi::filesystem::types::ErrorCode::Loop => ErrorCode::Loop, -// wasi::filesystem::types::ErrorCode::TooManyLinks => ErrorCode::TooManyLinks, -// wasi::filesystem::types::ErrorCode::MessageSize => ErrorCode::MessageSize, -// wasi::filesystem::types::ErrorCode::NameTooLong => ErrorCode::NameTooLong, -// wasi::filesystem::types::ErrorCode::NoDevice => ErrorCode::NoDevice, -// wasi::filesystem::types::ErrorCode::NoEntry => ErrorCode::NoEntry, -// wasi::filesystem::types::ErrorCode::NoLock => ErrorCode::NoLock, -// wasi::filesystem::types::ErrorCode::InsufficientMemory => ErrorCode::InsufficientMemory, -// wasi::filesystem::types::ErrorCode::InsufficientSpace => ErrorCode::InsufficientSpace, -// wasi::filesystem::types::ErrorCode::NotDirectory => ErrorCode::NotDirectory, -// wasi::filesystem::types::ErrorCode::NotEmpty => ErrorCode::NotEmpty, -// wasi::filesystem::types::ErrorCode::NotRecoverable => ErrorCode::NotRecoverable, -// wasi::filesystem::types::ErrorCode::Unsupported => ErrorCode::Unsupported, -// wasi::filesystem::types::ErrorCode::NoTty => ErrorCode::NoTty, -// wasi::filesystem::types::ErrorCode::NoSuchDevice => ErrorCode::NoSuchDevice, -// wasi::filesystem::types::ErrorCode::Overflow => ErrorCode::Overflow, -// wasi::filesystem::types::ErrorCode::NotPermitted => ErrorCode::NotPermitted, -// wasi::filesystem::types::ErrorCode::Pipe => ErrorCode::Pipe, -// wasi::filesystem::types::ErrorCode::ReadOnly => ErrorCode::ReadOnly, -// wasi::filesystem::types::ErrorCode::InvalidSeek => ErrorCode::InvalidSeek, -// wasi::filesystem::types::ErrorCode::TextFileBusy => ErrorCode::TextFileBusy, -// wasi::filesystem::types::ErrorCode::CrossDevice => ErrorCode::CrossDevice, -// } -// } -//} -// -//impl From for DescriptorStat { -// fn from(value: wasi::filesystem::types::DescriptorStat) -> Self { -// DescriptorStat { -// type_: value.type_.into(), -// link_count: value.link_count, -// size: value.size, -// data_access_timestamp: value.data_modification_timestamp, -// data_modification_timestamp: value.data_modification_timestamp, -// status_change_timestamp: value.status_change_timestamp, -// } -// } -//} -// -//impl From for MetadataHashValue { -// fn from(value: wasi::filesystem::types::MetadataHashValue) -> Self { -// MetadataHashValue { -// upper: value.upper, -// lower: value.lower, -// } -// } -//} -// diff --git a/crates/passthrough/src/cli.rs b/crates/passthrough/src/cli.rs deleted file mode 100644 index 2dc0b04..0000000 --- a/crates/passthrough/src/cli.rs +++ /dev/null @@ -1,74 +0,0 @@ -use crate::bindings::{exports, wasi}; -use crate::Handler; - -use wasi::cli::terminal_input::TerminalInput; -use wasi::cli::terminal_output::TerminalOutput; -use wasi::cli::terminal_stderr; -use wasi::cli::terminal_stdin; -use wasi::cli::terminal_stdout; -use wasi::cli::{stderr, stdin, stdout}; - -impl exports::wasi::cli::environment::Guest for Handler { - fn get_environment() -> Vec<(String, String)> { - wasi::cli::environment::get_environment() - } - - fn get_arguments() -> Vec { - wasi::cli::environment::get_arguments() - } - - fn initial_cwd() -> Option { - wasi::cli::environment::initial_cwd() - } -} - -impl exports::wasi::cli::stdin::Guest for Handler { - fn get_stdin() -> exports::wasi::io::streams::InputStream { - exports::wasi::io::streams::InputStream::new(stdin::get_stdin()) - } -} - -impl exports::wasi::cli::stdout::Guest for Handler { - fn get_stdout() -> exports::wasi::io::streams::OutputStream { - exports::wasi::io::streams::OutputStream::new(stdout::get_stdout()) - } -} - -impl exports::wasi::cli::stderr::Guest for Handler { - fn get_stderr() -> exports::wasi::io::streams::OutputStream { - exports::wasi::io::streams::OutputStream::new(stderr::get_stderr()) - } -} - -impl exports::wasi::cli::terminal_input::Guest for Handler { - type TerminalInput = TerminalInput; -} - -impl exports::wasi::cli::terminal_input::GuestTerminalInput for TerminalInput {} - -impl exports::wasi::cli::terminal_output::Guest for Handler { - type TerminalOutput = TerminalOutput; -} - -impl exports::wasi::cli::terminal_output::GuestTerminalOutput for TerminalOutput {} - -impl exports::wasi::cli::terminal_stdin::Guest for Handler { - fn get_terminal_stdin() -> Option { - terminal_stdin::get_terminal_stdin() - .map(exports::wasi::cli::terminal_input::TerminalInput::new) - } -} - -impl exports::wasi::cli::terminal_stdout::Guest for Handler { - fn get_terminal_stdout() -> Option { - terminal_stdout::get_terminal_stdout() - .map(exports::wasi::cli::terminal_output::TerminalOutput::new) - } -} - -impl exports::wasi::cli::terminal_stderr::Guest for Handler { - fn get_terminal_stderr() -> Option { - terminal_stderr::get_terminal_stderr() - .map(exports::wasi::cli::terminal_output::TerminalOutput::new) - } -} diff --git a/crates/passthrough/src/clocks.rs b/crates/passthrough/src/clocks.rs deleted file mode 100644 index 4811584..0000000 --- a/crates/passthrough/src/clocks.rs +++ /dev/null @@ -1,24 +0,0 @@ -use wasi::clocks::monotonic_clock; -use wasi::clocks::monotonic_clock::Duration; -use wasi::clocks::monotonic_clock::Instant; - -use crate::bindings::{exports, wasi}; -use crate::Handler; - -impl exports::wasi::clocks::monotonic_clock::Guest for Handler { - fn now() -> Instant { - monotonic_clock::now() - } - - fn resolution() -> Duration { - monotonic_clock::resolution() - } - - fn subscribe_instant(when: Instant) -> exports::wasi::io::poll::Pollable { - exports::wasi::io::poll::Pollable::new(monotonic_clock::subscribe_instant(when)) - } - - fn subscribe_duration(when: Duration) -> exports::wasi::io::poll::Pollable { - exports::wasi::io::poll::Pollable::new(monotonic_clock::subscribe_duration(when)) - } -} diff --git a/crates/passthrough/src/filesystem.rs b/crates/passthrough/src/filesystem.rs deleted file mode 100644 index ee6897b..0000000 --- a/crates/passthrough/src/filesystem.rs +++ /dev/null @@ -1,253 +0,0 @@ -use exports::wasi::filesystem::types::DescriptorBorrow; - -use wasi::filesystem::types::{Descriptor, DirectoryEntryStream, Filesize}; - -use crate::bindings::{exports, wasi}; -use crate::Handler; - -impl exports::wasi::filesystem::preopens::Guest for Handler { - fn get_directories() -> Vec<(exports::wasi::filesystem::types::Descriptor, String)> { - todo!() - } -} - -impl exports::wasi::filesystem::types::Guest for Handler { - type Descriptor = Descriptor; - type DirectoryEntryStream = DirectoryEntryStream; - - fn filesystem_error_code( - err: exports::wasi::io::error::ErrorBorrow<'_>, - ) -> Option { - todo!() - } -} - -impl exports::wasi::filesystem::types::GuestDescriptor for Descriptor { - fn read_via_stream( - &self, - offset: Filesize, - ) -> Result - { - todo!() - } - - fn write_via_stream( - &self, - offset: Filesize, - ) -> Result - { - todo!() - } - - fn append_via_stream( - &self, - ) -> Result - { - todo!() - } - - fn advise( - &self, - offset: Filesize, - length: Filesize, - advice: exports::wasi::filesystem::types::Advice, - ) -> Result<(), exports::wasi::filesystem::types::ErrorCode> { - todo!() - } - - fn sync_data(&self) -> Result<(), exports::wasi::filesystem::types::ErrorCode> { - todo!() - } - - fn get_flags( - &self, - ) -> Result< - exports::wasi::filesystem::types::DescriptorFlags, - exports::wasi::filesystem::types::ErrorCode, - > { - todo!() - } - - fn get_type( - &self, - ) -> Result< - exports::wasi::filesystem::types::DescriptorType, - exports::wasi::filesystem::types::ErrorCode, - > { - todo!() - } - - fn set_size(&self, size: Filesize) -> Result<(), exports::wasi::filesystem::types::ErrorCode> { - todo!() - } - - fn set_times( - &self, - data_access_timestamp: exports::wasi::filesystem::types::NewTimestamp, - data_modification_timestamp: exports::wasi::filesystem::types::NewTimestamp, - ) -> Result<(), exports::wasi::filesystem::types::ErrorCode> { - todo!() - } - - fn read( - &self, - length: Filesize, - offset: Filesize, - ) -> Result<(Vec, bool), exports::wasi::filesystem::types::ErrorCode> { - todo!() - } - - fn write( - &self, - buffer: Vec, - offset: Filesize, - ) -> Result { - todo!() - } - - fn read_directory( - &self, - ) -> Result< - exports::wasi::filesystem::types::DirectoryEntryStream, - exports::wasi::filesystem::types::ErrorCode, - > { - todo!() - } - - fn sync(&self) -> Result<(), exports::wasi::filesystem::types::ErrorCode> { - todo!() - } - - fn create_directory_at( - &self, - path: String, - ) -> Result<(), exports::wasi::filesystem::types::ErrorCode> { - todo!() - } - - fn stat( - &self, - ) -> Result< - exports::wasi::filesystem::types::DescriptorStat, - exports::wasi::filesystem::types::ErrorCode, - > { - todo!() - } - - fn stat_at( - &self, - path_flags: exports::wasi::filesystem::types::PathFlags, - path: String, - ) -> Result< - exports::wasi::filesystem::types::DescriptorStat, - exports::wasi::filesystem::types::ErrorCode, - > { - todo!() - } - - fn set_times_at( - &self, - path_flags: exports::wasi::filesystem::types::PathFlags, - path: String, - data_access_timestamp: exports::wasi::filesystem::types::NewTimestamp, - data_modification_timestamp: exports::wasi::filesystem::types::NewTimestamp, - ) -> Result<(), exports::wasi::filesystem::types::ErrorCode> { - todo!() - } - - fn link_at( - &self, - old_path_flags: exports::wasi::filesystem::types::PathFlags, - old_path: String, - new_descriptor: DescriptorBorrow<'_>, - new_path: String, - ) -> Result<(), exports::wasi::filesystem::types::ErrorCode> { - todo!() - } - - fn open_at( - &self, - path_flags: exports::wasi::filesystem::types::PathFlags, - path: String, - open_flags: exports::wasi::filesystem::types::OpenFlags, - flags: exports::wasi::filesystem::types::DescriptorFlags, - ) -> Result< - exports::wasi::filesystem::types::Descriptor, - exports::wasi::filesystem::types::ErrorCode, - > { - todo!() - } - - fn readlink_at( - &self, - path: String, - ) -> Result { - todo!() - } - - fn remove_directory_at( - &self, - path: String, - ) -> Result<(), exports::wasi::filesystem::types::ErrorCode> { - todo!() - } - - fn rename_at( - &self, - old_path: String, - new_descriptor: DescriptorBorrow<'_>, - new_path: String, - ) -> Result<(), exports::wasi::filesystem::types::ErrorCode> { - todo!() - } - - fn symlink_at( - &self, - old_path: String, - new_path: String, - ) -> Result<(), exports::wasi::filesystem::types::ErrorCode> { - todo!() - } - - fn unlink_file_at( - &self, - path: String, - ) -> Result<(), exports::wasi::filesystem::types::ErrorCode> { - todo!() - } - - fn is_same_object(&self, other: DescriptorBorrow<'_>) -> bool { - todo!() - } - - fn metadata_hash( - &self, - ) -> Result< - exports::wasi::filesystem::types::MetadataHashValue, - exports::wasi::filesystem::types::ErrorCode, - > { - todo!() - } - - fn metadata_hash_at( - &self, - path_flags: exports::wasi::filesystem::types::PathFlags, - path: String, - ) -> Result< - exports::wasi::filesystem::types::MetadataHashValue, - exports::wasi::filesystem::types::ErrorCode, - > { - todo!() - } -} - -impl exports::wasi::filesystem::types::GuestDirectoryEntryStream for DirectoryEntryStream { - fn read_directory_entry( - &self, - ) -> Result< - Option, - exports::wasi::filesystem::types::ErrorCode, - > { - todo!() - } -} diff --git a/crates/passthrough/src/http.rs b/crates/passthrough/src/http.rs deleted file mode 100644 index ed7ff2b..0000000 --- a/crates/passthrough/src/http.rs +++ /dev/null @@ -1,611 +0,0 @@ -use exports::wasi::http::types::IoErrorBorrow; - -use wasi::http::types::Duration; -use wasi::http::types::{ - DnsErrorPayload, ErrorCode, FieldSizePayload, Fields, FutureIncomingResponse, FutureTrailers, - HeaderError, IncomingBody, IncomingRequest, IncomingResponse, Method, OutgoingBody, - OutgoingRequest, OutgoingResponse, RequestOptions, ResponseOutparam, Scheme, - TlsAlertReceivedPayload, -}; - -use crate::bindings::{exports, wasi}; -use crate::Handler; - -impl From for exports::wasi::http::types::Scheme { - fn from(value: Scheme) -> Self { - match value { - Scheme::Http => Self::Http, - Scheme::Https => Self::Https, - Scheme::Other(s) => Self::Other(s), - } - } -} - -impl From for Scheme { - fn from(value: exports::wasi::http::types::Scheme) -> Self { - match value { - exports::wasi::http::types::Scheme::Http => Self::Http, - exports::wasi::http::types::Scheme::Https => Self::Https, - exports::wasi::http::types::Scheme::Other(s) => Self::Other(s), - } - } -} - -impl From for exports::wasi::http::types::HeaderError { - fn from(value: HeaderError) -> Self { - match value { - HeaderError::InvalidSyntax => Self::InvalidSyntax, - HeaderError::Forbidden => Self::Forbidden, - HeaderError::Immutable => Self::Immutable, - } - } -} - -impl From for HeaderError { - fn from(value: exports::wasi::http::types::HeaderError) -> Self { - match value { - exports::wasi::http::types::HeaderError::InvalidSyntax => Self::InvalidSyntax, - exports::wasi::http::types::HeaderError::Forbidden => Self::Forbidden, - exports::wasi::http::types::HeaderError::Immutable => Self::Immutable, - } - } -} - -impl From for exports::wasi::http::types::Method { - fn from(value: Method) -> Self { - match value { - Method::Get => Self::Get, - Method::Head => Self::Head, - Method::Post => Self::Post, - Method::Put => Self::Put, - Method::Delete => Self::Delete, - Method::Connect => Self::Connect, - Method::Options => Self::Options, - Method::Trace => Self::Trace, - Method::Patch => Self::Patch, - Method::Other(s) => Self::Other(s), - } - } -} - -impl From for Method { - fn from(value: exports::wasi::http::types::Method) -> Self { - match value { - exports::wasi::http::types::Method::Get => Self::Get, - exports::wasi::http::types::Method::Head => Self::Head, - exports::wasi::http::types::Method::Post => Self::Post, - exports::wasi::http::types::Method::Put => Self::Put, - exports::wasi::http::types::Method::Delete => Self::Delete, - exports::wasi::http::types::Method::Connect => Self::Connect, - exports::wasi::http::types::Method::Options => Self::Options, - exports::wasi::http::types::Method::Trace => Self::Trace, - exports::wasi::http::types::Method::Patch => Self::Patch, - exports::wasi::http::types::Method::Other(s) => Self::Other(s), - } - } -} - -impl From for wasi::http::types::ErrorCode { - fn from(value: exports::wasi::http::types::ErrorCode) -> Self { - match value { - exports::wasi::http::types::ErrorCode::DnsTimeout => Self::DnsTimeout, - exports::wasi::http::types::ErrorCode::DnsError( - exports::wasi::http::types::DnsErrorPayload { rcode, info_code }, - ) => Self::DnsError(DnsErrorPayload { rcode, info_code }), - exports::wasi::http::types::ErrorCode::DestinationNotFound => Self::DestinationNotFound, - exports::wasi::http::types::ErrorCode::DestinationUnavailable => { - Self::DestinationUnavailable - } - exports::wasi::http::types::ErrorCode::DestinationIpProhibited => { - Self::DestinationIpProhibited - } - exports::wasi::http::types::ErrorCode::DestinationIpUnroutable => { - Self::DestinationIpUnroutable - } - exports::wasi::http::types::ErrorCode::ConnectionRefused => Self::ConnectionRefused, - exports::wasi::http::types::ErrorCode::ConnectionTerminated => { - Self::ConnectionTerminated - } - exports::wasi::http::types::ErrorCode::ConnectionTimeout => Self::ConnectionTimeout, - exports::wasi::http::types::ErrorCode::ConnectionReadTimeout => { - Self::ConnectionReadTimeout - } - exports::wasi::http::types::ErrorCode::ConnectionWriteTimeout => { - Self::ConnectionWriteTimeout - } - exports::wasi::http::types::ErrorCode::ConnectionLimitReached => { - Self::ConnectionLimitReached - } - exports::wasi::http::types::ErrorCode::TlsProtocolError => Self::TlsProtocolError, - exports::wasi::http::types::ErrorCode::TlsCertificateError => Self::TlsCertificateError, - exports::wasi::http::types::ErrorCode::TlsAlertReceived( - exports::wasi::http::types::TlsAlertReceivedPayload { - alert_id, - alert_message, - }, - ) => Self::TlsAlertReceived(TlsAlertReceivedPayload { - alert_id, - alert_message, - }), - exports::wasi::http::types::ErrorCode::HttpRequestDenied => Self::HttpRequestDenied, - exports::wasi::http::types::ErrorCode::HttpRequestLengthRequired => { - Self::HttpRequestLengthRequired - } - exports::wasi::http::types::ErrorCode::HttpRequestBodySize(s) => { - Self::HttpRequestBodySize(s) - } - exports::wasi::http::types::ErrorCode::HttpRequestMethodInvalid => { - Self::HttpRequestMethodInvalid - } - exports::wasi::http::types::ErrorCode::HttpRequestUriInvalid => { - Self::HttpRequestUriInvalid - } - exports::wasi::http::types::ErrorCode::HttpRequestUriTooLong => { - Self::HttpRequestUriTooLong - } - exports::wasi::http::types::ErrorCode::HttpRequestHeaderSectionSize(s) => { - Self::HttpRequestHeaderSectionSize(s) - } - exports::wasi::http::types::ErrorCode::HttpRequestHeaderSize(Some( - exports::wasi::http::types::FieldSizePayload { - field_name, - field_size, - }, - )) => Self::HttpRequestHeaderSize(Some(FieldSizePayload { - field_name, - field_size, - })), - exports::wasi::http::types::ErrorCode::HttpRequestHeaderSize(None) => { - Self::HttpRequestHeaderSize(None) - } - exports::wasi::http::types::ErrorCode::HttpRequestTrailerSectionSize(s) => { - Self::HttpRequestTrailerSectionSize(s) - } - exports::wasi::http::types::ErrorCode::HttpRequestTrailerSize( - exports::wasi::http::types::FieldSizePayload { - field_name, - field_size, - }, - ) => Self::HttpRequestTrailerSize(FieldSizePayload { - field_name, - field_size, - }), - exports::wasi::http::types::ErrorCode::HttpResponseIncomplete => { - Self::HttpResponseIncomplete - } - exports::wasi::http::types::ErrorCode::HttpResponseHeaderSectionSize(s) => { - Self::HttpResponseHeaderSectionSize(s) - } - exports::wasi::http::types::ErrorCode::HttpResponseHeaderSize( - exports::wasi::http::types::FieldSizePayload { - field_name, - field_size, - }, - ) => Self::HttpResponseHeaderSize(FieldSizePayload { - field_name, - field_size, - }), - exports::wasi::http::types::ErrorCode::HttpResponseBodySize(s) => { - Self::HttpResponseBodySize(s) - } - exports::wasi::http::types::ErrorCode::HttpResponseTrailerSectionSize(s) => { - Self::HttpResponseTrailerSectionSize(s) - } - exports::wasi::http::types::ErrorCode::HttpResponseTrailerSize( - exports::wasi::http::types::FieldSizePayload { - field_name, - field_size, - }, - ) => Self::HttpResponseTrailerSize(FieldSizePayload { - field_name, - field_size, - }), - exports::wasi::http::types::ErrorCode::HttpResponseTransferCoding(e) => { - Self::HttpResponseTransferCoding(e) - } - exports::wasi::http::types::ErrorCode::HttpResponseContentCoding(e) => { - Self::HttpResponseContentCoding(e) - } - exports::wasi::http::types::ErrorCode::HttpResponseTimeout => Self::HttpResponseTimeout, - exports::wasi::http::types::ErrorCode::HttpUpgradeFailed => Self::HttpUpgradeFailed, - exports::wasi::http::types::ErrorCode::HttpProtocolError => Self::HttpProtocolError, - exports::wasi::http::types::ErrorCode::LoopDetected => Self::LoopDetected, - exports::wasi::http::types::ErrorCode::ConfigurationError => Self::ConfigurationError, - exports::wasi::http::types::ErrorCode::InternalError(e) => Self::InternalError(e), - } - } -} - -impl From for exports::wasi::http::types::ErrorCode { - fn from(value: ErrorCode) -> Self { - match value { - ErrorCode::DnsTimeout => Self::DnsTimeout, - ErrorCode::DnsError(DnsErrorPayload { rcode, info_code }) => { - Self::DnsError(exports::wasi::http::types::DnsErrorPayload { rcode, info_code }) - } - ErrorCode::DestinationNotFound => Self::DestinationNotFound, - ErrorCode::DestinationUnavailable => Self::DestinationUnavailable, - ErrorCode::DestinationIpProhibited => Self::DestinationIpProhibited, - ErrorCode::DestinationIpUnroutable => Self::DestinationIpUnroutable, - ErrorCode::ConnectionRefused => Self::ConnectionRefused, - ErrorCode::ConnectionTerminated => Self::ConnectionTerminated, - ErrorCode::ConnectionTimeout => Self::ConnectionTimeout, - ErrorCode::ConnectionReadTimeout => Self::ConnectionReadTimeout, - ErrorCode::ConnectionWriteTimeout => Self::ConnectionWriteTimeout, - ErrorCode::ConnectionLimitReached => Self::ConnectionLimitReached, - ErrorCode::TlsProtocolError => Self::TlsProtocolError, - ErrorCode::TlsCertificateError => Self::TlsCertificateError, - ErrorCode::TlsAlertReceived(TlsAlertReceivedPayload { - alert_id, - alert_message, - }) => Self::TlsAlertReceived(exports::wasi::http::types::TlsAlertReceivedPayload { - alert_id, - alert_message, - }), - ErrorCode::HttpRequestDenied => Self::HttpRequestDenied, - ErrorCode::HttpRequestLengthRequired => Self::HttpRequestLengthRequired, - ErrorCode::HttpRequestBodySize(s) => Self::HttpRequestBodySize(s), - ErrorCode::HttpRequestMethodInvalid => Self::HttpRequestMethodInvalid, - ErrorCode::HttpRequestUriInvalid => Self::HttpRequestUriInvalid, - ErrorCode::HttpRequestUriTooLong => Self::HttpRequestUriTooLong, - ErrorCode::HttpRequestHeaderSectionSize(s) => Self::HttpRequestHeaderSectionSize(s), - ErrorCode::HttpRequestHeaderSize(Some(FieldSizePayload { - field_name, - field_size, - })) => { - Self::HttpRequestHeaderSize(Some(exports::wasi::http::types::FieldSizePayload { - field_name, - field_size, - })) - } - ErrorCode::HttpRequestHeaderSize(None) => Self::HttpRequestHeaderSize(None), - ErrorCode::HttpRequestTrailerSectionSize(s) => Self::HttpRequestTrailerSectionSize(s), - ErrorCode::HttpRequestTrailerSize(FieldSizePayload { - field_name, - field_size, - }) => Self::HttpRequestTrailerSize(exports::wasi::http::types::FieldSizePayload { - field_name, - field_size, - }), - ErrorCode::HttpResponseIncomplete => Self::HttpResponseIncomplete, - ErrorCode::HttpResponseHeaderSectionSize(s) => Self::HttpResponseHeaderSectionSize(s), - ErrorCode::HttpResponseHeaderSize(FieldSizePayload { - field_name, - field_size, - }) => Self::HttpResponseHeaderSize(exports::wasi::http::types::FieldSizePayload { - field_name, - field_size, - }), - ErrorCode::HttpResponseBodySize(s) => Self::HttpResponseBodySize(s), - ErrorCode::HttpResponseTrailerSectionSize(s) => Self::HttpResponseTrailerSectionSize(s), - ErrorCode::HttpResponseTrailerSize(FieldSizePayload { - field_name, - field_size, - }) => Self::HttpResponseTrailerSize(exports::wasi::http::types::FieldSizePayload { - field_name, - field_size, - }), - ErrorCode::HttpResponseTransferCoding(e) => Self::HttpResponseTransferCoding(e), - ErrorCode::HttpResponseContentCoding(e) => Self::HttpResponseContentCoding(e), - ErrorCode::HttpResponseTimeout => Self::HttpResponseTimeout, - ErrorCode::HttpUpgradeFailed => Self::HttpUpgradeFailed, - ErrorCode::HttpProtocolError => Self::HttpProtocolError, - ErrorCode::LoopDetected => Self::LoopDetected, - ErrorCode::ConfigurationError => Self::ConfigurationError, - ErrorCode::InternalError(e) => Self::InternalError(e), - } - } -} - -impl exports::wasi::http::outgoing_handler::Guest for Handler { - fn handle( - request: exports::wasi::http::types::OutgoingRequest, - options: Option, - ) -> Result< - exports::wasi::http::types::FutureIncomingResponse, - exports::wasi::http::types::ErrorCode, - > { - todo!() - } -} - -impl exports::wasi::http::types::Guest for Handler { - type Fields = Fields; - type IncomingRequest = IncomingRequest; - type OutgoingRequest = OutgoingRequest; - type RequestOptions = RequestOptions; - type ResponseOutparam = ResponseOutparam; - type IncomingResponse = IncomingResponse; - type IncomingBody = IncomingBody; - type FutureTrailers = FutureTrailers; - type OutgoingResponse = OutgoingResponse; - type OutgoingBody = OutgoingBody; - type FutureIncomingResponse = FutureIncomingResponse; - - fn http_error_code(err: IoErrorBorrow<'_>) -> Option { - todo!() - } -} - -impl exports::wasi::http::types::GuestFields for wasi::http::types::Fields { - fn new() -> Self { - Self::new() - } - - fn get(&self, name: String) -> Vec> { - Self::get(self, &name) - } - - fn set( - &self, - name: String, - value: Vec>, - ) -> Result<(), exports::wasi::http::types::HeaderError> { - Self::set(self, &name, &value)?; - Ok(()) - } - - fn delete(&self, name: String) -> Result<(), exports::wasi::http::types::HeaderError> { - Self::delete(self, &name)?; - Ok(()) - } - - fn append( - &self, - name: String, - value: Vec, - ) -> Result<(), exports::wasi::http::types::HeaderError> { - Self::append(self, &name, &value)?; - Ok(()) - } - - fn entries(&self) -> Vec<(String, Vec)> { - Self::entries(self) - } - - fn clone(&self) -> exports::wasi::http::types::Fields { - exports::wasi::http::types::Fields::new(Self::clone(self)) - } - - fn from_list( - entries: Vec<(String, Vec)>, - ) -> Result { - let ret = Self::from_list(&entries)?; - Ok(exports::wasi::http::types::Fields::new(ret)) - } - - fn has(&self, name: String) -> bool { - Self::has(self, &name) - } -} - -impl exports::wasi::http::types::GuestIncomingRequest for IncomingRequest { - fn method(&self) -> exports::wasi::http::types::Method { - Self::method(self).into() - } - fn path_with_query(&self) -> Option { - Self::path_with_query(self) - } - fn scheme(&self) -> Option { - Self::scheme(self).map(Into::into) - } - fn authority(&self) -> Option { - Self::authority(self) - } - fn headers(&self) -> exports::wasi::http::types::Fields { - exports::wasi::http::types::Fields::new(Self::headers(self)) - } - fn consume(&self) -> Result { - let ret = Self::consume(self)?; - Ok(exports::wasi::http::types::IncomingBody::new(ret)) - } -} - -impl exports::wasi::http::types::GuestOutgoingRequest for OutgoingRequest { - fn new(headers: exports::wasi::http::types::Headers) -> Self { - Self::new(headers.into_inner()) - } - - fn body(&self) -> Result { - let ret = Self::body(self)?; - Ok(exports::wasi::http::types::OutgoingBody::new(ret)) - } - - fn method(&self) -> exports::wasi::http::types::Method { - Self::method(self).into() - } - - fn set_method(&self, method: exports::wasi::http::types::Method) -> Result<(), ()> { - Self::set_method(self, &method.into()) - } - - fn path_with_query(&self) -> Option { - Self::path_with_query(self) - } - - fn set_path_with_query(&self, path_with_query: Option) -> Result<(), ()> { - Self::set_path_with_query(self, path_with_query.as_deref()) - } - - fn scheme(&self) -> Option { - Self::scheme(self).map(Into::into) - } - - fn set_scheme(&self, scheme: Option) -> Result<(), ()> { - Self::set_scheme(self, scheme.map(Into::into).as_ref()) - } - - fn authority(&self) -> Option { - Self::authority(self) - } - - fn set_authority(&self, authority: Option) -> Result<(), ()> { - Self::set_authority(self, authority.as_deref()) - } - - fn headers(&self) -> exports::wasi::http::types::Headers { - exports::wasi::http::types::Headers::new(Self::headers(self)) - } -} - -impl exports::wasi::http::types::GuestRequestOptions for RequestOptions { - fn new() -> Self { - Self::new() - } - fn connect_timeout(&self) -> Option { - Self::connect_timeout(self) - } - fn set_connect_timeout(&self, duration: Option) -> Result<(), ()> { - Self::set_connect_timeout(self, duration) - } - fn first_byte_timeout(&self) -> Option { - Self::first_byte_timeout(self) - } - fn set_first_byte_timeout(&self, duration: Option) -> Result<(), ()> { - Self::set_first_byte_timeout(self, duration) - } - fn between_bytes_timeout(&self) -> Option { - Self::between_bytes_timeout(self) - } - fn set_between_bytes_timeout(&self, duration: Option) -> Result<(), ()> { - Self::set_between_bytes_timeout(self, duration) - } -} - -impl exports::wasi::http::types::GuestResponseOutparam for ResponseOutparam { - fn set( - param: exports::wasi::http::types::ResponseOutparam, - response: Result< - exports::wasi::http::types::OutgoingResponse, - exports::wasi::http::types::ErrorCode, - >, - ) { - Self::set( - param.into_inner(), - response - .map(exports::wasi::http::types::OutgoingResponse::into_inner) - .map_err(Into::into), - ); - } -} - -impl exports::wasi::http::types::GuestIncomingResponse for IncomingResponse { - fn status(&self) -> exports::wasi::http::types::StatusCode { - Self::status(self) - } - fn headers(&self) -> exports::wasi::http::types::Fields { - exports::wasi::http::types::Fields::new(Self::headers(self)) - } - fn consume(&self) -> Result { - Self::consume(self).map(exports::wasi::http::types::IncomingBody::new) - } -} - -impl exports::wasi::http::types::GuestIncomingBody for IncomingBody { - fn stream(&self) -> Result { - Self::stream(self).map(exports::wasi::io::streams::InputStream::new) - } - - fn finish( - body: exports::wasi::http::types::IncomingBody, - ) -> exports::wasi::http::types::FutureTrailers { - exports::wasi::http::types::FutureTrailers::new(Self::finish(body.into_inner())) - } -} - -impl exports::wasi::http::types::GuestFutureTrailers for FutureTrailers { - fn subscribe(&self) -> exports::wasi::io::poll::Pollable { - exports::wasi::io::poll::Pollable::new(Self::subscribe(self)) - } - - fn get( - &self, - ) -> Option< - Result< - Result< - Option, - exports::wasi::http::types::ErrorCode, - >, - (), - >, - > { - match Self::get(self)? { - Ok(Ok(Some(fields))) => Some(Ok(Ok(Some(exports::wasi::http::types::Fields::new( - fields, - ))))), - Ok(Ok(None)) => Some(Ok(Ok(None))), - Ok(Err(code)) => Some(Ok(Err(code.into()))), - Err(()) => Some(Err(())), - } - } -} - -impl exports::wasi::http::types::GuestOutgoingResponse for OutgoingResponse { - fn new(headers: exports::wasi::http::types::Fields) -> Self { - Self::new(headers.into_inner()) - } - - fn status_code(&self) -> exports::wasi::http::types::StatusCode { - Self::status_code(self) - } - - fn set_status_code( - &self, - status_code: exports::wasi::http::types::StatusCode, - ) -> Result<(), ()> { - Self::set_status_code(self, status_code) - } - - fn headers(&self) -> exports::wasi::http::types::Headers { - exports::wasi::http::types::Headers::new(Self::headers(self)) - } - - fn body(&self) -> Result { - let ret = Self::body(self)?; - Ok(exports::wasi::http::types::OutgoingBody::new(ret)) - } -} - -impl exports::wasi::http::types::GuestOutgoingBody for OutgoingBody { - fn write(&self) -> Result { - let ret = Self::write(self)?; - Ok(exports::wasi::io::streams::OutputStream::new(ret)) - } - - fn finish( - body: exports::wasi::http::types::OutgoingBody, - trailers: Option, - ) -> Result<(), exports::wasi::http::types::ErrorCode> { - Self::finish( - body.into_inner(), - trailers.map(exports::wasi::http::types::Fields::into_inner), - )?; - Ok(()) - } -} - -impl exports::wasi::http::types::GuestFutureIncomingResponse for FutureIncomingResponse { - fn subscribe(&self) -> exports::wasi::io::poll::Pollable { - exports::wasi::io::poll::Pollable::new(Self::subscribe(self)) - } - - fn get( - &self, - ) -> Option< - Result< - Result< - exports::wasi::http::types::IncomingResponse, - exports::wasi::http::types::ErrorCode, - >, - (), - >, - > { - match Self::get(self)? { - Ok(Ok(res)) => Some(Ok(Ok(exports::wasi::http::types::IncomingResponse::new( - res, - )))), - Ok(Err(code)) => Some(Ok(Err(code.into()))), - Err(()) => Some(Err(())), - } - } -} diff --git a/crates/passthrough/src/io.rs b/crates/passthrough/src/io.rs deleted file mode 100644 index 15c1f3b..0000000 --- a/crates/passthrough/src/io.rs +++ /dev/null @@ -1,148 +0,0 @@ -use crate::bindings::{exports, wasi}; -use crate::Handler; - -use exports::wasi::io::poll::PollableBorrow; -use exports::wasi::io::streams::InputStreamBorrow; - -use wasi::io::error::Error; -use wasi::io::poll::{self, Pollable}; -use wasi::io::streams::{InputStream, OutputStream, StreamError}; - -impl From for exports::wasi::io::streams::StreamError { - fn from(value: StreamError) -> Self { - match value { - StreamError::LastOperationFailed(err) => { - Self::LastOperationFailed(exports::wasi::io::error::Error::new(err)) - } - StreamError::Closed => Self::Closed, - } - } -} - -impl exports::wasi::io::error::Guest for Handler { - type Error = Error; -} - -impl exports::wasi::io::error::GuestError for Error { - fn to_debug_string(&self) -> String { - Self::to_debug_string(self) - } -} - -impl exports::wasi::io::streams::Guest for Handler { - type InputStream = InputStream; - type OutputStream = OutputStream; -} - -impl exports::wasi::io::streams::GuestInputStream for InputStream { - fn read(&self, len: u64) -> Result, exports::wasi::io::streams::StreamError> { - let ret = Self::read(self, len)?; - Ok(ret) - } - - fn blocking_read(&self, len: u64) -> Result, exports::wasi::io::streams::StreamError> { - let ret = Self::blocking_read(self, len)?; - Ok(ret) - } - - fn skip(&self, len: u64) -> Result { - let ret = Self::skip(self, len)?; - Ok(ret) - } - - fn blocking_skip(&self, len: u64) -> Result { - let ret = Self::blocking_skip(self, len)?; - Ok(ret) - } - - fn subscribe(&self) -> exports::wasi::io::poll::Pollable { - exports::wasi::io::poll::Pollable::new(Self::subscribe(self)) - } -} - -impl exports::wasi::io::streams::GuestOutputStream for OutputStream { - fn check_write(&self) -> Result { - let ret = Self::check_write(self)?; - Ok(ret) - } - - fn write(&self, contents: Vec) -> Result<(), exports::wasi::io::streams::StreamError> { - Self::write(self, &contents)?; - Ok(()) - } - - fn blocking_write_and_flush( - &self, - contents: Vec, - ) -> Result<(), exports::wasi::io::streams::StreamError> { - Self::blocking_write_and_flush(self, &contents)?; - Ok(()) - } - - fn flush(&self) -> Result<(), exports::wasi::io::streams::StreamError> { - Self::flush(self)?; - Ok(()) - } - - fn blocking_flush(&self) -> Result<(), exports::wasi::io::streams::StreamError> { - Self::blocking_flush(self)?; - Ok(()) - } - - fn subscribe(&self) -> exports::wasi::io::poll::Pollable { - exports::wasi::io::poll::Pollable::new(Self::subscribe(self)) - } - - fn write_zeroes(&self, len: u64) -> Result<(), exports::wasi::io::streams::StreamError> { - Self::write_zeroes(self, len)?; - Ok(()) - } - - fn blocking_write_zeroes_and_flush( - &self, - len: u64, - ) -> Result<(), exports::wasi::io::streams::StreamError> { - Self::blocking_write_zeroes_and_flush(self, len)?; - Ok(()) - } - - fn splice( - &self, - src: InputStreamBorrow<'_>, - len: u64, - ) -> Result { - let ret = Self::splice(self, src.get(), len)?; - Ok(ret) - } - - fn blocking_splice( - &self, - src: InputStreamBorrow<'_>, - len: u64, - ) -> Result { - let ret = Self::blocking_splice(self, src.get(), len)?; - Ok(ret) - } -} - -impl exports::wasi::io::poll::Guest for Handler { - type Pollable = Pollable; - - fn poll(in_: Vec>) -> Vec { - poll::poll( - &in_.iter() - .map(exports::wasi::io::poll::PollableBorrow::get) - .collect::>(), - ) - } -} - -impl exports::wasi::io::poll::GuestPollable for Pollable { - fn ready(&self) -> bool { - Self::ready(self) - } - - fn block(&self) { - Self::block(self); - } -} diff --git a/crates/passthrough/src/lib.rs b/crates/passthrough/src/lib.rs index 263333a..09b95e5 100644 --- a/crates/passthrough/src/lib.rs +++ b/crates/passthrough/src/lib.rs @@ -1,10 +1 @@ -mod bindings; -mod cli; -mod clocks; -mod filesystem; -mod http; -mod io; -mod sockets; -mod west; - -pub struct Handler; +use wasi_passthrough as _; diff --git a/crates/passthrough/src/sockets.rs b/crates/passthrough/src/sockets.rs deleted file mode 100644 index 5f2f5d2..0000000 --- a/crates/passthrough/src/sockets.rs +++ /dev/null @@ -1,284 +0,0 @@ -use wasi::clocks::monotonic_clock::Duration; -use wasi::sockets::ip_name_lookup::ResolveAddressStream; -use wasi::sockets::network::{ErrorCode, IpAddress, IpAddressFamily, IpSocketAddress, Network}; -use wasi::sockets::tcp::TcpSocket; -use wasi::sockets::udp::{IncomingDatagramStream, OutgoingDatagramStream, UdpSocket}; - -use crate::bindings::{exports, wasi}; -use crate::Handler; - -impl exports::wasi::sockets::ip_name_lookup::Guest for Handler { - type ResolveAddressStream = ResolveAddressStream; - - fn resolve_addresses( - network: &Network, - name: String, - ) -> Result { - todo!() - } -} - -impl exports::wasi::sockets::ip_name_lookup::GuestResolveAddressStream for ResolveAddressStream { - fn resolve_next_address(&self) -> Result, ErrorCode> { - todo!() - } - - fn subscribe(&self) -> exports::wasi::io::poll::Pollable { - todo!() - } -} - -impl exports::wasi::sockets::tcp::Guest for Handler { - type TcpSocket = TcpSocket; -} - -impl exports::wasi::sockets::tcp::GuestTcpSocket for TcpSocket { - fn start_bind( - &self, - network: &Network, - local_address: IpSocketAddress, - ) -> Result<(), ErrorCode> { - todo!() - } - - fn finish_bind(&self) -> Result<(), ErrorCode> { - todo!() - } - - fn start_connect( - &self, - network: &Network, - remote_address: IpSocketAddress, - ) -> Result<(), ErrorCode> { - todo!() - } - - fn finish_connect( - &self, - ) -> Result< - ( - exports::wasi::io::streams::InputStream, - exports::wasi::io::streams::OutputStream, - ), - ErrorCode, - > { - todo!() - } - - fn start_listen(&self) -> Result<(), ErrorCode> { - todo!() - } - - fn finish_listen(&self) -> Result<(), ErrorCode> { - todo!() - } - - fn accept( - &self, - ) -> Result< - ( - exports::wasi::sockets::tcp::TcpSocket, - exports::wasi::io::streams::InputStream, - exports::wasi::io::streams::OutputStream, - ), - ErrorCode, - > { - todo!() - } - - fn local_address(&self) -> Result { - todo!() - } - - fn remote_address(&self) -> Result { - todo!() - } - - fn is_listening(&self) -> bool { - todo!() - } - - fn address_family(&self) -> IpAddressFamily { - todo!() - } - - fn set_listen_backlog_size(&self, value: u64) -> Result<(), wasi::sockets::network::ErrorCode> { - todo!() - } - - fn keep_alive_enabled(&self) -> Result { - todo!() - } - - fn set_keep_alive_enabled(&self, value: bool) -> Result<(), wasi::sockets::network::ErrorCode> { - todo!() - } - - fn keep_alive_idle_time(&self) -> Result { - todo!() - } - - fn set_keep_alive_idle_time( - &self, - value: Duration, - ) -> Result<(), wasi::sockets::network::ErrorCode> { - todo!() - } - - fn keep_alive_interval(&self) -> Result { - todo!() - } - - fn set_keep_alive_interval( - &self, - value: Duration, - ) -> Result<(), wasi::sockets::network::ErrorCode> { - todo!() - } - - fn keep_alive_count(&self) -> Result { - todo!() - } - - fn set_keep_alive_count(&self, value: u32) -> Result<(), wasi::sockets::network::ErrorCode> { - todo!() - } - - fn hop_limit(&self) -> Result { - todo!() - } - - fn set_hop_limit(&self, value: u8) -> Result<(), wasi::sockets::network::ErrorCode> { - todo!() - } - - fn receive_buffer_size(&self) -> Result { - todo!() - } - - fn set_receive_buffer_size(&self, value: u64) -> Result<(), wasi::sockets::network::ErrorCode> { - todo!() - } - - fn send_buffer_size(&self) -> Result { - todo!() - } - - fn set_send_buffer_size(&self, value: u64) -> Result<(), ErrorCode> { - todo!() - } - - fn subscribe(&self) -> exports::wasi::io::poll::Pollable { - todo!() - } - - fn shutdown( - &self, - shutdown_type: exports::wasi::sockets::tcp::ShutdownType, - ) -> Result<(), ErrorCode> { - todo!() - } -} - -impl exports::wasi::sockets::udp::Guest for Handler { - type UdpSocket = UdpSocket; - type IncomingDatagramStream = IncomingDatagramStream; - type OutgoingDatagramStream = OutgoingDatagramStream; -} - -impl exports::wasi::sockets::udp::GuestUdpSocket for UdpSocket { - fn start_bind( - &self, - network: &Network, - local_address: IpSocketAddress, - ) -> Result<(), ErrorCode> { - todo!() - } - - fn finish_bind(&self) -> Result<(), ErrorCode> { - todo!() - } - - fn stream( - &self, - remote_address: Option, - ) -> Result< - ( - exports::wasi::sockets::udp::IncomingDatagramStream, - exports::wasi::sockets::udp::OutgoingDatagramStream, - ), - ErrorCode, - > { - todo!() - } - - fn local_address(&self) -> Result { - todo!() - } - - fn remote_address(&self) -> Result { - todo!() - } - - fn address_family(&self) -> IpAddressFamily { - todo!() - } - - fn unicast_hop_limit(&self) -> Result { - todo!() - } - - fn set_unicast_hop_limit(&self, value: u8) -> Result<(), ErrorCode> { - todo!() - } - - fn receive_buffer_size(&self) -> Result { - todo!() - } - - fn set_receive_buffer_size(&self, value: u64) -> Result<(), ErrorCode> { - todo!() - } - - fn send_buffer_size(&self) -> Result { - todo!() - } - - fn set_send_buffer_size(&self, value: u64) -> Result<(), ErrorCode> { - todo!() - } - - fn subscribe(&self) -> exports::wasi::io::poll::Pollable { - todo!() - } -} - -impl exports::wasi::sockets::udp::GuestIncomingDatagramStream for IncomingDatagramStream { - fn receive( - &self, - max_results: u64, - ) -> Result, ErrorCode> { - todo!() - } - - fn subscribe(&self) -> exports::wasi::io::poll::Pollable { - todo!() - } -} - -impl exports::wasi::sockets::udp::GuestOutgoingDatagramStream for OutgoingDatagramStream { - fn check_send(&self) -> Result { - todo!() - } - - fn send( - &self, - datagrams: Vec, - ) -> Result { - todo!() - } - - fn subscribe(&self) -> exports::wasi::io::poll::Pollable { - todo!() - } -} diff --git a/crates/passthrough/src/west.rs b/crates/passthrough/src/west.rs deleted file mode 100644 index c4bbebf..0000000 --- a/crates/passthrough/src/west.rs +++ /dev/null @@ -1,25 +0,0 @@ -use west::test::http_test; - -use crate::bindings::{exports, west}; -use crate::Handler; - -impl exports::west::test::http_test::Guest for Handler { - fn new_response_outparam() -> ( - exports::wasi::http::types::ResponseOutparam, - exports::wasi::http::types::FutureIncomingResponse, - ) { - let (out, res) = http_test::new_response_outparam(); - ( - exports::wasi::http::types::ResponseOutparam::new(out), - exports::wasi::http::types::FutureIncomingResponse::new(res), - ) - } - - fn new_incoming_request( - req: exports::wasi::http::types::OutgoingRequest, - ) -> exports::wasi::http::types::IncomingRequest { - exports::wasi::http::types::IncomingRequest::new(http_test::new_incoming_request( - req.into_inner(), - )) - } -} diff --git a/crates/passthrough/wit b/crates/passthrough/wit deleted file mode 120000 index 902b548..0000000 --- a/crates/passthrough/wit +++ /dev/null @@ -1 +0,0 @@ -../../wit \ No newline at end of file diff --git a/crates/sys/Cargo.toml b/crates/sys/Cargo.toml index f56fa9c..63b22f0 100644 --- a/crates/sys/Cargo.toml +++ b/crates/sys/Cargo.toml @@ -10,7 +10,7 @@ license.workspace = true repository.workspace = true [lib] -crate-type = ["cdylib", "staticlib"] +crate-type = ["staticlib"] [dependencies] anyhow = { workspace = true } diff --git a/tests/go/sync/bindings/.gitkeep b/examples/go/http/bindings/.gitkeep similarity index 100% rename from tests/go/sync/bindings/.gitkeep rename to examples/go/http/bindings/.gitkeep diff --git a/examples/go/http/bindings/wasi/cli/environment/empty.s b/examples/go/http/bindings/wasi/cli/environment/empty.s new file mode 100644 index 0000000..5444f20 --- /dev/null +++ b/examples/go/http/bindings/wasi/cli/environment/empty.s @@ -0,0 +1,3 @@ +// This file exists for testing this package without WebAssembly, +// allowing empty function bodies with a //go:wasmimport directive. +// See https://pkg.go.dev/cmd/compile for more information. diff --git a/examples/go/http/bindings/wasi/cli/environment/environment.wit.go b/examples/go/http/bindings/wasi/cli/environment/environment.wit.go new file mode 100644 index 0000000..19d95cf --- /dev/null +++ b/examples/go/http/bindings/wasi/cli/environment/environment.wit.go @@ -0,0 +1,64 @@ +// Code generated by wit-bindgen-go. DO NOT EDIT. + +// Package environment represents the imported interface "wasi:cli/environment@0.2.1". +package environment + +import ( + "github.com/bytecodealliance/wasm-tools-go/cm" +) + +// GetEnvironment represents the imported function "get-environment". +// +// Get the POSIX-style environment variables. +// +// Each environment variable is provided as a pair of string variable names +// and string value. +// +// Morally, these are a value import, but until value imports are available +// in the component model, this import function should return the same +// values each time it is called. +// +// get-environment: func() -> list> +// +//go:nosplit +func GetEnvironment() (result cm.List[[2]string]) { + wasmimport_GetEnvironment(&result) + return +} + +//go:wasmimport wasi:cli/environment@0.2.1 get-environment +//go:noescape +func wasmimport_GetEnvironment(result *cm.List[[2]string]) + +// GetArguments represents the imported function "get-arguments". +// +// Get the POSIX-style arguments to the program. +// +// get-arguments: func() -> list +// +//go:nosplit +func GetArguments() (result cm.List[string]) { + wasmimport_GetArguments(&result) + return +} + +//go:wasmimport wasi:cli/environment@0.2.1 get-arguments +//go:noescape +func wasmimport_GetArguments(result *cm.List[string]) + +// InitialCWD represents the imported function "initial-cwd". +// +// Return a path that programs should use as their initial current working +// directory, interpreting `.` as shorthand for this. +// +// initial-cwd: func() -> option +// +//go:nosplit +func InitialCWD() (result cm.Option[string]) { + wasmimport_InitialCWD(&result) + return +} + +//go:wasmimport wasi:cli/environment@0.2.1 initial-cwd +//go:noescape +func wasmimport_InitialCWD(result *cm.Option[string]) diff --git a/examples/go/http/bindings/wasi/cli/exit/empty.s b/examples/go/http/bindings/wasi/cli/exit/empty.s new file mode 100644 index 0000000..5444f20 --- /dev/null +++ b/examples/go/http/bindings/wasi/cli/exit/empty.s @@ -0,0 +1,3 @@ +// This file exists for testing this package without WebAssembly, +// allowing empty function bodies with a //go:wasmimport directive. +// See https://pkg.go.dev/cmd/compile for more information. diff --git a/examples/go/http/bindings/wasi/cli/exit/exit.wit.go b/examples/go/http/bindings/wasi/cli/exit/exit.wit.go new file mode 100644 index 0000000..7cf9449 --- /dev/null +++ b/examples/go/http/bindings/wasi/cli/exit/exit.wit.go @@ -0,0 +1,49 @@ +// Code generated by wit-bindgen-go. DO NOT EDIT. + +// Package exit represents the imported interface "wasi:cli/exit@0.2.1". +package exit + +import ( + "github.com/bytecodealliance/wasm-tools-go/cm" +) + +// Exit represents the imported function "exit". +// +// Exit the current instance and any linked instances. +// +// exit: func(status: result) +// +//go:nosplit +func Exit(status cm.BoolResult) { + status0 := cm.BoolToU32(status) + wasmimport_Exit((uint32)(status0)) + return +} + +//go:wasmimport wasi:cli/exit@0.2.1 exit +//go:noescape +func wasmimport_Exit(status0 uint32) + +// ExitWithCode represents the imported function "exit-with-code". +// +// Exit the current instance and any linked instances, reporting the +// specified status code to the host. +// +// The meaning of the code depends on the context, with 0 usually meaning +// "success", and other values indicating various types of failure. +// +// This function does not return; the effect is analogous to a trap, but +// without the connotation that something bad has happened. +// +// exit-with-code: func(status-code: u8) +// +//go:nosplit +func ExitWithCode(statusCode uint8) { + statusCode0 := (uint32)(statusCode) + wasmimport_ExitWithCode((uint32)(statusCode0)) + return +} + +//go:wasmimport wasi:cli/exit@0.2.1 exit-with-code +//go:noescape +func wasmimport_ExitWithCode(statusCode0 uint32) diff --git a/examples/go/http/bindings/wasi/cli/stderr/empty.s b/examples/go/http/bindings/wasi/cli/stderr/empty.s new file mode 100644 index 0000000..5444f20 --- /dev/null +++ b/examples/go/http/bindings/wasi/cli/stderr/empty.s @@ -0,0 +1,3 @@ +// This file exists for testing this package without WebAssembly, +// allowing empty function bodies with a //go:wasmimport directive. +// See https://pkg.go.dev/cmd/compile for more information. diff --git a/examples/go/http/bindings/wasi/cli/stderr/stderr.wit.go b/examples/go/http/bindings/wasi/cli/stderr/stderr.wit.go new file mode 100644 index 0000000..9544991 --- /dev/null +++ b/examples/go/http/bindings/wasi/cli/stderr/stderr.wit.go @@ -0,0 +1,24 @@ +// Code generated by wit-bindgen-go. DO NOT EDIT. + +// Package stderr represents the imported interface "wasi:cli/stderr@0.2.1". +package stderr + +import ( + "github.com/bytecodealliance/wasm-tools-go/cm" + "github.com/rvolosatovs/west/examples/go/http/bindings/wasi/io/streams" +) + +// GetStderr represents the imported function "get-stderr". +// +// get-stderr: func() -> output-stream +// +//go:nosplit +func GetStderr() (result streams.OutputStream) { + result0 := wasmimport_GetStderr() + result = cm.Reinterpret[streams.OutputStream]((uint32)(result0)) + return +} + +//go:wasmimport wasi:cli/stderr@0.2.1 get-stderr +//go:noescape +func wasmimport_GetStderr() (result0 uint32) diff --git a/examples/go/http/bindings/wasi/cli/stdin/empty.s b/examples/go/http/bindings/wasi/cli/stdin/empty.s new file mode 100644 index 0000000..5444f20 --- /dev/null +++ b/examples/go/http/bindings/wasi/cli/stdin/empty.s @@ -0,0 +1,3 @@ +// This file exists for testing this package without WebAssembly, +// allowing empty function bodies with a //go:wasmimport directive. +// See https://pkg.go.dev/cmd/compile for more information. diff --git a/examples/go/http/bindings/wasi/cli/stdin/stdin.wit.go b/examples/go/http/bindings/wasi/cli/stdin/stdin.wit.go new file mode 100644 index 0000000..a360c91 --- /dev/null +++ b/examples/go/http/bindings/wasi/cli/stdin/stdin.wit.go @@ -0,0 +1,24 @@ +// Code generated by wit-bindgen-go. DO NOT EDIT. + +// Package stdin represents the imported interface "wasi:cli/stdin@0.2.1". +package stdin + +import ( + "github.com/bytecodealliance/wasm-tools-go/cm" + "github.com/rvolosatovs/west/examples/go/http/bindings/wasi/io/streams" +) + +// GetStdin represents the imported function "get-stdin". +// +// get-stdin: func() -> input-stream +// +//go:nosplit +func GetStdin() (result streams.InputStream) { + result0 := wasmimport_GetStdin() + result = cm.Reinterpret[streams.InputStream]((uint32)(result0)) + return +} + +//go:wasmimport wasi:cli/stdin@0.2.1 get-stdin +//go:noescape +func wasmimport_GetStdin() (result0 uint32) diff --git a/examples/go/http/bindings/wasi/cli/stdout/empty.s b/examples/go/http/bindings/wasi/cli/stdout/empty.s new file mode 100644 index 0000000..5444f20 --- /dev/null +++ b/examples/go/http/bindings/wasi/cli/stdout/empty.s @@ -0,0 +1,3 @@ +// This file exists for testing this package without WebAssembly, +// allowing empty function bodies with a //go:wasmimport directive. +// See https://pkg.go.dev/cmd/compile for more information. diff --git a/examples/go/http/bindings/wasi/cli/stdout/stdout.wit.go b/examples/go/http/bindings/wasi/cli/stdout/stdout.wit.go new file mode 100644 index 0000000..be67608 --- /dev/null +++ b/examples/go/http/bindings/wasi/cli/stdout/stdout.wit.go @@ -0,0 +1,24 @@ +// Code generated by wit-bindgen-go. DO NOT EDIT. + +// Package stdout represents the imported interface "wasi:cli/stdout@0.2.1". +package stdout + +import ( + "github.com/bytecodealliance/wasm-tools-go/cm" + "github.com/rvolosatovs/west/examples/go/http/bindings/wasi/io/streams" +) + +// GetStdout represents the imported function "get-stdout". +// +// get-stdout: func() -> output-stream +// +//go:nosplit +func GetStdout() (result streams.OutputStream) { + result0 := wasmimport_GetStdout() + result = cm.Reinterpret[streams.OutputStream]((uint32)(result0)) + return +} + +//go:wasmimport wasi:cli/stdout@0.2.1 get-stdout +//go:noescape +func wasmimport_GetStdout() (result0 uint32) diff --git a/examples/go/http/bindings/wasi/cli/terminal-input/empty.s b/examples/go/http/bindings/wasi/cli/terminal-input/empty.s new file mode 100644 index 0000000..5444f20 --- /dev/null +++ b/examples/go/http/bindings/wasi/cli/terminal-input/empty.s @@ -0,0 +1,3 @@ +// This file exists for testing this package without WebAssembly, +// allowing empty function bodies with a //go:wasmimport directive. +// See https://pkg.go.dev/cmd/compile for more information. diff --git a/examples/go/http/bindings/wasi/cli/terminal-input/terminal-input.wit.go b/examples/go/http/bindings/wasi/cli/terminal-input/terminal-input.wit.go new file mode 100644 index 0000000..42bf805 --- /dev/null +++ b/examples/go/http/bindings/wasi/cli/terminal-input/terminal-input.wit.go @@ -0,0 +1,36 @@ +// Code generated by wit-bindgen-go. DO NOT EDIT. + +// Package terminalinput represents the imported interface "wasi:cli/terminal-input@0.2.1". +// +// Terminal input. +// +// In the future, this may include functions for disabling echoing, +// disabling input buffering so that keyboard events are sent through +// immediately, querying supported features, and so on. +package terminalinput + +import ( + "github.com/bytecodealliance/wasm-tools-go/cm" +) + +// TerminalInput represents the imported resource "wasi:cli/terminal-input@0.2.1#terminal-input". +// +// The input side of a terminal. +// +// resource terminal-input +type TerminalInput cm.Resource + +// ResourceDrop represents the imported resource-drop for resource "terminal-input". +// +// Drops a resource handle. +// +//go:nosplit +func (self TerminalInput) ResourceDrop() { + self0 := cm.Reinterpret[uint32](self) + wasmimport_TerminalInputResourceDrop((uint32)(self0)) + return +} + +//go:wasmimport wasi:cli/terminal-input@0.2.1 [resource-drop]terminal-input +//go:noescape +func wasmimport_TerminalInputResourceDrop(self0 uint32) diff --git a/examples/go/http/bindings/wasi/cli/terminal-output/empty.s b/examples/go/http/bindings/wasi/cli/terminal-output/empty.s new file mode 100644 index 0000000..5444f20 --- /dev/null +++ b/examples/go/http/bindings/wasi/cli/terminal-output/empty.s @@ -0,0 +1,3 @@ +// This file exists for testing this package without WebAssembly, +// allowing empty function bodies with a //go:wasmimport directive. +// See https://pkg.go.dev/cmd/compile for more information. diff --git a/examples/go/http/bindings/wasi/cli/terminal-output/terminal-output.wit.go b/examples/go/http/bindings/wasi/cli/terminal-output/terminal-output.wit.go new file mode 100644 index 0000000..e266abc --- /dev/null +++ b/examples/go/http/bindings/wasi/cli/terminal-output/terminal-output.wit.go @@ -0,0 +1,36 @@ +// Code generated by wit-bindgen-go. DO NOT EDIT. + +// Package terminaloutput represents the imported interface "wasi:cli/terminal-output@0.2.1". +// +// Terminal output. +// +// In the future, this may include functions for querying the terminal +// size, being notified of terminal size changes, querying supported +// features, and so on. +package terminaloutput + +import ( + "github.com/bytecodealliance/wasm-tools-go/cm" +) + +// TerminalOutput represents the imported resource "wasi:cli/terminal-output@0.2.1#terminal-output". +// +// The output side of a terminal. +// +// resource terminal-output +type TerminalOutput cm.Resource + +// ResourceDrop represents the imported resource-drop for resource "terminal-output". +// +// Drops a resource handle. +// +//go:nosplit +func (self TerminalOutput) ResourceDrop() { + self0 := cm.Reinterpret[uint32](self) + wasmimport_TerminalOutputResourceDrop((uint32)(self0)) + return +} + +//go:wasmimport wasi:cli/terminal-output@0.2.1 [resource-drop]terminal-output +//go:noescape +func wasmimport_TerminalOutputResourceDrop(self0 uint32) diff --git a/examples/go/http/bindings/wasi/cli/terminal-stderr/empty.s b/examples/go/http/bindings/wasi/cli/terminal-stderr/empty.s new file mode 100644 index 0000000..5444f20 --- /dev/null +++ b/examples/go/http/bindings/wasi/cli/terminal-stderr/empty.s @@ -0,0 +1,3 @@ +// This file exists for testing this package without WebAssembly, +// allowing empty function bodies with a //go:wasmimport directive. +// See https://pkg.go.dev/cmd/compile for more information. diff --git a/examples/go/http/bindings/wasi/cli/terminal-stderr/terminal-stderr.wit.go b/examples/go/http/bindings/wasi/cli/terminal-stderr/terminal-stderr.wit.go new file mode 100644 index 0000000..0dfe105 --- /dev/null +++ b/examples/go/http/bindings/wasi/cli/terminal-stderr/terminal-stderr.wit.go @@ -0,0 +1,29 @@ +// Code generated by wit-bindgen-go. DO NOT EDIT. + +// Package terminalstderr represents the imported interface "wasi:cli/terminal-stderr@0.2.1". +// +// An interface providing an optional `terminal-output` for stderr as a +// link-time authority. +package terminalstderr + +import ( + "github.com/bytecodealliance/wasm-tools-go/cm" + terminaloutput "github.com/rvolosatovs/west/examples/go/http/bindings/wasi/cli/terminal-output" +) + +// GetTerminalStderr represents the imported function "get-terminal-stderr". +// +// If stderr is connected to a terminal, return a `terminal-output` handle +// allowing further interaction with it. +// +// get-terminal-stderr: func() -> option +// +//go:nosplit +func GetTerminalStderr() (result cm.Option[terminaloutput.TerminalOutput]) { + wasmimport_GetTerminalStderr(&result) + return +} + +//go:wasmimport wasi:cli/terminal-stderr@0.2.1 get-terminal-stderr +//go:noescape +func wasmimport_GetTerminalStderr(result *cm.Option[terminaloutput.TerminalOutput]) diff --git a/examples/go/http/bindings/wasi/cli/terminal-stdin/empty.s b/examples/go/http/bindings/wasi/cli/terminal-stdin/empty.s new file mode 100644 index 0000000..5444f20 --- /dev/null +++ b/examples/go/http/bindings/wasi/cli/terminal-stdin/empty.s @@ -0,0 +1,3 @@ +// This file exists for testing this package without WebAssembly, +// allowing empty function bodies with a //go:wasmimport directive. +// See https://pkg.go.dev/cmd/compile for more information. diff --git a/examples/go/http/bindings/wasi/cli/terminal-stdin/terminal-stdin.wit.go b/examples/go/http/bindings/wasi/cli/terminal-stdin/terminal-stdin.wit.go new file mode 100644 index 0000000..4ae5030 --- /dev/null +++ b/examples/go/http/bindings/wasi/cli/terminal-stdin/terminal-stdin.wit.go @@ -0,0 +1,29 @@ +// Code generated by wit-bindgen-go. DO NOT EDIT. + +// Package terminalstdin represents the imported interface "wasi:cli/terminal-stdin@0.2.1". +// +// An interface providing an optional `terminal-input` for stdin as a +// link-time authority. +package terminalstdin + +import ( + "github.com/bytecodealliance/wasm-tools-go/cm" + terminalinput "github.com/rvolosatovs/west/examples/go/http/bindings/wasi/cli/terminal-input" +) + +// GetTerminalStdin represents the imported function "get-terminal-stdin". +// +// If stdin is connected to a terminal, return a `terminal-input` handle +// allowing further interaction with it. +// +// get-terminal-stdin: func() -> option +// +//go:nosplit +func GetTerminalStdin() (result cm.Option[terminalinput.TerminalInput]) { + wasmimport_GetTerminalStdin(&result) + return +} + +//go:wasmimport wasi:cli/terminal-stdin@0.2.1 get-terminal-stdin +//go:noescape +func wasmimport_GetTerminalStdin(result *cm.Option[terminalinput.TerminalInput]) diff --git a/examples/go/http/bindings/wasi/cli/terminal-stdout/empty.s b/examples/go/http/bindings/wasi/cli/terminal-stdout/empty.s new file mode 100644 index 0000000..5444f20 --- /dev/null +++ b/examples/go/http/bindings/wasi/cli/terminal-stdout/empty.s @@ -0,0 +1,3 @@ +// This file exists for testing this package without WebAssembly, +// allowing empty function bodies with a //go:wasmimport directive. +// See https://pkg.go.dev/cmd/compile for more information. diff --git a/examples/go/http/bindings/wasi/cli/terminal-stdout/terminal-stdout.wit.go b/examples/go/http/bindings/wasi/cli/terminal-stdout/terminal-stdout.wit.go new file mode 100644 index 0000000..1e88b90 --- /dev/null +++ b/examples/go/http/bindings/wasi/cli/terminal-stdout/terminal-stdout.wit.go @@ -0,0 +1,29 @@ +// Code generated by wit-bindgen-go. DO NOT EDIT. + +// Package terminalstdout represents the imported interface "wasi:cli/terminal-stdout@0.2.1". +// +// An interface providing an optional `terminal-output` for stdout as a +// link-time authority. +package terminalstdout + +import ( + "github.com/bytecodealliance/wasm-tools-go/cm" + terminaloutput "github.com/rvolosatovs/west/examples/go/http/bindings/wasi/cli/terminal-output" +) + +// GetTerminalStdout represents the imported function "get-terminal-stdout". +// +// If stdout is connected to a terminal, return a `terminal-output` handle +// allowing further interaction with it. +// +// get-terminal-stdout: func() -> option +// +//go:nosplit +func GetTerminalStdout() (result cm.Option[terminaloutput.TerminalOutput]) { + wasmimport_GetTerminalStdout(&result) + return +} + +//go:wasmimport wasi:cli/terminal-stdout@0.2.1 get-terminal-stdout +//go:noescape +func wasmimport_GetTerminalStdout(result *cm.Option[terminaloutput.TerminalOutput]) diff --git a/examples/go/http/bindings/wasi/clocks/monotonic-clock/empty.s b/examples/go/http/bindings/wasi/clocks/monotonic-clock/empty.s new file mode 100644 index 0000000..5444f20 --- /dev/null +++ b/examples/go/http/bindings/wasi/clocks/monotonic-clock/empty.s @@ -0,0 +1,3 @@ +// This file exists for testing this package without WebAssembly, +// allowing empty function bodies with a //go:wasmimport directive. +// See https://pkg.go.dev/cmd/compile for more information. diff --git a/examples/go/http/bindings/wasi/clocks/monotonic-clock/monotonic-clock.wit.go b/examples/go/http/bindings/wasi/clocks/monotonic-clock/monotonic-clock.wit.go new file mode 100644 index 0000000..3eb8fce --- /dev/null +++ b/examples/go/http/bindings/wasi/clocks/monotonic-clock/monotonic-clock.wit.go @@ -0,0 +1,110 @@ +// Code generated by wit-bindgen-go. DO NOT EDIT. + +// Package monotonicclock represents the imported interface "wasi:clocks/monotonic-clock@0.2.1". +// +// WASI Monotonic Clock is a clock API intended to let users measure elapsed +// time. +// +// It is intended to be portable at least between Unix-family platforms and +// Windows. +// +// A monotonic clock is a clock which has an unspecified initial value, and +// successive reads of the clock will produce non-decreasing values. +package monotonicclock + +import ( + "github.com/bytecodealliance/wasm-tools-go/cm" + "github.com/rvolosatovs/west/examples/go/http/bindings/wasi/io/poll" +) + +// Instant represents the u64 "wasi:clocks/monotonic-clock@0.2.1#instant". +// +// An instant in time, in nanoseconds. An instant is relative to an +// unspecified initial value, and can only be compared to instances from +// the same monotonic-clock. +// +// type instant = u64 +type Instant uint64 + +// Duration represents the u64 "wasi:clocks/monotonic-clock@0.2.1#duration". +// +// A duration of time, in nanoseconds. +// +// type duration = u64 +type Duration uint64 + +// Now represents the imported function "now". +// +// Read the current value of the clock. +// +// The clock is monotonic, therefore calling this function repeatedly will +// produce a sequence of non-decreasing values. +// +// now: func() -> instant +// +//go:nosplit +func Now() (result Instant) { + result0 := wasmimport_Now() + result = (Instant)((uint64)(result0)) + return +} + +//go:wasmimport wasi:clocks/monotonic-clock@0.2.1 now +//go:noescape +func wasmimport_Now() (result0 uint64) + +// Resolution represents the imported function "resolution". +// +// Query the resolution of the clock. Returns the duration of time +// corresponding to a clock tick. +// +// resolution: func() -> duration +// +//go:nosplit +func Resolution() (result Duration) { + result0 := wasmimport_Resolution() + result = (Duration)((uint64)(result0)) + return +} + +//go:wasmimport wasi:clocks/monotonic-clock@0.2.1 resolution +//go:noescape +func wasmimport_Resolution() (result0 uint64) + +// SubscribeInstant represents the imported function "subscribe-instant". +// +// Create a `pollable` which will resolve once the specified instant +// has occurred. +// +// subscribe-instant: func(when: instant) -> pollable +// +//go:nosplit +func SubscribeInstant(when Instant) (result poll.Pollable) { + when0 := (uint64)(when) + result0 := wasmimport_SubscribeInstant((uint64)(when0)) + result = cm.Reinterpret[poll.Pollable]((uint32)(result0)) + return +} + +//go:wasmimport wasi:clocks/monotonic-clock@0.2.1 subscribe-instant +//go:noescape +func wasmimport_SubscribeInstant(when0 uint64) (result0 uint32) + +// SubscribeDuration represents the imported function "subscribe-duration". +// +// Create a `pollable` that will resolve after the specified duration has +// elapsed from the time this function is invoked. +// +// subscribe-duration: func(when: duration) -> pollable +// +//go:nosplit +func SubscribeDuration(when Duration) (result poll.Pollable) { + when0 := (uint64)(when) + result0 := wasmimport_SubscribeDuration((uint64)(when0)) + result = cm.Reinterpret[poll.Pollable]((uint32)(result0)) + return +} + +//go:wasmimport wasi:clocks/monotonic-clock@0.2.1 subscribe-duration +//go:noescape +func wasmimport_SubscribeDuration(when0 uint64) (result0 uint32) diff --git a/examples/go/http/bindings/wasi/clocks/timezone/abi.go b/examples/go/http/bindings/wasi/clocks/timezone/abi.go new file mode 100644 index 0000000..c04a196 --- /dev/null +++ b/examples/go/http/bindings/wasi/clocks/timezone/abi.go @@ -0,0 +1,13 @@ +// Code generated by wit-bindgen-go. DO NOT EDIT. + +package timezone + +import ( + wallclock "github.com/rvolosatovs/west/examples/go/http/bindings/wasi/clocks/wall-clock" +) + +func lower_DateTime(v wallclock.DateTime) (f0 uint64, f1 uint32) { + f0 = (uint64)(v.Seconds) + f1 = (uint32)(v.Nanoseconds) + return +} diff --git a/examples/go/http/bindings/wasi/clocks/timezone/empty.s b/examples/go/http/bindings/wasi/clocks/timezone/empty.s new file mode 100644 index 0000000..5444f20 --- /dev/null +++ b/examples/go/http/bindings/wasi/clocks/timezone/empty.s @@ -0,0 +1,3 @@ +// This file exists for testing this package without WebAssembly, +// allowing empty function bodies with a //go:wasmimport directive. +// See https://pkg.go.dev/cmd/compile for more information. diff --git a/examples/go/http/bindings/wasi/clocks/timezone/timezone.wit.go b/examples/go/http/bindings/wasi/clocks/timezone/timezone.wit.go new file mode 100644 index 0000000..86f89f8 --- /dev/null +++ b/examples/go/http/bindings/wasi/clocks/timezone/timezone.wit.go @@ -0,0 +1,90 @@ +// Code generated by wit-bindgen-go. DO NOT EDIT. + +// Package timezone represents the imported interface "wasi:clocks/timezone@0.2.1". +package timezone + +import ( + wallclock "github.com/rvolosatovs/west/examples/go/http/bindings/wasi/clocks/wall-clock" +) + +// TimezoneDisplay represents the record "wasi:clocks/timezone@0.2.1#timezone-display". +// +// Information useful for displaying the timezone of a specific `datetime`. +// +// This information may vary within a single `timezone` to reflect daylight +// saving time adjustments. +// +// record timezone-display { +// utc-offset: s32, +// name: string, +// in-daylight-saving-time: bool, +// } +type TimezoneDisplay struct { + // The number of seconds difference between UTC time and the local + // time of the timezone. + // + // The returned value will always be less than 86400 which is the + // number of seconds in a day (24*60*60). + // + // In implementations that do not expose an actual time zone, this + // should return 0. + UtcOffset int32 + + // The abbreviated name of the timezone to display to a user. The name + // `UTC` indicates Coordinated Universal Time. Otherwise, this should + // reference local standards for the name of the time zone. + // + // In implementations that do not expose an actual time zone, this + // should be the string `UTC`. + // + // In time zones that do not have an applicable name, a formatted + // representation of the UTC offset may be returned, such as `-04:00`. + Name string + + // Whether daylight saving time is active. + // + // In implementations that do not expose an actual time zone, this + // should return false. + InDaylightSavingTime bool +} + +// Display represents the imported function "display". +// +// Return information needed to display the given `datetime`. This includes +// the UTC offset, the time zone name, and a flag indicating whether +// daylight saving time is active. +// +// If the timezone cannot be determined for the given `datetime`, return a +// `timezone-display` for `UTC` with a `utc-offset` of 0 and no daylight +// saving time. +// +// display: func(when: datetime) -> timezone-display +// +//go:nosplit +func Display(when wallclock.DateTime) (result TimezoneDisplay) { + when0, when1 := lower_DateTime(when) + wasmimport_Display((uint64)(when0), (uint32)(when1), &result) + return +} + +//go:wasmimport wasi:clocks/timezone@0.2.1 display +//go:noescape +func wasmimport_Display(when0 uint64, when1 uint32, result *TimezoneDisplay) + +// UtcOffset represents the imported function "utc-offset". +// +// The same as `display`, but only return the UTC offset. +// +// utc-offset: func(when: datetime) -> s32 +// +//go:nosplit +func UtcOffset(when wallclock.DateTime) (result int32) { + when0, when1 := lower_DateTime(when) + result0 := wasmimport_UtcOffset((uint64)(when0), (uint32)(when1)) + result = (int32)((uint32)(result0)) + return +} + +//go:wasmimport wasi:clocks/timezone@0.2.1 utc-offset +//go:noescape +func wasmimport_UtcOffset(when0 uint64, when1 uint32) (result0 uint32) diff --git a/examples/go/http/bindings/wasi/clocks/wall-clock/empty.s b/examples/go/http/bindings/wasi/clocks/wall-clock/empty.s new file mode 100644 index 0000000..5444f20 --- /dev/null +++ b/examples/go/http/bindings/wasi/clocks/wall-clock/empty.s @@ -0,0 +1,3 @@ +// This file exists for testing this package without WebAssembly, +// allowing empty function bodies with a //go:wasmimport directive. +// See https://pkg.go.dev/cmd/compile for more information. diff --git a/examples/go/http/bindings/wasi/clocks/wall-clock/wall-clock.wit.go b/examples/go/http/bindings/wasi/clocks/wall-clock/wall-clock.wit.go new file mode 100644 index 0000000..20dd2bb --- /dev/null +++ b/examples/go/http/bindings/wasi/clocks/wall-clock/wall-clock.wit.go @@ -0,0 +1,78 @@ +// Code generated by wit-bindgen-go. DO NOT EDIT. + +// Package wallclock represents the imported interface "wasi:clocks/wall-clock@0.2.1". +// +// WASI Wall Clock is a clock API intended to let users query the current +// time. The name "wall" makes an analogy to a "clock on the wall", which +// is not necessarily monotonic as it may be reset. +// +// It is intended to be portable at least between Unix-family platforms and +// Windows. +// +// A wall clock is a clock which measures the date and time according to +// some external reference. +// +// External references may be reset, so this clock is not necessarily +// monotonic, making it unsuitable for measuring elapsed time. +// +// It is intended for reporting the current date and time for humans. +package wallclock + +// DateTime represents the record "wasi:clocks/wall-clock@0.2.1#datetime". +// +// A time and date in seconds plus nanoseconds. +// +// record datetime { +// seconds: u64, +// nanoseconds: u32, +// } +type DateTime struct { + Seconds uint64 + Nanoseconds uint32 +} + +// Now represents the imported function "now". +// +// Read the current value of the clock. +// +// This clock is not monotonic, therefore calling this function repeatedly +// will not necessarily produce a sequence of non-decreasing values. +// +// The returned timestamps represent the number of seconds since +// 1970-01-01T00:00:00Z, also known as [POSIX's Seconds Since the Epoch], +// also known as [Unix Time]. +// +// The nanoseconds field of the output is always less than 1000000000. +// +// now: func() -> datetime +// +// [POSIX's Seconds Since the Epoch]: https://pubs.opengroup.org/onlinepubs/9699919799/xrat/V4_xbd_chap04.html#tag_21_04_16 +// [Unix Time]: https://en.wikipedia.org/wiki/Unix_time +// +//go:nosplit +func Now() (result DateTime) { + wasmimport_Now(&result) + return +} + +//go:wasmimport wasi:clocks/wall-clock@0.2.1 now +//go:noescape +func wasmimport_Now(result *DateTime) + +// Resolution represents the imported function "resolution". +// +// Query the resolution of the clock. +// +// The nanoseconds field of the output is always less than 1000000000. +// +// resolution: func() -> datetime +// +//go:nosplit +func Resolution() (result DateTime) { + wasmimport_Resolution(&result) + return +} + +//go:wasmimport wasi:clocks/wall-clock@0.2.1 resolution +//go:noescape +func wasmimport_Resolution(result *DateTime) diff --git a/examples/go/http/bindings/wasi/filesystem/preopens/empty.s b/examples/go/http/bindings/wasi/filesystem/preopens/empty.s new file mode 100644 index 0000000..5444f20 --- /dev/null +++ b/examples/go/http/bindings/wasi/filesystem/preopens/empty.s @@ -0,0 +1,3 @@ +// This file exists for testing this package without WebAssembly, +// allowing empty function bodies with a //go:wasmimport directive. +// See https://pkg.go.dev/cmd/compile for more information. diff --git a/examples/go/http/bindings/wasi/filesystem/preopens/preopens.wit.go b/examples/go/http/bindings/wasi/filesystem/preopens/preopens.wit.go new file mode 100644 index 0000000..92072b5 --- /dev/null +++ b/examples/go/http/bindings/wasi/filesystem/preopens/preopens.wit.go @@ -0,0 +1,25 @@ +// Code generated by wit-bindgen-go. DO NOT EDIT. + +// Package preopens represents the imported interface "wasi:filesystem/preopens@0.2.1". +package preopens + +import ( + "github.com/bytecodealliance/wasm-tools-go/cm" + "github.com/rvolosatovs/west/examples/go/http/bindings/wasi/filesystem/types" +) + +// GetDirectories represents the imported function "get-directories". +// +// Return the set of preopened directories, and their path. +// +// get-directories: func() -> list> +// +//go:nosplit +func GetDirectories() (result cm.List[cm.Tuple[types.Descriptor, string]]) { + wasmimport_GetDirectories(&result) + return +} + +//go:wasmimport wasi:filesystem/preopens@0.2.1 get-directories +//go:noescape +func wasmimport_GetDirectories(result *cm.List[cm.Tuple[types.Descriptor, string]]) diff --git a/examples/go/http/bindings/wasi/filesystem/types/abi.go b/examples/go/http/bindings/wasi/filesystem/types/abi.go new file mode 100644 index 0000000..5fe821b --- /dev/null +++ b/examples/go/http/bindings/wasi/filesystem/types/abi.go @@ -0,0 +1,51 @@ +// Code generated by wit-bindgen-go. DO NOT EDIT. + +package types + +import ( + "github.com/bytecodealliance/wasm-tools-go/cm" + wallclock "github.com/rvolosatovs/west/examples/go/http/bindings/wasi/clocks/wall-clock" + "unsafe" +) + +// DateTimeShape is used for storage in variant or result types. +type DateTimeShape struct { + shape [unsafe.Sizeof(wallclock.DateTime{})]byte +} + +// MetadataHashValueShape is used for storage in variant or result types. +type MetadataHashValueShape struct { + shape [unsafe.Sizeof(MetadataHashValue{})]byte +} + +// TupleListU8BoolShape is used for storage in variant or result types. +type TupleListU8BoolShape struct { + shape [unsafe.Sizeof(cm.Tuple[cm.List[uint8], bool]{})]byte +} + +func lower_DateTime(v wallclock.DateTime) (f0 uint64, f1 uint32) { + f0 = (uint64)(v.Seconds) + f1 = (uint32)(v.Nanoseconds) + return +} + +func lower_NewTimestamp(v NewTimestamp) (f0 uint32, f1 uint64, f2 uint32) { + f0 = (uint32)(v.Tag()) + switch f0 { + case 2: // timestamp + v1, v2 := lower_DateTime(*v.Timestamp()) + f1 = (uint64)(v1) + f2 = (uint32)(v2) + } + return +} + +// DescriptorStatShape is used for storage in variant or result types. +type DescriptorStatShape struct { + shape [unsafe.Sizeof(DescriptorStat{})]byte +} + +// OptionDirectoryEntryShape is used for storage in variant or result types. +type OptionDirectoryEntryShape struct { + shape [unsafe.Sizeof(cm.Option[DirectoryEntry]{})]byte +} diff --git a/examples/go/http/bindings/wasi/filesystem/types/empty.s b/examples/go/http/bindings/wasi/filesystem/types/empty.s new file mode 100644 index 0000000..5444f20 --- /dev/null +++ b/examples/go/http/bindings/wasi/filesystem/types/empty.s @@ -0,0 +1,3 @@ +// This file exists for testing this package without WebAssembly, +// allowing empty function bodies with a //go:wasmimport directive. +// See https://pkg.go.dev/cmd/compile for more information. diff --git a/examples/go/http/bindings/wasi/filesystem/types/types.wit.go b/examples/go/http/bindings/wasi/filesystem/types/types.wit.go new file mode 100644 index 0000000..7db768c --- /dev/null +++ b/examples/go/http/bindings/wasi/filesystem/types/types.wit.go @@ -0,0 +1,1357 @@ +// Code generated by wit-bindgen-go. DO NOT EDIT. + +// Package types represents the imported interface "wasi:filesystem/types@0.2.1". +// +// WASI filesystem is a filesystem API primarily intended to let users run WASI +// programs that access their files on their existing filesystems, without +// significant overhead. +// +// It is intended to be roughly portable between Unix-family platforms and +// Windows, though it does not hide many of the major differences. +// +// Paths are passed as interface-type `string`s, meaning they must consist of +// a sequence of Unicode Scalar Values (USVs). Some filesystems may contain +// paths which are not accessible by this API. +// +// The directory separator in WASI is always the forward-slash (`/`). +// +// All paths in WASI are relative paths, and are interpreted relative to a +// `descriptor` referring to a base directory. If a `path` argument to any WASI +// function starts with `/`, or if any step of resolving a `path`, including +// `..` and symbolic link steps, reaches a directory outside of the base +// directory, or reaches a symlink to an absolute or rooted path in the +// underlying filesystem, the function fails with `error-code::not-permitted`. +// +// For more information about WASI path resolution and sandboxing, see +// [WASI filesystem path resolution]. +// +// [WASI filesystem path resolution]: https://github.com/WebAssembly/wasi-filesystem/blob/main/path-resolution.md +package types + +import ( + "github.com/bytecodealliance/wasm-tools-go/cm" + wallclock "github.com/rvolosatovs/west/examples/go/http/bindings/wasi/clocks/wall-clock" + ioerror "github.com/rvolosatovs/west/examples/go/http/bindings/wasi/io/error" + "github.com/rvolosatovs/west/examples/go/http/bindings/wasi/io/streams" +) + +// FileSize represents the u64 "wasi:filesystem/types@0.2.1#filesize". +// +// File size or length of a region within a file. +// +// type filesize = u64 +type FileSize uint64 + +// DescriptorType represents the enum "wasi:filesystem/types@0.2.1#descriptor-type". +// +// The type of a filesystem object referenced by a descriptor. +// +// Note: This was called `filetype` in earlier versions of WASI. +// +// enum descriptor-type { +// unknown, +// block-device, +// character-device, +// directory, +// fifo, +// symbolic-link, +// regular-file, +// socket +// } +type DescriptorType uint8 + +const ( + // The type of the descriptor or file is unknown or is different from + // any of the other types specified. + DescriptorTypeUnknown DescriptorType = iota + + // The descriptor refers to a block device inode. + DescriptorTypeBlockDevice + + // The descriptor refers to a character device inode. + DescriptorTypeCharacterDevice + + // The descriptor refers to a directory inode. + DescriptorTypeDirectory + + // The descriptor refers to a named pipe. + DescriptorTypeFIFO + + // The file refers to a symbolic link inode. + DescriptorTypeSymbolicLink + + // The descriptor refers to a regular file inode. + DescriptorTypeRegularFile + + // The descriptor refers to a socket. + DescriptorTypeSocket +) + +var stringsDescriptorType = [8]string{ + "unknown", + "block-device", + "character-device", + "directory", + "fifo", + "symbolic-link", + "regular-file", + "socket", +} + +// String implements [fmt.Stringer], returning the enum case name of e. +func (e DescriptorType) String() string { + return stringsDescriptorType[e] +} + +// DescriptorFlags represents the flags "wasi:filesystem/types@0.2.1#descriptor-flags". +// +// Descriptor flags. +// +// Note: This was called `fdflags` in earlier versions of WASI. +// +// flags descriptor-flags { +// read, +// write, +// file-integrity-sync, +// data-integrity-sync, +// requested-write-sync, +// mutate-directory, +// } +type DescriptorFlags uint8 + +const ( + // Read mode: Data can be read. + DescriptorFlagsRead DescriptorFlags = 1 << iota + + // Write mode: Data can be written to. + DescriptorFlagsWrite + + // Request that writes be performed according to synchronized I/O file + // integrity completion. The data stored in the file and the file's + // metadata are synchronized. This is similar to `O_SYNC` in POSIX. + // + // The precise semantics of this operation have not yet been defined for + // WASI. At this time, it should be interpreted as a request, and not a + // requirement. + DescriptorFlagsFileIntegritySync + + // Request that writes be performed according to synchronized I/O data + // integrity completion. Only the data stored in the file is + // synchronized. This is similar to `O_DSYNC` in POSIX. + // + // The precise semantics of this operation have not yet been defined for + // WASI. At this time, it should be interpreted as a request, and not a + // requirement. + DescriptorFlagsDataIntegritySync + + // Requests that reads be performed at the same level of integrity + // requested for writes. This is similar to `O_RSYNC` in POSIX. + // + // The precise semantics of this operation have not yet been defined for + // WASI. At this time, it should be interpreted as a request, and not a + // requirement. + DescriptorFlagsRequestedWriteSync + + // Mutating directories mode: Directory contents may be mutated. + // + // When this flag is unset on a descriptor, operations using the + // descriptor which would create, rename, delete, modify the data or + // metadata of filesystem objects, or obtain another handle which + // would permit any of those, shall fail with `error-code::read-only` if + // they would otherwise succeed. + // + // This may only be set on directories. + DescriptorFlagsMutateDirectory +) + +// PathFlags represents the flags "wasi:filesystem/types@0.2.1#path-flags". +// +// Flags determining the method of how paths are resolved. +// +// flags path-flags { +// symlink-follow, +// } +type PathFlags uint8 + +const ( + // As long as the resolved path corresponds to a symbolic link, it is + // expanded. + PathFlagsSymlinkFollow PathFlags = 1 << iota +) + +// OpenFlags represents the flags "wasi:filesystem/types@0.2.1#open-flags". +// +// Open flags used by `open-at`. +// +// flags open-flags { +// create, +// directory, +// exclusive, +// truncate, +// } +type OpenFlags uint8 + +const ( + // Create file if it does not exist, similar to `O_CREAT` in POSIX. + OpenFlagsCreate OpenFlags = 1 << iota + + // Fail if not a directory, similar to `O_DIRECTORY` in POSIX. + OpenFlagsDirectory + + // Fail if file already exists, similar to `O_EXCL` in POSIX. + OpenFlagsExclusive + + // Truncate file to size 0, similar to `O_TRUNC` in POSIX. + OpenFlagsTruncate +) + +// LinkCount represents the u64 "wasi:filesystem/types@0.2.1#link-count". +// +// Number of hard links to an inode. +// +// type link-count = u64 +type LinkCount uint64 + +// DescriptorStat represents the record "wasi:filesystem/types@0.2.1#descriptor-stat". +// +// File attributes. +// +// Note: This was called `filestat` in earlier versions of WASI. +// +// record descriptor-stat { +// %type: descriptor-type, +// link-count: link-count, +// size: filesize, +// data-access-timestamp: option, +// data-modification-timestamp: option, +// status-change-timestamp: option, +// } +type DescriptorStat struct { + // File type. + Type DescriptorType + + // Number of hard links to the file. + LinkCount LinkCount + + // For regular files, the file size in bytes. For symbolic links, the + // length in bytes of the pathname contained in the symbolic link. + Size FileSize + + // Last data access timestamp. + // + // If the `option` is none, the platform doesn't maintain an access + // timestamp for this file. + DataAccessTimestamp cm.Option[wallclock.DateTime] + + // Last data modification timestamp. + // + // If the `option` is none, the platform doesn't maintain a + // modification timestamp for this file. + DataModificationTimestamp cm.Option[wallclock.DateTime] + + // Last file status-change timestamp. + // + // If the `option` is none, the platform doesn't maintain a + // status-change timestamp for this file. + StatusChangeTimestamp cm.Option[wallclock.DateTime] +} + +// NewTimestamp represents the variant "wasi:filesystem/types@0.2.1#new-timestamp". +// +// When setting a timestamp, this gives the value to set it to. +// +// variant new-timestamp { +// no-change, +// now, +// timestamp(datetime), +// } +type NewTimestamp cm.Variant[uint8, wallclock.DateTime, wallclock.DateTime] + +// NewTimestampNoChange returns a [NewTimestamp] of case "no-change". +// +// Leave the timestamp set to its previous value. +func NewTimestampNoChange() NewTimestamp { + var data struct{} + return cm.New[NewTimestamp](0, data) +} + +// NoChange returns true if [NewTimestamp] represents the variant case "no-change". +func (self *NewTimestamp) NoChange() bool { + return self.Tag() == 0 +} + +// NewTimestampNow returns a [NewTimestamp] of case "now". +// +// Set the timestamp to the current time of the system clock associated +// with the filesystem. +func NewTimestampNow() NewTimestamp { + var data struct{} + return cm.New[NewTimestamp](1, data) +} + +// Now returns true if [NewTimestamp] represents the variant case "now". +func (self *NewTimestamp) Now() bool { + return self.Tag() == 1 +} + +// NewTimestampTimestamp returns a [NewTimestamp] of case "timestamp". +// +// Set the timestamp to the given value. +func NewTimestampTimestamp(data wallclock.DateTime) NewTimestamp { + return cm.New[NewTimestamp](2, data) +} + +// Timestamp returns a non-nil *[wallclock.DateTime] if [NewTimestamp] represents the variant case "timestamp". +func (self *NewTimestamp) Timestamp() *wallclock.DateTime { + return cm.Case[wallclock.DateTime](self, 2) +} + +// DirectoryEntry represents the record "wasi:filesystem/types@0.2.1#directory-entry". +// +// A directory entry. +// +// record directory-entry { +// %type: descriptor-type, +// name: string, +// } +type DirectoryEntry struct { + // The type of the file referred to by this directory entry. + Type DescriptorType + + // The name of the object. + Name string +} + +// ErrorCode represents the enum "wasi:filesystem/types@0.2.1#error-code". +// +// Error codes returned by functions, similar to `errno` in POSIX. +// Not all of these error codes are returned by the functions provided by this +// API; some are used in higher-level library layers, and others are provided +// merely for alignment with POSIX. +// +// enum error-code { +// access, +// would-block, +// already, +// bad-descriptor, +// busy, +// deadlock, +// quota, +// exist, +// file-too-large, +// illegal-byte-sequence, +// in-progress, +// interrupted, +// invalid, +// io, +// is-directory, +// loop, +// too-many-links, +// message-size, +// name-too-long, +// no-device, +// no-entry, +// no-lock, +// insufficient-memory, +// insufficient-space, +// not-directory, +// not-empty, +// not-recoverable, +// unsupported, +// no-tty, +// no-such-device, +// overflow, +// not-permitted, +// pipe, +// read-only, +// invalid-seek, +// text-file-busy, +// cross-device +// } +type ErrorCode uint8 + +const ( + // Permission denied, similar to `EACCES` in POSIX. + ErrorCodeAccess ErrorCode = iota + + // Resource unavailable, or operation would block, similar to `EAGAIN` and `EWOULDBLOCK` + // in POSIX. + ErrorCodeWouldBlock + + // Connection already in progress, similar to `EALREADY` in POSIX. + ErrorCodeAlready + + // Bad descriptor, similar to `EBADF` in POSIX. + ErrorCodeBadDescriptor + + // Device or resource busy, similar to `EBUSY` in POSIX. + ErrorCodeBusy + + // Resource deadlock would occur, similar to `EDEADLK` in POSIX. + ErrorCodeDeadlock + + // Storage quota exceeded, similar to `EDQUOT` in POSIX. + ErrorCodeQuota + + // File exists, similar to `EEXIST` in POSIX. + ErrorCodeExist + + // File too large, similar to `EFBIG` in POSIX. + ErrorCodeFileTooLarge + + // Illegal byte sequence, similar to `EILSEQ` in POSIX. + ErrorCodeIllegalByteSequence + + // Operation in progress, similar to `EINPROGRESS` in POSIX. + ErrorCodeInProgress + + // Interrupted function, similar to `EINTR` in POSIX. + ErrorCodeInterrupted + + // Invalid argument, similar to `EINVAL` in POSIX. + ErrorCodeInvalid + + // I/O error, similar to `EIO` in POSIX. + ErrorCodeIO + + // Is a directory, similar to `EISDIR` in POSIX. + ErrorCodeIsDirectory + + // Too many levels of symbolic links, similar to `ELOOP` in POSIX. + ErrorCodeLoop + + // Too many links, similar to `EMLINK` in POSIX. + ErrorCodeTooManyLinks + + // Message too large, similar to `EMSGSIZE` in POSIX. + ErrorCodeMessageSize + + // Filename too long, similar to `ENAMETOOLONG` in POSIX. + ErrorCodeNameTooLong + + // No such device, similar to `ENODEV` in POSIX. + ErrorCodeNoDevice + + // No such file or directory, similar to `ENOENT` in POSIX. + ErrorCodeNoEntry + + // No locks available, similar to `ENOLCK` in POSIX. + ErrorCodeNoLock + + // Not enough space, similar to `ENOMEM` in POSIX. + ErrorCodeInsufficientMemory + + // No space left on device, similar to `ENOSPC` in POSIX. + ErrorCodeInsufficientSpace + + // Not a directory or a symbolic link to a directory, similar to `ENOTDIR` in POSIX. + ErrorCodeNotDirectory + + // Directory not empty, similar to `ENOTEMPTY` in POSIX. + ErrorCodeNotEmpty + + // State not recoverable, similar to `ENOTRECOVERABLE` in POSIX. + ErrorCodeNotRecoverable + + // Not supported, similar to `ENOTSUP` and `ENOSYS` in POSIX. + ErrorCodeUnsupported + + // Inappropriate I/O control operation, similar to `ENOTTY` in POSIX. + ErrorCodeNoTTY + + // No such device or address, similar to `ENXIO` in POSIX. + ErrorCodeNoSuchDevice + + // Value too large to be stored in data type, similar to `EOVERFLOW` in POSIX. + ErrorCodeOverflow + + // Operation not permitted, similar to `EPERM` in POSIX. + ErrorCodeNotPermitted + + // Broken pipe, similar to `EPIPE` in POSIX. + ErrorCodePipe + + // Read-only file system, similar to `EROFS` in POSIX. + ErrorCodeReadOnly + + // Invalid seek, similar to `ESPIPE` in POSIX. + ErrorCodeInvalidSeek + + // Text file busy, similar to `ETXTBSY` in POSIX. + ErrorCodeTextFileBusy + + // Cross-device link, similar to `EXDEV` in POSIX. + ErrorCodeCrossDevice +) + +var stringsErrorCode = [37]string{ + "access", + "would-block", + "already", + "bad-descriptor", + "busy", + "deadlock", + "quota", + "exist", + "file-too-large", + "illegal-byte-sequence", + "in-progress", + "interrupted", + "invalid", + "io", + "is-directory", + "loop", + "too-many-links", + "message-size", + "name-too-long", + "no-device", + "no-entry", + "no-lock", + "insufficient-memory", + "insufficient-space", + "not-directory", + "not-empty", + "not-recoverable", + "unsupported", + "no-tty", + "no-such-device", + "overflow", + "not-permitted", + "pipe", + "read-only", + "invalid-seek", + "text-file-busy", + "cross-device", +} + +// String implements [fmt.Stringer], returning the enum case name of e. +func (e ErrorCode) String() string { + return stringsErrorCode[e] +} + +// Advice represents the enum "wasi:filesystem/types@0.2.1#advice". +// +// File or memory access pattern advisory information. +// +// enum advice { +// normal, +// sequential, +// random, +// will-need, +// dont-need, +// no-reuse +// } +type Advice uint8 + +const ( + // The application has no advice to give on its behavior with respect + // to the specified data. + AdviceNormal Advice = iota + + // The application expects to access the specified data sequentially + // from lower offsets to higher offsets. + AdviceSequential + + // The application expects to access the specified data in a random + // order. + AdviceRandom + + // The application expects to access the specified data in the near + // future. + AdviceWillNeed + + // The application expects that it will not access the specified data + // in the near future. + AdviceDontNeed + + // The application expects to access the specified data once and then + // not reuse it thereafter. + AdviceNoReuse +) + +var stringsAdvice = [6]string{ + "normal", + "sequential", + "random", + "will-need", + "dont-need", + "no-reuse", +} + +// String implements [fmt.Stringer], returning the enum case name of e. +func (e Advice) String() string { + return stringsAdvice[e] +} + +// MetadataHashValue represents the record "wasi:filesystem/types@0.2.1#metadata-hash-value". +// +// A 128-bit hash value, split into parts because wasm doesn't have a +// 128-bit integer type. +// +// record metadata-hash-value { +// lower: u64, +// upper: u64, +// } +type MetadataHashValue struct { + // 64 bits of a 128-bit hash value. + Lower uint64 + + // Another 64 bits of a 128-bit hash value. + Upper uint64 +} + +// Descriptor represents the imported resource "wasi:filesystem/types@0.2.1#descriptor". +// +// A descriptor is a reference to a filesystem object, which may be a file, +// directory, named pipe, special file, or other object on which filesystem +// calls may be made. +// +// resource descriptor +type Descriptor cm.Resource + +// ResourceDrop represents the imported resource-drop for resource "descriptor". +// +// Drops a resource handle. +// +//go:nosplit +func (self Descriptor) ResourceDrop() { + self0 := cm.Reinterpret[uint32](self) + wasmimport_DescriptorResourceDrop((uint32)(self0)) + return +} + +//go:wasmimport wasi:filesystem/types@0.2.1 [resource-drop]descriptor +//go:noescape +func wasmimport_DescriptorResourceDrop(self0 uint32) + +// Advise represents the imported method "advise". +// +// Provide file advisory information on a descriptor. +// +// This is similar to `posix_fadvise` in POSIX. +// +// advise: func(offset: filesize, length: filesize, advice: advice) -> result<_, error-code> +// +//go:nosplit +func (self Descriptor) Advise(offset FileSize, length FileSize, advice Advice) (result cm.Result[ErrorCode, struct{}, ErrorCode]) { + self0 := cm.Reinterpret[uint32](self) + offset0 := (uint64)(offset) + length0 := (uint64)(length) + advice0 := (uint32)(advice) + wasmimport_DescriptorAdvise((uint32)(self0), (uint64)(offset0), (uint64)(length0), (uint32)(advice0), &result) + return +} + +//go:wasmimport wasi:filesystem/types@0.2.1 [method]descriptor.advise +//go:noescape +func wasmimport_DescriptorAdvise(self0 uint32, offset0 uint64, length0 uint64, advice0 uint32, result *cm.Result[ErrorCode, struct{}, ErrorCode]) + +// AppendViaStream represents the imported method "append-via-stream". +// +// Return a stream for appending to a file, if available. +// +// May fail with an error-code describing why the file cannot be appended. +// +// Note: This allows using `write-stream`, which is similar to `write` with +// `O_APPEND` in in POSIX. +// +// append-via-stream: func() -> result +// +//go:nosplit +func (self Descriptor) AppendViaStream() (result cm.Result[streams.OutputStream, streams.OutputStream, ErrorCode]) { + self0 := cm.Reinterpret[uint32](self) + wasmimport_DescriptorAppendViaStream((uint32)(self0), &result) + return +} + +//go:wasmimport wasi:filesystem/types@0.2.1 [method]descriptor.append-via-stream +//go:noescape +func wasmimport_DescriptorAppendViaStream(self0 uint32, result *cm.Result[streams.OutputStream, streams.OutputStream, ErrorCode]) + +// CreateDirectoryAt represents the imported method "create-directory-at". +// +// Create a directory. +// +// Note: This is similar to `mkdirat` in POSIX. +// +// create-directory-at: func(path: string) -> result<_, error-code> +// +//go:nosplit +func (self Descriptor) CreateDirectoryAt(path string) (result cm.Result[ErrorCode, struct{}, ErrorCode]) { + self0 := cm.Reinterpret[uint32](self) + path0, path1 := cm.LowerString(path) + wasmimport_DescriptorCreateDirectoryAt((uint32)(self0), (*uint8)(path0), (uint32)(path1), &result) + return +} + +//go:wasmimport wasi:filesystem/types@0.2.1 [method]descriptor.create-directory-at +//go:noescape +func wasmimport_DescriptorCreateDirectoryAt(self0 uint32, path0 *uint8, path1 uint32, result *cm.Result[ErrorCode, struct{}, ErrorCode]) + +// GetFlags represents the imported method "get-flags". +// +// Get flags associated with a descriptor. +// +// Note: This returns similar flags to `fcntl(fd, F_GETFL)` in POSIX. +// +// Note: This returns the value that was the `fs_flags` value returned +// from `fdstat_get` in earlier versions of WASI. +// +// get-flags: func() -> result +// +//go:nosplit +func (self Descriptor) GetFlags() (result cm.Result[DescriptorFlags, DescriptorFlags, ErrorCode]) { + self0 := cm.Reinterpret[uint32](self) + wasmimport_DescriptorGetFlags((uint32)(self0), &result) + return +} + +//go:wasmimport wasi:filesystem/types@0.2.1 [method]descriptor.get-flags +//go:noescape +func wasmimport_DescriptorGetFlags(self0 uint32, result *cm.Result[DescriptorFlags, DescriptorFlags, ErrorCode]) + +// GetType represents the imported method "get-type". +// +// Get the dynamic type of a descriptor. +// +// Note: This returns the same value as the `type` field of the `fd-stat` +// returned by `stat`, `stat-at` and similar. +// +// Note: This returns similar flags to the `st_mode & S_IFMT` value provided +// by `fstat` in POSIX. +// +// Note: This returns the value that was the `fs_filetype` value returned +// from `fdstat_get` in earlier versions of WASI. +// +// get-type: func() -> result +// +//go:nosplit +func (self Descriptor) GetType() (result cm.Result[DescriptorType, DescriptorType, ErrorCode]) { + self0 := cm.Reinterpret[uint32](self) + wasmimport_DescriptorGetType((uint32)(self0), &result) + return +} + +//go:wasmimport wasi:filesystem/types@0.2.1 [method]descriptor.get-type +//go:noescape +func wasmimport_DescriptorGetType(self0 uint32, result *cm.Result[DescriptorType, DescriptorType, ErrorCode]) + +// IsSameObject represents the imported method "is-same-object". +// +// Test whether two descriptors refer to the same filesystem object. +// +// In POSIX, this corresponds to testing whether the two descriptors have the +// same device (`st_dev`) and inode (`st_ino` or `d_ino`) numbers. +// wasi-filesystem does not expose device and inode numbers, so this function +// may be used instead. +// +// is-same-object: func(other: borrow) -> bool +// +//go:nosplit +func (self Descriptor) IsSameObject(other Descriptor) (result bool) { + self0 := cm.Reinterpret[uint32](self) + other0 := cm.Reinterpret[uint32](other) + result0 := wasmimport_DescriptorIsSameObject((uint32)(self0), (uint32)(other0)) + result = cm.U32ToBool((uint32)(result0)) + return +} + +//go:wasmimport wasi:filesystem/types@0.2.1 [method]descriptor.is-same-object +//go:noescape +func wasmimport_DescriptorIsSameObject(self0 uint32, other0 uint32) (result0 uint32) + +// LinkAt represents the imported method "link-at". +// +// Create a hard link. +// +// Note: This is similar to `linkat` in POSIX. +// +// link-at: func(old-path-flags: path-flags, old-path: string, new-descriptor: borrow, +// new-path: string) -> result<_, error-code> +// +//go:nosplit +func (self Descriptor) LinkAt(oldPathFlags PathFlags, oldPath string, newDescriptor Descriptor, newPath string) (result cm.Result[ErrorCode, struct{}, ErrorCode]) { + self0 := cm.Reinterpret[uint32](self) + oldPathFlags0 := (uint32)(oldPathFlags) + oldPath0, oldPath1 := cm.LowerString(oldPath) + newDescriptor0 := cm.Reinterpret[uint32](newDescriptor) + newPath0, newPath1 := cm.LowerString(newPath) + wasmimport_DescriptorLinkAt((uint32)(self0), (uint32)(oldPathFlags0), (*uint8)(oldPath0), (uint32)(oldPath1), (uint32)(newDescriptor0), (*uint8)(newPath0), (uint32)(newPath1), &result) + return +} + +//go:wasmimport wasi:filesystem/types@0.2.1 [method]descriptor.link-at +//go:noescape +func wasmimport_DescriptorLinkAt(self0 uint32, oldPathFlags0 uint32, oldPath0 *uint8, oldPath1 uint32, newDescriptor0 uint32, newPath0 *uint8, newPath1 uint32, result *cm.Result[ErrorCode, struct{}, ErrorCode]) + +// MetadataHash represents the imported method "metadata-hash". +// +// Return a hash of the metadata associated with a filesystem object referred +// to by a descriptor. +// +// This returns a hash of the last-modification timestamp and file size, and +// may also include the inode number, device number, birth timestamp, and +// other metadata fields that may change when the file is modified or +// replaced. It may also include a secret value chosen by the +// implementation and not otherwise exposed. +// +// Implementations are encourated to provide the following properties: +// +// - If the file is not modified or replaced, the computed hash value should +// usually not change. +// - If the object is modified or replaced, the computed hash value should +// usually change. +// - The inputs to the hash should not be easily computable from the +// computed hash. +// +// However, none of these is required. +// +// metadata-hash: func() -> result +// +//go:nosplit +func (self Descriptor) MetadataHash() (result cm.Result[MetadataHashValueShape, MetadataHashValue, ErrorCode]) { + self0 := cm.Reinterpret[uint32](self) + wasmimport_DescriptorMetadataHash((uint32)(self0), &result) + return +} + +//go:wasmimport wasi:filesystem/types@0.2.1 [method]descriptor.metadata-hash +//go:noescape +func wasmimport_DescriptorMetadataHash(self0 uint32, result *cm.Result[MetadataHashValueShape, MetadataHashValue, ErrorCode]) + +// MetadataHashAt represents the imported method "metadata-hash-at". +// +// 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`. +// +// metadata-hash-at: func(path-flags: path-flags, path: string) -> result +// +//go:nosplit +func (self Descriptor) MetadataHashAt(pathFlags PathFlags, path string) (result cm.Result[MetadataHashValueShape, MetadataHashValue, ErrorCode]) { + self0 := cm.Reinterpret[uint32](self) + pathFlags0 := (uint32)(pathFlags) + path0, path1 := cm.LowerString(path) + wasmimport_DescriptorMetadataHashAt((uint32)(self0), (uint32)(pathFlags0), (*uint8)(path0), (uint32)(path1), &result) + return +} + +//go:wasmimport wasi:filesystem/types@0.2.1 [method]descriptor.metadata-hash-at +//go:noescape +func wasmimport_DescriptorMetadataHashAt(self0 uint32, pathFlags0 uint32, path0 *uint8, path1 uint32, result *cm.Result[MetadataHashValueShape, MetadataHashValue, ErrorCode]) + +// OpenAt represents the imported method "open-at". +// +// Open a file or directory. +// +// The returned descriptor is not guaranteed to be the lowest-numbered +// descriptor not currently open/ it is randomized to prevent applications +// from depending on making assumptions about indexes, since this is +// error-prone in multi-threaded contexts. The returned descriptor is +// guaranteed to be less than 2**31. +// +// If `flags` contains `descriptor-flags::mutate-directory`, and the base +// descriptor doesn't have `descriptor-flags::mutate-directory` set, +// `open-at` fails with `error-code::read-only`. +// +// If `flags` contains `write` or `mutate-directory`, or `open-flags` +// contains `truncate` or `create`, and the base descriptor doesn't have +// `descriptor-flags::mutate-directory` set, `open-at` fails with +// `error-code::read-only`. +// +// Note: This is similar to `openat` in POSIX. +// +// open-at: func(path-flags: path-flags, path: string, open-flags: open-flags, %flags: +// descriptor-flags) -> result +// +//go:nosplit +func (self Descriptor) OpenAt(pathFlags PathFlags, path string, openFlags OpenFlags, flags DescriptorFlags) (result cm.Result[Descriptor, Descriptor, ErrorCode]) { + self0 := cm.Reinterpret[uint32](self) + pathFlags0 := (uint32)(pathFlags) + path0, path1 := cm.LowerString(path) + openFlags0 := (uint32)(openFlags) + flags0 := (uint32)(flags) + wasmimport_DescriptorOpenAt((uint32)(self0), (uint32)(pathFlags0), (*uint8)(path0), (uint32)(path1), (uint32)(openFlags0), (uint32)(flags0), &result) + return +} + +//go:wasmimport wasi:filesystem/types@0.2.1 [method]descriptor.open-at +//go:noescape +func wasmimport_DescriptorOpenAt(self0 uint32, pathFlags0 uint32, path0 *uint8, path1 uint32, openFlags0 uint32, flags0 uint32, result *cm.Result[Descriptor, Descriptor, ErrorCode]) + +// Read represents the imported method "read". +// +// Read from a descriptor, without using and updating the descriptor's offset. +// +// This function returns a list of bytes containing the data that was +// read, along with a bool which, when true, indicates that the end of the +// file was reached. The returned list will contain up to `length` bytes; it +// may return fewer than requested, if the end of the file is reached or +// if the I/O operation is interrupted. +// +// In the future, this may change to return a `stream`. +// +// Note: This is similar to `pread` in POSIX. +// +// read: func(length: filesize, offset: filesize) -> result, bool>, +// error-code> +// +//go:nosplit +func (self Descriptor) Read(length FileSize, offset FileSize) (result cm.Result[TupleListU8BoolShape, cm.Tuple[cm.List[uint8], bool], ErrorCode]) { + self0 := cm.Reinterpret[uint32](self) + length0 := (uint64)(length) + offset0 := (uint64)(offset) + wasmimport_DescriptorRead((uint32)(self0), (uint64)(length0), (uint64)(offset0), &result) + return +} + +//go:wasmimport wasi:filesystem/types@0.2.1 [method]descriptor.read +//go:noescape +func wasmimport_DescriptorRead(self0 uint32, length0 uint64, offset0 uint64, result *cm.Result[TupleListU8BoolShape, cm.Tuple[cm.List[uint8], bool], ErrorCode]) + +// ReadDirectory represents the imported method "read-directory". +// +// Read directory entries from a directory. +// +// On filesystems where directories contain entries referring to themselves +// and their parents, often named `.` and `..` respectively, these entries +// are omitted. +// +// This always returns a new stream which starts at the beginning of the +// directory. Multiple streams may be active on the same directory, and they +// do not interfere with each other. +// +// read-directory: func() -> result +// +//go:nosplit +func (self Descriptor) ReadDirectory() (result cm.Result[DirectoryEntryStream, DirectoryEntryStream, ErrorCode]) { + self0 := cm.Reinterpret[uint32](self) + wasmimport_DescriptorReadDirectory((uint32)(self0), &result) + return +} + +//go:wasmimport wasi:filesystem/types@0.2.1 [method]descriptor.read-directory +//go:noescape +func wasmimport_DescriptorReadDirectory(self0 uint32, result *cm.Result[DirectoryEntryStream, DirectoryEntryStream, ErrorCode]) + +// ReadViaStream represents the imported method "read-via-stream". +// +// Return a stream for reading from a file, if available. +// +// May fail with an error-code describing why the file cannot be read. +// +// Multiple read, write, and append streams may be active on the same open +// file and they do not interfere with each other. +// +// Note: This allows using `read-stream`, which is similar to `read` in POSIX. +// +// read-via-stream: func(offset: filesize) -> result +// +//go:nosplit +func (self Descriptor) ReadViaStream(offset FileSize) (result cm.Result[streams.InputStream, streams.InputStream, ErrorCode]) { + self0 := cm.Reinterpret[uint32](self) + offset0 := (uint64)(offset) + wasmimport_DescriptorReadViaStream((uint32)(self0), (uint64)(offset0), &result) + return +} + +//go:wasmimport wasi:filesystem/types@0.2.1 [method]descriptor.read-via-stream +//go:noescape +func wasmimport_DescriptorReadViaStream(self0 uint32, offset0 uint64, result *cm.Result[streams.InputStream, streams.InputStream, ErrorCode]) + +// ReadLinkAt represents the imported method "readlink-at". +// +// Read the contents of a symbolic link. +// +// If the contents contain an absolute or rooted path in the underlying +// filesystem, this function fails with `error-code::not-permitted`. +// +// Note: This is similar to `readlinkat` in POSIX. +// +// readlink-at: func(path: string) -> result +// +//go:nosplit +func (self Descriptor) ReadLinkAt(path string) (result cm.Result[string, string, ErrorCode]) { + self0 := cm.Reinterpret[uint32](self) + path0, path1 := cm.LowerString(path) + wasmimport_DescriptorReadLinkAt((uint32)(self0), (*uint8)(path0), (uint32)(path1), &result) + return +} + +//go:wasmimport wasi:filesystem/types@0.2.1 [method]descriptor.readlink-at +//go:noescape +func wasmimport_DescriptorReadLinkAt(self0 uint32, path0 *uint8, path1 uint32, result *cm.Result[string, string, ErrorCode]) + +// RemoveDirectoryAt represents the imported method "remove-directory-at". +// +// Remove a directory. +// +// Return `error-code::not-empty` if the directory is not empty. +// +// Note: This is similar to `unlinkat(fd, path, AT_REMOVEDIR)` in POSIX. +// +// remove-directory-at: func(path: string) -> result<_, error-code> +// +//go:nosplit +func (self Descriptor) RemoveDirectoryAt(path string) (result cm.Result[ErrorCode, struct{}, ErrorCode]) { + self0 := cm.Reinterpret[uint32](self) + path0, path1 := cm.LowerString(path) + wasmimport_DescriptorRemoveDirectoryAt((uint32)(self0), (*uint8)(path0), (uint32)(path1), &result) + return +} + +//go:wasmimport wasi:filesystem/types@0.2.1 [method]descriptor.remove-directory-at +//go:noescape +func wasmimport_DescriptorRemoveDirectoryAt(self0 uint32, path0 *uint8, path1 uint32, result *cm.Result[ErrorCode, struct{}, ErrorCode]) + +// RenameAt represents the imported method "rename-at". +// +// Rename a filesystem object. +// +// Note: This is similar to `renameat` in POSIX. +// +// rename-at: func(old-path: string, new-descriptor: borrow, new-path: +// string) -> result<_, error-code> +// +//go:nosplit +func (self Descriptor) RenameAt(oldPath string, newDescriptor Descriptor, newPath string) (result cm.Result[ErrorCode, struct{}, ErrorCode]) { + self0 := cm.Reinterpret[uint32](self) + oldPath0, oldPath1 := cm.LowerString(oldPath) + newDescriptor0 := cm.Reinterpret[uint32](newDescriptor) + newPath0, newPath1 := cm.LowerString(newPath) + wasmimport_DescriptorRenameAt((uint32)(self0), (*uint8)(oldPath0), (uint32)(oldPath1), (uint32)(newDescriptor0), (*uint8)(newPath0), (uint32)(newPath1), &result) + return +} + +//go:wasmimport wasi:filesystem/types@0.2.1 [method]descriptor.rename-at +//go:noescape +func wasmimport_DescriptorRenameAt(self0 uint32, oldPath0 *uint8, oldPath1 uint32, newDescriptor0 uint32, newPath0 *uint8, newPath1 uint32, result *cm.Result[ErrorCode, struct{}, ErrorCode]) + +// SetSize represents the imported method "set-size". +// +// 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. +// +// set-size: func(size: filesize) -> result<_, error-code> +// +//go:nosplit +func (self Descriptor) SetSize(size FileSize) (result cm.Result[ErrorCode, struct{}, ErrorCode]) { + self0 := cm.Reinterpret[uint32](self) + size0 := (uint64)(size) + wasmimport_DescriptorSetSize((uint32)(self0), (uint64)(size0), &result) + return +} + +//go:wasmimport wasi:filesystem/types@0.2.1 [method]descriptor.set-size +//go:noescape +func wasmimport_DescriptorSetSize(self0 uint32, size0 uint64, result *cm.Result[ErrorCode, struct{}, ErrorCode]) + +// SetTimes represents the imported method "set-times". +// +// Adjust the timestamps of an open file or directory. +// +// Note: This is similar to `futimens` in POSIX. +// +// Note: This was called `fd_filestat_set_times` in earlier versions of WASI. +// +// set-times: func(data-access-timestamp: new-timestamp, data-modification-timestamp: +// new-timestamp) -> result<_, error-code> +// +//go:nosplit +func (self Descriptor) SetTimes(dataAccessTimestamp NewTimestamp, dataModificationTimestamp NewTimestamp) (result cm.Result[ErrorCode, struct{}, ErrorCode]) { + self0 := cm.Reinterpret[uint32](self) + dataAccessTimestamp0, dataAccessTimestamp1, dataAccessTimestamp2 := lower_NewTimestamp(dataAccessTimestamp) + dataModificationTimestamp0, dataModificationTimestamp1, dataModificationTimestamp2 := lower_NewTimestamp(dataModificationTimestamp) + wasmimport_DescriptorSetTimes((uint32)(self0), (uint32)(dataAccessTimestamp0), (uint64)(dataAccessTimestamp1), (uint32)(dataAccessTimestamp2), (uint32)(dataModificationTimestamp0), (uint64)(dataModificationTimestamp1), (uint32)(dataModificationTimestamp2), &result) + return +} + +//go:wasmimport wasi:filesystem/types@0.2.1 [method]descriptor.set-times +//go:noescape +func wasmimport_DescriptorSetTimes(self0 uint32, dataAccessTimestamp0 uint32, dataAccessTimestamp1 uint64, dataAccessTimestamp2 uint32, dataModificationTimestamp0 uint32, dataModificationTimestamp1 uint64, dataModificationTimestamp2 uint32, result *cm.Result[ErrorCode, struct{}, ErrorCode]) + +// SetTimesAt represents the imported method "set-times-at". +// +// Adjust the timestamps of a file or directory. +// +// Note: This is similar to `utimensat` in POSIX. +// +// Note: This was called `path_filestat_set_times` in earlier versions of +// WASI. +// +// set-times-at: func(path-flags: path-flags, path: string, data-access-timestamp: +// new-timestamp, data-modification-timestamp: new-timestamp) -> result<_, error-code> +// +//go:nosplit +func (self Descriptor) SetTimesAt(pathFlags PathFlags, path string, dataAccessTimestamp NewTimestamp, dataModificationTimestamp NewTimestamp) (result cm.Result[ErrorCode, struct{}, ErrorCode]) { + self0 := cm.Reinterpret[uint32](self) + pathFlags0 := (uint32)(pathFlags) + path0, path1 := cm.LowerString(path) + dataAccessTimestamp0, dataAccessTimestamp1, dataAccessTimestamp2 := lower_NewTimestamp(dataAccessTimestamp) + dataModificationTimestamp0, dataModificationTimestamp1, dataModificationTimestamp2 := lower_NewTimestamp(dataModificationTimestamp) + wasmimport_DescriptorSetTimesAt((uint32)(self0), (uint32)(pathFlags0), (*uint8)(path0), (uint32)(path1), (uint32)(dataAccessTimestamp0), (uint64)(dataAccessTimestamp1), (uint32)(dataAccessTimestamp2), (uint32)(dataModificationTimestamp0), (uint64)(dataModificationTimestamp1), (uint32)(dataModificationTimestamp2), &result) + return +} + +//go:wasmimport wasi:filesystem/types@0.2.1 [method]descriptor.set-times-at +//go:noescape +func wasmimport_DescriptorSetTimesAt(self0 uint32, pathFlags0 uint32, path0 *uint8, path1 uint32, dataAccessTimestamp0 uint32, dataAccessTimestamp1 uint64, dataAccessTimestamp2 uint32, dataModificationTimestamp0 uint32, dataModificationTimestamp1 uint64, dataModificationTimestamp2 uint32, result *cm.Result[ErrorCode, struct{}, ErrorCode]) + +// Stat represents the imported method "stat". +// +// Return the attributes of an open file or directory. +// +// Note: This is similar to `fstat` in POSIX, except that it does not return +// device and inode information. For testing whether two descriptors refer to +// the same underlying filesystem object, use `is-same-object`. To obtain +// additional data that can be used do determine whether a file has been +// modified, use `metadata-hash`. +// +// Note: This was called `fd_filestat_get` in earlier versions of WASI. +// +// stat: func() -> result +// +//go:nosplit +func (self Descriptor) Stat() (result cm.Result[DescriptorStatShape, DescriptorStat, ErrorCode]) { + self0 := cm.Reinterpret[uint32](self) + wasmimport_DescriptorStat((uint32)(self0), &result) + return +} + +//go:wasmimport wasi:filesystem/types@0.2.1 [method]descriptor.stat +//go:noescape +func wasmimport_DescriptorStat(self0 uint32, result *cm.Result[DescriptorStatShape, DescriptorStat, ErrorCode]) + +// StatAt represents the imported method "stat-at". +// +// Return the attributes of a file or directory. +// +// Note: This is similar to `fstatat` in POSIX, except that it does not +// return device and inode information. See the `stat` description for a +// discussion of alternatives. +// +// Note: This was called `path_filestat_get` in earlier versions of WASI. +// +// stat-at: func(path-flags: path-flags, path: string) -> result +// +//go:nosplit +func (self Descriptor) StatAt(pathFlags PathFlags, path string) (result cm.Result[DescriptorStatShape, DescriptorStat, ErrorCode]) { + self0 := cm.Reinterpret[uint32](self) + pathFlags0 := (uint32)(pathFlags) + path0, path1 := cm.LowerString(path) + wasmimport_DescriptorStatAt((uint32)(self0), (uint32)(pathFlags0), (*uint8)(path0), (uint32)(path1), &result) + return +} + +//go:wasmimport wasi:filesystem/types@0.2.1 [method]descriptor.stat-at +//go:noescape +func wasmimport_DescriptorStatAt(self0 uint32, pathFlags0 uint32, path0 *uint8, path1 uint32, result *cm.Result[DescriptorStatShape, DescriptorStat, ErrorCode]) + +// SymlinkAt represents the imported method "symlink-at". +// +// Create a symbolic link (also known as a "symlink"). +// +// If `old-path` starts with `/`, the function fails with +// `error-code::not-permitted`. +// +// Note: This is similar to `symlinkat` in POSIX. +// +// symlink-at: func(old-path: string, new-path: string) -> result<_, error-code> +// +//go:nosplit +func (self Descriptor) SymlinkAt(oldPath string, newPath string) (result cm.Result[ErrorCode, struct{}, ErrorCode]) { + self0 := cm.Reinterpret[uint32](self) + oldPath0, oldPath1 := cm.LowerString(oldPath) + newPath0, newPath1 := cm.LowerString(newPath) + wasmimport_DescriptorSymlinkAt((uint32)(self0), (*uint8)(oldPath0), (uint32)(oldPath1), (*uint8)(newPath0), (uint32)(newPath1), &result) + return +} + +//go:wasmimport wasi:filesystem/types@0.2.1 [method]descriptor.symlink-at +//go:noescape +func wasmimport_DescriptorSymlinkAt(self0 uint32, oldPath0 *uint8, oldPath1 uint32, newPath0 *uint8, newPath1 uint32, result *cm.Result[ErrorCode, struct{}, ErrorCode]) + +// Sync represents the imported method "sync". +// +// Synchronize the data and metadata of a file to disk. +// +// This function succeeds with no effect if the file descriptor is not +// opened for writing. +// +// Note: This is similar to `fsync` in POSIX. +// +// sync: func() -> result<_, error-code> +// +//go:nosplit +func (self Descriptor) Sync() (result cm.Result[ErrorCode, struct{}, ErrorCode]) { + self0 := cm.Reinterpret[uint32](self) + wasmimport_DescriptorSync((uint32)(self0), &result) + return +} + +//go:wasmimport wasi:filesystem/types@0.2.1 [method]descriptor.sync +//go:noescape +func wasmimport_DescriptorSync(self0 uint32, result *cm.Result[ErrorCode, struct{}, ErrorCode]) + +// SyncData represents the imported method "sync-data". +// +// Synchronize the data of a file to disk. +// +// This function succeeds with no effect if the file descriptor is not +// opened for writing. +// +// Note: This is similar to `fdatasync` in POSIX. +// +// sync-data: func() -> result<_, error-code> +// +//go:nosplit +func (self Descriptor) SyncData() (result cm.Result[ErrorCode, struct{}, ErrorCode]) { + self0 := cm.Reinterpret[uint32](self) + wasmimport_DescriptorSyncData((uint32)(self0), &result) + return +} + +//go:wasmimport wasi:filesystem/types@0.2.1 [method]descriptor.sync-data +//go:noescape +func wasmimport_DescriptorSyncData(self0 uint32, result *cm.Result[ErrorCode, struct{}, ErrorCode]) + +// UnlinkFileAt represents the imported method "unlink-file-at". +// +// Unlink a filesystem object that is not a directory. +// +// Return `error-code::is-directory` if the path refers to a directory. +// Note: This is similar to `unlinkat(fd, path, 0)` in POSIX. +// +// unlink-file-at: func(path: string) -> result<_, error-code> +// +//go:nosplit +func (self Descriptor) UnlinkFileAt(path string) (result cm.Result[ErrorCode, struct{}, ErrorCode]) { + self0 := cm.Reinterpret[uint32](self) + path0, path1 := cm.LowerString(path) + wasmimport_DescriptorUnlinkFileAt((uint32)(self0), (*uint8)(path0), (uint32)(path1), &result) + return +} + +//go:wasmimport wasi:filesystem/types@0.2.1 [method]descriptor.unlink-file-at +//go:noescape +func wasmimport_DescriptorUnlinkFileAt(self0 uint32, path0 *uint8, path1 uint32, result *cm.Result[ErrorCode, struct{}, ErrorCode]) + +// Write represents the imported method "write". +// +// Write to a descriptor, without using and updating the descriptor's offset. +// +// It is valid to write past the end of a file; the file is extended to the +// extent of the write, with bytes between the previous end and the start of +// the write set to zero. +// +// In the future, this may change to take a `stream`. +// +// Note: This is similar to `pwrite` in POSIX. +// +// write: func(buffer: list, offset: filesize) -> result +// +//go:nosplit +func (self Descriptor) Write(buffer cm.List[uint8], offset FileSize) (result cm.Result[uint64, FileSize, ErrorCode]) { + self0 := cm.Reinterpret[uint32](self) + buffer0, buffer1 := cm.LowerList(buffer) + offset0 := (uint64)(offset) + wasmimport_DescriptorWrite((uint32)(self0), (*uint8)(buffer0), (uint32)(buffer1), (uint64)(offset0), &result) + return +} + +//go:wasmimport wasi:filesystem/types@0.2.1 [method]descriptor.write +//go:noescape +func wasmimport_DescriptorWrite(self0 uint32, buffer0 *uint8, buffer1 uint32, offset0 uint64, result *cm.Result[uint64, FileSize, ErrorCode]) + +// WriteViaStream represents the imported method "write-via-stream". +// +// Return a stream for writing to a file, if available. +// +// May fail with an error-code describing why the file cannot be written. +// +// Note: This allows using `write-stream`, which is similar to `write` in +// POSIX. +// +// write-via-stream: func(offset: filesize) -> result +// +//go:nosplit +func (self Descriptor) WriteViaStream(offset FileSize) (result cm.Result[streams.OutputStream, streams.OutputStream, ErrorCode]) { + self0 := cm.Reinterpret[uint32](self) + offset0 := (uint64)(offset) + wasmimport_DescriptorWriteViaStream((uint32)(self0), (uint64)(offset0), &result) + return +} + +//go:wasmimport wasi:filesystem/types@0.2.1 [method]descriptor.write-via-stream +//go:noescape +func wasmimport_DescriptorWriteViaStream(self0 uint32, offset0 uint64, result *cm.Result[streams.OutputStream, streams.OutputStream, ErrorCode]) + +// DirectoryEntryStream represents the imported resource "wasi:filesystem/types@0.2.1#directory-entry-stream". +// +// A stream of directory entries. +// +// resource directory-entry-stream +type DirectoryEntryStream cm.Resource + +// ResourceDrop represents the imported resource-drop for resource "directory-entry-stream". +// +// Drops a resource handle. +// +//go:nosplit +func (self DirectoryEntryStream) ResourceDrop() { + self0 := cm.Reinterpret[uint32](self) + wasmimport_DirectoryEntryStreamResourceDrop((uint32)(self0)) + return +} + +//go:wasmimport wasi:filesystem/types@0.2.1 [resource-drop]directory-entry-stream +//go:noescape +func wasmimport_DirectoryEntryStreamResourceDrop(self0 uint32) + +// ReadDirectoryEntry represents the imported method "read-directory-entry". +// +// Read a single directory entry from a `directory-entry-stream`. +// +// read-directory-entry: func() -> result, error-code> +// +//go:nosplit +func (self DirectoryEntryStream) ReadDirectoryEntry() (result cm.Result[OptionDirectoryEntryShape, cm.Option[DirectoryEntry], ErrorCode]) { + self0 := cm.Reinterpret[uint32](self) + wasmimport_DirectoryEntryStreamReadDirectoryEntry((uint32)(self0), &result) + return +} + +//go:wasmimport wasi:filesystem/types@0.2.1 [method]directory-entry-stream.read-directory-entry +//go:noescape +func wasmimport_DirectoryEntryStreamReadDirectoryEntry(self0 uint32, result *cm.Result[OptionDirectoryEntryShape, cm.Option[DirectoryEntry], ErrorCode]) + +// FilesystemErrorCode represents the imported function "filesystem-error-code". +// +// Attempts to extract a filesystem-related `error-code` from the stream +// `error` provided. +// +// Stream operations which return `stream-error::last-operation-failed` +// have a payload with more information about the operation that failed. +// This payload can be passed through to this function to see if there's +// filesystem-related information about the error to return. +// +// Note that this function is fallible because not all stream-related +// errors are filesystem-related errors. +// +// filesystem-error-code: func(err: borrow) -> option +// +//go:nosplit +func FilesystemErrorCode(err ioerror.Error) (result cm.Option[ErrorCode]) { + err0 := cm.Reinterpret[uint32](err) + wasmimport_FilesystemErrorCode((uint32)(err0), &result) + return +} + +//go:wasmimport wasi:filesystem/types@0.2.1 filesystem-error-code +//go:noescape +func wasmimport_FilesystemErrorCode(err0 uint32, result *cm.Option[ErrorCode]) diff --git a/examples/go/http/bindings/wasi/http/incoming-handler/empty.s b/examples/go/http/bindings/wasi/http/incoming-handler/empty.s new file mode 100644 index 0000000..5444f20 --- /dev/null +++ b/examples/go/http/bindings/wasi/http/incoming-handler/empty.s @@ -0,0 +1,3 @@ +// This file exists for testing this package without WebAssembly, +// allowing empty function bodies with a //go:wasmimport directive. +// See https://pkg.go.dev/cmd/compile for more information. diff --git a/examples/go/http/bindings/wasi/http/incoming-handler/incoming-handler.exports.go b/examples/go/http/bindings/wasi/http/incoming-handler/incoming-handler.exports.go new file mode 100644 index 0000000..72f13ac --- /dev/null +++ b/examples/go/http/bindings/wasi/http/incoming-handler/incoming-handler.exports.go @@ -0,0 +1,26 @@ +// Code generated by wit-bindgen-go. DO NOT EDIT. + +package incominghandler + +import ( + "github.com/rvolosatovs/west/examples/go/http/bindings/wasi/http/types" +) + +// Exports represents the caller-defined exports from "wasi:http/incoming-handler@0.2.1". +var Exports struct { + // Handle represents the caller-defined, exported function "handle". + // + // This function is invoked with an incoming HTTP Request, and a resource + // `response-outparam` which provides the capability to reply with an HTTP + // Response. The response is sent by calling the `response-outparam.set` + // method, which allows execution to continue after the response has been + // sent. This enables both streaming to the response body, and performing other + // work. + // + // The implementor of this function must write a response to the + // `response-outparam` before returning, or else the caller will respond + // with an error on its behalf. + // + // handle: func(request: incoming-request, response-out: response-outparam) + Handle func(request types.IncomingRequest, responseOut types.ResponseOutparam) +} diff --git a/examples/go/http/bindings/wasi/http/incoming-handler/incoming-handler.wit.go b/examples/go/http/bindings/wasi/http/incoming-handler/incoming-handler.wit.go new file mode 100644 index 0000000..0cc16ba --- /dev/null +++ b/examples/go/http/bindings/wasi/http/incoming-handler/incoming-handler.wit.go @@ -0,0 +1,21 @@ +// Code generated by wit-bindgen-go. DO NOT EDIT. + +// Package incominghandler represents the exported interface "wasi:http/incoming-handler@0.2.1". +// +// This interface defines a handler of incoming HTTP Requests. It should +// be exported by components which can respond to HTTP Requests. +package incominghandler + +import ( + "github.com/bytecodealliance/wasm-tools-go/cm" + "github.com/rvolosatovs/west/examples/go/http/bindings/wasi/http/types" +) + +//go:wasmexport wasi:http/incoming-handler@0.2.1#handle +//export wasi:http/incoming-handler@0.2.1#handle +func wasmexport_Handle(request0 uint32, responseOut0 uint32) { + request := cm.Reinterpret[types.IncomingRequest]((uint32)(request0)) + responseOut := cm.Reinterpret[types.ResponseOutparam]((uint32)(responseOut0)) + Exports.Handle(request, responseOut) + return +} diff --git a/examples/go/http/bindings/wasi/http/outgoing-handler/abi.go b/examples/go/http/bindings/wasi/http/outgoing-handler/abi.go new file mode 100644 index 0000000..871ec59 --- /dev/null +++ b/examples/go/http/bindings/wasi/http/outgoing-handler/abi.go @@ -0,0 +1,24 @@ +// Code generated by wit-bindgen-go. DO NOT EDIT. + +package outgoinghandler + +import ( + "github.com/bytecodealliance/wasm-tools-go/cm" + "github.com/rvolosatovs/west/examples/go/http/bindings/wasi/http/types" + "unsafe" +) + +// ErrorCodeShape is used for storage in variant or result types. +type ErrorCodeShape struct { + shape [unsafe.Sizeof(types.ErrorCode{})]byte +} + +func lower_OptionRequestOptions(v cm.Option[types.RequestOptions]) (f0 uint32, f1 uint32) { + some := v.Some() + if some != nil { + f0 = 1 + v1 := cm.Reinterpret[uint32](*some) + f1 = (uint32)(v1) + } + return +} diff --git a/examples/go/http/bindings/wasi/http/outgoing-handler/empty.s b/examples/go/http/bindings/wasi/http/outgoing-handler/empty.s new file mode 100644 index 0000000..5444f20 --- /dev/null +++ b/examples/go/http/bindings/wasi/http/outgoing-handler/empty.s @@ -0,0 +1,3 @@ +// This file exists for testing this package without WebAssembly, +// allowing empty function bodies with a //go:wasmimport directive. +// See https://pkg.go.dev/cmd/compile for more information. diff --git a/examples/go/http/bindings/wasi/http/outgoing-handler/outgoing-handler.wit.go b/examples/go/http/bindings/wasi/http/outgoing-handler/outgoing-handler.wit.go new file mode 100644 index 0000000..36dbd8e --- /dev/null +++ b/examples/go/http/bindings/wasi/http/outgoing-handler/outgoing-handler.wit.go @@ -0,0 +1,40 @@ +// Code generated by wit-bindgen-go. DO NOT EDIT. + +// Package outgoinghandler represents the imported interface "wasi:http/outgoing-handler@0.2.1". +// +// This interface defines a handler of outgoing HTTP Requests. It should be +// imported by components which wish to make HTTP Requests. +package outgoinghandler + +import ( + "github.com/bytecodealliance/wasm-tools-go/cm" + "github.com/rvolosatovs/west/examples/go/http/bindings/wasi/http/types" +) + +// Handle represents the imported function "handle". +// +// This function is invoked with an outgoing HTTP Request, and it returns +// a resource `future-incoming-response` which represents an HTTP Response +// which may arrive in the future. +// +// The `options` argument accepts optional parameters for the HTTP +// protocol's transport layer. +// +// This function may return an error if the `outgoing-request` is invalid +// or not allowed to be made. Otherwise, protocol errors are reported +// through the `future-incoming-response`. +// +// handle: func(request: outgoing-request, options: option) -> result +// +//go:nosplit +func Handle(request types.OutgoingRequest, options cm.Option[types.RequestOptions]) (result cm.Result[ErrorCodeShape, types.FutureIncomingResponse, types.ErrorCode]) { + request0 := cm.Reinterpret[uint32](request) + options0, options1 := lower_OptionRequestOptions(options) + wasmimport_Handle((uint32)(request0), (uint32)(options0), (uint32)(options1), &result) + return +} + +//go:wasmimport wasi:http/outgoing-handler@0.2.1 handle +//go:noescape +func wasmimport_Handle(request0 uint32, options0 uint32, options1 uint32, result *cm.Result[ErrorCodeShape, types.FutureIncomingResponse, types.ErrorCode]) diff --git a/examples/go/http/bindings/wasi/http/types/abi.go b/examples/go/http/bindings/wasi/http/types/abi.go new file mode 100644 index 0000000..8d22a2a --- /dev/null +++ b/examples/go/http/bindings/wasi/http/types/abi.go @@ -0,0 +1,273 @@ +// Code generated by wit-bindgen-go. DO NOT EDIT. + +package types + +import ( + "github.com/bytecodealliance/wasm-tools-go/cm" + monotonicclock "github.com/rvolosatovs/west/examples/go/http/bindings/wasi/clocks/monotonic-clock" + "unsafe" +) + +// OptionFieldSizePayloadShape is used for storage in variant or result types. +type OptionFieldSizePayloadShape struct { + shape [unsafe.Sizeof(cm.Option[FieldSizePayload]{})]byte +} + +func lower_OptionString(v cm.Option[string]) (f0 uint32, f1 *uint8, f2 uint32) { + some := v.Some() + if some != nil { + f0 = 1 + v1, v2 := cm.LowerString(*some) + f1 = (*uint8)(v1) + f2 = (uint32)(v2) + } + return +} + +func lower_Method(v Method) (f0 uint32, f1 *uint8, f2 uint32) { + f0 = (uint32)(v.Tag()) + switch f0 { + case 9: // other + v1, v2 := cm.LowerString(*v.Other()) + f1 = (*uint8)(v1) + f2 = (uint32)(v2) + } + return +} + +func lower_Scheme(v Scheme) (f0 uint32, f1 *uint8, f2 uint32) { + f0 = (uint32)(v.Tag()) + switch f0 { + case 2: // other + v1, v2 := cm.LowerString(*v.Other()) + f1 = (*uint8)(v1) + f2 = (uint32)(v2) + } + return +} + +func lower_OptionScheme(v cm.Option[Scheme]) (f0 uint32, f1 uint32, f2 *uint8, f3 uint32) { + some := v.Some() + if some != nil { + f0 = 1 + v1, v2, v3 := lower_Scheme(*some) + f1 = (uint32)(v1) + f2 = (*uint8)(v2) + f3 = (uint32)(v3) + } + return +} + +func lower_OptionDuration(v cm.Option[monotonicclock.Duration]) (f0 uint32, f1 uint64) { + some := v.Some() + if some != nil { + f0 = 1 + v1 := (uint64)(*some) + f1 = (uint64)(v1) + } + return +} + +// ErrorCodeShape is used for storage in variant or result types. +type ErrorCodeShape struct { + shape [unsafe.Sizeof(ErrorCode{})]byte +} + +func lower_OptionU16(v cm.Option[uint16]) (f0 uint32, f1 uint32) { + some := v.Some() + if some != nil { + f0 = 1 + v1 := (uint32)(*some) + f1 = (uint32)(v1) + } + return +} + +func lower_DNSErrorPayload(v DNSErrorPayload) (f0 uint32, f1 *uint8, f2 uint32, f3 uint32, f4 uint32) { + f0, f1, f2 = lower_OptionString(v.Rcode) + f3, f4 = lower_OptionU16(v.InfoCode) + return +} + +func lower_OptionU8(v cm.Option[uint8]) (f0 uint32, f1 uint32) { + some := v.Some() + if some != nil { + f0 = 1 + v1 := (uint32)(*some) + f1 = (uint32)(v1) + } + return +} + +func lower_TLSAlertReceivedPayload(v TLSAlertReceivedPayload) (f0 uint32, f1 uint32, f2 uint32, f3 *uint8, f4 uint32) { + f0, f1 = lower_OptionU8(v.AlertID) + f2, f3, f4 = lower_OptionString(v.AlertMessage) + return +} + +func lower_OptionU64(v cm.Option[uint64]) (f0 uint32, f1 uint64) { + some := v.Some() + if some != nil { + f0 = 1 + v1 := (uint64)(*some) + f1 = (uint64)(v1) + } + return +} + +func lower_OptionU32(v cm.Option[uint32]) (f0 uint32, f1 uint32) { + some := v.Some() + if some != nil { + f0 = 1 + v1 := (uint32)(*some) + f1 = (uint32)(v1) + } + return +} + +func lower_FieldSizePayload(v FieldSizePayload) (f0 uint32, f1 *uint8, f2 uint32, f3 uint32, f4 uint32) { + f0, f1, f2 = lower_OptionString(v.FieldName) + f3, f4 = lower_OptionU32(v.FieldSize) + return +} + +func lower_OptionFieldSizePayload(v cm.Option[FieldSizePayload]) (f0 uint32, f1 uint32, f2 *uint8, f3 uint32, f4 uint32, f5 uint32) { + some := v.Some() + if some != nil { + f0 = 1 + v1, v2, v3, v4, v5 := lower_FieldSizePayload(*some) + f1 = (uint32)(v1) + f2 = (*uint8)(v2) + f3 = (uint32)(v3) + f4 = (uint32)(v4) + f5 = (uint32)(v5) + } + return +} + +func lower_ErrorCode(v ErrorCode) (f0 uint32, f1 uint32, f2 uint64, f3 uint32, f4 uint32, f5 uint32, f6 uint32) { + f0 = (uint32)(v.Tag()) + switch f0 { + case 1: // DNS-error + v1, v2, v3, v4, v5 := lower_DNSErrorPayload(*v.DNSError()) + f1 = (uint32)(v1) + f2 = cm.PointerToU64(v2) + f3 = (uint32)(v3) + f4 = (uint32)(v4) + f5 = (uint32)(v5) + case 14: // TLS-alert-received + v1, v2, v3, v4, v5 := lower_TLSAlertReceivedPayload(*v.TLSAlertReceived()) + f1 = (uint32)(v1) + f2 = (uint64)(v2) + f3 = (uint32)(v3) + f4 = cm.PointerToU32(v4) + f5 = (uint32)(v5) + case 17: // HTTP-request-body-size + v1, v2 := lower_OptionU64(*v.HTTPRequestBodySize()) + f1 = (uint32)(v1) + f2 = (uint64)(v2) + case 21: // HTTP-request-header-section-size + v1, v2 := lower_OptionU32(*v.HTTPRequestHeaderSectionSize()) + f1 = (uint32)(v1) + f2 = (uint64)(v2) + case 22: // HTTP-request-header-size + v1, v2, v3, v4, v5, v6 := lower_OptionFieldSizePayload(*v.HTTPRequestHeaderSize()) + f1 = (uint32)(v1) + f2 = (uint64)(v2) + f3 = cm.PointerToU32(v3) + f4 = (uint32)(v4) + f5 = (uint32)(v5) + f6 = (uint32)(v6) + case 23: // HTTP-request-trailer-section-size + v1, v2 := lower_OptionU32(*v.HTTPRequestTrailerSectionSize()) + f1 = (uint32)(v1) + f2 = (uint64)(v2) + case 24: // HTTP-request-trailer-size + v1, v2, v3, v4, v5 := lower_FieldSizePayload(*v.HTTPRequestTrailerSize()) + f1 = (uint32)(v1) + f2 = cm.PointerToU64(v2) + f3 = (uint32)(v3) + f4 = (uint32)(v4) + f5 = (uint32)(v5) + case 26: // HTTP-response-header-section-size + v1, v2 := lower_OptionU32(*v.HTTPResponseHeaderSectionSize()) + f1 = (uint32)(v1) + f2 = (uint64)(v2) + case 27: // HTTP-response-header-size + v1, v2, v3, v4, v5 := lower_FieldSizePayload(*v.HTTPResponseHeaderSize()) + f1 = (uint32)(v1) + f2 = cm.PointerToU64(v2) + f3 = (uint32)(v3) + f4 = (uint32)(v4) + f5 = (uint32)(v5) + case 28: // HTTP-response-body-size + v1, v2 := lower_OptionU64(*v.HTTPResponseBodySize()) + f1 = (uint32)(v1) + f2 = (uint64)(v2) + case 29: // HTTP-response-trailer-section-size + v1, v2 := lower_OptionU32(*v.HTTPResponseTrailerSectionSize()) + f1 = (uint32)(v1) + f2 = (uint64)(v2) + case 30: // HTTP-response-trailer-size + v1, v2, v3, v4, v5 := lower_FieldSizePayload(*v.HTTPResponseTrailerSize()) + f1 = (uint32)(v1) + f2 = cm.PointerToU64(v2) + f3 = (uint32)(v3) + f4 = (uint32)(v4) + f5 = (uint32)(v5) + case 31: // HTTP-response-transfer-coding + v1, v2, v3 := lower_OptionString(*v.HTTPResponseTransferCoding()) + f1 = (uint32)(v1) + f2 = cm.PointerToU64(v2) + f3 = (uint32)(v3) + case 32: // HTTP-response-content-coding + v1, v2, v3 := lower_OptionString(*v.HTTPResponseContentCoding()) + f1 = (uint32)(v1) + f2 = cm.PointerToU64(v2) + f3 = (uint32)(v3) + case 38: // internal-error + v1, v2, v3 := lower_OptionString(*v.InternalError()) + f1 = (uint32)(v1) + f2 = cm.PointerToU64(v2) + f3 = (uint32)(v3) + } + return +} + +func lower_ResultOutgoingResponseErrorCode(v cm.Result[ErrorCodeShape, OutgoingResponse, ErrorCode]) (f0 uint32, f1 uint32, f2 uint32, f3 uint64, f4 uint32, f5 uint32, f6 uint32, f7 uint32) { + if v.IsOK() { + v1 := cm.Reinterpret[uint32](*v.OK()) + f1 = (uint32)(v1) + } else { + f0 = 1 + v1, v2, v3, v4, v5, v6, v7 := lower_ErrorCode(*v.Err()) + f1 = (uint32)(v1) + f2 = (uint32)(v2) + f3 = (uint64)(v3) + f4 = (uint32)(v4) + f5 = (uint32)(v5) + f6 = (uint32)(v6) + f7 = (uint32)(v7) + } + return +} + +// ResultOptionTrailersErrorCodeShape is used for storage in variant or result types. +type ResultOptionTrailersErrorCodeShape struct { + shape [unsafe.Sizeof(cm.Result[ErrorCodeShape, cm.Option[Fields], ErrorCode]{})]byte +} + +func lower_OptionTrailers(v cm.Option[Fields]) (f0 uint32, f1 uint32) { + some := v.Some() + if some != nil { + f0 = 1 + v1 := cm.Reinterpret[uint32](*some) + f1 = (uint32)(v1) + } + return +} + +// ResultIncomingResponseErrorCodeShape is used for storage in variant or result types. +type ResultIncomingResponseErrorCodeShape struct { + shape [unsafe.Sizeof(cm.Result[ErrorCodeShape, IncomingResponse, ErrorCode]{})]byte +} diff --git a/examples/go/http/bindings/wasi/http/types/empty.s b/examples/go/http/bindings/wasi/http/types/empty.s new file mode 100644 index 0000000..5444f20 --- /dev/null +++ b/examples/go/http/bindings/wasi/http/types/empty.s @@ -0,0 +1,3 @@ +// This file exists for testing this package without WebAssembly, +// allowing empty function bodies with a //go:wasmimport directive. +// See https://pkg.go.dev/cmd/compile for more information. diff --git a/examples/go/http/bindings/wasi/http/types/types.wit.go b/examples/go/http/bindings/wasi/http/types/types.wit.go new file mode 100644 index 0000000..a364f94 --- /dev/null +++ b/examples/go/http/bindings/wasi/http/types/types.wit.go @@ -0,0 +1,2148 @@ +// Code generated by wit-bindgen-go. DO NOT EDIT. + +// Package types represents the imported interface "wasi:http/types@0.2.1". +// +// This interface defines all of the types and methods for implementing +// HTTP Requests and Responses, both incoming and outgoing, as well as +// their headers, trailers, and bodies. +package types + +import ( + "github.com/bytecodealliance/wasm-tools-go/cm" + monotonicclock "github.com/rvolosatovs/west/examples/go/http/bindings/wasi/clocks/monotonic-clock" + ioerror "github.com/rvolosatovs/west/examples/go/http/bindings/wasi/io/error" + "github.com/rvolosatovs/west/examples/go/http/bindings/wasi/io/poll" + "github.com/rvolosatovs/west/examples/go/http/bindings/wasi/io/streams" +) + +// Method represents the variant "wasi:http/types@0.2.1#method". +// +// This type corresponds to HTTP standard Methods. +// +// variant method { +// get, +// head, +// post, +// put, +// delete, +// connect, +// options, +// trace, +// patch, +// other(string), +// } +type Method cm.Variant[uint8, string, string] + +// MethodGet returns a [Method] of case "get". +func MethodGet() Method { + var data struct{} + return cm.New[Method](0, data) +} + +// Get returns true if [Method] represents the variant case "get". +func (self *Method) Get() bool { + return self.Tag() == 0 +} + +// MethodHead returns a [Method] of case "head". +func MethodHead() Method { + var data struct{} + return cm.New[Method](1, data) +} + +// Head returns true if [Method] represents the variant case "head". +func (self *Method) Head() bool { + return self.Tag() == 1 +} + +// MethodPost returns a [Method] of case "post". +func MethodPost() Method { + var data struct{} + return cm.New[Method](2, data) +} + +// Post returns true if [Method] represents the variant case "post". +func (self *Method) Post() bool { + return self.Tag() == 2 +} + +// MethodPut returns a [Method] of case "put". +func MethodPut() Method { + var data struct{} + return cm.New[Method](3, data) +} + +// Put returns true if [Method] represents the variant case "put". +func (self *Method) Put() bool { + return self.Tag() == 3 +} + +// MethodDelete returns a [Method] of case "delete". +func MethodDelete() Method { + var data struct{} + return cm.New[Method](4, data) +} + +// Delete returns true if [Method] represents the variant case "delete". +func (self *Method) Delete() bool { + return self.Tag() == 4 +} + +// MethodConnect returns a [Method] of case "connect". +func MethodConnect() Method { + var data struct{} + return cm.New[Method](5, data) +} + +// Connect returns true if [Method] represents the variant case "connect". +func (self *Method) Connect() bool { + return self.Tag() == 5 +} + +// MethodOptions returns a [Method] of case "options". +func MethodOptions() Method { + var data struct{} + return cm.New[Method](6, data) +} + +// Options returns true if [Method] represents the variant case "options". +func (self *Method) Options() bool { + return self.Tag() == 6 +} + +// MethodTrace returns a [Method] of case "trace". +func MethodTrace() Method { + var data struct{} + return cm.New[Method](7, data) +} + +// Trace returns true if [Method] represents the variant case "trace". +func (self *Method) Trace() bool { + return self.Tag() == 7 +} + +// MethodPatch returns a [Method] of case "patch". +func MethodPatch() Method { + var data struct{} + return cm.New[Method](8, data) +} + +// Patch returns true if [Method] represents the variant case "patch". +func (self *Method) Patch() bool { + return self.Tag() == 8 +} + +// MethodOther returns a [Method] of case "other". +func MethodOther(data string) Method { + return cm.New[Method](9, data) +} + +// Other returns a non-nil *[string] if [Method] represents the variant case "other". +func (self *Method) Other() *string { + return cm.Case[string](self, 9) +} + +// Scheme represents the variant "wasi:http/types@0.2.1#scheme". +// +// This type corresponds to HTTP standard Related Schemes. +// +// variant scheme { +// HTTP, +// HTTPS, +// other(string), +// } +type Scheme cm.Variant[uint8, string, string] + +// SchemeHTTP returns a [Scheme] of case "HTTP". +func SchemeHTTP() Scheme { + var data struct{} + return cm.New[Scheme](0, data) +} + +// HTTP returns true if [Scheme] represents the variant case "HTTP". +func (self *Scheme) HTTP() bool { + return self.Tag() == 0 +} + +// SchemeHTTPS returns a [Scheme] of case "HTTPS". +func SchemeHTTPS() Scheme { + var data struct{} + return cm.New[Scheme](1, data) +} + +// HTTPS returns true if [Scheme] represents the variant case "HTTPS". +func (self *Scheme) HTTPS() bool { + return self.Tag() == 1 +} + +// SchemeOther returns a [Scheme] of case "other". +func SchemeOther(data string) Scheme { + return cm.New[Scheme](2, data) +} + +// Other returns a non-nil *[string] if [Scheme] represents the variant case "other". +func (self *Scheme) Other() *string { + return cm.Case[string](self, 2) +} + +// DNSErrorPayload represents the record "wasi:http/types@0.2.1#DNS-error-payload". +// +// Defines the case payload type for `DNS-error` above: +// +// record DNS-error-payload { +// rcode: option, +// info-code: option, +// } +type DNSErrorPayload struct { + Rcode cm.Option[string] + InfoCode cm.Option[uint16] +} + +// TLSAlertReceivedPayload represents the record "wasi:http/types@0.2.1#TLS-alert-received-payload". +// +// Defines the case payload type for `TLS-alert-received` above: +// +// record TLS-alert-received-payload { +// alert-id: option, +// alert-message: option, +// } +type TLSAlertReceivedPayload struct { + AlertID cm.Option[uint8] + AlertMessage cm.Option[string] +} + +// FieldSizePayload represents the record "wasi:http/types@0.2.1#field-size-payload". +// +// Defines the case payload type for `HTTP-response-{header,trailer}-size` above: +// +// record field-size-payload { +// field-name: option, +// field-size: option, +// } +type FieldSizePayload struct { + FieldName cm.Option[string] + FieldSize cm.Option[uint32] +} + +// ErrorCode represents the variant "wasi:http/types@0.2.1#error-code". +// +// These cases are inspired by the IANA HTTP Proxy Error Types: +// https://www.iana.org/assignments/http-proxy-status/http-proxy-status.xhtml#table-http-proxy-error-types +// +// variant error-code { +// DNS-timeout, +// DNS-error(DNS-error-payload), +// destination-not-found, +// destination-unavailable, +// destination-IP-prohibited, +// destination-IP-unroutable, +// connection-refused, +// connection-terminated, +// connection-timeout, +// connection-read-timeout, +// connection-write-timeout, +// connection-limit-reached, +// TLS-protocol-error, +// TLS-certificate-error, +// TLS-alert-received(TLS-alert-received-payload), +// HTTP-request-denied, +// HTTP-request-length-required, +// HTTP-request-body-size(option), +// HTTP-request-method-invalid, +// HTTP-request-URI-invalid, +// HTTP-request-URI-too-long, +// HTTP-request-header-section-size(option), +// HTTP-request-header-size(option), +// HTTP-request-trailer-section-size(option), +// HTTP-request-trailer-size(field-size-payload), +// HTTP-response-incomplete, +// HTTP-response-header-section-size(option), +// HTTP-response-header-size(field-size-payload), +// HTTP-response-body-size(option), +// HTTP-response-trailer-section-size(option), +// HTTP-response-trailer-size(field-size-payload), +// HTTP-response-transfer-coding(option), +// HTTP-response-content-coding(option), +// HTTP-response-timeout, +// HTTP-upgrade-failed, +// HTTP-protocol-error, +// loop-detected, +// configuration-error, +// internal-error(option), +// } +type ErrorCode cm.Variant[uint8, OptionFieldSizePayloadShape, cm.Option[uint64]] + +// ErrorCodeDNSTimeout returns a [ErrorCode] of case "DNS-timeout". +func ErrorCodeDNSTimeout() ErrorCode { + var data struct{} + return cm.New[ErrorCode](0, data) +} + +// DNSTimeout returns true if [ErrorCode] represents the variant case "DNS-timeout". +func (self *ErrorCode) DNSTimeout() bool { + return self.Tag() == 0 +} + +// ErrorCodeDNSError returns a [ErrorCode] of case "DNS-error". +func ErrorCodeDNSError(data DNSErrorPayload) ErrorCode { + return cm.New[ErrorCode](1, data) +} + +// DNSError returns a non-nil *[DNSErrorPayload] if [ErrorCode] represents the variant case "DNS-error". +func (self *ErrorCode) DNSError() *DNSErrorPayload { + return cm.Case[DNSErrorPayload](self, 1) +} + +// ErrorCodeDestinationNotFound returns a [ErrorCode] of case "destination-not-found". +func ErrorCodeDestinationNotFound() ErrorCode { + var data struct{} + return cm.New[ErrorCode](2, data) +} + +// DestinationNotFound returns true if [ErrorCode] represents the variant case "destination-not-found". +func (self *ErrorCode) DestinationNotFound() bool { + return self.Tag() == 2 +} + +// ErrorCodeDestinationUnavailable returns a [ErrorCode] of case "destination-unavailable". +func ErrorCodeDestinationUnavailable() ErrorCode { + var data struct{} + return cm.New[ErrorCode](3, data) +} + +// DestinationUnavailable returns true if [ErrorCode] represents the variant case "destination-unavailable". +func (self *ErrorCode) DestinationUnavailable() bool { + return self.Tag() == 3 +} + +// ErrorCodeDestinationIPProhibited returns a [ErrorCode] of case "destination-IP-prohibited". +func ErrorCodeDestinationIPProhibited() ErrorCode { + var data struct{} + return cm.New[ErrorCode](4, data) +} + +// DestinationIPProhibited returns true if [ErrorCode] represents the variant case "destination-IP-prohibited". +func (self *ErrorCode) DestinationIPProhibited() bool { + return self.Tag() == 4 +} + +// ErrorCodeDestinationIPUnroutable returns a [ErrorCode] of case "destination-IP-unroutable". +func ErrorCodeDestinationIPUnroutable() ErrorCode { + var data struct{} + return cm.New[ErrorCode](5, data) +} + +// DestinationIPUnroutable returns true if [ErrorCode] represents the variant case "destination-IP-unroutable". +func (self *ErrorCode) DestinationIPUnroutable() bool { + return self.Tag() == 5 +} + +// ErrorCodeConnectionRefused returns a [ErrorCode] of case "connection-refused". +func ErrorCodeConnectionRefused() ErrorCode { + var data struct{} + return cm.New[ErrorCode](6, data) +} + +// ConnectionRefused returns true if [ErrorCode] represents the variant case "connection-refused". +func (self *ErrorCode) ConnectionRefused() bool { + return self.Tag() == 6 +} + +// ErrorCodeConnectionTerminated returns a [ErrorCode] of case "connection-terminated". +func ErrorCodeConnectionTerminated() ErrorCode { + var data struct{} + return cm.New[ErrorCode](7, data) +} + +// ConnectionTerminated returns true if [ErrorCode] represents the variant case "connection-terminated". +func (self *ErrorCode) ConnectionTerminated() bool { + return self.Tag() == 7 +} + +// ErrorCodeConnectionTimeout returns a [ErrorCode] of case "connection-timeout". +func ErrorCodeConnectionTimeout() ErrorCode { + var data struct{} + return cm.New[ErrorCode](8, data) +} + +// ConnectionTimeout returns true if [ErrorCode] represents the variant case "connection-timeout". +func (self *ErrorCode) ConnectionTimeout() bool { + return self.Tag() == 8 +} + +// ErrorCodeConnectionReadTimeout returns a [ErrorCode] of case "connection-read-timeout". +func ErrorCodeConnectionReadTimeout() ErrorCode { + var data struct{} + return cm.New[ErrorCode](9, data) +} + +// ConnectionReadTimeout returns true if [ErrorCode] represents the variant case "connection-read-timeout". +func (self *ErrorCode) ConnectionReadTimeout() bool { + return self.Tag() == 9 +} + +// ErrorCodeConnectionWriteTimeout returns a [ErrorCode] of case "connection-write-timeout". +func ErrorCodeConnectionWriteTimeout() ErrorCode { + var data struct{} + return cm.New[ErrorCode](10, data) +} + +// ConnectionWriteTimeout returns true if [ErrorCode] represents the variant case "connection-write-timeout". +func (self *ErrorCode) ConnectionWriteTimeout() bool { + return self.Tag() == 10 +} + +// ErrorCodeConnectionLimitReached returns a [ErrorCode] of case "connection-limit-reached". +func ErrorCodeConnectionLimitReached() ErrorCode { + var data struct{} + return cm.New[ErrorCode](11, data) +} + +// ConnectionLimitReached returns true if [ErrorCode] represents the variant case "connection-limit-reached". +func (self *ErrorCode) ConnectionLimitReached() bool { + return self.Tag() == 11 +} + +// ErrorCodeTLSProtocolError returns a [ErrorCode] of case "TLS-protocol-error". +func ErrorCodeTLSProtocolError() ErrorCode { + var data struct{} + return cm.New[ErrorCode](12, data) +} + +// TLSProtocolError returns true if [ErrorCode] represents the variant case "TLS-protocol-error". +func (self *ErrorCode) TLSProtocolError() bool { + return self.Tag() == 12 +} + +// ErrorCodeTLSCertificateError returns a [ErrorCode] of case "TLS-certificate-error". +func ErrorCodeTLSCertificateError() ErrorCode { + var data struct{} + return cm.New[ErrorCode](13, data) +} + +// TLSCertificateError returns true if [ErrorCode] represents the variant case "TLS-certificate-error". +func (self *ErrorCode) TLSCertificateError() bool { + return self.Tag() == 13 +} + +// ErrorCodeTLSAlertReceived returns a [ErrorCode] of case "TLS-alert-received". +func ErrorCodeTLSAlertReceived(data TLSAlertReceivedPayload) ErrorCode { + return cm.New[ErrorCode](14, data) +} + +// TLSAlertReceived returns a non-nil *[TLSAlertReceivedPayload] if [ErrorCode] represents the variant case "TLS-alert-received". +func (self *ErrorCode) TLSAlertReceived() *TLSAlertReceivedPayload { + return cm.Case[TLSAlertReceivedPayload](self, 14) +} + +// ErrorCodeHTTPRequestDenied returns a [ErrorCode] of case "HTTP-request-denied". +func ErrorCodeHTTPRequestDenied() ErrorCode { + var data struct{} + return cm.New[ErrorCode](15, data) +} + +// HTTPRequestDenied returns true if [ErrorCode] represents the variant case "HTTP-request-denied". +func (self *ErrorCode) HTTPRequestDenied() bool { + return self.Tag() == 15 +} + +// ErrorCodeHTTPRequestLengthRequired returns a [ErrorCode] of case "HTTP-request-length-required". +func ErrorCodeHTTPRequestLengthRequired() ErrorCode { + var data struct{} + return cm.New[ErrorCode](16, data) +} + +// HTTPRequestLengthRequired returns true if [ErrorCode] represents the variant case "HTTP-request-length-required". +func (self *ErrorCode) HTTPRequestLengthRequired() bool { + return self.Tag() == 16 +} + +// ErrorCodeHTTPRequestBodySize returns a [ErrorCode] of case "HTTP-request-body-size". +func ErrorCodeHTTPRequestBodySize(data cm.Option[uint64]) ErrorCode { + return cm.New[ErrorCode](17, data) +} + +// HTTPRequestBodySize returns a non-nil *[cm.Option[uint64]] if [ErrorCode] represents the variant case "HTTP-request-body-size". +func (self *ErrorCode) HTTPRequestBodySize() *cm.Option[uint64] { + return cm.Case[cm.Option[uint64]](self, 17) +} + +// ErrorCodeHTTPRequestMethodInvalid returns a [ErrorCode] of case "HTTP-request-method-invalid". +func ErrorCodeHTTPRequestMethodInvalid() ErrorCode { + var data struct{} + return cm.New[ErrorCode](18, data) +} + +// HTTPRequestMethodInvalid returns true if [ErrorCode] represents the variant case "HTTP-request-method-invalid". +func (self *ErrorCode) HTTPRequestMethodInvalid() bool { + return self.Tag() == 18 +} + +// ErrorCodeHTTPRequestURIInvalid returns a [ErrorCode] of case "HTTP-request-URI-invalid". +func ErrorCodeHTTPRequestURIInvalid() ErrorCode { + var data struct{} + return cm.New[ErrorCode](19, data) +} + +// HTTPRequestURIInvalid returns true if [ErrorCode] represents the variant case "HTTP-request-URI-invalid". +func (self *ErrorCode) HTTPRequestURIInvalid() bool { + return self.Tag() == 19 +} + +// ErrorCodeHTTPRequestURITooLong returns a [ErrorCode] of case "HTTP-request-URI-too-long". +func ErrorCodeHTTPRequestURITooLong() ErrorCode { + var data struct{} + return cm.New[ErrorCode](20, data) +} + +// HTTPRequestURITooLong returns true if [ErrorCode] represents the variant case "HTTP-request-URI-too-long". +func (self *ErrorCode) HTTPRequestURITooLong() bool { + return self.Tag() == 20 +} + +// ErrorCodeHTTPRequestHeaderSectionSize returns a [ErrorCode] of case "HTTP-request-header-section-size". +func ErrorCodeHTTPRequestHeaderSectionSize(data cm.Option[uint32]) ErrorCode { + return cm.New[ErrorCode](21, data) +} + +// HTTPRequestHeaderSectionSize returns a non-nil *[cm.Option[uint32]] if [ErrorCode] represents the variant case "HTTP-request-header-section-size". +func (self *ErrorCode) HTTPRequestHeaderSectionSize() *cm.Option[uint32] { + return cm.Case[cm.Option[uint32]](self, 21) +} + +// ErrorCodeHTTPRequestHeaderSize returns a [ErrorCode] of case "HTTP-request-header-size". +func ErrorCodeHTTPRequestHeaderSize(data cm.Option[FieldSizePayload]) ErrorCode { + return cm.New[ErrorCode](22, data) +} + +// HTTPRequestHeaderSize returns a non-nil *[cm.Option[FieldSizePayload]] if [ErrorCode] represents the variant case "HTTP-request-header-size". +func (self *ErrorCode) HTTPRequestHeaderSize() *cm.Option[FieldSizePayload] { + return cm.Case[cm.Option[FieldSizePayload]](self, 22) +} + +// ErrorCodeHTTPRequestTrailerSectionSize returns a [ErrorCode] of case "HTTP-request-trailer-section-size". +func ErrorCodeHTTPRequestTrailerSectionSize(data cm.Option[uint32]) ErrorCode { + return cm.New[ErrorCode](23, data) +} + +// HTTPRequestTrailerSectionSize returns a non-nil *[cm.Option[uint32]] if [ErrorCode] represents the variant case "HTTP-request-trailer-section-size". +func (self *ErrorCode) HTTPRequestTrailerSectionSize() *cm.Option[uint32] { + return cm.Case[cm.Option[uint32]](self, 23) +} + +// ErrorCodeHTTPRequestTrailerSize returns a [ErrorCode] of case "HTTP-request-trailer-size". +func ErrorCodeHTTPRequestTrailerSize(data FieldSizePayload) ErrorCode { + return cm.New[ErrorCode](24, data) +} + +// HTTPRequestTrailerSize returns a non-nil *[FieldSizePayload] if [ErrorCode] represents the variant case "HTTP-request-trailer-size". +func (self *ErrorCode) HTTPRequestTrailerSize() *FieldSizePayload { + return cm.Case[FieldSizePayload](self, 24) +} + +// ErrorCodeHTTPResponseIncomplete returns a [ErrorCode] of case "HTTP-response-incomplete". +func ErrorCodeHTTPResponseIncomplete() ErrorCode { + var data struct{} + return cm.New[ErrorCode](25, data) +} + +// HTTPResponseIncomplete returns true if [ErrorCode] represents the variant case "HTTP-response-incomplete". +func (self *ErrorCode) HTTPResponseIncomplete() bool { + return self.Tag() == 25 +} + +// ErrorCodeHTTPResponseHeaderSectionSize returns a [ErrorCode] of case "HTTP-response-header-section-size". +func ErrorCodeHTTPResponseHeaderSectionSize(data cm.Option[uint32]) ErrorCode { + return cm.New[ErrorCode](26, data) +} + +// HTTPResponseHeaderSectionSize returns a non-nil *[cm.Option[uint32]] if [ErrorCode] represents the variant case "HTTP-response-header-section-size". +func (self *ErrorCode) HTTPResponseHeaderSectionSize() *cm.Option[uint32] { + return cm.Case[cm.Option[uint32]](self, 26) +} + +// ErrorCodeHTTPResponseHeaderSize returns a [ErrorCode] of case "HTTP-response-header-size". +func ErrorCodeHTTPResponseHeaderSize(data FieldSizePayload) ErrorCode { + return cm.New[ErrorCode](27, data) +} + +// HTTPResponseHeaderSize returns a non-nil *[FieldSizePayload] if [ErrorCode] represents the variant case "HTTP-response-header-size". +func (self *ErrorCode) HTTPResponseHeaderSize() *FieldSizePayload { + return cm.Case[FieldSizePayload](self, 27) +} + +// ErrorCodeHTTPResponseBodySize returns a [ErrorCode] of case "HTTP-response-body-size". +func ErrorCodeHTTPResponseBodySize(data cm.Option[uint64]) ErrorCode { + return cm.New[ErrorCode](28, data) +} + +// HTTPResponseBodySize returns a non-nil *[cm.Option[uint64]] if [ErrorCode] represents the variant case "HTTP-response-body-size". +func (self *ErrorCode) HTTPResponseBodySize() *cm.Option[uint64] { + return cm.Case[cm.Option[uint64]](self, 28) +} + +// ErrorCodeHTTPResponseTrailerSectionSize returns a [ErrorCode] of case "HTTP-response-trailer-section-size". +func ErrorCodeHTTPResponseTrailerSectionSize(data cm.Option[uint32]) ErrorCode { + return cm.New[ErrorCode](29, data) +} + +// HTTPResponseTrailerSectionSize returns a non-nil *[cm.Option[uint32]] if [ErrorCode] represents the variant case "HTTP-response-trailer-section-size". +func (self *ErrorCode) HTTPResponseTrailerSectionSize() *cm.Option[uint32] { + return cm.Case[cm.Option[uint32]](self, 29) +} + +// ErrorCodeHTTPResponseTrailerSize returns a [ErrorCode] of case "HTTP-response-trailer-size". +func ErrorCodeHTTPResponseTrailerSize(data FieldSizePayload) ErrorCode { + return cm.New[ErrorCode](30, data) +} + +// HTTPResponseTrailerSize returns a non-nil *[FieldSizePayload] if [ErrorCode] represents the variant case "HTTP-response-trailer-size". +func (self *ErrorCode) HTTPResponseTrailerSize() *FieldSizePayload { + return cm.Case[FieldSizePayload](self, 30) +} + +// ErrorCodeHTTPResponseTransferCoding returns a [ErrorCode] of case "HTTP-response-transfer-coding". +func ErrorCodeHTTPResponseTransferCoding(data cm.Option[string]) ErrorCode { + return cm.New[ErrorCode](31, data) +} + +// HTTPResponseTransferCoding returns a non-nil *[cm.Option[string]] if [ErrorCode] represents the variant case "HTTP-response-transfer-coding". +func (self *ErrorCode) HTTPResponseTransferCoding() *cm.Option[string] { + return cm.Case[cm.Option[string]](self, 31) +} + +// ErrorCodeHTTPResponseContentCoding returns a [ErrorCode] of case "HTTP-response-content-coding". +func ErrorCodeHTTPResponseContentCoding(data cm.Option[string]) ErrorCode { + return cm.New[ErrorCode](32, data) +} + +// HTTPResponseContentCoding returns a non-nil *[cm.Option[string]] if [ErrorCode] represents the variant case "HTTP-response-content-coding". +func (self *ErrorCode) HTTPResponseContentCoding() *cm.Option[string] { + return cm.Case[cm.Option[string]](self, 32) +} + +// ErrorCodeHTTPResponseTimeout returns a [ErrorCode] of case "HTTP-response-timeout". +func ErrorCodeHTTPResponseTimeout() ErrorCode { + var data struct{} + return cm.New[ErrorCode](33, data) +} + +// HTTPResponseTimeout returns true if [ErrorCode] represents the variant case "HTTP-response-timeout". +func (self *ErrorCode) HTTPResponseTimeout() bool { + return self.Tag() == 33 +} + +// ErrorCodeHTTPUpgradeFailed returns a [ErrorCode] of case "HTTP-upgrade-failed". +func ErrorCodeHTTPUpgradeFailed() ErrorCode { + var data struct{} + return cm.New[ErrorCode](34, data) +} + +// HTTPUpgradeFailed returns true if [ErrorCode] represents the variant case "HTTP-upgrade-failed". +func (self *ErrorCode) HTTPUpgradeFailed() bool { + return self.Tag() == 34 +} + +// ErrorCodeHTTPProtocolError returns a [ErrorCode] of case "HTTP-protocol-error". +func ErrorCodeHTTPProtocolError() ErrorCode { + var data struct{} + return cm.New[ErrorCode](35, data) +} + +// HTTPProtocolError returns true if [ErrorCode] represents the variant case "HTTP-protocol-error". +func (self *ErrorCode) HTTPProtocolError() bool { + return self.Tag() == 35 +} + +// ErrorCodeLoopDetected returns a [ErrorCode] of case "loop-detected". +func ErrorCodeLoopDetected() ErrorCode { + var data struct{} + return cm.New[ErrorCode](36, data) +} + +// LoopDetected returns true if [ErrorCode] represents the variant case "loop-detected". +func (self *ErrorCode) LoopDetected() bool { + return self.Tag() == 36 +} + +// ErrorCodeConfigurationError returns a [ErrorCode] of case "configuration-error". +func ErrorCodeConfigurationError() ErrorCode { + var data struct{} + return cm.New[ErrorCode](37, data) +} + +// ConfigurationError returns true if [ErrorCode] represents the variant case "configuration-error". +func (self *ErrorCode) ConfigurationError() bool { + return self.Tag() == 37 +} + +// ErrorCodeInternalError returns a [ErrorCode] of case "internal-error". +// +// This is a catch-all error for anything that doesn't fit cleanly into a +// more specific case. It also includes an optional string for an +// unstructured description of the error. Users should not depend on the +// string for diagnosing errors, as it's not required to be consistent +// between implementations. +func ErrorCodeInternalError(data cm.Option[string]) ErrorCode { + return cm.New[ErrorCode](38, data) +} + +// InternalError returns a non-nil *[cm.Option[string]] if [ErrorCode] represents the variant case "internal-error". +func (self *ErrorCode) InternalError() *cm.Option[string] { + return cm.Case[cm.Option[string]](self, 38) +} + +// HeaderError represents the variant "wasi:http/types@0.2.1#header-error". +// +// This type enumerates the different kinds of errors that may occur when +// setting or appending to a `fields` resource. +// +// variant header-error { +// invalid-syntax, +// forbidden, +// immutable, +// } +type HeaderError uint8 + +const ( + // This error indicates that a `field-key` or `field-value` was + // syntactically invalid when used with an operation that sets headers in a + // `fields`. + HeaderErrorInvalidSyntax HeaderError = iota + + // This error indicates that a forbidden `field-key` was used when trying + // to set a header in a `fields`. + HeaderErrorForbidden + + // This error indicates that the operation on the `fields` was not + // permitted because the fields are immutable. + HeaderErrorImmutable +) + +var stringsHeaderError = [3]string{ + "invalid-syntax", + "forbidden", + "immutable", +} + +// String implements [fmt.Stringer], returning the enum case name of e. +func (e HeaderError) String() string { + return stringsHeaderError[e] +} + +// FieldKey represents the string "wasi:http/types@0.2.1#field-key". +// +// Field keys are always strings. +// +// type field-key = string +type FieldKey string + +// FieldValue represents the list "wasi:http/types@0.2.1#field-value". +// +// Field values should always be ASCII strings. However, in +// reality, HTTP implementations often have to interpret malformed values, +// so they are provided as a list of bytes. +// +// type field-value = list +type FieldValue cm.List[uint8] + +// Fields represents the imported resource "wasi:http/types@0.2.1#fields". +// +// This following block defines the `fields` resource which corresponds to +// HTTP standard Fields. Fields are a common representation used for both +// Headers and Trailers. +// +// A `fields` may be mutable or immutable. A `fields` created using the +// constructor, `from-list`, or `clone` will be mutable, but a `fields` +// resource given by other means (including, but not limited to, +// `incoming-request.headers`, `outgoing-request.headers`) might be be +// immutable. In an immutable fields, the `set`, `append`, and `delete` +// operations will fail with `header-error.immutable`. +// +// resource fields +type Fields cm.Resource + +// ResourceDrop represents the imported resource-drop for resource "fields". +// +// Drops a resource handle. +// +//go:nosplit +func (self Fields) ResourceDrop() { + self0 := cm.Reinterpret[uint32](self) + wasmimport_FieldsResourceDrop((uint32)(self0)) + return +} + +//go:wasmimport wasi:http/types@0.2.1 [resource-drop]fields +//go:noescape +func wasmimport_FieldsResourceDrop(self0 uint32) + +// NewFields represents the imported constructor for resource "fields". +// +// Construct an empty HTTP Fields. +// +// The resulting `fields` is mutable. +// +// constructor() +// +//go:nosplit +func NewFields() (result Fields) { + result0 := wasmimport_NewFields() + result = cm.Reinterpret[Fields]((uint32)(result0)) + return +} + +//go:wasmimport wasi:http/types@0.2.1 [constructor]fields +//go:noescape +func wasmimport_NewFields() (result0 uint32) + +// FieldsFromList represents the imported static function "from-list". +// +// Construct an HTTP Fields. +// +// The resulting `fields` is mutable. +// +// The list represents each key-value pair in the Fields. Keys +// which have multiple values are represented by multiple entries in this +// list with the same key. +// +// The tuple is a pair of the field key, represented as a string, and +// Value, represented as a list of bytes. +// +// An error result will be returned if any `field-key` or `field-value` is +// syntactically invalid, or if a field is forbidden. +// +// from-list: static func(entries: list>) -> result +// +//go:nosplit +func FieldsFromList(entries cm.List[cm.Tuple[FieldKey, FieldValue]]) (result cm.Result[Fields, Fields, HeaderError]) { + entries0, entries1 := cm.LowerList(entries) + wasmimport_FieldsFromList((*cm.Tuple[FieldKey, FieldValue])(entries0), (uint32)(entries1), &result) + return +} + +//go:wasmimport wasi:http/types@0.2.1 [static]fields.from-list +//go:noescape +func wasmimport_FieldsFromList(entries0 *cm.Tuple[FieldKey, FieldValue], entries1 uint32, result *cm.Result[Fields, Fields, HeaderError]) + +// Append represents the imported method "append". +// +// Append a value for a key. Does not change or delete any existing +// values for that key. +// +// Fails with `header-error.immutable` if the `fields` are immutable. +// +// Fails with `header-error.invalid-syntax` if the `field-key` or +// `field-value` are syntactically invalid. +// +// append: func(name: field-key, value: field-value) -> result<_, header-error> +// +//go:nosplit +func (self Fields) Append(name FieldKey, value FieldValue) (result cm.Result[HeaderError, struct{}, HeaderError]) { + self0 := cm.Reinterpret[uint32](self) + name0, name1 := cm.LowerString(name) + value0, value1 := cm.LowerList(value) + wasmimport_FieldsAppend((uint32)(self0), (*uint8)(name0), (uint32)(name1), (*uint8)(value0), (uint32)(value1), &result) + return +} + +//go:wasmimport wasi:http/types@0.2.1 [method]fields.append +//go:noescape +func wasmimport_FieldsAppend(self0 uint32, name0 *uint8, name1 uint32, value0 *uint8, value1 uint32, result *cm.Result[HeaderError, struct{}, HeaderError]) + +// Clone represents the imported method "clone". +// +// Make a deep copy of the Fields. Equivalent in behavior to calling the +// `fields` constructor on the return value of `entries`. The resulting +// `fields` is mutable. +// +// clone: func() -> fields +// +//go:nosplit +func (self Fields) Clone() (result Fields) { + self0 := cm.Reinterpret[uint32](self) + result0 := wasmimport_FieldsClone((uint32)(self0)) + result = cm.Reinterpret[Fields]((uint32)(result0)) + return +} + +//go:wasmimport wasi:http/types@0.2.1 [method]fields.clone +//go:noescape +func wasmimport_FieldsClone(self0 uint32) (result0 uint32) + +// Delete represents the imported method "delete". +// +// Delete all values for a key. Does nothing if no values for the key +// exist. +// +// Fails with `header-error.immutable` if the `fields` are immutable. +// +// Fails with `header-error.invalid-syntax` if the `field-key` is +// syntactically invalid. +// +// delete: func(name: field-key) -> result<_, header-error> +// +//go:nosplit +func (self Fields) Delete(name FieldKey) (result cm.Result[HeaderError, struct{}, HeaderError]) { + self0 := cm.Reinterpret[uint32](self) + name0, name1 := cm.LowerString(name) + wasmimport_FieldsDelete((uint32)(self0), (*uint8)(name0), (uint32)(name1), &result) + return +} + +//go:wasmimport wasi:http/types@0.2.1 [method]fields.delete +//go:noescape +func wasmimport_FieldsDelete(self0 uint32, name0 *uint8, name1 uint32, result *cm.Result[HeaderError, struct{}, HeaderError]) + +// Entries represents the imported method "entries". +// +// Retrieve the full set of keys and values in the Fields. Like the +// constructor, the list represents each key-value pair. +// +// The outer list represents each key-value pair in the Fields. Keys +// which have multiple values are represented by multiple entries in this +// list with the same key. +// +// entries: func() -> list> +// +//go:nosplit +func (self Fields) Entries() (result cm.List[cm.Tuple[FieldKey, FieldValue]]) { + self0 := cm.Reinterpret[uint32](self) + wasmimport_FieldsEntries((uint32)(self0), &result) + return +} + +//go:wasmimport wasi:http/types@0.2.1 [method]fields.entries +//go:noescape +func wasmimport_FieldsEntries(self0 uint32, result *cm.List[cm.Tuple[FieldKey, FieldValue]]) + +// Get represents the imported method "get". +// +// Get all of the values corresponding to a key. If the key is not present +// in this `fields` or is syntactically invalid, an empty list is returned. +// However, if the key is present but empty, this is represented by a list +// with one or more empty field-values present. +// +// get: func(name: field-key) -> list +// +//go:nosplit +func (self Fields) Get(name FieldKey) (result cm.List[FieldValue]) { + self0 := cm.Reinterpret[uint32](self) + name0, name1 := cm.LowerString(name) + wasmimport_FieldsGet((uint32)(self0), (*uint8)(name0), (uint32)(name1), &result) + return +} + +//go:wasmimport wasi:http/types@0.2.1 [method]fields.get +//go:noescape +func wasmimport_FieldsGet(self0 uint32, name0 *uint8, name1 uint32, result *cm.List[FieldValue]) + +// Has represents the imported method "has". +// +// Returns `true` when the key is present in this `fields`. If the key is +// syntactically invalid, `false` is returned. +// +// has: func(name: field-key) -> bool +// +//go:nosplit +func (self Fields) Has(name FieldKey) (result bool) { + self0 := cm.Reinterpret[uint32](self) + name0, name1 := cm.LowerString(name) + result0 := wasmimport_FieldsHas((uint32)(self0), (*uint8)(name0), (uint32)(name1)) + result = cm.U32ToBool((uint32)(result0)) + return +} + +//go:wasmimport wasi:http/types@0.2.1 [method]fields.has +//go:noescape +func wasmimport_FieldsHas(self0 uint32, name0 *uint8, name1 uint32) (result0 uint32) + +// Set represents the imported method "set". +// +// Set all of the values for a key. Clears any existing values for that +// key, if they have been set. +// +// Fails with `header-error.immutable` if the `fields` are immutable. +// +// Fails with `header-error.invalid-syntax` if the `field-key` or any of +// the `field-value`s are syntactically invalid. +// +// set: func(name: field-key, value: list) -> result<_, header-error> +// +//go:nosplit +func (self Fields) Set(name FieldKey, value cm.List[FieldValue]) (result cm.Result[HeaderError, struct{}, HeaderError]) { + self0 := cm.Reinterpret[uint32](self) + name0, name1 := cm.LowerString(name) + value0, value1 := cm.LowerList(value) + wasmimport_FieldsSet((uint32)(self0), (*uint8)(name0), (uint32)(name1), (*FieldValue)(value0), (uint32)(value1), &result) + return +} + +//go:wasmimport wasi:http/types@0.2.1 [method]fields.set +//go:noescape +func wasmimport_FieldsSet(self0 uint32, name0 *uint8, name1 uint32, value0 *FieldValue, value1 uint32, result *cm.Result[HeaderError, struct{}, HeaderError]) + +// IncomingRequest represents the imported resource "wasi:http/types@0.2.1#incoming-request". +// +// Represents an incoming HTTP Request. +// +// resource incoming-request +type IncomingRequest cm.Resource + +// ResourceDrop represents the imported resource-drop for resource "incoming-request". +// +// Drops a resource handle. +// +//go:nosplit +func (self IncomingRequest) ResourceDrop() { + self0 := cm.Reinterpret[uint32](self) + wasmimport_IncomingRequestResourceDrop((uint32)(self0)) + return +} + +//go:wasmimport wasi:http/types@0.2.1 [resource-drop]incoming-request +//go:noescape +func wasmimport_IncomingRequestResourceDrop(self0 uint32) + +// Authority represents the imported method "authority". +// +// Returns the authority of the Request's target URI, if present. +// +// authority: func() -> option +// +//go:nosplit +func (self IncomingRequest) Authority() (result cm.Option[string]) { + self0 := cm.Reinterpret[uint32](self) + wasmimport_IncomingRequestAuthority((uint32)(self0), &result) + return +} + +//go:wasmimport wasi:http/types@0.2.1 [method]incoming-request.authority +//go:noescape +func wasmimport_IncomingRequestAuthority(self0 uint32, result *cm.Option[string]) + +// Consume represents the imported method "consume". +// +// Gives the `incoming-body` associated with this request. Will only +// return success at most once, and subsequent calls will return error. +// +// consume: func() -> result +// +//go:nosplit +func (self IncomingRequest) Consume() (result cm.Result[IncomingBody, IncomingBody, struct{}]) { + self0 := cm.Reinterpret[uint32](self) + wasmimport_IncomingRequestConsume((uint32)(self0), &result) + return +} + +//go:wasmimport wasi:http/types@0.2.1 [method]incoming-request.consume +//go:noescape +func wasmimport_IncomingRequestConsume(self0 uint32, result *cm.Result[IncomingBody, IncomingBody, struct{}]) + +// Headers represents the imported method "headers". +// +// Get the `headers` associated with the request. +// +// The returned `headers` resource is immutable: `set`, `append`, and +// `delete` operations will fail with `header-error.immutable`. +// +// The `headers` returned are a child resource: it must be dropped before +// the parent `incoming-request` is dropped. Dropping this +// `incoming-request` before all children are dropped will trap. +// +// headers: func() -> headers +// +//go:nosplit +func (self IncomingRequest) Headers() (result Fields) { + self0 := cm.Reinterpret[uint32](self) + result0 := wasmimport_IncomingRequestHeaders((uint32)(self0)) + result = cm.Reinterpret[Fields]((uint32)(result0)) + return +} + +//go:wasmimport wasi:http/types@0.2.1 [method]incoming-request.headers +//go:noescape +func wasmimport_IncomingRequestHeaders(self0 uint32) (result0 uint32) + +// Method represents the imported method "method". +// +// Returns the method of the incoming request. +// +// method: func() -> method +// +//go:nosplit +func (self IncomingRequest) Method() (result Method) { + self0 := cm.Reinterpret[uint32](self) + wasmimport_IncomingRequestMethod((uint32)(self0), &result) + return +} + +//go:wasmimport wasi:http/types@0.2.1 [method]incoming-request.method +//go:noescape +func wasmimport_IncomingRequestMethod(self0 uint32, result *Method) + +// PathWithQuery represents the imported method "path-with-query". +// +// Returns the path with query parameters from the request, as a string. +// +// path-with-query: func() -> option +// +//go:nosplit +func (self IncomingRequest) PathWithQuery() (result cm.Option[string]) { + self0 := cm.Reinterpret[uint32](self) + wasmimport_IncomingRequestPathWithQuery((uint32)(self0), &result) + return +} + +//go:wasmimport wasi:http/types@0.2.1 [method]incoming-request.path-with-query +//go:noescape +func wasmimport_IncomingRequestPathWithQuery(self0 uint32, result *cm.Option[string]) + +// Scheme represents the imported method "scheme". +// +// Returns the protocol scheme from the request. +// +// scheme: func() -> option +// +//go:nosplit +func (self IncomingRequest) Scheme() (result cm.Option[Scheme]) { + self0 := cm.Reinterpret[uint32](self) + wasmimport_IncomingRequestScheme((uint32)(self0), &result) + return +} + +//go:wasmimport wasi:http/types@0.2.1 [method]incoming-request.scheme +//go:noescape +func wasmimport_IncomingRequestScheme(self0 uint32, result *cm.Option[Scheme]) + +// OutgoingRequest represents the imported resource "wasi:http/types@0.2.1#outgoing-request". +// +// Represents an outgoing HTTP Request. +// +// resource outgoing-request +type OutgoingRequest cm.Resource + +// ResourceDrop represents the imported resource-drop for resource "outgoing-request". +// +// Drops a resource handle. +// +//go:nosplit +func (self OutgoingRequest) ResourceDrop() { + self0 := cm.Reinterpret[uint32](self) + wasmimport_OutgoingRequestResourceDrop((uint32)(self0)) + return +} + +//go:wasmimport wasi:http/types@0.2.1 [resource-drop]outgoing-request +//go:noescape +func wasmimport_OutgoingRequestResourceDrop(self0 uint32) + +// NewOutgoingRequest represents the imported constructor for resource "outgoing-request". +// +// Construct a new `outgoing-request` with a default `method` of `GET`, and +// `none` values for `path-with-query`, `scheme`, and `authority`. +// +// * `headers` is the HTTP Headers for the Request. +// +// It is possible to construct, or manipulate with the accessor functions +// below, an `outgoing-request` with an invalid combination of `scheme` +// and `authority`, or `headers` which are not permitted to be sent. +// It is the obligation of the `outgoing-handler.handle` implementation +// to reject invalid constructions of `outgoing-request`. +// +// constructor(headers: headers) +// +//go:nosplit +func NewOutgoingRequest(headers Fields) (result OutgoingRequest) { + headers0 := cm.Reinterpret[uint32](headers) + result0 := wasmimport_NewOutgoingRequest((uint32)(headers0)) + result = cm.Reinterpret[OutgoingRequest]((uint32)(result0)) + return +} + +//go:wasmimport wasi:http/types@0.2.1 [constructor]outgoing-request +//go:noescape +func wasmimport_NewOutgoingRequest(headers0 uint32) (result0 uint32) + +// Authority represents the imported method "authority". +// +// Get the authority of the Request's target URI. A value of `none` may be used +// with Related Schemes which do not require an authority. The HTTP and +// HTTPS schemes always require an authority. +// +// authority: func() -> option +// +//go:nosplit +func (self OutgoingRequest) Authority() (result cm.Option[string]) { + self0 := cm.Reinterpret[uint32](self) + wasmimport_OutgoingRequestAuthority((uint32)(self0), &result) + return +} + +//go:wasmimport wasi:http/types@0.2.1 [method]outgoing-request.authority +//go:noescape +func wasmimport_OutgoingRequestAuthority(self0 uint32, result *cm.Option[string]) + +// Body represents the imported method "body". +// +// Returns the resource corresponding to the outgoing Body for this +// Request. +// +// Returns success on the first call: the `outgoing-body` resource for +// this `outgoing-request` can be retrieved at most once. Subsequent +// calls will return error. +// +// body: func() -> result +// +//go:nosplit +func (self OutgoingRequest) Body() (result cm.Result[OutgoingBody, OutgoingBody, struct{}]) { + self0 := cm.Reinterpret[uint32](self) + wasmimport_OutgoingRequestBody((uint32)(self0), &result) + return +} + +//go:wasmimport wasi:http/types@0.2.1 [method]outgoing-request.body +//go:noescape +func wasmimport_OutgoingRequestBody(self0 uint32, result *cm.Result[OutgoingBody, OutgoingBody, struct{}]) + +// Headers represents the imported method "headers". +// +// Get the headers associated with the Request. +// +// The returned `headers` resource is immutable: `set`, `append`, and +// `delete` operations will fail with `header-error.immutable`. +// +// This headers resource is a child: it must be dropped before the parent +// `outgoing-request` is dropped, or its ownership is transferred to +// another component by e.g. `outgoing-handler.handle`. +// +// headers: func() -> headers +// +//go:nosplit +func (self OutgoingRequest) Headers() (result Fields) { + self0 := cm.Reinterpret[uint32](self) + result0 := wasmimport_OutgoingRequestHeaders((uint32)(self0)) + result = cm.Reinterpret[Fields]((uint32)(result0)) + return +} + +//go:wasmimport wasi:http/types@0.2.1 [method]outgoing-request.headers +//go:noescape +func wasmimport_OutgoingRequestHeaders(self0 uint32) (result0 uint32) + +// Method represents the imported method "method". +// +// Get the Method for the Request. +// +// method: func() -> method +// +//go:nosplit +func (self OutgoingRequest) Method() (result Method) { + self0 := cm.Reinterpret[uint32](self) + wasmimport_OutgoingRequestMethod((uint32)(self0), &result) + return +} + +//go:wasmimport wasi:http/types@0.2.1 [method]outgoing-request.method +//go:noescape +func wasmimport_OutgoingRequestMethod(self0 uint32, result *Method) + +// PathWithQuery represents the imported method "path-with-query". +// +// Get the combination of the HTTP Path and Query for the Request. +// When `none`, this represents an empty Path and empty Query. +// +// path-with-query: func() -> option +// +//go:nosplit +func (self OutgoingRequest) PathWithQuery() (result cm.Option[string]) { + self0 := cm.Reinterpret[uint32](self) + wasmimport_OutgoingRequestPathWithQuery((uint32)(self0), &result) + return +} + +//go:wasmimport wasi:http/types@0.2.1 [method]outgoing-request.path-with-query +//go:noescape +func wasmimport_OutgoingRequestPathWithQuery(self0 uint32, result *cm.Option[string]) + +// Scheme represents the imported method "scheme". +// +// Get the HTTP Related Scheme for the Request. When `none`, the +// implementation may choose an appropriate default scheme. +// +// scheme: func() -> option +// +//go:nosplit +func (self OutgoingRequest) Scheme() (result cm.Option[Scheme]) { + self0 := cm.Reinterpret[uint32](self) + wasmimport_OutgoingRequestScheme((uint32)(self0), &result) + return +} + +//go:wasmimport wasi:http/types@0.2.1 [method]outgoing-request.scheme +//go:noescape +func wasmimport_OutgoingRequestScheme(self0 uint32, result *cm.Option[Scheme]) + +// SetAuthority represents the imported method "set-authority". +// +// Set the authority of the Request's target URI. A value of `none` may be used +// with Related Schemes which do not require an authority. The HTTP and +// HTTPS schemes always require an authority. Fails if the string given is +// not a syntactically valid URI authority. +// +// set-authority: func(authority: option) -> result +// +//go:nosplit +func (self OutgoingRequest) SetAuthority(authority cm.Option[string]) (result cm.BoolResult) { + self0 := cm.Reinterpret[uint32](self) + authority0, authority1, authority2 := lower_OptionString(authority) + result0 := wasmimport_OutgoingRequestSetAuthority((uint32)(self0), (uint32)(authority0), (*uint8)(authority1), (uint32)(authority2)) + result = (cm.BoolResult)(cm.U32ToBool((uint32)(result0))) + return +} + +//go:wasmimport wasi:http/types@0.2.1 [method]outgoing-request.set-authority +//go:noescape +func wasmimport_OutgoingRequestSetAuthority(self0 uint32, authority0 uint32, authority1 *uint8, authority2 uint32) (result0 uint32) + +// SetMethod represents the imported method "set-method". +// +// Set the Method for the Request. Fails if the string present in a +// `method.other` argument is not a syntactically valid method. +// +// set-method: func(method: method) -> result +// +//go:nosplit +func (self OutgoingRequest) SetMethod(method Method) (result cm.BoolResult) { + self0 := cm.Reinterpret[uint32](self) + method0, method1, method2 := lower_Method(method) + result0 := wasmimport_OutgoingRequestSetMethod((uint32)(self0), (uint32)(method0), (*uint8)(method1), (uint32)(method2)) + result = (cm.BoolResult)(cm.U32ToBool((uint32)(result0))) + return +} + +//go:wasmimport wasi:http/types@0.2.1 [method]outgoing-request.set-method +//go:noescape +func wasmimport_OutgoingRequestSetMethod(self0 uint32, method0 uint32, method1 *uint8, method2 uint32) (result0 uint32) + +// SetPathWithQuery represents the imported method "set-path-with-query". +// +// Set the combination of the HTTP Path and Query for the Request. +// When `none`, this represents an empty Path and empty Query. Fails is the +// string given is not a syntactically valid path and query uri component. +// +// set-path-with-query: func(path-with-query: option) -> result +// +//go:nosplit +func (self OutgoingRequest) SetPathWithQuery(pathWithQuery cm.Option[string]) (result cm.BoolResult) { + self0 := cm.Reinterpret[uint32](self) + pathWithQuery0, pathWithQuery1, pathWithQuery2 := lower_OptionString(pathWithQuery) + result0 := wasmimport_OutgoingRequestSetPathWithQuery((uint32)(self0), (uint32)(pathWithQuery0), (*uint8)(pathWithQuery1), (uint32)(pathWithQuery2)) + result = (cm.BoolResult)(cm.U32ToBool((uint32)(result0))) + return +} + +//go:wasmimport wasi:http/types@0.2.1 [method]outgoing-request.set-path-with-query +//go:noescape +func wasmimport_OutgoingRequestSetPathWithQuery(self0 uint32, pathWithQuery0 uint32, pathWithQuery1 *uint8, pathWithQuery2 uint32) (result0 uint32) + +// SetScheme represents the imported method "set-scheme". +// +// Set the HTTP Related Scheme for the Request. When `none`, the +// implementation may choose an appropriate default scheme. Fails if the +// string given is not a syntactically valid uri scheme. +// +// set-scheme: func(scheme: option) -> result +// +//go:nosplit +func (self OutgoingRequest) SetScheme(scheme cm.Option[Scheme]) (result cm.BoolResult) { + self0 := cm.Reinterpret[uint32](self) + scheme0, scheme1, scheme2, scheme3 := lower_OptionScheme(scheme) + result0 := wasmimport_OutgoingRequestSetScheme((uint32)(self0), (uint32)(scheme0), (uint32)(scheme1), (*uint8)(scheme2), (uint32)(scheme3)) + result = (cm.BoolResult)(cm.U32ToBool((uint32)(result0))) + return +} + +//go:wasmimport wasi:http/types@0.2.1 [method]outgoing-request.set-scheme +//go:noescape +func wasmimport_OutgoingRequestSetScheme(self0 uint32, scheme0 uint32, scheme1 uint32, scheme2 *uint8, scheme3 uint32) (result0 uint32) + +// RequestOptions represents the imported resource "wasi:http/types@0.2.1#request-options". +// +// Parameters for making an HTTP Request. Each of these parameters is +// currently an optional timeout applicable to the transport layer of the +// HTTP protocol. +// +// These timeouts are separate from any the user may use to bound a +// blocking call to `wasi:io/poll.poll`. +// +// resource request-options +type RequestOptions cm.Resource + +// ResourceDrop represents the imported resource-drop for resource "request-options". +// +// Drops a resource handle. +// +//go:nosplit +func (self RequestOptions) ResourceDrop() { + self0 := cm.Reinterpret[uint32](self) + wasmimport_RequestOptionsResourceDrop((uint32)(self0)) + return +} + +//go:wasmimport wasi:http/types@0.2.1 [resource-drop]request-options +//go:noescape +func wasmimport_RequestOptionsResourceDrop(self0 uint32) + +// NewRequestOptions represents the imported constructor for resource "request-options". +// +// Construct a default `request-options` value. +// +// constructor() +// +//go:nosplit +func NewRequestOptions() (result RequestOptions) { + result0 := wasmimport_NewRequestOptions() + result = cm.Reinterpret[RequestOptions]((uint32)(result0)) + return +} + +//go:wasmimport wasi:http/types@0.2.1 [constructor]request-options +//go:noescape +func wasmimport_NewRequestOptions() (result0 uint32) + +// BetweenBytesTimeout represents the imported method "between-bytes-timeout". +// +// The timeout for receiving subsequent chunks of bytes in the Response +// body stream. +// +// between-bytes-timeout: func() -> option +// +//go:nosplit +func (self RequestOptions) BetweenBytesTimeout() (result cm.Option[monotonicclock.Duration]) { + self0 := cm.Reinterpret[uint32](self) + wasmimport_RequestOptionsBetweenBytesTimeout((uint32)(self0), &result) + return +} + +//go:wasmimport wasi:http/types@0.2.1 [method]request-options.between-bytes-timeout +//go:noescape +func wasmimport_RequestOptionsBetweenBytesTimeout(self0 uint32, result *cm.Option[monotonicclock.Duration]) + +// ConnectTimeout represents the imported method "connect-timeout". +// +// The timeout for the initial connect to the HTTP Server. +// +// connect-timeout: func() -> option +// +//go:nosplit +func (self RequestOptions) ConnectTimeout() (result cm.Option[monotonicclock.Duration]) { + self0 := cm.Reinterpret[uint32](self) + wasmimport_RequestOptionsConnectTimeout((uint32)(self0), &result) + return +} + +//go:wasmimport wasi:http/types@0.2.1 [method]request-options.connect-timeout +//go:noescape +func wasmimport_RequestOptionsConnectTimeout(self0 uint32, result *cm.Option[monotonicclock.Duration]) + +// FirstByteTimeout represents the imported method "first-byte-timeout". +// +// The timeout for receiving the first byte of the Response body. +// +// first-byte-timeout: func() -> option +// +//go:nosplit +func (self RequestOptions) FirstByteTimeout() (result cm.Option[monotonicclock.Duration]) { + self0 := cm.Reinterpret[uint32](self) + wasmimport_RequestOptionsFirstByteTimeout((uint32)(self0), &result) + return +} + +//go:wasmimport wasi:http/types@0.2.1 [method]request-options.first-byte-timeout +//go:noescape +func wasmimport_RequestOptionsFirstByteTimeout(self0 uint32, result *cm.Option[monotonicclock.Duration]) + +// SetBetweenBytesTimeout represents the imported method "set-between-bytes-timeout". +// +// Set the timeout for receiving subsequent chunks of bytes in the Response +// body stream. An error return value indicates that this timeout is not +// supported. +// +// set-between-bytes-timeout: func(duration: option) -> result +// +//go:nosplit +func (self RequestOptions) SetBetweenBytesTimeout(duration cm.Option[monotonicclock.Duration]) (result cm.BoolResult) { + self0 := cm.Reinterpret[uint32](self) + duration0, duration1 := lower_OptionDuration(duration) + result0 := wasmimport_RequestOptionsSetBetweenBytesTimeout((uint32)(self0), (uint32)(duration0), (uint64)(duration1)) + result = (cm.BoolResult)(cm.U32ToBool((uint32)(result0))) + return +} + +//go:wasmimport wasi:http/types@0.2.1 [method]request-options.set-between-bytes-timeout +//go:noescape +func wasmimport_RequestOptionsSetBetweenBytesTimeout(self0 uint32, duration0 uint32, duration1 uint64) (result0 uint32) + +// SetConnectTimeout represents the imported method "set-connect-timeout". +// +// Set the timeout for the initial connect to the HTTP Server. An error +// return value indicates that this timeout is not supported. +// +// set-connect-timeout: func(duration: option) -> result +// +//go:nosplit +func (self RequestOptions) SetConnectTimeout(duration cm.Option[monotonicclock.Duration]) (result cm.BoolResult) { + self0 := cm.Reinterpret[uint32](self) + duration0, duration1 := lower_OptionDuration(duration) + result0 := wasmimport_RequestOptionsSetConnectTimeout((uint32)(self0), (uint32)(duration0), (uint64)(duration1)) + result = (cm.BoolResult)(cm.U32ToBool((uint32)(result0))) + return +} + +//go:wasmimport wasi:http/types@0.2.1 [method]request-options.set-connect-timeout +//go:noescape +func wasmimport_RequestOptionsSetConnectTimeout(self0 uint32, duration0 uint32, duration1 uint64) (result0 uint32) + +// SetFirstByteTimeout represents the imported method "set-first-byte-timeout". +// +// Set the timeout for receiving the first byte of the Response body. An +// error return value indicates that this timeout is not supported. +// +// set-first-byte-timeout: func(duration: option) -> result +// +//go:nosplit +func (self RequestOptions) SetFirstByteTimeout(duration cm.Option[monotonicclock.Duration]) (result cm.BoolResult) { + self0 := cm.Reinterpret[uint32](self) + duration0, duration1 := lower_OptionDuration(duration) + result0 := wasmimport_RequestOptionsSetFirstByteTimeout((uint32)(self0), (uint32)(duration0), (uint64)(duration1)) + result = (cm.BoolResult)(cm.U32ToBool((uint32)(result0))) + return +} + +//go:wasmimport wasi:http/types@0.2.1 [method]request-options.set-first-byte-timeout +//go:noescape +func wasmimport_RequestOptionsSetFirstByteTimeout(self0 uint32, duration0 uint32, duration1 uint64) (result0 uint32) + +// ResponseOutparam represents the imported resource "wasi:http/types@0.2.1#response-outparam". +// +// Represents the ability to send an HTTP Response. +// +// This resource is used by the `wasi:http/incoming-handler` interface to +// allow a Response to be sent corresponding to the Request provided as the +// other argument to `incoming-handler.handle`. +// +// resource response-outparam +type ResponseOutparam cm.Resource + +// ResourceDrop represents the imported resource-drop for resource "response-outparam". +// +// Drops a resource handle. +// +//go:nosplit +func (self ResponseOutparam) ResourceDrop() { + self0 := cm.Reinterpret[uint32](self) + wasmimport_ResponseOutparamResourceDrop((uint32)(self0)) + return +} + +//go:wasmimport wasi:http/types@0.2.1 [resource-drop]response-outparam +//go:noescape +func wasmimport_ResponseOutparamResourceDrop(self0 uint32) + +// ResponseOutparamSet represents the imported static function "set". +// +// Set the value of the `response-outparam` to either send a response, +// or indicate an error. +// +// This method consumes the `response-outparam` to ensure that it is +// called at most once. If it is never called, the implementation +// will respond with an error. +// +// The user may provide an `error` to `response` to allow the +// implementation determine how to respond with an HTTP error response. +// +// set: static func(param: response-outparam, response: result) +// +//go:nosplit +func ResponseOutparamSet(param ResponseOutparam, response cm.Result[ErrorCodeShape, OutgoingResponse, ErrorCode]) { + param0 := cm.Reinterpret[uint32](param) + response0, response1, response2, response3, response4, response5, response6, response7 := lower_ResultOutgoingResponseErrorCode(response) + wasmimport_ResponseOutparamSet((uint32)(param0), (uint32)(response0), (uint32)(response1), (uint32)(response2), (uint64)(response3), (uint32)(response4), (uint32)(response5), (uint32)(response6), (uint32)(response7)) + return +} + +//go:wasmimport wasi:http/types@0.2.1 [static]response-outparam.set +//go:noescape +func wasmimport_ResponseOutparamSet(param0 uint32, response0 uint32, response1 uint32, response2 uint32, response3 uint64, response4 uint32, response5 uint32, response6 uint32, response7 uint32) + +// StatusCode represents the u16 "wasi:http/types@0.2.1#status-code". +// +// This type corresponds to the HTTP standard Status Code. +// +// type status-code = u16 +type StatusCode uint16 + +// IncomingResponse represents the imported resource "wasi:http/types@0.2.1#incoming-response". +// +// Represents an incoming HTTP Response. +// +// resource incoming-response +type IncomingResponse cm.Resource + +// ResourceDrop represents the imported resource-drop for resource "incoming-response". +// +// Drops a resource handle. +// +//go:nosplit +func (self IncomingResponse) ResourceDrop() { + self0 := cm.Reinterpret[uint32](self) + wasmimport_IncomingResponseResourceDrop((uint32)(self0)) + return +} + +//go:wasmimport wasi:http/types@0.2.1 [resource-drop]incoming-response +//go:noescape +func wasmimport_IncomingResponseResourceDrop(self0 uint32) + +// Consume represents the imported method "consume". +// +// Returns the incoming body. May be called at most once. Returns error +// if called additional times. +// +// consume: func() -> result +// +//go:nosplit +func (self IncomingResponse) Consume() (result cm.Result[IncomingBody, IncomingBody, struct{}]) { + self0 := cm.Reinterpret[uint32](self) + wasmimport_IncomingResponseConsume((uint32)(self0), &result) + return +} + +//go:wasmimport wasi:http/types@0.2.1 [method]incoming-response.consume +//go:noescape +func wasmimport_IncomingResponseConsume(self0 uint32, result *cm.Result[IncomingBody, IncomingBody, struct{}]) + +// Headers represents the imported method "headers". +// +// Returns the headers from the incoming response. +// +// The returned `headers` resource is immutable: `set`, `append`, and +// `delete` operations will fail with `header-error.immutable`. +// +// This headers resource is a child: it must be dropped before the parent +// `incoming-response` is dropped. +// +// headers: func() -> headers +// +//go:nosplit +func (self IncomingResponse) Headers() (result Fields) { + self0 := cm.Reinterpret[uint32](self) + result0 := wasmimport_IncomingResponseHeaders((uint32)(self0)) + result = cm.Reinterpret[Fields]((uint32)(result0)) + return +} + +//go:wasmimport wasi:http/types@0.2.1 [method]incoming-response.headers +//go:noescape +func wasmimport_IncomingResponseHeaders(self0 uint32) (result0 uint32) + +// Status represents the imported method "status". +// +// Returns the status code from the incoming response. +// +// status: func() -> status-code +// +//go:nosplit +func (self IncomingResponse) Status() (result StatusCode) { + self0 := cm.Reinterpret[uint32](self) + result0 := wasmimport_IncomingResponseStatus((uint32)(self0)) + result = (StatusCode)((uint32)(result0)) + return +} + +//go:wasmimport wasi:http/types@0.2.1 [method]incoming-response.status +//go:noescape +func wasmimport_IncomingResponseStatus(self0 uint32) (result0 uint32) + +// IncomingBody represents the imported resource "wasi:http/types@0.2.1#incoming-body". +// +// Represents an incoming HTTP Request or Response's Body. +// +// A body has both its contents - a stream of bytes - and a (possibly +// empty) set of trailers, indicating that the full contents of the +// body have been received. This resource represents the contents as +// an `input-stream` and the delivery of trailers as a `future-trailers`, +// and ensures that the user of this interface may only be consuming either +// the body contents or waiting on trailers at any given time. +// +// resource incoming-body +type IncomingBody cm.Resource + +// ResourceDrop represents the imported resource-drop for resource "incoming-body". +// +// Drops a resource handle. +// +//go:nosplit +func (self IncomingBody) ResourceDrop() { + self0 := cm.Reinterpret[uint32](self) + wasmimport_IncomingBodyResourceDrop((uint32)(self0)) + return +} + +//go:wasmimport wasi:http/types@0.2.1 [resource-drop]incoming-body +//go:noescape +func wasmimport_IncomingBodyResourceDrop(self0 uint32) + +// IncomingBodyFinish represents the imported static function "finish". +// +// Takes ownership of `incoming-body`, and returns a `future-trailers`. +// This function will trap if the `input-stream` child is still alive. +// +// finish: static func(this: incoming-body) -> future-trailers +// +//go:nosplit +func IncomingBodyFinish(this IncomingBody) (result FutureTrailers) { + this0 := cm.Reinterpret[uint32](this) + result0 := wasmimport_IncomingBodyFinish((uint32)(this0)) + result = cm.Reinterpret[FutureTrailers]((uint32)(result0)) + return +} + +//go:wasmimport wasi:http/types@0.2.1 [static]incoming-body.finish +//go:noescape +func wasmimport_IncomingBodyFinish(this0 uint32) (result0 uint32) + +// Stream represents the imported method "stream". +// +// Returns the contents of the body, as a stream of bytes. +// +// Returns success on first call: the stream representing the contents +// can be retrieved at most once. Subsequent calls will return error. +// +// The returned `input-stream` resource is a child: it must be dropped +// before the parent `incoming-body` is dropped, or consumed by +// `incoming-body.finish`. +// +// This invariant ensures that the implementation can determine whether +// the user is consuming the contents of the body, waiting on the +// `future-trailers` to be ready, or neither. This allows for network +// backpressure is to be applied when the user is consuming the body, +// and for that backpressure to not inhibit delivery of the trailers if +// the user does not read the entire body. +// +// %stream: func() -> result +// +//go:nosplit +func (self IncomingBody) Stream() (result cm.Result[streams.InputStream, streams.InputStream, struct{}]) { + self0 := cm.Reinterpret[uint32](self) + wasmimport_IncomingBodyStream((uint32)(self0), &result) + return +} + +//go:wasmimport wasi:http/types@0.2.1 [method]incoming-body.stream +//go:noescape +func wasmimport_IncomingBodyStream(self0 uint32, result *cm.Result[streams.InputStream, streams.InputStream, struct{}]) + +// FutureTrailers represents the imported resource "wasi:http/types@0.2.1#future-trailers". +// +// Represents a future which may eventually return trailers, or an error. +// +// In the case that the incoming HTTP Request or Response did not have any +// trailers, this future will resolve to the empty set of trailers once the +// complete Request or Response body has been received. +// +// resource future-trailers +type FutureTrailers cm.Resource + +// ResourceDrop represents the imported resource-drop for resource "future-trailers". +// +// Drops a resource handle. +// +//go:nosplit +func (self FutureTrailers) ResourceDrop() { + self0 := cm.Reinterpret[uint32](self) + wasmimport_FutureTrailersResourceDrop((uint32)(self0)) + return +} + +//go:wasmimport wasi:http/types@0.2.1 [resource-drop]future-trailers +//go:noescape +func wasmimport_FutureTrailersResourceDrop(self0 uint32) + +// Get represents the imported method "get". +// +// Returns the contents of the trailers, or an error which occurred, +// once the future is ready. +// +// The outer `option` represents future readiness. Users can wait on this +// `option` to become `some` using the `subscribe` method. +// +// The outer `result` is used to retrieve the trailers or error at most +// once. It will be success on the first call in which the outer option +// is `some`, and error on subsequent calls. +// +// The inner `result` represents that either the HTTP Request or Response +// body, as well as any trailers, were received successfully, or that an +// error occurred receiving them. The optional `trailers` indicates whether +// or not trailers were present in the body. +// +// When some `trailers` are returned by this method, the `trailers` +// resource is immutable, and a child. Use of the `set`, `append`, or +// `delete` methods will return an error, and the resource must be +// dropped before the parent `future-trailers` is dropped. +// +// get: func() -> option, error-code>>> +// +//go:nosplit +func (self FutureTrailers) Get() (result cm.Option[cm.Result[cm.Result[ErrorCodeShape, cm.Option[Fields], ErrorCode], cm.Result[ErrorCodeShape, cm.Option[Fields], ErrorCode], struct{}]]) { + self0 := cm.Reinterpret[uint32](self) + wasmimport_FutureTrailersGet((uint32)(self0), &result) + return +} + +//go:wasmimport wasi:http/types@0.2.1 [method]future-trailers.get +//go:noescape +func wasmimport_FutureTrailersGet(self0 uint32, result *cm.Option[cm.Result[cm.Result[ErrorCodeShape, cm.Option[Fields], ErrorCode], cm.Result[ErrorCodeShape, cm.Option[Fields], ErrorCode], struct{}]]) + +// Subscribe represents the imported method "subscribe". +// +// Returns a pollable which becomes ready when either the trailers have +// been received, or an error has occurred. When this pollable is ready, +// the `get` method will return `some`. +// +// subscribe: func() -> pollable +// +//go:nosplit +func (self FutureTrailers) Subscribe() (result poll.Pollable) { + self0 := cm.Reinterpret[uint32](self) + result0 := wasmimport_FutureTrailersSubscribe((uint32)(self0)) + result = cm.Reinterpret[poll.Pollable]((uint32)(result0)) + return +} + +//go:wasmimport wasi:http/types@0.2.1 [method]future-trailers.subscribe +//go:noescape +func wasmimport_FutureTrailersSubscribe(self0 uint32) (result0 uint32) + +// OutgoingResponse represents the imported resource "wasi:http/types@0.2.1#outgoing-response". +// +// Represents an outgoing HTTP Response. +// +// resource outgoing-response +type OutgoingResponse cm.Resource + +// ResourceDrop represents the imported resource-drop for resource "outgoing-response". +// +// Drops a resource handle. +// +//go:nosplit +func (self OutgoingResponse) ResourceDrop() { + self0 := cm.Reinterpret[uint32](self) + wasmimport_OutgoingResponseResourceDrop((uint32)(self0)) + return +} + +//go:wasmimport wasi:http/types@0.2.1 [resource-drop]outgoing-response +//go:noescape +func wasmimport_OutgoingResponseResourceDrop(self0 uint32) + +// NewOutgoingResponse represents the imported constructor for resource "outgoing-response". +// +// Construct an `outgoing-response`, with a default `status-code` of `200`. +// If a different `status-code` is needed, it must be set via the +// `set-status-code` method. +// +// * `headers` is the HTTP Headers for the Response. +// +// constructor(headers: headers) +// +//go:nosplit +func NewOutgoingResponse(headers Fields) (result OutgoingResponse) { + headers0 := cm.Reinterpret[uint32](headers) + result0 := wasmimport_NewOutgoingResponse((uint32)(headers0)) + result = cm.Reinterpret[OutgoingResponse]((uint32)(result0)) + return +} + +//go:wasmimport wasi:http/types@0.2.1 [constructor]outgoing-response +//go:noescape +func wasmimport_NewOutgoingResponse(headers0 uint32) (result0 uint32) + +// Body represents the imported method "body". +// +// Returns the resource corresponding to the outgoing Body for this Response. +// +// Returns success on the first call: the `outgoing-body` resource for +// this `outgoing-response` can be retrieved at most once. Subsequent +// calls will return error. +// +// body: func() -> result +// +//go:nosplit +func (self OutgoingResponse) Body() (result cm.Result[OutgoingBody, OutgoingBody, struct{}]) { + self0 := cm.Reinterpret[uint32](self) + wasmimport_OutgoingResponseBody((uint32)(self0), &result) + return +} + +//go:wasmimport wasi:http/types@0.2.1 [method]outgoing-response.body +//go:noescape +func wasmimport_OutgoingResponseBody(self0 uint32, result *cm.Result[OutgoingBody, OutgoingBody, struct{}]) + +// Headers represents the imported method "headers". +// +// Get the headers associated with the Request. +// +// The returned `headers` resource is immutable: `set`, `append`, and +// `delete` operations will fail with `header-error.immutable`. +// +// This headers resource is a child: it must be dropped before the parent +// `outgoing-request` is dropped, or its ownership is transferred to +// another component by e.g. `outgoing-handler.handle`. +// +// headers: func() -> headers +// +//go:nosplit +func (self OutgoingResponse) Headers() (result Fields) { + self0 := cm.Reinterpret[uint32](self) + result0 := wasmimport_OutgoingResponseHeaders((uint32)(self0)) + result = cm.Reinterpret[Fields]((uint32)(result0)) + return +} + +//go:wasmimport wasi:http/types@0.2.1 [method]outgoing-response.headers +//go:noescape +func wasmimport_OutgoingResponseHeaders(self0 uint32) (result0 uint32) + +// SetStatusCode represents the imported method "set-status-code". +// +// Set the HTTP Status Code for the Response. Fails if the status-code +// given is not a valid http status code. +// +// set-status-code: func(status-code: status-code) -> result +// +//go:nosplit +func (self OutgoingResponse) SetStatusCode(statusCode StatusCode) (result cm.BoolResult) { + self0 := cm.Reinterpret[uint32](self) + statusCode0 := (uint32)(statusCode) + result0 := wasmimport_OutgoingResponseSetStatusCode((uint32)(self0), (uint32)(statusCode0)) + result = (cm.BoolResult)(cm.U32ToBool((uint32)(result0))) + return +} + +//go:wasmimport wasi:http/types@0.2.1 [method]outgoing-response.set-status-code +//go:noescape +func wasmimport_OutgoingResponseSetStatusCode(self0 uint32, statusCode0 uint32) (result0 uint32) + +// StatusCode represents the imported method "status-code". +// +// Get the HTTP Status Code for the Response. +// +// status-code: func() -> status-code +// +//go:nosplit +func (self OutgoingResponse) StatusCode() (result StatusCode) { + self0 := cm.Reinterpret[uint32](self) + result0 := wasmimport_OutgoingResponseStatusCode((uint32)(self0)) + result = (StatusCode)((uint32)(result0)) + return +} + +//go:wasmimport wasi:http/types@0.2.1 [method]outgoing-response.status-code +//go:noescape +func wasmimport_OutgoingResponseStatusCode(self0 uint32) (result0 uint32) + +// OutgoingBody represents the imported resource "wasi:http/types@0.2.1#outgoing-body". +// +// Represents an outgoing HTTP Request or Response's Body. +// +// A body has both its contents - a stream of bytes - and a (possibly +// empty) set of trailers, inducating the full contents of the body +// have been sent. This resource represents the contents as an +// `output-stream` child resource, and the completion of the body (with +// optional trailers) with a static function that consumes the +// `outgoing-body` resource, and ensures that the user of this interface +// may not write to the body contents after the body has been finished. +// +// If the user code drops this resource, as opposed to calling the static +// method `finish`, the implementation should treat the body as incomplete, +// and that an error has occurred. The implementation should propagate this +// error to the HTTP protocol by whatever means it has available, +// including: corrupting the body on the wire, aborting the associated +// Request, or sending a late status code for the Response. +// +// resource outgoing-body +type OutgoingBody cm.Resource + +// ResourceDrop represents the imported resource-drop for resource "outgoing-body". +// +// Drops a resource handle. +// +//go:nosplit +func (self OutgoingBody) ResourceDrop() { + self0 := cm.Reinterpret[uint32](self) + wasmimport_OutgoingBodyResourceDrop((uint32)(self0)) + return +} + +//go:wasmimport wasi:http/types@0.2.1 [resource-drop]outgoing-body +//go:noescape +func wasmimport_OutgoingBodyResourceDrop(self0 uint32) + +// OutgoingBodyFinish represents the imported static function "finish". +// +// Finalize an outgoing body, optionally providing trailers. This must be +// called to signal that the response is complete. If the `outgoing-body` +// is dropped without calling `outgoing-body.finalize`, the implementation +// should treat the body as corrupted. +// +// Fails if the body's `outgoing-request` or `outgoing-response` was +// constructed with a Content-Length header, and the contents written +// to the body (via `write`) does not match the value given in the +// Content-Length. +// +// finish: static func(this: outgoing-body, trailers: option) -> result<_, +// error-code> +// +//go:nosplit +func OutgoingBodyFinish(this OutgoingBody, trailers cm.Option[Fields]) (result cm.Result[ErrorCode, struct{}, ErrorCode]) { + this0 := cm.Reinterpret[uint32](this) + trailers0, trailers1 := lower_OptionTrailers(trailers) + wasmimport_OutgoingBodyFinish((uint32)(this0), (uint32)(trailers0), (uint32)(trailers1), &result) + return +} + +//go:wasmimport wasi:http/types@0.2.1 [static]outgoing-body.finish +//go:noescape +func wasmimport_OutgoingBodyFinish(this0 uint32, trailers0 uint32, trailers1 uint32, result *cm.Result[ErrorCode, struct{}, ErrorCode]) + +// Write represents the imported method "write". +// +// Returns a stream for writing the body contents. +// +// The returned `output-stream` is a child resource: it must be dropped +// before the parent `outgoing-body` resource is dropped (or finished), +// otherwise the `outgoing-body` drop or `finish` will trap. +// +// Returns success on the first call: the `output-stream` resource for +// this `outgoing-body` may be retrieved at most once. Subsequent calls +// will return error. +// +// write: func() -> result +// +//go:nosplit +func (self OutgoingBody) Write() (result cm.Result[streams.OutputStream, streams.OutputStream, struct{}]) { + self0 := cm.Reinterpret[uint32](self) + wasmimport_OutgoingBodyWrite((uint32)(self0), &result) + return +} + +//go:wasmimport wasi:http/types@0.2.1 [method]outgoing-body.write +//go:noescape +func wasmimport_OutgoingBodyWrite(self0 uint32, result *cm.Result[streams.OutputStream, streams.OutputStream, struct{}]) + +// FutureIncomingResponse represents the imported resource "wasi:http/types@0.2.1#future-incoming-response". +// +// Represents a future which may eventually return an incoming HTTP +// Response, or an error. +// +// This resource is returned by the `wasi:http/outgoing-handler` interface to +// provide the HTTP Response corresponding to the sent Request. +// +// resource future-incoming-response +type FutureIncomingResponse cm.Resource + +// ResourceDrop represents the imported resource-drop for resource "future-incoming-response". +// +// Drops a resource handle. +// +//go:nosplit +func (self FutureIncomingResponse) ResourceDrop() { + self0 := cm.Reinterpret[uint32](self) + wasmimport_FutureIncomingResponseResourceDrop((uint32)(self0)) + return +} + +//go:wasmimport wasi:http/types@0.2.1 [resource-drop]future-incoming-response +//go:noescape +func wasmimport_FutureIncomingResponseResourceDrop(self0 uint32) + +// Get represents the imported method "get". +// +// Returns the incoming HTTP Response, or an error, once one is ready. +// +// The outer `option` represents future readiness. Users can wait on this +// `option` to become `some` using the `subscribe` method. +// +// The outer `result` is used to retrieve the response or error at most +// once. It will be success on the first call in which the outer option +// is `some`, and error on subsequent calls. +// +// The inner `result` represents that either the incoming HTTP Response +// status and headers have received successfully, or that an error +// occurred. Errors may also occur while consuming the response body, +// but those will be reported by the `incoming-body` and its +// `output-stream` child. +// +// get: func() -> option>> +// +//go:nosplit +func (self FutureIncomingResponse) Get() (result cm.Option[cm.Result[cm.Result[ErrorCodeShape, IncomingResponse, ErrorCode], cm.Result[ErrorCodeShape, IncomingResponse, ErrorCode], struct{}]]) { + self0 := cm.Reinterpret[uint32](self) + wasmimport_FutureIncomingResponseGet((uint32)(self0), &result) + return +} + +//go:wasmimport wasi:http/types@0.2.1 [method]future-incoming-response.get +//go:noescape +func wasmimport_FutureIncomingResponseGet(self0 uint32, result *cm.Option[cm.Result[cm.Result[ErrorCodeShape, IncomingResponse, ErrorCode], cm.Result[ErrorCodeShape, IncomingResponse, ErrorCode], struct{}]]) + +// Subscribe represents the imported method "subscribe". +// +// Returns a pollable which becomes ready when either the Response has +// been received, or an error has occurred. When this pollable is ready, +// the `get` method will return `some`. +// +// subscribe: func() -> pollable +// +//go:nosplit +func (self FutureIncomingResponse) Subscribe() (result poll.Pollable) { + self0 := cm.Reinterpret[uint32](self) + result0 := wasmimport_FutureIncomingResponseSubscribe((uint32)(self0)) + result = cm.Reinterpret[poll.Pollable]((uint32)(result0)) + return +} + +//go:wasmimport wasi:http/types@0.2.1 [method]future-incoming-response.subscribe +//go:noescape +func wasmimport_FutureIncomingResponseSubscribe(self0 uint32) (result0 uint32) + +// HTTPErrorCode represents the imported function "http-error-code". +// +// Attempts to extract a http-related `error` from the wasi:io `error` +// provided. +// +// Stream operations which return +// `wasi:io/stream/stream-error::last-operation-failed` have a payload of +// type `wasi:io/error/error` with more information about the operation +// that failed. This payload can be passed through to this function to see +// if there's http-related information about the error to return. +// +// Note that this function is fallible because not all io-errors are +// http-related errors. +// +// http-error-code: func(err: borrow) -> option +// +//go:nosplit +func HTTPErrorCode(err ioerror.Error) (result cm.Option[ErrorCode]) { + err0 := cm.Reinterpret[uint32](err) + wasmimport_HTTPErrorCode((uint32)(err0), &result) + return +} + +//go:wasmimport wasi:http/types@0.2.1 http-error-code +//go:noescape +func wasmimport_HTTPErrorCode(err0 uint32, result *cm.Option[ErrorCode]) diff --git a/examples/go/http/bindings/wasi/io/error/empty.s b/examples/go/http/bindings/wasi/io/error/empty.s new file mode 100644 index 0000000..5444f20 --- /dev/null +++ b/examples/go/http/bindings/wasi/io/error/empty.s @@ -0,0 +1,3 @@ +// This file exists for testing this package without WebAssembly, +// allowing empty function bodies with a //go:wasmimport directive. +// See https://pkg.go.dev/cmd/compile for more information. diff --git a/examples/go/http/bindings/wasi/io/error/error.wit.go b/examples/go/http/bindings/wasi/io/error/error.wit.go new file mode 100644 index 0000000..9571a52 --- /dev/null +++ b/examples/go/http/bindings/wasi/io/error/error.wit.go @@ -0,0 +1,69 @@ +// Code generated by wit-bindgen-go. DO NOT EDIT. + +// Package ioerror represents the imported interface "wasi:io/error@0.2.1". +package ioerror + +import ( + "github.com/bytecodealliance/wasm-tools-go/cm" +) + +// Error represents the imported resource "wasi:io/error@0.2.1#error". +// +// A resource which represents some error information. +// +// The only method provided by this resource is `to-debug-string`, +// which provides some human-readable information about the error. +// +// In the `wasi:io` package, this resource is returned through the +// `wasi:io/streams/stream-error` type. +// +// To provide more specific error information, other interfaces may +// offer functions to "downcast" this error into more specific types. For example, +// errors returned from streams derived from filesystem types can be described using +// the filesystem's own error-code type. This is done using the function +// `wasi:filesystem/types/filesystem-error-code`, which takes a `borrow` +// parameter and returns an `option`. +// +// The set of functions which can "downcast" an `error` into a more +// concrete type is open. +// +// resource error +type Error cm.Resource + +// ResourceDrop represents the imported resource-drop for resource "error". +// +// Drops a resource handle. +// +//go:nosplit +func (self Error) ResourceDrop() { + self0 := cm.Reinterpret[uint32](self) + wasmimport_ErrorResourceDrop((uint32)(self0)) + return +} + +//go:wasmimport wasi:io/error@0.2.1 [resource-drop]error +//go:noescape +func wasmimport_ErrorResourceDrop(self0 uint32) + +// ToDebugString represents the imported method "to-debug-string". +// +// Returns a string that is suitable to assist humans in debugging +// this error. +// +// WARNING: The returned string should not be consumed mechanically! +// It may change across platforms, hosts, or other implementation +// details. Parsing this string is a major platform-compatibility +// hazard. +// +// to-debug-string: func() -> string +// +//go:nosplit +func (self Error) ToDebugString() (result string) { + self0 := cm.Reinterpret[uint32](self) + wasmimport_ErrorToDebugString((uint32)(self0), &result) + return +} + +//go:wasmimport wasi:io/error@0.2.1 [method]error.to-debug-string +//go:noescape +func wasmimport_ErrorToDebugString(self0 uint32, result *string) diff --git a/examples/go/http/bindings/wasi/io/poll/empty.s b/examples/go/http/bindings/wasi/io/poll/empty.s new file mode 100644 index 0000000..5444f20 --- /dev/null +++ b/examples/go/http/bindings/wasi/io/poll/empty.s @@ -0,0 +1,3 @@ +// This file exists for testing this package without WebAssembly, +// allowing empty function bodies with a //go:wasmimport directive. +// See https://pkg.go.dev/cmd/compile for more information. diff --git a/examples/go/http/bindings/wasi/io/poll/poll.wit.go b/examples/go/http/bindings/wasi/io/poll/poll.wit.go new file mode 100644 index 0000000..89ed0b9 --- /dev/null +++ b/examples/go/http/bindings/wasi/io/poll/poll.wit.go @@ -0,0 +1,109 @@ +// Code generated by wit-bindgen-go. DO NOT EDIT. + +// Package poll represents the imported interface "wasi:io/poll@0.2.1". +// +// A poll API intended to let users wait for I/O events on multiple handles +// at once. +package poll + +import ( + "github.com/bytecodealliance/wasm-tools-go/cm" +) + +// Pollable represents the imported resource "wasi:io/poll@0.2.1#pollable". +// +// `pollable` represents a single I/O event which may be ready, or not. +// +// resource pollable +type Pollable cm.Resource + +// ResourceDrop represents the imported resource-drop for resource "pollable". +// +// Drops a resource handle. +// +//go:nosplit +func (self Pollable) ResourceDrop() { + self0 := cm.Reinterpret[uint32](self) + wasmimport_PollableResourceDrop((uint32)(self0)) + return +} + +//go:wasmimport wasi:io/poll@0.2.1 [resource-drop]pollable +//go:noescape +func wasmimport_PollableResourceDrop(self0 uint32) + +// Block represents the imported method "block". +// +// `block` returns immediately if the pollable is ready, and otherwise +// blocks until ready. +// +// This function is equivalent to calling `poll.poll` on a list +// containing only this pollable. +// +// block: func() +// +//go:nosplit +func (self Pollable) Block() { + self0 := cm.Reinterpret[uint32](self) + wasmimport_PollableBlock((uint32)(self0)) + return +} + +//go:wasmimport wasi:io/poll@0.2.1 [method]pollable.block +//go:noescape +func wasmimport_PollableBlock(self0 uint32) + +// Ready represents the imported method "ready". +// +// Return the readiness of a pollable. This function never blocks. +// +// Returns `true` when the pollable is ready, and `false` otherwise. +// +// ready: func() -> bool +// +//go:nosplit +func (self Pollable) Ready() (result bool) { + self0 := cm.Reinterpret[uint32](self) + result0 := wasmimport_PollableReady((uint32)(self0)) + result = cm.U32ToBool((uint32)(result0)) + return +} + +//go:wasmimport wasi:io/poll@0.2.1 [method]pollable.ready +//go:noescape +func wasmimport_PollableReady(self0 uint32) (result0 uint32) + +// Poll represents the imported function "poll". +// +// Poll for completion on a set of pollables. +// +// This function takes a list of pollables, which identify I/O sources of +// interest, and waits until one or more of the events is ready for I/O. +// +// The result `list` contains one or more indices of handles in the +// argument list that is ready for I/O. +// +// This function traps if either: +// - the list is empty, or: +// - the list contains more elements than can be indexed with a `u32` value. +// +// A timeout can be implemented by adding a pollable from the +// wasi-clocks API to the list. +// +// This function does not return a `result`; polling in itself does not +// do any I/O so it doesn't fail. If any of the I/O sources identified by +// the pollables has an error, it is indicated by marking the source as +// being ready for I/O. +// +// poll: func(in: list>) -> list +// +//go:nosplit +func Poll(in cm.List[Pollable]) (result cm.List[uint32]) { + in0, in1 := cm.LowerList(in) + wasmimport_Poll((*Pollable)(in0), (uint32)(in1), &result) + return +} + +//go:wasmimport wasi:io/poll@0.2.1 poll +//go:noescape +func wasmimport_Poll(in0 *Pollable, in1 uint32, result *cm.List[uint32]) diff --git a/examples/go/http/bindings/wasi/io/streams/abi.go b/examples/go/http/bindings/wasi/io/streams/abi.go new file mode 100644 index 0000000..5f15002 --- /dev/null +++ b/examples/go/http/bindings/wasi/io/streams/abi.go @@ -0,0 +1,12 @@ +// Code generated by wit-bindgen-go. DO NOT EDIT. + +package streams + +import ( + "unsafe" +) + +// StreamErrorShape is used for storage in variant or result types. +type StreamErrorShape struct { + shape [unsafe.Sizeof(StreamError{})]byte +} diff --git a/examples/go/http/bindings/wasi/io/streams/empty.s b/examples/go/http/bindings/wasi/io/streams/empty.s new file mode 100644 index 0000000..5444f20 --- /dev/null +++ b/examples/go/http/bindings/wasi/io/streams/empty.s @@ -0,0 +1,3 @@ +// This file exists for testing this package without WebAssembly, +// allowing empty function bodies with a //go:wasmimport directive. +// See https://pkg.go.dev/cmd/compile for more information. diff --git a/examples/go/http/bindings/wasi/io/streams/streams.wit.go b/examples/go/http/bindings/wasi/io/streams/streams.wit.go new file mode 100644 index 0000000..1daca29 --- /dev/null +++ b/examples/go/http/bindings/wasi/io/streams/streams.wit.go @@ -0,0 +1,523 @@ +// Code generated by wit-bindgen-go. DO NOT EDIT. + +// Package streams represents the imported interface "wasi:io/streams@0.2.1". +// +// WASI I/O is an I/O abstraction API which is currently focused on providing +// stream types. +// +// In the future, the component model is expected to add built-in stream types; +// when it does, they are expected to subsume this API. +package streams + +import ( + "github.com/bytecodealliance/wasm-tools-go/cm" + ioerror "github.com/rvolosatovs/west/examples/go/http/bindings/wasi/io/error" + "github.com/rvolosatovs/west/examples/go/http/bindings/wasi/io/poll" +) + +// StreamError represents the imported variant "wasi:io/streams@0.2.1#stream-error". +// +// An error for input-stream and output-stream operations. +// +// variant stream-error { +// last-operation-failed(error), +// closed, +// } +type StreamError cm.Variant[uint8, ioerror.Error, ioerror.Error] + +// StreamErrorLastOperationFailed returns a [StreamError] of case "last-operation-failed". +// +// The last operation (a write or flush) failed before completion. +// +// More information is available in the `error` payload. +func StreamErrorLastOperationFailed(data ioerror.Error) StreamError { + return cm.New[StreamError](0, data) +} + +// LastOperationFailed returns a non-nil *[ioerror.Error] if [StreamError] represents the variant case "last-operation-failed". +func (self *StreamError) LastOperationFailed() *ioerror.Error { + return cm.Case[ioerror.Error](self, 0) +} + +// StreamErrorClosed returns a [StreamError] of case "closed". +// +// The stream is closed: no more input will be accepted by the +// stream. A closed output-stream will return this error on all +// future operations. +func StreamErrorClosed() StreamError { + var data struct{} + return cm.New[StreamError](1, data) +} + +// Closed returns true if [StreamError] represents the variant case "closed". +func (self *StreamError) Closed() bool { + return self.Tag() == 1 +} + +// InputStream represents the imported resource "wasi:io/streams@0.2.1#input-stream". +// +// An input bytestream. +// +// `input-stream`s are *non-blocking* to the extent practical on underlying +// platforms. I/O operations always return promptly; if fewer bytes are +// promptly available than requested, they return the number of bytes promptly +// available, which could even be zero. To wait for data to be available, +// use the `subscribe` function to obtain a `pollable` which can be polled +// for using `wasi:io/poll`. +// +// resource input-stream +type InputStream cm.Resource + +// ResourceDrop represents the imported resource-drop for resource "input-stream". +// +// Drops a resource handle. +// +//go:nosplit +func (self InputStream) ResourceDrop() { + self0 := cm.Reinterpret[uint32](self) + wasmimport_InputStreamResourceDrop((uint32)(self0)) + return +} + +//go:wasmimport wasi:io/streams@0.2.1 [resource-drop]input-stream +//go:noescape +func wasmimport_InputStreamResourceDrop(self0 uint32) + +// BlockingRead represents the imported method "blocking-read". +// +// Read bytes from a stream, after blocking until at least one byte can +// be read. Except for blocking, behavior is identical to `read`. +// +// blocking-read: func(len: u64) -> result, stream-error> +// +//go:nosplit +func (self InputStream) BlockingRead(len_ uint64) (result cm.Result[cm.List[uint8], cm.List[uint8], StreamError]) { + self0 := cm.Reinterpret[uint32](self) + len0 := (uint64)(len_) + wasmimport_InputStreamBlockingRead((uint32)(self0), (uint64)(len0), &result) + return +} + +//go:wasmimport wasi:io/streams@0.2.1 [method]input-stream.blocking-read +//go:noescape +func wasmimport_InputStreamBlockingRead(self0 uint32, len0 uint64, result *cm.Result[cm.List[uint8], cm.List[uint8], StreamError]) + +// BlockingSkip represents the imported method "blocking-skip". +// +// Skip bytes from a stream, after blocking until at least one byte +// can be skipped. Except for blocking behavior, identical to `skip`. +// +// blocking-skip: func(len: u64) -> result +// +//go:nosplit +func (self InputStream) BlockingSkip(len_ uint64) (result cm.Result[uint64, uint64, StreamError]) { + self0 := cm.Reinterpret[uint32](self) + len0 := (uint64)(len_) + wasmimport_InputStreamBlockingSkip((uint32)(self0), (uint64)(len0), &result) + return +} + +//go:wasmimport wasi:io/streams@0.2.1 [method]input-stream.blocking-skip +//go:noescape +func wasmimport_InputStreamBlockingSkip(self0 uint32, len0 uint64, result *cm.Result[uint64, uint64, StreamError]) + +// Read represents the imported method "read". +// +// Perform a non-blocking read from the stream. +// +// When the source of a `read` is binary data, the bytes from the source +// are returned verbatim. When the source of a `read` is known to the +// implementation to be text, bytes containing the UTF-8 encoding of the +// text are returned. +// +// This function returns a list of bytes containing the read data, +// when successful. The returned list will contain up to `len` bytes; +// it may return fewer than requested, but not more. The list is +// empty when no bytes are available for reading at this time. The +// pollable given by `subscribe` will be ready when more bytes are +// available. +// +// This function fails with a `stream-error` when the operation +// encounters an error, giving `last-operation-failed`, or when the +// stream is closed, giving `closed`. +// +// When the caller gives a `len` of 0, it represents a request to +// read 0 bytes. If the stream is still open, this call should +// succeed and return an empty list, or otherwise fail with `closed`. +// +// The `len` parameter is a `u64`, which could represent a list of u8 which +// is not possible to allocate in wasm32, or not desirable to allocate as +// as a return value by the callee. The callee may return a list of bytes +// less than `len` in size while more bytes are available for reading. +// +// read: func(len: u64) -> result, stream-error> +// +//go:nosplit +func (self InputStream) Read(len_ uint64) (result cm.Result[cm.List[uint8], cm.List[uint8], StreamError]) { + self0 := cm.Reinterpret[uint32](self) + len0 := (uint64)(len_) + wasmimport_InputStreamRead((uint32)(self0), (uint64)(len0), &result) + return +} + +//go:wasmimport wasi:io/streams@0.2.1 [method]input-stream.read +//go:noescape +func wasmimport_InputStreamRead(self0 uint32, len0 uint64, result *cm.Result[cm.List[uint8], cm.List[uint8], StreamError]) + +// Skip represents the imported method "skip". +// +// Skip bytes from a stream. Returns number of bytes skipped. +// +// Behaves identical to `read`, except instead of returning a list +// of bytes, returns the number of bytes consumed from the stream. +// +// skip: func(len: u64) -> result +// +//go:nosplit +func (self InputStream) Skip(len_ uint64) (result cm.Result[uint64, uint64, StreamError]) { + self0 := cm.Reinterpret[uint32](self) + len0 := (uint64)(len_) + wasmimport_InputStreamSkip((uint32)(self0), (uint64)(len0), &result) + return +} + +//go:wasmimport wasi:io/streams@0.2.1 [method]input-stream.skip +//go:noescape +func wasmimport_InputStreamSkip(self0 uint32, len0 uint64, result *cm.Result[uint64, uint64, StreamError]) + +// Subscribe represents the imported method "subscribe". +// +// Create a `pollable` which will resolve once either the specified stream +// has bytes available to read or the other end of the stream has been +// closed. +// The created `pollable` is a child resource of the `input-stream`. +// Implementations may trap if the `input-stream` is dropped before +// all derived `pollable`s created with this function are dropped. +// +// subscribe: func() -> pollable +// +//go:nosplit +func (self InputStream) Subscribe() (result poll.Pollable) { + self0 := cm.Reinterpret[uint32](self) + result0 := wasmimport_InputStreamSubscribe((uint32)(self0)) + result = cm.Reinterpret[poll.Pollable]((uint32)(result0)) + return +} + +//go:wasmimport wasi:io/streams@0.2.1 [method]input-stream.subscribe +//go:noescape +func wasmimport_InputStreamSubscribe(self0 uint32) (result0 uint32) + +// OutputStream represents the imported resource "wasi:io/streams@0.2.1#output-stream". +// +// An output bytestream. +// +// `output-stream`s are *non-blocking* to the extent practical on +// underlying platforms. Except where specified otherwise, I/O operations also +// always return promptly, after the number of bytes that can be written +// promptly, which could even be zero. To wait for the stream to be ready to +// accept data, the `subscribe` function to obtain a `pollable` which can be +// polled for using `wasi:io/poll`. +// +// Dropping an `output-stream` while there's still an active write in +// progress may result in the data being lost. Before dropping the stream, +// be sure to fully flush your writes. +// +// resource output-stream +type OutputStream cm.Resource + +// ResourceDrop represents the imported resource-drop for resource "output-stream". +// +// Drops a resource handle. +// +//go:nosplit +func (self OutputStream) ResourceDrop() { + self0 := cm.Reinterpret[uint32](self) + wasmimport_OutputStreamResourceDrop((uint32)(self0)) + return +} + +//go:wasmimport wasi:io/streams@0.2.1 [resource-drop]output-stream +//go:noescape +func wasmimport_OutputStreamResourceDrop(self0 uint32) + +// BlockingFlush represents the imported method "blocking-flush". +// +// Request to flush buffered output, and block until flush completes +// and stream is ready for writing again. +// +// blocking-flush: func() -> result<_, stream-error> +// +//go:nosplit +func (self OutputStream) BlockingFlush() (result cm.Result[StreamError, struct{}, StreamError]) { + self0 := cm.Reinterpret[uint32](self) + wasmimport_OutputStreamBlockingFlush((uint32)(self0), &result) + return +} + +//go:wasmimport wasi:io/streams@0.2.1 [method]output-stream.blocking-flush +//go:noescape +func wasmimport_OutputStreamBlockingFlush(self0 uint32, result *cm.Result[StreamError, struct{}, StreamError]) + +// BlockingSplice represents the imported method "blocking-splice". +// +// Read from one stream and write to another, with blocking. +// +// This is similar to `splice`, except that it blocks until the +// `output-stream` is ready for writing, and the `input-stream` +// is ready for reading, before performing the `splice`. +// +// blocking-splice: func(src: borrow, len: u64) -> result +// +//go:nosplit +func (self OutputStream) BlockingSplice(src InputStream, len_ uint64) (result cm.Result[uint64, uint64, StreamError]) { + self0 := cm.Reinterpret[uint32](self) + src0 := cm.Reinterpret[uint32](src) + len0 := (uint64)(len_) + wasmimport_OutputStreamBlockingSplice((uint32)(self0), (uint32)(src0), (uint64)(len0), &result) + return +} + +//go:wasmimport wasi:io/streams@0.2.1 [method]output-stream.blocking-splice +//go:noescape +func wasmimport_OutputStreamBlockingSplice(self0 uint32, src0 uint32, len0 uint64, result *cm.Result[uint64, uint64, StreamError]) + +// BlockingWriteAndFlush represents the imported method "blocking-write-and-flush". +// +// Perform a write of up to 4096 bytes, and then flush the stream. Block +// until all of these operations are complete, or an error occurs. +// +// This is a convenience wrapper around the use of `check-write`, +// `subscribe`, `write`, and `flush`, and is implemented with the +// following pseudo-code: +// +// let pollable = this.subscribe(); +// while !contents.is_empty() { +// // Wait for the stream to become writable +// pollable.block(); +// let Ok(n) = this.check-write(); // eliding error handling +// let len = min(n, contents.len()); +// let (chunk, rest) = contents.split_at(len); +// this.write(chunk ); // eliding error handling +// contents = rest; +// } +// this.flush(); +// // Wait for completion of `flush` +// pollable.block(); +// // Check for any errors that arose during `flush` +// let _ = this.check-write(); // eliding error handling +// +// blocking-write-and-flush: func(contents: list) -> result<_, stream-error> +// +//go:nosplit +func (self OutputStream) BlockingWriteAndFlush(contents cm.List[uint8]) (result cm.Result[StreamError, struct{}, StreamError]) { + self0 := cm.Reinterpret[uint32](self) + contents0, contents1 := cm.LowerList(contents) + wasmimport_OutputStreamBlockingWriteAndFlush((uint32)(self0), (*uint8)(contents0), (uint32)(contents1), &result) + return +} + +//go:wasmimport wasi:io/streams@0.2.1 [method]output-stream.blocking-write-and-flush +//go:noescape +func wasmimport_OutputStreamBlockingWriteAndFlush(self0 uint32, contents0 *uint8, contents1 uint32, result *cm.Result[StreamError, struct{}, StreamError]) + +// BlockingWriteZeroesAndFlush represents the imported method "blocking-write-zeroes-and-flush". +// +// Perform a write of up to 4096 zeroes, and then flush the stream. +// Block until all of these operations are complete, or an error +// occurs. +// +// This is a convenience wrapper around the use of `check-write`, +// `subscribe`, `write-zeroes`, and `flush`, and is implemented with +// the following pseudo-code: +// +// let pollable = this.subscribe(); +// while num_zeroes != 0 { +// // Wait for the stream to become writable +// pollable.block(); +// let Ok(n) = this.check-write(); // eliding error handling +// let len = min(n, num_zeroes); +// this.write-zeroes(len); // eliding error handling +// num_zeroes -= len; +// } +// this.flush(); +// // Wait for completion of `flush` +// pollable.block(); +// // Check for any errors that arose during `flush` +// let _ = this.check-write(); // eliding error handling +// +// blocking-write-zeroes-and-flush: func(len: u64) -> result<_, stream-error> +// +//go:nosplit +func (self OutputStream) BlockingWriteZeroesAndFlush(len_ uint64) (result cm.Result[StreamError, struct{}, StreamError]) { + self0 := cm.Reinterpret[uint32](self) + len0 := (uint64)(len_) + wasmimport_OutputStreamBlockingWriteZeroesAndFlush((uint32)(self0), (uint64)(len0), &result) + return +} + +//go:wasmimport wasi:io/streams@0.2.1 [method]output-stream.blocking-write-zeroes-and-flush +//go:noescape +func wasmimport_OutputStreamBlockingWriteZeroesAndFlush(self0 uint32, len0 uint64, result *cm.Result[StreamError, struct{}, StreamError]) + +// CheckWrite represents the imported method "check-write". +// +// Check readiness for writing. This function never blocks. +// +// Returns the number of bytes permitted for the next call to `write`, +// or an error. Calling `write` with more bytes than this function has +// permitted will trap. +// +// When this function returns 0 bytes, the `subscribe` pollable will +// become ready when this function will report at least 1 byte, or an +// error. +// +// check-write: func() -> result +// +//go:nosplit +func (self OutputStream) CheckWrite() (result cm.Result[uint64, uint64, StreamError]) { + self0 := cm.Reinterpret[uint32](self) + wasmimport_OutputStreamCheckWrite((uint32)(self0), &result) + return +} + +//go:wasmimport wasi:io/streams@0.2.1 [method]output-stream.check-write +//go:noescape +func wasmimport_OutputStreamCheckWrite(self0 uint32, result *cm.Result[uint64, uint64, StreamError]) + +// Flush represents the imported method "flush". +// +// Request to flush buffered output. This function never blocks. +// +// This tells the output-stream that the caller intends any buffered +// output to be flushed. the output which is expected to be flushed +// is all that has been passed to `write` prior to this call. +// +// Upon calling this function, the `output-stream` will not accept any +// writes (`check-write` will return `ok(0)`) until the flush has +// completed. The `subscribe` pollable will become ready when the +// flush has completed and the stream can accept more writes. +// +// flush: func() -> result<_, stream-error> +// +//go:nosplit +func (self OutputStream) Flush() (result cm.Result[StreamError, struct{}, StreamError]) { + self0 := cm.Reinterpret[uint32](self) + wasmimport_OutputStreamFlush((uint32)(self0), &result) + return +} + +//go:wasmimport wasi:io/streams@0.2.1 [method]output-stream.flush +//go:noescape +func wasmimport_OutputStreamFlush(self0 uint32, result *cm.Result[StreamError, struct{}, StreamError]) + +// Splice represents the imported method "splice". +// +// Read from one stream and write to another. +// +// The behavior of splice is equivalent to: +// 1. calling `check-write` on the `output-stream` +// 2. calling `read` on the `input-stream` with the smaller of the +// `check-write` permitted length and the `len` provided to `splice` +// 3. calling `write` on the `output-stream` with that read data. +// +// Any error reported by the call to `check-write`, `read`, or +// `write` ends the splice and reports that error. +// +// This function returns the number of bytes transferred; it may be less +// than `len`. +// +// splice: func(src: borrow, len: u64) -> result +// +//go:nosplit +func (self OutputStream) Splice(src InputStream, len_ uint64) (result cm.Result[uint64, uint64, StreamError]) { + self0 := cm.Reinterpret[uint32](self) + src0 := cm.Reinterpret[uint32](src) + len0 := (uint64)(len_) + wasmimport_OutputStreamSplice((uint32)(self0), (uint32)(src0), (uint64)(len0), &result) + return +} + +//go:wasmimport wasi:io/streams@0.2.1 [method]output-stream.splice +//go:noescape +func wasmimport_OutputStreamSplice(self0 uint32, src0 uint32, len0 uint64, result *cm.Result[uint64, uint64, StreamError]) + +// Subscribe represents the imported method "subscribe". +// +// Create a `pollable` which will resolve once the output-stream +// is ready for more writing, or an error has occurred. When this +// pollable is ready, `check-write` will return `ok(n)` with n>0, or an +// error. +// +// If the stream is closed, this pollable is always ready immediately. +// +// The created `pollable` is a child resource of the `output-stream`. +// Implementations may trap if the `output-stream` is dropped before +// all derived `pollable`s created with this function are dropped. +// +// subscribe: func() -> pollable +// +//go:nosplit +func (self OutputStream) Subscribe() (result poll.Pollable) { + self0 := cm.Reinterpret[uint32](self) + result0 := wasmimport_OutputStreamSubscribe((uint32)(self0)) + result = cm.Reinterpret[poll.Pollable]((uint32)(result0)) + return +} + +//go:wasmimport wasi:io/streams@0.2.1 [method]output-stream.subscribe +//go:noescape +func wasmimport_OutputStreamSubscribe(self0 uint32) (result0 uint32) + +// Write represents the imported method "write". +// +// Perform a write. This function never blocks. +// +// When the destination of a `write` is binary data, the bytes from +// `contents` are written verbatim. When the destination of a `write` is +// known to the implementation to be text, the bytes of `contents` are +// transcoded from UTF-8 into the encoding of the destination and then +// written. +// +// Precondition: check-write gave permit of Ok(n) and contents has a +// length of less than or equal to n. Otherwise, this function will trap. +// +// returns Err(closed) without writing if the stream has closed since +// the last call to check-write provided a permit. +// +// write: func(contents: list) -> result<_, stream-error> +// +//go:nosplit +func (self OutputStream) Write(contents cm.List[uint8]) (result cm.Result[StreamError, struct{}, StreamError]) { + self0 := cm.Reinterpret[uint32](self) + contents0, contents1 := cm.LowerList(contents) + wasmimport_OutputStreamWrite((uint32)(self0), (*uint8)(contents0), (uint32)(contents1), &result) + return +} + +//go:wasmimport wasi:io/streams@0.2.1 [method]output-stream.write +//go:noescape +func wasmimport_OutputStreamWrite(self0 uint32, contents0 *uint8, contents1 uint32, result *cm.Result[StreamError, struct{}, StreamError]) + +// WriteZeroes represents the imported method "write-zeroes". +// +// Write zeroes to a stream. +// +// This should be used precisely like `write` with the exact same +// preconditions (must use check-write first), but instead of +// passing a list of bytes, you simply pass the number of zero-bytes +// that should be written. +// +// write-zeroes: func(len: u64) -> result<_, stream-error> +// +//go:nosplit +func (self OutputStream) WriteZeroes(len_ uint64) (result cm.Result[StreamError, struct{}, StreamError]) { + self0 := cm.Reinterpret[uint32](self) + len0 := (uint64)(len_) + wasmimport_OutputStreamWriteZeroes((uint32)(self0), (uint64)(len0), &result) + return +} + +//go:wasmimport wasi:io/streams@0.2.1 [method]output-stream.write-zeroes +//go:noescape +func wasmimport_OutputStreamWriteZeroes(self0 uint32, len0 uint64, result *cm.Result[StreamError, struct{}, StreamError]) diff --git a/examples/go/http/bindings/wasi/random/insecure-seed/empty.s b/examples/go/http/bindings/wasi/random/insecure-seed/empty.s new file mode 100644 index 0000000..5444f20 --- /dev/null +++ b/examples/go/http/bindings/wasi/random/insecure-seed/empty.s @@ -0,0 +1,3 @@ +// This file exists for testing this package without WebAssembly, +// allowing empty function bodies with a //go:wasmimport directive. +// See https://pkg.go.dev/cmd/compile for more information. diff --git a/examples/go/http/bindings/wasi/random/insecure-seed/insecure-seed.wit.go b/examples/go/http/bindings/wasi/random/insecure-seed/insecure-seed.wit.go new file mode 100644 index 0000000..fa25a3b --- /dev/null +++ b/examples/go/http/bindings/wasi/random/insecure-seed/insecure-seed.wit.go @@ -0,0 +1,41 @@ +// Code generated by wit-bindgen-go. DO NOT EDIT. + +// Package insecureseed represents the imported interface "wasi:random/insecure-seed@0.2.1". +// +// The insecure-seed interface for seeding hash-map DoS resistance. +// +// It is intended to be portable at least between Unix-family platforms and +// Windows. +package insecureseed + +// InsecureSeed represents the imported function "insecure-seed". +// +// Return a 128-bit value that may contain a pseudo-random value. +// +// The returned value is not required to be computed from a CSPRNG, and may +// even be entirely deterministic. Host implementations are encouraged to +// provide pseudo-random values to any program exposed to +// attacker-controlled content, to enable DoS protection built into many +// languages' hash-map implementations. +// +// This function is intended to only be called once, by a source language +// to initialize Denial Of Service (DoS) protection in its hash-map +// implementation. +// +// # Expected future evolution +// +// This will likely be changed to a value import, to prevent it from being +// called multiple times and potentially used for purposes other than DoS +// protection. +// +// insecure-seed: func() -> tuple +// +//go:nosplit +func InsecureSeed() (result [2]uint64) { + wasmimport_InsecureSeed(&result) + return +} + +//go:wasmimport wasi:random/insecure-seed@0.2.1 insecure-seed +//go:noescape +func wasmimport_InsecureSeed(result *[2]uint64) diff --git a/examples/go/http/bindings/wasi/random/insecure/empty.s b/examples/go/http/bindings/wasi/random/insecure/empty.s new file mode 100644 index 0000000..5444f20 --- /dev/null +++ b/examples/go/http/bindings/wasi/random/insecure/empty.s @@ -0,0 +1,3 @@ +// This file exists for testing this package without WebAssembly, +// allowing empty function bodies with a //go:wasmimport directive. +// See https://pkg.go.dev/cmd/compile for more information. diff --git a/examples/go/http/bindings/wasi/random/insecure/insecure.wit.go b/examples/go/http/bindings/wasi/random/insecure/insecure.wit.go new file mode 100644 index 0000000..6235f33 --- /dev/null +++ b/examples/go/http/bindings/wasi/random/insecure/insecure.wit.go @@ -0,0 +1,57 @@ +// Code generated by wit-bindgen-go. DO NOT EDIT. + +// Package insecure represents the imported interface "wasi:random/insecure@0.2.1". +// +// The insecure interface for insecure pseudo-random numbers. +// +// It is intended to be portable at least between Unix-family platforms and +// Windows. +package insecure + +import ( + "github.com/bytecodealliance/wasm-tools-go/cm" +) + +// GetInsecureRandomBytes represents the imported function "get-insecure-random-bytes". +// +// Return `len` insecure pseudo-random bytes. +// +// This function is not cryptographically secure. Do not use it for +// anything related to security. +// +// There are no requirements on the values of the returned bytes, however +// implementations are encouraged to return evenly distributed values with +// a long period. +// +// get-insecure-random-bytes: func(len: u64) -> list +// +//go:nosplit +func GetInsecureRandomBytes(len_ uint64) (result cm.List[uint8]) { + len0 := (uint64)(len_) + wasmimport_GetInsecureRandomBytes((uint64)(len0), &result) + return +} + +//go:wasmimport wasi:random/insecure@0.2.1 get-insecure-random-bytes +//go:noescape +func wasmimport_GetInsecureRandomBytes(len0 uint64, result *cm.List[uint8]) + +// GetInsecureRandomU64 represents the imported function "get-insecure-random-u64". +// +// Return an insecure pseudo-random `u64` value. +// +// This function returns the same type of pseudo-random data as +// `get-insecure-random-bytes`, represented as a `u64`. +// +// get-insecure-random-u64: func() -> u64 +// +//go:nosplit +func GetInsecureRandomU64() (result uint64) { + result0 := wasmimport_GetInsecureRandomU64() + result = (uint64)((uint64)(result0)) + return +} + +//go:wasmimport wasi:random/insecure@0.2.1 get-insecure-random-u64 +//go:noescape +func wasmimport_GetInsecureRandomU64() (result0 uint64) diff --git a/examples/go/http/bindings/wasi/random/random/empty.s b/examples/go/http/bindings/wasi/random/random/empty.s new file mode 100644 index 0000000..5444f20 --- /dev/null +++ b/examples/go/http/bindings/wasi/random/random/empty.s @@ -0,0 +1,3 @@ +// This file exists for testing this package without WebAssembly, +// allowing empty function bodies with a //go:wasmimport directive. +// See https://pkg.go.dev/cmd/compile for more information. diff --git a/examples/go/http/bindings/wasi/random/random/random.wit.go b/examples/go/http/bindings/wasi/random/random/random.wit.go new file mode 100644 index 0000000..fbdbdb2 --- /dev/null +++ b/examples/go/http/bindings/wasi/random/random/random.wit.go @@ -0,0 +1,61 @@ +// Code generated by wit-bindgen-go. DO NOT EDIT. + +// Package random represents the imported interface "wasi:random/random@0.2.1". +// +// WASI Random is a random data API. +// +// It is intended to be portable at least between Unix-family platforms and +// Windows. +package random + +import ( + "github.com/bytecodealliance/wasm-tools-go/cm" +) + +// GetRandomBytes represents the imported function "get-random-bytes". +// +// Return `len` cryptographically-secure random or pseudo-random bytes. +// +// This function must produce data at least as cryptographically secure and +// fast as an adequately seeded cryptographically-secure pseudo-random +// number generator (CSPRNG). It must not block, from the perspective of +// the calling program, under any circumstances, including on the first +// request and on requests for numbers of bytes. The returned data must +// always be unpredictable. +// +// This function must always return fresh data. Deterministic environments +// must omit this function, rather than implementing it with deterministic +// data. +// +// get-random-bytes: func(len: u64) -> list +// +//go:nosplit +func GetRandomBytes(len_ uint64) (result cm.List[uint8]) { + len0 := (uint64)(len_) + wasmimport_GetRandomBytes((uint64)(len0), &result) + return +} + +//go:wasmimport wasi:random/random@0.2.1 get-random-bytes +//go:noescape +func wasmimport_GetRandomBytes(len0 uint64, result *cm.List[uint8]) + +// GetRandomU64 represents the imported function "get-random-u64". +// +// Return a cryptographically-secure random or pseudo-random `u64` value. +// +// This function returns the same type of data as `get-random-bytes`, +// represented as a `u64`. +// +// get-random-u64: func() -> u64 +// +//go:nosplit +func GetRandomU64() (result uint64) { + result0 := wasmimport_GetRandomU64() + result = (uint64)((uint64)(result0)) + return +} + +//go:wasmimport wasi:random/random@0.2.1 get-random-u64 +//go:noescape +func wasmimport_GetRandomU64() (result0 uint64) diff --git a/examples/go/http/bindings/wasi/sockets/instance-network/empty.s b/examples/go/http/bindings/wasi/sockets/instance-network/empty.s new file mode 100644 index 0000000..5444f20 --- /dev/null +++ b/examples/go/http/bindings/wasi/sockets/instance-network/empty.s @@ -0,0 +1,3 @@ +// This file exists for testing this package without WebAssembly, +// allowing empty function bodies with a //go:wasmimport directive. +// See https://pkg.go.dev/cmd/compile for more information. diff --git a/examples/go/http/bindings/wasi/sockets/instance-network/instance-network.wit.go b/examples/go/http/bindings/wasi/sockets/instance-network/instance-network.wit.go new file mode 100644 index 0000000..14cc872 --- /dev/null +++ b/examples/go/http/bindings/wasi/sockets/instance-network/instance-network.wit.go @@ -0,0 +1,28 @@ +// Code generated by wit-bindgen-go. DO NOT EDIT. + +// Package instancenetwork represents the imported interface "wasi:sockets/instance-network@0.2.1". +// +// This interface provides a value-export of the default network handle.. +package instancenetwork + +import ( + "github.com/bytecodealliance/wasm-tools-go/cm" + "github.com/rvolosatovs/west/examples/go/http/bindings/wasi/sockets/network" +) + +// InstanceNetwork represents the imported function "instance-network". +// +// Get a handle to the default network. +// +// instance-network: func() -> network +// +//go:nosplit +func InstanceNetwork() (result network.Network) { + result0 := wasmimport_InstanceNetwork() + result = cm.Reinterpret[network.Network]((uint32)(result0)) + return +} + +//go:wasmimport wasi:sockets/instance-network@0.2.1 instance-network +//go:noescape +func wasmimport_InstanceNetwork() (result0 uint32) diff --git a/examples/go/http/bindings/wasi/sockets/ip-name-lookup/abi.go b/examples/go/http/bindings/wasi/sockets/ip-name-lookup/abi.go new file mode 100644 index 0000000..b95c16d --- /dev/null +++ b/examples/go/http/bindings/wasi/sockets/ip-name-lookup/abi.go @@ -0,0 +1,14 @@ +// Code generated by wit-bindgen-go. DO NOT EDIT. + +package ipnamelookup + +import ( + "github.com/bytecodealliance/wasm-tools-go/cm" + "github.com/rvolosatovs/west/examples/go/http/bindings/wasi/sockets/network" + "unsafe" +) + +// OptionIPAddressShape is used for storage in variant or result types. +type OptionIPAddressShape struct { + shape [unsafe.Sizeof(cm.Option[network.IPAddress]{})]byte +} diff --git a/examples/go/http/bindings/wasi/sockets/ip-name-lookup/empty.s b/examples/go/http/bindings/wasi/sockets/ip-name-lookup/empty.s new file mode 100644 index 0000000..5444f20 --- /dev/null +++ b/examples/go/http/bindings/wasi/sockets/ip-name-lookup/empty.s @@ -0,0 +1,3 @@ +// This file exists for testing this package without WebAssembly, +// allowing empty function bodies with a //go:wasmimport directive. +// See https://pkg.go.dev/cmd/compile for more information. diff --git a/examples/go/http/bindings/wasi/sockets/ip-name-lookup/ip-name-lookup.wit.go b/examples/go/http/bindings/wasi/sockets/ip-name-lookup/ip-name-lookup.wit.go new file mode 100644 index 0000000..b949cda --- /dev/null +++ b/examples/go/http/bindings/wasi/sockets/ip-name-lookup/ip-name-lookup.wit.go @@ -0,0 +1,121 @@ +// Code generated by wit-bindgen-go. DO NOT EDIT. + +// Package ipnamelookup represents the imported interface "wasi:sockets/ip-name-lookup@0.2.1". +package ipnamelookup + +import ( + "github.com/bytecodealliance/wasm-tools-go/cm" + "github.com/rvolosatovs/west/examples/go/http/bindings/wasi/io/poll" + "github.com/rvolosatovs/west/examples/go/http/bindings/wasi/sockets/network" +) + +// ResolveAddressStream represents the imported resource "wasi:sockets/ip-name-lookup@0.2.1#resolve-address-stream". +// +// resource resolve-address-stream +type ResolveAddressStream cm.Resource + +// ResourceDrop represents the imported resource-drop for resource "resolve-address-stream". +// +// Drops a resource handle. +// +//go:nosplit +func (self ResolveAddressStream) ResourceDrop() { + self0 := cm.Reinterpret[uint32](self) + wasmimport_ResolveAddressStreamResourceDrop((uint32)(self0)) + return +} + +//go:wasmimport wasi:sockets/ip-name-lookup@0.2.1 [resource-drop]resolve-address-stream +//go:noescape +func wasmimport_ResolveAddressStreamResourceDrop(self0 uint32) + +// ResolveNextAddress represents the imported method "resolve-next-address". +// +// Returns the next address from the resolver. +// +// This function should be called multiple times. On each call, it will +// return the next address in connection order preference. If all +// addresses have been exhausted, this function returns `none`. +// +// This function never returns IPv4-mapped IPv6 addresses. +// +// # Typical errors +// - `name-unresolvable`: Name does not exist or has no suitable associated +// IP addresses. (EAI_NONAME, EAI_NODATA, EAI_ADDRFAMILY) +// - `temporary-resolver-failure`: A temporary failure in name resolution occurred. +// (EAI_AGAIN) +// - `permanent-resolver-failure`: A permanent failure in name resolution occurred. +// (EAI_FAIL) +// - `would-block`: A result is not available yet. (EWOULDBLOCK, EAGAIN) +// +// resolve-next-address: func() -> result, error-code> +// +//go:nosplit +func (self ResolveAddressStream) ResolveNextAddress() (result cm.Result[OptionIPAddressShape, cm.Option[network.IPAddress], network.ErrorCode]) { + self0 := cm.Reinterpret[uint32](self) + wasmimport_ResolveAddressStreamResolveNextAddress((uint32)(self0), &result) + return +} + +//go:wasmimport wasi:sockets/ip-name-lookup@0.2.1 [method]resolve-address-stream.resolve-next-address +//go:noescape +func wasmimport_ResolveAddressStreamResolveNextAddress(self0 uint32, result *cm.Result[OptionIPAddressShape, cm.Option[network.IPAddress], network.ErrorCode]) + +// Subscribe represents the imported method "subscribe". +// +// Create a `pollable` which will resolve once the stream is ready for I/O. +// +// Note: this function is here for WASI Preview2 only. +// It's planned to be removed when `future` is natively supported in Preview3. +// +// subscribe: func() -> pollable +// +//go:nosplit +func (self ResolveAddressStream) Subscribe() (result poll.Pollable) { + self0 := cm.Reinterpret[uint32](self) + result0 := wasmimport_ResolveAddressStreamSubscribe((uint32)(self0)) + result = cm.Reinterpret[poll.Pollable]((uint32)(result0)) + return +} + +//go:wasmimport wasi:sockets/ip-name-lookup@0.2.1 [method]resolve-address-stream.subscribe +//go:noescape +func wasmimport_ResolveAddressStreamSubscribe(self0 uint32) (result0 uint32) + +// ResolveAddresses represents the imported function "resolve-addresses". +// +// Resolve an internet host name to a list of IP addresses. +// +// Unicode domain names are automatically converted to ASCII using IDNA encoding. +// If the input is an IP address string, the address is parsed and returned +// as-is without making any external requests. +// +// See the wasi-socket proposal README.md for a comparison with getaddrinfo. +// +// This function never blocks. It either immediately fails or immediately +// returns successfully with a `resolve-address-stream` that can be used +// to (asynchronously) fetch the results. +// +// # Typical errors +// - `invalid-argument`: `name` is a syntactically invalid domain name or IP address. +// +// # References: +// - +// - +// - +// - +// +// resolve-addresses: func(network: borrow, name: string) -> result +// +//go:nosplit +func ResolveAddresses(network_ network.Network, name string) (result cm.Result[ResolveAddressStream, ResolveAddressStream, network.ErrorCode]) { + network0 := cm.Reinterpret[uint32](network_) + name0, name1 := cm.LowerString(name) + wasmimport_ResolveAddresses((uint32)(network0), (*uint8)(name0), (uint32)(name1), &result) + return +} + +//go:wasmimport wasi:sockets/ip-name-lookup@0.2.1 resolve-addresses +//go:noescape +func wasmimport_ResolveAddresses(network0 uint32, name0 *uint8, name1 uint32, result *cm.Result[ResolveAddressStream, ResolveAddressStream, network.ErrorCode]) diff --git a/examples/go/http/bindings/wasi/sockets/network/abi.go b/examples/go/http/bindings/wasi/sockets/network/abi.go new file mode 100644 index 0000000..54820be --- /dev/null +++ b/examples/go/http/bindings/wasi/sockets/network/abi.go @@ -0,0 +1,12 @@ +// Code generated by wit-bindgen-go. DO NOT EDIT. + +package network + +import ( + "unsafe" +) + +// IPv6SocketAddressShape is used for storage in variant or result types. +type IPv6SocketAddressShape struct { + shape [unsafe.Sizeof(IPv6SocketAddress{})]byte +} diff --git a/examples/go/http/bindings/wasi/sockets/network/empty.s b/examples/go/http/bindings/wasi/sockets/network/empty.s new file mode 100644 index 0000000..5444f20 --- /dev/null +++ b/examples/go/http/bindings/wasi/sockets/network/empty.s @@ -0,0 +1,3 @@ +// This file exists for testing this package without WebAssembly, +// allowing empty function bodies with a //go:wasmimport directive. +// See https://pkg.go.dev/cmd/compile for more information. diff --git a/examples/go/http/bindings/wasi/sockets/network/network.wit.go b/examples/go/http/bindings/wasi/sockets/network/network.wit.go new file mode 100644 index 0000000..7d55115 --- /dev/null +++ b/examples/go/http/bindings/wasi/sockets/network/network.wit.go @@ -0,0 +1,315 @@ +// Code generated by wit-bindgen-go. DO NOT EDIT. + +// Package network represents the imported interface "wasi:sockets/network@0.2.1". +package network + +import ( + "github.com/bytecodealliance/wasm-tools-go/cm" +) + +// Network represents the imported resource "wasi:sockets/network@0.2.1#network". +// +// An opaque resource that represents access to (a subset of) the network. +// This enables context-based security for networking. +// There is no need for this to map 1:1 to a physical network interface. +// +// resource network +type Network cm.Resource + +// ResourceDrop represents the imported resource-drop for resource "network". +// +// Drops a resource handle. +// +//go:nosplit +func (self Network) ResourceDrop() { + self0 := cm.Reinterpret[uint32](self) + wasmimport_NetworkResourceDrop((uint32)(self0)) + return +} + +//go:wasmimport wasi:sockets/network@0.2.1 [resource-drop]network +//go:noescape +func wasmimport_NetworkResourceDrop(self0 uint32) + +// ErrorCode represents the enum "wasi:sockets/network@0.2.1#error-code". +// +// Error codes. +// +// In theory, every API can return any error code. +// In practice, API's typically only return the errors documented per API +// combined with a couple of errors that are always possible: +// - `unknown` +// - `access-denied` +// - `not-supported` +// - `out-of-memory` +// - `concurrency-conflict` +// +// See each individual API for what the POSIX equivalents are. They sometimes differ +// per API. +// +// enum error-code { +// unknown, +// access-denied, +// not-supported, +// invalid-argument, +// out-of-memory, +// timeout, +// concurrency-conflict, +// not-in-progress, +// would-block, +// invalid-state, +// new-socket-limit, +// address-not-bindable, +// address-in-use, +// remote-unreachable, +// connection-refused, +// connection-reset, +// connection-aborted, +// datagram-too-large, +// name-unresolvable, +// temporary-resolver-failure, +// permanent-resolver-failure +// } +type ErrorCode uint8 + +const ( + // Unknown error + ErrorCodeUnknown ErrorCode = iota + + // Access denied. + // + // POSIX equivalent: EACCES, EPERM + ErrorCodeAccessDenied + + // The operation is not supported. + // + // POSIX equivalent: EOPNOTSUPP + ErrorCodeNotSupported + + // One of the arguments is invalid. + // + // POSIX equivalent: EINVAL + ErrorCodeInvalidArgument + + // Not enough memory to complete the operation. + // + // POSIX equivalent: ENOMEM, ENOBUFS, EAI_MEMORY + ErrorCodeOutOfMemory + + // The operation timed out before it could finish completely. + ErrorCodeTimeout + + // This operation is incompatible with another asynchronous operation that is already + // in progress. + // + // POSIX equivalent: EALREADY + ErrorCodeConcurrencyConflict + + // Trying to finish an asynchronous operation that: + // - has not been started yet, or: + // - was already finished by a previous `finish-*` call. + // + // Note: this is scheduled to be removed when `future`s are natively supported. + ErrorCodeNotInProgress + + // The operation has been aborted because it could not be completed immediately. + // + // Note: this is scheduled to be removed when `future`s are natively supported. + ErrorCodeWouldBlock + + // The operation is not valid in the socket's current state. + ErrorCodeInvalidState + + // A new socket resource could not be created because of a system limit. + ErrorCodeNewSocketLimit + + // A bind operation failed because the provided address is not an address that the + // `network` can bind to. + ErrorCodeAddressNotBindable + + // A bind operation failed because the provided address is already in use or because + // there are no ephemeral ports available. + ErrorCodeAddressInUse + + // The remote address is not reachable + ErrorCodeRemoteUnreachable + + // The TCP connection was forcefully rejected + ErrorCodeConnectionRefused + + // The TCP connection was reset. + ErrorCodeConnectionReset + + // A TCP connection was aborted. + ErrorCodeConnectionAborted + + // The size of a datagram sent to a UDP socket exceeded the maximum + // supported size. + ErrorCodeDatagramTooLarge + + // Name does not exist or has no suitable associated IP addresses. + ErrorCodeNameUnresolvable + + // A temporary failure in name resolution occurred. + ErrorCodeTemporaryResolverFailure + + // A permanent failure in name resolution occurred. + ErrorCodePermanentResolverFailure +) + +var stringsErrorCode = [21]string{ + "unknown", + "access-denied", + "not-supported", + "invalid-argument", + "out-of-memory", + "timeout", + "concurrency-conflict", + "not-in-progress", + "would-block", + "invalid-state", + "new-socket-limit", + "address-not-bindable", + "address-in-use", + "remote-unreachable", + "connection-refused", + "connection-reset", + "connection-aborted", + "datagram-too-large", + "name-unresolvable", + "temporary-resolver-failure", + "permanent-resolver-failure", +} + +// String implements [fmt.Stringer], returning the enum case name of e. +func (e ErrorCode) String() string { + return stringsErrorCode[e] +} + +// IPAddressFamily represents the enum "wasi:sockets/network@0.2.1#ip-address-family". +// +// enum ip-address-family { +// ipv4, +// ipv6 +// } +type IPAddressFamily uint8 + +const ( + // Similar to `AF_INET` in POSIX. + IPAddressFamilyIPv4 IPAddressFamily = iota + + // Similar to `AF_INET6` in POSIX. + IPAddressFamilyIPv6 +) + +var stringsIPAddressFamily = [2]string{ + "ipv4", + "ipv6", +} + +// String implements [fmt.Stringer], returning the enum case name of e. +func (e IPAddressFamily) String() string { + return stringsIPAddressFamily[e] +} + +// IPv4Address represents the tuple "wasi:sockets/network@0.2.1#ipv4-address". +// +// type ipv4-address = tuple +type IPv4Address [4]uint8 + +// IPv6Address represents the tuple "wasi:sockets/network@0.2.1#ipv6-address". +// +// type ipv6-address = tuple +type IPv6Address [8]uint16 + +// IPAddress represents the variant "wasi:sockets/network@0.2.1#ip-address". +// +// variant ip-address { +// ipv4(ipv4-address), +// ipv6(ipv6-address), +// } +type IPAddress cm.Variant[uint8, IPv6Address, IPv6Address] + +// IPAddressIPv4 returns a [IPAddress] of case "ipv4". +func IPAddressIPv4(data IPv4Address) IPAddress { + return cm.New[IPAddress](0, data) +} + +// IPv4 returns a non-nil *[IPv4Address] if [IPAddress] represents the variant case "ipv4". +func (self *IPAddress) IPv4() *IPv4Address { + return cm.Case[IPv4Address](self, 0) +} + +// IPAddressIPv6 returns a [IPAddress] of case "ipv6". +func IPAddressIPv6(data IPv6Address) IPAddress { + return cm.New[IPAddress](1, data) +} + +// IPv6 returns a non-nil *[IPv6Address] if [IPAddress] represents the variant case "ipv6". +func (self *IPAddress) IPv6() *IPv6Address { + return cm.Case[IPv6Address](self, 1) +} + +// IPv4SocketAddress represents the record "wasi:sockets/network@0.2.1#ipv4-socket-address". +// +// record ipv4-socket-address { +// port: u16, +// address: ipv4-address, +// } +type IPv4SocketAddress struct { + // sin_port + Port uint16 + + // sin_addr + Address IPv4Address +} + +// IPv6SocketAddress represents the record "wasi:sockets/network@0.2.1#ipv6-socket-address". +// +// record ipv6-socket-address { +// port: u16, +// flow-info: u32, +// address: ipv6-address, +// scope-id: u32, +// } +type IPv6SocketAddress struct { + // sin6_port + Port uint16 + + // sin6_flowinfo + FlowInfo uint32 + + // sin6_addr + Address IPv6Address + + // sin6_scope_id + ScopeID uint32 +} + +// IPSocketAddress represents the variant "wasi:sockets/network@0.2.1#ip-socket-address". +// +// variant ip-socket-address { +// ipv4(ipv4-socket-address), +// ipv6(ipv6-socket-address), +// } +type IPSocketAddress cm.Variant[uint8, IPv6SocketAddressShape, IPv6SocketAddress] + +// IPSocketAddressIPv4 returns a [IPSocketAddress] of case "ipv4". +func IPSocketAddressIPv4(data IPv4SocketAddress) IPSocketAddress { + return cm.New[IPSocketAddress](0, data) +} + +// IPv4 returns a non-nil *[IPv4SocketAddress] if [IPSocketAddress] represents the variant case "ipv4". +func (self *IPSocketAddress) IPv4() *IPv4SocketAddress { + return cm.Case[IPv4SocketAddress](self, 0) +} + +// IPSocketAddressIPv6 returns a [IPSocketAddress] of case "ipv6". +func IPSocketAddressIPv6(data IPv6SocketAddress) IPSocketAddress { + return cm.New[IPSocketAddress](1, data) +} + +// IPv6 returns a non-nil *[IPv6SocketAddress] if [IPSocketAddress] represents the variant case "ipv6". +func (self *IPSocketAddress) IPv6() *IPv6SocketAddress { + return cm.Case[IPv6SocketAddress](self, 1) +} diff --git a/examples/go/http/bindings/wasi/sockets/tcp-create-socket/empty.s b/examples/go/http/bindings/wasi/sockets/tcp-create-socket/empty.s new file mode 100644 index 0000000..5444f20 --- /dev/null +++ b/examples/go/http/bindings/wasi/sockets/tcp-create-socket/empty.s @@ -0,0 +1,3 @@ +// This file exists for testing this package without WebAssembly, +// allowing empty function bodies with a //go:wasmimport directive. +// See https://pkg.go.dev/cmd/compile for more information. diff --git a/examples/go/http/bindings/wasi/sockets/tcp-create-socket/tcp-create-socket.wit.go b/examples/go/http/bindings/wasi/sockets/tcp-create-socket/tcp-create-socket.wit.go new file mode 100644 index 0000000..e724acc --- /dev/null +++ b/examples/go/http/bindings/wasi/sockets/tcp-create-socket/tcp-create-socket.wit.go @@ -0,0 +1,52 @@ +// Code generated by wit-bindgen-go. DO NOT EDIT. + +// Package tcpcreatesocket represents the imported interface "wasi:sockets/tcp-create-socket@0.2.1". +package tcpcreatesocket + +import ( + "github.com/bytecodealliance/wasm-tools-go/cm" + "github.com/rvolosatovs/west/examples/go/http/bindings/wasi/sockets/network" + "github.com/rvolosatovs/west/examples/go/http/bindings/wasi/sockets/tcp" +) + +// CreateTCPSocket represents the imported function "create-tcp-socket". +// +// Create a new TCP socket. +// +// Similar to `socket(AF_INET or AF_INET6, SOCK_STREAM, IPPROTO_TCP)` in POSIX. +// On IPv6 sockets, IPV6_V6ONLY is enabled by default and can't be configured otherwise. +// +// This function does not require a network capability handle. This is considered +// to be safe because +// at time of creation, the socket is not bound to any `network` yet. Up to the moment +// `bind`/`connect` +// is called, the socket is effectively an in-memory configuration object, unable +// to communicate with the outside world. +// +// All sockets are non-blocking. Use the wasi-poll interface to block on asynchronous +// operations. +// +// # Typical errors +// - `not-supported`: The specified `address-family` is not supported. (EAFNOSUPPORT) +// - `new-socket-limit`: The new socket resource could not be created because of +// a system limit. (EMFILE, ENFILE) +// +// # References +// - +// - +// - +// - +// +// create-tcp-socket: func(address-family: ip-address-family) -> result +// +//go:nosplit +func CreateTCPSocket(addressFamily network.IPAddressFamily) (result cm.Result[tcp.TCPSocket, tcp.TCPSocket, network.ErrorCode]) { + addressFamily0 := (uint32)(addressFamily) + wasmimport_CreateTCPSocket((uint32)(addressFamily0), &result) + return +} + +//go:wasmimport wasi:sockets/tcp-create-socket@0.2.1 create-tcp-socket +//go:noescape +func wasmimport_CreateTCPSocket(addressFamily0 uint32, result *cm.Result[tcp.TCPSocket, tcp.TCPSocket, network.ErrorCode]) diff --git a/examples/go/http/bindings/wasi/sockets/tcp/abi.go b/examples/go/http/bindings/wasi/sockets/tcp/abi.go new file mode 100644 index 0000000..56c6c9c --- /dev/null +++ b/examples/go/http/bindings/wasi/sockets/tcp/abi.go @@ -0,0 +1,86 @@ +// Code generated by wit-bindgen-go. DO NOT EDIT. + +package tcp + +import ( + "github.com/bytecodealliance/wasm-tools-go/cm" + "github.com/rvolosatovs/west/examples/go/http/bindings/wasi/io/streams" + "github.com/rvolosatovs/west/examples/go/http/bindings/wasi/sockets/network" + "unsafe" +) + +// TupleTCPSocketInputStreamOutputStreamShape is used for storage in variant or result types. +type TupleTCPSocketInputStreamOutputStreamShape struct { + shape [unsafe.Sizeof(cm.Tuple3[TCPSocket, streams.InputStream, streams.OutputStream]{})]byte +} + +// TupleInputStreamOutputStreamShape is used for storage in variant or result types. +type TupleInputStreamOutputStreamShape struct { + shape [unsafe.Sizeof(cm.Tuple[streams.InputStream, streams.OutputStream]{})]byte +} + +// IPSocketAddressShape is used for storage in variant or result types. +type IPSocketAddressShape struct { + shape [unsafe.Sizeof(network.IPSocketAddress{})]byte +} + +func lower_IPv4Address(v network.IPv4Address) (f0 uint32, f1 uint32, f2 uint32, f3 uint32) { + f0 = (uint32)(v[0]) + f1 = (uint32)(v[1]) + f2 = (uint32)(v[2]) + f3 = (uint32)(v[3]) + return +} + +func lower_IPv4SocketAddress(v network.IPv4SocketAddress) (f0 uint32, f1 uint32, f2 uint32, f3 uint32, f4 uint32) { + f0 = (uint32)(v.Port) + f1, f2, f3, f4 = lower_IPv4Address(v.Address) + return +} + +func lower_IPv6Address(v network.IPv6Address) (f0 uint32, f1 uint32, f2 uint32, f3 uint32, f4 uint32, f5 uint32, f6 uint32, f7 uint32) { + f0 = (uint32)(v[0]) + f1 = (uint32)(v[1]) + f2 = (uint32)(v[2]) + f3 = (uint32)(v[3]) + f4 = (uint32)(v[4]) + f5 = (uint32)(v[5]) + f6 = (uint32)(v[6]) + f7 = (uint32)(v[7]) + return +} + +func lower_IPv6SocketAddress(v network.IPv6SocketAddress) (f0 uint32, f1 uint32, f2 uint32, f3 uint32, f4 uint32, f5 uint32, f6 uint32, f7 uint32, f8 uint32, f9 uint32, f10 uint32) { + f0 = (uint32)(v.Port) + f1 = (uint32)(v.FlowInfo) + f2, f3, f4, f5, f6, f7, f8, f9 = lower_IPv6Address(v.Address) + f10 = (uint32)(v.ScopeID) + return +} + +func lower_IPSocketAddress(v network.IPSocketAddress) (f0 uint32, f1 uint32, f2 uint32, f3 uint32, f4 uint32, f5 uint32, f6 uint32, f7 uint32, f8 uint32, f9 uint32, f10 uint32, f11 uint32) { + f0 = (uint32)(v.Tag()) + switch f0 { + case 0: // ipv4 + v1, v2, v3, v4, v5 := lower_IPv4SocketAddress(*v.IPv4()) + f1 = (uint32)(v1) + f2 = (uint32)(v2) + f3 = (uint32)(v3) + f4 = (uint32)(v4) + f5 = (uint32)(v5) + case 1: // ipv6 + v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11 := lower_IPv6SocketAddress(*v.IPv6()) + f1 = (uint32)(v1) + f2 = (uint32)(v2) + f3 = (uint32)(v3) + f4 = (uint32)(v4) + f5 = (uint32)(v5) + f6 = (uint32)(v6) + f7 = (uint32)(v7) + f8 = (uint32)(v8) + f9 = (uint32)(v9) + f10 = (uint32)(v10) + f11 = (uint32)(v11) + } + return +} diff --git a/examples/go/http/bindings/wasi/sockets/tcp/empty.s b/examples/go/http/bindings/wasi/sockets/tcp/empty.s new file mode 100644 index 0000000..5444f20 --- /dev/null +++ b/examples/go/http/bindings/wasi/sockets/tcp/empty.s @@ -0,0 +1,3 @@ +// This file exists for testing this package without WebAssembly, +// allowing empty function bodies with a //go:wasmimport directive. +// See https://pkg.go.dev/cmd/compile for more information. diff --git a/examples/go/http/bindings/wasi/sockets/tcp/tcp.wit.go b/examples/go/http/bindings/wasi/sockets/tcp/tcp.wit.go new file mode 100644 index 0000000..aefead8 --- /dev/null +++ b/examples/go/http/bindings/wasi/sockets/tcp/tcp.wit.go @@ -0,0 +1,848 @@ +// Code generated by wit-bindgen-go. DO NOT EDIT. + +// Package tcp represents the imported interface "wasi:sockets/tcp@0.2.1". +package tcp + +import ( + "github.com/bytecodealliance/wasm-tools-go/cm" + monotonicclock "github.com/rvolosatovs/west/examples/go/http/bindings/wasi/clocks/monotonic-clock" + "github.com/rvolosatovs/west/examples/go/http/bindings/wasi/io/poll" + "github.com/rvolosatovs/west/examples/go/http/bindings/wasi/io/streams" + "github.com/rvolosatovs/west/examples/go/http/bindings/wasi/sockets/network" +) + +// ShutdownType represents the enum "wasi:sockets/tcp@0.2.1#shutdown-type". +// +// enum shutdown-type { +// receive, +// send, +// both +// } +type ShutdownType uint8 + +const ( + // Similar to `SHUT_RD` in POSIX. + ShutdownTypeReceive ShutdownType = iota + + // Similar to `SHUT_WR` in POSIX. + ShutdownTypeSend + + // Similar to `SHUT_RDWR` in POSIX. + ShutdownTypeBoth +) + +var stringsShutdownType = [3]string{ + "receive", + "send", + "both", +} + +// String implements [fmt.Stringer], returning the enum case name of e. +func (e ShutdownType) String() string { + return stringsShutdownType[e] +} + +// TCPSocket represents the imported resource "wasi:sockets/tcp@0.2.1#tcp-socket". +// +// A TCP socket resource. +// +// The socket can be in one of the following states: +// - `unbound` +// - `bind-in-progress` +// - `bound` (See note below) +// - `listen-in-progress` +// - `listening` +// - `connect-in-progress` +// - `connected` +// - `closed` +// See +// for more information. +// +// Note: Except where explicitly mentioned, whenever this documentation uses +// the term "bound" without backticks it actually means: in the `bound` state *or +// higher*. +// (i.e. `bound`, `listen-in-progress`, `listening`, `connect-in-progress` or `connected`) +// +// In addition to the general error codes documented on the +// `network::error-code` type, TCP socket methods may always return +// `error(invalid-state)` when in the `closed` state. +// +// resource tcp-socket +type TCPSocket cm.Resource + +// ResourceDrop represents the imported resource-drop for resource "tcp-socket". +// +// Drops a resource handle. +// +//go:nosplit +func (self TCPSocket) ResourceDrop() { + self0 := cm.Reinterpret[uint32](self) + wasmimport_TCPSocketResourceDrop((uint32)(self0)) + return +} + +//go:wasmimport wasi:sockets/tcp@0.2.1 [resource-drop]tcp-socket +//go:noescape +func wasmimport_TCPSocketResourceDrop(self0 uint32) + +// Accept represents the imported method "accept". +// +// Accept a new client socket. +// +// The returned socket is bound and in the `connected` state. The following properties +// are inherited from the listener socket: +// - `address-family` +// - `keep-alive-enabled` +// - `keep-alive-idle-time` +// - `keep-alive-interval` +// - `keep-alive-count` +// - `hop-limit` +// - `receive-buffer-size` +// - `send-buffer-size` +// +// On success, this function returns the newly accepted client socket along with +// a pair of streams that can be used to read & write to the connection. +// +// # Typical errors +// - `invalid-state`: Socket is not in the `listening` state. (EINVAL) +// - `would-block`: No pending connections at the moment. (EWOULDBLOCK, EAGAIN) +// - `connection-aborted`: An incoming connection was pending, but was terminated +// by the client before this listener could accept it. (ECONNABORTED) +// - `new-socket-limit`: The new socket resource could not be created because of +// a system limit. (EMFILE, ENFILE) +// +// # References +// - +// - +// - +// - +// +// accept: func() -> result, error-code> +// +//go:nosplit +func (self TCPSocket) Accept() (result cm.Result[TupleTCPSocketInputStreamOutputStreamShape, cm.Tuple3[TCPSocket, streams.InputStream, streams.OutputStream], network.ErrorCode]) { + self0 := cm.Reinterpret[uint32](self) + wasmimport_TCPSocketAccept((uint32)(self0), &result) + return +} + +//go:wasmimport wasi:sockets/tcp@0.2.1 [method]tcp-socket.accept +//go:noescape +func wasmimport_TCPSocketAccept(self0 uint32, result *cm.Result[TupleTCPSocketInputStreamOutputStreamShape, cm.Tuple3[TCPSocket, streams.InputStream, streams.OutputStream], network.ErrorCode]) + +// AddressFamily represents the imported method "address-family". +// +// Whether this is a IPv4 or IPv6 socket. +// +// Equivalent to the SO_DOMAIN socket option. +// +// address-family: func() -> ip-address-family +// +//go:nosplit +func (self TCPSocket) AddressFamily() (result network.IPAddressFamily) { + self0 := cm.Reinterpret[uint32](self) + result0 := wasmimport_TCPSocketAddressFamily((uint32)(self0)) + result = (network.IPAddressFamily)((uint32)(result0)) + return +} + +//go:wasmimport wasi:sockets/tcp@0.2.1 [method]tcp-socket.address-family +//go:noescape +func wasmimport_TCPSocketAddressFamily(self0 uint32) (result0 uint32) + +// FinishBind represents the imported method "finish-bind". +// +// finish-bind: func() -> result<_, error-code> +// +//go:nosplit +func (self TCPSocket) FinishBind() (result cm.Result[network.ErrorCode, struct{}, network.ErrorCode]) { + self0 := cm.Reinterpret[uint32](self) + wasmimport_TCPSocketFinishBind((uint32)(self0), &result) + return +} + +//go:wasmimport wasi:sockets/tcp@0.2.1 [method]tcp-socket.finish-bind +//go:noescape +func wasmimport_TCPSocketFinishBind(self0 uint32, result *cm.Result[network.ErrorCode, struct{}, network.ErrorCode]) + +// FinishConnect represents the imported method "finish-connect". +// +// finish-connect: func() -> result, error-code> +// +//go:nosplit +func (self TCPSocket) FinishConnect() (result cm.Result[TupleInputStreamOutputStreamShape, cm.Tuple[streams.InputStream, streams.OutputStream], network.ErrorCode]) { + self0 := cm.Reinterpret[uint32](self) + wasmimport_TCPSocketFinishConnect((uint32)(self0), &result) + return +} + +//go:wasmimport wasi:sockets/tcp@0.2.1 [method]tcp-socket.finish-connect +//go:noescape +func wasmimport_TCPSocketFinishConnect(self0 uint32, result *cm.Result[TupleInputStreamOutputStreamShape, cm.Tuple[streams.InputStream, streams.OutputStream], network.ErrorCode]) + +// FinishListen represents the imported method "finish-listen". +// +// finish-listen: func() -> result<_, error-code> +// +//go:nosplit +func (self TCPSocket) FinishListen() (result cm.Result[network.ErrorCode, struct{}, network.ErrorCode]) { + self0 := cm.Reinterpret[uint32](self) + wasmimport_TCPSocketFinishListen((uint32)(self0), &result) + return +} + +//go:wasmimport wasi:sockets/tcp@0.2.1 [method]tcp-socket.finish-listen +//go:noescape +func wasmimport_TCPSocketFinishListen(self0 uint32, result *cm.Result[network.ErrorCode, struct{}, network.ErrorCode]) + +// HopLimit represents the imported method "hop-limit". +// +// Equivalent to the IP_TTL & IPV6_UNICAST_HOPS socket options. +// +// If the provided value is 0, an `invalid-argument` error is returned. +// +// # Typical errors +// - `invalid-argument`: (set) The TTL value must be 1 or higher. +// +// hop-limit: func() -> result +// +//go:nosplit +func (self TCPSocket) HopLimit() (result cm.Result[uint8, uint8, network.ErrorCode]) { + self0 := cm.Reinterpret[uint32](self) + wasmimport_TCPSocketHopLimit((uint32)(self0), &result) + return +} + +//go:wasmimport wasi:sockets/tcp@0.2.1 [method]tcp-socket.hop-limit +//go:noescape +func wasmimport_TCPSocketHopLimit(self0 uint32, result *cm.Result[uint8, uint8, network.ErrorCode]) + +// IsListening represents the imported method "is-listening". +// +// Whether the socket is in the `listening` state. +// +// Equivalent to the SO_ACCEPTCONN socket option. +// +// is-listening: func() -> bool +// +//go:nosplit +func (self TCPSocket) IsListening() (result bool) { + self0 := cm.Reinterpret[uint32](self) + result0 := wasmimport_TCPSocketIsListening((uint32)(self0)) + result = cm.U32ToBool((uint32)(result0)) + return +} + +//go:wasmimport wasi:sockets/tcp@0.2.1 [method]tcp-socket.is-listening +//go:noescape +func wasmimport_TCPSocketIsListening(self0 uint32) (result0 uint32) + +// KeepAliveCount represents the imported method "keep-alive-count". +// +// The maximum amount of keepalive packets TCP should send before aborting the connection. +// +// If the provided value is 0, an `invalid-argument` error is returned. +// Any other value will never cause an error, but it might be silently clamped and/or +// rounded. +// I.e. after setting a value, reading the same setting back may return a different +// value. +// +// Equivalent to the TCP_KEEPCNT socket option. +// +// # Typical errors +// - `invalid-argument`: (set) The provided value was 0. +// +// keep-alive-count: func() -> result +// +//go:nosplit +func (self TCPSocket) KeepAliveCount() (result cm.Result[uint32, uint32, network.ErrorCode]) { + self0 := cm.Reinterpret[uint32](self) + wasmimport_TCPSocketKeepAliveCount((uint32)(self0), &result) + return +} + +//go:wasmimport wasi:sockets/tcp@0.2.1 [method]tcp-socket.keep-alive-count +//go:noescape +func wasmimport_TCPSocketKeepAliveCount(self0 uint32, result *cm.Result[uint32, uint32, network.ErrorCode]) + +// KeepAliveEnabled represents the imported method "keep-alive-enabled". +// +// Enables or disables keepalive. +// +// The keepalive behavior can be adjusted using: +// - `keep-alive-idle-time` +// - `keep-alive-interval` +// - `keep-alive-count` +// These properties can be configured while `keep-alive-enabled` is false, but only +// come into effect when `keep-alive-enabled` is true. +// +// Equivalent to the SO_KEEPALIVE socket option. +// +// keep-alive-enabled: func() -> result +// +//go:nosplit +func (self TCPSocket) KeepAliveEnabled() (result cm.Result[bool, bool, network.ErrorCode]) { + self0 := cm.Reinterpret[uint32](self) + wasmimport_TCPSocketKeepAliveEnabled((uint32)(self0), &result) + return +} + +//go:wasmimport wasi:sockets/tcp@0.2.1 [method]tcp-socket.keep-alive-enabled +//go:noescape +func wasmimport_TCPSocketKeepAliveEnabled(self0 uint32, result *cm.Result[bool, bool, network.ErrorCode]) + +// KeepAliveIdleTime represents the imported method "keep-alive-idle-time". +// +// Amount of time the connection has to be idle before TCP starts sending keepalive +// packets. +// +// If the provided value is 0, an `invalid-argument` error is returned. +// Any other value will never cause an error, but it might be silently clamped and/or +// rounded. +// I.e. after setting a value, reading the same setting back may return a different +// value. +// +// Equivalent to the TCP_KEEPIDLE socket option. (TCP_KEEPALIVE on MacOS) +// +// # Typical errors +// - `invalid-argument`: (set) The provided value was 0. +// +// keep-alive-idle-time: func() -> result +// +//go:nosplit +func (self TCPSocket) KeepAliveIdleTime() (result cm.Result[uint64, monotonicclock.Duration, network.ErrorCode]) { + self0 := cm.Reinterpret[uint32](self) + wasmimport_TCPSocketKeepAliveIdleTime((uint32)(self0), &result) + return +} + +//go:wasmimport wasi:sockets/tcp@0.2.1 [method]tcp-socket.keep-alive-idle-time +//go:noescape +func wasmimport_TCPSocketKeepAliveIdleTime(self0 uint32, result *cm.Result[uint64, monotonicclock.Duration, network.ErrorCode]) + +// KeepAliveInterval represents the imported method "keep-alive-interval". +// +// The time between keepalive packets. +// +// If the provided value is 0, an `invalid-argument` error is returned. +// Any other value will never cause an error, but it might be silently clamped and/or +// rounded. +// I.e. after setting a value, reading the same setting back may return a different +// value. +// +// Equivalent to the TCP_KEEPINTVL socket option. +// +// # Typical errors +// - `invalid-argument`: (set) The provided value was 0. +// +// keep-alive-interval: func() -> result +// +//go:nosplit +func (self TCPSocket) KeepAliveInterval() (result cm.Result[uint64, monotonicclock.Duration, network.ErrorCode]) { + self0 := cm.Reinterpret[uint32](self) + wasmimport_TCPSocketKeepAliveInterval((uint32)(self0), &result) + return +} + +//go:wasmimport wasi:sockets/tcp@0.2.1 [method]tcp-socket.keep-alive-interval +//go:noescape +func wasmimport_TCPSocketKeepAliveInterval(self0 uint32, result *cm.Result[uint64, monotonicclock.Duration, network.ErrorCode]) + +// LocalAddress represents the imported method "local-address". +// +// Get the bound local address. +// +// POSIX mentions: +// > If the socket has not been bound to a local name, the value +// > stored in the object pointed to by `address` is unspecified. +// +// WASI is stricter and requires `local-address` to return `invalid-state` when the +// socket hasn't been bound yet. +// +// # Typical errors +// - `invalid-state`: The socket is not bound to any local address. +// +// # References +// - +// - +// - +// - +// +// local-address: func() -> result +// +//go:nosplit +func (self TCPSocket) LocalAddress() (result cm.Result[IPSocketAddressShape, network.IPSocketAddress, network.ErrorCode]) { + self0 := cm.Reinterpret[uint32](self) + wasmimport_TCPSocketLocalAddress((uint32)(self0), &result) + return +} + +//go:wasmimport wasi:sockets/tcp@0.2.1 [method]tcp-socket.local-address +//go:noescape +func wasmimport_TCPSocketLocalAddress(self0 uint32, result *cm.Result[IPSocketAddressShape, network.IPSocketAddress, network.ErrorCode]) + +// ReceiveBufferSize represents the imported method "receive-buffer-size". +// +// The kernel buffer space reserved for sends/receives on this socket. +// +// If the provided value is 0, an `invalid-argument` error is returned. +// Any other value will never cause an error, but it might be silently clamped and/or +// rounded. +// I.e. after setting a value, reading the same setting back may return a different +// value. +// +// Equivalent to the SO_RCVBUF and SO_SNDBUF socket options. +// +// # Typical errors +// - `invalid-argument`: (set) The provided value was 0. +// +// receive-buffer-size: func() -> result +// +//go:nosplit +func (self TCPSocket) ReceiveBufferSize() (result cm.Result[uint64, uint64, network.ErrorCode]) { + self0 := cm.Reinterpret[uint32](self) + wasmimport_TCPSocketReceiveBufferSize((uint32)(self0), &result) + return +} + +//go:wasmimport wasi:sockets/tcp@0.2.1 [method]tcp-socket.receive-buffer-size +//go:noescape +func wasmimport_TCPSocketReceiveBufferSize(self0 uint32, result *cm.Result[uint64, uint64, network.ErrorCode]) + +// RemoteAddress represents the imported method "remote-address". +// +// Get the remote address. +// +// # Typical errors +// - `invalid-state`: The socket is not connected to a remote address. (ENOTCONN) +// +// # References +// - +// - +// - +// - +// +// remote-address: func() -> result +// +//go:nosplit +func (self TCPSocket) RemoteAddress() (result cm.Result[IPSocketAddressShape, network.IPSocketAddress, network.ErrorCode]) { + self0 := cm.Reinterpret[uint32](self) + wasmimport_TCPSocketRemoteAddress((uint32)(self0), &result) + return +} + +//go:wasmimport wasi:sockets/tcp@0.2.1 [method]tcp-socket.remote-address +//go:noescape +func wasmimport_TCPSocketRemoteAddress(self0 uint32, result *cm.Result[IPSocketAddressShape, network.IPSocketAddress, network.ErrorCode]) + +// SendBufferSize represents the imported method "send-buffer-size". +// +// send-buffer-size: func() -> result +// +//go:nosplit +func (self TCPSocket) SendBufferSize() (result cm.Result[uint64, uint64, network.ErrorCode]) { + self0 := cm.Reinterpret[uint32](self) + wasmimport_TCPSocketSendBufferSize((uint32)(self0), &result) + return +} + +//go:wasmimport wasi:sockets/tcp@0.2.1 [method]tcp-socket.send-buffer-size +//go:noescape +func wasmimport_TCPSocketSendBufferSize(self0 uint32, result *cm.Result[uint64, uint64, network.ErrorCode]) + +// SetHopLimit represents the imported method "set-hop-limit". +// +// set-hop-limit: func(value: u8) -> result<_, error-code> +// +//go:nosplit +func (self TCPSocket) SetHopLimit(value uint8) (result cm.Result[network.ErrorCode, struct{}, network.ErrorCode]) { + self0 := cm.Reinterpret[uint32](self) + value0 := (uint32)(value) + wasmimport_TCPSocketSetHopLimit((uint32)(self0), (uint32)(value0), &result) + return +} + +//go:wasmimport wasi:sockets/tcp@0.2.1 [method]tcp-socket.set-hop-limit +//go:noescape +func wasmimport_TCPSocketSetHopLimit(self0 uint32, value0 uint32, result *cm.Result[network.ErrorCode, struct{}, network.ErrorCode]) + +// SetKeepAliveCount represents the imported method "set-keep-alive-count". +// +// set-keep-alive-count: func(value: u32) -> result<_, error-code> +// +//go:nosplit +func (self TCPSocket) SetKeepAliveCount(value uint32) (result cm.Result[network.ErrorCode, struct{}, network.ErrorCode]) { + self0 := cm.Reinterpret[uint32](self) + value0 := (uint32)(value) + wasmimport_TCPSocketSetKeepAliveCount((uint32)(self0), (uint32)(value0), &result) + return +} + +//go:wasmimport wasi:sockets/tcp@0.2.1 [method]tcp-socket.set-keep-alive-count +//go:noescape +func wasmimport_TCPSocketSetKeepAliveCount(self0 uint32, value0 uint32, result *cm.Result[network.ErrorCode, struct{}, network.ErrorCode]) + +// SetKeepAliveEnabled represents the imported method "set-keep-alive-enabled". +// +// set-keep-alive-enabled: func(value: bool) -> result<_, error-code> +// +//go:nosplit +func (self TCPSocket) SetKeepAliveEnabled(value bool) (result cm.Result[network.ErrorCode, struct{}, network.ErrorCode]) { + self0 := cm.Reinterpret[uint32](self) + value0 := cm.BoolToU32(value) + wasmimport_TCPSocketSetKeepAliveEnabled((uint32)(self0), (uint32)(value0), &result) + return +} + +//go:wasmimport wasi:sockets/tcp@0.2.1 [method]tcp-socket.set-keep-alive-enabled +//go:noescape +func wasmimport_TCPSocketSetKeepAliveEnabled(self0 uint32, value0 uint32, result *cm.Result[network.ErrorCode, struct{}, network.ErrorCode]) + +// SetKeepAliveIdleTime represents the imported method "set-keep-alive-idle-time". +// +// set-keep-alive-idle-time: func(value: duration) -> result<_, error-code> +// +//go:nosplit +func (self TCPSocket) SetKeepAliveIdleTime(value monotonicclock.Duration) (result cm.Result[network.ErrorCode, struct{}, network.ErrorCode]) { + self0 := cm.Reinterpret[uint32](self) + value0 := (uint64)(value) + wasmimport_TCPSocketSetKeepAliveIdleTime((uint32)(self0), (uint64)(value0), &result) + return +} + +//go:wasmimport wasi:sockets/tcp@0.2.1 [method]tcp-socket.set-keep-alive-idle-time +//go:noescape +func wasmimport_TCPSocketSetKeepAliveIdleTime(self0 uint32, value0 uint64, result *cm.Result[network.ErrorCode, struct{}, network.ErrorCode]) + +// SetKeepAliveInterval represents the imported method "set-keep-alive-interval". +// +// set-keep-alive-interval: func(value: duration) -> result<_, error-code> +// +//go:nosplit +func (self TCPSocket) SetKeepAliveInterval(value monotonicclock.Duration) (result cm.Result[network.ErrorCode, struct{}, network.ErrorCode]) { + self0 := cm.Reinterpret[uint32](self) + value0 := (uint64)(value) + wasmimport_TCPSocketSetKeepAliveInterval((uint32)(self0), (uint64)(value0), &result) + return +} + +//go:wasmimport wasi:sockets/tcp@0.2.1 [method]tcp-socket.set-keep-alive-interval +//go:noescape +func wasmimport_TCPSocketSetKeepAliveInterval(self0 uint32, value0 uint64, result *cm.Result[network.ErrorCode, struct{}, network.ErrorCode]) + +// SetListenBacklogSize represents the imported method "set-listen-backlog-size". +// +// Hints the desired listen queue size. Implementations are free to ignore this. +// +// If the provided value is 0, an `invalid-argument` error is returned. +// Any other value will never cause an error, but it might be silently clamped and/or +// rounded. +// +// # Typical errors +// - `not-supported`: (set) The platform does not support changing the backlog +// size after the initial listen. +// - `invalid-argument`: (set) The provided value was 0. +// - `invalid-state`: (set) The socket is in the `connect-in-progress` or `connected` +// state. +// +// set-listen-backlog-size: func(value: u64) -> result<_, error-code> +// +//go:nosplit +func (self TCPSocket) SetListenBacklogSize(value uint64) (result cm.Result[network.ErrorCode, struct{}, network.ErrorCode]) { + self0 := cm.Reinterpret[uint32](self) + value0 := (uint64)(value) + wasmimport_TCPSocketSetListenBacklogSize((uint32)(self0), (uint64)(value0), &result) + return +} + +//go:wasmimport wasi:sockets/tcp@0.2.1 [method]tcp-socket.set-listen-backlog-size +//go:noescape +func wasmimport_TCPSocketSetListenBacklogSize(self0 uint32, value0 uint64, result *cm.Result[network.ErrorCode, struct{}, network.ErrorCode]) + +// SetReceiveBufferSize represents the imported method "set-receive-buffer-size". +// +// set-receive-buffer-size: func(value: u64) -> result<_, error-code> +// +//go:nosplit +func (self TCPSocket) SetReceiveBufferSize(value uint64) (result cm.Result[network.ErrorCode, struct{}, network.ErrorCode]) { + self0 := cm.Reinterpret[uint32](self) + value0 := (uint64)(value) + wasmimport_TCPSocketSetReceiveBufferSize((uint32)(self0), (uint64)(value0), &result) + return +} + +//go:wasmimport wasi:sockets/tcp@0.2.1 [method]tcp-socket.set-receive-buffer-size +//go:noescape +func wasmimport_TCPSocketSetReceiveBufferSize(self0 uint32, value0 uint64, result *cm.Result[network.ErrorCode, struct{}, network.ErrorCode]) + +// SetSendBufferSize represents the imported method "set-send-buffer-size". +// +// set-send-buffer-size: func(value: u64) -> result<_, error-code> +// +//go:nosplit +func (self TCPSocket) SetSendBufferSize(value uint64) (result cm.Result[network.ErrorCode, struct{}, network.ErrorCode]) { + self0 := cm.Reinterpret[uint32](self) + value0 := (uint64)(value) + wasmimport_TCPSocketSetSendBufferSize((uint32)(self0), (uint64)(value0), &result) + return +} + +//go:wasmimport wasi:sockets/tcp@0.2.1 [method]tcp-socket.set-send-buffer-size +//go:noescape +func wasmimport_TCPSocketSetSendBufferSize(self0 uint32, value0 uint64, result *cm.Result[network.ErrorCode, struct{}, network.ErrorCode]) + +// Shutdown represents the imported method "shutdown". +// +// Initiate a graceful shutdown. +// +// - `receive`: The socket is not expecting to receive any data from +// the peer. The `input-stream` associated with this socket will be +// closed. Any data still in the receive queue at time of calling +// this method will be discarded. +// - `send`: The socket has no more data to send to the peer. The `output-stream` +// associated with this socket will be closed and a FIN packet will be sent. +// - `both`: Same effect as `receive` & `send` combined. +// +// This function is idempotent; shutting down a direction more than once +// has no effect and returns `ok`. +// +// The shutdown function does not close (drop) the socket. +// +// # Typical errors +// - `invalid-state`: The socket is not in the `connected` state. (ENOTCONN) +// +// # References +// - +// - +// - +// - +// +// shutdown: func(shutdown-type: shutdown-type) -> result<_, error-code> +// +//go:nosplit +func (self TCPSocket) Shutdown(shutdownType ShutdownType) (result cm.Result[network.ErrorCode, struct{}, network.ErrorCode]) { + self0 := cm.Reinterpret[uint32](self) + shutdownType0 := (uint32)(shutdownType) + wasmimport_TCPSocketShutdown((uint32)(self0), (uint32)(shutdownType0), &result) + return +} + +//go:wasmimport wasi:sockets/tcp@0.2.1 [method]tcp-socket.shutdown +//go:noescape +func wasmimport_TCPSocketShutdown(self0 uint32, shutdownType0 uint32, result *cm.Result[network.ErrorCode, struct{}, network.ErrorCode]) + +// StartBind represents the imported method "start-bind". +// +// Bind the socket to a specific network on the provided IP address and port. +// +// If the IP address is zero (`0.0.0.0` in IPv4, `::` in IPv6), it is left to the +// implementation to decide which +// network interface(s) to bind to. +// If the TCP/UDP port is zero, the socket will be bound to a random free port. +// +// Bind can be attempted multiple times on the same socket, even with +// different arguments on each iteration. But never concurrently and +// only as long as the previous bind failed. Once a bind succeeds, the +// binding can't be changed anymore. +// +// # Typical errors +// - `invalid-argument`: The `local-address` has the wrong address family. +// (EAFNOSUPPORT, EFAULT on Windows) +// - `invalid-argument`: `local-address` is not a unicast address. (EINVAL) +// - `invalid-argument`: `local-address` is an IPv4-mapped IPv6 address. +// (EINVAL) +// - `invalid-state`: The socket is already bound. (EINVAL) +// - `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 the `network` +// can bind to. (EADDRNOTAVAIL) +// - `not-in-progress`: A `bind` operation is not in progress. +// - `would-block`: Can't finish the operation, it is still in progress. +// (EWOULDBLOCK, EAGAIN) +// +// # 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 +// 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. +// +// Unlike in POSIX, in WASI the bind operation is async. This enables +// interactive WASI hosts to inject permission prompts. Runtimes that +// don't want to make use of this ability can simply call the native +// `bind` as part of either `start-bind` or `finish-bind`. +// +// # References +// - +// - +// - +// - +// +// start-bind: func(network: borrow, local-address: ip-socket-address) -> +// result<_, error-code> +// +//go:nosplit +func (self TCPSocket) StartBind(network_ network.Network, localAddress network.IPSocketAddress) (result cm.Result[network.ErrorCode, struct{}, network.ErrorCode]) { + self0 := cm.Reinterpret[uint32](self) + network0 := cm.Reinterpret[uint32](network_) + localAddress0, localAddress1, localAddress2, localAddress3, localAddress4, localAddress5, localAddress6, localAddress7, localAddress8, localAddress9, localAddress10, localAddress11 := lower_IPSocketAddress(localAddress) + wasmimport_TCPSocketStartBind((uint32)(self0), (uint32)(network0), (uint32)(localAddress0), (uint32)(localAddress1), (uint32)(localAddress2), (uint32)(localAddress3), (uint32)(localAddress4), (uint32)(localAddress5), (uint32)(localAddress6), (uint32)(localAddress7), (uint32)(localAddress8), (uint32)(localAddress9), (uint32)(localAddress10), (uint32)(localAddress11), &result) + return +} + +//go:wasmimport wasi:sockets/tcp@0.2.1 [method]tcp-socket.start-bind +//go:noescape +func wasmimport_TCPSocketStartBind(self0 uint32, network0 uint32, localAddress0 uint32, localAddress1 uint32, localAddress2 uint32, localAddress3 uint32, localAddress4 uint32, localAddress5 uint32, localAddress6 uint32, localAddress7 uint32, localAddress8 uint32, localAddress9 uint32, localAddress10 uint32, localAddress11 uint32, result *cm.Result[network.ErrorCode, struct{}, network.ErrorCode]) + +// StartConnect represents the imported method "start-connect". +// +// Connect to a remote endpoint. +// +// On success: +// - the socket is transitioned into the `connected` state. +// - a pair of streams is returned that can be used to read & write to the connection +// +// After a failed connection attempt, the socket will be in the `closed` +// state and the only valid action left is to `drop` the socket. A single +// socket can not be used to connect more than once. +// +// # Typical errors +// - `invalid-argument`: The `remote-address` has the wrong address family. +// (EAFNOSUPPORT) +// - `invalid-argument`: `remote-address` is not a unicast address. (EINVAL, +// ENETUNREACH on Linux, EAFNOSUPPORT on MacOS) +// - `invalid-argument`: `remote-address` is an IPv4-mapped IPv6 address. +// (EINVAL, EADDRNOTAVAIL on Illumos) +// - `invalid-argument`: The IP address in `remote-address` is set to INADDR_ANY +// (`0.0.0.0` / `::`). (EADDRNOTAVAIL on Windows) +// - `invalid-argument`: The port in `remote-address` is set to 0. (EADDRNOTAVAIL +// on Windows) +// - `invalid-argument`: The socket is already attached to a different network. +// The `network` passed to `connect` must be identical to the one passed to `bind`. +// - `invalid-state`: The socket is already in the `connected` state. +// (EISCONN) +// - `invalid-state`: The socket is already in the `listening` state. +// (EOPNOTSUPP, EINVAL on Windows) +// - `timeout`: Connection timed out. (ETIMEDOUT) +// - `connection-refused`: The connection was forcefully rejected. (ECONNREFUSED) +// - `connection-reset`: The connection was reset. (ECONNRESET) +// - `connection-aborted`: The connection was aborted. (ECONNABORTED) +// - `remote-unreachable`: The remote address is not reachable. (EHOSTUNREACH, +// EHOSTDOWN, ENETUNREACH, ENETDOWN, ENONET) +// - `address-in-use`: Tried to perform an implicit bind, but there were +// no ephemeral ports available. (EADDRINUSE, EADDRNOTAVAIL on Linux, EAGAIN on BSD) +// - `not-in-progress`: A connect operation is not in progress. +// - `would-block`: Can't finish the operation, it is still in progress. +// (EWOULDBLOCK, EAGAIN) +// +// # Implementors note +// The POSIX equivalent of `start-connect` is the regular `connect` syscall. +// Because all WASI sockets are non-blocking this is expected to return +// EINPROGRESS, which should be translated to `ok()` in WASI. +// +// The POSIX equivalent of `finish-connect` is a `poll` for event `POLLOUT` +// with a timeout of 0 on the socket descriptor. Followed by a check for +// the `SO_ERROR` socket option, in case the poll signaled readiness. +// +// # References +// - +// - +// - +// - +// +// start-connect: func(network: borrow, remote-address: ip-socket-address) +// -> result<_, error-code> +// +//go:nosplit +func (self TCPSocket) StartConnect(network_ network.Network, remoteAddress network.IPSocketAddress) (result cm.Result[network.ErrorCode, struct{}, network.ErrorCode]) { + self0 := cm.Reinterpret[uint32](self) + network0 := cm.Reinterpret[uint32](network_) + remoteAddress0, remoteAddress1, remoteAddress2, remoteAddress3, remoteAddress4, remoteAddress5, remoteAddress6, remoteAddress7, remoteAddress8, remoteAddress9, remoteAddress10, remoteAddress11 := lower_IPSocketAddress(remoteAddress) + wasmimport_TCPSocketStartConnect((uint32)(self0), (uint32)(network0), (uint32)(remoteAddress0), (uint32)(remoteAddress1), (uint32)(remoteAddress2), (uint32)(remoteAddress3), (uint32)(remoteAddress4), (uint32)(remoteAddress5), (uint32)(remoteAddress6), (uint32)(remoteAddress7), (uint32)(remoteAddress8), (uint32)(remoteAddress9), (uint32)(remoteAddress10), (uint32)(remoteAddress11), &result) + return +} + +//go:wasmimport wasi:sockets/tcp@0.2.1 [method]tcp-socket.start-connect +//go:noescape +func wasmimport_TCPSocketStartConnect(self0 uint32, network0 uint32, remoteAddress0 uint32, remoteAddress1 uint32, remoteAddress2 uint32, remoteAddress3 uint32, remoteAddress4 uint32, remoteAddress5 uint32, remoteAddress6 uint32, remoteAddress7 uint32, remoteAddress8 uint32, remoteAddress9 uint32, remoteAddress10 uint32, remoteAddress11 uint32, result *cm.Result[network.ErrorCode, struct{}, network.ErrorCode]) + +// StartListen represents the imported method "start-listen". +// +// Start listening for new connections. +// +// Transitions the socket into the `listening` state. +// +// Unlike POSIX, the socket must already be explicitly bound. +// +// # Typical errors +// - `invalid-state`: The socket is not bound to any local address. (EDESTADDRREQ) +// - `invalid-state`: The socket is already in the `connected` state. +// (EISCONN, EINVAL on BSD) +// - `invalid-state`: The socket is already in the `listening` state. +// - `address-in-use`: Tried to perform an implicit bind, but there were +// no ephemeral ports available. (EADDRINUSE) +// - `not-in-progress`: A listen operation is not in progress. +// - `would-block`: Can't finish the operation, it is still in progress. +// (EWOULDBLOCK, EAGAIN) +// +// # Implementors note +// Unlike in POSIX, in WASI the listen operation is async. This enables +// interactive WASI hosts to inject permission prompts. Runtimes that +// don't want to make use of this ability can simply call the native +// `listen` as part of either `start-listen` or `finish-listen`. +// +// # References +// - +// - +// - +// - +// +// start-listen: func() -> result<_, error-code> +// +//go:nosplit +func (self TCPSocket) StartListen() (result cm.Result[network.ErrorCode, struct{}, network.ErrorCode]) { + self0 := cm.Reinterpret[uint32](self) + wasmimport_TCPSocketStartListen((uint32)(self0), &result) + return +} + +//go:wasmimport wasi:sockets/tcp@0.2.1 [method]tcp-socket.start-listen +//go:noescape +func wasmimport_TCPSocketStartListen(self0 uint32, result *cm.Result[network.ErrorCode, struct{}, network.ErrorCode]) + +// Subscribe represents the imported method "subscribe". +// +// Create a `pollable` which can be used to poll for, or block on, +// completion of any of the asynchronous operations of this socket. +// +// When `finish-bind`, `finish-listen`, `finish-connect` or `accept` +// return `error(would-block)`, this pollable can be used to wait for +// their success or failure, after which the method can be retried. +// +// The pollable is not limited to the async operation that happens to be +// in progress at the time of calling `subscribe` (if any). Theoretically, +// `subscribe` only has to be called once per socket and can then be +// (re)used for the remainder of the socket's lifetime. +// +// See +// for more information. +// +// Note: this function is here for WASI Preview2 only. +// It's planned to be removed when `future` is natively supported in Preview3. +// +// subscribe: func() -> pollable +// +//go:nosplit +func (self TCPSocket) Subscribe() (result poll.Pollable) { + self0 := cm.Reinterpret[uint32](self) + result0 := wasmimport_TCPSocketSubscribe((uint32)(self0)) + result = cm.Reinterpret[poll.Pollable]((uint32)(result0)) + return +} + +//go:wasmimport wasi:sockets/tcp@0.2.1 [method]tcp-socket.subscribe +//go:noescape +func wasmimport_TCPSocketSubscribe(self0 uint32) (result0 uint32) diff --git a/examples/go/http/bindings/wasi/sockets/udp-create-socket/empty.s b/examples/go/http/bindings/wasi/sockets/udp-create-socket/empty.s new file mode 100644 index 0000000..5444f20 --- /dev/null +++ b/examples/go/http/bindings/wasi/sockets/udp-create-socket/empty.s @@ -0,0 +1,3 @@ +// This file exists for testing this package without WebAssembly, +// allowing empty function bodies with a //go:wasmimport directive. +// See https://pkg.go.dev/cmd/compile for more information. diff --git a/examples/go/http/bindings/wasi/sockets/udp-create-socket/udp-create-socket.wit.go b/examples/go/http/bindings/wasi/sockets/udp-create-socket/udp-create-socket.wit.go new file mode 100644 index 0000000..4363915 --- /dev/null +++ b/examples/go/http/bindings/wasi/sockets/udp-create-socket/udp-create-socket.wit.go @@ -0,0 +1,52 @@ +// Code generated by wit-bindgen-go. DO NOT EDIT. + +// Package udpcreatesocket represents the imported interface "wasi:sockets/udp-create-socket@0.2.1". +package udpcreatesocket + +import ( + "github.com/bytecodealliance/wasm-tools-go/cm" + "github.com/rvolosatovs/west/examples/go/http/bindings/wasi/sockets/network" + "github.com/rvolosatovs/west/examples/go/http/bindings/wasi/sockets/udp" +) + +// CreateUDPSocket represents the imported function "create-udp-socket". +// +// Create a new UDP socket. +// +// Similar to `socket(AF_INET or AF_INET6, SOCK_DGRAM, IPPROTO_UDP)` in POSIX. +// On IPv6 sockets, IPV6_V6ONLY is enabled by default and can't be configured otherwise. +// +// This function does not require a network capability handle. This is considered +// to be safe because +// at time of creation, the socket is not bound to any `network` yet. Up to the moment +// `bind` is called, +// the socket is effectively an in-memory configuration object, unable to communicate +// with the outside world. +// +// All sockets are non-blocking. Use the wasi-poll interface to block on asynchronous +// operations. +// +// # Typical errors +// - `not-supported`: The specified `address-family` is not supported. (EAFNOSUPPORT) +// - `new-socket-limit`: The new socket resource could not be created because of +// a system limit. (EMFILE, ENFILE) +// +// # References: +// - +// - +// - +// - +// +// create-udp-socket: func(address-family: ip-address-family) -> result +// +//go:nosplit +func CreateUDPSocket(addressFamily network.IPAddressFamily) (result cm.Result[udp.UDPSocket, udp.UDPSocket, network.ErrorCode]) { + addressFamily0 := (uint32)(addressFamily) + wasmimport_CreateUDPSocket((uint32)(addressFamily0), &result) + return +} + +//go:wasmimport wasi:sockets/udp-create-socket@0.2.1 create-udp-socket +//go:noescape +func wasmimport_CreateUDPSocket(addressFamily0 uint32, result *cm.Result[udp.UDPSocket, udp.UDPSocket, network.ErrorCode]) diff --git a/examples/go/http/bindings/wasi/sockets/udp/abi.go b/examples/go/http/bindings/wasi/sockets/udp/abi.go new file mode 100644 index 0000000..f4885ff --- /dev/null +++ b/examples/go/http/bindings/wasi/sockets/udp/abi.go @@ -0,0 +1,101 @@ +// Code generated by wit-bindgen-go. DO NOT EDIT. + +package udp + +import ( + "github.com/bytecodealliance/wasm-tools-go/cm" + "github.com/rvolosatovs/west/examples/go/http/bindings/wasi/sockets/network" + "unsafe" +) + +// IPSocketAddressShape is used for storage in variant or result types. +type IPSocketAddressShape struct { + shape [unsafe.Sizeof(network.IPSocketAddress{})]byte +} + +func lower_IPv4Address(v network.IPv4Address) (f0 uint32, f1 uint32, f2 uint32, f3 uint32) { + f0 = (uint32)(v[0]) + f1 = (uint32)(v[1]) + f2 = (uint32)(v[2]) + f3 = (uint32)(v[3]) + return +} + +func lower_IPv4SocketAddress(v network.IPv4SocketAddress) (f0 uint32, f1 uint32, f2 uint32, f3 uint32, f4 uint32) { + f0 = (uint32)(v.Port) + f1, f2, f3, f4 = lower_IPv4Address(v.Address) + return +} + +func lower_IPv6Address(v network.IPv6Address) (f0 uint32, f1 uint32, f2 uint32, f3 uint32, f4 uint32, f5 uint32, f6 uint32, f7 uint32) { + f0 = (uint32)(v[0]) + f1 = (uint32)(v[1]) + f2 = (uint32)(v[2]) + f3 = (uint32)(v[3]) + f4 = (uint32)(v[4]) + f5 = (uint32)(v[5]) + f6 = (uint32)(v[6]) + f7 = (uint32)(v[7]) + return +} + +func lower_IPv6SocketAddress(v network.IPv6SocketAddress) (f0 uint32, f1 uint32, f2 uint32, f3 uint32, f4 uint32, f5 uint32, f6 uint32, f7 uint32, f8 uint32, f9 uint32, f10 uint32) { + f0 = (uint32)(v.Port) + f1 = (uint32)(v.FlowInfo) + f2, f3, f4, f5, f6, f7, f8, f9 = lower_IPv6Address(v.Address) + f10 = (uint32)(v.ScopeID) + return +} + +func lower_IPSocketAddress(v network.IPSocketAddress) (f0 uint32, f1 uint32, f2 uint32, f3 uint32, f4 uint32, f5 uint32, f6 uint32, f7 uint32, f8 uint32, f9 uint32, f10 uint32, f11 uint32) { + f0 = (uint32)(v.Tag()) + switch f0 { + case 0: // ipv4 + v1, v2, v3, v4, v5 := lower_IPv4SocketAddress(*v.IPv4()) + f1 = (uint32)(v1) + f2 = (uint32)(v2) + f3 = (uint32)(v3) + f4 = (uint32)(v4) + f5 = (uint32)(v5) + case 1: // ipv6 + v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11 := lower_IPv6SocketAddress(*v.IPv6()) + f1 = (uint32)(v1) + f2 = (uint32)(v2) + f3 = (uint32)(v3) + f4 = (uint32)(v4) + f5 = (uint32)(v5) + f6 = (uint32)(v6) + f7 = (uint32)(v7) + f8 = (uint32)(v8) + f9 = (uint32)(v9) + f10 = (uint32)(v10) + f11 = (uint32)(v11) + } + return +} + +// TupleIncomingDatagramStreamOutgoingDatagramStreamShape is used for storage in variant or result types. +type TupleIncomingDatagramStreamOutgoingDatagramStreamShape struct { + shape [unsafe.Sizeof(cm.Tuple[IncomingDatagramStream, OutgoingDatagramStream]{})]byte +} + +func lower_OptionIPSocketAddress(v cm.Option[network.IPSocketAddress]) (f0 uint32, f1 uint32, f2 uint32, f3 uint32, f4 uint32, f5 uint32, f6 uint32, f7 uint32, f8 uint32, f9 uint32, f10 uint32, f11 uint32, f12 uint32) { + some := v.Some() + if some != nil { + f0 = 1 + v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12 := lower_IPSocketAddress(*some) + f1 = (uint32)(v1) + f2 = (uint32)(v2) + f3 = (uint32)(v3) + f4 = (uint32)(v4) + f5 = (uint32)(v5) + f6 = (uint32)(v6) + f7 = (uint32)(v7) + f8 = (uint32)(v8) + f9 = (uint32)(v9) + f10 = (uint32)(v10) + f11 = (uint32)(v11) + f12 = (uint32)(v12) + } + return +} diff --git a/examples/go/http/bindings/wasi/sockets/udp/empty.s b/examples/go/http/bindings/wasi/sockets/udp/empty.s new file mode 100644 index 0000000..5444f20 --- /dev/null +++ b/examples/go/http/bindings/wasi/sockets/udp/empty.s @@ -0,0 +1,3 @@ +// This file exists for testing this package without WebAssembly, +// allowing empty function bodies with a //go:wasmimport directive. +// See https://pkg.go.dev/cmd/compile for more information. diff --git a/examples/go/http/bindings/wasi/sockets/udp/udp.wit.go b/examples/go/http/bindings/wasi/sockets/udp/udp.wit.go new file mode 100644 index 0000000..9bc7f1b --- /dev/null +++ b/examples/go/http/bindings/wasi/sockets/udp/udp.wit.go @@ -0,0 +1,641 @@ +// Code generated by wit-bindgen-go. DO NOT EDIT. + +// Package udp represents the imported interface "wasi:sockets/udp@0.2.1". +package udp + +import ( + "github.com/bytecodealliance/wasm-tools-go/cm" + "github.com/rvolosatovs/west/examples/go/http/bindings/wasi/io/poll" + "github.com/rvolosatovs/west/examples/go/http/bindings/wasi/sockets/network" +) + +// IncomingDatagram represents the record "wasi:sockets/udp@0.2.1#incoming-datagram". +// +// A received datagram. +// +// record incoming-datagram { +// data: list, +// remote-address: ip-socket-address, +// } +type IncomingDatagram struct { + // The payload. + // + // Theoretical max size: ~64 KiB. In practice, typically less than 1500 bytes. + Data cm.List[uint8] + + // The source address. + // + // This field is guaranteed to match the remote address the stream was initialized + // with, if any. + // + // Equivalent to the `src_addr` out parameter of `recvfrom`. + RemoteAddress network.IPSocketAddress +} + +// OutgoingDatagram represents the record "wasi:sockets/udp@0.2.1#outgoing-datagram". +// +// A datagram to be sent out. +// +// record outgoing-datagram { +// data: list, +// remote-address: option, +// } +type OutgoingDatagram struct { + // The payload. + Data cm.List[uint8] + + // The destination address. + // + // The requirements on this field depend on how the stream was initialized: + // - with a remote address: this field must be None or match the stream's remote address + // exactly. + // - without a remote address: this field is required. + // + // If this value is None, the send operation is equivalent to `send` in POSIX. Otherwise + // it is equivalent to `sendto`. + RemoteAddress cm.Option[network.IPSocketAddress] +} + +// UDPSocket represents the imported resource "wasi:sockets/udp@0.2.1#udp-socket". +// +// A UDP socket handle. +// +// resource udp-socket +type UDPSocket cm.Resource + +// ResourceDrop represents the imported resource-drop for resource "udp-socket". +// +// Drops a resource handle. +// +//go:nosplit +func (self UDPSocket) ResourceDrop() { + self0 := cm.Reinterpret[uint32](self) + wasmimport_UDPSocketResourceDrop((uint32)(self0)) + return +} + +//go:wasmimport wasi:sockets/udp@0.2.1 [resource-drop]udp-socket +//go:noescape +func wasmimport_UDPSocketResourceDrop(self0 uint32) + +// AddressFamily represents the imported method "address-family". +// +// Whether this is a IPv4 or IPv6 socket. +// +// Equivalent to the SO_DOMAIN socket option. +// +// address-family: func() -> ip-address-family +// +//go:nosplit +func (self UDPSocket) AddressFamily() (result network.IPAddressFamily) { + self0 := cm.Reinterpret[uint32](self) + result0 := wasmimport_UDPSocketAddressFamily((uint32)(self0)) + result = (network.IPAddressFamily)((uint32)(result0)) + return +} + +//go:wasmimport wasi:sockets/udp@0.2.1 [method]udp-socket.address-family +//go:noescape +func wasmimport_UDPSocketAddressFamily(self0 uint32) (result0 uint32) + +// FinishBind represents the imported method "finish-bind". +// +// finish-bind: func() -> result<_, error-code> +// +//go:nosplit +func (self UDPSocket) FinishBind() (result cm.Result[network.ErrorCode, struct{}, network.ErrorCode]) { + self0 := cm.Reinterpret[uint32](self) + wasmimport_UDPSocketFinishBind((uint32)(self0), &result) + return +} + +//go:wasmimport wasi:sockets/udp@0.2.1 [method]udp-socket.finish-bind +//go:noescape +func wasmimport_UDPSocketFinishBind(self0 uint32, result *cm.Result[network.ErrorCode, struct{}, network.ErrorCode]) + +// LocalAddress represents the imported method "local-address". +// +// Get the current bound address. +// +// POSIX mentions: +// > If the socket has not been bound to a local name, the value +// > stored in the object pointed to by `address` is unspecified. +// +// WASI is stricter and requires `local-address` to return `invalid-state` when the +// socket hasn't been bound yet. +// +// # Typical errors +// - `invalid-state`: The socket is not bound to any local address. +// +// # References +// - +// - +// - +// - +// +// local-address: func() -> result +// +//go:nosplit +func (self UDPSocket) LocalAddress() (result cm.Result[IPSocketAddressShape, network.IPSocketAddress, network.ErrorCode]) { + self0 := cm.Reinterpret[uint32](self) + wasmimport_UDPSocketLocalAddress((uint32)(self0), &result) + return +} + +//go:wasmimport wasi:sockets/udp@0.2.1 [method]udp-socket.local-address +//go:noescape +func wasmimport_UDPSocketLocalAddress(self0 uint32, result *cm.Result[IPSocketAddressShape, network.IPSocketAddress, network.ErrorCode]) + +// ReceiveBufferSize represents the imported method "receive-buffer-size". +// +// The kernel buffer space reserved for sends/receives on this socket. +// +// If the provided value is 0, an `invalid-argument` error is returned. +// Any other value will never cause an error, but it might be silently clamped and/or +// rounded. +// I.e. after setting a value, reading the same setting back may return a different +// value. +// +// Equivalent to the SO_RCVBUF and SO_SNDBUF socket options. +// +// # Typical errors +// - `invalid-argument`: (set) The provided value was 0. +// +// receive-buffer-size: func() -> result +// +//go:nosplit +func (self UDPSocket) ReceiveBufferSize() (result cm.Result[uint64, uint64, network.ErrorCode]) { + self0 := cm.Reinterpret[uint32](self) + wasmimport_UDPSocketReceiveBufferSize((uint32)(self0), &result) + return +} + +//go:wasmimport wasi:sockets/udp@0.2.1 [method]udp-socket.receive-buffer-size +//go:noescape +func wasmimport_UDPSocketReceiveBufferSize(self0 uint32, result *cm.Result[uint64, uint64, network.ErrorCode]) + +// RemoteAddress represents the imported method "remote-address". +// +// Get the address the socket is currently streaming to. +// +// # Typical errors +// - `invalid-state`: The socket is not streaming to a specific remote address. (ENOTCONN) +// +// # References +// - +// - +// - +// - +// +// remote-address: func() -> result +// +//go:nosplit +func (self UDPSocket) RemoteAddress() (result cm.Result[IPSocketAddressShape, network.IPSocketAddress, network.ErrorCode]) { + self0 := cm.Reinterpret[uint32](self) + wasmimport_UDPSocketRemoteAddress((uint32)(self0), &result) + return +} + +//go:wasmimport wasi:sockets/udp@0.2.1 [method]udp-socket.remote-address +//go:noescape +func wasmimport_UDPSocketRemoteAddress(self0 uint32, result *cm.Result[IPSocketAddressShape, network.IPSocketAddress, network.ErrorCode]) + +// SendBufferSize represents the imported method "send-buffer-size". +// +// send-buffer-size: func() -> result +// +//go:nosplit +func (self UDPSocket) SendBufferSize() (result cm.Result[uint64, uint64, network.ErrorCode]) { + self0 := cm.Reinterpret[uint32](self) + wasmimport_UDPSocketSendBufferSize((uint32)(self0), &result) + return +} + +//go:wasmimport wasi:sockets/udp@0.2.1 [method]udp-socket.send-buffer-size +//go:noescape +func wasmimport_UDPSocketSendBufferSize(self0 uint32, result *cm.Result[uint64, uint64, network.ErrorCode]) + +// SetReceiveBufferSize represents the imported method "set-receive-buffer-size". +// +// set-receive-buffer-size: func(value: u64) -> result<_, error-code> +// +//go:nosplit +func (self UDPSocket) SetReceiveBufferSize(value uint64) (result cm.Result[network.ErrorCode, struct{}, network.ErrorCode]) { + self0 := cm.Reinterpret[uint32](self) + value0 := (uint64)(value) + wasmimport_UDPSocketSetReceiveBufferSize((uint32)(self0), (uint64)(value0), &result) + return +} + +//go:wasmimport wasi:sockets/udp@0.2.1 [method]udp-socket.set-receive-buffer-size +//go:noescape +func wasmimport_UDPSocketSetReceiveBufferSize(self0 uint32, value0 uint64, result *cm.Result[network.ErrorCode, struct{}, network.ErrorCode]) + +// SetSendBufferSize represents the imported method "set-send-buffer-size". +// +// set-send-buffer-size: func(value: u64) -> result<_, error-code> +// +//go:nosplit +func (self UDPSocket) SetSendBufferSize(value uint64) (result cm.Result[network.ErrorCode, struct{}, network.ErrorCode]) { + self0 := cm.Reinterpret[uint32](self) + value0 := (uint64)(value) + wasmimport_UDPSocketSetSendBufferSize((uint32)(self0), (uint64)(value0), &result) + return +} + +//go:wasmimport wasi:sockets/udp@0.2.1 [method]udp-socket.set-send-buffer-size +//go:noescape +func wasmimport_UDPSocketSetSendBufferSize(self0 uint32, value0 uint64, result *cm.Result[network.ErrorCode, struct{}, network.ErrorCode]) + +// SetUnicastHopLimit represents the imported method "set-unicast-hop-limit". +// +// set-unicast-hop-limit: func(value: u8) -> result<_, error-code> +// +//go:nosplit +func (self UDPSocket) SetUnicastHopLimit(value uint8) (result cm.Result[network.ErrorCode, struct{}, network.ErrorCode]) { + self0 := cm.Reinterpret[uint32](self) + value0 := (uint32)(value) + wasmimport_UDPSocketSetUnicastHopLimit((uint32)(self0), (uint32)(value0), &result) + return +} + +//go:wasmimport wasi:sockets/udp@0.2.1 [method]udp-socket.set-unicast-hop-limit +//go:noescape +func wasmimport_UDPSocketSetUnicastHopLimit(self0 uint32, value0 uint32, result *cm.Result[network.ErrorCode, struct{}, network.ErrorCode]) + +// StartBind represents the imported method "start-bind". +// +// Bind the socket to a specific network on the provided IP address and port. +// +// If the IP address is zero (`0.0.0.0` in IPv4, `::` in IPv6), it is left to the +// implementation to decide which +// network interface(s) to bind to. +// If the port is zero, the socket will be bound to a random free port. +// +// # Typical errors +// - `invalid-argument`: The `local-address` has the wrong address family. +// (EAFNOSUPPORT, EFAULT on Windows) +// - `invalid-state`: The socket is already bound. (EINVAL) +// - `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 the `network` +// can bind to. (EADDRNOTAVAIL) +// - `not-in-progress`: A `bind` operation is not in progress. +// - `would-block`: Can't finish the operation, it is still in progress. +// (EWOULDBLOCK, EAGAIN) +// +// # Implementors note +// Unlike in POSIX, in WASI the bind operation is async. This enables +// interactive WASI hosts to inject permission prompts. Runtimes that +// don't want to make use of this ability can simply call the native +// `bind` as part of either `start-bind` or `finish-bind`. +// +// # References +// - +// - +// - +// - +// +// start-bind: func(network: borrow, local-address: ip-socket-address) -> +// result<_, error-code> +// +//go:nosplit +func (self UDPSocket) StartBind(network_ network.Network, localAddress network.IPSocketAddress) (result cm.Result[network.ErrorCode, struct{}, network.ErrorCode]) { + self0 := cm.Reinterpret[uint32](self) + network0 := cm.Reinterpret[uint32](network_) + localAddress0, localAddress1, localAddress2, localAddress3, localAddress4, localAddress5, localAddress6, localAddress7, localAddress8, localAddress9, localAddress10, localAddress11 := lower_IPSocketAddress(localAddress) + wasmimport_UDPSocketStartBind((uint32)(self0), (uint32)(network0), (uint32)(localAddress0), (uint32)(localAddress1), (uint32)(localAddress2), (uint32)(localAddress3), (uint32)(localAddress4), (uint32)(localAddress5), (uint32)(localAddress6), (uint32)(localAddress7), (uint32)(localAddress8), (uint32)(localAddress9), (uint32)(localAddress10), (uint32)(localAddress11), &result) + return +} + +//go:wasmimport wasi:sockets/udp@0.2.1 [method]udp-socket.start-bind +//go:noescape +func wasmimport_UDPSocketStartBind(self0 uint32, network0 uint32, localAddress0 uint32, localAddress1 uint32, localAddress2 uint32, localAddress3 uint32, localAddress4 uint32, localAddress5 uint32, localAddress6 uint32, localAddress7 uint32, localAddress8 uint32, localAddress9 uint32, localAddress10 uint32, localAddress11 uint32, result *cm.Result[network.ErrorCode, struct{}, network.ErrorCode]) + +// Stream represents the imported method "stream". +// +// Set up inbound & outbound communication channels, optionally to a specific peer. +// +// This function only changes the local socket configuration and does not generate +// any network traffic. +// On success, the `remote-address` of the socket is updated. The `local-address` +// may be updated as well, +// based on the best network path to `remote-address`. +// +// When a `remote-address` is provided, the returned streams are limited to communicating +// with that specific peer: +// - `send` can only be used to send to this destination. +// - `receive` will only return datagrams sent from the provided `remote-address`. +// +// This method may be called multiple times on the same socket to change its association, +// but +// only the most recently returned pair of streams will be operational. Implementations +// may trap if +// the streams returned by a previous invocation haven't been dropped yet before calling +// `stream` again. +// +// The POSIX equivalent in pseudo-code is: +// +// if (was previously connected) { +// connect(s, AF_UNSPEC) +// } +// if (remote_address is Some) { +// connect(s, remote_address) +// } +// +// Unlike in POSIX, the socket must already be explicitly bound. +// +// # Typical errors +// - `invalid-argument`: The `remote-address` has the wrong address family. +// (EAFNOSUPPORT) +// - `invalid-argument`: The IP address in `remote-address` is set to INADDR_ANY +// (`0.0.0.0` / `::`). (EDESTADDRREQ, EADDRNOTAVAIL) +// - `invalid-argument`: The port in `remote-address` is set to 0. (EDESTADDRREQ, +// EADDRNOTAVAIL) +// - `invalid-state`: The socket is not bound. +// - `address-in-use`: Tried to perform an implicit bind, but there were +// no ephemeral ports available. (EADDRINUSE, EADDRNOTAVAIL on Linux, EAGAIN on BSD) +// - `remote-unreachable`: The remote address is not reachable. (ECONNRESET, +// ENETRESET, EHOSTUNREACH, EHOSTDOWN, ENETUNREACH, ENETDOWN, ENONET) +// - `connection-refused`: The connection was refused. (ECONNREFUSED) +// +// # References +// - +// - +// - +// - +// +// %stream: func(remote-address: option) -> result, error-code> +// +//go:nosplit +func (self UDPSocket) Stream(remoteAddress cm.Option[network.IPSocketAddress]) (result cm.Result[TupleIncomingDatagramStreamOutgoingDatagramStreamShape, cm.Tuple[IncomingDatagramStream, OutgoingDatagramStream], network.ErrorCode]) { + self0 := cm.Reinterpret[uint32](self) + remoteAddress0, remoteAddress1, remoteAddress2, remoteAddress3, remoteAddress4, remoteAddress5, remoteAddress6, remoteAddress7, remoteAddress8, remoteAddress9, remoteAddress10, remoteAddress11, remoteAddress12 := lower_OptionIPSocketAddress(remoteAddress) + wasmimport_UDPSocketStream((uint32)(self0), (uint32)(remoteAddress0), (uint32)(remoteAddress1), (uint32)(remoteAddress2), (uint32)(remoteAddress3), (uint32)(remoteAddress4), (uint32)(remoteAddress5), (uint32)(remoteAddress6), (uint32)(remoteAddress7), (uint32)(remoteAddress8), (uint32)(remoteAddress9), (uint32)(remoteAddress10), (uint32)(remoteAddress11), (uint32)(remoteAddress12), &result) + return +} + +//go:wasmimport wasi:sockets/udp@0.2.1 [method]udp-socket.stream +//go:noescape +func wasmimport_UDPSocketStream(self0 uint32, remoteAddress0 uint32, remoteAddress1 uint32, remoteAddress2 uint32, remoteAddress3 uint32, remoteAddress4 uint32, remoteAddress5 uint32, remoteAddress6 uint32, remoteAddress7 uint32, remoteAddress8 uint32, remoteAddress9 uint32, remoteAddress10 uint32, remoteAddress11 uint32, remoteAddress12 uint32, result *cm.Result[TupleIncomingDatagramStreamOutgoingDatagramStreamShape, cm.Tuple[IncomingDatagramStream, OutgoingDatagramStream], network.ErrorCode]) + +// Subscribe represents the imported method "subscribe". +// +// Create a `pollable` which will resolve once the socket is ready for I/O. +// +// Note: this function is here for WASI Preview2 only. +// It's planned to be removed when `future` is natively supported in Preview3. +// +// subscribe: func() -> pollable +// +//go:nosplit +func (self UDPSocket) Subscribe() (result poll.Pollable) { + self0 := cm.Reinterpret[uint32](self) + result0 := wasmimport_UDPSocketSubscribe((uint32)(self0)) + result = cm.Reinterpret[poll.Pollable]((uint32)(result0)) + return +} + +//go:wasmimport wasi:sockets/udp@0.2.1 [method]udp-socket.subscribe +//go:noescape +func wasmimport_UDPSocketSubscribe(self0 uint32) (result0 uint32) + +// UnicastHopLimit represents the imported method "unicast-hop-limit". +// +// Equivalent to the IP_TTL & IPV6_UNICAST_HOPS socket options. +// +// If the provided value is 0, an `invalid-argument` error is returned. +// +// # Typical errors +// - `invalid-argument`: (set) The TTL value must be 1 or higher. +// +// unicast-hop-limit: func() -> result +// +//go:nosplit +func (self UDPSocket) UnicastHopLimit() (result cm.Result[uint8, uint8, network.ErrorCode]) { + self0 := cm.Reinterpret[uint32](self) + wasmimport_UDPSocketUnicastHopLimit((uint32)(self0), &result) + return +} + +//go:wasmimport wasi:sockets/udp@0.2.1 [method]udp-socket.unicast-hop-limit +//go:noescape +func wasmimport_UDPSocketUnicastHopLimit(self0 uint32, result *cm.Result[uint8, uint8, network.ErrorCode]) + +// IncomingDatagramStream represents the imported resource "wasi:sockets/udp@0.2.1#incoming-datagram-stream". +// +// resource incoming-datagram-stream +type IncomingDatagramStream cm.Resource + +// ResourceDrop represents the imported resource-drop for resource "incoming-datagram-stream". +// +// Drops a resource handle. +// +//go:nosplit +func (self IncomingDatagramStream) ResourceDrop() { + self0 := cm.Reinterpret[uint32](self) + wasmimport_IncomingDatagramStreamResourceDrop((uint32)(self0)) + return +} + +//go:wasmimport wasi:sockets/udp@0.2.1 [resource-drop]incoming-datagram-stream +//go:noescape +func wasmimport_IncomingDatagramStreamResourceDrop(self0 uint32) + +// Receive represents the imported method "receive". +// +// Receive messages on the socket. +// +// This function attempts to receive up to `max-results` datagrams on the socket without +// blocking. +// The returned list may contain fewer elements than requested, but never more. +// +// This function returns successfully with an empty list when either: +// - `max-results` is 0, or: +// - `max-results` is greater than 0, but no results are immediately available. +// This function never returns `error(would-block)`. +// +// # Typical errors +// - `remote-unreachable`: The remote address is not reachable. (ECONNRESET, ENETRESET +// on Windows, EHOSTUNREACH, EHOSTDOWN, ENETUNREACH, ENETDOWN, ENONET) +// - `connection-refused`: The connection was refused. (ECONNREFUSED) +// +// # References +// - +// - +// - +// - +// - +// - +// - +// - +// +// receive: func(max-results: u64) -> result, error-code> +// +//go:nosplit +func (self IncomingDatagramStream) Receive(maxResults uint64) (result cm.Result[cm.List[IncomingDatagram], cm.List[IncomingDatagram], network.ErrorCode]) { + self0 := cm.Reinterpret[uint32](self) + maxResults0 := (uint64)(maxResults) + wasmimport_IncomingDatagramStreamReceive((uint32)(self0), (uint64)(maxResults0), &result) + return +} + +//go:wasmimport wasi:sockets/udp@0.2.1 [method]incoming-datagram-stream.receive +//go:noescape +func wasmimport_IncomingDatagramStreamReceive(self0 uint32, maxResults0 uint64, result *cm.Result[cm.List[IncomingDatagram], cm.List[IncomingDatagram], network.ErrorCode]) + +// Subscribe represents the imported method "subscribe". +// +// Create a `pollable` which will resolve once the stream is ready to receive again. +// +// Note: this function is here for WASI Preview2 only. +// It's planned to be removed when `future` is natively supported in Preview3. +// +// subscribe: func() -> pollable +// +//go:nosplit +func (self IncomingDatagramStream) Subscribe() (result poll.Pollable) { + self0 := cm.Reinterpret[uint32](self) + result0 := wasmimport_IncomingDatagramStreamSubscribe((uint32)(self0)) + result = cm.Reinterpret[poll.Pollable]((uint32)(result0)) + return +} + +//go:wasmimport wasi:sockets/udp@0.2.1 [method]incoming-datagram-stream.subscribe +//go:noescape +func wasmimport_IncomingDatagramStreamSubscribe(self0 uint32) (result0 uint32) + +// OutgoingDatagramStream represents the imported resource "wasi:sockets/udp@0.2.1#outgoing-datagram-stream". +// +// resource outgoing-datagram-stream +type OutgoingDatagramStream cm.Resource + +// ResourceDrop represents the imported resource-drop for resource "outgoing-datagram-stream". +// +// Drops a resource handle. +// +//go:nosplit +func (self OutgoingDatagramStream) ResourceDrop() { + self0 := cm.Reinterpret[uint32](self) + wasmimport_OutgoingDatagramStreamResourceDrop((uint32)(self0)) + return +} + +//go:wasmimport wasi:sockets/udp@0.2.1 [resource-drop]outgoing-datagram-stream +//go:noescape +func wasmimport_OutgoingDatagramStreamResourceDrop(self0 uint32) + +// CheckSend represents the imported method "check-send". +// +// Check readiness for sending. This function never blocks. +// +// Returns the number of datagrams permitted for the next call to `send`, +// or an error. Calling `send` with more datagrams than this function has +// permitted will trap. +// +// When this function returns ok(0), the `subscribe` pollable will +// become ready when this function will report at least ok(1), or an +// error. +// +// Never returns `would-block`. +// +// check-send: func() -> result +// +//go:nosplit +func (self OutgoingDatagramStream) CheckSend() (result cm.Result[uint64, uint64, network.ErrorCode]) { + self0 := cm.Reinterpret[uint32](self) + wasmimport_OutgoingDatagramStreamCheckSend((uint32)(self0), &result) + return +} + +//go:wasmimport wasi:sockets/udp@0.2.1 [method]outgoing-datagram-stream.check-send +//go:noescape +func wasmimport_OutgoingDatagramStreamCheckSend(self0 uint32, result *cm.Result[uint64, uint64, network.ErrorCode]) + +// Send represents the imported method "send". +// +// Send messages on the socket. +// +// This function attempts to send all provided `datagrams` on the socket without blocking +// and +// returns how many messages were actually sent (or queued for sending). This function +// never +// returns `error(would-block)`. If none of the datagrams were able to be sent, `ok(0)` +// is returned. +// +// This function semantically behaves the same as iterating the `datagrams` list and +// sequentially +// sending each individual datagram until either the end of the list has been reached +// or the first error occurred. +// If at least one datagram has been sent successfully, this function never returns +// an error. +// +// If the input list is empty, the function returns `ok(0)`. +// +// Each call to `send` must be permitted by a preceding `check-send`. Implementations +// must trap if +// either `check-send` was not called or `datagrams` contains more items than `check-send` +// permitted. +// +// # Typical errors +// - `invalid-argument`: The `remote-address` has the wrong address family. +// (EAFNOSUPPORT) +// - `invalid-argument`: The IP address in `remote-address` is set to INADDR_ANY +// (`0.0.0.0` / `::`). (EDESTADDRREQ, EADDRNOTAVAIL) +// - `invalid-argument`: The port in `remote-address` is set to 0. (EDESTADDRREQ, +// EADDRNOTAVAIL) +// - `invalid-argument`: The socket is in "connected" mode and `remote-address` +// is `some` value that does not match the address passed to `stream`. (EISCONN) +// - `invalid-argument`: The socket is not "connected" and no value for `remote-address` +// was provided. (EDESTADDRREQ) +// - `remote-unreachable`: The remote address is not reachable. (ECONNRESET, +// ENETRESET on Windows, EHOSTUNREACH, EHOSTDOWN, ENETUNREACH, ENETDOWN, ENONET) +// - `connection-refused`: The connection was refused. (ECONNREFUSED) +// - `datagram-too-large`: The datagram is too large. (EMSGSIZE) +// +// # References +// - +// - +// - +// - +// - +// - +// - +// - +// +// send: func(datagrams: list) -> result +// +//go:nosplit +func (self OutgoingDatagramStream) Send(datagrams cm.List[OutgoingDatagram]) (result cm.Result[uint64, uint64, network.ErrorCode]) { + self0 := cm.Reinterpret[uint32](self) + datagrams0, datagrams1 := cm.LowerList(datagrams) + wasmimport_OutgoingDatagramStreamSend((uint32)(self0), (*OutgoingDatagram)(datagrams0), (uint32)(datagrams1), &result) + return +} + +//go:wasmimport wasi:sockets/udp@0.2.1 [method]outgoing-datagram-stream.send +//go:noescape +func wasmimport_OutgoingDatagramStreamSend(self0 uint32, datagrams0 *OutgoingDatagram, datagrams1 uint32, result *cm.Result[uint64, uint64, network.ErrorCode]) + +// Subscribe represents the imported method "subscribe". +// +// Create a `pollable` which will resolve once the stream is ready to send again. +// +// Note: this function is here for WASI Preview2 only. +// It's planned to be removed when `future` is natively supported in Preview3. +// +// subscribe: func() -> pollable +// +//go:nosplit +func (self OutgoingDatagramStream) Subscribe() (result poll.Pollable) { + self0 := cm.Reinterpret[uint32](self) + result0 := wasmimport_OutgoingDatagramStreamSubscribe((uint32)(self0)) + result = cm.Reinterpret[poll.Pollable]((uint32)(result0)) + return +} + +//go:wasmimport wasi:sockets/udp@0.2.1 [method]outgoing-datagram-stream.subscribe +//go:noescape +func wasmimport_OutgoingDatagramStreamSubscribe(self0 uint32) (result0 uint32) diff --git a/examples/go/http/bindings/west-examples/http/app/app.wit.go b/examples/go/http/bindings/west-examples/http/app/app.wit.go new file mode 100644 index 0000000..324bc91 --- /dev/null +++ b/examples/go/http/bindings/west-examples/http/app/app.wit.go @@ -0,0 +1,4 @@ +// Code generated by wit-bindgen-go. DO NOT EDIT. + +// Package app represents the world "west-examples:http/app". +package app diff --git a/examples/go/http/http.go b/examples/go/http/http.go new file mode 100644 index 0000000..4a82908 --- /dev/null +++ b/examples/go/http/http.go @@ -0,0 +1,64 @@ +//go:generate go run github.com/bytecodealliance/wasm-tools-go/cmd/wit-bindgen-go generate -w app -o bindings ./wit + +package wasi + +import ( + "log/slog" + "unsafe" + + "github.com/bytecodealliance/wasm-tools-go/cm" + incominghandler "github.com/rvolosatovs/west/tests/go/wasi/bindings/wasi/http/incoming-handler" + "github.com/rvolosatovs/west/tests/go/wasi/bindings/wasi/http/types" +) + +func init() { + incominghandler.Exports.Handle = func(request types.IncomingRequest, responseOut types.ResponseOutparam) { + if err := handle(request, responseOut); err != nil { + types.ResponseOutparamSet(responseOut, cm.Err[cm.Result[types.ErrorCodeShape, types.OutgoingResponse, types.ErrorCode]](*err)) + } + } +} + +func ptr[T any](v T) *T { + return &v +} + +func handle(req types.IncomingRequest, out types.ResponseOutparam) *types.ErrorCode { + slog.Debug("constructing new response") + resp := types.NewOutgoingResponse(req.Headers()) + + slog.Debug("getting response body") + body := resp.Body() + if body.IsErr() { + slog.Debug("failed to get response body") + return ptr(types.ErrorCodeInternalError(cm.Some("failed to get response body"))) + } + bodyOut := body.OK() + + slog.Debug("getting response body stream") + bodyWrite := bodyOut.Write() + if bodyWrite.IsErr() { + slog.Debug("failed to get response body stream") + return ptr(types.ErrorCodeInternalError(cm.Some("failed to get response body stream"))) + } + + slog.Debug("setting response outparam") + types.ResponseOutparamSet(out, cm.OK[cm.Result[types.ErrorCodeShape, types.OutgoingResponse, types.ErrorCode]](resp)) + stream := bodyWrite.OK() + s := "foo bar baz" + writeRes := stream.BlockingWriteAndFlush(cm.NewList(unsafe.StringData(s), uint(len(s)))) + if writeRes.IsErr() { + slog.Error("failed to write to stream", "err", writeRes.Err()) + return nil + } + slog.Debug("dropping body stream") + stream.ResourceDrop() + + slog.Debug("finishing outgoing body") + finishRes := types.OutgoingBodyFinish(*bodyOut, cm.None[types.Fields]()) + if finishRes.IsErr() { + slog.Error("failed to finish outgoing body", "err", finishRes.Err()) + return nil + } + return nil +} diff --git a/examples/go/http/http_test.go b/examples/go/http/http_test.go new file mode 100644 index 0000000..58c92fb --- /dev/null +++ b/examples/go/http/http_test.go @@ -0,0 +1,102 @@ +//go:generate go run github.com/rvolosatovs/west/cmd/west-bindgen-go + +package wasi_test + +import ( + "testing" + "unsafe" + + "github.com/bytecodealliance/wasm-tools-go/cm" + west "github.com/rvolosatovs/west" + _ "github.com/rvolosatovs/west/bindings" + testtypes "github.com/rvolosatovs/west/bindings/wasi/http/types" + httpext "github.com/rvolosatovs/west/bindings/wasiext/http/ext" + incominghandler "github.com/rvolosatovs/west/tests/go/wasi/bindings/wasi/http/incoming-handler" + "github.com/rvolosatovs/west/tests/go/wasi/bindings/wasi/http/types" + "github.com/stretchr/testify/assert" +) + +func TestIncomingHandler(t *testing.T) { + west.RunTest(t, func() { + headers := testtypes.NewFields() + headers.Append( + testtypes.FieldKey("foo"), + testtypes.FieldValue(cm.NewList( + unsafe.SliceData([]byte("bar")), + 3, + )), + ) + headers.Append( + testtypes.FieldKey("foo"), + testtypes.FieldValue(cm.NewList( + unsafe.SliceData([]byte("baz")), + 3, + )), + ) + headers.Set( + testtypes.FieldKey("key"), + cm.NewList( + unsafe.SliceData( + []testtypes.FieldValue{ + testtypes.FieldValue(cm.NewList( + unsafe.SliceData([]byte("value")), + 5, + )), + }, + ), + 1, + ), + ) + req := testtypes.NewOutgoingRequest(headers) + req.SetPathWithQuery(cm.Some("test")) + req.SetMethod(testtypes.MethodGet()) + out := httpext.NewResponseOutparam() + incominghandler.Exports.Handle( + types.IncomingRequest(httpext.NewIncomingRequest(req)), + types.ResponseOutparam(out.F0), + ) + out.F1.Subscribe().Block() + respOptResRes := out.F1.Get() + respResRes := respOptResRes.Some() + if !assert.NotNil(t, respResRes) { + t.FailNow() + } + respRes := respResRes.OK() + if !assert.NotNil(t, respRes) || !assert.Nil(t, respRes.Err()) { + t.FailNow() + } + resp := respRes.OK() + assert.Equal(t, testtypes.StatusCode(200), resp.Status()) + hs := map[string][][]byte{} + for _, h := range resp.Headers().Entries().Slice() { + k := string(h.F0) + hs[k] = append(hs[k], h.F1.Slice()) + } + assert.Equal(t, map[string][][]byte{ + "foo": { + []byte("bar"), + []byte("baz"), + }, + "key": { + []byte("value"), + }, + }, hs) + bodyRes := resp.Consume() + body := bodyRes.OK() + if !assert.NotNil(t, body) { + t.FailNow() + } + bodyStreamRes := body.Stream() + bodyStream := bodyStreamRes.OK() + if !assert.NotNil(t, bodyStream) { + t.FailNow() + } + bufRes := bodyStream.BlockingRead(4096) + buf := bufRes.OK() + if !assert.NotNil(t, buf) { + t.FailNow() + } + assert.Equal(t, []byte("foo bar baz"), buf.Slice()) + bodyStream.ResourceDrop() + }) +} diff --git a/examples/go/http/wit/app.wit b/examples/go/http/wit/app.wit new file mode 100644 index 0000000..245ac56 --- /dev/null +++ b/examples/go/http/wit/app.wit @@ -0,0 +1,8 @@ +package west-examples:http; + +world app { + include wasi:http/proxy@0.2.1; + + // Import all CLI interfaces, which are used by Go libraries + include wasi:cli/imports@0.2.1; +} diff --git a/examples/go/http/wit/deps.lock b/examples/go/http/wit/deps.lock new file mode 100644 index 0000000..463fc62 --- /dev/null +++ b/examples/go/http/wit/deps.lock @@ -0,0 +1,29 @@ +[cli] +sha256 = "1de50b8e6940e73110cda10b7f90ca87a8fea886f0fa36c748f96dc70671ee38" +sha512 = "bbb6cd3e7b4d3237b6af9bfbb2633ccd2c4ea2a4f37b8c033255c7e0c1cb037be7f22ec1f8ca792cc8ec1942199582943979e646b4b272b85dcff7654eac51d0" + +[clocks] +sha256 = "ea9d69ee803bc176e23e5268f5e24a2ac485dd1f62a0ab4c748e9d3f901f576f" +sha512 = "5efc22927c46cd56c41e5549ec775561c7fac2ea0d365abc0b55396d9475a7c9f984077a81f84a44a726f1c008fd2fadbffffa4fa53ecd5fbfd05afd379ab428" + +[filesystem] +sha256 = "cfe8c420e8b857de612ae2a3336680dae16b95c93c8ba3a6ff05b21210966740" +sha512 = "3c00c5544a58658e3e8025677091685286027fd49f37abf198c30b4e83b9e68f19723975aaa98794fba9f425ae9ef4f3dc0f5b9cf59203b5ecfaadf62b296f9a" + +[http] +url = "https://github.com/WebAssembly/wasi-http/archive/v0.2.1.tar.gz" +sha256 = "ff21e05571af02488371bebc9cb674e30e0613eda22e3c1d8e1aba36cdff5ee8" +sha512 = "1825b56f1718e822acf1b49929ead8f6493752b1d3524ce0974c3acdf656af2fc3fe5c8456b71ffab44583bc3ae7061d5a285d8a7203fcae949d44b3d81e2f2b" +deps = ["cli", "clocks", "filesystem", "io", "random", "sockets"] + +[io] +sha256 = "2a74bd811adc46b5a0f19827ddbde89870e52b17615f4d0873f06fd977250caf" +sha512 = "94624f00c66e66203592cee820f80b1ba91ecdb71f682c154f25eaf71f8d8954197dcb64503bc21e72ed5e812af7eae876df47b7eb727b02db3a74a7ce0aefca" + +[random] +sha256 = "9e2d5056186f81b2e7f96bc97d2babd0341840f6abb4f170449b70992f1b598f" +sha512 = "67bf41d8d5d4b7af084124ee85196585225785969059f59e2f9ddb77ac1a8095cfe811ae29d076aac817418fa01064d7b9fbc0233930bace680758eeb21e36f8" + +[sockets] +sha256 = "4c361137a7e61e8b9a73da2a0899dd9ad1a0c2dfee7d310cf168704c57b7a07c" +sha512 = "348b4ef381f57aec23d48537df8b69ab8963587dcb056e94c4cd5657e217677a4ee2a545868a5c829d2334cc6b8b0a61d3e72797999f44d78553fbd3a73c5b8d" diff --git a/examples/go/http/wit/deps.toml b/examples/go/http/wit/deps.toml new file mode 100644 index 0000000..77a7d11 --- /dev/null +++ b/examples/go/http/wit/deps.toml @@ -0,0 +1 @@ +http = "https://github.com/WebAssembly/wasi-http/archive/v0.2.1.tar.gz" diff --git a/examples/go/http/wit/deps/cli/command.wit b/examples/go/http/wit/deps/cli/command.wit new file mode 100644 index 0000000..dc064a3 --- /dev/null +++ b/examples/go/http/wit/deps/cli/command.wit @@ -0,0 +1,10 @@ +package wasi:cli@0.2.1; + +@since(version = 0.2.0) +world command { + @since(version = 0.2.0) + include imports; + + @since(version = 0.2.0) + export run; +} diff --git a/examples/go/http/wit/deps/cli/environment.wit b/examples/go/http/wit/deps/cli/environment.wit new file mode 100644 index 0000000..2f449bd --- /dev/null +++ b/examples/go/http/wit/deps/cli/environment.wit @@ -0,0 +1,22 @@ +@since(version = 0.2.0) +interface environment { + /// Get the POSIX-style environment variables. + /// + /// Each environment variable is provided as a pair of string variable names + /// and string value. + /// + /// Morally, these are a value import, but until value imports are available + /// in the component model, this import function should return the same + /// values each time it is called. + @since(version = 0.2.0) + get-environment: func() -> list>; + + /// Get the POSIX-style arguments to the program. + @since(version = 0.2.0) + get-arguments: func() -> list; + + /// Return a path that programs should use as their initial current working + /// directory, interpreting `.` as shorthand for this. + @since(version = 0.2.0) + initial-cwd: func() -> option; +} diff --git a/examples/go/http/wit/deps/cli/exit.wit b/examples/go/http/wit/deps/cli/exit.wit new file mode 100644 index 0000000..427935c --- /dev/null +++ b/examples/go/http/wit/deps/cli/exit.wit @@ -0,0 +1,17 @@ +@since(version = 0.2.0) +interface exit { + /// Exit the current instance and any linked instances. + @since(version = 0.2.0) + exit: func(status: result); + + /// Exit the current instance and any linked instances, reporting the + /// specified status code to the host. + /// + /// The meaning of the code depends on the context, with 0 usually meaning + /// "success", and other values indicating various types of failure. + /// + /// This function does not return; the effect is analogous to a trap, but + /// without the connotation that something bad has happened. + @unstable(feature = cli-exit-with-code) + exit-with-code: func(status-code: u8); +} diff --git a/examples/go/http/wit/deps/cli/imports.wit b/examples/go/http/wit/deps/cli/imports.wit new file mode 100644 index 0000000..b8339d3 --- /dev/null +++ b/examples/go/http/wit/deps/cli/imports.wit @@ -0,0 +1,36 @@ +package wasi:cli@0.2.1; + +@since(version = 0.2.0) +world imports { + @since(version = 0.2.0) + include wasi:clocks/imports@0.2.1; + @since(version = 0.2.0) + include wasi:filesystem/imports@0.2.1; + @since(version = 0.2.0) + include wasi:sockets/imports@0.2.1; + @since(version = 0.2.0) + include wasi:random/imports@0.2.1; + @since(version = 0.2.0) + include wasi:io/imports@0.2.1; + + @since(version = 0.2.0) + import environment; + @since(version = 0.2.0) + import exit; + @since(version = 0.2.0) + import stdin; + @since(version = 0.2.0) + import stdout; + @since(version = 0.2.0) + import stderr; + @since(version = 0.2.0) + import terminal-input; + @since(version = 0.2.0) + import terminal-output; + @since(version = 0.2.0) + import terminal-stdin; + @since(version = 0.2.0) + import terminal-stdout; + @since(version = 0.2.0) + import terminal-stderr; +} diff --git a/examples/go/http/wit/deps/cli/run.wit b/examples/go/http/wit/deps/cli/run.wit new file mode 100644 index 0000000..655346e --- /dev/null +++ b/examples/go/http/wit/deps/cli/run.wit @@ -0,0 +1,6 @@ +@since(version = 0.2.0) +interface run { + /// Run the program. + @since(version = 0.2.0) + run: func() -> result; +} diff --git a/examples/go/http/wit/deps/cli/stdio.wit b/examples/go/http/wit/deps/cli/stdio.wit new file mode 100644 index 0000000..d1d26eb --- /dev/null +++ b/examples/go/http/wit/deps/cli/stdio.wit @@ -0,0 +1,26 @@ +@since(version = 0.2.0) +interface stdin { + @since(version = 0.2.0) + use wasi:io/streams@0.2.1.{input-stream}; + + @since(version = 0.2.0) + get-stdin: func() -> input-stream; +} + +@since(version = 0.2.0) +interface stdout { + @since(version = 0.2.0) + use wasi:io/streams@0.2.1.{output-stream}; + + @since(version = 0.2.0) + get-stdout: func() -> output-stream; +} + +@since(version = 0.2.0) +interface stderr { + @since(version = 0.2.0) + use wasi:io/streams@0.2.1.{output-stream}; + + @since(version = 0.2.0) + get-stderr: func() -> output-stream; +} diff --git a/examples/go/http/wit/deps/cli/terminal.wit b/examples/go/http/wit/deps/cli/terminal.wit new file mode 100644 index 0000000..d305498 --- /dev/null +++ b/examples/go/http/wit/deps/cli/terminal.wit @@ -0,0 +1,62 @@ +/// Terminal input. +/// +/// In the future, this may include functions for disabling echoing, +/// disabling input buffering so that keyboard events are sent through +/// immediately, querying supported features, and so on. +@since(version = 0.2.0) +interface terminal-input { + /// The input side of a terminal. + @since(version = 0.2.0) + resource terminal-input; +} + +/// Terminal output. +/// +/// In the future, this may include functions for querying the terminal +/// size, being notified of terminal size changes, querying supported +/// features, and so on. +@since(version = 0.2.0) +interface terminal-output { + /// The output side of a terminal. + @since(version = 0.2.0) + resource terminal-output; +} + +/// An interface providing an optional `terminal-input` for stdin as a +/// link-time authority. +@since(version = 0.2.0) +interface terminal-stdin { + @since(version = 0.2.0) + use terminal-input.{terminal-input}; + + /// If stdin is connected to a terminal, return a `terminal-input` handle + /// allowing further interaction with it. + @since(version = 0.2.0) + get-terminal-stdin: func() -> option; +} + +/// An interface providing an optional `terminal-output` for stdout as a +/// link-time authority. +@since(version = 0.2.0) +interface terminal-stdout { + @since(version = 0.2.0) + use terminal-output.{terminal-output}; + + /// If stdout is connected to a terminal, return a `terminal-output` handle + /// allowing further interaction with it. + @since(version = 0.2.0) + get-terminal-stdout: func() -> option; +} + +/// An interface providing an optional `terminal-output` for stderr as a +/// link-time authority. +@since(version = 0.2.0) +interface terminal-stderr { + @since(version = 0.2.0) + use terminal-output.{terminal-output}; + + /// If stderr is connected to a terminal, return a `terminal-output` handle + /// allowing further interaction with it. + @since(version = 0.2.0) + get-terminal-stderr: func() -> option; +} diff --git a/examples/go/http/wit/deps/clocks/monotonic-clock.wit b/examples/go/http/wit/deps/clocks/monotonic-clock.wit new file mode 100644 index 0000000..3c24840 --- /dev/null +++ b/examples/go/http/wit/deps/clocks/monotonic-clock.wit @@ -0,0 +1,50 @@ +package wasi:clocks@0.2.1; +/// WASI Monotonic Clock is a clock API intended to let users measure elapsed +/// time. +/// +/// It is intended to be portable at least between Unix-family platforms and +/// Windows. +/// +/// A monotonic clock is a clock which has an unspecified initial value, and +/// successive reads of the clock will produce non-decreasing values. +@since(version = 0.2.0) +interface monotonic-clock { + @since(version = 0.2.0) + use wasi:io/poll@0.2.1.{pollable}; + + /// An instant in time, in nanoseconds. An instant is relative to an + /// unspecified initial value, and can only be compared to instances from + /// the same monotonic-clock. + @since(version = 0.2.0) + type instant = u64; + + /// A duration of time, in nanoseconds. + @since(version = 0.2.0) + type duration = u64; + + /// Read the current value of the clock. + /// + /// The clock is monotonic, therefore calling this function repeatedly will + /// produce a sequence of non-decreasing values. + @since(version = 0.2.0) + now: func() -> instant; + + /// Query the resolution of the clock. Returns the duration of time + /// corresponding to a clock tick. + @since(version = 0.2.0) + resolution: func() -> duration; + + /// Create a `pollable` which will resolve once the specified instant + /// has occurred. + @since(version = 0.2.0) + subscribe-instant: func( + when: instant, + ) -> pollable; + + /// Create a `pollable` that will resolve after the specified duration has + /// elapsed from the time this function is invoked. + @since(version = 0.2.0) + subscribe-duration: func( + when: duration, + ) -> pollable; +} diff --git a/examples/go/http/wit/deps/clocks/timezone.wit b/examples/go/http/wit/deps/clocks/timezone.wit new file mode 100644 index 0000000..212da66 --- /dev/null +++ b/examples/go/http/wit/deps/clocks/timezone.wit @@ -0,0 +1,55 @@ +package wasi:clocks@0.2.1; + +@unstable(feature = clocks-timezone) +interface timezone { + @unstable(feature = clocks-timezone) + use wall-clock.{datetime}; + + /// Return information needed to display the given `datetime`. This includes + /// the UTC offset, the time zone name, and a flag indicating whether + /// daylight saving time is active. + /// + /// If the timezone cannot be determined for the given `datetime`, return a + /// `timezone-display` for `UTC` with a `utc-offset` of 0 and no daylight + /// saving time. + @unstable(feature = clocks-timezone) + display: func(when: datetime) -> timezone-display; + + /// The same as `display`, but only return the UTC offset. + @unstable(feature = clocks-timezone) + utc-offset: func(when: datetime) -> s32; + + /// Information useful for displaying the timezone of a specific `datetime`. + /// + /// This information may vary within a single `timezone` to reflect daylight + /// saving time adjustments. + @unstable(feature = clocks-timezone) + record timezone-display { + /// The number of seconds difference between UTC time and the local + /// time of the timezone. + /// + /// The returned value will always be less than 86400 which is the + /// number of seconds in a day (24*60*60). + /// + /// In implementations that do not expose an actual time zone, this + /// should return 0. + utc-offset: s32, + + /// The abbreviated name of the timezone to display to a user. The name + /// `UTC` indicates Coordinated Universal Time. Otherwise, this should + /// reference local standards for the name of the time zone. + /// + /// In implementations that do not expose an actual time zone, this + /// should be the string `UTC`. + /// + /// In time zones that do not have an applicable name, a formatted + /// representation of the UTC offset may be returned, such as `-04:00`. + name: string, + + /// Whether daylight saving time is active. + /// + /// In implementations that do not expose an actual time zone, this + /// should return false. + in-daylight-saving-time: bool, + } +} diff --git a/examples/go/http/wit/deps/clocks/wall-clock.wit b/examples/go/http/wit/deps/clocks/wall-clock.wit new file mode 100644 index 0000000..6be069a --- /dev/null +++ b/examples/go/http/wit/deps/clocks/wall-clock.wit @@ -0,0 +1,46 @@ +package wasi:clocks@0.2.1; +/// WASI Wall Clock is a clock API intended to let users query the current +/// time. The name "wall" makes an analogy to a "clock on the wall", which +/// is not necessarily monotonic as it may be reset. +/// +/// It is intended to be portable at least between Unix-family platforms and +/// Windows. +/// +/// A wall clock is a clock which measures the date and time according to +/// some external reference. +/// +/// External references may be reset, so this clock is not necessarily +/// monotonic, making it unsuitable for measuring elapsed time. +/// +/// It is intended for reporting the current date and time for humans. +@since(version = 0.2.0) +interface wall-clock { + /// A time and date in seconds plus nanoseconds. + @since(version = 0.2.0) + record datetime { + seconds: u64, + nanoseconds: u32, + } + + /// Read the current value of the clock. + /// + /// This clock is not monotonic, therefore calling this function repeatedly + /// will not necessarily produce a sequence of non-decreasing values. + /// + /// The returned timestamps represent the number of seconds since + /// 1970-01-01T00:00:00Z, also known as [POSIX's Seconds Since the Epoch], + /// also known as [Unix Time]. + /// + /// The nanoseconds field of the output is always less than 1000000000. + /// + /// [POSIX's Seconds Since the Epoch]: https://pubs.opengroup.org/onlinepubs/9699919799/xrat/V4_xbd_chap04.html#tag_21_04_16 + /// [Unix Time]: https://en.wikipedia.org/wiki/Unix_time + @since(version = 0.2.0) + now: func() -> datetime; + + /// Query the resolution of the clock. + /// + /// The nanoseconds field of the output is always less than 1000000000. + @since(version = 0.2.0) + resolution: func() -> datetime; +} diff --git a/examples/go/http/wit/deps/clocks/world.wit b/examples/go/http/wit/deps/clocks/world.wit new file mode 100644 index 0000000..9251ac6 --- /dev/null +++ b/examples/go/http/wit/deps/clocks/world.wit @@ -0,0 +1,11 @@ +package wasi:clocks@0.2.1; + +@since(version = 0.2.0) +world imports { + @since(version = 0.2.0) + import monotonic-clock; + @since(version = 0.2.0) + import wall-clock; + @unstable(feature = clocks-timezone) + import timezone; +} diff --git a/examples/go/http/wit/deps/filesystem/preopens.wit b/examples/go/http/wit/deps/filesystem/preopens.wit new file mode 100644 index 0000000..ca2f726 --- /dev/null +++ b/examples/go/http/wit/deps/filesystem/preopens.wit @@ -0,0 +1,11 @@ +package wasi:filesystem@0.2.1; + +@since(version = 0.2.0) +interface preopens { + @since(version = 0.2.0) + use types.{descriptor}; + + /// Return the set of preopened directories, and their path. + @since(version = 0.2.0) + get-directories: func() -> list>; +} diff --git a/examples/go/http/wit/deps/filesystem/types.wit b/examples/go/http/wit/deps/filesystem/types.wit new file mode 100644 index 0000000..db3d968 --- /dev/null +++ b/examples/go/http/wit/deps/filesystem/types.wit @@ -0,0 +1,678 @@ +package wasi:filesystem@0.2.1; +/// WASI filesystem is a filesystem API primarily intended to let users run WASI +/// programs that access their files on their existing filesystems, without +/// significant overhead. +/// +/// It is intended to be roughly portable between Unix-family platforms and +/// Windows, though it does not hide many of the major differences. +/// +/// Paths are passed as interface-type `string`s, meaning they must consist of +/// a sequence of Unicode Scalar Values (USVs). Some filesystems may contain +/// paths which are not accessible by this API. +/// +/// The directory separator in WASI is always the forward-slash (`/`). +/// +/// All paths in WASI are relative paths, and are interpreted relative to a +/// `descriptor` referring to a base directory. If a `path` argument to any WASI +/// function starts with `/`, or if any step of resolving a `path`, including +/// `..` and symbolic link steps, reaches a directory outside of the base +/// directory, or reaches a symlink to an absolute or rooted path in the +/// underlying filesystem, the function fails with `error-code::not-permitted`. +/// +/// For more information about WASI path resolution and sandboxing, see +/// [WASI filesystem path resolution]. +/// +/// [WASI filesystem path resolution]: https://github.com/WebAssembly/wasi-filesystem/blob/main/path-resolution.md +@since(version = 0.2.0) +interface types { + @since(version = 0.2.0) + use wasi:io/streams@0.2.1.{input-stream, output-stream, error}; + @since(version = 0.2.0) + use wasi:clocks/wall-clock@0.2.1.{datetime}; + + /// File size or length of a region within a file. + @since(version = 0.2.0) + type filesize = u64; + + /// The type of a filesystem object referenced by a descriptor. + /// + /// Note: This was called `filetype` in earlier versions of WASI. + @since(version = 0.2.0) + enum descriptor-type { + /// The type of the descriptor or file is unknown or is different from + /// any of the other types specified. + unknown, + /// The descriptor refers to a block device inode. + block-device, + /// The descriptor refers to a character device inode. + character-device, + /// The descriptor refers to a directory inode. + directory, + /// The descriptor refers to a named pipe. + fifo, + /// The file refers to a symbolic link inode. + symbolic-link, + /// The descriptor refers to a regular file inode. + regular-file, + /// The descriptor refers to a socket. + socket, + } + + /// Descriptor flags. + /// + /// Note: This was called `fdflags` in earlier versions of WASI. + @since(version = 0.2.0) + flags descriptor-flags { + /// Read mode: Data can be read. + read, + /// Write mode: Data can be written to. + write, + /// Request that writes be performed according to synchronized I/O file + /// integrity completion. The data stored in the file and the file's + /// metadata are synchronized. This is similar to `O_SYNC` in POSIX. + /// + /// The precise semantics of this operation have not yet been defined for + /// WASI. At this time, it should be interpreted as a request, and not a + /// requirement. + file-integrity-sync, + /// Request that writes be performed according to synchronized I/O data + /// integrity completion. Only the data stored in the file is + /// synchronized. This is similar to `O_DSYNC` in POSIX. + /// + /// The precise semantics of this operation have not yet been defined for + /// WASI. At this time, it should be interpreted as a request, and not a + /// requirement. + data-integrity-sync, + /// Requests that reads be performed at the same level of integrity + /// requested for writes. This is similar to `O_RSYNC` in POSIX. + /// + /// The precise semantics of this operation have not yet been defined for + /// WASI. At this time, it should be interpreted as a request, and not a + /// requirement. + requested-write-sync, + /// Mutating directories mode: Directory contents may be mutated. + /// + /// When this flag is unset on a descriptor, operations using the + /// descriptor which would create, rename, delete, modify the data or + /// metadata of filesystem objects, or obtain another handle which + /// would permit any of those, shall fail with `error-code::read-only` if + /// they would otherwise succeed. + /// + /// This may only be set on directories. + mutate-directory, + } + + /// File attributes. + /// + /// Note: This was called `filestat` in earlier versions of WASI. + @since(version = 0.2.0) + record descriptor-stat { + /// File type. + %type: descriptor-type, + /// Number of hard links to the file. + link-count: link-count, + /// For regular files, the file size in bytes. For symbolic links, the + /// length in bytes of the pathname contained in the symbolic link. + size: filesize, + /// Last data access timestamp. + /// + /// If the `option` is none, the platform doesn't maintain an access + /// timestamp for this file. + data-access-timestamp: option, + /// Last data modification timestamp. + /// + /// If the `option` is none, the platform doesn't maintain a + /// modification timestamp for this file. + data-modification-timestamp: option, + /// Last file status-change timestamp. + /// + /// If the `option` is none, the platform doesn't maintain a + /// status-change timestamp for this file. + status-change-timestamp: option, + } + + /// Flags determining the method of how paths are resolved. + @since(version = 0.2.0) + flags path-flags { + /// As long as the resolved path corresponds to a symbolic link, it is + /// expanded. + symlink-follow, + } + + /// Open flags used by `open-at`. + @since(version = 0.2.0) + flags open-flags { + /// Create file if it does not exist, similar to `O_CREAT` in POSIX. + create, + /// Fail if not a directory, similar to `O_DIRECTORY` in POSIX. + directory, + /// Fail if file already exists, similar to `O_EXCL` in POSIX. + exclusive, + /// Truncate file to size 0, similar to `O_TRUNC` in POSIX. + truncate, + } + + /// Number of hard links to an inode. + @since(version = 0.2.0) + type link-count = u64; + + /// When setting a timestamp, this gives the value to set it to. + @since(version = 0.2.0) + variant new-timestamp { + /// Leave the timestamp set to its previous value. + no-change, + /// Set the timestamp to the current time of the system clock associated + /// with the filesystem. + now, + /// Set the timestamp to the given value. + timestamp(datetime), + } + + /// A directory entry. + record directory-entry { + /// The type of the file referred to by this directory entry. + %type: descriptor-type, + + /// The name of the object. + name: string, + } + + /// Error codes returned by functions, similar to `errno` in POSIX. + /// Not all of these error codes are returned by the functions provided by this + /// API; some are used in higher-level library layers, and others are provided + /// merely for alignment with POSIX. + enum error-code { + /// Permission denied, similar to `EACCES` in POSIX. + access, + /// Resource unavailable, or operation would block, similar to `EAGAIN` and `EWOULDBLOCK` in POSIX. + would-block, + /// Connection already in progress, similar to `EALREADY` in POSIX. + already, + /// Bad descriptor, similar to `EBADF` in POSIX. + bad-descriptor, + /// Device or resource busy, similar to `EBUSY` in POSIX. + busy, + /// Resource deadlock would occur, similar to `EDEADLK` in POSIX. + deadlock, + /// Storage quota exceeded, similar to `EDQUOT` in POSIX. + quota, + /// File exists, similar to `EEXIST` in POSIX. + exist, + /// File too large, similar to `EFBIG` in POSIX. + file-too-large, + /// Illegal byte sequence, similar to `EILSEQ` in POSIX. + illegal-byte-sequence, + /// Operation in progress, similar to `EINPROGRESS` in POSIX. + in-progress, + /// Interrupted function, similar to `EINTR` in POSIX. + interrupted, + /// Invalid argument, similar to `EINVAL` in POSIX. + invalid, + /// I/O error, similar to `EIO` in POSIX. + io, + /// Is a directory, similar to `EISDIR` in POSIX. + is-directory, + /// Too many levels of symbolic links, similar to `ELOOP` in POSIX. + loop, + /// Too many links, similar to `EMLINK` in POSIX. + too-many-links, + /// Message too large, similar to `EMSGSIZE` in POSIX. + message-size, + /// Filename too long, similar to `ENAMETOOLONG` in POSIX. + name-too-long, + /// No such device, similar to `ENODEV` in POSIX. + no-device, + /// No such file or directory, similar to `ENOENT` in POSIX. + no-entry, + /// No locks available, similar to `ENOLCK` in POSIX. + no-lock, + /// Not enough space, similar to `ENOMEM` in POSIX. + insufficient-memory, + /// No space left on device, similar to `ENOSPC` in POSIX. + insufficient-space, + /// Not a directory or a symbolic link to a directory, similar to `ENOTDIR` in POSIX. + not-directory, + /// Directory not empty, similar to `ENOTEMPTY` in POSIX. + not-empty, + /// State not recoverable, similar to `ENOTRECOVERABLE` in POSIX. + not-recoverable, + /// Not supported, similar to `ENOTSUP` and `ENOSYS` in POSIX. + unsupported, + /// Inappropriate I/O control operation, similar to `ENOTTY` in POSIX. + no-tty, + /// No such device or address, similar to `ENXIO` in POSIX. + no-such-device, + /// Value too large to be stored in data type, similar to `EOVERFLOW` in POSIX. + overflow, + /// Operation not permitted, similar to `EPERM` in POSIX. + not-permitted, + /// Broken pipe, similar to `EPIPE` in POSIX. + pipe, + /// Read-only file system, similar to `EROFS` in POSIX. + read-only, + /// Invalid seek, similar to `ESPIPE` in POSIX. + invalid-seek, + /// Text file busy, similar to `ETXTBSY` in POSIX. + text-file-busy, + /// Cross-device link, similar to `EXDEV` in POSIX. + cross-device, + } + + /// File or memory access pattern advisory information. + @since(version = 0.2.0) + enum advice { + /// The application has no advice to give on its behavior with respect + /// to the specified data. + normal, + /// The application expects to access the specified data sequentially + /// from lower offsets to higher offsets. + sequential, + /// The application expects to access the specified data in a random + /// order. + random, + /// The application expects to access the specified data in the near + /// future. + will-need, + /// The application expects that it will not access the specified data + /// in the near future. + dont-need, + /// The application expects to access the specified data once and then + /// not reuse it thereafter. + no-reuse, + } + + /// A 128-bit hash value, split into parts because wasm doesn't have a + /// 128-bit integer type. + @since(version = 0.2.0) + record metadata-hash-value { + /// 64 bits of a 128-bit hash value. + lower: u64, + /// Another 64 bits of a 128-bit hash value. + upper: u64, + } + + /// A descriptor is a reference to a filesystem object, which may be a file, + /// directory, named pipe, special file, or other object on which filesystem + /// calls may be made. + @since(version = 0.2.0) + resource descriptor { + /// Return a stream for reading from a file, if available. + /// + /// May fail with an error-code describing why the file cannot be read. + /// + /// Multiple read, write, and append streams may be active on the same open + /// file and they do not interfere with each other. + /// + /// Note: This allows using `read-stream`, which is similar to `read` in POSIX. + @since(version = 0.2.0) + read-via-stream: func( + /// The offset within the file at which to start reading. + offset: filesize, + ) -> result; + + /// Return a stream for writing to a file, if available. + /// + /// May fail with an error-code describing why the file cannot be written. + /// + /// Note: This allows using `write-stream`, which is similar to `write` in + /// POSIX. + @since(version = 0.2.0) + write-via-stream: func( + /// The offset within the file at which to start writing. + offset: filesize, + ) -> result; + + /// Return a stream for appending to a file, if available. + /// + /// May fail with an error-code describing why the file cannot be appended. + /// + /// Note: This allows using `write-stream`, which is similar to `write` with + /// `O_APPEND` in in POSIX. + @since(version = 0.2.0) + append-via-stream: func() -> result; + + /// Provide file advisory information on a descriptor. + /// + /// This is similar to `posix_fadvise` in POSIX. + @since(version = 0.2.0) + advise: func( + /// The offset within the file to which the advisory applies. + offset: filesize, + /// The length of the region to which the advisory applies. + length: filesize, + /// The advice. + advice: advice + ) -> result<_, error-code>; + + /// Synchronize the data of a file to disk. + /// + /// This function succeeds with no effect if the file descriptor is not + /// opened for writing. + /// + /// Note: This is similar to `fdatasync` in POSIX. + @since(version = 0.2.0) + sync-data: func() -> result<_, error-code>; + + /// Get flags associated with a descriptor. + /// + /// Note: This returns similar flags to `fcntl(fd, F_GETFL)` in POSIX. + /// + /// Note: This returns the value that was the `fs_flags` value returned + /// from `fdstat_get` in earlier versions of WASI. + @since(version = 0.2.0) + get-flags: func() -> result; + + /// Get the dynamic type of a descriptor. + /// + /// Note: This returns the same value as the `type` field of the `fd-stat` + /// returned by `stat`, `stat-at` and similar. + /// + /// Note: This returns similar flags to the `st_mode & S_IFMT` value provided + /// by `fstat` in POSIX. + /// + /// Note: This returns the value that was the `fs_filetype` value returned + /// from `fdstat_get` in earlier versions of WASI. + @since(version = 0.2.0) + get-type: 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.2.0) + set-size: func(size: filesize) -> result<_, error-code>; + + /// Adjust the timestamps of an open file or directory. + /// + /// Note: This is similar to `futimens` in POSIX. + /// + /// Note: This was called `fd_filestat_set_times` in earlier versions of WASI. + @since(version = 0.2.0) + set-times: func( + /// The desired values of the data access timestamp. + data-access-timestamp: new-timestamp, + /// The desired values of the data modification timestamp. + data-modification-timestamp: new-timestamp, + ) -> result<_, error-code>; + + /// Read from a descriptor, without using and updating the descriptor's offset. + /// + /// This function returns a list of bytes containing the data that was + /// read, along with a bool which, when true, indicates that the end of the + /// file was reached. The returned list will contain up to `length` bytes; it + /// may return fewer than requested, if the end of the file is reached or + /// if the I/O operation is interrupted. + /// + /// In the future, this may change to return a `stream`. + /// + /// Note: This is similar to `pread` in POSIX. + @since(version = 0.2.0) + read: func( + /// The maximum number of bytes to read. + length: filesize, + /// The offset within the file at which to read. + offset: filesize, + ) -> result, bool>, error-code>; + + /// Write to a descriptor, without using and updating the descriptor's offset. + /// + /// It is valid to write past the end of a file; the file is extended to the + /// extent of the write, with bytes between the previous end and the start of + /// the write set to zero. + /// + /// In the future, this may change to take a `stream`. + /// + /// Note: This is similar to `pwrite` in POSIX. + @since(version = 0.2.0) + write: func( + /// Data to write + buffer: list, + /// The offset within the file at which to write. + offset: filesize, + ) -> result; + + /// Read directory entries from a directory. + /// + /// On filesystems where directories contain entries referring to themselves + /// and their parents, often named `.` and `..` respectively, these entries + /// are omitted. + /// + /// This always returns a new stream which starts at the beginning of the + /// directory. Multiple streams may be active on the same directory, and they + /// do not interfere with each other. + @since(version = 0.2.0) + read-directory: func() -> result; + + /// Synchronize the data and metadata of a file to disk. + /// + /// This function succeeds with no effect if the file descriptor is not + /// opened for writing. + /// + /// Note: This is similar to `fsync` in POSIX. + @since(version = 0.2.0) + sync: func() -> result<_, error-code>; + + /// Create a directory. + /// + /// Note: This is similar to `mkdirat` in POSIX. + @since(version = 0.2.0) + create-directory-at: func( + /// The relative path at which to create the directory. + path: string, + ) -> result<_, error-code>; + + /// Return the attributes of an open file or directory. + /// + /// Note: This is similar to `fstat` in POSIX, except that it does not return + /// device and inode information. For testing whether two descriptors refer to + /// the same underlying filesystem object, use `is-same-object`. To obtain + /// additional data that can be used do determine whether a file has been + /// modified, use `metadata-hash`. + /// + /// Note: This was called `fd_filestat_get` in earlier versions of WASI. + @since(version = 0.2.0) + stat: func() -> result; + + /// Return the attributes of a file or directory. + /// + /// Note: This is similar to `fstatat` in POSIX, except that it does not + /// return device and inode information. See the `stat` description for a + /// discussion of alternatives. + /// + /// Note: This was called `path_filestat_get` in earlier versions of WASI. + @since(version = 0.2.0) + stat-at: 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. + path: string, + ) -> result; + + /// Adjust the timestamps of a file or directory. + /// + /// Note: This is similar to `utimensat` in POSIX. + /// + /// Note: This was called `path_filestat_set_times` in earlier versions of + /// WASI. + @since(version = 0.2.0) + set-times-at: 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. + path: string, + /// The desired values of the data access timestamp. + data-access-timestamp: new-timestamp, + /// The desired values of the data modification timestamp. + data-modification-timestamp: new-timestamp, + ) -> result<_, error-code>; + + /// Create a hard link. + /// + /// Note: This is similar to `linkat` in POSIX. + @since(version = 0.2.0) + link-at: func( + /// Flags determining the method of how the path is resolved. + old-path-flags: path-flags, + /// The relative source path from which to link. + old-path: string, + /// The base directory for `new-path`. + new-descriptor: borrow, + /// The relative destination path at which to create the hard link. + new-path: string, + ) -> result<_, error-code>; + + /// Open a file or directory. + /// + /// The returned descriptor is not guaranteed to be the lowest-numbered + /// descriptor not currently open/ it is randomized to prevent applications + /// from depending on making assumptions about indexes, since this is + /// error-prone in multi-threaded contexts. The returned descriptor is + /// guaranteed to be less than 2**31. + /// + /// If `flags` contains `descriptor-flags::mutate-directory`, and the base + /// descriptor doesn't have `descriptor-flags::mutate-directory` set, + /// `open-at` fails with `error-code::read-only`. + /// + /// If `flags` contains `write` or `mutate-directory`, or `open-flags` + /// contains `truncate` or `create`, and the base descriptor doesn't have + /// `descriptor-flags::mutate-directory` set, `open-at` fails with + /// `error-code::read-only`. + /// + /// Note: This is similar to `openat` in POSIX. + @since(version = 0.2.0) + open-at: func( + /// Flags determining the method of how the path is resolved. + path-flags: path-flags, + /// The relative path of the object to open. + path: string, + /// The method by which to open the file. + open-flags: open-flags, + /// Flags to use for the resulting descriptor. + %flags: descriptor-flags, + ) -> result; + + /// Read the contents of a symbolic link. + /// + /// If the contents contain an absolute or rooted path in the underlying + /// filesystem, this function fails with `error-code::not-permitted`. + /// + /// Note: This is similar to `readlinkat` in POSIX. + @since(version = 0.2.0) + readlink-at: func( + /// The relative path of the symbolic link from which to read. + path: string, + ) -> result; + + /// Remove a directory. + /// + /// Return `error-code::not-empty` if the directory is not empty. + /// + /// Note: This is similar to `unlinkat(fd, path, AT_REMOVEDIR)` in POSIX. + @since(version = 0.2.0) + remove-directory-at: func( + /// The relative path to a directory to remove. + path: string, + ) -> result<_, error-code>; + + /// Rename a filesystem object. + /// + /// Note: This is similar to `renameat` in POSIX. + @since(version = 0.2.0) + rename-at: func( + /// The relative source path of the file or directory to rename. + old-path: string, + /// The base directory for `new-path`. + new-descriptor: borrow, + /// The relative destination path to which to rename the file or directory. + new-path: string, + ) -> result<_, error-code>; + + /// Create a symbolic link (also known as a "symlink"). + /// + /// If `old-path` starts with `/`, the function fails with + /// `error-code::not-permitted`. + /// + /// Note: This is similar to `symlinkat` in POSIX. + @since(version = 0.2.0) + symlink-at: func( + /// The contents of the symbolic link. + old-path: string, + /// The relative destination path at which to create the symbolic link. + new-path: string, + ) -> result<_, error-code>; + + /// Unlink a filesystem object that is not a directory. + /// + /// 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.2.0) + unlink-file-at: func( + /// The relative path to a file to unlink. + path: string, + ) -> result<_, error-code>; + + /// Test whether two descriptors refer to the same filesystem object. + /// + /// In POSIX, this corresponds to testing whether the two descriptors have the + /// same device (`st_dev`) and inode (`st_ino` or `d_ino`) numbers. + /// wasi-filesystem does not expose device and inode numbers, so this function + /// may be used instead. + @since(version = 0.2.0) + is-same-object: func(other: borrow) -> bool; + + /// Return a hash of the metadata associated with a filesystem object referred + /// to by a descriptor. + /// + /// This returns a hash of the last-modification timestamp and file size, and + /// may also include the inode number, device number, birth timestamp, and + /// other metadata fields that may change when the file is modified or + /// replaced. It may also include a secret value chosen by the + /// implementation and not otherwise exposed. + /// + /// Implementations are encourated to provide the following properties: + /// + /// - If the file is not modified or replaced, the computed hash value should + /// usually not change. + /// - If the object is modified or replaced, the computed hash value should + /// usually change. + /// - The inputs to the hash should not be easily computable from the + /// computed hash. + /// + /// However, none of these is required. + @since(version = 0.2.0) + metadata-hash: 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.2.0) + metadata-hash-at: 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. + path: string, + ) -> result; + } + + /// A stream of directory entries. + @since(version = 0.2.0) + resource directory-entry-stream { + /// Read a single directory entry from a `directory-entry-stream`. + @since(version = 0.2.0) + read-directory-entry: func() -> result, error-code>; + } + + /// Attempts to extract a filesystem-related `error-code` from the stream + /// `error` provided. + /// + /// Stream operations which return `stream-error::last-operation-failed` + /// have a payload with more information about the operation that failed. + /// This payload can be passed through to this function to see if there's + /// filesystem-related information about the error to return. + /// + /// Note that this function is fallible because not all stream-related + /// errors are filesystem-related errors. + @since(version = 0.2.0) + filesystem-error-code: func(err: borrow) -> option; +} diff --git a/examples/go/http/wit/deps/filesystem/world.wit b/examples/go/http/wit/deps/filesystem/world.wit new file mode 100644 index 0000000..af0146c --- /dev/null +++ b/examples/go/http/wit/deps/filesystem/world.wit @@ -0,0 +1,9 @@ +package wasi:filesystem@0.2.1; + +@since(version = 0.2.0) +world imports { + @since(version = 0.2.0) + import types; + @since(version = 0.2.0) + import preopens; +} diff --git a/examples/go/http/wit/deps/http/handler.wit b/examples/go/http/wit/deps/http/handler.wit new file mode 100644 index 0000000..6a6c629 --- /dev/null +++ b/examples/go/http/wit/deps/http/handler.wit @@ -0,0 +1,49 @@ +/// This interface defines a handler of incoming HTTP Requests. It should +/// be exported by components which can respond to HTTP Requests. +@since(version = 0.2.0) +interface incoming-handler { + @since(version = 0.2.0) + use types.{incoming-request, response-outparam}; + + /// This function is invoked with an incoming HTTP Request, and a resource + /// `response-outparam` which provides the capability to reply with an HTTP + /// Response. The response is sent by calling the `response-outparam.set` + /// method, which allows execution to continue after the response has been + /// sent. This enables both streaming to the response body, and performing other + /// work. + /// + /// The implementor of this function must write a response to the + /// `response-outparam` before returning, or else the caller will respond + /// with an error on its behalf. + @since(version = 0.2.0) + handle: func( + request: incoming-request, + response-out: response-outparam + ); +} + +/// This interface defines a handler of outgoing HTTP Requests. It should be +/// imported by components which wish to make HTTP Requests. +@since(version = 0.2.0) +interface outgoing-handler { + @since(version = 0.2.0) + use types.{ + outgoing-request, request-options, future-incoming-response, error-code + }; + + /// This function is invoked with an outgoing HTTP Request, and it returns + /// a resource `future-incoming-response` which represents an HTTP Response + /// which may arrive in the future. + /// + /// The `options` argument accepts optional parameters for the HTTP + /// protocol's transport layer. + /// + /// This function may return an error if the `outgoing-request` is invalid + /// or not allowed to be made. Otherwise, protocol errors are reported + /// through the `future-incoming-response`. + @since(version = 0.2.0) + handle: func( + request: outgoing-request, + options: option + ) -> result; +} diff --git a/examples/go/http/wit/deps/http/proxy.wit b/examples/go/http/wit/deps/http/proxy.wit new file mode 100644 index 0000000..415d2ee --- /dev/null +++ b/examples/go/http/wit/deps/http/proxy.wit @@ -0,0 +1,50 @@ +package wasi:http@0.2.1; + +/// The `wasi:http/imports` world imports all the APIs for HTTP proxies. +/// It is intended to be `include`d in other worlds. +@since(version = 0.2.0) +world imports { + /// HTTP proxies have access to time and randomness. + @since(version = 0.2.0) + import wasi:clocks/monotonic-clock@0.2.1; + @since(version = 0.2.0) + import wasi:clocks/wall-clock@0.2.1; + @since(version = 0.2.0) + import wasi:random/random@0.2.1; + + /// Proxies have standard output and error streams which are expected to + /// terminate in a developer-facing console provided by the host. + @since(version = 0.2.0) + import wasi:cli/stdout@0.2.1; + @since(version = 0.2.0) + import wasi:cli/stderr@0.2.1; + + /// TODO: this is a temporary workaround until component tooling is able to + /// gracefully handle the absence of stdin. Hosts must return an eof stream + /// for this import, which is what wasi-libc + tooling will do automatically + /// when this import is properly removed. + @since(version = 0.2.0) + import wasi:cli/stdin@0.2.1; + + /// This is the default handler to use when user code simply wants to make an + /// HTTP request (e.g., via `fetch()`). + @since(version = 0.2.0) + import outgoing-handler; +} + +/// The `wasi:http/proxy` world captures a widely-implementable intersection of +/// hosts that includes HTTP forward and reverse proxies. Components targeting +/// this world may concurrently stream in and out any number of incoming and +/// outgoing HTTP requests. +@since(version = 0.2.0) +world proxy { + @since(version = 0.2.0) + include imports; + + /// The host delivers incoming HTTP requests to a component by calling the + /// `handle` function of this exported interface. A host may arbitrarily reuse + /// or not reuse component instance when delivering incoming HTTP requests and + /// thus a component must be able to handle 0..N calls to `handle`. + @since(version = 0.2.0) + export incoming-handler; +} diff --git a/examples/go/http/wit/deps/http/types.wit b/examples/go/http/wit/deps/http/types.wit new file mode 100644 index 0000000..3c45cd0 --- /dev/null +++ b/examples/go/http/wit/deps/http/types.wit @@ -0,0 +1,655 @@ +/// This interface defines all of the types and methods for implementing +/// HTTP Requests and Responses, both incoming and outgoing, as well as +/// their headers, trailers, and bodies. +@since(version = 0.2.0) +interface types { + @since(version = 0.2.0) + use wasi:clocks/monotonic-clock@0.2.1.{duration}; + @since(version = 0.2.0) + use wasi:io/streams@0.2.1.{input-stream, output-stream}; + @since(version = 0.2.0) + use wasi:io/error@0.2.1.{error as io-error}; + @since(version = 0.2.0) + use wasi:io/poll@0.2.1.{pollable}; + + /// This type corresponds to HTTP standard Methods. + @since(version = 0.2.0) + variant method { + get, + head, + post, + put, + delete, + connect, + options, + trace, + patch, + other(string) + } + + /// This type corresponds to HTTP standard Related Schemes. + @since(version = 0.2.0) + variant scheme { + HTTP, + HTTPS, + other(string) + } + + /// These cases are inspired by the IANA HTTP Proxy Error Types: + /// https://www.iana.org/assignments/http-proxy-status/http-proxy-status.xhtml#table-http-proxy-error-types + @since(version = 0.2.0) + variant error-code { + DNS-timeout, + DNS-error(DNS-error-payload), + destination-not-found, + destination-unavailable, + destination-IP-prohibited, + destination-IP-unroutable, + connection-refused, + connection-terminated, + connection-timeout, + connection-read-timeout, + connection-write-timeout, + connection-limit-reached, + TLS-protocol-error, + TLS-certificate-error, + TLS-alert-received(TLS-alert-received-payload), + HTTP-request-denied, + HTTP-request-length-required, + HTTP-request-body-size(option), + HTTP-request-method-invalid, + HTTP-request-URI-invalid, + HTTP-request-URI-too-long, + HTTP-request-header-section-size(option), + HTTP-request-header-size(option), + HTTP-request-trailer-section-size(option), + HTTP-request-trailer-size(field-size-payload), + HTTP-response-incomplete, + HTTP-response-header-section-size(option), + HTTP-response-header-size(field-size-payload), + HTTP-response-body-size(option), + HTTP-response-trailer-section-size(option), + HTTP-response-trailer-size(field-size-payload), + HTTP-response-transfer-coding(option), + HTTP-response-content-coding(option), + HTTP-response-timeout, + HTTP-upgrade-failed, + HTTP-protocol-error, + loop-detected, + configuration-error, + /// This is a catch-all error for anything that doesn't fit cleanly into a + /// more specific case. It also includes an optional string for an + /// unstructured description of the error. Users should not depend on the + /// string for diagnosing errors, as it's not required to be consistent + /// between implementations. + internal-error(option) + } + + /// Defines the case payload type for `DNS-error` above: + @since(version = 0.2.0) + record DNS-error-payload { + rcode: option, + info-code: option + } + + /// Defines the case payload type for `TLS-alert-received` above: + @since(version = 0.2.0) + record TLS-alert-received-payload { + alert-id: option, + alert-message: option + } + + /// Defines the case payload type for `HTTP-response-{header,trailer}-size` above: + @since(version = 0.2.0) + record field-size-payload { + field-name: option, + field-size: option + } + + /// Attempts to extract a http-related `error` from the wasi:io `error` + /// provided. + /// + /// Stream operations which return + /// `wasi:io/stream/stream-error::last-operation-failed` have a payload of + /// type `wasi:io/error/error` with more information about the operation + /// that failed. This payload can be passed through to this function to see + /// if there's http-related information about the error to return. + /// + /// Note that this function is fallible because not all io-errors are + /// http-related errors. + @since(version = 0.2.0) + http-error-code: func(err: borrow) -> option; + + /// This type enumerates the different kinds of errors that may occur when + /// setting or appending to a `fields` resource. + @since(version = 0.2.0) + variant header-error { + /// This error indicates that a `field-key` or `field-value` was + /// syntactically invalid when used with an operation that sets headers in a + /// `fields`. + invalid-syntax, + + /// This error indicates that a forbidden `field-key` was used when trying + /// to set a header in a `fields`. + forbidden, + + /// This error indicates that the operation on the `fields` was not + /// permitted because the fields are immutable. + immutable, + } + + /// Field keys are always strings. + @since(version = 0.2.0) + type field-key = string; + + /// Field values should always be ASCII strings. However, in + /// reality, HTTP implementations often have to interpret malformed values, + /// so they are provided as a list of bytes. + @since(version = 0.2.0) + type field-value = list; + + /// This following block defines the `fields` resource which corresponds to + /// HTTP standard Fields. Fields are a common representation used for both + /// Headers and Trailers. + /// + /// A `fields` may be mutable or immutable. A `fields` created using the + /// constructor, `from-list`, or `clone` will be mutable, but a `fields` + /// resource given by other means (including, but not limited to, + /// `incoming-request.headers`, `outgoing-request.headers`) might be be + /// immutable. In an immutable fields, the `set`, `append`, and `delete` + /// operations will fail with `header-error.immutable`. + @since(version = 0.2.0) + resource fields { + + /// Construct an empty HTTP Fields. + /// + /// The resulting `fields` is mutable. + @since(version = 0.2.0) + constructor(); + + /// Construct an HTTP Fields. + /// + /// The resulting `fields` is mutable. + /// + /// The list represents each key-value pair in the Fields. Keys + /// which have multiple values are represented by multiple entries in this + /// list with the same key. + /// + /// The tuple is a pair of the field key, represented as a string, and + /// Value, represented as a list of bytes. + /// + /// An error result will be returned if any `field-key` or `field-value` is + /// syntactically invalid, or if a field is forbidden. + @since(version = 0.2.0) + from-list: static func( + entries: list> + ) -> result; + + /// Get all of the values corresponding to a key. If the key is not present + /// in this `fields` or is syntactically invalid, an empty list is returned. + /// However, if the key is present but empty, this is represented by a list + /// with one or more empty field-values present. + @since(version = 0.2.0) + get: func(name: field-key) -> list; + + /// Returns `true` when the key is present in this `fields`. If the key is + /// syntactically invalid, `false` is returned. + @since(version = 0.2.0) + has: func(name: field-key) -> bool; + + /// Set all of the values for a key. Clears any existing values for that + /// key, if they have been set. + /// + /// Fails with `header-error.immutable` if the `fields` are immutable. + /// + /// Fails with `header-error.invalid-syntax` if the `field-key` or any of + /// the `field-value`s are syntactically invalid. + @since(version = 0.2.0) + set: func(name: field-key, value: list) -> result<_, header-error>; + + /// Delete all values for a key. Does nothing if no values for the key + /// exist. + /// + /// Fails with `header-error.immutable` if the `fields` are immutable. + /// + /// Fails with `header-error.invalid-syntax` if the `field-key` is + /// syntactically invalid. + @since(version = 0.2.0) + delete: func(name: field-key) -> result<_, header-error>; + + /// Append a value for a key. Does not change or delete any existing + /// values for that key. + /// + /// Fails with `header-error.immutable` if the `fields` are immutable. + /// + /// Fails with `header-error.invalid-syntax` if the `field-key` or + /// `field-value` are syntactically invalid. + @since(version = 0.2.0) + append: func(name: field-key, value: field-value) -> result<_, header-error>; + + /// Retrieve the full set of keys and values in the Fields. Like the + /// constructor, the list represents each key-value pair. + /// + /// The outer list represents each key-value pair in the Fields. Keys + /// which have multiple values are represented by multiple entries in this + /// list with the same key. + @since(version = 0.2.0) + entries: func() -> list>; + + /// Make a deep copy of the Fields. Equivalent in behavior to calling the + /// `fields` constructor on the return value of `entries`. The resulting + /// `fields` is mutable. + @since(version = 0.2.0) + clone: func() -> fields; + } + + /// Headers is an alias for Fields. + @since(version = 0.2.0) + type headers = fields; + + /// Trailers is an alias for Fields. + @since(version = 0.2.0) + type trailers = fields; + + /// Represents an incoming HTTP Request. + @since(version = 0.2.0) + resource incoming-request { + + /// Returns the method of the incoming request. + @since(version = 0.2.0) + method: func() -> method; + + /// Returns the path with query parameters from the request, as a string. + @since(version = 0.2.0) + path-with-query: func() -> option; + + /// Returns the protocol scheme from the request. + @since(version = 0.2.0) + scheme: func() -> option; + + /// Returns the authority of the Request's target URI, if present. + @since(version = 0.2.0) + authority: func() -> option; + + /// Get the `headers` associated with the request. + /// + /// The returned `headers` resource is immutable: `set`, `append`, and + /// `delete` operations will fail with `header-error.immutable`. + /// + /// The `headers` returned are a child resource: it must be dropped before + /// the parent `incoming-request` is dropped. Dropping this + /// `incoming-request` before all children are dropped will trap. + @since(version = 0.2.0) + headers: func() -> headers; + + /// Gives the `incoming-body` associated with this request. Will only + /// return success at most once, and subsequent calls will return error. + @since(version = 0.2.0) + consume: func() -> result; + } + + /// Represents an outgoing HTTP Request. + @since(version = 0.2.0) + resource outgoing-request { + + /// Construct a new `outgoing-request` with a default `method` of `GET`, and + /// `none` values for `path-with-query`, `scheme`, and `authority`. + /// + /// * `headers` is the HTTP Headers for the Request. + /// + /// It is possible to construct, or manipulate with the accessor functions + /// below, an `outgoing-request` with an invalid combination of `scheme` + /// and `authority`, or `headers` which are not permitted to be sent. + /// It is the obligation of the `outgoing-handler.handle` implementation + /// to reject invalid constructions of `outgoing-request`. + @since(version = 0.2.0) + constructor( + headers: headers + ); + + /// Returns the resource corresponding to the outgoing Body for this + /// Request. + /// + /// Returns success on the first call: the `outgoing-body` resource for + /// this `outgoing-request` can be retrieved at most once. Subsequent + /// calls will return error. + @since(version = 0.2.0) + body: func() -> result; + + /// Get the Method for the Request. + @since(version = 0.2.0) + method: func() -> method; + /// Set the Method for the Request. Fails if the string present in a + /// `method.other` argument is not a syntactically valid method. + @since(version = 0.2.0) + set-method: func(method: method) -> result; + + /// Get the combination of the HTTP Path and Query for the Request. + /// When `none`, this represents an empty Path and empty Query. + @since(version = 0.2.0) + path-with-query: func() -> option; + /// Set the combination of the HTTP Path and Query for the Request. + /// When `none`, this represents an empty Path and empty Query. Fails is the + /// string given is not a syntactically valid path and query uri component. + @since(version = 0.2.0) + set-path-with-query: func(path-with-query: option) -> result; + + /// Get the HTTP Related Scheme for the Request. When `none`, the + /// implementation may choose an appropriate default scheme. + @since(version = 0.2.0) + scheme: func() -> option; + /// Set the HTTP Related Scheme for the Request. When `none`, the + /// implementation may choose an appropriate default scheme. Fails if the + /// string given is not a syntactically valid uri scheme. + @since(version = 0.2.0) + set-scheme: func(scheme: option) -> result; + + /// Get the authority of the Request's target URI. A value of `none` may be used + /// with Related Schemes which do not require an authority. The HTTP and + /// HTTPS schemes always require an authority. + @since(version = 0.2.0) + authority: func() -> option; + /// Set the authority of the Request's target URI. A value of `none` may be used + /// with Related Schemes which do not require an authority. The HTTP and + /// HTTPS schemes always require an authority. Fails if the string given is + /// not a syntactically valid URI authority. + @since(version = 0.2.0) + set-authority: func(authority: option) -> result; + + /// Get the headers associated with the Request. + /// + /// The returned `headers` resource is immutable: `set`, `append`, and + /// `delete` operations will fail with `header-error.immutable`. + /// + /// This headers resource is a child: it must be dropped before the parent + /// `outgoing-request` is dropped, or its ownership is transferred to + /// another component by e.g. `outgoing-handler.handle`. + @since(version = 0.2.0) + headers: func() -> headers; + } + + /// Parameters for making an HTTP Request. Each of these parameters is + /// currently an optional timeout applicable to the transport layer of the + /// HTTP protocol. + /// + /// These timeouts are separate from any the user may use to bound a + /// blocking call to `wasi:io/poll.poll`. + @since(version = 0.2.0) + resource request-options { + /// Construct a default `request-options` value. + @since(version = 0.2.0) + constructor(); + + /// The timeout for the initial connect to the HTTP Server. + @since(version = 0.2.0) + connect-timeout: func() -> option; + + /// Set the timeout for the initial connect to the HTTP Server. An error + /// return value indicates that this timeout is not supported. + @since(version = 0.2.0) + set-connect-timeout: func(duration: option) -> result; + + /// The timeout for receiving the first byte of the Response body. + @since(version = 0.2.0) + first-byte-timeout: func() -> option; + + /// Set the timeout for receiving the first byte of the Response body. An + /// error return value indicates that this timeout is not supported. + @since(version = 0.2.0) + set-first-byte-timeout: func(duration: option) -> result; + + /// The timeout for receiving subsequent chunks of bytes in the Response + /// body stream. + @since(version = 0.2.0) + between-bytes-timeout: func() -> option; + + /// Set the timeout for receiving subsequent chunks of bytes in the Response + /// body stream. An error return value indicates that this timeout is not + /// supported. + @since(version = 0.2.0) + set-between-bytes-timeout: func(duration: option) -> result; + } + + /// Represents the ability to send an HTTP Response. + /// + /// This resource is used by the `wasi:http/incoming-handler` interface to + /// allow a Response to be sent corresponding to the Request provided as the + /// other argument to `incoming-handler.handle`. + @since(version = 0.2.0) + resource response-outparam { + + /// Set the value of the `response-outparam` to either send a response, + /// or indicate an error. + /// + /// This method consumes the `response-outparam` to ensure that it is + /// called at most once. If it is never called, the implementation + /// will respond with an error. + /// + /// The user may provide an `error` to `response` to allow the + /// implementation determine how to respond with an HTTP error response. + @since(version = 0.2.0) + set: static func( + param: response-outparam, + response: result, + ); + } + + /// This type corresponds to the HTTP standard Status Code. + @since(version = 0.2.0) + type status-code = u16; + + /// Represents an incoming HTTP Response. + @since(version = 0.2.0) + resource incoming-response { + + /// Returns the status code from the incoming response. + @since(version = 0.2.0) + status: func() -> status-code; + + /// Returns the headers from the incoming response. + /// + /// The returned `headers` resource is immutable: `set`, `append`, and + /// `delete` operations will fail with `header-error.immutable`. + /// + /// This headers resource is a child: it must be dropped before the parent + /// `incoming-response` is dropped. + @since(version = 0.2.0) + headers: func() -> headers; + + /// Returns the incoming body. May be called at most once. Returns error + /// if called additional times. + @since(version = 0.2.0) + consume: func() -> result; + } + + /// Represents an incoming HTTP Request or Response's Body. + /// + /// A body has both its contents - a stream of bytes - and a (possibly + /// empty) set of trailers, indicating that the full contents of the + /// body have been received. This resource represents the contents as + /// an `input-stream` and the delivery of trailers as a `future-trailers`, + /// and ensures that the user of this interface may only be consuming either + /// the body contents or waiting on trailers at any given time. + @since(version = 0.2.0) + resource incoming-body { + + /// Returns the contents of the body, as a stream of bytes. + /// + /// Returns success on first call: the stream representing the contents + /// can be retrieved at most once. Subsequent calls will return error. + /// + /// The returned `input-stream` resource is a child: it must be dropped + /// before the parent `incoming-body` is dropped, or consumed by + /// `incoming-body.finish`. + /// + /// This invariant ensures that the implementation can determine whether + /// the user is consuming the contents of the body, waiting on the + /// `future-trailers` to be ready, or neither. This allows for network + /// backpressure is to be applied when the user is consuming the body, + /// and for that backpressure to not inhibit delivery of the trailers if + /// the user does not read the entire body. + @since(version = 0.2.0) + %stream: func() -> result; + + /// Takes ownership of `incoming-body`, and returns a `future-trailers`. + /// This function will trap if the `input-stream` child is still alive. + @since(version = 0.2.0) + finish: static func(this: incoming-body) -> future-trailers; + } + + /// Represents a future which may eventually return trailers, or an error. + /// + /// In the case that the incoming HTTP Request or Response did not have any + /// trailers, this future will resolve to the empty set of trailers once the + /// complete Request or Response body has been received. + @since(version = 0.2.0) + resource future-trailers { + + /// Returns a pollable which becomes ready when either the trailers have + /// been received, or an error has occurred. When this pollable is ready, + /// the `get` method will return `some`. + @since(version = 0.2.0) + subscribe: func() -> pollable; + + /// Returns the contents of the trailers, or an error which occurred, + /// once the future is ready. + /// + /// The outer `option` represents future readiness. Users can wait on this + /// `option` to become `some` using the `subscribe` method. + /// + /// The outer `result` is used to retrieve the trailers or error at most + /// once. It will be success on the first call in which the outer option + /// is `some`, and error on subsequent calls. + /// + /// The inner `result` represents that either the HTTP Request or Response + /// body, as well as any trailers, were received successfully, or that an + /// error occurred receiving them. The optional `trailers` indicates whether + /// or not trailers were present in the body. + /// + /// When some `trailers` are returned by this method, the `trailers` + /// resource is immutable, and a child. Use of the `set`, `append`, or + /// `delete` methods will return an error, and the resource must be + /// dropped before the parent `future-trailers` is dropped. + @since(version = 0.2.0) + get: func() -> option, error-code>>>; + } + + /// Represents an outgoing HTTP Response. + @since(version = 0.2.0) + resource outgoing-response { + + /// Construct an `outgoing-response`, with a default `status-code` of `200`. + /// If a different `status-code` is needed, it must be set via the + /// `set-status-code` method. + /// + /// * `headers` is the HTTP Headers for the Response. + @since(version = 0.2.0) + constructor(headers: headers); + + /// Get the HTTP Status Code for the Response. + @since(version = 0.2.0) + status-code: func() -> status-code; + + /// Set the HTTP Status Code for the Response. Fails if the status-code + /// given is not a valid http status code. + @since(version = 0.2.0) + set-status-code: func(status-code: status-code) -> result; + + /// Get the headers associated with the Request. + /// + /// The returned `headers` resource is immutable: `set`, `append`, and + /// `delete` operations will fail with `header-error.immutable`. + /// + /// This headers resource is a child: it must be dropped before the parent + /// `outgoing-request` is dropped, or its ownership is transferred to + /// another component by e.g. `outgoing-handler.handle`. + @since(version = 0.2.0) + headers: func() -> headers; + + /// Returns the resource corresponding to the outgoing Body for this Response. + /// + /// Returns success on the first call: the `outgoing-body` resource for + /// this `outgoing-response` can be retrieved at most once. Subsequent + /// calls will return error. + @since(version = 0.2.0) + body: func() -> result; + } + + /// Represents an outgoing HTTP Request or Response's Body. + /// + /// A body has both its contents - a stream of bytes - and a (possibly + /// empty) set of trailers, inducating the full contents of the body + /// have been sent. This resource represents the contents as an + /// `output-stream` child resource, and the completion of the body (with + /// optional trailers) with a static function that consumes the + /// `outgoing-body` resource, and ensures that the user of this interface + /// may not write to the body contents after the body has been finished. + /// + /// If the user code drops this resource, as opposed to calling the static + /// method `finish`, the implementation should treat the body as incomplete, + /// and that an error has occurred. The implementation should propagate this + /// error to the HTTP protocol by whatever means it has available, + /// including: corrupting the body on the wire, aborting the associated + /// Request, or sending a late status code for the Response. + @since(version = 0.2.0) + resource outgoing-body { + + /// Returns a stream for writing the body contents. + /// + /// The returned `output-stream` is a child resource: it must be dropped + /// before the parent `outgoing-body` resource is dropped (or finished), + /// otherwise the `outgoing-body` drop or `finish` will trap. + /// + /// Returns success on the first call: the `output-stream` resource for + /// this `outgoing-body` may be retrieved at most once. Subsequent calls + /// will return error. + @since(version = 0.2.0) + write: func() -> result; + + /// Finalize an outgoing body, optionally providing trailers. This must be + /// called to signal that the response is complete. If the `outgoing-body` + /// is dropped without calling `outgoing-body.finalize`, the implementation + /// should treat the body as corrupted. + /// + /// Fails if the body's `outgoing-request` or `outgoing-response` was + /// constructed with a Content-Length header, and the contents written + /// to the body (via `write`) does not match the value given in the + /// Content-Length. + @since(version = 0.2.0) + finish: static func( + this: outgoing-body, + trailers: option + ) -> result<_, error-code>; + } + + /// Represents a future which may eventually return an incoming HTTP + /// Response, or an error. + /// + /// This resource is returned by the `wasi:http/outgoing-handler` interface to + /// provide the HTTP Response corresponding to the sent Request. + @since(version = 0.2.0) + resource future-incoming-response { + /// Returns a pollable which becomes ready when either the Response has + /// been received, or an error has occurred. When this pollable is ready, + /// the `get` method will return `some`. + @since(version = 0.2.0) + subscribe: func() -> pollable; + + /// Returns the incoming HTTP Response, or an error, once one is ready. + /// + /// The outer `option` represents future readiness. Users can wait on this + /// `option` to become `some` using the `subscribe` method. + /// + /// The outer `result` is used to retrieve the response or error at most + /// once. It will be success on the first call in which the outer option + /// is `some`, and error on subsequent calls. + /// + /// The inner `result` represents that either the incoming HTTP Response + /// status and headers have received successfully, or that an error + /// occurred. Errors may also occur while consuming the response body, + /// but those will be reported by the `incoming-body` and its + /// `output-stream` child. + @since(version = 0.2.0) + get: func() -> option>>; + } +} diff --git a/examples/go/http/wit/deps/io/error.wit b/examples/go/http/wit/deps/io/error.wit new file mode 100644 index 0000000..4ea29c4 --- /dev/null +++ b/examples/go/http/wit/deps/io/error.wit @@ -0,0 +1,34 @@ +package wasi:io@0.2.1; + +@since(version = 0.2.0) +interface error { + /// A resource which represents some error information. + /// + /// The only method provided by this resource is `to-debug-string`, + /// which provides some human-readable information about the error. + /// + /// In the `wasi:io` package, this resource is returned through the + /// `wasi:io/streams/stream-error` type. + /// + /// To provide more specific error information, other interfaces may + /// offer functions to "downcast" this error into more specific types. For example, + /// errors returned from streams derived from filesystem types can be described using + /// the filesystem's own error-code type. This is done using the function + /// `wasi:filesystem/types/filesystem-error-code`, which takes a `borrow` + /// parameter and returns an `option`. + /// + /// The set of functions which can "downcast" an `error` into a more + /// concrete type is open. + @since(version = 0.2.0) + resource error { + /// Returns a string that is suitable to assist humans in debugging + /// this error. + /// + /// WARNING: The returned string should not be consumed mechanically! + /// It may change across platforms, hosts, or other implementation + /// details. Parsing this string is a major platform-compatibility + /// hazard. + @since(version = 0.2.0) + to-debug-string: func() -> string; + } +} diff --git a/examples/go/http/wit/deps/io/poll.wit b/examples/go/http/wit/deps/io/poll.wit new file mode 100644 index 0000000..b25ac72 --- /dev/null +++ b/examples/go/http/wit/deps/io/poll.wit @@ -0,0 +1,47 @@ +package wasi:io@0.2.1; + +/// A poll API intended to let users wait for I/O events on multiple handles +/// at once. +@since(version = 0.2.0) +interface poll { + /// `pollable` represents a single I/O event which may be ready, or not. + @since(version = 0.2.0) + resource pollable { + + /// Return the readiness of a pollable. This function never blocks. + /// + /// Returns `true` when the pollable is ready, and `false` otherwise. + @since(version = 0.2.0) + ready: func() -> bool; + + /// `block` returns immediately if the pollable is ready, and otherwise + /// blocks until ready. + /// + /// This function is equivalent to calling `poll.poll` on a list + /// containing only this pollable. + @since(version = 0.2.0) + block: func(); + } + + /// Poll for completion on a set of pollables. + /// + /// This function takes a list of pollables, which identify I/O sources of + /// interest, and waits until one or more of the events is ready for I/O. + /// + /// The result `list` contains one or more indices of handles in the + /// argument list that is ready for I/O. + /// + /// This function traps if either: + /// - the list is empty, or: + /// - the list contains more elements than can be indexed with a `u32` value. + /// + /// A timeout can be implemented by adding a pollable from the + /// wasi-clocks API to the list. + /// + /// This function does not return a `result`; polling in itself does not + /// do any I/O so it doesn't fail. If any of the I/O sources identified by + /// the pollables has an error, it is indicated by marking the source as + /// being ready for I/O. + @since(version = 0.2.0) + poll: func(in: list>) -> list; +} diff --git a/examples/go/http/wit/deps/io/streams.wit b/examples/go/http/wit/deps/io/streams.wit new file mode 100644 index 0000000..b697e24 --- /dev/null +++ b/examples/go/http/wit/deps/io/streams.wit @@ -0,0 +1,286 @@ +package wasi:io@0.2.1; + +/// WASI I/O is an I/O abstraction API which is currently focused on providing +/// stream types. +/// +/// In the future, the component model is expected to add built-in stream types; +/// when it does, they are expected to subsume this API. +@since(version = 0.2.0) +interface streams { + @since(version = 0.2.0) + use error.{error}; + @since(version = 0.2.0) + use poll.{pollable}; + + /// An error for input-stream and output-stream operations. + @since(version = 0.2.0) + variant stream-error { + /// The last operation (a write or flush) failed before completion. + /// + /// More information is available in the `error` payload. + last-operation-failed(error), + /// The stream is closed: no more input will be accepted by the + /// stream. A closed output-stream will return this error on all + /// future operations. + closed + } + + /// An input bytestream. + /// + /// `input-stream`s are *non-blocking* to the extent practical on underlying + /// platforms. I/O operations always return promptly; if fewer bytes are + /// promptly available than requested, they return the number of bytes promptly + /// available, which could even be zero. To wait for data to be available, + /// use the `subscribe` function to obtain a `pollable` which can be polled + /// for using `wasi:io/poll`. + @since(version = 0.2.0) + resource input-stream { + /// Perform a non-blocking read from the stream. + /// + /// When the source of a `read` is binary data, the bytes from the source + /// are returned verbatim. When the source of a `read` is known to the + /// implementation to be text, bytes containing the UTF-8 encoding of the + /// text are returned. + /// + /// This function returns a list of bytes containing the read data, + /// when successful. The returned list will contain up to `len` bytes; + /// it may return fewer than requested, but not more. The list is + /// empty when no bytes are available for reading at this time. The + /// pollable given by `subscribe` will be ready when more bytes are + /// available. + /// + /// This function fails with a `stream-error` when the operation + /// encounters an error, giving `last-operation-failed`, or when the + /// stream is closed, giving `closed`. + /// + /// When the caller gives a `len` of 0, it represents a request to + /// read 0 bytes. If the stream is still open, this call should + /// succeed and return an empty list, or otherwise fail with `closed`. + /// + /// The `len` parameter is a `u64`, which could represent a list of u8 which + /// is not possible to allocate in wasm32, or not desirable to allocate as + /// as a return value by the callee. The callee may return a list of bytes + /// less than `len` in size while more bytes are available for reading. + @since(version = 0.2.0) + read: func( + /// The maximum number of bytes to read + len: u64 + ) -> result, stream-error>; + + /// Read bytes from a stream, after blocking until at least one byte can + /// be read. Except for blocking, behavior is identical to `read`. + @since(version = 0.2.0) + blocking-read: func( + /// The maximum number of bytes to read + len: u64 + ) -> result, stream-error>; + + /// Skip bytes from a stream. Returns number of bytes skipped. + /// + /// Behaves identical to `read`, except instead of returning a list + /// of bytes, returns the number of bytes consumed from the stream. + @since(version = 0.2.0) + skip: func( + /// The maximum number of bytes to skip. + len: u64, + ) -> result; + + /// Skip bytes from a stream, after blocking until at least one byte + /// can be skipped. Except for blocking behavior, identical to `skip`. + @since(version = 0.2.0) + blocking-skip: func( + /// The maximum number of bytes to skip. + len: u64, + ) -> result; + + /// Create a `pollable` which will resolve once either the specified stream + /// has bytes available to read or the other end of the stream has been + /// closed. + /// The created `pollable` is a child resource of the `input-stream`. + /// Implementations may trap if the `input-stream` is dropped before + /// all derived `pollable`s created with this function are dropped. + @since(version = 0.2.0) + subscribe: func() -> pollable; + } + + + /// An output bytestream. + /// + /// `output-stream`s are *non-blocking* to the extent practical on + /// underlying platforms. Except where specified otherwise, I/O operations also + /// always return promptly, after the number of bytes that can be written + /// promptly, which could even be zero. To wait for the stream to be ready to + /// accept data, the `subscribe` function to obtain a `pollable` which can be + /// polled for using `wasi:io/poll`. + /// + /// Dropping an `output-stream` while there's still an active write in + /// progress may result in the data being lost. Before dropping the stream, + /// be sure to fully flush your writes. + @since(version = 0.2.0) + resource output-stream { + /// Check readiness for writing. This function never blocks. + /// + /// Returns the number of bytes permitted for the next call to `write`, + /// or an error. Calling `write` with more bytes than this function has + /// permitted will trap. + /// + /// When this function returns 0 bytes, the `subscribe` pollable will + /// become ready when this function will report at least 1 byte, or an + /// error. + @since(version = 0.2.0) + check-write: func() -> result; + + /// Perform a write. This function never blocks. + /// + /// When the destination of a `write` is binary data, the bytes from + /// `contents` are written verbatim. When the destination of a `write` is + /// known to the implementation to be text, the bytes of `contents` are + /// transcoded from UTF-8 into the encoding of the destination and then + /// written. + /// + /// Precondition: check-write gave permit of Ok(n) and contents has a + /// length of less than or equal to n. Otherwise, this function will trap. + /// + /// returns Err(closed) without writing if the stream has closed since + /// the last call to check-write provided a permit. + @since(version = 0.2.0) + write: func( + contents: list + ) -> result<_, stream-error>; + + /// Perform a write of up to 4096 bytes, and then flush the stream. Block + /// until all of these operations are complete, or an error occurs. + /// + /// This is a convenience wrapper around the use of `check-write`, + /// `subscribe`, `write`, and `flush`, and is implemented with the + /// following pseudo-code: + /// + /// ```text + /// let pollable = this.subscribe(); + /// while !contents.is_empty() { + /// // Wait for the stream to become writable + /// pollable.block(); + /// let Ok(n) = this.check-write(); // eliding error handling + /// let len = min(n, contents.len()); + /// let (chunk, rest) = contents.split_at(len); + /// this.write(chunk ); // eliding error handling + /// contents = rest; + /// } + /// this.flush(); + /// // Wait for completion of `flush` + /// pollable.block(); + /// // Check for any errors that arose during `flush` + /// let _ = this.check-write(); // eliding error handling + /// ``` + @since(version = 0.2.0) + blocking-write-and-flush: func( + contents: list + ) -> result<_, stream-error>; + + /// Request to flush buffered output. This function never blocks. + /// + /// This tells the output-stream that the caller intends any buffered + /// output to be flushed. the output which is expected to be flushed + /// is all that has been passed to `write` prior to this call. + /// + /// Upon calling this function, the `output-stream` will not accept any + /// writes (`check-write` will return `ok(0)`) until the flush has + /// completed. The `subscribe` pollable will become ready when the + /// flush has completed and the stream can accept more writes. + @since(version = 0.2.0) + flush: func() -> result<_, stream-error>; + + /// Request to flush buffered output, and block until flush completes + /// and stream is ready for writing again. + @since(version = 0.2.0) + blocking-flush: func() -> result<_, stream-error>; + + /// Create a `pollable` which will resolve once the output-stream + /// is ready for more writing, or an error has occurred. When this + /// pollable is ready, `check-write` will return `ok(n)` with n>0, or an + /// error. + /// + /// If the stream is closed, this pollable is always ready immediately. + /// + /// The created `pollable` is a child resource of the `output-stream`. + /// Implementations may trap if the `output-stream` is dropped before + /// all derived `pollable`s created with this function are dropped. + subscribe: func() -> pollable; + + /// Write zeroes to a stream. + /// + /// This should be used precisely like `write` with the exact same + /// preconditions (must use check-write first), but instead of + /// passing a list of bytes, you simply pass the number of zero-bytes + /// that should be written. + @since(version = 0.2.0) + write-zeroes: func( + /// The number of zero-bytes to write + len: u64 + ) -> result<_, stream-error>; + + /// Perform a write of up to 4096 zeroes, and then flush the stream. + /// Block until all of these operations are complete, or an error + /// occurs. + /// + /// This is a convenience wrapper around the use of `check-write`, + /// `subscribe`, `write-zeroes`, and `flush`, and is implemented with + /// the following pseudo-code: + /// + /// ```text + /// let pollable = this.subscribe(); + /// while num_zeroes != 0 { + /// // Wait for the stream to become writable + /// pollable.block(); + /// let Ok(n) = this.check-write(); // eliding error handling + /// let len = min(n, num_zeroes); + /// this.write-zeroes(len); // eliding error handling + /// num_zeroes -= len; + /// } + /// this.flush(); + /// // Wait for completion of `flush` + /// pollable.block(); + /// // Check for any errors that arose during `flush` + /// let _ = this.check-write(); // eliding error handling + /// ``` + @since(version = 0.2.0) + blocking-write-zeroes-and-flush: func( + /// The number of zero-bytes to write + len: u64 + ) -> result<_, stream-error>; + + /// Read from one stream and write to another. + /// + /// The behavior of splice is equivalent to: + /// 1. calling `check-write` on the `output-stream` + /// 2. calling `read` on the `input-stream` with the smaller of the + /// `check-write` permitted length and the `len` provided to `splice` + /// 3. calling `write` on the `output-stream` with that read data. + /// + /// Any error reported by the call to `check-write`, `read`, or + /// `write` ends the splice and reports that error. + /// + /// This function returns the number of bytes transferred; it may be less + /// than `len`. + @since(version = 0.2.0) + splice: func( + /// The stream to read from + src: borrow, + /// The number of bytes to splice + len: u64, + ) -> result; + + /// Read from one stream and write to another, with blocking. + /// + /// This is similar to `splice`, except that it blocks until the + /// `output-stream` is ready for writing, and the `input-stream` + /// is ready for reading, before performing the `splice`. + @since(version = 0.2.0) + blocking-splice: func( + /// The stream to read from + src: borrow, + /// The number of bytes to splice + len: u64, + ) -> result; + } +} diff --git a/examples/go/http/wit/deps/io/world.wit b/examples/go/http/wit/deps/io/world.wit new file mode 100644 index 0000000..6405a4e --- /dev/null +++ b/examples/go/http/wit/deps/io/world.wit @@ -0,0 +1,10 @@ +package wasi:io@0.2.1; + +@since(version = 0.2.0) +world imports { + @since(version = 0.2.0) + import streams; + + @since(version = 0.2.0) + import poll; +} diff --git a/examples/go/http/wit/deps/random/insecure-seed.wit b/examples/go/http/wit/deps/random/insecure-seed.wit new file mode 100644 index 0000000..7e708dc --- /dev/null +++ b/examples/go/http/wit/deps/random/insecure-seed.wit @@ -0,0 +1,27 @@ +package wasi:random@0.2.1; +/// The insecure-seed interface for seeding hash-map DoS resistance. +/// +/// It is intended to be portable at least between Unix-family platforms and +/// Windows. +@since(version = 0.2.0) +interface insecure-seed { + /// Return a 128-bit value that may contain a pseudo-random value. + /// + /// The returned value is not required to be computed from a CSPRNG, and may + /// even be entirely deterministic. Host implementations are encouraged to + /// provide pseudo-random values to any program exposed to + /// attacker-controlled content, to enable DoS protection built into many + /// languages' hash-map implementations. + /// + /// This function is intended to only be called once, by a source language + /// to initialize Denial Of Service (DoS) protection in its hash-map + /// implementation. + /// + /// # Expected future evolution + /// + /// This will likely be changed to a value import, to prevent it from being + /// called multiple times and potentially used for purposes other than DoS + /// protection. + @since(version = 0.2.0) + insecure-seed: func() -> tuple; +} diff --git a/examples/go/http/wit/deps/random/insecure.wit b/examples/go/http/wit/deps/random/insecure.wit new file mode 100644 index 0000000..3cdb53d --- /dev/null +++ b/examples/go/http/wit/deps/random/insecure.wit @@ -0,0 +1,25 @@ +package wasi:random@0.2.1; +/// The insecure interface for insecure pseudo-random numbers. +/// +/// It is intended to be portable at least between Unix-family platforms and +/// Windows. +@since(version = 0.2.0) +interface insecure { + /// Return `len` insecure pseudo-random bytes. + /// + /// This function is not cryptographically secure. Do not use it for + /// anything related to security. + /// + /// There are no requirements on the values of the returned bytes, however + /// implementations are encouraged to return evenly distributed values with + /// a long period. + @since(version = 0.2.0) + get-insecure-random-bytes: func(len: u64) -> list; + + /// Return an insecure pseudo-random `u64` value. + /// + /// This function returns the same type of pseudo-random data as + /// `get-insecure-random-bytes`, represented as a `u64`. + @since(version = 0.2.0) + get-insecure-random-u64: func() -> u64; +} diff --git a/examples/go/http/wit/deps/random/random.wit b/examples/go/http/wit/deps/random/random.wit new file mode 100644 index 0000000..2b5035d --- /dev/null +++ b/examples/go/http/wit/deps/random/random.wit @@ -0,0 +1,29 @@ +package wasi:random@0.2.1; +/// WASI Random is a random data API. +/// +/// It is intended to be portable at least between Unix-family platforms and +/// Windows. +@since(version = 0.2.0) +interface random { + /// Return `len` cryptographically-secure random or pseudo-random bytes. + /// + /// This function must produce data at least as cryptographically secure and + /// fast as an adequately seeded cryptographically-secure pseudo-random + /// number generator (CSPRNG). It must not block, from the perspective of + /// the calling program, under any circumstances, including on the first + /// request and on requests for numbers of bytes. The returned data must + /// always be unpredictable. + /// + /// This function must always return fresh data. Deterministic environments + /// must omit this function, rather than implementing it with deterministic + /// data. + @since(version = 0.2.0) + get-random-bytes: func(len: u64) -> list; + + /// Return a cryptographically-secure random or pseudo-random `u64` value. + /// + /// This function returns the same type of data as `get-random-bytes`, + /// represented as a `u64`. + @since(version = 0.2.0) + get-random-u64: func() -> u64; +} diff --git a/examples/go/http/wit/deps/random/world.wit b/examples/go/http/wit/deps/random/world.wit new file mode 100644 index 0000000..c615e96 --- /dev/null +++ b/examples/go/http/wit/deps/random/world.wit @@ -0,0 +1,13 @@ +package wasi:random@0.2.1; + +@since(version = 0.2.0) +world imports { + @since(version = 0.2.0) + import random; + + @since(version = 0.2.0) + import insecure; + + @since(version = 0.2.0) + import insecure-seed; +} diff --git a/examples/go/http/wit/deps/sockets/instance-network.wit b/examples/go/http/wit/deps/sockets/instance-network.wit new file mode 100644 index 0000000..5f6e6c1 --- /dev/null +++ b/examples/go/http/wit/deps/sockets/instance-network.wit @@ -0,0 +1,11 @@ + +/// This interface provides a value-export of the default network handle.. +@since(version = 0.2.0) +interface instance-network { + @since(version = 0.2.0) + use network.{network}; + + /// Get a handle to the default network. + @since(version = 0.2.0) + instance-network: func() -> network; +} diff --git a/examples/go/http/wit/deps/sockets/ip-name-lookup.wit b/examples/go/http/wit/deps/sockets/ip-name-lookup.wit new file mode 100644 index 0000000..dc56f30 --- /dev/null +++ b/examples/go/http/wit/deps/sockets/ip-name-lookup.wit @@ -0,0 +1,56 @@ +@since(version = 0.2.0) +interface ip-name-lookup { + @since(version = 0.2.0) + use wasi:io/poll@0.2.1.{pollable}; + @since(version = 0.2.0) + use network.{network, error-code, ip-address}; + + /// Resolve an internet host name to a list of IP addresses. + /// + /// Unicode domain names are automatically converted to ASCII using IDNA encoding. + /// If the input is an IP address string, the address is parsed and returned + /// as-is without making any external requests. + /// + /// See the wasi-socket proposal README.md for a comparison with getaddrinfo. + /// + /// This function never blocks. It either immediately fails or immediately + /// returns successfully with a `resolve-address-stream` that can be used + /// to (asynchronously) fetch the results. + /// + /// # Typical errors + /// - `invalid-argument`: `name` is a syntactically invalid domain name or IP address. + /// + /// # References: + /// - + /// - + /// - + /// - + @since(version = 0.2.0) + resolve-addresses: func(network: borrow, name: string) -> result; + + @since(version = 0.2.0) + resource resolve-address-stream { + /// Returns the next address from the resolver. + /// + /// This function should be called multiple times. On each call, it will + /// return the next address in connection order preference. If all + /// addresses have been exhausted, this function returns `none`. + /// + /// This function never returns IPv4-mapped IPv6 addresses. + /// + /// # Typical errors + /// - `name-unresolvable`: Name does not exist or has no suitable associated IP addresses. (EAI_NONAME, EAI_NODATA, EAI_ADDRFAMILY) + /// - `temporary-resolver-failure`: A temporary failure in name resolution occurred. (EAI_AGAIN) + /// - `permanent-resolver-failure`: A permanent failure in name resolution occurred. (EAI_FAIL) + /// - `would-block`: A result is not available yet. (EWOULDBLOCK, EAGAIN) + @since(version = 0.2.0) + resolve-next-address: func() -> result, error-code>; + + /// Create a `pollable` which will resolve once the stream is ready for I/O. + /// + /// Note: this function is here for WASI Preview2 only. + /// It's planned to be removed when `future` is natively supported in Preview3. + @since(version = 0.2.0) + subscribe: func() -> pollable; + } +} diff --git a/examples/go/http/wit/deps/sockets/network.wit b/examples/go/http/wit/deps/sockets/network.wit new file mode 100644 index 0000000..8c13b34 --- /dev/null +++ b/examples/go/http/wit/deps/sockets/network.wit @@ -0,0 +1,153 @@ +@since(version = 0.2.0) +interface network { + /// An opaque resource that represents access to (a subset of) the network. + /// This enables context-based security for networking. + /// There is no need for this to map 1:1 to a physical network interface. + @since(version = 0.2.0) + resource network; + + /// Error codes. + /// + /// In theory, every API can return any error code. + /// In practice, API's typically only return the errors documented per API + /// combined with a couple of errors that are always possible: + /// - `unknown` + /// - `access-denied` + /// - `not-supported` + /// - `out-of-memory` + /// - `concurrency-conflict` + /// + /// See each individual API for what the POSIX equivalents are. They sometimes differ per API. + @since(version = 0.2.0) + enum error-code { + /// Unknown error + unknown, + + /// Access denied. + /// + /// POSIX equivalent: EACCES, EPERM + access-denied, + + /// The operation is not supported. + /// + /// POSIX equivalent: EOPNOTSUPP + not-supported, + + /// One of the arguments is invalid. + /// + /// POSIX equivalent: EINVAL + invalid-argument, + + /// Not enough memory to complete the operation. + /// + /// POSIX equivalent: ENOMEM, ENOBUFS, EAI_MEMORY + out-of-memory, + + /// The operation timed out before it could finish completely. + timeout, + + /// This operation is incompatible with another asynchronous operation that is already in progress. + /// + /// POSIX equivalent: EALREADY + concurrency-conflict, + + /// Trying to finish an asynchronous operation that: + /// - has not been started yet, or: + /// - was already finished by a previous `finish-*` call. + /// + /// Note: this is scheduled to be removed when `future`s are natively supported. + not-in-progress, + + /// The operation has been aborted because it could not be completed immediately. + /// + /// Note: this is scheduled to be removed when `future`s are natively supported. + would-block, + + + /// The operation is not valid in the socket's current state. + invalid-state, + + /// A new socket resource could not be created because of a system limit. + new-socket-limit, + + /// A bind operation failed because the provided address is not an address that the `network` can bind to. + address-not-bindable, + + /// A bind operation failed because the provided address is already in use or because there are no ephemeral ports available. + address-in-use, + + /// The remote address is not reachable + remote-unreachable, + + + /// The TCP connection was forcefully rejected + connection-refused, + + /// The TCP connection was reset. + connection-reset, + + /// A TCP connection was aborted. + connection-aborted, + + + /// The size of a datagram sent to a UDP socket exceeded the maximum + /// supported size. + datagram-too-large, + + + /// Name does not exist or has no suitable associated IP addresses. + name-unresolvable, + + /// A temporary failure in name resolution occurred. + temporary-resolver-failure, + + /// A permanent failure in name resolution occurred. + permanent-resolver-failure, + } + + @since(version = 0.2.0) + enum ip-address-family { + /// Similar to `AF_INET` in POSIX. + ipv4, + + /// Similar to `AF_INET6` in POSIX. + ipv6, + } + + @since(version = 0.2.0) + type ipv4-address = tuple; + @since(version = 0.2.0) + type ipv6-address = tuple; + + @since(version = 0.2.0) + variant ip-address { + ipv4(ipv4-address), + ipv6(ipv6-address), + } + + @since(version = 0.2.0) + record ipv4-socket-address { + /// sin_port + port: u16, + /// sin_addr + address: ipv4-address, + } + + @since(version = 0.2.0) + record ipv6-socket-address { + /// sin6_port + port: u16, + /// sin6_flowinfo + flow-info: u32, + /// sin6_addr + address: ipv6-address, + /// sin6_scope_id + scope-id: u32, + } + + @since(version = 0.2.0) + variant ip-socket-address { + ipv4(ipv4-socket-address), + ipv6(ipv6-socket-address), + } +} diff --git a/examples/go/http/wit/deps/sockets/tcp-create-socket.wit b/examples/go/http/wit/deps/sockets/tcp-create-socket.wit new file mode 100644 index 0000000..eedbd30 --- /dev/null +++ b/examples/go/http/wit/deps/sockets/tcp-create-socket.wit @@ -0,0 +1,30 @@ +@since(version = 0.2.0) +interface tcp-create-socket { + @since(version = 0.2.0) + use network.{network, error-code, ip-address-family}; + @since(version = 0.2.0) + use tcp.{tcp-socket}; + + /// Create a new TCP socket. + /// + /// Similar to `socket(AF_INET or AF_INET6, SOCK_STREAM, IPPROTO_TCP)` in POSIX. + /// On IPv6 sockets, IPV6_V6ONLY is enabled by default and can't be configured otherwise. + /// + /// This function does not require a network capability handle. This is considered to be safe because + /// at time of creation, the socket is not bound to any `network` yet. Up to the moment `bind`/`connect` + /// is called, the socket is effectively an in-memory configuration object, unable to communicate with the outside world. + /// + /// All sockets are non-blocking. Use the wasi-poll interface to block on asynchronous operations. + /// + /// # Typical errors + /// - `not-supported`: The specified `address-family` is not supported. (EAFNOSUPPORT) + /// - `new-socket-limit`: The new socket resource could not be created because of a system limit. (EMFILE, ENFILE) + /// + /// # References + /// - + /// - + /// - + /// - + @since(version = 0.2.0) + create-tcp-socket: func(address-family: ip-address-family) -> result; +} diff --git a/examples/go/http/wit/deps/sockets/tcp.wit b/examples/go/http/wit/deps/sockets/tcp.wit new file mode 100644 index 0000000..bae5a29 --- /dev/null +++ b/examples/go/http/wit/deps/sockets/tcp.wit @@ -0,0 +1,387 @@ +@since(version = 0.2.0) +interface tcp { + @since(version = 0.2.0) + use wasi:io/streams@0.2.1.{input-stream, output-stream}; + @since(version = 0.2.0) + use wasi:io/poll@0.2.1.{pollable}; + @since(version = 0.2.0) + use wasi:clocks/monotonic-clock@0.2.1.{duration}; + @since(version = 0.2.0) + use network.{network, error-code, ip-socket-address, ip-address-family}; + + @since(version = 0.2.0) + enum shutdown-type { + /// Similar to `SHUT_RD` in POSIX. + receive, + + /// Similar to `SHUT_WR` in POSIX. + send, + + /// Similar to `SHUT_RDWR` in POSIX. + both, + } + + /// A TCP socket resource. + /// + /// The socket can be in one of the following states: + /// - `unbound` + /// - `bind-in-progress` + /// - `bound` (See note below) + /// - `listen-in-progress` + /// - `listening` + /// - `connect-in-progress` + /// - `connected` + /// - `closed` + /// See + /// for more information. + /// + /// Note: Except where explicitly mentioned, whenever this documentation uses + /// the term "bound" without backticks it actually means: in the `bound` state *or higher*. + /// (i.e. `bound`, `listen-in-progress`, `listening`, `connect-in-progress` or `connected`) + /// + /// In addition to the general error codes documented on the + /// `network::error-code` type, TCP socket methods may always return + /// `error(invalid-state)` when in the `closed` state. + @since(version = 0.2.0) + resource tcp-socket { + /// Bind the socket to a specific network on the provided IP address and port. + /// + /// If the IP address is zero (`0.0.0.0` in IPv4, `::` in IPv6), it is left to the implementation to decide which + /// network interface(s) to bind to. + /// If the TCP/UDP port is zero, the socket will be bound to a random free port. + /// + /// Bind can be attempted multiple times on the same socket, even with + /// different arguments on each iteration. But never concurrently and + /// only as long as the previous bind failed. Once a bind succeeds, the + /// binding can't be changed anymore. + /// + /// # Typical errors + /// - `invalid-argument`: The `local-address` has the wrong address family. (EAFNOSUPPORT, EFAULT on Windows) + /// - `invalid-argument`: `local-address` is not a unicast address. (EINVAL) + /// - `invalid-argument`: `local-address` is an IPv4-mapped IPv6 address. (EINVAL) + /// - `invalid-state`: The socket is already bound. (EINVAL) + /// - `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 the `network` can bind to. (EADDRNOTAVAIL) + /// - `not-in-progress`: A `bind` operation is not in progress. + /// - `would-block`: Can't finish the operation, it is still in progress. (EWOULDBLOCK, EAGAIN) + /// + /// # 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 + /// 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. + /// + /// Unlike in POSIX, in WASI the bind operation is async. This enables + /// interactive WASI hosts to inject permission prompts. Runtimes that + /// don't want to make use of this ability can simply call the native + /// `bind` as part of either `start-bind` or `finish-bind`. + /// + /// # References + /// - + /// - + /// - + /// - + @since(version = 0.2.0) + start-bind: func(network: borrow, local-address: ip-socket-address) -> result<_, error-code>; + @since(version = 0.2.0) + finish-bind: func() -> result<_, error-code>; + + /// Connect to a remote endpoint. + /// + /// On success: + /// - the socket is transitioned into the `connected` state. + /// - a pair of streams is returned that can be used to read & write to the connection + /// + /// After a failed connection attempt, the socket will be in the `closed` + /// state and the only valid action left is to `drop` the socket. A single + /// socket can not be used to connect more than once. + /// + /// # Typical errors + /// - `invalid-argument`: The `remote-address` has the wrong address family. (EAFNOSUPPORT) + /// - `invalid-argument`: `remote-address` is not a unicast address. (EINVAL, ENETUNREACH on Linux, EAFNOSUPPORT on MacOS) + /// - `invalid-argument`: `remote-address` is an IPv4-mapped IPv6 address. (EINVAL, EADDRNOTAVAIL on Illumos) + /// - `invalid-argument`: The IP address in `remote-address` is set to INADDR_ANY (`0.0.0.0` / `::`). (EADDRNOTAVAIL on Windows) + /// - `invalid-argument`: The port in `remote-address` is set to 0. (EADDRNOTAVAIL on Windows) + /// - `invalid-argument`: The socket is already attached to a different network. The `network` passed to `connect` must be identical to the one passed to `bind`. + /// - `invalid-state`: The socket is already in the `connected` state. (EISCONN) + /// - `invalid-state`: The socket is already in the `listening` state. (EOPNOTSUPP, EINVAL on Windows) + /// - `timeout`: Connection timed out. (ETIMEDOUT) + /// - `connection-refused`: The connection was forcefully rejected. (ECONNREFUSED) + /// - `connection-reset`: The connection was reset. (ECONNRESET) + /// - `connection-aborted`: The connection was aborted. (ECONNABORTED) + /// - `remote-unreachable`: The remote address is not reachable. (EHOSTUNREACH, EHOSTDOWN, ENETUNREACH, ENETDOWN, ENONET) + /// - `address-in-use`: Tried to perform an implicit bind, but there were no ephemeral ports available. (EADDRINUSE, EADDRNOTAVAIL on Linux, EAGAIN on BSD) + /// - `not-in-progress`: A connect operation is not in progress. + /// - `would-block`: Can't finish the operation, it is still in progress. (EWOULDBLOCK, EAGAIN) + /// + /// # Implementors note + /// The POSIX equivalent of `start-connect` is the regular `connect` syscall. + /// Because all WASI sockets are non-blocking this is expected to return + /// EINPROGRESS, which should be translated to `ok()` in WASI. + /// + /// The POSIX equivalent of `finish-connect` is a `poll` for event `POLLOUT` + /// with a timeout of 0 on the socket descriptor. Followed by a check for + /// the `SO_ERROR` socket option, in case the poll signaled readiness. + /// + /// # References + /// - + /// - + /// - + /// - + @since(version = 0.2.0) + start-connect: func(network: borrow, remote-address: ip-socket-address) -> result<_, error-code>; + @since(version = 0.2.0) + finish-connect: func() -> result, error-code>; + + /// Start listening for new connections. + /// + /// Transitions the socket into the `listening` state. + /// + /// Unlike POSIX, the socket must already be explicitly bound. + /// + /// # Typical errors + /// - `invalid-state`: The socket is not bound to any local address. (EDESTADDRREQ) + /// - `invalid-state`: The socket is already in the `connected` state. (EISCONN, EINVAL on BSD) + /// - `invalid-state`: The socket is already in the `listening` state. + /// - `address-in-use`: Tried to perform an implicit bind, but there were no ephemeral ports available. (EADDRINUSE) + /// - `not-in-progress`: A listen operation is not in progress. + /// - `would-block`: Can't finish the operation, it is still in progress. (EWOULDBLOCK, EAGAIN) + /// + /// # Implementors note + /// Unlike in POSIX, in WASI the listen operation is async. This enables + /// interactive WASI hosts to inject permission prompts. Runtimes that + /// don't want to make use of this ability can simply call the native + /// `listen` as part of either `start-listen` or `finish-listen`. + /// + /// # References + /// - + /// - + /// - + /// - + @since(version = 0.2.0) + start-listen: func() -> result<_, error-code>; + @since(version = 0.2.0) + finish-listen: func() -> result<_, error-code>; + + /// Accept a new client socket. + /// + /// The returned socket is bound and in the `connected` state. The following properties are inherited from the listener socket: + /// - `address-family` + /// - `keep-alive-enabled` + /// - `keep-alive-idle-time` + /// - `keep-alive-interval` + /// - `keep-alive-count` + /// - `hop-limit` + /// - `receive-buffer-size` + /// - `send-buffer-size` + /// + /// On success, this function returns the newly accepted client socket along with + /// a pair of streams that can be used to read & write to the connection. + /// + /// # Typical errors + /// - `invalid-state`: Socket is not in the `listening` state. (EINVAL) + /// - `would-block`: No pending connections at the moment. (EWOULDBLOCK, EAGAIN) + /// - `connection-aborted`: An incoming connection was pending, but was terminated by the client before this listener could accept it. (ECONNABORTED) + /// - `new-socket-limit`: The new socket resource could not be created because of a system limit. (EMFILE, ENFILE) + /// + /// # References + /// - + /// - + /// - + /// - + @since(version = 0.2.0) + accept: func() -> result, error-code>; + + /// Get the bound local address. + /// + /// POSIX mentions: + /// > If the socket has not been bound to a local name, the value + /// > stored in the object pointed to by `address` is unspecified. + /// + /// WASI is stricter and requires `local-address` to return `invalid-state` when the socket hasn't been bound yet. + /// + /// # Typical errors + /// - `invalid-state`: The socket is not bound to any local address. + /// + /// # References + /// - + /// - + /// - + /// - + @since(version = 0.2.0) + local-address: func() -> result; + + /// Get the remote address. + /// + /// # Typical errors + /// - `invalid-state`: The socket is not connected to a remote address. (ENOTCONN) + /// + /// # References + /// - + /// - + /// - + /// - + @since(version = 0.2.0) + remote-address: func() -> result; + + /// Whether the socket is in the `listening` state. + /// + /// Equivalent to the SO_ACCEPTCONN socket option. + @since(version = 0.2.0) + is-listening: func() -> bool; + + /// Whether this is a IPv4 or IPv6 socket. + /// + /// Equivalent to the SO_DOMAIN socket option. + @since(version = 0.2.0) + address-family: func() -> ip-address-family; + + /// Hints the desired listen queue size. Implementations are free to ignore this. + /// + /// If the provided value is 0, an `invalid-argument` error is returned. + /// Any other value will never cause an error, but it might be silently clamped and/or rounded. + /// + /// # Typical errors + /// - `not-supported`: (set) The platform does not support changing the backlog size after the initial listen. + /// - `invalid-argument`: (set) The provided value was 0. + /// - `invalid-state`: (set) The socket is in the `connect-in-progress` or `connected` state. + @since(version = 0.2.0) + set-listen-backlog-size: func(value: u64) -> result<_, error-code>; + + /// Enables or disables keepalive. + /// + /// The keepalive behavior can be adjusted using: + /// - `keep-alive-idle-time` + /// - `keep-alive-interval` + /// - `keep-alive-count` + /// These properties can be configured while `keep-alive-enabled` is false, but only come into effect when `keep-alive-enabled` is true. + /// + /// Equivalent to the SO_KEEPALIVE socket option. + @since(version = 0.2.0) + keep-alive-enabled: func() -> result; + @since(version = 0.2.0) + set-keep-alive-enabled: func(value: bool) -> result<_, error-code>; + + /// Amount of time the connection has to be idle before TCP starts sending keepalive packets. + /// + /// If the provided value is 0, an `invalid-argument` error is returned. + /// Any other value will never cause an error, but it might be silently clamped and/or rounded. + /// I.e. after setting a value, reading the same setting back may return a different value. + /// + /// Equivalent to the TCP_KEEPIDLE socket option. (TCP_KEEPALIVE on MacOS) + /// + /// # Typical errors + /// - `invalid-argument`: (set) The provided value was 0. + @since(version = 0.2.0) + keep-alive-idle-time: func() -> result; + @since(version = 0.2.0) + set-keep-alive-idle-time: func(value: duration) -> result<_, error-code>; + + /// The time between keepalive packets. + /// + /// If the provided value is 0, an `invalid-argument` error is returned. + /// Any other value will never cause an error, but it might be silently clamped and/or rounded. + /// I.e. after setting a value, reading the same setting back may return a different value. + /// + /// Equivalent to the TCP_KEEPINTVL socket option. + /// + /// # Typical errors + /// - `invalid-argument`: (set) The provided value was 0. + @since(version = 0.2.0) + keep-alive-interval: func() -> result; + @since(version = 0.2.0) + set-keep-alive-interval: func(value: duration) -> result<_, error-code>; + + /// The maximum amount of keepalive packets TCP should send before aborting the connection. + /// + /// If the provided value is 0, an `invalid-argument` error is returned. + /// Any other value will never cause an error, but it might be silently clamped and/or rounded. + /// I.e. after setting a value, reading the same setting back may return a different value. + /// + /// Equivalent to the TCP_KEEPCNT socket option. + /// + /// # Typical errors + /// - `invalid-argument`: (set) The provided value was 0. + @since(version = 0.2.0) + keep-alive-count: func() -> result; + @since(version = 0.2.0) + set-keep-alive-count: func(value: u32) -> result<_, error-code>; + + /// Equivalent to the IP_TTL & IPV6_UNICAST_HOPS socket options. + /// + /// If the provided value is 0, an `invalid-argument` error is returned. + /// + /// # Typical errors + /// - `invalid-argument`: (set) The TTL value must be 1 or higher. + @since(version = 0.2.0) + hop-limit: func() -> result; + @since(version = 0.2.0) + set-hop-limit: func(value: u8) -> result<_, error-code>; + + /// The kernel buffer space reserved for sends/receives on this socket. + /// + /// If the provided value is 0, an `invalid-argument` error is returned. + /// Any other value will never cause an error, but it might be silently clamped and/or rounded. + /// I.e. after setting a value, reading the same setting back may return a different value. + /// + /// Equivalent to the SO_RCVBUF and SO_SNDBUF socket options. + /// + /// # Typical errors + /// - `invalid-argument`: (set) The provided value was 0. + @since(version = 0.2.0) + receive-buffer-size: func() -> result; + @since(version = 0.2.0) + set-receive-buffer-size: func(value: u64) -> result<_, error-code>; + @since(version = 0.2.0) + send-buffer-size: func() -> result; + @since(version = 0.2.0) + set-send-buffer-size: func(value: u64) -> result<_, error-code>; + + /// Create a `pollable` which can be used to poll for, or block on, + /// completion of any of the asynchronous operations of this socket. + /// + /// When `finish-bind`, `finish-listen`, `finish-connect` or `accept` + /// return `error(would-block)`, this pollable can be used to wait for + /// their success or failure, after which the method can be retried. + /// + /// The pollable is not limited to the async operation that happens to be + /// in progress at the time of calling `subscribe` (if any). Theoretically, + /// `subscribe` only has to be called once per socket and can then be + /// (re)used for the remainder of the socket's lifetime. + /// + /// See + /// for more information. + /// + /// Note: this function is here for WASI Preview2 only. + /// It's planned to be removed when `future` is natively supported in Preview3. + @since(version = 0.2.0) + subscribe: func() -> pollable; + + /// Initiate a graceful shutdown. + /// + /// - `receive`: The socket is not expecting to receive any data from + /// the peer. The `input-stream` associated with this socket will be + /// closed. Any data still in the receive queue at time of calling + /// this method will be discarded. + /// - `send`: The socket has no more data to send to the peer. The `output-stream` + /// associated with this socket will be closed and a FIN packet will be sent. + /// - `both`: Same effect as `receive` & `send` combined. + /// + /// This function is idempotent; shutting down a direction more than once + /// has no effect and returns `ok`. + /// + /// The shutdown function does not close (drop) the socket. + /// + /// # Typical errors + /// - `invalid-state`: The socket is not in the `connected` state. (ENOTCONN) + /// + /// # References + /// - + /// - + /// - + /// - + @since(version = 0.2.0) + shutdown: func(shutdown-type: shutdown-type) -> result<_, error-code>; + } +} diff --git a/examples/go/http/wit/deps/sockets/udp-create-socket.wit b/examples/go/http/wit/deps/sockets/udp-create-socket.wit new file mode 100644 index 0000000..e8eeacb --- /dev/null +++ b/examples/go/http/wit/deps/sockets/udp-create-socket.wit @@ -0,0 +1,30 @@ +@since(version = 0.2.0) +interface udp-create-socket { + @since(version = 0.2.0) + use network.{network, error-code, ip-address-family}; + @since(version = 0.2.0) + use udp.{udp-socket}; + + /// Create a new UDP socket. + /// + /// Similar to `socket(AF_INET or AF_INET6, SOCK_DGRAM, IPPROTO_UDP)` in POSIX. + /// On IPv6 sockets, IPV6_V6ONLY is enabled by default and can't be configured otherwise. + /// + /// This function does not require a network capability handle. This is considered to be safe because + /// at time of creation, the socket is not bound to any `network` yet. Up to the moment `bind` is called, + /// the socket is effectively an in-memory configuration object, unable to communicate with the outside world. + /// + /// All sockets are non-blocking. Use the wasi-poll interface to block on asynchronous operations. + /// + /// # Typical errors + /// - `not-supported`: The specified `address-family` is not supported. (EAFNOSUPPORT) + /// - `new-socket-limit`: The new socket resource could not be created because of a system limit. (EMFILE, ENFILE) + /// + /// # References: + /// - + /// - + /// - + /// - + @since(version = 0.2.0) + create-udp-socket: func(address-family: ip-address-family) -> result; +} diff --git a/examples/go/http/wit/deps/sockets/udp.wit b/examples/go/http/wit/deps/sockets/udp.wit new file mode 100644 index 0000000..b289e49 --- /dev/null +++ b/examples/go/http/wit/deps/sockets/udp.wit @@ -0,0 +1,288 @@ +@since(version = 0.2.0) +interface udp { + @since(version = 0.2.0) + use wasi:io/poll@0.2.1.{pollable}; + @since(version = 0.2.0) + use network.{network, error-code, ip-socket-address, ip-address-family}; + + /// A received datagram. + @since(version = 0.2.0) + record incoming-datagram { + /// The payload. + /// + /// Theoretical max size: ~64 KiB. In practice, typically less than 1500 bytes. + data: list, + + /// The source address. + /// + /// This field is guaranteed to match the remote address the stream was initialized with, if any. + /// + /// Equivalent to the `src_addr` out parameter of `recvfrom`. + remote-address: ip-socket-address, + } + + /// A datagram to be sent out. + @since(version = 0.2.0) + record outgoing-datagram { + /// The payload. + data: list, + + /// The destination address. + /// + /// The requirements on this field depend on how the stream was initialized: + /// - with a remote address: this field must be None or match the stream's remote address exactly. + /// - without a remote address: this field is required. + /// + /// If this value is None, the send operation is equivalent to `send` in POSIX. Otherwise it is equivalent to `sendto`. + remote-address: option, + } + + /// A UDP socket handle. + @since(version = 0.2.0) + resource udp-socket { + /// Bind the socket to a specific network on the provided IP address and port. + /// + /// If the IP address is zero (`0.0.0.0` in IPv4, `::` in IPv6), it is left to the implementation to decide which + /// network interface(s) to bind to. + /// If the port is zero, the socket will be bound to a random free port. + /// + /// # Typical errors + /// - `invalid-argument`: The `local-address` has the wrong address family. (EAFNOSUPPORT, EFAULT on Windows) + /// - `invalid-state`: The socket is already bound. (EINVAL) + /// - `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 the `network` can bind to. (EADDRNOTAVAIL) + /// - `not-in-progress`: A `bind` operation is not in progress. + /// - `would-block`: Can't finish the operation, it is still in progress. (EWOULDBLOCK, EAGAIN) + /// + /// # Implementors note + /// Unlike in POSIX, in WASI the bind operation is async. This enables + /// interactive WASI hosts to inject permission prompts. Runtimes that + /// don't want to make use of this ability can simply call the native + /// `bind` as part of either `start-bind` or `finish-bind`. + /// + /// # References + /// - + /// - + /// - + /// - + @since(version = 0.2.0) + start-bind: func(network: borrow, local-address: ip-socket-address) -> result<_, error-code>; + @since(version = 0.2.0) + finish-bind: func() -> result<_, error-code>; + + /// Set up inbound & outbound communication channels, optionally to a specific peer. + /// + /// This function only changes the local socket configuration and does not generate any network traffic. + /// On success, the `remote-address` of the socket is updated. The `local-address` may be updated as well, + /// based on the best network path to `remote-address`. + /// + /// When a `remote-address` is provided, the returned streams are limited to communicating with that specific peer: + /// - `send` can only be used to send to this destination. + /// - `receive` will only return datagrams sent from the provided `remote-address`. + /// + /// This method may be called multiple times on the same socket to change its association, but + /// only the most recently returned pair of streams will be operational. Implementations may trap if + /// the streams returned by a previous invocation haven't been dropped yet before calling `stream` again. + /// + /// The POSIX equivalent in pseudo-code is: + /// ```text + /// if (was previously connected) { + /// connect(s, AF_UNSPEC) + /// } + /// if (remote_address is Some) { + /// connect(s, remote_address) + /// } + /// ``` + /// + /// Unlike in POSIX, the socket must already be explicitly bound. + /// + /// # Typical errors + /// - `invalid-argument`: The `remote-address` has the wrong address family. (EAFNOSUPPORT) + /// - `invalid-argument`: The IP address in `remote-address` is set to INADDR_ANY (`0.0.0.0` / `::`). (EDESTADDRREQ, EADDRNOTAVAIL) + /// - `invalid-argument`: The port in `remote-address` is set to 0. (EDESTADDRREQ, EADDRNOTAVAIL) + /// - `invalid-state`: The socket is not bound. + /// - `address-in-use`: Tried to perform an implicit bind, but there were no ephemeral ports available. (EADDRINUSE, EADDRNOTAVAIL on Linux, EAGAIN on BSD) + /// - `remote-unreachable`: The remote address is not reachable. (ECONNRESET, ENETRESET, EHOSTUNREACH, EHOSTDOWN, ENETUNREACH, ENETDOWN, ENONET) + /// - `connection-refused`: The connection was refused. (ECONNREFUSED) + /// + /// # References + /// - + /// - + /// - + /// - + @since(version = 0.2.0) + %stream: func(remote-address: option) -> result, error-code>; + + /// Get the current bound address. + /// + /// POSIX mentions: + /// > If the socket has not been bound to a local name, the value + /// > stored in the object pointed to by `address` is unspecified. + /// + /// WASI is stricter and requires `local-address` to return `invalid-state` when the socket hasn't been bound yet. + /// + /// # Typical errors + /// - `invalid-state`: The socket is not bound to any local address. + /// + /// # References + /// - + /// - + /// - + /// - + @since(version = 0.2.0) + local-address: func() -> result; + + /// Get the address the socket is currently streaming to. + /// + /// # Typical errors + /// - `invalid-state`: The socket is not streaming to a specific remote address. (ENOTCONN) + /// + /// # References + /// - + /// - + /// - + /// - + @since(version = 0.2.0) + remote-address: func() -> result; + + /// Whether this is a IPv4 or IPv6 socket. + /// + /// Equivalent to the SO_DOMAIN socket option. + @since(version = 0.2.0) + address-family: func() -> ip-address-family; + + /// Equivalent to the IP_TTL & IPV6_UNICAST_HOPS socket options. + /// + /// If the provided value is 0, an `invalid-argument` error is returned. + /// + /// # Typical errors + /// - `invalid-argument`: (set) The TTL value must be 1 or higher. + @since(version = 0.2.0) + unicast-hop-limit: func() -> result; + @since(version = 0.2.0) + set-unicast-hop-limit: func(value: u8) -> result<_, error-code>; + + /// The kernel buffer space reserved for sends/receives on this socket. + /// + /// If the provided value is 0, an `invalid-argument` error is returned. + /// Any other value will never cause an error, but it might be silently clamped and/or rounded. + /// I.e. after setting a value, reading the same setting back may return a different value. + /// + /// Equivalent to the SO_RCVBUF and SO_SNDBUF socket options. + /// + /// # Typical errors + /// - `invalid-argument`: (set) The provided value was 0. + @since(version = 0.2.0) + receive-buffer-size: func() -> result; + @since(version = 0.2.0) + set-receive-buffer-size: func(value: u64) -> result<_, error-code>; + @since(version = 0.2.0) + send-buffer-size: func() -> result; + @since(version = 0.2.0) + set-send-buffer-size: func(value: u64) -> result<_, error-code>; + + /// Create a `pollable` which will resolve once the socket is ready for I/O. + /// + /// Note: this function is here for WASI Preview2 only. + /// It's planned to be removed when `future` is natively supported in Preview3. + @since(version = 0.2.0) + subscribe: func() -> pollable; + } + + @since(version = 0.2.0) + resource incoming-datagram-stream { + /// Receive messages on the socket. + /// + /// This function attempts to receive up to `max-results` datagrams on the socket without blocking. + /// The returned list may contain fewer elements than requested, but never more. + /// + /// This function returns successfully with an empty list when either: + /// - `max-results` is 0, or: + /// - `max-results` is greater than 0, but no results are immediately available. + /// This function never returns `error(would-block)`. + /// + /// # Typical errors + /// - `remote-unreachable`: The remote address is not reachable. (ECONNRESET, ENETRESET on Windows, EHOSTUNREACH, EHOSTDOWN, ENETUNREACH, ENETDOWN, ENONET) + /// - `connection-refused`: The connection was refused. (ECONNREFUSED) + /// + /// # References + /// - + /// - + /// - + /// - + /// - + /// - + /// - + /// - + @since(version = 0.2.0) + receive: func(max-results: u64) -> result, error-code>; + + /// Create a `pollable` which will resolve once the stream is ready to receive again. + /// + /// Note: this function is here for WASI Preview2 only. + /// It's planned to be removed when `future` is natively supported in Preview3. + @since(version = 0.2.0) + subscribe: func() -> pollable; + } + + @since(version = 0.2.0) + resource outgoing-datagram-stream { + /// Check readiness for sending. This function never blocks. + /// + /// Returns the number of datagrams permitted for the next call to `send`, + /// or an error. Calling `send` with more datagrams than this function has + /// permitted will trap. + /// + /// When this function returns ok(0), the `subscribe` pollable will + /// become ready when this function will report at least ok(1), or an + /// error. + /// + /// Never returns `would-block`. + check-send: func() -> result; + + /// Send messages on the socket. + /// + /// This function attempts to send all provided `datagrams` on the socket without blocking and + /// returns how many messages were actually sent (or queued for sending). This function never + /// returns `error(would-block)`. If none of the datagrams were able to be sent, `ok(0)` is returned. + /// + /// This function semantically behaves the same as iterating the `datagrams` list and sequentially + /// sending each individual datagram until either the end of the list has been reached or the first error occurred. + /// If at least one datagram has been sent successfully, this function never returns an error. + /// + /// If the input list is empty, the function returns `ok(0)`. + /// + /// Each call to `send` must be permitted by a preceding `check-send`. Implementations must trap if + /// either `check-send` was not called or `datagrams` contains more items than `check-send` permitted. + /// + /// # Typical errors + /// - `invalid-argument`: The `remote-address` has the wrong address family. (EAFNOSUPPORT) + /// - `invalid-argument`: The IP address in `remote-address` is set to INADDR_ANY (`0.0.0.0` / `::`). (EDESTADDRREQ, EADDRNOTAVAIL) + /// - `invalid-argument`: The port in `remote-address` is set to 0. (EDESTADDRREQ, EADDRNOTAVAIL) + /// - `invalid-argument`: The socket is in "connected" mode and `remote-address` is `some` value that does not match the address passed to `stream`. (EISCONN) + /// - `invalid-argument`: The socket is not "connected" and no value for `remote-address` was provided. (EDESTADDRREQ) + /// - `remote-unreachable`: The remote address is not reachable. (ECONNRESET, ENETRESET on Windows, EHOSTUNREACH, EHOSTDOWN, ENETUNREACH, ENETDOWN, ENONET) + /// - `connection-refused`: The connection was refused. (ECONNREFUSED) + /// - `datagram-too-large`: The datagram is too large. (EMSGSIZE) + /// + /// # References + /// - + /// - + /// - + /// - + /// - + /// - + /// - + /// - + @since(version = 0.2.0) + send: func(datagrams: list) -> result; + + /// Create a `pollable` which will resolve once the stream is ready to send again. + /// + /// Note: this function is here for WASI Preview2 only. + /// It's planned to be removed when `future` is natively supported in Preview3. + @since(version = 0.2.0) + subscribe: func() -> pollable; + } +} diff --git a/examples/go/http/wit/deps/sockets/world.wit b/examples/go/http/wit/deps/sockets/world.wit new file mode 100644 index 0000000..a1d4267 --- /dev/null +++ b/examples/go/http/wit/deps/sockets/world.wit @@ -0,0 +1,19 @@ +package wasi:sockets@0.2.1; + +@since(version = 0.2.0) +world imports { + @since(version = 0.2.0) + import instance-network; + @since(version = 0.2.0) + import network; + @since(version = 0.2.0) + import udp; + @since(version = 0.2.0) + import udp-create-socket; + @since(version = 0.2.0) + import tcp; + @since(version = 0.2.0) + import tcp-create-socket; + @since(version = 0.2.0) + import ip-name-lookup; +} diff --git a/go.mod b/go.mod index c01802a..125874e 100644 --- a/go.mod +++ b/go.mod @@ -3,15 +3,17 @@ module github.com/rvolosatovs/west go 1.23.0 require ( + github.com/bytecodealliance/wasm-tools-go v0.2.0 github.com/stretchr/testify v1.9.0 - github.com/ydnar/wasm-tools-go v0.1.5 golang.org/x/tools v0.24.0 ) require ( github.com/davecgh/go-spew v1.1.1 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect - golang.org/x/mod v0.20.0 // indirect + golang.org/x/mod v0.21.0 // indirect golang.org/x/sync v0.8.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) + +replace github.com/rvolosatovs/west => ./. diff --git a/go.sum b/go.sum index bba5fc0..bba474d 100644 --- a/go.sum +++ b/go.sum @@ -1,13 +1,13 @@ +github.com/bytecodealliance/wasm-tools-go v0.2.0 h1:JdmiZew7ewHjf+ZGGRE4gZM85Ad/PGW/5I57hepEOjQ= +github.com/bytecodealliance/wasm-tools-go v0.2.0/go.mod h1:2GnJCUlcDrslZ/L6+yYqoUnewDlBvqRS2N/0NW9ro6w= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= -github.com/ydnar/wasm-tools-go v0.1.5 h1:ah2WT4gH0IrmN29ZSsjgNC9SPsdXZ+KN+o9uTZqNVSI= -github.com/ydnar/wasm-tools-go v0.1.5/go.mod h1:L3sDi5rbAMJNmMO5cpDRzYYhB0r9xIU0xgpKjwU0Adg= -golang.org/x/mod v0.20.0 h1:utOm6MM3R3dnawAiJgn0y+xvuYRsm1RKM/4giyfDgV0= -golang.org/x/mod v0.20.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= +golang.org/x/mod v0.21.0 h1:vvrHzRwRfVKSiLrG+d4FMl/Qi4ukBCE6kZlTUkDYRT0= +golang.org/x/mod v0.21.0/go.mod h1:6SkKJ3Xj0I0BrPOZoBy3bdMptDDU9oJrpohJ3eWZ1fY= golang.org/x/sync v0.8.0 h1:3NFvSEYkUoMifnESzZl15y791HH1qU2xm6eCJU5ZPXQ= golang.org/x/sync v0.8.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= golang.org/x/tools v0.24.0 h1:J1shsA93PJUEVaUSaay7UXAyE8aimq3GW0pjlolpa24= diff --git a/go.work.sum b/go.work.sum index 321d589..0d9205b 100644 --- a/go.work.sum +++ b/go.work.sum @@ -1,11 +1,13 @@ +github.com/coreos/go-semver v0.3.1 h1:yi21YpKnrx1gt5R+la8n5WgS0kCrsPp33dmEyHReZr4= github.com/coreos/go-semver v0.3.1/go.mod h1:irMmmIw/7yzSRPWryHsK7EYSg09caPQL03VsM8rvUec= github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/sergi/go-diff v1.3.1/go.mod h1:aMJSSKb2lpPvRNec0+w3fl7LP9IOFzdc9Pa4NFbPK1I= github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA= +github.com/urfave/cli/v3 v3.0.0-alpha9 h1:P0RMy5fQm1AslQS+XCmy9UknDXctOmG/q/FZkUFnJSo= github.com/urfave/cli/v3 v3.0.0-alpha9/go.mod h1:0kK/RUFHyh+yIKSfWxwheGndfnrvYSmYFVeKCh03ZUc= +github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 h1:bAn7/zixMGCfxrRTfdpNzjtPYqr8smhKouy9mxVdGPU= github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673/go.mod h1:N3UwUGtsrSj3ccvlPHLoLsHnpR27oXr4ZE984MbSER8= github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= golang.org/x/net v0.28.0/go.mod h1:yqtgsTWOOnlGLG9GFRrK3++bGOUEkNBoHZc8MEDWPNg= golang.org/x/sys v0.23.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/telemetry v0.0.0-20240521205824-bda55230c457/go.mod h1:pRgIJT+bRLFKnoM1ldnzKoxTIn14Yxz928LQRYYgIN0= -gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= diff --git a/lib/amd64-linux/lib_linux_amd64.go b/lib/aarch64-windows/lib_windows_arm64.go similarity index 100% rename from lib/amd64-linux/lib_linux_amd64.go rename to lib/aarch64-windows/lib_windows_arm64.go diff --git a/lib/x86_64-linux/lib_linux_amd64.go b/lib/x86_64-linux/lib_linux_amd64.go new file mode 100644 index 0000000..55c21f8 --- /dev/null +++ b/lib/x86_64-linux/lib_linux_amd64.go @@ -0,0 +1 @@ +package lib diff --git a/src/lib.rs b/src/lib.rs index ae9510d..788e958 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,6 +1,7 @@ use core::time::Duration; use anyhow::Context as _; +use tracing::instrument; use wasi_preview1_component_adapter_provider::{ WASI_SNAPSHOT_PREVIEW1_ADAPTER_NAME, WASI_SNAPSHOT_PREVIEW1_REACTOR_ADAPTER, }; @@ -14,13 +15,13 @@ mod bindings { wasmtime::component::bindgen!({ trappable_imports: true, with: { - "wasi:http/types@0.2.0/fields": wasmtime_wasi_http::bindings::http::types::Fields, - "wasi:http/types@0.2.0/future-incoming-response": wasmtime_wasi_http::bindings::http::types::FutureIncomingResponse, - "wasi:http/types@0.2.0/incoming-request": wasmtime_wasi_http::bindings::http::types::IncomingRequest, - "wasi:http/types@0.2.0/outgoing-request": wasmtime_wasi_http::bindings::http::types::OutgoingRequest, - "wasi:http/types@0.2.0/response-outparam": wasmtime_wasi_http::bindings::http::types::ResponseOutparam, + "wasi:http/types@0.2.1/fields": wasmtime_wasi_http::bindings::http::types::Fields, + "wasi:http/types@0.2.1/future-incoming-response": wasmtime_wasi_http::bindings::http::types::FutureIncomingResponse, + "wasi:http/types@0.2.1/incoming-request": wasmtime_wasi_http::bindings::http::types::IncomingRequest, + "wasi:http/types@0.2.1/outgoing-request": wasmtime_wasi_http::bindings::http::types::OutgoingRequest, + "wasi:http/types@0.2.1/response-outparam": wasmtime_wasi_http::bindings::http::types::ResponseOutparam, }, - world: "http-test-passthrough", + world: "imports", }); } @@ -48,7 +49,8 @@ impl WasiHttpView for Ctx { } } -impl bindings::west::test::http_test::Host for Ctx { +impl bindings::wasiext::http::ext::Host for Ctx { + #[instrument(level = "trace", skip_all, ret(level = "trace"))] fn new_response_outparam( &mut self, ) -> wasmtime::Result<( @@ -77,6 +79,7 @@ impl bindings::west::test::http_test::Host for Ctx { Ok((out, res)) } + #[instrument(level = "trace", skip_all, ret(level = "trace"))] fn new_incoming_request( &mut self, req: Resource, @@ -284,7 +287,7 @@ pub fn instantiate(Config { engine, wasm }: Config) -> anyhow::Result wasmtime_wasi::add_to_linker_sync(&mut linker).context("failed to link WASI")?; wasmtime_wasi_http::add_only_http_to_linker_sync(&mut linker) .context("failed to link `wasi:http`")?; - bindings::west::test::http_test::add_to_linker(&mut linker, |cx| cx)?; + bindings::wasiext::http::ext::add_to_linker(&mut linker, |cx| cx)?; let wasi = WasiCtxBuilder::new() .inherit_env() diff --git a/tests/components/wasi/Cargo.toml b/tests/components/wasi/Cargo.toml index 1f4537b..f622360 100644 --- a/tests/components/wasi/Cargo.toml +++ b/tests/components/wasi/Cargo.toml @@ -13,5 +13,5 @@ repository.workspace = true crate-type = ["cdylib"] [dependencies] -west-passthrough = { workspace = true } +wasi-passthrough = { workspace = true } wit-bindgen = { workspace = true, features = ["realloc", "macros"] } diff --git a/tests/components/wasi/src/lib.rs b/tests/components/wasi/src/lib.rs index 4af5de0..8108aee 100644 --- a/tests/components/wasi/src/lib.rs +++ b/tests/components/wasi/src/lib.rs @@ -2,16 +2,20 @@ mod bindings { use crate::Handler; wit_bindgen::generate!({ - world: "host", - path: "../../wit/fib", with: { + "wasi:io/error@0.2.1": wasi_passthrough::bindings::exports::wasi::io::error, + "wasi:io/poll@0.2.1": wasi_passthrough::bindings::exports::wasi::io::poll, + "wasi:io/streams@0.2.1": wasi_passthrough::bindings::exports::wasi::io::streams, "west-test:fib/fib": generate, + "west-test:leftpad/leftpad": generate, } }); export!(Handler); } -use west_passthrough as _; +use core::iter::{self, zip}; + +use wasi_passthrough::bindings::wasi::io::streams::{InputStream, OutputStream, StreamError}; pub struct Handler; @@ -24,3 +28,39 @@ impl bindings::exports::west_test::fib::fib::Guest for Handler { } } } + +impl bindings::exports::west_test::leftpad::leftpad::Guest for Handler { + fn leftpad( + in_: wasi_passthrough::bindings::exports::wasi::io::streams::InputStream, + out: wasi_passthrough::bindings::exports::wasi::io::streams::OutputStreamBorrow<'_>, + len: u64, + c: char, + ) -> Result<(), wasi_passthrough::bindings::exports::wasi::io::streams::StreamError> { + let rx: InputStream = in_.into_inner(); + let tx: &OutputStream = out.get(); + + let mut cs = zip(0..len, iter::repeat(c)).map(|(_, c)| c); + loop { + let mut n = tx.check_write()?; + if n == 0 { + tx.subscribe().block(); + n = tx.check_write()?; + } + let s: Box = cs + .by_ref() + .take(n.try_into().unwrap_or(usize::MAX) / c.len_utf8()) + .collect(); + if s.is_empty() { + break; + } + tx.write(s.as_bytes())?; + } + loop { + match rx.blocking_read(4096) { + Ok(buf) => tx.write(&buf)?, + Err(StreamError::Closed) => return Ok(()), + Err(StreamError::LastOperationFailed(err)) => return Err(wasi_passthrough::bindings::exports::wasi::io::streams::StreamError::LastOperationFailed(err.into())) + } + } + } +} diff --git a/tests/components/wasi/wit/deps/fib b/tests/components/wasi/wit/deps/fib new file mode 120000 index 0000000..fd88a8c --- /dev/null +++ b/tests/components/wasi/wit/deps/fib @@ -0,0 +1 @@ +../../../../wit/fib \ No newline at end of file diff --git a/tests/components/wasi/wit/deps/io b/tests/components/wasi/wit/deps/io new file mode 120000 index 0000000..74876c5 --- /dev/null +++ b/tests/components/wasi/wit/deps/io @@ -0,0 +1 @@ +../../../../../wit/deps/io \ No newline at end of file diff --git a/tests/components/wasi/wit/deps/leftpad b/tests/components/wasi/wit/deps/leftpad new file mode 120000 index 0000000..07b3863 --- /dev/null +++ b/tests/components/wasi/wit/deps/leftpad @@ -0,0 +1 @@ +../../../../wit/leftpad \ No newline at end of file diff --git a/tests/components/wasi/wit/harness.wit b/tests/components/wasi/wit/harness.wit new file mode 100644 index 0000000..9af9a45 --- /dev/null +++ b/tests/components/wasi/wit/harness.wit @@ -0,0 +1,10 @@ +package west-test:wasi; + +world harness { + include west-test:fib/host; + include west-test:leftpad/host; + + export wasi:io/error@0.2.1; + export wasi:io/poll@0.2.1; + export wasi:io/streams@0.2.1; +} diff --git a/tests/go/sync/bindings/west-test/sync/sync/abi.go b/tests/go/sync/bindings/west-test/sync/sync/abi.go index 5e646e4..a1b9acc 100644 --- a/tests/go/sync/bindings/west-test/sync/sync/abi.go +++ b/tests/go/sync/bindings/west-test/sync/sync/abi.go @@ -3,7 +3,7 @@ package sync import ( - "github.com/ydnar/wasm-tools-go/cm" + "github.com/bytecodealliance/wasm-tools-go/cm" "unsafe" ) diff --git a/tests/go/sync/bindings/west-test/sync/sync/sync.wit.go b/tests/go/sync/bindings/west-test/sync/sync/sync.wit.go index 3d00b21..121ccf9 100644 --- a/tests/go/sync/bindings/west-test/sync/sync/sync.wit.go +++ b/tests/go/sync/bindings/west-test/sync/sync/sync.wit.go @@ -4,7 +4,7 @@ package sync import ( - "github.com/ydnar/wasm-tools-go/cm" + "github.com/bytecodealliance/wasm-tools-go/cm" ) // Abc represents the flags "west-test:sync/sync#abc". diff --git a/tests/go/sync/sync.go b/tests/go/sync/sync.go index 7a9e95c..2a72057 100644 --- a/tests/go/sync/sync.go +++ b/tests/go/sync/sync.go @@ -1,4 +1,4 @@ -//go:generate go run github.com/ydnar/wasm-tools-go/cmd/wit-bindgen-go@v0.1.5 generate -w guest -o bindings ../../wit/sync +//go:generate go run github.com/bytecodealliance/wasm-tools-go/cmd/wit-bindgen-go generate -w guest -o bindings ../../wit/sync package sync diff --git a/tests/go/sync/sync_test.go b/tests/go/sync/sync_test.go index ab3716d..420aa9e 100644 --- a/tests/go/sync/sync_test.go +++ b/tests/go/sync/sync_test.go @@ -1,29 +1,36 @@ -//go:generate go run ../../../cmd/west-bindgen-go -//go:generate cargo build -p sync-test-component --target wasm32-wasip1 -//go:generate cp ../../../target/wasm32-wasip1/debug/sync_test_component.wasm component.wasm +//go:generate go run github.com/rvolosatovs/west/cmd/west-bindgen-go +//go:generate cargo build -p sync-test-component --target wasm32-unknown-unknown +//go:generate cp ../../../target/wasm32-unknown-unknown/debug/sync_test_component.wasm component.wasm package sync_test import ( _ "embed" "log" - stdsync "sync" + "log/slog" + "os" "testing" "unsafe" + "github.com/bytecodealliance/wasm-tools-go/cm" "github.com/rvolosatovs/west" "github.com/rvolosatovs/west/tests/go/sync/bindings/west-test/sync/sync" "github.com/stretchr/testify/assert" - "github.com/ydnar/wasm-tools-go/cm" ) -var errorMu stdsync.Mutex - //go:embed component.wasm var component []byte func init() { log.SetFlags(0) + slog.SetDefault(slog.New(slog.NewTextHandler(os.Stderr, &slog.HandlerOptions{ + Level: slog.LevelDebug, ReplaceAttr: func(groups []string, a slog.Attr) slog.Attr { + if a.Key == slog.TimeKey { + return slog.Attr{} + } + return a + }, + }))) instance, err := west.NewInstance(&west.Config{ Wasm: component, diff --git a/tests/go/wasi/bindings/wasi/cli/environment/environment.wit.go b/tests/go/wasi/bindings/wasi/cli/environment/environment.wit.go index a582bdf..19d95cf 100644 --- a/tests/go/wasi/bindings/wasi/cli/environment/environment.wit.go +++ b/tests/go/wasi/bindings/wasi/cli/environment/environment.wit.go @@ -1,10 +1,10 @@ // Code generated by wit-bindgen-go. DO NOT EDIT. -// Package environment represents the imported interface "wasi:cli/environment@0.2.0". +// Package environment represents the imported interface "wasi:cli/environment@0.2.1". package environment import ( - "github.com/ydnar/wasm-tools-go/cm" + "github.com/bytecodealliance/wasm-tools-go/cm" ) // GetEnvironment represents the imported function "get-environment". @@ -26,7 +26,7 @@ func GetEnvironment() (result cm.List[[2]string]) { return } -//go:wasmimport wasi:cli/environment@0.2.0 get-environment +//go:wasmimport wasi:cli/environment@0.2.1 get-environment //go:noescape func wasmimport_GetEnvironment(result *cm.List[[2]string]) @@ -42,7 +42,7 @@ func GetArguments() (result cm.List[string]) { return } -//go:wasmimport wasi:cli/environment@0.2.0 get-arguments +//go:wasmimport wasi:cli/environment@0.2.1 get-arguments //go:noescape func wasmimport_GetArguments(result *cm.List[string]) @@ -59,6 +59,6 @@ func InitialCWD() (result cm.Option[string]) { return } -//go:wasmimport wasi:cli/environment@0.2.0 initial-cwd +//go:wasmimport wasi:cli/environment@0.2.1 initial-cwd //go:noescape func wasmimport_InitialCWD(result *cm.Option[string]) diff --git a/tests/go/wasi/bindings/wasi/cli/exit/exit.wit.go b/tests/go/wasi/bindings/wasi/cli/exit/exit.wit.go index bf46d1b..7cf9449 100644 --- a/tests/go/wasi/bindings/wasi/cli/exit/exit.wit.go +++ b/tests/go/wasi/bindings/wasi/cli/exit/exit.wit.go @@ -1,10 +1,10 @@ // Code generated by wit-bindgen-go. DO NOT EDIT. -// Package exit represents the imported interface "wasi:cli/exit@0.2.0". +// Package exit represents the imported interface "wasi:cli/exit@0.2.1". package exit import ( - "github.com/ydnar/wasm-tools-go/cm" + "github.com/bytecodealliance/wasm-tools-go/cm" ) // Exit represents the imported function "exit". @@ -20,6 +20,30 @@ func Exit(status cm.BoolResult) { return } -//go:wasmimport wasi:cli/exit@0.2.0 exit +//go:wasmimport wasi:cli/exit@0.2.1 exit //go:noescape func wasmimport_Exit(status0 uint32) + +// ExitWithCode represents the imported function "exit-with-code". +// +// Exit the current instance and any linked instances, reporting the +// specified status code to the host. +// +// The meaning of the code depends on the context, with 0 usually meaning +// "success", and other values indicating various types of failure. +// +// This function does not return; the effect is analogous to a trap, but +// without the connotation that something bad has happened. +// +// exit-with-code: func(status-code: u8) +// +//go:nosplit +func ExitWithCode(statusCode uint8) { + statusCode0 := (uint32)(statusCode) + wasmimport_ExitWithCode((uint32)(statusCode0)) + return +} + +//go:wasmimport wasi:cli/exit@0.2.1 exit-with-code +//go:noescape +func wasmimport_ExitWithCode(statusCode0 uint32) diff --git a/tests/go/wasi/bindings/wasi/cli/stderr/stderr.wit.go b/tests/go/wasi/bindings/wasi/cli/stderr/stderr.wit.go index cb64a5a..617be56 100644 --- a/tests/go/wasi/bindings/wasi/cli/stderr/stderr.wit.go +++ b/tests/go/wasi/bindings/wasi/cli/stderr/stderr.wit.go @@ -1,11 +1,11 @@ // Code generated by wit-bindgen-go. DO NOT EDIT. -// Package stderr represents the imported interface "wasi:cli/stderr@0.2.0". +// Package stderr represents the imported interface "wasi:cli/stderr@0.2.1". package stderr import ( + "github.com/bytecodealliance/wasm-tools-go/cm" "github.com/rvolosatovs/west/tests/go/wasi/bindings/wasi/io/streams" - "github.com/ydnar/wasm-tools-go/cm" ) // GetStderr represents the imported function "get-stderr". @@ -19,6 +19,6 @@ func GetStderr() (result streams.OutputStream) { return } -//go:wasmimport wasi:cli/stderr@0.2.0 get-stderr +//go:wasmimport wasi:cli/stderr@0.2.1 get-stderr //go:noescape func wasmimport_GetStderr() (result0 uint32) diff --git a/tests/go/wasi/bindings/wasi/cli/stdin/stdin.wit.go b/tests/go/wasi/bindings/wasi/cli/stdin/stdin.wit.go index 2823537..a2587e3 100644 --- a/tests/go/wasi/bindings/wasi/cli/stdin/stdin.wit.go +++ b/tests/go/wasi/bindings/wasi/cli/stdin/stdin.wit.go @@ -1,11 +1,11 @@ // Code generated by wit-bindgen-go. DO NOT EDIT. -// Package stdin represents the imported interface "wasi:cli/stdin@0.2.0". +// Package stdin represents the imported interface "wasi:cli/stdin@0.2.1". package stdin import ( + "github.com/bytecodealliance/wasm-tools-go/cm" "github.com/rvolosatovs/west/tests/go/wasi/bindings/wasi/io/streams" - "github.com/ydnar/wasm-tools-go/cm" ) // GetStdin represents the imported function "get-stdin". @@ -19,6 +19,6 @@ func GetStdin() (result streams.InputStream) { return } -//go:wasmimport wasi:cli/stdin@0.2.0 get-stdin +//go:wasmimport wasi:cli/stdin@0.2.1 get-stdin //go:noescape func wasmimport_GetStdin() (result0 uint32) diff --git a/tests/go/wasi/bindings/wasi/cli/stdout/stdout.wit.go b/tests/go/wasi/bindings/wasi/cli/stdout/stdout.wit.go index 3d989c0..1d93e36 100644 --- a/tests/go/wasi/bindings/wasi/cli/stdout/stdout.wit.go +++ b/tests/go/wasi/bindings/wasi/cli/stdout/stdout.wit.go @@ -1,11 +1,11 @@ // Code generated by wit-bindgen-go. DO NOT EDIT. -// Package stdout represents the imported interface "wasi:cli/stdout@0.2.0". +// Package stdout represents the imported interface "wasi:cli/stdout@0.2.1". package stdout import ( + "github.com/bytecodealliance/wasm-tools-go/cm" "github.com/rvolosatovs/west/tests/go/wasi/bindings/wasi/io/streams" - "github.com/ydnar/wasm-tools-go/cm" ) // GetStdout represents the imported function "get-stdout". @@ -19,6 +19,6 @@ func GetStdout() (result streams.OutputStream) { return } -//go:wasmimport wasi:cli/stdout@0.2.0 get-stdout +//go:wasmimport wasi:cli/stdout@0.2.1 get-stdout //go:noescape func wasmimport_GetStdout() (result0 uint32) diff --git a/tests/go/wasi/bindings/wasi/cli/terminal-input/terminal-input.wit.go b/tests/go/wasi/bindings/wasi/cli/terminal-input/terminal-input.wit.go index 9dca7df..42bf805 100644 --- a/tests/go/wasi/bindings/wasi/cli/terminal-input/terminal-input.wit.go +++ b/tests/go/wasi/bindings/wasi/cli/terminal-input/terminal-input.wit.go @@ -1,6 +1,6 @@ // Code generated by wit-bindgen-go. DO NOT EDIT. -// Package terminalinput represents the imported interface "wasi:cli/terminal-input@0.2.0". +// Package terminalinput represents the imported interface "wasi:cli/terminal-input@0.2.1". // // Terminal input. // @@ -10,10 +10,10 @@ package terminalinput import ( - "github.com/ydnar/wasm-tools-go/cm" + "github.com/bytecodealliance/wasm-tools-go/cm" ) -// TerminalInput represents the imported resource "wasi:cli/terminal-input@0.2.0#terminal-input". +// TerminalInput represents the imported resource "wasi:cli/terminal-input@0.2.1#terminal-input". // // The input side of a terminal. // @@ -31,6 +31,6 @@ func (self TerminalInput) ResourceDrop() { return } -//go:wasmimport wasi:cli/terminal-input@0.2.0 [resource-drop]terminal-input +//go:wasmimport wasi:cli/terminal-input@0.2.1 [resource-drop]terminal-input //go:noescape func wasmimport_TerminalInputResourceDrop(self0 uint32) diff --git a/tests/go/wasi/bindings/wasi/cli/terminal-output/terminal-output.wit.go b/tests/go/wasi/bindings/wasi/cli/terminal-output/terminal-output.wit.go index b6ff728..e266abc 100644 --- a/tests/go/wasi/bindings/wasi/cli/terminal-output/terminal-output.wit.go +++ b/tests/go/wasi/bindings/wasi/cli/terminal-output/terminal-output.wit.go @@ -1,6 +1,6 @@ // Code generated by wit-bindgen-go. DO NOT EDIT. -// Package terminaloutput represents the imported interface "wasi:cli/terminal-output@0.2.0". +// Package terminaloutput represents the imported interface "wasi:cli/terminal-output@0.2.1". // // Terminal output. // @@ -10,10 +10,10 @@ package terminaloutput import ( - "github.com/ydnar/wasm-tools-go/cm" + "github.com/bytecodealliance/wasm-tools-go/cm" ) -// TerminalOutput represents the imported resource "wasi:cli/terminal-output@0.2.0#terminal-output". +// TerminalOutput represents the imported resource "wasi:cli/terminal-output@0.2.1#terminal-output". // // The output side of a terminal. // @@ -31,6 +31,6 @@ func (self TerminalOutput) ResourceDrop() { return } -//go:wasmimport wasi:cli/terminal-output@0.2.0 [resource-drop]terminal-output +//go:wasmimport wasi:cli/terminal-output@0.2.1 [resource-drop]terminal-output //go:noescape func wasmimport_TerminalOutputResourceDrop(self0 uint32) diff --git a/tests/go/wasi/bindings/wasi/cli/terminal-stderr/terminal-stderr.wit.go b/tests/go/wasi/bindings/wasi/cli/terminal-stderr/terminal-stderr.wit.go index fbcd3ac..e71c3ef 100644 --- a/tests/go/wasi/bindings/wasi/cli/terminal-stderr/terminal-stderr.wit.go +++ b/tests/go/wasi/bindings/wasi/cli/terminal-stderr/terminal-stderr.wit.go @@ -1,14 +1,14 @@ // Code generated by wit-bindgen-go. DO NOT EDIT. -// Package terminalstderr represents the imported interface "wasi:cli/terminal-stderr@0.2.0". +// Package terminalstderr represents the imported interface "wasi:cli/terminal-stderr@0.2.1". // // An interface providing an optional `terminal-output` for stderr as a // link-time authority. package terminalstderr import ( + "github.com/bytecodealliance/wasm-tools-go/cm" terminaloutput "github.com/rvolosatovs/west/tests/go/wasi/bindings/wasi/cli/terminal-output" - "github.com/ydnar/wasm-tools-go/cm" ) // GetTerminalStderr represents the imported function "get-terminal-stderr". @@ -24,6 +24,6 @@ func GetTerminalStderr() (result cm.Option[terminaloutput.TerminalOutput]) { return } -//go:wasmimport wasi:cli/terminal-stderr@0.2.0 get-terminal-stderr +//go:wasmimport wasi:cli/terminal-stderr@0.2.1 get-terminal-stderr //go:noescape func wasmimport_GetTerminalStderr(result *cm.Option[terminaloutput.TerminalOutput]) diff --git a/tests/go/wasi/bindings/wasi/cli/terminal-stdin/terminal-stdin.wit.go b/tests/go/wasi/bindings/wasi/cli/terminal-stdin/terminal-stdin.wit.go index dd4fcbc..5c230d9 100644 --- a/tests/go/wasi/bindings/wasi/cli/terminal-stdin/terminal-stdin.wit.go +++ b/tests/go/wasi/bindings/wasi/cli/terminal-stdin/terminal-stdin.wit.go @@ -1,14 +1,14 @@ // Code generated by wit-bindgen-go. DO NOT EDIT. -// Package terminalstdin represents the imported interface "wasi:cli/terminal-stdin@0.2.0". +// Package terminalstdin represents the imported interface "wasi:cli/terminal-stdin@0.2.1". // // An interface providing an optional `terminal-input` for stdin as a // link-time authority. package terminalstdin import ( + "github.com/bytecodealliance/wasm-tools-go/cm" terminalinput "github.com/rvolosatovs/west/tests/go/wasi/bindings/wasi/cli/terminal-input" - "github.com/ydnar/wasm-tools-go/cm" ) // GetTerminalStdin represents the imported function "get-terminal-stdin". @@ -24,6 +24,6 @@ func GetTerminalStdin() (result cm.Option[terminalinput.TerminalInput]) { return } -//go:wasmimport wasi:cli/terminal-stdin@0.2.0 get-terminal-stdin +//go:wasmimport wasi:cli/terminal-stdin@0.2.1 get-terminal-stdin //go:noescape func wasmimport_GetTerminalStdin(result *cm.Option[terminalinput.TerminalInput]) diff --git a/tests/go/wasi/bindings/wasi/cli/terminal-stdout/terminal-stdout.wit.go b/tests/go/wasi/bindings/wasi/cli/terminal-stdout/terminal-stdout.wit.go index d8b46bc..f660195 100644 --- a/tests/go/wasi/bindings/wasi/cli/terminal-stdout/terminal-stdout.wit.go +++ b/tests/go/wasi/bindings/wasi/cli/terminal-stdout/terminal-stdout.wit.go @@ -1,14 +1,14 @@ // Code generated by wit-bindgen-go. DO NOT EDIT. -// Package terminalstdout represents the imported interface "wasi:cli/terminal-stdout@0.2.0". +// Package terminalstdout represents the imported interface "wasi:cli/terminal-stdout@0.2.1". // // An interface providing an optional `terminal-output` for stdout as a // link-time authority. package terminalstdout import ( + "github.com/bytecodealliance/wasm-tools-go/cm" terminaloutput "github.com/rvolosatovs/west/tests/go/wasi/bindings/wasi/cli/terminal-output" - "github.com/ydnar/wasm-tools-go/cm" ) // GetTerminalStdout represents the imported function "get-terminal-stdout". @@ -24,6 +24,6 @@ func GetTerminalStdout() (result cm.Option[terminaloutput.TerminalOutput]) { return } -//go:wasmimport wasi:cli/terminal-stdout@0.2.0 get-terminal-stdout +//go:wasmimport wasi:cli/terminal-stdout@0.2.1 get-terminal-stdout //go:noescape func wasmimport_GetTerminalStdout(result *cm.Option[terminaloutput.TerminalOutput]) diff --git a/tests/go/wasi/bindings/wasi/clocks/monotonic-clock/monotonic-clock.wit.go b/tests/go/wasi/bindings/wasi/clocks/monotonic-clock/monotonic-clock.wit.go index 15e7ec8..b2d6dbb 100644 --- a/tests/go/wasi/bindings/wasi/clocks/monotonic-clock/monotonic-clock.wit.go +++ b/tests/go/wasi/bindings/wasi/clocks/monotonic-clock/monotonic-clock.wit.go @@ -1,6 +1,6 @@ // Code generated by wit-bindgen-go. DO NOT EDIT. -// Package monotonicclock represents the imported interface "wasi:clocks/monotonic-clock@0.2.0". +// Package monotonicclock represents the imported interface "wasi:clocks/monotonic-clock@0.2.1". // // WASI Monotonic Clock is a clock API intended to let users measure elapsed // time. @@ -10,16 +10,14 @@ // // A monotonic clock is a clock which has an unspecified initial value, and // successive reads of the clock will produce non-decreasing values. -// -// It is intended for measuring elapsed time. package monotonicclock import ( + "github.com/bytecodealliance/wasm-tools-go/cm" "github.com/rvolosatovs/west/tests/go/wasi/bindings/wasi/io/poll" - "github.com/ydnar/wasm-tools-go/cm" ) -// Instant represents the u64 "wasi:clocks/monotonic-clock@0.2.0#instant". +// Instant represents the u64 "wasi:clocks/monotonic-clock@0.2.1#instant". // // An instant in time, in nanoseconds. An instant is relative to an // unspecified initial value, and can only be compared to instances from @@ -28,7 +26,7 @@ import ( // type instant = u64 type Instant uint64 -// Duration represents the u64 "wasi:clocks/monotonic-clock@0.2.0#duration". +// Duration represents the u64 "wasi:clocks/monotonic-clock@0.2.1#duration". // // A duration of time, in nanoseconds. // @@ -51,7 +49,7 @@ func Now() (result Instant) { return } -//go:wasmimport wasi:clocks/monotonic-clock@0.2.0 now +//go:wasmimport wasi:clocks/monotonic-clock@0.2.1 now //go:noescape func wasmimport_Now() (result0 uint64) @@ -69,14 +67,14 @@ func Resolution() (result Duration) { return } -//go:wasmimport wasi:clocks/monotonic-clock@0.2.0 resolution +//go:wasmimport wasi:clocks/monotonic-clock@0.2.1 resolution //go:noescape func wasmimport_Resolution() (result0 uint64) // SubscribeInstant represents the imported function "subscribe-instant". // // Create a `pollable` which will resolve once the specified instant -// occured. +// has occurred. // // subscribe-instant: func(when: instant) -> pollable // @@ -88,15 +86,14 @@ func SubscribeInstant(when Instant) (result poll.Pollable) { return } -//go:wasmimport wasi:clocks/monotonic-clock@0.2.0 subscribe-instant +//go:wasmimport wasi:clocks/monotonic-clock@0.2.1 subscribe-instant //go:noescape func wasmimport_SubscribeInstant(when0 uint64) (result0 uint32) // SubscribeDuration represents the imported function "subscribe-duration". // -// Create a `pollable` which will resolve once the given duration has -// elapsed, starting at the time at which this function was called. -// occured. +// Create a `pollable` that will resolve after the specified duration has +// elapsed from the time this function is invoked. // // subscribe-duration: func(when: duration) -> pollable // @@ -108,6 +105,6 @@ func SubscribeDuration(when Duration) (result poll.Pollable) { return } -//go:wasmimport wasi:clocks/monotonic-clock@0.2.0 subscribe-duration +//go:wasmimport wasi:clocks/monotonic-clock@0.2.1 subscribe-duration //go:noescape func wasmimport_SubscribeDuration(when0 uint64) (result0 uint32) diff --git a/tests/go/wasi/bindings/wasi/clocks/timezone/abi.go b/tests/go/wasi/bindings/wasi/clocks/timezone/abi.go new file mode 100644 index 0000000..bb9d150 --- /dev/null +++ b/tests/go/wasi/bindings/wasi/clocks/timezone/abi.go @@ -0,0 +1,13 @@ +// Code generated by wit-bindgen-go. DO NOT EDIT. + +package timezone + +import ( + wallclock "github.com/rvolosatovs/west/tests/go/wasi/bindings/wasi/clocks/wall-clock" +) + +func lower_DateTime(v wallclock.DateTime) (f0 uint64, f1 uint32) { + f0 = (uint64)(v.Seconds) + f1 = (uint32)(v.Nanoseconds) + return +} diff --git a/tests/go/wasi/bindings/wasi/clocks/timezone/empty.s b/tests/go/wasi/bindings/wasi/clocks/timezone/empty.s new file mode 100644 index 0000000..5444f20 --- /dev/null +++ b/tests/go/wasi/bindings/wasi/clocks/timezone/empty.s @@ -0,0 +1,3 @@ +// This file exists for testing this package without WebAssembly, +// allowing empty function bodies with a //go:wasmimport directive. +// See https://pkg.go.dev/cmd/compile for more information. diff --git a/tests/go/wasi/bindings/wasi/clocks/timezone/timezone.wit.go b/tests/go/wasi/bindings/wasi/clocks/timezone/timezone.wit.go new file mode 100644 index 0000000..f7df12a --- /dev/null +++ b/tests/go/wasi/bindings/wasi/clocks/timezone/timezone.wit.go @@ -0,0 +1,90 @@ +// Code generated by wit-bindgen-go. DO NOT EDIT. + +// Package timezone represents the imported interface "wasi:clocks/timezone@0.2.1". +package timezone + +import ( + wallclock "github.com/rvolosatovs/west/tests/go/wasi/bindings/wasi/clocks/wall-clock" +) + +// TimezoneDisplay represents the record "wasi:clocks/timezone@0.2.1#timezone-display". +// +// Information useful for displaying the timezone of a specific `datetime`. +// +// This information may vary within a single `timezone` to reflect daylight +// saving time adjustments. +// +// record timezone-display { +// utc-offset: s32, +// name: string, +// in-daylight-saving-time: bool, +// } +type TimezoneDisplay struct { + // The number of seconds difference between UTC time and the local + // time of the timezone. + // + // The returned value will always be less than 86400 which is the + // number of seconds in a day (24*60*60). + // + // In implementations that do not expose an actual time zone, this + // should return 0. + UtcOffset int32 + + // The abbreviated name of the timezone to display to a user. The name + // `UTC` indicates Coordinated Universal Time. Otherwise, this should + // reference local standards for the name of the time zone. + // + // In implementations that do not expose an actual time zone, this + // should be the string `UTC`. + // + // In time zones that do not have an applicable name, a formatted + // representation of the UTC offset may be returned, such as `-04:00`. + Name string + + // Whether daylight saving time is active. + // + // In implementations that do not expose an actual time zone, this + // should return false. + InDaylightSavingTime bool +} + +// Display represents the imported function "display". +// +// Return information needed to display the given `datetime`. This includes +// the UTC offset, the time zone name, and a flag indicating whether +// daylight saving time is active. +// +// If the timezone cannot be determined for the given `datetime`, return a +// `timezone-display` for `UTC` with a `utc-offset` of 0 and no daylight +// saving time. +// +// display: func(when: datetime) -> timezone-display +// +//go:nosplit +func Display(when wallclock.DateTime) (result TimezoneDisplay) { + when0, when1 := lower_DateTime(when) + wasmimport_Display((uint64)(when0), (uint32)(when1), &result) + return +} + +//go:wasmimport wasi:clocks/timezone@0.2.1 display +//go:noescape +func wasmimport_Display(when0 uint64, when1 uint32, result *TimezoneDisplay) + +// UtcOffset represents the imported function "utc-offset". +// +// The same as `display`, but only return the UTC offset. +// +// utc-offset: func(when: datetime) -> s32 +// +//go:nosplit +func UtcOffset(when wallclock.DateTime) (result int32) { + when0, when1 := lower_DateTime(when) + result0 := wasmimport_UtcOffset((uint64)(when0), (uint32)(when1)) + result = (int32)((uint32)(result0)) + return +} + +//go:wasmimport wasi:clocks/timezone@0.2.1 utc-offset +//go:noescape +func wasmimport_UtcOffset(when0 uint64, when1 uint32) (result0 uint32) diff --git a/tests/go/wasi/bindings/wasi/clocks/wall-clock/wall-clock.wit.go b/tests/go/wasi/bindings/wasi/clocks/wall-clock/wall-clock.wit.go index a59a313..20dd2bb 100644 --- a/tests/go/wasi/bindings/wasi/clocks/wall-clock/wall-clock.wit.go +++ b/tests/go/wasi/bindings/wasi/clocks/wall-clock/wall-clock.wit.go @@ -1,6 +1,6 @@ // Code generated by wit-bindgen-go. DO NOT EDIT. -// Package wallclock represents the imported interface "wasi:clocks/wall-clock@0.2.0". +// Package wallclock represents the imported interface "wasi:clocks/wall-clock@0.2.1". // // WASI Wall Clock is a clock API intended to let users query the current // time. The name "wall" makes an analogy to a "clock on the wall", which @@ -18,7 +18,7 @@ // It is intended for reporting the current date and time for humans. package wallclock -// DateTime represents the record "wasi:clocks/wall-clock@0.2.0#datetime". +// DateTime represents the record "wasi:clocks/wall-clock@0.2.1#datetime". // // A time and date in seconds plus nanoseconds. // @@ -55,7 +55,7 @@ func Now() (result DateTime) { return } -//go:wasmimport wasi:clocks/wall-clock@0.2.0 now +//go:wasmimport wasi:clocks/wall-clock@0.2.1 now //go:noescape func wasmimport_Now(result *DateTime) @@ -73,6 +73,6 @@ func Resolution() (result DateTime) { return } -//go:wasmimport wasi:clocks/wall-clock@0.2.0 resolution +//go:wasmimport wasi:clocks/wall-clock@0.2.1 resolution //go:noescape func wasmimport_Resolution(result *DateTime) diff --git a/tests/go/wasi/bindings/wasi/filesystem/preopens/preopens.wit.go b/tests/go/wasi/bindings/wasi/filesystem/preopens/preopens.wit.go index 1a9149d..b7ba9a1 100644 --- a/tests/go/wasi/bindings/wasi/filesystem/preopens/preopens.wit.go +++ b/tests/go/wasi/bindings/wasi/filesystem/preopens/preopens.wit.go @@ -1,11 +1,11 @@ // Code generated by wit-bindgen-go. DO NOT EDIT. -// Package preopens represents the imported interface "wasi:filesystem/preopens@0.2.0". +// Package preopens represents the imported interface "wasi:filesystem/preopens@0.2.1". package preopens import ( + "github.com/bytecodealliance/wasm-tools-go/cm" "github.com/rvolosatovs/west/tests/go/wasi/bindings/wasi/filesystem/types" - "github.com/ydnar/wasm-tools-go/cm" ) // GetDirectories represents the imported function "get-directories". @@ -20,6 +20,6 @@ func GetDirectories() (result cm.List[cm.Tuple[types.Descriptor, string]]) { return } -//go:wasmimport wasi:filesystem/preopens@0.2.0 get-directories +//go:wasmimport wasi:filesystem/preopens@0.2.1 get-directories //go:noescape func wasmimport_GetDirectories(result *cm.List[cm.Tuple[types.Descriptor, string]]) diff --git a/tests/go/wasi/bindings/wasi/filesystem/types/abi.go b/tests/go/wasi/bindings/wasi/filesystem/types/abi.go index 3edb7a5..c387688 100644 --- a/tests/go/wasi/bindings/wasi/filesystem/types/abi.go +++ b/tests/go/wasi/bindings/wasi/filesystem/types/abi.go @@ -3,8 +3,8 @@ package types import ( + "github.com/bytecodealliance/wasm-tools-go/cm" wallclock "github.com/rvolosatovs/west/tests/go/wasi/bindings/wasi/clocks/wall-clock" - "github.com/ydnar/wasm-tools-go/cm" "unsafe" ) diff --git a/tests/go/wasi/bindings/wasi/filesystem/types/types.wit.go b/tests/go/wasi/bindings/wasi/filesystem/types/types.wit.go index 5e9b357..123ebb2 100644 --- a/tests/go/wasi/bindings/wasi/filesystem/types/types.wit.go +++ b/tests/go/wasi/bindings/wasi/filesystem/types/types.wit.go @@ -1,6 +1,6 @@ // Code generated by wit-bindgen-go. DO NOT EDIT. -// Package types represents the imported interface "wasi:filesystem/types@0.2.0". +// Package types represents the imported interface "wasi:filesystem/types@0.2.1". // // WASI filesystem is a filesystem API primarily intended to let users run WASI // programs that access their files on their existing filesystems, without @@ -29,20 +29,20 @@ package types import ( + "github.com/bytecodealliance/wasm-tools-go/cm" wallclock "github.com/rvolosatovs/west/tests/go/wasi/bindings/wasi/clocks/wall-clock" ioerror "github.com/rvolosatovs/west/tests/go/wasi/bindings/wasi/io/error" "github.com/rvolosatovs/west/tests/go/wasi/bindings/wasi/io/streams" - "github.com/ydnar/wasm-tools-go/cm" ) -// FileSize represents the u64 "wasi:filesystem/types@0.2.0#filesize". +// FileSize represents the u64 "wasi:filesystem/types@0.2.1#filesize". // // File size or length of a region within a file. // // type filesize = u64 type FileSize uint64 -// DescriptorType represents the enum "wasi:filesystem/types@0.2.0#descriptor-type". +// DescriptorType represents the enum "wasi:filesystem/types@0.2.1#descriptor-type". // // The type of a filesystem object referenced by a descriptor. // @@ -103,7 +103,7 @@ func (e DescriptorType) String() string { return stringsDescriptorType[e] } -// DescriptorFlags represents the flags "wasi:filesystem/types@0.2.0#descriptor-flags". +// DescriptorFlags represents the flags "wasi:filesystem/types@0.2.1#descriptor-flags". // // Descriptor flags. // @@ -144,7 +144,7 @@ const ( // requirement. DescriptorFlagsDataIntegritySync - // Requests that reads be performed at the same level of integrety + // Requests that reads be performed at the same level of integrity // requested for writes. This is similar to `O_RSYNC` in POSIX. // // The precise semantics of this operation have not yet been defined for @@ -164,7 +164,7 @@ const ( DescriptorFlagsMutateDirectory ) -// PathFlags represents the flags "wasi:filesystem/types@0.2.0#path-flags". +// PathFlags represents the flags "wasi:filesystem/types@0.2.1#path-flags". // // Flags determining the method of how paths are resolved. // @@ -179,7 +179,7 @@ const ( PathFlagsSymlinkFollow PathFlags = 1 << iota ) -// OpenFlags represents the flags "wasi:filesystem/types@0.2.0#open-flags". +// OpenFlags represents the flags "wasi:filesystem/types@0.2.1#open-flags". // // Open flags used by `open-at`. // @@ -205,14 +205,14 @@ const ( OpenFlagsTruncate ) -// LinkCount represents the u64 "wasi:filesystem/types@0.2.0#link-count". +// LinkCount represents the u64 "wasi:filesystem/types@0.2.1#link-count". // // Number of hard links to an inode. // // type link-count = u64 type LinkCount uint64 -// DescriptorStat represents the record "wasi:filesystem/types@0.2.0#descriptor-stat". +// DescriptorStat represents the record "wasi:filesystem/types@0.2.1#descriptor-stat". // // File attributes. // @@ -256,7 +256,7 @@ type DescriptorStat struct { StatusChangeTimestamp cm.Option[wallclock.DateTime] } -// NewTimestamp represents the variant "wasi:filesystem/types@0.2.0#new-timestamp". +// NewTimestamp represents the variant "wasi:filesystem/types@0.2.1#new-timestamp". // // When setting a timestamp, this gives the value to set it to. // @@ -306,7 +306,7 @@ func (self *NewTimestamp) Timestamp() *wallclock.DateTime { return cm.Case[wallclock.DateTime](self, 2) } -// DirectoryEntry represents the record "wasi:filesystem/types@0.2.0#directory-entry". +// DirectoryEntry represents the record "wasi:filesystem/types@0.2.1#directory-entry". // // A directory entry. // @@ -322,7 +322,7 @@ type DirectoryEntry struct { Name string } -// ErrorCode represents the enum "wasi:filesystem/types@0.2.0#error-code". +// ErrorCode represents the enum "wasi:filesystem/types@0.2.1#error-code". // // Error codes returned by functions, similar to `errno` in POSIX. // Not all of these error codes are returned by the functions provided by this @@ -529,7 +529,7 @@ func (e ErrorCode) String() string { return stringsErrorCode[e] } -// Advice represents the enum "wasi:filesystem/types@0.2.0#advice". +// Advice represents the enum "wasi:filesystem/types@0.2.1#advice". // // File or memory access pattern advisory information. // @@ -583,7 +583,7 @@ func (e Advice) String() string { return stringsAdvice[e] } -// MetadataHashValue represents the record "wasi:filesystem/types@0.2.0#metadata-hash-value". +// MetadataHashValue represents the record "wasi:filesystem/types@0.2.1#metadata-hash-value". // // A 128-bit hash value, split into parts because wasm doesn't have a // 128-bit integer type. @@ -600,7 +600,7 @@ type MetadataHashValue struct { Upper uint64 } -// Descriptor represents the imported resource "wasi:filesystem/types@0.2.0#descriptor". +// Descriptor represents the imported resource "wasi:filesystem/types@0.2.1#descriptor". // // A descriptor is a reference to a filesystem object, which may be a file, // directory, named pipe, special file, or other object on which filesystem @@ -620,7 +620,7 @@ func (self Descriptor) ResourceDrop() { return } -//go:wasmimport wasi:filesystem/types@0.2.0 [resource-drop]descriptor +//go:wasmimport wasi:filesystem/types@0.2.1 [resource-drop]descriptor //go:noescape func wasmimport_DescriptorResourceDrop(self0 uint32) @@ -642,7 +642,7 @@ func (self Descriptor) Advise(offset FileSize, length FileSize, advice Advice) ( return } -//go:wasmimport wasi:filesystem/types@0.2.0 [method]descriptor.advise +//go:wasmimport wasi:filesystem/types@0.2.1 [method]descriptor.advise //go:noescape func wasmimport_DescriptorAdvise(self0 uint32, offset0 uint64, length0 uint64, advice0 uint32, result *cm.Result[ErrorCode, struct{}, ErrorCode]) @@ -664,7 +664,7 @@ func (self Descriptor) AppendViaStream() (result cm.Result[streams.OutputStream, return } -//go:wasmimport wasi:filesystem/types@0.2.0 [method]descriptor.append-via-stream +//go:wasmimport wasi:filesystem/types@0.2.1 [method]descriptor.append-via-stream //go:noescape func wasmimport_DescriptorAppendViaStream(self0 uint32, result *cm.Result[streams.OutputStream, streams.OutputStream, ErrorCode]) @@ -684,7 +684,7 @@ func (self Descriptor) CreateDirectoryAt(path string) (result cm.Result[ErrorCod return } -//go:wasmimport wasi:filesystem/types@0.2.0 [method]descriptor.create-directory-at +//go:wasmimport wasi:filesystem/types@0.2.1 [method]descriptor.create-directory-at //go:noescape func wasmimport_DescriptorCreateDirectoryAt(self0 uint32, path0 *uint8, path1 uint32, result *cm.Result[ErrorCode, struct{}, ErrorCode]) @@ -706,7 +706,7 @@ func (self Descriptor) GetFlags() (result cm.Result[DescriptorFlags, DescriptorF return } -//go:wasmimport wasi:filesystem/types@0.2.0 [method]descriptor.get-flags +//go:wasmimport wasi:filesystem/types@0.2.1 [method]descriptor.get-flags //go:noescape func wasmimport_DescriptorGetFlags(self0 uint32, result *cm.Result[DescriptorFlags, DescriptorFlags, ErrorCode]) @@ -732,7 +732,7 @@ func (self Descriptor) GetType() (result cm.Result[DescriptorType, DescriptorTyp return } -//go:wasmimport wasi:filesystem/types@0.2.0 [method]descriptor.get-type +//go:wasmimport wasi:filesystem/types@0.2.1 [method]descriptor.get-type //go:noescape func wasmimport_DescriptorGetType(self0 uint32, result *cm.Result[DescriptorType, DescriptorType, ErrorCode]) @@ -756,7 +756,7 @@ func (self Descriptor) IsSameObject(other Descriptor) (result bool) { return } -//go:wasmimport wasi:filesystem/types@0.2.0 [method]descriptor.is-same-object +//go:wasmimport wasi:filesystem/types@0.2.1 [method]descriptor.is-same-object //go:noescape func wasmimport_DescriptorIsSameObject(self0 uint32, other0 uint32) (result0 uint32) @@ -780,7 +780,7 @@ func (self Descriptor) LinkAt(oldPathFlags PathFlags, oldPath string, newDescrip return } -//go:wasmimport wasi:filesystem/types@0.2.0 [method]descriptor.link-at +//go:wasmimport wasi:filesystem/types@0.2.1 [method]descriptor.link-at //go:noescape func wasmimport_DescriptorLinkAt(self0 uint32, oldPathFlags0 uint32, oldPath0 *uint8, oldPath1 uint32, newDescriptor0 uint32, newPath0 *uint8, newPath1 uint32, result *cm.Result[ErrorCode, struct{}, ErrorCode]) @@ -815,7 +815,7 @@ func (self Descriptor) MetadataHash() (result cm.Result[MetadataHashValueShape, return } -//go:wasmimport wasi:filesystem/types@0.2.0 [method]descriptor.metadata-hash +//go:wasmimport wasi:filesystem/types@0.2.1 [method]descriptor.metadata-hash //go:noescape func wasmimport_DescriptorMetadataHash(self0 uint32, result *cm.Result[MetadataHashValueShape, MetadataHashValue, ErrorCode]) @@ -838,7 +838,7 @@ func (self Descriptor) MetadataHashAt(pathFlags PathFlags, path string) (result return } -//go:wasmimport wasi:filesystem/types@0.2.0 [method]descriptor.metadata-hash-at +//go:wasmimport wasi:filesystem/types@0.2.1 [method]descriptor.metadata-hash-at //go:noescape func wasmimport_DescriptorMetadataHashAt(self0 uint32, pathFlags0 uint32, path0 *uint8, path1 uint32, result *cm.Result[MetadataHashValueShape, MetadataHashValue, ErrorCode]) @@ -877,7 +877,7 @@ func (self Descriptor) OpenAt(pathFlags PathFlags, path string, openFlags OpenFl return } -//go:wasmimport wasi:filesystem/types@0.2.0 [method]descriptor.open-at +//go:wasmimport wasi:filesystem/types@0.2.1 [method]descriptor.open-at //go:noescape func wasmimport_DescriptorOpenAt(self0 uint32, pathFlags0 uint32, path0 *uint8, path1 uint32, openFlags0 uint32, flags0 uint32, result *cm.Result[Descriptor, Descriptor, ErrorCode]) @@ -907,7 +907,7 @@ func (self Descriptor) Read(length FileSize, offset FileSize) (result cm.Result[ return } -//go:wasmimport wasi:filesystem/types@0.2.0 [method]descriptor.read +//go:wasmimport wasi:filesystem/types@0.2.1 [method]descriptor.read //go:noescape func wasmimport_DescriptorRead(self0 uint32, length0 uint64, offset0 uint64, result *cm.Result[TupleListU8BoolShape, cm.Tuple[cm.List[uint8], bool], ErrorCode]) @@ -932,7 +932,7 @@ func (self Descriptor) ReadDirectory() (result cm.Result[DirectoryEntryStream, D return } -//go:wasmimport wasi:filesystem/types@0.2.0 [method]descriptor.read-directory +//go:wasmimport wasi:filesystem/types@0.2.1 [method]descriptor.read-directory //go:noescape func wasmimport_DescriptorReadDirectory(self0 uint32, result *cm.Result[DirectoryEntryStream, DirectoryEntryStream, ErrorCode]) @@ -957,7 +957,7 @@ func (self Descriptor) ReadViaStream(offset FileSize) (result cm.Result[streams. return } -//go:wasmimport wasi:filesystem/types@0.2.0 [method]descriptor.read-via-stream +//go:wasmimport wasi:filesystem/types@0.2.1 [method]descriptor.read-via-stream //go:noescape func wasmimport_DescriptorReadViaStream(self0 uint32, offset0 uint64, result *cm.Result[streams.InputStream, streams.InputStream, ErrorCode]) @@ -980,7 +980,7 @@ func (self Descriptor) ReadLinkAt(path string) (result cm.Result[string, string, return } -//go:wasmimport wasi:filesystem/types@0.2.0 [method]descriptor.readlink-at +//go:wasmimport wasi:filesystem/types@0.2.1 [method]descriptor.readlink-at //go:noescape func wasmimport_DescriptorReadLinkAt(self0 uint32, path0 *uint8, path1 uint32, result *cm.Result[string, string, ErrorCode]) @@ -1002,7 +1002,7 @@ func (self Descriptor) RemoveDirectoryAt(path string) (result cm.Result[ErrorCod return } -//go:wasmimport wasi:filesystem/types@0.2.0 [method]descriptor.remove-directory-at +//go:wasmimport wasi:filesystem/types@0.2.1 [method]descriptor.remove-directory-at //go:noescape func wasmimport_DescriptorRemoveDirectoryAt(self0 uint32, path0 *uint8, path1 uint32, result *cm.Result[ErrorCode, struct{}, ErrorCode]) @@ -1025,7 +1025,7 @@ func (self Descriptor) RenameAt(oldPath string, newDescriptor Descriptor, newPat return } -//go:wasmimport wasi:filesystem/types@0.2.0 [method]descriptor.rename-at +//go:wasmimport wasi:filesystem/types@0.2.1 [method]descriptor.rename-at //go:noescape func wasmimport_DescriptorRenameAt(self0 uint32, oldPath0 *uint8, oldPath1 uint32, newDescriptor0 uint32, newPath0 *uint8, newPath1 uint32, result *cm.Result[ErrorCode, struct{}, ErrorCode]) @@ -1046,7 +1046,7 @@ func (self Descriptor) SetSize(size FileSize) (result cm.Result[ErrorCode, struc return } -//go:wasmimport wasi:filesystem/types@0.2.0 [method]descriptor.set-size +//go:wasmimport wasi:filesystem/types@0.2.1 [method]descriptor.set-size //go:noescape func wasmimport_DescriptorSetSize(self0 uint32, size0 uint64, result *cm.Result[ErrorCode, struct{}, ErrorCode]) @@ -1070,7 +1070,7 @@ func (self Descriptor) SetTimes(dataAccessTimestamp NewTimestamp, dataModificati return } -//go:wasmimport wasi:filesystem/types@0.2.0 [method]descriptor.set-times +//go:wasmimport wasi:filesystem/types@0.2.1 [method]descriptor.set-times //go:noescape func wasmimport_DescriptorSetTimes(self0 uint32, dataAccessTimestamp0 uint32, dataAccessTimestamp1 uint64, dataAccessTimestamp2 uint32, dataModificationTimestamp0 uint32, dataModificationTimestamp1 uint64, dataModificationTimestamp2 uint32, result *cm.Result[ErrorCode, struct{}, ErrorCode]) @@ -1097,7 +1097,7 @@ func (self Descriptor) SetTimesAt(pathFlags PathFlags, path string, dataAccessTi return } -//go:wasmimport wasi:filesystem/types@0.2.0 [method]descriptor.set-times-at +//go:wasmimport wasi:filesystem/types@0.2.1 [method]descriptor.set-times-at //go:noescape func wasmimport_DescriptorSetTimesAt(self0 uint32, pathFlags0 uint32, path0 *uint8, path1 uint32, dataAccessTimestamp0 uint32, dataAccessTimestamp1 uint64, dataAccessTimestamp2 uint32, dataModificationTimestamp0 uint32, dataModificationTimestamp1 uint64, dataModificationTimestamp2 uint32, result *cm.Result[ErrorCode, struct{}, ErrorCode]) @@ -1122,7 +1122,7 @@ func (self Descriptor) Stat() (result cm.Result[DescriptorStatShape, DescriptorS return } -//go:wasmimport wasi:filesystem/types@0.2.0 [method]descriptor.stat +//go:wasmimport wasi:filesystem/types@0.2.1 [method]descriptor.stat //go:noescape func wasmimport_DescriptorStat(self0 uint32, result *cm.Result[DescriptorStatShape, DescriptorStat, ErrorCode]) @@ -1148,7 +1148,7 @@ func (self Descriptor) StatAt(pathFlags PathFlags, path string) (result cm.Resul return } -//go:wasmimport wasi:filesystem/types@0.2.0 [method]descriptor.stat-at +//go:wasmimport wasi:filesystem/types@0.2.1 [method]descriptor.stat-at //go:noescape func wasmimport_DescriptorStatAt(self0 uint32, pathFlags0 uint32, path0 *uint8, path1 uint32, result *cm.Result[DescriptorStatShape, DescriptorStat, ErrorCode]) @@ -1172,7 +1172,7 @@ func (self Descriptor) SymlinkAt(oldPath string, newPath string) (result cm.Resu return } -//go:wasmimport wasi:filesystem/types@0.2.0 [method]descriptor.symlink-at +//go:wasmimport wasi:filesystem/types@0.2.1 [method]descriptor.symlink-at //go:noescape func wasmimport_DescriptorSymlinkAt(self0 uint32, oldPath0 *uint8, oldPath1 uint32, newPath0 *uint8, newPath1 uint32, result *cm.Result[ErrorCode, struct{}, ErrorCode]) @@ -1194,7 +1194,7 @@ func (self Descriptor) Sync() (result cm.Result[ErrorCode, struct{}, ErrorCode]) return } -//go:wasmimport wasi:filesystem/types@0.2.0 [method]descriptor.sync +//go:wasmimport wasi:filesystem/types@0.2.1 [method]descriptor.sync //go:noescape func wasmimport_DescriptorSync(self0 uint32, result *cm.Result[ErrorCode, struct{}, ErrorCode]) @@ -1216,7 +1216,7 @@ func (self Descriptor) SyncData() (result cm.Result[ErrorCode, struct{}, ErrorCo return } -//go:wasmimport wasi:filesystem/types@0.2.0 [method]descriptor.sync-data +//go:wasmimport wasi:filesystem/types@0.2.1 [method]descriptor.sync-data //go:noescape func wasmimport_DescriptorSyncData(self0 uint32, result *cm.Result[ErrorCode, struct{}, ErrorCode]) @@ -1237,7 +1237,7 @@ func (self Descriptor) UnlinkFileAt(path string) (result cm.Result[ErrorCode, st return } -//go:wasmimport wasi:filesystem/types@0.2.0 [method]descriptor.unlink-file-at +//go:wasmimport wasi:filesystem/types@0.2.1 [method]descriptor.unlink-file-at //go:noescape func wasmimport_DescriptorUnlinkFileAt(self0 uint32, path0 *uint8, path1 uint32, result *cm.Result[ErrorCode, struct{}, ErrorCode]) @@ -1264,7 +1264,7 @@ func (self Descriptor) Write(buffer cm.List[uint8], offset FileSize) (result cm. return } -//go:wasmimport wasi:filesystem/types@0.2.0 [method]descriptor.write +//go:wasmimport wasi:filesystem/types@0.2.1 [method]descriptor.write //go:noescape func wasmimport_DescriptorWrite(self0 uint32, buffer0 *uint8, buffer1 uint32, offset0 uint64, result *cm.Result[uint64, FileSize, ErrorCode]) @@ -1287,11 +1287,11 @@ func (self Descriptor) WriteViaStream(offset FileSize) (result cm.Result[streams return } -//go:wasmimport wasi:filesystem/types@0.2.0 [method]descriptor.write-via-stream +//go:wasmimport wasi:filesystem/types@0.2.1 [method]descriptor.write-via-stream //go:noescape func wasmimport_DescriptorWriteViaStream(self0 uint32, offset0 uint64, result *cm.Result[streams.OutputStream, streams.OutputStream, ErrorCode]) -// DirectoryEntryStream represents the imported resource "wasi:filesystem/types@0.2.0#directory-entry-stream". +// DirectoryEntryStream represents the imported resource "wasi:filesystem/types@0.2.1#directory-entry-stream". // // A stream of directory entries. // @@ -1309,7 +1309,7 @@ func (self DirectoryEntryStream) ResourceDrop() { return } -//go:wasmimport wasi:filesystem/types@0.2.0 [resource-drop]directory-entry-stream +//go:wasmimport wasi:filesystem/types@0.2.1 [resource-drop]directory-entry-stream //go:noescape func wasmimport_DirectoryEntryStreamResourceDrop(self0 uint32) @@ -1326,7 +1326,7 @@ func (self DirectoryEntryStream) ReadDirectoryEntry() (result cm.Result[OptionDi return } -//go:wasmimport wasi:filesystem/types@0.2.0 [method]directory-entry-stream.read-directory-entry +//go:wasmimport wasi:filesystem/types@0.2.1 [method]directory-entry-stream.read-directory-entry //go:noescape func wasmimport_DirectoryEntryStreamReadDirectoryEntry(self0 uint32, result *cm.Result[OptionDirectoryEntryShape, cm.Option[DirectoryEntry], ErrorCode]) @@ -1352,6 +1352,6 @@ func FilesystemErrorCode(err ioerror.Error) (result cm.Option[ErrorCode]) { return } -//go:wasmimport wasi:filesystem/types@0.2.0 filesystem-error-code +//go:wasmimport wasi:filesystem/types@0.2.1 filesystem-error-code //go:noescape func wasmimport_FilesystemErrorCode(err0 uint32, result *cm.Option[ErrorCode]) diff --git a/tests/go/wasi/bindings/wasi/http/incoming-handler/incoming-handler.exports.go b/tests/go/wasi/bindings/wasi/http/incoming-handler/incoming-handler.exports.go index 5543ea4..ab579df 100644 --- a/tests/go/wasi/bindings/wasi/http/incoming-handler/incoming-handler.exports.go +++ b/tests/go/wasi/bindings/wasi/http/incoming-handler/incoming-handler.exports.go @@ -6,7 +6,7 @@ import ( "github.com/rvolosatovs/west/tests/go/wasi/bindings/wasi/http/types" ) -// Exports represents the caller-defined exports from "wasi:http/incoming-handler@0.2.0". +// Exports represents the caller-defined exports from "wasi:http/incoming-handler@0.2.1". var Exports struct { // Handle represents the caller-defined, exported function "handle". // diff --git a/tests/go/wasi/bindings/wasi/http/incoming-handler/incoming-handler.wit.go b/tests/go/wasi/bindings/wasi/http/incoming-handler/incoming-handler.wit.go index 0095107..2ffb2e3 100644 --- a/tests/go/wasi/bindings/wasi/http/incoming-handler/incoming-handler.wit.go +++ b/tests/go/wasi/bindings/wasi/http/incoming-handler/incoming-handler.wit.go @@ -1,18 +1,18 @@ // Code generated by wit-bindgen-go. DO NOT EDIT. -// Package incominghandler represents the exported interface "wasi:http/incoming-handler@0.2.0". +// Package incominghandler represents the exported interface "wasi:http/incoming-handler@0.2.1". // // This interface defines a handler of incoming HTTP Requests. It should // be exported by components which can respond to HTTP Requests. package incominghandler import ( + "github.com/bytecodealliance/wasm-tools-go/cm" "github.com/rvolosatovs/west/tests/go/wasi/bindings/wasi/http/types" - "github.com/ydnar/wasm-tools-go/cm" ) -//go:wasmexport wasi:http/incoming-handler@0.2.0#handle -//export wasi:http/incoming-handler@0.2.0#handle +//go:wasmexport wasi:http/incoming-handler@0.2.1#handle +//export wasi:http/incoming-handler@0.2.1#handle func wasmexport_Handle(request0 uint32, responseOut0 uint32) { request := cm.Reinterpret[types.IncomingRequest]((uint32)(request0)) responseOut := cm.Reinterpret[types.ResponseOutparam]((uint32)(responseOut0)) diff --git a/tests/go/wasi/bindings/wasi/http/types/abi.go b/tests/go/wasi/bindings/wasi/http/types/abi.go index b6f9587..d4bc5fd 100644 --- a/tests/go/wasi/bindings/wasi/http/types/abi.go +++ b/tests/go/wasi/bindings/wasi/http/types/abi.go @@ -3,8 +3,8 @@ package types import ( + "github.com/bytecodealliance/wasm-tools-go/cm" monotonicclock "github.com/rvolosatovs/west/tests/go/wasi/bindings/wasi/clocks/monotonic-clock" - "github.com/ydnar/wasm-tools-go/cm" "unsafe" ) diff --git a/tests/go/wasi/bindings/wasi/http/types/types.wit.go b/tests/go/wasi/bindings/wasi/http/types/types.wit.go index 5a7bbea..3ac1e10 100644 --- a/tests/go/wasi/bindings/wasi/http/types/types.wit.go +++ b/tests/go/wasi/bindings/wasi/http/types/types.wit.go @@ -1,6 +1,6 @@ // Code generated by wit-bindgen-go. DO NOT EDIT. -// Package types represents the imported interface "wasi:http/types@0.2.0". +// Package types represents the imported interface "wasi:http/types@0.2.1". // // This interface defines all of the types and methods for implementing // HTTP Requests and Responses, both incoming and outgoing, as well as @@ -8,14 +8,14 @@ package types import ( + "github.com/bytecodealliance/wasm-tools-go/cm" monotonicclock "github.com/rvolosatovs/west/tests/go/wasi/bindings/wasi/clocks/monotonic-clock" ioerror "github.com/rvolosatovs/west/tests/go/wasi/bindings/wasi/io/error" "github.com/rvolosatovs/west/tests/go/wasi/bindings/wasi/io/poll" "github.com/rvolosatovs/west/tests/go/wasi/bindings/wasi/io/streams" - "github.com/ydnar/wasm-tools-go/cm" ) -// Method represents the variant "wasi:http/types@0.2.0#method". +// Method represents the variant "wasi:http/types@0.2.1#method". // // This type corresponds to HTTP standard Methods. // @@ -142,7 +142,7 @@ func (self *Method) Other() *string { return cm.Case[string](self, 9) } -// Scheme represents the variant "wasi:http/types@0.2.0#scheme". +// Scheme represents the variant "wasi:http/types@0.2.1#scheme". // // This type corresponds to HTTP standard Related Schemes. // @@ -185,7 +185,7 @@ func (self *Scheme) Other() *string { return cm.Case[string](self, 2) } -// DNSErrorPayload represents the record "wasi:http/types@0.2.0#DNS-error-payload". +// DNSErrorPayload represents the record "wasi:http/types@0.2.1#DNS-error-payload". // // Defines the case payload type for `DNS-error` above: // @@ -198,7 +198,7 @@ type DNSErrorPayload struct { InfoCode cm.Option[uint16] } -// TLSAlertReceivedPayload represents the record "wasi:http/types@0.2.0#TLS-alert-received-payload". +// TLSAlertReceivedPayload represents the record "wasi:http/types@0.2.1#TLS-alert-received-payload". // // Defines the case payload type for `TLS-alert-received` above: // @@ -211,7 +211,7 @@ type TLSAlertReceivedPayload struct { AlertMessage cm.Option[string] } -// FieldSizePayload represents the record "wasi:http/types@0.2.0#field-size-payload". +// FieldSizePayload represents the record "wasi:http/types@0.2.1#field-size-payload". // // Defines the case payload type for `HTTP-response-{header,trailer}-size` above: // @@ -224,7 +224,7 @@ type FieldSizePayload struct { FieldSize cm.Option[uint32] } -// ErrorCode represents the variant "wasi:http/types@0.2.0#error-code". +// ErrorCode represents the variant "wasi:http/types@0.2.1#error-code". // // These cases are inspired by the IANA HTTP Proxy Error Types: // https://www.iana.org/assignments/http-proxy-status/http-proxy-status.xhtml#table-http-proxy-error-types @@ -692,7 +692,7 @@ func (self *ErrorCode) InternalError() *cm.Option[string] { return cm.Case[cm.Option[string]](self, 38) } -// HeaderError represents the variant "wasi:http/types@0.2.0#header-error". +// HeaderError represents the variant "wasi:http/types@0.2.1#header-error". // // This type enumerates the different kinds of errors that may occur when // setting or appending to a `fields` resource. @@ -730,14 +730,14 @@ func (e HeaderError) String() string { return stringsHeaderError[e] } -// FieldKey represents the string "wasi:http/types@0.2.0#field-key". +// FieldKey represents the string "wasi:http/types@0.2.1#field-key". // // Field keys are always strings. // // type field-key = string type FieldKey string -// FieldValue represents the list "wasi:http/types@0.2.0#field-value". +// FieldValue represents the list "wasi:http/types@0.2.1#field-value". // // Field values should always be ASCII strings. However, in // reality, HTTP implementations often have to interpret malformed values, @@ -746,7 +746,7 @@ type FieldKey string // type field-value = list type FieldValue cm.List[uint8] -// Fields represents the imported resource "wasi:http/types@0.2.0#fields". +// Fields represents the imported resource "wasi:http/types@0.2.1#fields". // // This following block defines the `fields` resource which corresponds to // HTTP standard Fields. Fields are a common representation used for both @@ -773,7 +773,7 @@ func (self Fields) ResourceDrop() { return } -//go:wasmimport wasi:http/types@0.2.0 [resource-drop]fields +//go:wasmimport wasi:http/types@0.2.1 [resource-drop]fields //go:noescape func wasmimport_FieldsResourceDrop(self0 uint32) @@ -792,7 +792,7 @@ func NewFields() (result Fields) { return } -//go:wasmimport wasi:http/types@0.2.0 [constructor]fields +//go:wasmimport wasi:http/types@0.2.1 [constructor]fields //go:noescape func wasmimport_NewFields() (result0 uint32) @@ -807,12 +807,10 @@ func wasmimport_NewFields() (result0 uint32) // list with the same key. // // The tuple is a pair of the field key, represented as a string, and -// Value, represented as a list of bytes. In a valid Fields, all keys -// and values are valid UTF-8 strings. However, values are not always -// well-formed, so they are represented as a raw list of bytes. +// Value, represented as a list of bytes. // -// An error result will be returned if any header or value was -// syntactically invalid, or if a header was forbidden. +// An error result will be returned if any `field-key` or `field-value` is +// syntactically invalid, or if a field is forbidden. // // from-list: static func(entries: list>) -> result @@ -824,7 +822,7 @@ func FieldsFromList(entries cm.List[cm.Tuple[FieldKey, FieldValue]]) (result cm. return } -//go:wasmimport wasi:http/types@0.2.0 [static]fields.from-list +//go:wasmimport wasi:http/types@0.2.1 [static]fields.from-list //go:noescape func wasmimport_FieldsFromList(entries0 *cm.Tuple[FieldKey, FieldValue], entries1 uint32, result *cm.Result[Fields, Fields, HeaderError]) @@ -835,6 +833,9 @@ func wasmimport_FieldsFromList(entries0 *cm.Tuple[FieldKey, FieldValue], entries // // Fails with `header-error.immutable` if the `fields` are immutable. // +// Fails with `header-error.invalid-syntax` if the `field-key` or +// `field-value` are syntactically invalid. +// // append: func(name: field-key, value: field-value) -> result<_, header-error> // //go:nosplit @@ -846,13 +847,13 @@ func (self Fields) Append(name FieldKey, value FieldValue) (result cm.Result[Hea return } -//go:wasmimport wasi:http/types@0.2.0 [method]fields.append +//go:wasmimport wasi:http/types@0.2.1 [method]fields.append //go:noescape func wasmimport_FieldsAppend(self0 uint32, name0 *uint8, name1 uint32, value0 *uint8, value1 uint32, result *cm.Result[HeaderError, struct{}, HeaderError]) // Clone represents the imported method "clone". // -// Make a deep copy of the Fields. Equivelant in behavior to calling the +// Make a deep copy of the Fields. Equivalent in behavior to calling the // `fields` constructor on the return value of `entries`. The resulting // `fields` is mutable. // @@ -866,7 +867,7 @@ func (self Fields) Clone() (result Fields) { return } -//go:wasmimport wasi:http/types@0.2.0 [method]fields.clone +//go:wasmimport wasi:http/types@0.2.1 [method]fields.clone //go:noescape func wasmimport_FieldsClone(self0 uint32) (result0 uint32) @@ -877,6 +878,9 @@ func wasmimport_FieldsClone(self0 uint32) (result0 uint32) // // Fails with `header-error.immutable` if the `fields` are immutable. // +// Fails with `header-error.invalid-syntax` if the `field-key` is +// syntactically invalid. +// // delete: func(name: field-key) -> result<_, header-error> // //go:nosplit @@ -887,7 +891,7 @@ func (self Fields) Delete(name FieldKey) (result cm.Result[HeaderError, struct{} return } -//go:wasmimport wasi:http/types@0.2.0 [method]fields.delete +//go:wasmimport wasi:http/types@0.2.1 [method]fields.delete //go:noescape func wasmimport_FieldsDelete(self0 uint32, name0 *uint8, name1 uint32, result *cm.Result[HeaderError, struct{}, HeaderError]) @@ -909,16 +913,16 @@ func (self Fields) Entries() (result cm.List[cm.Tuple[FieldKey, FieldValue]]) { return } -//go:wasmimport wasi:http/types@0.2.0 [method]fields.entries +//go:wasmimport wasi:http/types@0.2.1 [method]fields.entries //go:noescape func wasmimport_FieldsEntries(self0 uint32, result *cm.List[cm.Tuple[FieldKey, FieldValue]]) // Get represents the imported method "get". // // Get all of the values corresponding to a key. If the key is not present -// in this `fields`, an empty list is returned. However, if the key is -// present but empty, this is represented by a list with one or more -// empty field-values present. +// in this `fields` or is syntactically invalid, an empty list is returned. +// However, if the key is present but empty, this is represented by a list +// with one or more empty field-values present. // // get: func(name: field-key) -> list // @@ -930,7 +934,7 @@ func (self Fields) Get(name FieldKey) (result cm.List[FieldValue]) { return } -//go:wasmimport wasi:http/types@0.2.0 [method]fields.get +//go:wasmimport wasi:http/types@0.2.1 [method]fields.get //go:noescape func wasmimport_FieldsGet(self0 uint32, name0 *uint8, name1 uint32, result *cm.List[FieldValue]) @@ -950,7 +954,7 @@ func (self Fields) Has(name FieldKey) (result bool) { return } -//go:wasmimport wasi:http/types@0.2.0 [method]fields.has +//go:wasmimport wasi:http/types@0.2.1 [method]fields.has //go:noescape func wasmimport_FieldsHas(self0 uint32, name0 *uint8, name1 uint32) (result0 uint32) @@ -961,6 +965,9 @@ func wasmimport_FieldsHas(self0 uint32, name0 *uint8, name1 uint32) (result0 uin // // Fails with `header-error.immutable` if the `fields` are immutable. // +// Fails with `header-error.invalid-syntax` if the `field-key` or any of +// the `field-value`s are syntactically invalid. +// // set: func(name: field-key, value: list) -> result<_, header-error> // //go:nosplit @@ -972,11 +979,11 @@ func (self Fields) Set(name FieldKey, value cm.List[FieldValue]) (result cm.Resu return } -//go:wasmimport wasi:http/types@0.2.0 [method]fields.set +//go:wasmimport wasi:http/types@0.2.1 [method]fields.set //go:noescape func wasmimport_FieldsSet(self0 uint32, name0 *uint8, name1 uint32, value0 *FieldValue, value1 uint32, result *cm.Result[HeaderError, struct{}, HeaderError]) -// IncomingRequest represents the imported resource "wasi:http/types@0.2.0#incoming-request". +// IncomingRequest represents the imported resource "wasi:http/types@0.2.1#incoming-request". // // Represents an incoming HTTP Request. // @@ -994,13 +1001,13 @@ func (self IncomingRequest) ResourceDrop() { return } -//go:wasmimport wasi:http/types@0.2.0 [resource-drop]incoming-request +//go:wasmimport wasi:http/types@0.2.1 [resource-drop]incoming-request //go:noescape func wasmimport_IncomingRequestResourceDrop(self0 uint32) // Authority represents the imported method "authority". // -// Returns the authority from the request, if it was present. +// Returns the authority of the Request's target URI, if present. // // authority: func() -> option // @@ -1011,7 +1018,7 @@ func (self IncomingRequest) Authority() (result cm.Option[string]) { return } -//go:wasmimport wasi:http/types@0.2.0 [method]incoming-request.authority +//go:wasmimport wasi:http/types@0.2.1 [method]incoming-request.authority //go:noescape func wasmimport_IncomingRequestAuthority(self0 uint32, result *cm.Option[string]) @@ -1029,7 +1036,7 @@ func (self IncomingRequest) Consume() (result cm.Result[IncomingBody, IncomingBo return } -//go:wasmimport wasi:http/types@0.2.0 [method]incoming-request.consume +//go:wasmimport wasi:http/types@0.2.1 [method]incoming-request.consume //go:noescape func wasmimport_IncomingRequestConsume(self0 uint32, result *cm.Result[IncomingBody, IncomingBody, struct{}]) @@ -1054,7 +1061,7 @@ func (self IncomingRequest) Headers() (result Fields) { return } -//go:wasmimport wasi:http/types@0.2.0 [method]incoming-request.headers +//go:wasmimport wasi:http/types@0.2.1 [method]incoming-request.headers //go:noescape func wasmimport_IncomingRequestHeaders(self0 uint32) (result0 uint32) @@ -1071,7 +1078,7 @@ func (self IncomingRequest) Method() (result Method) { return } -//go:wasmimport wasi:http/types@0.2.0 [method]incoming-request.method +//go:wasmimport wasi:http/types@0.2.1 [method]incoming-request.method //go:noescape func wasmimport_IncomingRequestMethod(self0 uint32, result *Method) @@ -1088,7 +1095,7 @@ func (self IncomingRequest) PathWithQuery() (result cm.Option[string]) { return } -//go:wasmimport wasi:http/types@0.2.0 [method]incoming-request.path-with-query +//go:wasmimport wasi:http/types@0.2.1 [method]incoming-request.path-with-query //go:noescape func wasmimport_IncomingRequestPathWithQuery(self0 uint32, result *cm.Option[string]) @@ -1105,11 +1112,11 @@ func (self IncomingRequest) Scheme() (result cm.Option[Scheme]) { return } -//go:wasmimport wasi:http/types@0.2.0 [method]incoming-request.scheme +//go:wasmimport wasi:http/types@0.2.1 [method]incoming-request.scheme //go:noescape func wasmimport_IncomingRequestScheme(self0 uint32, result *cm.Option[Scheme]) -// OutgoingRequest represents the imported resource "wasi:http/types@0.2.0#outgoing-request". +// OutgoingRequest represents the imported resource "wasi:http/types@0.2.1#outgoing-request". // // Represents an outgoing HTTP Request. // @@ -1127,7 +1134,7 @@ func (self OutgoingRequest) ResourceDrop() { return } -//go:wasmimport wasi:http/types@0.2.0 [resource-drop]outgoing-request +//go:wasmimport wasi:http/types@0.2.1 [resource-drop]outgoing-request //go:noescape func wasmimport_OutgoingRequestResourceDrop(self0 uint32) @@ -1154,14 +1161,14 @@ func NewOutgoingRequest(headers Fields) (result OutgoingRequest) { return } -//go:wasmimport wasi:http/types@0.2.0 [constructor]outgoing-request +//go:wasmimport wasi:http/types@0.2.1 [constructor]outgoing-request //go:noescape func wasmimport_NewOutgoingRequest(headers0 uint32) (result0 uint32) // Authority represents the imported method "authority". // -// Get the HTTP Authority for the Request. A value of `none` may be used -// with Related Schemes which do not require an Authority. The HTTP and +// Get the authority of the Request's target URI. A value of `none` may be used +// with Related Schemes which do not require an authority. The HTTP and // HTTPS schemes always require an authority. // // authority: func() -> option @@ -1173,7 +1180,7 @@ func (self OutgoingRequest) Authority() (result cm.Option[string]) { return } -//go:wasmimport wasi:http/types@0.2.0 [method]outgoing-request.authority +//go:wasmimport wasi:http/types@0.2.1 [method]outgoing-request.authority //go:noescape func wasmimport_OutgoingRequestAuthority(self0 uint32, result *cm.Option[string]) @@ -1195,7 +1202,7 @@ func (self OutgoingRequest) Body() (result cm.Result[OutgoingBody, OutgoingBody, return } -//go:wasmimport wasi:http/types@0.2.0 [method]outgoing-request.body +//go:wasmimport wasi:http/types@0.2.1 [method]outgoing-request.body //go:noescape func wasmimport_OutgoingRequestBody(self0 uint32, result *cm.Result[OutgoingBody, OutgoingBody, struct{}]) @@ -1207,7 +1214,7 @@ func wasmimport_OutgoingRequestBody(self0 uint32, result *cm.Result[OutgoingBody // `delete` operations will fail with `header-error.immutable`. // // This headers resource is a child: it must be dropped before the parent -// `outgoing-request` is dropped, or its ownership is transfered to +// `outgoing-request` is dropped, or its ownership is transferred to // another component by e.g. `outgoing-handler.handle`. // // headers: func() -> headers @@ -1220,7 +1227,7 @@ func (self OutgoingRequest) Headers() (result Fields) { return } -//go:wasmimport wasi:http/types@0.2.0 [method]outgoing-request.headers +//go:wasmimport wasi:http/types@0.2.1 [method]outgoing-request.headers //go:noescape func wasmimport_OutgoingRequestHeaders(self0 uint32) (result0 uint32) @@ -1237,7 +1244,7 @@ func (self OutgoingRequest) Method() (result Method) { return } -//go:wasmimport wasi:http/types@0.2.0 [method]outgoing-request.method +//go:wasmimport wasi:http/types@0.2.1 [method]outgoing-request.method //go:noescape func wasmimport_OutgoingRequestMethod(self0 uint32, result *Method) @@ -1255,7 +1262,7 @@ func (self OutgoingRequest) PathWithQuery() (result cm.Option[string]) { return } -//go:wasmimport wasi:http/types@0.2.0 [method]outgoing-request.path-with-query +//go:wasmimport wasi:http/types@0.2.1 [method]outgoing-request.path-with-query //go:noescape func wasmimport_OutgoingRequestPathWithQuery(self0 uint32, result *cm.Option[string]) @@ -1273,16 +1280,16 @@ func (self OutgoingRequest) Scheme() (result cm.Option[Scheme]) { return } -//go:wasmimport wasi:http/types@0.2.0 [method]outgoing-request.scheme +//go:wasmimport wasi:http/types@0.2.1 [method]outgoing-request.scheme //go:noescape func wasmimport_OutgoingRequestScheme(self0 uint32, result *cm.Option[Scheme]) // SetAuthority represents the imported method "set-authority". // -// Set the HTTP Authority for the Request. A value of `none` may be used -// with Related Schemes which do not require an Authority. The HTTP and +// Set the authority of the Request's target URI. A value of `none` may be used +// with Related Schemes which do not require an authority. The HTTP and // HTTPS schemes always require an authority. Fails if the string given is -// not a syntactically valid uri authority. +// not a syntactically valid URI authority. // // set-authority: func(authority: option) -> result // @@ -1295,7 +1302,7 @@ func (self OutgoingRequest) SetAuthority(authority cm.Option[string]) (result cm return } -//go:wasmimport wasi:http/types@0.2.0 [method]outgoing-request.set-authority +//go:wasmimport wasi:http/types@0.2.1 [method]outgoing-request.set-authority //go:noescape func wasmimport_OutgoingRequestSetAuthority(self0 uint32, authority0 uint32, authority1 *uint8, authority2 uint32) (result0 uint32) @@ -1315,7 +1322,7 @@ func (self OutgoingRequest) SetMethod(method Method) (result cm.BoolResult) { return } -//go:wasmimport wasi:http/types@0.2.0 [method]outgoing-request.set-method +//go:wasmimport wasi:http/types@0.2.1 [method]outgoing-request.set-method //go:noescape func wasmimport_OutgoingRequestSetMethod(self0 uint32, method0 uint32, method1 *uint8, method2 uint32) (result0 uint32) @@ -1336,7 +1343,7 @@ func (self OutgoingRequest) SetPathWithQuery(pathWithQuery cm.Option[string]) (r return } -//go:wasmimport wasi:http/types@0.2.0 [method]outgoing-request.set-path-with-query +//go:wasmimport wasi:http/types@0.2.1 [method]outgoing-request.set-path-with-query //go:noescape func wasmimport_OutgoingRequestSetPathWithQuery(self0 uint32, pathWithQuery0 uint32, pathWithQuery1 *uint8, pathWithQuery2 uint32) (result0 uint32) @@ -1357,11 +1364,11 @@ func (self OutgoingRequest) SetScheme(scheme cm.Option[Scheme]) (result cm.BoolR return } -//go:wasmimport wasi:http/types@0.2.0 [method]outgoing-request.set-scheme +//go:wasmimport wasi:http/types@0.2.1 [method]outgoing-request.set-scheme //go:noescape func wasmimport_OutgoingRequestSetScheme(self0 uint32, scheme0 uint32, scheme1 uint32, scheme2 *uint8, scheme3 uint32) (result0 uint32) -// RequestOptions represents the imported resource "wasi:http/types@0.2.0#request-options". +// RequestOptions represents the imported resource "wasi:http/types@0.2.1#request-options". // // Parameters for making an HTTP Request. Each of these parameters is // currently an optional timeout applicable to the transport layer of the @@ -1384,7 +1391,7 @@ func (self RequestOptions) ResourceDrop() { return } -//go:wasmimport wasi:http/types@0.2.0 [resource-drop]request-options +//go:wasmimport wasi:http/types@0.2.1 [resource-drop]request-options //go:noescape func wasmimport_RequestOptionsResourceDrop(self0 uint32) @@ -1401,7 +1408,7 @@ func NewRequestOptions() (result RequestOptions) { return } -//go:wasmimport wasi:http/types@0.2.0 [constructor]request-options +//go:wasmimport wasi:http/types@0.2.1 [constructor]request-options //go:noescape func wasmimport_NewRequestOptions() (result0 uint32) @@ -1419,7 +1426,7 @@ func (self RequestOptions) BetweenBytesTimeout() (result cm.Option[monotoniccloc return } -//go:wasmimport wasi:http/types@0.2.0 [method]request-options.between-bytes-timeout +//go:wasmimport wasi:http/types@0.2.1 [method]request-options.between-bytes-timeout //go:noescape func wasmimport_RequestOptionsBetweenBytesTimeout(self0 uint32, result *cm.Option[monotonicclock.Duration]) @@ -1436,7 +1443,7 @@ func (self RequestOptions) ConnectTimeout() (result cm.Option[monotonicclock.Dur return } -//go:wasmimport wasi:http/types@0.2.0 [method]request-options.connect-timeout +//go:wasmimport wasi:http/types@0.2.1 [method]request-options.connect-timeout //go:noescape func wasmimport_RequestOptionsConnectTimeout(self0 uint32, result *cm.Option[monotonicclock.Duration]) @@ -1453,7 +1460,7 @@ func (self RequestOptions) FirstByteTimeout() (result cm.Option[monotonicclock.D return } -//go:wasmimport wasi:http/types@0.2.0 [method]request-options.first-byte-timeout +//go:wasmimport wasi:http/types@0.2.1 [method]request-options.first-byte-timeout //go:noescape func wasmimport_RequestOptionsFirstByteTimeout(self0 uint32, result *cm.Option[monotonicclock.Duration]) @@ -1474,7 +1481,7 @@ func (self RequestOptions) SetBetweenBytesTimeout(duration cm.Option[monotoniccl return } -//go:wasmimport wasi:http/types@0.2.0 [method]request-options.set-between-bytes-timeout +//go:wasmimport wasi:http/types@0.2.1 [method]request-options.set-between-bytes-timeout //go:noescape func wasmimport_RequestOptionsSetBetweenBytesTimeout(self0 uint32, duration0 uint32, duration1 uint64) (result0 uint32) @@ -1494,7 +1501,7 @@ func (self RequestOptions) SetConnectTimeout(duration cm.Option[monotonicclock.D return } -//go:wasmimport wasi:http/types@0.2.0 [method]request-options.set-connect-timeout +//go:wasmimport wasi:http/types@0.2.1 [method]request-options.set-connect-timeout //go:noescape func wasmimport_RequestOptionsSetConnectTimeout(self0 uint32, duration0 uint32, duration1 uint64) (result0 uint32) @@ -1514,11 +1521,11 @@ func (self RequestOptions) SetFirstByteTimeout(duration cm.Option[monotonicclock return } -//go:wasmimport wasi:http/types@0.2.0 [method]request-options.set-first-byte-timeout +//go:wasmimport wasi:http/types@0.2.1 [method]request-options.set-first-byte-timeout //go:noescape func wasmimport_RequestOptionsSetFirstByteTimeout(self0 uint32, duration0 uint32, duration1 uint64) (result0 uint32) -// ResponseOutparam represents the imported resource "wasi:http/types@0.2.0#response-outparam". +// ResponseOutparam represents the imported resource "wasi:http/types@0.2.1#response-outparam". // // Represents the ability to send an HTTP Response. // @@ -1540,7 +1547,7 @@ func (self ResponseOutparam) ResourceDrop() { return } -//go:wasmimport wasi:http/types@0.2.0 [resource-drop]response-outparam +//go:wasmimport wasi:http/types@0.2.1 [resource-drop]response-outparam //go:noescape func wasmimport_ResponseOutparamResourceDrop(self0 uint32) @@ -1567,18 +1574,18 @@ func ResponseOutparamSet(param ResponseOutparam, response cm.Result[ErrorCodeSha return } -//go:wasmimport wasi:http/types@0.2.0 [static]response-outparam.set +//go:wasmimport wasi:http/types@0.2.1 [static]response-outparam.set //go:noescape func wasmimport_ResponseOutparamSet(param0 uint32, response0 uint32, response1 uint32, response2 uint32, response3 uint64, response4 uint32, response5 uint32, response6 uint32, response7 uint32) -// StatusCode represents the u16 "wasi:http/types@0.2.0#status-code". +// StatusCode represents the u16 "wasi:http/types@0.2.1#status-code". // // This type corresponds to the HTTP standard Status Code. // // type status-code = u16 type StatusCode uint16 -// IncomingResponse represents the imported resource "wasi:http/types@0.2.0#incoming-response". +// IncomingResponse represents the imported resource "wasi:http/types@0.2.1#incoming-response". // // Represents an incoming HTTP Response. // @@ -1596,7 +1603,7 @@ func (self IncomingResponse) ResourceDrop() { return } -//go:wasmimport wasi:http/types@0.2.0 [resource-drop]incoming-response +//go:wasmimport wasi:http/types@0.2.1 [resource-drop]incoming-response //go:noescape func wasmimport_IncomingResponseResourceDrop(self0 uint32) @@ -1614,7 +1621,7 @@ func (self IncomingResponse) Consume() (result cm.Result[IncomingBody, IncomingB return } -//go:wasmimport wasi:http/types@0.2.0 [method]incoming-response.consume +//go:wasmimport wasi:http/types@0.2.1 [method]incoming-response.consume //go:noescape func wasmimport_IncomingResponseConsume(self0 uint32, result *cm.Result[IncomingBody, IncomingBody, struct{}]) @@ -1638,7 +1645,7 @@ func (self IncomingResponse) Headers() (result Fields) { return } -//go:wasmimport wasi:http/types@0.2.0 [method]incoming-response.headers +//go:wasmimport wasi:http/types@0.2.1 [method]incoming-response.headers //go:noescape func wasmimport_IncomingResponseHeaders(self0 uint32) (result0 uint32) @@ -1656,11 +1663,11 @@ func (self IncomingResponse) Status() (result StatusCode) { return } -//go:wasmimport wasi:http/types@0.2.0 [method]incoming-response.status +//go:wasmimport wasi:http/types@0.2.1 [method]incoming-response.status //go:noescape func wasmimport_IncomingResponseStatus(self0 uint32) (result0 uint32) -// IncomingBody represents the imported resource "wasi:http/types@0.2.0#incoming-body". +// IncomingBody represents the imported resource "wasi:http/types@0.2.1#incoming-body". // // Represents an incoming HTTP Request or Response's Body. // @@ -1685,7 +1692,7 @@ func (self IncomingBody) ResourceDrop() { return } -//go:wasmimport wasi:http/types@0.2.0 [resource-drop]incoming-body +//go:wasmimport wasi:http/types@0.2.1 [resource-drop]incoming-body //go:noescape func wasmimport_IncomingBodyResourceDrop(self0 uint32) @@ -1704,7 +1711,7 @@ func IncomingBodyFinish(this IncomingBody) (result FutureTrailers) { return } -//go:wasmimport wasi:http/types@0.2.0 [static]incoming-body.finish +//go:wasmimport wasi:http/types@0.2.1 [static]incoming-body.finish //go:noescape func wasmimport_IncomingBodyFinish(this0 uint32) (result0 uint32) @@ -1735,13 +1742,13 @@ func (self IncomingBody) Stream() (result cm.Result[streams.InputStream, streams return } -//go:wasmimport wasi:http/types@0.2.0 [method]incoming-body.stream +//go:wasmimport wasi:http/types@0.2.1 [method]incoming-body.stream //go:noescape func wasmimport_IncomingBodyStream(self0 uint32, result *cm.Result[streams.InputStream, streams.InputStream, struct{}]) -// FutureTrailers represents the imported resource "wasi:http/types@0.2.0#future-trailers". +// FutureTrailers represents the imported resource "wasi:http/types@0.2.1#future-trailers". // -// Represents a future which may eventaully return trailers, or an error. +// Represents a future which may eventually return trailers, or an error. // // In the case that the incoming HTTP Request or Response did not have any // trailers, this future will resolve to the empty set of trailers once the @@ -1761,13 +1768,13 @@ func (self FutureTrailers) ResourceDrop() { return } -//go:wasmimport wasi:http/types@0.2.0 [resource-drop]future-trailers +//go:wasmimport wasi:http/types@0.2.1 [resource-drop]future-trailers //go:noescape func wasmimport_FutureTrailersResourceDrop(self0 uint32) // Get represents the imported method "get". // -// Returns the contents of the trailers, or an error which occured, +// Returns the contents of the trailers, or an error which occurred, // once the future is ready. // // The outer `option` represents future readiness. Users can wait on this @@ -1779,7 +1786,7 @@ func wasmimport_FutureTrailersResourceDrop(self0 uint32) // // The inner `result` represents that either the HTTP Request or Response // body, as well as any trailers, were received successfully, or that an -// error occured receiving them. The optional `trailers` indicates whether +// error occurred receiving them. The optional `trailers` indicates whether // or not trailers were present in the body. // // When some `trailers` are returned by this method, the `trailers` @@ -1796,14 +1803,14 @@ func (self FutureTrailers) Get() (result cm.Option[cm.Result[cm.Result[ErrorCode return } -//go:wasmimport wasi:http/types@0.2.0 [method]future-trailers.get +//go:wasmimport wasi:http/types@0.2.1 [method]future-trailers.get //go:noescape func wasmimport_FutureTrailersGet(self0 uint32, result *cm.Option[cm.Result[cm.Result[ErrorCodeShape, cm.Option[Fields], ErrorCode], cm.Result[ErrorCodeShape, cm.Option[Fields], ErrorCode], struct{}]]) // Subscribe represents the imported method "subscribe". // // Returns a pollable which becomes ready when either the trailers have -// been received, or an error has occured. When this pollable is ready, +// been received, or an error has occurred. When this pollable is ready, // the `get` method will return `some`. // // subscribe: func() -> pollable @@ -1816,11 +1823,11 @@ func (self FutureTrailers) Subscribe() (result poll.Pollable) { return } -//go:wasmimport wasi:http/types@0.2.0 [method]future-trailers.subscribe +//go:wasmimport wasi:http/types@0.2.1 [method]future-trailers.subscribe //go:noescape func wasmimport_FutureTrailersSubscribe(self0 uint32) (result0 uint32) -// OutgoingResponse represents the imported resource "wasi:http/types@0.2.0#outgoing-response". +// OutgoingResponse represents the imported resource "wasi:http/types@0.2.1#outgoing-response". // // Represents an outgoing HTTP Response. // @@ -1838,7 +1845,7 @@ func (self OutgoingResponse) ResourceDrop() { return } -//go:wasmimport wasi:http/types@0.2.0 [resource-drop]outgoing-response +//go:wasmimport wasi:http/types@0.2.1 [resource-drop]outgoing-response //go:noescape func wasmimport_OutgoingResponseResourceDrop(self0 uint32) @@ -1860,7 +1867,7 @@ func NewOutgoingResponse(headers Fields) (result OutgoingResponse) { return } -//go:wasmimport wasi:http/types@0.2.0 [constructor]outgoing-response +//go:wasmimport wasi:http/types@0.2.1 [constructor]outgoing-response //go:noescape func wasmimport_NewOutgoingResponse(headers0 uint32) (result0 uint32) @@ -1881,7 +1888,7 @@ func (self OutgoingResponse) Body() (result cm.Result[OutgoingBody, OutgoingBody return } -//go:wasmimport wasi:http/types@0.2.0 [method]outgoing-response.body +//go:wasmimport wasi:http/types@0.2.1 [method]outgoing-response.body //go:noescape func wasmimport_OutgoingResponseBody(self0 uint32, result *cm.Result[OutgoingBody, OutgoingBody, struct{}]) @@ -1893,7 +1900,7 @@ func wasmimport_OutgoingResponseBody(self0 uint32, result *cm.Result[OutgoingBod // `delete` operations will fail with `header-error.immutable`. // // This headers resource is a child: it must be dropped before the parent -// `outgoing-request` is dropped, or its ownership is transfered to +// `outgoing-request` is dropped, or its ownership is transferred to // another component by e.g. `outgoing-handler.handle`. // // headers: func() -> headers @@ -1906,7 +1913,7 @@ func (self OutgoingResponse) Headers() (result Fields) { return } -//go:wasmimport wasi:http/types@0.2.0 [method]outgoing-response.headers +//go:wasmimport wasi:http/types@0.2.1 [method]outgoing-response.headers //go:noescape func wasmimport_OutgoingResponseHeaders(self0 uint32) (result0 uint32) @@ -1926,7 +1933,7 @@ func (self OutgoingResponse) SetStatusCode(statusCode StatusCode) (result cm.Boo return } -//go:wasmimport wasi:http/types@0.2.0 [method]outgoing-response.set-status-code +//go:wasmimport wasi:http/types@0.2.1 [method]outgoing-response.set-status-code //go:noescape func wasmimport_OutgoingResponseSetStatusCode(self0 uint32, statusCode0 uint32) (result0 uint32) @@ -1944,11 +1951,11 @@ func (self OutgoingResponse) StatusCode() (result StatusCode) { return } -//go:wasmimport wasi:http/types@0.2.0 [method]outgoing-response.status-code +//go:wasmimport wasi:http/types@0.2.1 [method]outgoing-response.status-code //go:noescape func wasmimport_OutgoingResponseStatusCode(self0 uint32) (result0 uint32) -// OutgoingBody represents the imported resource "wasi:http/types@0.2.0#outgoing-body". +// OutgoingBody represents the imported resource "wasi:http/types@0.2.1#outgoing-body". // // Represents an outgoing HTTP Request or Response's Body. // @@ -1962,7 +1969,7 @@ func wasmimport_OutgoingResponseStatusCode(self0 uint32) (result0 uint32) // // If the user code drops this resource, as opposed to calling the static // method `finish`, the implementation should treat the body as incomplete, -// and that an error has occured. The implementation should propogate this +// and that an error has occurred. The implementation should propagate this // error to the HTTP protocol by whatever means it has available, // including: corrupting the body on the wire, aborting the associated // Request, or sending a late status code for the Response. @@ -1981,7 +1988,7 @@ func (self OutgoingBody) ResourceDrop() { return } -//go:wasmimport wasi:http/types@0.2.0 [resource-drop]outgoing-body +//go:wasmimport wasi:http/types@0.2.1 [resource-drop]outgoing-body //go:noescape func wasmimport_OutgoingBodyResourceDrop(self0 uint32) @@ -2008,7 +2015,7 @@ func OutgoingBodyFinish(this OutgoingBody, trailers cm.Option[Fields]) (result c return } -//go:wasmimport wasi:http/types@0.2.0 [static]outgoing-body.finish +//go:wasmimport wasi:http/types@0.2.1 [static]outgoing-body.finish //go:noescape func wasmimport_OutgoingBodyFinish(this0 uint32, trailers0 uint32, trailers1 uint32, result *cm.Result[ErrorCode, struct{}, ErrorCode]) @@ -2033,13 +2040,13 @@ func (self OutgoingBody) Write() (result cm.Result[streams.OutputStream, streams return } -//go:wasmimport wasi:http/types@0.2.0 [method]outgoing-body.write +//go:wasmimport wasi:http/types@0.2.1 [method]outgoing-body.write //go:noescape func wasmimport_OutgoingBodyWrite(self0 uint32, result *cm.Result[streams.OutputStream, streams.OutputStream, struct{}]) -// FutureIncomingResponse represents the imported resource "wasi:http/types@0.2.0#future-incoming-response". +// FutureIncomingResponse represents the imported resource "wasi:http/types@0.2.1#future-incoming-response". // -// Represents a future which may eventaully return an incoming HTTP +// Represents a future which may eventually return an incoming HTTP // Response, or an error. // // This resource is returned by the `wasi:http/outgoing-handler` interface to @@ -2059,7 +2066,7 @@ func (self FutureIncomingResponse) ResourceDrop() { return } -//go:wasmimport wasi:http/types@0.2.0 [resource-drop]future-incoming-response +//go:wasmimport wasi:http/types@0.2.1 [resource-drop]future-incoming-response //go:noescape func wasmimport_FutureIncomingResponseResourceDrop(self0 uint32) @@ -2075,8 +2082,8 @@ func wasmimport_FutureIncomingResponseResourceDrop(self0 uint32) // is `some`, and error on subsequent calls. // // The inner `result` represents that either the incoming HTTP Response -// status and headers have recieved successfully, or that an error -// occured. Errors may also occur while consuming the response body, +// status and headers have received successfully, or that an error +// occurred. Errors may also occur while consuming the response body, // but those will be reported by the `incoming-body` and its // `output-stream` child. // @@ -2089,14 +2096,14 @@ func (self FutureIncomingResponse) Get() (result cm.Option[cm.Result[cm.Result[E return } -//go:wasmimport wasi:http/types@0.2.0 [method]future-incoming-response.get +//go:wasmimport wasi:http/types@0.2.1 [method]future-incoming-response.get //go:noescape func wasmimport_FutureIncomingResponseGet(self0 uint32, result *cm.Option[cm.Result[cm.Result[ErrorCodeShape, IncomingResponse, ErrorCode], cm.Result[ErrorCodeShape, IncomingResponse, ErrorCode], struct{}]]) // Subscribe represents the imported method "subscribe". // // Returns a pollable which becomes ready when either the Response has -// been received, or an error has occured. When this pollable is ready, +// been received, or an error has occurred. When this pollable is ready, // the `get` method will return `some`. // // subscribe: func() -> pollable @@ -2109,7 +2116,7 @@ func (self FutureIncomingResponse) Subscribe() (result poll.Pollable) { return } -//go:wasmimport wasi:http/types@0.2.0 [method]future-incoming-response.subscribe +//go:wasmimport wasi:http/types@0.2.1 [method]future-incoming-response.subscribe //go:noescape func wasmimport_FutureIncomingResponseSubscribe(self0 uint32) (result0 uint32) @@ -2136,6 +2143,6 @@ func HTTPErrorCode(err ioerror.Error) (result cm.Option[ErrorCode]) { return } -//go:wasmimport wasi:http/types@0.2.0 http-error-code +//go:wasmimport wasi:http/types@0.2.1 http-error-code //go:noescape func wasmimport_HTTPErrorCode(err0 uint32, result *cm.Option[ErrorCode]) diff --git a/tests/go/wasi/bindings/wasi/io/error/error.wit.go b/tests/go/wasi/bindings/wasi/io/error/error.wit.go index 96d18cf..9571a52 100644 --- a/tests/go/wasi/bindings/wasi/io/error/error.wit.go +++ b/tests/go/wasi/bindings/wasi/io/error/error.wit.go @@ -1,13 +1,13 @@ // Code generated by wit-bindgen-go. DO NOT EDIT. -// Package ioerror represents the imported interface "wasi:io/error@0.2.0". +// Package ioerror represents the imported interface "wasi:io/error@0.2.1". package ioerror import ( - "github.com/ydnar/wasm-tools-go/cm" + "github.com/bytecodealliance/wasm-tools-go/cm" ) -// Error represents the imported resource "wasi:io/error@0.2.0#error". +// Error represents the imported resource "wasi:io/error@0.2.1#error". // // A resource which represents some error information. // @@ -18,13 +18,11 @@ import ( // `wasi:io/streams/stream-error` type. // // To provide more specific error information, other interfaces may -// provide functions to further "downcast" this error into more specific -// error information. For example, `error`s returned in streams derived -// from filesystem types to be described using the filesystem's own -// error-code type, using the function -// `wasi:filesystem/types/filesystem-error-code`, which takes a parameter -// `borrow` and returns -// `option`. +// offer functions to "downcast" this error into more specific types. For example, +// errors returned from streams derived from filesystem types can be described using +// the filesystem's own error-code type. This is done using the function +// `wasi:filesystem/types/filesystem-error-code`, which takes a `borrow` +// parameter and returns an `option`. // // The set of functions which can "downcast" an `error` into a more // concrete type is open. @@ -43,7 +41,7 @@ func (self Error) ResourceDrop() { return } -//go:wasmimport wasi:io/error@0.2.0 [resource-drop]error +//go:wasmimport wasi:io/error@0.2.1 [resource-drop]error //go:noescape func wasmimport_ErrorResourceDrop(self0 uint32) @@ -66,6 +64,6 @@ func (self Error) ToDebugString() (result string) { return } -//go:wasmimport wasi:io/error@0.2.0 [method]error.to-debug-string +//go:wasmimport wasi:io/error@0.2.1 [method]error.to-debug-string //go:noescape func wasmimport_ErrorToDebugString(self0 uint32, result *string) diff --git a/tests/go/wasi/bindings/wasi/io/poll/poll.wit.go b/tests/go/wasi/bindings/wasi/io/poll/poll.wit.go index ba22e54..89ed0b9 100644 --- a/tests/go/wasi/bindings/wasi/io/poll/poll.wit.go +++ b/tests/go/wasi/bindings/wasi/io/poll/poll.wit.go @@ -1,16 +1,16 @@ // Code generated by wit-bindgen-go. DO NOT EDIT. -// Package poll represents the imported interface "wasi:io/poll@0.2.0". +// Package poll represents the imported interface "wasi:io/poll@0.2.1". // // A poll API intended to let users wait for I/O events on multiple handles // at once. package poll import ( - "github.com/ydnar/wasm-tools-go/cm" + "github.com/bytecodealliance/wasm-tools-go/cm" ) -// Pollable represents the imported resource "wasi:io/poll@0.2.0#pollable". +// Pollable represents the imported resource "wasi:io/poll@0.2.1#pollable". // // `pollable` represents a single I/O event which may be ready, or not. // @@ -28,7 +28,7 @@ func (self Pollable) ResourceDrop() { return } -//go:wasmimport wasi:io/poll@0.2.0 [resource-drop]pollable +//go:wasmimport wasi:io/poll@0.2.1 [resource-drop]pollable //go:noescape func wasmimport_PollableResourceDrop(self0 uint32) @@ -49,7 +49,7 @@ func (self Pollable) Block() { return } -//go:wasmimport wasi:io/poll@0.2.0 [method]pollable.block +//go:wasmimport wasi:io/poll@0.2.1 [method]pollable.block //go:noescape func wasmimport_PollableBlock(self0 uint32) @@ -69,7 +69,7 @@ func (self Pollable) Ready() (result bool) { return } -//go:wasmimport wasi:io/poll@0.2.0 [method]pollable.ready +//go:wasmimport wasi:io/poll@0.2.1 [method]pollable.ready //go:noescape func wasmimport_PollableReady(self0 uint32) (result0 uint32) @@ -83,8 +83,9 @@ func wasmimport_PollableReady(self0 uint32) (result0 uint32) // The result `list` contains one or more indices of handles in the // argument list that is ready for I/O. // -// If the list contains more elements than can be indexed with a `u32` -// value, this function traps. +// This function traps if either: +// - the list is empty, or: +// - the list contains more elements than can be indexed with a `u32` value. // // A timeout can be implemented by adding a pollable from the // wasi-clocks API to the list. @@ -92,7 +93,7 @@ func wasmimport_PollableReady(self0 uint32) (result0 uint32) // This function does not return a `result`; polling in itself does not // do any I/O so it doesn't fail. If any of the I/O sources identified by // the pollables has an error, it is indicated by marking the source as -// being reaedy for I/O. +// being ready for I/O. // // poll: func(in: list>) -> list // @@ -103,6 +104,6 @@ func Poll(in cm.List[Pollable]) (result cm.List[uint32]) { return } -//go:wasmimport wasi:io/poll@0.2.0 poll +//go:wasmimport wasi:io/poll@0.2.1 poll //go:noescape func wasmimport_Poll(in0 *Pollable, in1 uint32, result *cm.List[uint32]) diff --git a/tests/go/wasi/bindings/wasi/io/streams/streams.wit.go b/tests/go/wasi/bindings/wasi/io/streams/streams.wit.go index a9f30a7..50625d8 100644 --- a/tests/go/wasi/bindings/wasi/io/streams/streams.wit.go +++ b/tests/go/wasi/bindings/wasi/io/streams/streams.wit.go @@ -1,6 +1,6 @@ // Code generated by wit-bindgen-go. DO NOT EDIT. -// Package streams represents the imported interface "wasi:io/streams@0.2.0". +// Package streams represents the imported interface "wasi:io/streams@0.2.1". // // WASI I/O is an I/O abstraction API which is currently focused on providing // stream types. @@ -10,12 +10,12 @@ package streams import ( + "github.com/bytecodealliance/wasm-tools-go/cm" ioerror "github.com/rvolosatovs/west/tests/go/wasi/bindings/wasi/io/error" "github.com/rvolosatovs/west/tests/go/wasi/bindings/wasi/io/poll" - "github.com/ydnar/wasm-tools-go/cm" ) -// StreamError represents the imported variant "wasi:io/streams@0.2.0#stream-error". +// StreamError represents the imported variant "wasi:io/streams@0.2.1#stream-error". // // An error for input-stream and output-stream operations. // @@ -54,7 +54,7 @@ func (self *StreamError) Closed() bool { return self.Tag() == 1 } -// InputStream represents the imported resource "wasi:io/streams@0.2.0#input-stream". +// InputStream represents the imported resource "wasi:io/streams@0.2.1#input-stream". // // An input bytestream. // @@ -79,7 +79,7 @@ func (self InputStream) ResourceDrop() { return } -//go:wasmimport wasi:io/streams@0.2.0 [resource-drop]input-stream +//go:wasmimport wasi:io/streams@0.2.1 [resource-drop]input-stream //go:noescape func wasmimport_InputStreamResourceDrop(self0 uint32) @@ -98,7 +98,7 @@ func (self InputStream) BlockingRead(len_ uint64) (result cm.Result[cm.List[uint return } -//go:wasmimport wasi:io/streams@0.2.0 [method]input-stream.blocking-read +//go:wasmimport wasi:io/streams@0.2.1 [method]input-stream.blocking-read //go:noescape func wasmimport_InputStreamBlockingRead(self0 uint32, len0 uint64, result *cm.Result[cm.List[uint8], cm.List[uint8], StreamError]) @@ -117,7 +117,7 @@ func (self InputStream) BlockingSkip(len_ uint64) (result cm.Result[uint64, uint return } -//go:wasmimport wasi:io/streams@0.2.0 [method]input-stream.blocking-skip +//go:wasmimport wasi:io/streams@0.2.1 [method]input-stream.blocking-skip //go:noescape func wasmimport_InputStreamBlockingSkip(self0 uint32, len0 uint64, result *cm.Result[uint64, uint64, StreamError]) @@ -160,7 +160,7 @@ func (self InputStream) Read(len_ uint64) (result cm.Result[cm.List[uint8], cm.L return } -//go:wasmimport wasi:io/streams@0.2.0 [method]input-stream.read +//go:wasmimport wasi:io/streams@0.2.1 [method]input-stream.read //go:noescape func wasmimport_InputStreamRead(self0 uint32, len0 uint64, result *cm.Result[cm.List[uint8], cm.List[uint8], StreamError]) @@ -181,7 +181,7 @@ func (self InputStream) Skip(len_ uint64) (result cm.Result[uint64, uint64, Stre return } -//go:wasmimport wasi:io/streams@0.2.0 [method]input-stream.skip +//go:wasmimport wasi:io/streams@0.2.1 [method]input-stream.skip //go:noescape func wasmimport_InputStreamSkip(self0 uint32, len0 uint64, result *cm.Result[uint64, uint64, StreamError]) @@ -204,11 +204,11 @@ func (self InputStream) Subscribe() (result poll.Pollable) { return } -//go:wasmimport wasi:io/streams@0.2.0 [method]input-stream.subscribe +//go:wasmimport wasi:io/streams@0.2.1 [method]input-stream.subscribe //go:noescape func wasmimport_InputStreamSubscribe(self0 uint32) (result0 uint32) -// OutputStream represents the imported resource "wasi:io/streams@0.2.0#output-stream". +// OutputStream represents the imported resource "wasi:io/streams@0.2.1#output-stream". // // An output bytestream. // @@ -219,6 +219,10 @@ func wasmimport_InputStreamSubscribe(self0 uint32) (result0 uint32) // accept data, the `subscribe` function to obtain a `pollable` which can be // polled for using `wasi:io/poll`. // +// Dropping an `output-stream` while there's still an active write in +// progress may result in the data being lost. Before dropping the stream, +// be sure to fully flush your writes. +// // resource output-stream type OutputStream cm.Resource @@ -233,7 +237,7 @@ func (self OutputStream) ResourceDrop() { return } -//go:wasmimport wasi:io/streams@0.2.0 [resource-drop]output-stream +//go:wasmimport wasi:io/streams@0.2.1 [resource-drop]output-stream //go:noescape func wasmimport_OutputStreamResourceDrop(self0 uint32) @@ -251,7 +255,7 @@ func (self OutputStream) BlockingFlush() (result cm.Result[StreamError, struct{} return } -//go:wasmimport wasi:io/streams@0.2.0 [method]output-stream.blocking-flush +//go:wasmimport wasi:io/streams@0.2.1 [method]output-stream.blocking-flush //go:noescape func wasmimport_OutputStreamBlockingFlush(self0 uint32, result *cm.Result[StreamError, struct{}, StreamError]) @@ -274,7 +278,7 @@ func (self OutputStream) BlockingSplice(src InputStream, len_ uint64) (result cm return } -//go:wasmimport wasi:io/streams@0.2.0 [method]output-stream.blocking-splice +//go:wasmimport wasi:io/streams@0.2.1 [method]output-stream.blocking-splice //go:noescape func wasmimport_OutputStreamBlockingSplice(self0 uint32, src0 uint32, len0 uint64, result *cm.Result[uint64, uint64, StreamError]) @@ -313,7 +317,7 @@ func (self OutputStream) BlockingWriteAndFlush(contents cm.List[uint8]) (result return } -//go:wasmimport wasi:io/streams@0.2.0 [method]output-stream.blocking-write-and-flush +//go:wasmimport wasi:io/streams@0.2.1 [method]output-stream.blocking-write-and-flush //go:noescape func wasmimport_OutputStreamBlockingWriteAndFlush(self0 uint32, contents0 *uint8, contents1 uint32, result *cm.Result[StreamError, struct{}, StreamError]) @@ -352,7 +356,7 @@ func (self OutputStream) BlockingWriteZeroesAndFlush(len_ uint64) (result cm.Res return } -//go:wasmimport wasi:io/streams@0.2.0 [method]output-stream.blocking-write-zeroes-and-flush +//go:wasmimport wasi:io/streams@0.2.1 [method]output-stream.blocking-write-zeroes-and-flush //go:noescape func wasmimport_OutputStreamBlockingWriteZeroesAndFlush(self0 uint32, len0 uint64, result *cm.Result[StreamError, struct{}, StreamError]) @@ -377,7 +381,7 @@ func (self OutputStream) CheckWrite() (result cm.Result[uint64, uint64, StreamEr return } -//go:wasmimport wasi:io/streams@0.2.0 [method]output-stream.check-write +//go:wasmimport wasi:io/streams@0.2.1 [method]output-stream.check-write //go:noescape func wasmimport_OutputStreamCheckWrite(self0 uint32, result *cm.Result[uint64, uint64, StreamError]) @@ -403,7 +407,7 @@ func (self OutputStream) Flush() (result cm.Result[StreamError, struct{}, Stream return } -//go:wasmimport wasi:io/streams@0.2.0 [method]output-stream.flush +//go:wasmimport wasi:io/streams@0.2.1 [method]output-stream.flush //go:noescape func wasmimport_OutputStreamFlush(self0 uint32, result *cm.Result[StreamError, struct{}, StreamError]) @@ -411,7 +415,7 @@ func wasmimport_OutputStreamFlush(self0 uint32, result *cm.Result[StreamError, s // // Read from one stream and write to another. // -// The behavior of splice is equivelant to: +// The behavior of splice is equivalent to: // 1. calling `check-write` on the `output-stream` // 2. calling `read` on the `input-stream` with the smaller of the // `check-write` permitted length and the `len` provided to `splice` @@ -434,14 +438,14 @@ func (self OutputStream) Splice(src InputStream, len_ uint64) (result cm.Result[ return } -//go:wasmimport wasi:io/streams@0.2.0 [method]output-stream.splice +//go:wasmimport wasi:io/streams@0.2.1 [method]output-stream.splice //go:noescape func wasmimport_OutputStreamSplice(self0 uint32, src0 uint32, len0 uint64, result *cm.Result[uint64, uint64, StreamError]) // Subscribe represents the imported method "subscribe". // // Create a `pollable` which will resolve once the output-stream -// is ready for more writing, or an error has occured. When this +// is ready for more writing, or an error has occurred. When this // pollable is ready, `check-write` will return `ok(n)` with n>0, or an // error. // @@ -461,7 +465,7 @@ func (self OutputStream) Subscribe() (result poll.Pollable) { return } -//go:wasmimport wasi:io/streams@0.2.0 [method]output-stream.subscribe +//go:wasmimport wasi:io/streams@0.2.1 [method]output-stream.subscribe //go:noescape func wasmimport_OutputStreamSubscribe(self0 uint32) (result0 uint32) @@ -491,7 +495,7 @@ func (self OutputStream) Write(contents cm.List[uint8]) (result cm.Result[Stream return } -//go:wasmimport wasi:io/streams@0.2.0 [method]output-stream.write +//go:wasmimport wasi:io/streams@0.2.1 [method]output-stream.write //go:noescape func wasmimport_OutputStreamWrite(self0 uint32, contents0 *uint8, contents1 uint32, result *cm.Result[StreamError, struct{}, StreamError]) @@ -514,6 +518,6 @@ func (self OutputStream) WriteZeroes(len_ uint64) (result cm.Result[StreamError, return } -//go:wasmimport wasi:io/streams@0.2.0 [method]output-stream.write-zeroes +//go:wasmimport wasi:io/streams@0.2.1 [method]output-stream.write-zeroes //go:noescape func wasmimport_OutputStreamWriteZeroes(self0 uint32, len0 uint64, result *cm.Result[StreamError, struct{}, StreamError]) diff --git a/tests/go/wasi/bindings/wasi/random/insecure-seed/insecure-seed.wit.go b/tests/go/wasi/bindings/wasi/random/insecure-seed/insecure-seed.wit.go index 3b8f33c..fa25a3b 100644 --- a/tests/go/wasi/bindings/wasi/random/insecure-seed/insecure-seed.wit.go +++ b/tests/go/wasi/bindings/wasi/random/insecure-seed/insecure-seed.wit.go @@ -1,6 +1,6 @@ // Code generated by wit-bindgen-go. DO NOT EDIT. -// Package insecureseed represents the imported interface "wasi:random/insecure-seed@0.2.0". +// Package insecureseed represents the imported interface "wasi:random/insecure-seed@0.2.1". // // The insecure-seed interface for seeding hash-map DoS resistance. // @@ -36,6 +36,6 @@ func InsecureSeed() (result [2]uint64) { return } -//go:wasmimport wasi:random/insecure-seed@0.2.0 insecure-seed +//go:wasmimport wasi:random/insecure-seed@0.2.1 insecure-seed //go:noescape func wasmimport_InsecureSeed(result *[2]uint64) diff --git a/tests/go/wasi/bindings/wasi/random/insecure/insecure.wit.go b/tests/go/wasi/bindings/wasi/random/insecure/insecure.wit.go index 4f813bf..6235f33 100644 --- a/tests/go/wasi/bindings/wasi/random/insecure/insecure.wit.go +++ b/tests/go/wasi/bindings/wasi/random/insecure/insecure.wit.go @@ -1,6 +1,6 @@ // Code generated by wit-bindgen-go. DO NOT EDIT. -// Package insecure represents the imported interface "wasi:random/insecure@0.2.0". +// Package insecure represents the imported interface "wasi:random/insecure@0.2.1". // // The insecure interface for insecure pseudo-random numbers. // @@ -9,7 +9,7 @@ package insecure import ( - "github.com/ydnar/wasm-tools-go/cm" + "github.com/bytecodealliance/wasm-tools-go/cm" ) // GetInsecureRandomBytes represents the imported function "get-insecure-random-bytes". @@ -32,7 +32,7 @@ func GetInsecureRandomBytes(len_ uint64) (result cm.List[uint8]) { return } -//go:wasmimport wasi:random/insecure@0.2.0 get-insecure-random-bytes +//go:wasmimport wasi:random/insecure@0.2.1 get-insecure-random-bytes //go:noescape func wasmimport_GetInsecureRandomBytes(len0 uint64, result *cm.List[uint8]) @@ -52,6 +52,6 @@ func GetInsecureRandomU64() (result uint64) { return } -//go:wasmimport wasi:random/insecure@0.2.0 get-insecure-random-u64 +//go:wasmimport wasi:random/insecure@0.2.1 get-insecure-random-u64 //go:noescape func wasmimport_GetInsecureRandomU64() (result0 uint64) diff --git a/tests/go/wasi/bindings/wasi/random/random/random.wit.go b/tests/go/wasi/bindings/wasi/random/random/random.wit.go index 04b2319..fbdbdb2 100644 --- a/tests/go/wasi/bindings/wasi/random/random/random.wit.go +++ b/tests/go/wasi/bindings/wasi/random/random/random.wit.go @@ -1,6 +1,6 @@ // Code generated by wit-bindgen-go. DO NOT EDIT. -// Package random represents the imported interface "wasi:random/random@0.2.0". +// Package random represents the imported interface "wasi:random/random@0.2.1". // // WASI Random is a random data API. // @@ -9,7 +9,7 @@ package random import ( - "github.com/ydnar/wasm-tools-go/cm" + "github.com/bytecodealliance/wasm-tools-go/cm" ) // GetRandomBytes represents the imported function "get-random-bytes". @@ -36,7 +36,7 @@ func GetRandomBytes(len_ uint64) (result cm.List[uint8]) { return } -//go:wasmimport wasi:random/random@0.2.0 get-random-bytes +//go:wasmimport wasi:random/random@0.2.1 get-random-bytes //go:noescape func wasmimport_GetRandomBytes(len0 uint64, result *cm.List[uint8]) @@ -56,6 +56,6 @@ func GetRandomU64() (result uint64) { return } -//go:wasmimport wasi:random/random@0.2.0 get-random-u64 +//go:wasmimport wasi:random/random@0.2.1 get-random-u64 //go:noescape func wasmimport_GetRandomU64() (result0 uint64) diff --git a/tests/go/wasi/bindings/wasi/sockets/instance-network/instance-network.wit.go b/tests/go/wasi/bindings/wasi/sockets/instance-network/instance-network.wit.go index d7d2abf..be46870 100644 --- a/tests/go/wasi/bindings/wasi/sockets/instance-network/instance-network.wit.go +++ b/tests/go/wasi/bindings/wasi/sockets/instance-network/instance-network.wit.go @@ -1,13 +1,13 @@ // Code generated by wit-bindgen-go. DO NOT EDIT. -// Package instancenetwork represents the imported interface "wasi:sockets/instance-network@0.2.0". +// Package instancenetwork represents the imported interface "wasi:sockets/instance-network@0.2.1". // // This interface provides a value-export of the default network handle.. package instancenetwork import ( + "github.com/bytecodealliance/wasm-tools-go/cm" "github.com/rvolosatovs/west/tests/go/wasi/bindings/wasi/sockets/network" - "github.com/ydnar/wasm-tools-go/cm" ) // InstanceNetwork represents the imported function "instance-network". @@ -23,6 +23,6 @@ func InstanceNetwork() (result network.Network) { return } -//go:wasmimport wasi:sockets/instance-network@0.2.0 instance-network +//go:wasmimport wasi:sockets/instance-network@0.2.1 instance-network //go:noescape func wasmimport_InstanceNetwork() (result0 uint32) diff --git a/tests/go/wasi/bindings/wasi/sockets/ip-name-lookup/abi.go b/tests/go/wasi/bindings/wasi/sockets/ip-name-lookup/abi.go index b1f7c7d..d4c9dc9 100644 --- a/tests/go/wasi/bindings/wasi/sockets/ip-name-lookup/abi.go +++ b/tests/go/wasi/bindings/wasi/sockets/ip-name-lookup/abi.go @@ -3,8 +3,8 @@ package ipnamelookup import ( + "github.com/bytecodealliance/wasm-tools-go/cm" "github.com/rvolosatovs/west/tests/go/wasi/bindings/wasi/sockets/network" - "github.com/ydnar/wasm-tools-go/cm" "unsafe" ) diff --git a/tests/go/wasi/bindings/wasi/sockets/ip-name-lookup/ip-name-lookup.wit.go b/tests/go/wasi/bindings/wasi/sockets/ip-name-lookup/ip-name-lookup.wit.go index e0b167d..1ef7b7a 100644 --- a/tests/go/wasi/bindings/wasi/sockets/ip-name-lookup/ip-name-lookup.wit.go +++ b/tests/go/wasi/bindings/wasi/sockets/ip-name-lookup/ip-name-lookup.wit.go @@ -1,15 +1,15 @@ // Code generated by wit-bindgen-go. DO NOT EDIT. -// Package ipnamelookup represents the imported interface "wasi:sockets/ip-name-lookup@0.2.0". +// Package ipnamelookup represents the imported interface "wasi:sockets/ip-name-lookup@0.2.1". package ipnamelookup import ( + "github.com/bytecodealliance/wasm-tools-go/cm" "github.com/rvolosatovs/west/tests/go/wasi/bindings/wasi/io/poll" "github.com/rvolosatovs/west/tests/go/wasi/bindings/wasi/sockets/network" - "github.com/ydnar/wasm-tools-go/cm" ) -// ResolveAddressStream represents the imported resource "wasi:sockets/ip-name-lookup@0.2.0#resolve-address-stream". +// ResolveAddressStream represents the imported resource "wasi:sockets/ip-name-lookup@0.2.1#resolve-address-stream". // // resource resolve-address-stream type ResolveAddressStream cm.Resource @@ -25,7 +25,7 @@ func (self ResolveAddressStream) ResourceDrop() { return } -//go:wasmimport wasi:sockets/ip-name-lookup@0.2.0 [resource-drop]resolve-address-stream +//go:wasmimport wasi:sockets/ip-name-lookup@0.2.1 [resource-drop]resolve-address-stream //go:noescape func wasmimport_ResolveAddressStreamResourceDrop(self0 uint32) @@ -57,7 +57,7 @@ func (self ResolveAddressStream) ResolveNextAddress() (result cm.Result[OptionIP return } -//go:wasmimport wasi:sockets/ip-name-lookup@0.2.0 [method]resolve-address-stream.resolve-next-address +//go:wasmimport wasi:sockets/ip-name-lookup@0.2.1 [method]resolve-address-stream.resolve-next-address //go:noescape func wasmimport_ResolveAddressStreamResolveNextAddress(self0 uint32, result *cm.Result[OptionIPAddressShape, cm.Option[network.IPAddress], network.ErrorCode]) @@ -78,7 +78,7 @@ func (self ResolveAddressStream) Subscribe() (result poll.Pollable) { return } -//go:wasmimport wasi:sockets/ip-name-lookup@0.2.0 [method]resolve-address-stream.subscribe +//go:wasmimport wasi:sockets/ip-name-lookup@0.2.1 [method]resolve-address-stream.subscribe //go:noescape func wasmimport_ResolveAddressStreamSubscribe(self0 uint32) (result0 uint32) @@ -116,6 +116,6 @@ func ResolveAddresses(network_ network.Network, name string) (result cm.Result[R return } -//go:wasmimport wasi:sockets/ip-name-lookup@0.2.0 resolve-addresses +//go:wasmimport wasi:sockets/ip-name-lookup@0.2.1 resolve-addresses //go:noescape func wasmimport_ResolveAddresses(network0 uint32, name0 *uint8, name1 uint32, result *cm.Result[ResolveAddressStream, ResolveAddressStream, network.ErrorCode]) diff --git a/tests/go/wasi/bindings/wasi/sockets/network/network.wit.go b/tests/go/wasi/bindings/wasi/sockets/network/network.wit.go index 4597e24..7d55115 100644 --- a/tests/go/wasi/bindings/wasi/sockets/network/network.wit.go +++ b/tests/go/wasi/bindings/wasi/sockets/network/network.wit.go @@ -1,13 +1,13 @@ // Code generated by wit-bindgen-go. DO NOT EDIT. -// Package network represents the imported interface "wasi:sockets/network@0.2.0". +// Package network represents the imported interface "wasi:sockets/network@0.2.1". package network import ( - "github.com/ydnar/wasm-tools-go/cm" + "github.com/bytecodealliance/wasm-tools-go/cm" ) -// Network represents the imported resource "wasi:sockets/network@0.2.0#network". +// Network represents the imported resource "wasi:sockets/network@0.2.1#network". // // An opaque resource that represents access to (a subset of) the network. // This enables context-based security for networking. @@ -27,11 +27,11 @@ func (self Network) ResourceDrop() { return } -//go:wasmimport wasi:sockets/network@0.2.0 [resource-drop]network +//go:wasmimport wasi:sockets/network@0.2.1 [resource-drop]network //go:noescape func wasmimport_NetworkResourceDrop(self0 uint32) -// ErrorCode represents the enum "wasi:sockets/network@0.2.0#error-code". +// ErrorCode represents the enum "wasi:sockets/network@0.2.1#error-code". // // Error codes. // @@ -186,7 +186,7 @@ func (e ErrorCode) String() string { return stringsErrorCode[e] } -// IPAddressFamily represents the enum "wasi:sockets/network@0.2.0#ip-address-family". +// IPAddressFamily represents the enum "wasi:sockets/network@0.2.1#ip-address-family". // // enum ip-address-family { // ipv4, @@ -212,17 +212,17 @@ func (e IPAddressFamily) String() string { return stringsIPAddressFamily[e] } -// IPv4Address represents the tuple "wasi:sockets/network@0.2.0#ipv4-address". +// IPv4Address represents the tuple "wasi:sockets/network@0.2.1#ipv4-address". // // type ipv4-address = tuple type IPv4Address [4]uint8 -// IPv6Address represents the tuple "wasi:sockets/network@0.2.0#ipv6-address". +// IPv6Address represents the tuple "wasi:sockets/network@0.2.1#ipv6-address". // // type ipv6-address = tuple type IPv6Address [8]uint16 -// IPAddress represents the variant "wasi:sockets/network@0.2.0#ip-address". +// IPAddress represents the variant "wasi:sockets/network@0.2.1#ip-address". // // variant ip-address { // ipv4(ipv4-address), @@ -250,7 +250,7 @@ func (self *IPAddress) IPv6() *IPv6Address { return cm.Case[IPv6Address](self, 1) } -// IPv4SocketAddress represents the record "wasi:sockets/network@0.2.0#ipv4-socket-address". +// IPv4SocketAddress represents the record "wasi:sockets/network@0.2.1#ipv4-socket-address". // // record ipv4-socket-address { // port: u16, @@ -264,7 +264,7 @@ type IPv4SocketAddress struct { Address IPv4Address } -// IPv6SocketAddress represents the record "wasi:sockets/network@0.2.0#ipv6-socket-address". +// IPv6SocketAddress represents the record "wasi:sockets/network@0.2.1#ipv6-socket-address". // // record ipv6-socket-address { // port: u16, @@ -286,7 +286,7 @@ type IPv6SocketAddress struct { ScopeID uint32 } -// IPSocketAddress represents the variant "wasi:sockets/network@0.2.0#ip-socket-address". +// IPSocketAddress represents the variant "wasi:sockets/network@0.2.1#ip-socket-address". // // variant ip-socket-address { // ipv4(ipv4-socket-address), diff --git a/tests/go/wasi/bindings/wasi/sockets/tcp-create-socket/tcp-create-socket.wit.go b/tests/go/wasi/bindings/wasi/sockets/tcp-create-socket/tcp-create-socket.wit.go index e53a343..a1366b3 100644 --- a/tests/go/wasi/bindings/wasi/sockets/tcp-create-socket/tcp-create-socket.wit.go +++ b/tests/go/wasi/bindings/wasi/sockets/tcp-create-socket/tcp-create-socket.wit.go @@ -1,12 +1,12 @@ // Code generated by wit-bindgen-go. DO NOT EDIT. -// Package tcpcreatesocket represents the imported interface "wasi:sockets/tcp-create-socket@0.2.0". +// Package tcpcreatesocket represents the imported interface "wasi:sockets/tcp-create-socket@0.2.1". package tcpcreatesocket import ( + "github.com/bytecodealliance/wasm-tools-go/cm" "github.com/rvolosatovs/west/tests/go/wasi/bindings/wasi/sockets/network" "github.com/rvolosatovs/west/tests/go/wasi/bindings/wasi/sockets/tcp" - "github.com/ydnar/wasm-tools-go/cm" ) // CreateTCPSocket represents the imported function "create-tcp-socket". @@ -47,6 +47,6 @@ func CreateTCPSocket(addressFamily network.IPAddressFamily) (result cm.Result[tc return } -//go:wasmimport wasi:sockets/tcp-create-socket@0.2.0 create-tcp-socket +//go:wasmimport wasi:sockets/tcp-create-socket@0.2.1 create-tcp-socket //go:noescape func wasmimport_CreateTCPSocket(addressFamily0 uint32, result *cm.Result[tcp.TCPSocket, tcp.TCPSocket, network.ErrorCode]) diff --git a/tests/go/wasi/bindings/wasi/sockets/tcp/abi.go b/tests/go/wasi/bindings/wasi/sockets/tcp/abi.go index efc8727..540e53a 100644 --- a/tests/go/wasi/bindings/wasi/sockets/tcp/abi.go +++ b/tests/go/wasi/bindings/wasi/sockets/tcp/abi.go @@ -3,9 +3,9 @@ package tcp import ( + "github.com/bytecodealliance/wasm-tools-go/cm" "github.com/rvolosatovs/west/tests/go/wasi/bindings/wasi/io/streams" "github.com/rvolosatovs/west/tests/go/wasi/bindings/wasi/sockets/network" - "github.com/ydnar/wasm-tools-go/cm" "unsafe" ) diff --git a/tests/go/wasi/bindings/wasi/sockets/tcp/tcp.wit.go b/tests/go/wasi/bindings/wasi/sockets/tcp/tcp.wit.go index e17ae40..82dce86 100644 --- a/tests/go/wasi/bindings/wasi/sockets/tcp/tcp.wit.go +++ b/tests/go/wasi/bindings/wasi/sockets/tcp/tcp.wit.go @@ -1,17 +1,17 @@ // Code generated by wit-bindgen-go. DO NOT EDIT. -// Package tcp represents the imported interface "wasi:sockets/tcp@0.2.0". +// Package tcp represents the imported interface "wasi:sockets/tcp@0.2.1". package tcp import ( + "github.com/bytecodealliance/wasm-tools-go/cm" monotonicclock "github.com/rvolosatovs/west/tests/go/wasi/bindings/wasi/clocks/monotonic-clock" "github.com/rvolosatovs/west/tests/go/wasi/bindings/wasi/io/poll" "github.com/rvolosatovs/west/tests/go/wasi/bindings/wasi/io/streams" "github.com/rvolosatovs/west/tests/go/wasi/bindings/wasi/sockets/network" - "github.com/ydnar/wasm-tools-go/cm" ) -// ShutdownType represents the enum "wasi:sockets/tcp@0.2.0#shutdown-type". +// ShutdownType represents the enum "wasi:sockets/tcp@0.2.1#shutdown-type". // // enum shutdown-type { // receive, @@ -42,7 +42,7 @@ func (e ShutdownType) String() string { return stringsShutdownType[e] } -// TCPSocket represents the imported resource "wasi:sockets/tcp@0.2.0#tcp-socket". +// TCPSocket represents the imported resource "wasi:sockets/tcp@0.2.1#tcp-socket". // // A TCP socket resource. // @@ -55,8 +55,8 @@ func (e ShutdownType) String() string { // - `connect-in-progress` // - `connected` // - `closed` -// See -// for a more information. +// See +// for more information. // // Note: Except where explicitly mentioned, whenever this documentation uses // the term "bound" without backticks it actually means: in the `bound` state *or @@ -81,7 +81,7 @@ func (self TCPSocket) ResourceDrop() { return } -//go:wasmimport wasi:sockets/tcp@0.2.0 [resource-drop]tcp-socket +//go:wasmimport wasi:sockets/tcp@0.2.1 [resource-drop]tcp-socket //go:noescape func wasmimport_TCPSocketResourceDrop(self0 uint32) @@ -126,7 +126,7 @@ func (self TCPSocket) Accept() (result cm.Result[TupleTCPSocketInputStreamOutput return } -//go:wasmimport wasi:sockets/tcp@0.2.0 [method]tcp-socket.accept +//go:wasmimport wasi:sockets/tcp@0.2.1 [method]tcp-socket.accept //go:noescape func wasmimport_TCPSocketAccept(self0 uint32, result *cm.Result[TupleTCPSocketInputStreamOutputStreamShape, cm.Tuple3[TCPSocket, streams.InputStream, streams.OutputStream], network.ErrorCode]) @@ -146,7 +146,7 @@ func (self TCPSocket) AddressFamily() (result network.IPAddressFamily) { return } -//go:wasmimport wasi:sockets/tcp@0.2.0 [method]tcp-socket.address-family +//go:wasmimport wasi:sockets/tcp@0.2.1 [method]tcp-socket.address-family //go:noescape func wasmimport_TCPSocketAddressFamily(self0 uint32) (result0 uint32) @@ -161,7 +161,7 @@ func (self TCPSocket) FinishBind() (result cm.Result[network.ErrorCode, struct{} return } -//go:wasmimport wasi:sockets/tcp@0.2.0 [method]tcp-socket.finish-bind +//go:wasmimport wasi:sockets/tcp@0.2.1 [method]tcp-socket.finish-bind //go:noescape func wasmimport_TCPSocketFinishBind(self0 uint32, result *cm.Result[network.ErrorCode, struct{}, network.ErrorCode]) @@ -176,7 +176,7 @@ func (self TCPSocket) FinishConnect() (result cm.Result[TupleInputStreamOutputSt return } -//go:wasmimport wasi:sockets/tcp@0.2.0 [method]tcp-socket.finish-connect +//go:wasmimport wasi:sockets/tcp@0.2.1 [method]tcp-socket.finish-connect //go:noescape func wasmimport_TCPSocketFinishConnect(self0 uint32, result *cm.Result[TupleInputStreamOutputStreamShape, cm.Tuple[streams.InputStream, streams.OutputStream], network.ErrorCode]) @@ -191,7 +191,7 @@ func (self TCPSocket) FinishListen() (result cm.Result[network.ErrorCode, struct return } -//go:wasmimport wasi:sockets/tcp@0.2.0 [method]tcp-socket.finish-listen +//go:wasmimport wasi:sockets/tcp@0.2.1 [method]tcp-socket.finish-listen //go:noescape func wasmimport_TCPSocketFinishListen(self0 uint32, result *cm.Result[network.ErrorCode, struct{}, network.ErrorCode]) @@ -213,7 +213,7 @@ func (self TCPSocket) HopLimit() (result cm.Result[uint8, uint8, network.ErrorCo return } -//go:wasmimport wasi:sockets/tcp@0.2.0 [method]tcp-socket.hop-limit +//go:wasmimport wasi:sockets/tcp@0.2.1 [method]tcp-socket.hop-limit //go:noescape func wasmimport_TCPSocketHopLimit(self0 uint32, result *cm.Result[uint8, uint8, network.ErrorCode]) @@ -233,7 +233,7 @@ func (self TCPSocket) IsListening() (result bool) { return } -//go:wasmimport wasi:sockets/tcp@0.2.0 [method]tcp-socket.is-listening +//go:wasmimport wasi:sockets/tcp@0.2.1 [method]tcp-socket.is-listening //go:noescape func wasmimport_TCPSocketIsListening(self0 uint32) (result0 uint32) @@ -261,7 +261,7 @@ func (self TCPSocket) KeepAliveCount() (result cm.Result[uint32, uint32, network return } -//go:wasmimport wasi:sockets/tcp@0.2.0 [method]tcp-socket.keep-alive-count +//go:wasmimport wasi:sockets/tcp@0.2.1 [method]tcp-socket.keep-alive-count //go:noescape func wasmimport_TCPSocketKeepAliveCount(self0 uint32, result *cm.Result[uint32, uint32, network.ErrorCode]) @@ -287,7 +287,7 @@ func (self TCPSocket) KeepAliveEnabled() (result cm.Result[bool, bool, network.E return } -//go:wasmimport wasi:sockets/tcp@0.2.0 [method]tcp-socket.keep-alive-enabled +//go:wasmimport wasi:sockets/tcp@0.2.1 [method]tcp-socket.keep-alive-enabled //go:noescape func wasmimport_TCPSocketKeepAliveEnabled(self0 uint32, result *cm.Result[bool, bool, network.ErrorCode]) @@ -316,7 +316,7 @@ func (self TCPSocket) KeepAliveIdleTime() (result cm.Result[uint64, monotonicclo return } -//go:wasmimport wasi:sockets/tcp@0.2.0 [method]tcp-socket.keep-alive-idle-time +//go:wasmimport wasi:sockets/tcp@0.2.1 [method]tcp-socket.keep-alive-idle-time //go:noescape func wasmimport_TCPSocketKeepAliveIdleTime(self0 uint32, result *cm.Result[uint64, monotonicclock.Duration, network.ErrorCode]) @@ -344,7 +344,7 @@ func (self TCPSocket) KeepAliveInterval() (result cm.Result[uint64, monotonicclo return } -//go:wasmimport wasi:sockets/tcp@0.2.0 [method]tcp-socket.keep-alive-interval +//go:wasmimport wasi:sockets/tcp@0.2.1 [method]tcp-socket.keep-alive-interval //go:noescape func wasmimport_TCPSocketKeepAliveInterval(self0 uint32, result *cm.Result[uint64, monotonicclock.Duration, network.ErrorCode]) @@ -377,7 +377,7 @@ func (self TCPSocket) LocalAddress() (result cm.Result[IPSocketAddressShape, net return } -//go:wasmimport wasi:sockets/tcp@0.2.0 [method]tcp-socket.local-address +//go:wasmimport wasi:sockets/tcp@0.2.1 [method]tcp-socket.local-address //go:noescape func wasmimport_TCPSocketLocalAddress(self0 uint32, result *cm.Result[IPSocketAddressShape, network.IPSocketAddress, network.ErrorCode]) @@ -405,7 +405,7 @@ func (self TCPSocket) ReceiveBufferSize() (result cm.Result[uint64, uint64, netw return } -//go:wasmimport wasi:sockets/tcp@0.2.0 [method]tcp-socket.receive-buffer-size +//go:wasmimport wasi:sockets/tcp@0.2.1 [method]tcp-socket.receive-buffer-size //go:noescape func wasmimport_TCPSocketReceiveBufferSize(self0 uint32, result *cm.Result[uint64, uint64, network.ErrorCode]) @@ -431,7 +431,7 @@ func (self TCPSocket) RemoteAddress() (result cm.Result[IPSocketAddressShape, ne return } -//go:wasmimport wasi:sockets/tcp@0.2.0 [method]tcp-socket.remote-address +//go:wasmimport wasi:sockets/tcp@0.2.1 [method]tcp-socket.remote-address //go:noescape func wasmimport_TCPSocketRemoteAddress(self0 uint32, result *cm.Result[IPSocketAddressShape, network.IPSocketAddress, network.ErrorCode]) @@ -446,7 +446,7 @@ func (self TCPSocket) SendBufferSize() (result cm.Result[uint64, uint64, network return } -//go:wasmimport wasi:sockets/tcp@0.2.0 [method]tcp-socket.send-buffer-size +//go:wasmimport wasi:sockets/tcp@0.2.1 [method]tcp-socket.send-buffer-size //go:noescape func wasmimport_TCPSocketSendBufferSize(self0 uint32, result *cm.Result[uint64, uint64, network.ErrorCode]) @@ -462,7 +462,7 @@ func (self TCPSocket) SetHopLimit(value uint8) (result cm.Result[network.ErrorCo return } -//go:wasmimport wasi:sockets/tcp@0.2.0 [method]tcp-socket.set-hop-limit +//go:wasmimport wasi:sockets/tcp@0.2.1 [method]tcp-socket.set-hop-limit //go:noescape func wasmimport_TCPSocketSetHopLimit(self0 uint32, value0 uint32, result *cm.Result[network.ErrorCode, struct{}, network.ErrorCode]) @@ -478,7 +478,7 @@ func (self TCPSocket) SetKeepAliveCount(value uint32) (result cm.Result[network. return } -//go:wasmimport wasi:sockets/tcp@0.2.0 [method]tcp-socket.set-keep-alive-count +//go:wasmimport wasi:sockets/tcp@0.2.1 [method]tcp-socket.set-keep-alive-count //go:noescape func wasmimport_TCPSocketSetKeepAliveCount(self0 uint32, value0 uint32, result *cm.Result[network.ErrorCode, struct{}, network.ErrorCode]) @@ -494,7 +494,7 @@ func (self TCPSocket) SetKeepAliveEnabled(value bool) (result cm.Result[network. return } -//go:wasmimport wasi:sockets/tcp@0.2.0 [method]tcp-socket.set-keep-alive-enabled +//go:wasmimport wasi:sockets/tcp@0.2.1 [method]tcp-socket.set-keep-alive-enabled //go:noescape func wasmimport_TCPSocketSetKeepAliveEnabled(self0 uint32, value0 uint32, result *cm.Result[network.ErrorCode, struct{}, network.ErrorCode]) @@ -510,7 +510,7 @@ func (self TCPSocket) SetKeepAliveIdleTime(value monotonicclock.Duration) (resul return } -//go:wasmimport wasi:sockets/tcp@0.2.0 [method]tcp-socket.set-keep-alive-idle-time +//go:wasmimport wasi:sockets/tcp@0.2.1 [method]tcp-socket.set-keep-alive-idle-time //go:noescape func wasmimport_TCPSocketSetKeepAliveIdleTime(self0 uint32, value0 uint64, result *cm.Result[network.ErrorCode, struct{}, network.ErrorCode]) @@ -526,7 +526,7 @@ func (self TCPSocket) SetKeepAliveInterval(value monotonicclock.Duration) (resul return } -//go:wasmimport wasi:sockets/tcp@0.2.0 [method]tcp-socket.set-keep-alive-interval +//go:wasmimport wasi:sockets/tcp@0.2.1 [method]tcp-socket.set-keep-alive-interval //go:noescape func wasmimport_TCPSocketSetKeepAliveInterval(self0 uint32, value0 uint64, result *cm.Result[network.ErrorCode, struct{}, network.ErrorCode]) @@ -555,7 +555,7 @@ func (self TCPSocket) SetListenBacklogSize(value uint64) (result cm.Result[netwo return } -//go:wasmimport wasi:sockets/tcp@0.2.0 [method]tcp-socket.set-listen-backlog-size +//go:wasmimport wasi:sockets/tcp@0.2.1 [method]tcp-socket.set-listen-backlog-size //go:noescape func wasmimport_TCPSocketSetListenBacklogSize(self0 uint32, value0 uint64, result *cm.Result[network.ErrorCode, struct{}, network.ErrorCode]) @@ -571,7 +571,7 @@ func (self TCPSocket) SetReceiveBufferSize(value uint64) (result cm.Result[netwo return } -//go:wasmimport wasi:sockets/tcp@0.2.0 [method]tcp-socket.set-receive-buffer-size +//go:wasmimport wasi:sockets/tcp@0.2.1 [method]tcp-socket.set-receive-buffer-size //go:noescape func wasmimport_TCPSocketSetReceiveBufferSize(self0 uint32, value0 uint64, result *cm.Result[network.ErrorCode, struct{}, network.ErrorCode]) @@ -587,7 +587,7 @@ func (self TCPSocket) SetSendBufferSize(value uint64) (result cm.Result[network. return } -//go:wasmimport wasi:sockets/tcp@0.2.0 [method]tcp-socket.set-send-buffer-size +//go:wasmimport wasi:sockets/tcp@0.2.1 [method]tcp-socket.set-send-buffer-size //go:noescape func wasmimport_TCPSocketSetSendBufferSize(self0 uint32, value0 uint64, result *cm.Result[network.ErrorCode, struct{}, network.ErrorCode]) @@ -603,7 +603,7 @@ func wasmimport_TCPSocketSetSendBufferSize(self0 uint32, value0 uint64, result * // associated with this socket will be closed and a FIN packet will be sent. // - `both`: Same effect as `receive` & `send` combined. // -// This function is idempotent. Shutting a down a direction more than once +// This function is idempotent; shutting down a direction more than once // has no effect and returns `ok`. // // The shutdown function does not close (drop) the socket. @@ -627,7 +627,7 @@ func (self TCPSocket) Shutdown(shutdownType ShutdownType) (result cm.Result[netw return } -//go:wasmimport wasi:sockets/tcp@0.2.0 [method]tcp-socket.shutdown +//go:wasmimport wasi:sockets/tcp@0.2.1 [method]tcp-socket.shutdown //go:noescape func wasmimport_TCPSocketShutdown(self0 uint32, shutdownType0 uint32, result *cm.Result[network.ErrorCode, struct{}, network.ErrorCode]) @@ -693,7 +693,7 @@ func (self TCPSocket) StartBind(network_ network.Network, localAddress network.I return } -//go:wasmimport wasi:sockets/tcp@0.2.0 [method]tcp-socket.start-bind +//go:wasmimport wasi:sockets/tcp@0.2.1 [method]tcp-socket.start-bind //go:noescape func wasmimport_TCPSocketStartBind(self0 uint32, network0 uint32, localAddress0 uint32, localAddress1 uint32, localAddress2 uint32, localAddress3 uint32, localAddress4 uint32, localAddress5 uint32, localAddress6 uint32, localAddress7 uint32, localAddress8 uint32, localAddress9 uint32, localAddress10 uint32, localAddress11 uint32, result *cm.Result[network.ErrorCode, struct{}, network.ErrorCode]) @@ -702,7 +702,7 @@ func wasmimport_TCPSocketStartBind(self0 uint32, network0 uint32, localAddress0 // Connect to a remote endpoint. // // On success: -// - the socket is transitioned into the `connection` state. +// - the socket is transitioned into the `connected` state. // - a pair of streams is returned that can be used to read & write to the connection // // After a failed connection attempt, the socket will be in the `closed` @@ -765,7 +765,7 @@ func (self TCPSocket) StartConnect(network_ network.Network, remoteAddress netwo return } -//go:wasmimport wasi:sockets/tcp@0.2.0 [method]tcp-socket.start-connect +//go:wasmimport wasi:sockets/tcp@0.2.1 [method]tcp-socket.start-connect //go:noescape func wasmimport_TCPSocketStartConnect(self0 uint32, network0 uint32, remoteAddress0 uint32, remoteAddress1 uint32, remoteAddress2 uint32, remoteAddress3 uint32, remoteAddress4 uint32, remoteAddress5 uint32, remoteAddress6 uint32, remoteAddress7 uint32, remoteAddress8 uint32, remoteAddress9 uint32, remoteAddress10 uint32, remoteAddress11 uint32, result *cm.Result[network.ErrorCode, struct{}, network.ErrorCode]) @@ -809,7 +809,7 @@ func (self TCPSocket) StartListen() (result cm.Result[network.ErrorCode, struct{ return } -//go:wasmimport wasi:sockets/tcp@0.2.0 [method]tcp-socket.start-listen +//go:wasmimport wasi:sockets/tcp@0.2.1 [method]tcp-socket.start-listen //go:noescape func wasmimport_TCPSocketStartListen(self0 uint32, result *cm.Result[network.ErrorCode, struct{}, network.ErrorCode]) @@ -827,8 +827,8 @@ func wasmimport_TCPSocketStartListen(self0 uint32, result *cm.Result[network.Err // `subscribe` only has to be called once per socket and can then be // (re)used for the remainder of the socket's lifetime. // -// See -// for a more information. +// See +// for more information. // // Note: this function is here for WASI Preview2 only. // It's planned to be removed when `future` is natively supported in Preview3. @@ -843,6 +843,6 @@ func (self TCPSocket) Subscribe() (result poll.Pollable) { return } -//go:wasmimport wasi:sockets/tcp@0.2.0 [method]tcp-socket.subscribe +//go:wasmimport wasi:sockets/tcp@0.2.1 [method]tcp-socket.subscribe //go:noescape func wasmimport_TCPSocketSubscribe(self0 uint32) (result0 uint32) diff --git a/tests/go/wasi/bindings/wasi/sockets/udp-create-socket/udp-create-socket.wit.go b/tests/go/wasi/bindings/wasi/sockets/udp-create-socket/udp-create-socket.wit.go index a88c8ab..96f415f 100644 --- a/tests/go/wasi/bindings/wasi/sockets/udp-create-socket/udp-create-socket.wit.go +++ b/tests/go/wasi/bindings/wasi/sockets/udp-create-socket/udp-create-socket.wit.go @@ -1,12 +1,12 @@ // Code generated by wit-bindgen-go. DO NOT EDIT. -// Package udpcreatesocket represents the imported interface "wasi:sockets/udp-create-socket@0.2.0". +// Package udpcreatesocket represents the imported interface "wasi:sockets/udp-create-socket@0.2.1". package udpcreatesocket import ( + "github.com/bytecodealliance/wasm-tools-go/cm" "github.com/rvolosatovs/west/tests/go/wasi/bindings/wasi/sockets/network" "github.com/rvolosatovs/west/tests/go/wasi/bindings/wasi/sockets/udp" - "github.com/ydnar/wasm-tools-go/cm" ) // CreateUDPSocket represents the imported function "create-udp-socket". @@ -47,6 +47,6 @@ func CreateUDPSocket(addressFamily network.IPAddressFamily) (result cm.Result[ud return } -//go:wasmimport wasi:sockets/udp-create-socket@0.2.0 create-udp-socket +//go:wasmimport wasi:sockets/udp-create-socket@0.2.1 create-udp-socket //go:noescape func wasmimport_CreateUDPSocket(addressFamily0 uint32, result *cm.Result[udp.UDPSocket, udp.UDPSocket, network.ErrorCode]) diff --git a/tests/go/wasi/bindings/wasi/sockets/udp/abi.go b/tests/go/wasi/bindings/wasi/sockets/udp/abi.go index d5f1d36..0924263 100644 --- a/tests/go/wasi/bindings/wasi/sockets/udp/abi.go +++ b/tests/go/wasi/bindings/wasi/sockets/udp/abi.go @@ -3,8 +3,8 @@ package udp import ( + "github.com/bytecodealliance/wasm-tools-go/cm" "github.com/rvolosatovs/west/tests/go/wasi/bindings/wasi/sockets/network" - "github.com/ydnar/wasm-tools-go/cm" "unsafe" ) diff --git a/tests/go/wasi/bindings/wasi/sockets/udp/udp.wit.go b/tests/go/wasi/bindings/wasi/sockets/udp/udp.wit.go index 43fc7d6..f0fcb72 100644 --- a/tests/go/wasi/bindings/wasi/sockets/udp/udp.wit.go +++ b/tests/go/wasi/bindings/wasi/sockets/udp/udp.wit.go @@ -1,15 +1,15 @@ // Code generated by wit-bindgen-go. DO NOT EDIT. -// Package udp represents the imported interface "wasi:sockets/udp@0.2.0". +// Package udp represents the imported interface "wasi:sockets/udp@0.2.1". package udp import ( + "github.com/bytecodealliance/wasm-tools-go/cm" "github.com/rvolosatovs/west/tests/go/wasi/bindings/wasi/io/poll" "github.com/rvolosatovs/west/tests/go/wasi/bindings/wasi/sockets/network" - "github.com/ydnar/wasm-tools-go/cm" ) -// IncomingDatagram represents the record "wasi:sockets/udp@0.2.0#incoming-datagram". +// IncomingDatagram represents the record "wasi:sockets/udp@0.2.1#incoming-datagram". // // A received datagram. // @@ -32,7 +32,7 @@ type IncomingDatagram struct { RemoteAddress network.IPSocketAddress } -// OutgoingDatagram represents the record "wasi:sockets/udp@0.2.0#outgoing-datagram". +// OutgoingDatagram represents the record "wasi:sockets/udp@0.2.1#outgoing-datagram". // // A datagram to be sent out. // @@ -56,7 +56,7 @@ type OutgoingDatagram struct { RemoteAddress cm.Option[network.IPSocketAddress] } -// UDPSocket represents the imported resource "wasi:sockets/udp@0.2.0#udp-socket". +// UDPSocket represents the imported resource "wasi:sockets/udp@0.2.1#udp-socket". // // A UDP socket handle. // @@ -74,7 +74,7 @@ func (self UDPSocket) ResourceDrop() { return } -//go:wasmimport wasi:sockets/udp@0.2.0 [resource-drop]udp-socket +//go:wasmimport wasi:sockets/udp@0.2.1 [resource-drop]udp-socket //go:noescape func wasmimport_UDPSocketResourceDrop(self0 uint32) @@ -94,7 +94,7 @@ func (self UDPSocket) AddressFamily() (result network.IPAddressFamily) { return } -//go:wasmimport wasi:sockets/udp@0.2.0 [method]udp-socket.address-family +//go:wasmimport wasi:sockets/udp@0.2.1 [method]udp-socket.address-family //go:noescape func wasmimport_UDPSocketAddressFamily(self0 uint32) (result0 uint32) @@ -109,7 +109,7 @@ func (self UDPSocket) FinishBind() (result cm.Result[network.ErrorCode, struct{} return } -//go:wasmimport wasi:sockets/udp@0.2.0 [method]udp-socket.finish-bind +//go:wasmimport wasi:sockets/udp@0.2.1 [method]udp-socket.finish-bind //go:noescape func wasmimport_UDPSocketFinishBind(self0 uint32, result *cm.Result[network.ErrorCode, struct{}, network.ErrorCode]) @@ -142,7 +142,7 @@ func (self UDPSocket) LocalAddress() (result cm.Result[IPSocketAddressShape, net return } -//go:wasmimport wasi:sockets/udp@0.2.0 [method]udp-socket.local-address +//go:wasmimport wasi:sockets/udp@0.2.1 [method]udp-socket.local-address //go:noescape func wasmimport_UDPSocketLocalAddress(self0 uint32, result *cm.Result[IPSocketAddressShape, network.IPSocketAddress, network.ErrorCode]) @@ -170,7 +170,7 @@ func (self UDPSocket) ReceiveBufferSize() (result cm.Result[uint64, uint64, netw return } -//go:wasmimport wasi:sockets/udp@0.2.0 [method]udp-socket.receive-buffer-size +//go:wasmimport wasi:sockets/udp@0.2.1 [method]udp-socket.receive-buffer-size //go:noescape func wasmimport_UDPSocketReceiveBufferSize(self0 uint32, result *cm.Result[uint64, uint64, network.ErrorCode]) @@ -196,7 +196,7 @@ func (self UDPSocket) RemoteAddress() (result cm.Result[IPSocketAddressShape, ne return } -//go:wasmimport wasi:sockets/udp@0.2.0 [method]udp-socket.remote-address +//go:wasmimport wasi:sockets/udp@0.2.1 [method]udp-socket.remote-address //go:noescape func wasmimport_UDPSocketRemoteAddress(self0 uint32, result *cm.Result[IPSocketAddressShape, network.IPSocketAddress, network.ErrorCode]) @@ -211,7 +211,7 @@ func (self UDPSocket) SendBufferSize() (result cm.Result[uint64, uint64, network return } -//go:wasmimport wasi:sockets/udp@0.2.0 [method]udp-socket.send-buffer-size +//go:wasmimport wasi:sockets/udp@0.2.1 [method]udp-socket.send-buffer-size //go:noescape func wasmimport_UDPSocketSendBufferSize(self0 uint32, result *cm.Result[uint64, uint64, network.ErrorCode]) @@ -227,7 +227,7 @@ func (self UDPSocket) SetReceiveBufferSize(value uint64) (result cm.Result[netwo return } -//go:wasmimport wasi:sockets/udp@0.2.0 [method]udp-socket.set-receive-buffer-size +//go:wasmimport wasi:sockets/udp@0.2.1 [method]udp-socket.set-receive-buffer-size //go:noescape func wasmimport_UDPSocketSetReceiveBufferSize(self0 uint32, value0 uint64, result *cm.Result[network.ErrorCode, struct{}, network.ErrorCode]) @@ -243,7 +243,7 @@ func (self UDPSocket) SetSendBufferSize(value uint64) (result cm.Result[network. return } -//go:wasmimport wasi:sockets/udp@0.2.0 [method]udp-socket.set-send-buffer-size +//go:wasmimport wasi:sockets/udp@0.2.1 [method]udp-socket.set-send-buffer-size //go:noescape func wasmimport_UDPSocketSetSendBufferSize(self0 uint32, value0 uint64, result *cm.Result[network.ErrorCode, struct{}, network.ErrorCode]) @@ -259,7 +259,7 @@ func (self UDPSocket) SetUnicastHopLimit(value uint8) (result cm.Result[network. return } -//go:wasmimport wasi:sockets/udp@0.2.0 [method]udp-socket.set-unicast-hop-limit +//go:wasmimport wasi:sockets/udp@0.2.1 [method]udp-socket.set-unicast-hop-limit //go:noescape func wasmimport_UDPSocketSetUnicastHopLimit(self0 uint32, value0 uint32, result *cm.Result[network.ErrorCode, struct{}, network.ErrorCode]) @@ -309,7 +309,7 @@ func (self UDPSocket) StartBind(network_ network.Network, localAddress network.I return } -//go:wasmimport wasi:sockets/udp@0.2.0 [method]udp-socket.start-bind +//go:wasmimport wasi:sockets/udp@0.2.1 [method]udp-socket.start-bind //go:noescape func wasmimport_UDPSocketStartBind(self0 uint32, network0 uint32, localAddress0 uint32, localAddress1 uint32, localAddress2 uint32, localAddress3 uint32, localAddress4 uint32, localAddress5 uint32, localAddress6 uint32, localAddress7 uint32, localAddress8 uint32, localAddress9 uint32, localAddress10 uint32, localAddress11 uint32, result *cm.Result[network.ErrorCode, struct{}, network.ErrorCode]) @@ -377,7 +377,7 @@ func (self UDPSocket) Stream(remoteAddress cm.Option[network.IPSocketAddress]) ( return } -//go:wasmimport wasi:sockets/udp@0.2.0 [method]udp-socket.stream +//go:wasmimport wasi:sockets/udp@0.2.1 [method]udp-socket.stream //go:noescape func wasmimport_UDPSocketStream(self0 uint32, remoteAddress0 uint32, remoteAddress1 uint32, remoteAddress2 uint32, remoteAddress3 uint32, remoteAddress4 uint32, remoteAddress5 uint32, remoteAddress6 uint32, remoteAddress7 uint32, remoteAddress8 uint32, remoteAddress9 uint32, remoteAddress10 uint32, remoteAddress11 uint32, remoteAddress12 uint32, result *cm.Result[TupleIncomingDatagramStreamOutgoingDatagramStreamShape, cm.Tuple[IncomingDatagramStream, OutgoingDatagramStream], network.ErrorCode]) @@ -398,7 +398,7 @@ func (self UDPSocket) Subscribe() (result poll.Pollable) { return } -//go:wasmimport wasi:sockets/udp@0.2.0 [method]udp-socket.subscribe +//go:wasmimport wasi:sockets/udp@0.2.1 [method]udp-socket.subscribe //go:noescape func wasmimport_UDPSocketSubscribe(self0 uint32) (result0 uint32) @@ -420,11 +420,11 @@ func (self UDPSocket) UnicastHopLimit() (result cm.Result[uint8, uint8, network. return } -//go:wasmimport wasi:sockets/udp@0.2.0 [method]udp-socket.unicast-hop-limit +//go:wasmimport wasi:sockets/udp@0.2.1 [method]udp-socket.unicast-hop-limit //go:noescape func wasmimport_UDPSocketUnicastHopLimit(self0 uint32, result *cm.Result[uint8, uint8, network.ErrorCode]) -// IncomingDatagramStream represents the imported resource "wasi:sockets/udp@0.2.0#incoming-datagram-stream". +// IncomingDatagramStream represents the imported resource "wasi:sockets/udp@0.2.1#incoming-datagram-stream". // // resource incoming-datagram-stream type IncomingDatagramStream cm.Resource @@ -440,7 +440,7 @@ func (self IncomingDatagramStream) ResourceDrop() { return } -//go:wasmimport wasi:sockets/udp@0.2.0 [resource-drop]incoming-datagram-stream +//go:wasmimport wasi:sockets/udp@0.2.1 [resource-drop]incoming-datagram-stream //go:noescape func wasmimport_IncomingDatagramStreamResourceDrop(self0 uint32) @@ -482,7 +482,7 @@ func (self IncomingDatagramStream) Receive(maxResults uint64) (result cm.Result[ return } -//go:wasmimport wasi:sockets/udp@0.2.0 [method]incoming-datagram-stream.receive +//go:wasmimport wasi:sockets/udp@0.2.1 [method]incoming-datagram-stream.receive //go:noescape func wasmimport_IncomingDatagramStreamReceive(self0 uint32, maxResults0 uint64, result *cm.Result[cm.List[IncomingDatagram], cm.List[IncomingDatagram], network.ErrorCode]) @@ -503,11 +503,11 @@ func (self IncomingDatagramStream) Subscribe() (result poll.Pollable) { return } -//go:wasmimport wasi:sockets/udp@0.2.0 [method]incoming-datagram-stream.subscribe +//go:wasmimport wasi:sockets/udp@0.2.1 [method]incoming-datagram-stream.subscribe //go:noescape func wasmimport_IncomingDatagramStreamSubscribe(self0 uint32) (result0 uint32) -// OutgoingDatagramStream represents the imported resource "wasi:sockets/udp@0.2.0#outgoing-datagram-stream". +// OutgoingDatagramStream represents the imported resource "wasi:sockets/udp@0.2.1#outgoing-datagram-stream". // // resource outgoing-datagram-stream type OutgoingDatagramStream cm.Resource @@ -523,7 +523,7 @@ func (self OutgoingDatagramStream) ResourceDrop() { return } -//go:wasmimport wasi:sockets/udp@0.2.0 [resource-drop]outgoing-datagram-stream +//go:wasmimport wasi:sockets/udp@0.2.1 [resource-drop]outgoing-datagram-stream //go:noescape func wasmimport_OutgoingDatagramStreamResourceDrop(self0 uint32) @@ -550,7 +550,7 @@ func (self OutgoingDatagramStream) CheckSend() (result cm.Result[uint64, uint64, return } -//go:wasmimport wasi:sockets/udp@0.2.0 [method]outgoing-datagram-stream.check-send +//go:wasmimport wasi:sockets/udp@0.2.1 [method]outgoing-datagram-stream.check-send //go:noescape func wasmimport_OutgoingDatagramStreamCheckSend(self0 uint32, result *cm.Result[uint64, uint64, network.ErrorCode]) @@ -615,7 +615,7 @@ func (self OutgoingDatagramStream) Send(datagrams cm.List[OutgoingDatagram]) (re return } -//go:wasmimport wasi:sockets/udp@0.2.0 [method]outgoing-datagram-stream.send +//go:wasmimport wasi:sockets/udp@0.2.1 [method]outgoing-datagram-stream.send //go:noescape func wasmimport_OutgoingDatagramStreamSend(self0 uint32, datagrams0 *OutgoingDatagram, datagrams1 uint32, result *cm.Result[uint64, uint64, network.ErrorCode]) @@ -636,6 +636,6 @@ func (self OutgoingDatagramStream) Subscribe() (result poll.Pollable) { return } -//go:wasmimport wasi:sockets/udp@0.2.0 [method]outgoing-datagram-stream.subscribe +//go:wasmimport wasi:sockets/udp@0.2.1 [method]outgoing-datagram-stream.subscribe //go:noescape func wasmimport_OutgoingDatagramStreamSubscribe(self0 uint32) (result0 uint32) diff --git a/tests/go/wasi/bindings/west-test/leftpad/leftpad/abi.go b/tests/go/wasi/bindings/west-test/leftpad/leftpad/abi.go new file mode 100644 index 0000000..c6d22b9 --- /dev/null +++ b/tests/go/wasi/bindings/west-test/leftpad/leftpad/abi.go @@ -0,0 +1,13 @@ +// Code generated by wit-bindgen-go. DO NOT EDIT. + +package leftpad + +import ( + "github.com/rvolosatovs/west/tests/go/wasi/bindings/wasi/io/streams" + "unsafe" +) + +// StreamErrorShape is used for storage in variant or result types. +type StreamErrorShape struct { + shape [unsafe.Sizeof(streams.StreamError{})]byte +} diff --git a/tests/go/wasi/bindings/west-test/leftpad/leftpad/empty.s b/tests/go/wasi/bindings/west-test/leftpad/leftpad/empty.s new file mode 100644 index 0000000..5444f20 --- /dev/null +++ b/tests/go/wasi/bindings/west-test/leftpad/leftpad/empty.s @@ -0,0 +1,3 @@ +// This file exists for testing this package without WebAssembly, +// allowing empty function bodies with a //go:wasmimport directive. +// See https://pkg.go.dev/cmd/compile for more information. diff --git a/tests/go/wasi/bindings/west-test/leftpad/leftpad/leftpad.wit.go b/tests/go/wasi/bindings/west-test/leftpad/leftpad/leftpad.wit.go new file mode 100644 index 0000000..313492e --- /dev/null +++ b/tests/go/wasi/bindings/west-test/leftpad/leftpad/leftpad.wit.go @@ -0,0 +1,28 @@ +// Code generated by wit-bindgen-go. DO NOT EDIT. + +// Package leftpad represents the imported interface "west-test:leftpad/leftpad". +package leftpad + +import ( + "github.com/bytecodealliance/wasm-tools-go/cm" + "github.com/rvolosatovs/west/tests/go/wasi/bindings/wasi/io/streams" +) + +// Leftpad represents the imported function "leftpad". +// +// leftpad: func(in: input-stream, out: borrow, len: u64, c: char) +// -> result<_, stream-error> +// +//go:nosplit +func Leftpad(in streams.InputStream, out streams.OutputStream, len_ uint64, c rune) (result cm.Result[streams.StreamError, struct{}, streams.StreamError]) { + in0 := cm.Reinterpret[uint32](in) + out0 := cm.Reinterpret[uint32](out) + len0 := (uint64)(len_) + c0 := (uint32)(c) + wasmimport_Leftpad((uint32)(in0), (uint32)(out0), (uint64)(len0), (uint32)(c0), &result) + return +} + +//go:wasmimport west-test:leftpad/leftpad leftpad +//go:noescape +func wasmimport_Leftpad(in0 uint32, out0 uint32, len0 uint64, c0 uint32, result *cm.Result[streams.StreamError, struct{}, streams.StreamError]) diff --git a/tests/go/wasi/wasi.go b/tests/go/wasi/wasi.go index 9b18152..4a37ec4 100644 --- a/tests/go/wasi/wasi.go +++ b/tests/go/wasi/wasi.go @@ -1,14 +1,16 @@ -//go:generate go run github.com/ydnar/wasm-tools-go/cmd/wit-bindgen-go@v0.1.5 generate -w service -o bindings ./wit +//go:generate go run github.com/bytecodealliance/wasm-tools-go/cmd/wit-bindgen-go generate -w service -o bindings ./wit package wasi import ( "log/slog" - "unsafe" + "strconv" + "github.com/bytecodealliance/wasm-tools-go/cm" incominghandler "github.com/rvolosatovs/west/tests/go/wasi/bindings/wasi/http/incoming-handler" "github.com/rvolosatovs/west/tests/go/wasi/bindings/wasi/http/types" - "github.com/ydnar/wasm-tools-go/cm" + "github.com/rvolosatovs/west/tests/go/wasi/bindings/west-test/fib/fib" + "github.com/rvolosatovs/west/tests/go/wasi/bindings/west-test/leftpad/leftpad" ) func init() { @@ -24,38 +26,76 @@ func ptr[T any](v T) *T { } func handle(req types.IncomingRequest, out types.ResponseOutparam) *types.ErrorCode { + switch meth := req.Method(); meth { + case types.MethodPost(): + default: + slog.Debug("invalid method", "method", meth) + return ptr(types.ErrorCodeHTTPRequestMethodInvalid()) + } + q := req.PathWithQuery() + if q.None() { + slog.Debug("missing path") + return ptr(types.ErrorCodeHTTPRequestURIInvalid()) + } + n, err := strconv.ParseUint(*q.Some(), 10, 32) + if err != nil { + slog.Debug("failed to parse uint32 from path", "err", err) + return ptr(types.ErrorCodeHTTPRequestURIInvalid()) + } + + reqBodyRes := req.Consume() + if reqBodyRes.IsErr() { + slog.Debug("failed to consume request body") + return ptr(types.ErrorCodeInternalError(cm.Some("failed to consume request body"))) + } + reqBody := reqBodyRes.OK() + reqBodyStreamRes := reqBody.Stream() + if reqBodyStreamRes.IsErr() { + slog.Debug("failed to get request body stream") + return ptr(types.ErrorCodeInternalError(cm.Some("failed to get request body stream"))) + } + reqBodyStream := reqBodyStreamRes.OK() + slog.Debug("constructing new response") - res := types.NewOutgoingResponse(req.Headers()) + resp := types.NewOutgoingResponse(req.Headers()) slog.Debug("getting response body") - body := res.Body() - if body.IsErr() { - slog.Debug("failed to get body") - return ptr(types.ErrorCodeInternalError(cm.Some("failed to get body"))) + respBodyRes := resp.Body() + if respBodyRes.IsErr() { + slog.Debug("failed to get response body") + return ptr(types.ErrorCodeInternalError(cm.Some("failed to get response body"))) } - bodyOut := body.OK() + respBody := respBodyRes.OK() slog.Debug("getting response body stream") - bodyWrite := bodyOut.Write() - if bodyWrite.IsErr() { + respBodyStreamRes := respBody.Write() + if respBodyStreamRes.IsErr() { slog.Debug("failed to get response body stream") return ptr(types.ErrorCodeInternalError(cm.Some("failed to get response body stream"))) } + respBodyStream := respBodyStreamRes.OK() slog.Debug("setting response outparam") - types.ResponseOutparamSet(out, cm.OK[cm.Result[types.ErrorCodeShape, types.OutgoingResponse, types.ErrorCode]](res)) - stream := bodyWrite.OK() - s := "foo bar baz" - writeRes := stream.BlockingWriteAndFlush(cm.NewList(unsafe.StringData(s), uint(len(s)))) - if writeRes.IsErr() { - slog.Error("failed to write to stream", "err", writeRes.Err()) + types.ResponseOutparamSet(out, cm.OK[cm.Result[types.ErrorCodeShape, types.OutgoingResponse, types.ErrorCode]](resp)) + + slog.Debug("calculating Fibonacci number", "n", n) + count := fib.Fib(uint32(n)) + + slog.Debug("invoking leftpad", "count", count) + padRes := leftpad.Leftpad(*reqBodyStream, *respBodyStream, count, '🧭') + if padRes.IsErr() { + slog.Debug("failed to left-pad stream", "err", padRes.Err().LastOperationFailed().ToDebugString()) + return nil + } + flushRes := respBodyStream.Flush() + if flushRes.IsErr() { + slog.Debug("failed to flush stream", "err", flushRes.Err().LastOperationFailed().ToDebugString()) return nil } - slog.Debug("dropping body stream") - stream.ResourceDrop() + respBodyStream.ResourceDrop() slog.Debug("finishing outgoing body") - finishRes := types.OutgoingBodyFinish(*bodyOut, cm.None[types.Fields]()) + finishRes := types.OutgoingBodyFinish(*respBody, cm.None[types.Fields]()) if finishRes.IsErr() { slog.Error("failed to finish outgoing body", "err", finishRes.Err()) return nil diff --git a/tests/go/wasi/wasi_test.go b/tests/go/wasi/wasi_test.go index 5a1e7d9..1ac371a 100644 --- a/tests/go/wasi/wasi_test.go +++ b/tests/go/wasi/wasi_test.go @@ -1,21 +1,51 @@ -//go:generate go run ../../../cmd/west-bindgen-go +//go:generate go run github.com/rvolosatovs/west/cmd/west-bindgen-go +//go:generate cargo build -p wasi-test-component --target wasm32-wasip1 +//go:generate cp ../../../target/wasm32-wasip1/debug/wasi_test_component.wasm component.wasm package wasi_test import ( + _ "embed" + "log" + "log/slog" + "os" "testing" "unsafe" + "github.com/bytecodealliance/wasm-tools-go/cm" west "github.com/rvolosatovs/west" _ "github.com/rvolosatovs/west/bindings" testtypes "github.com/rvolosatovs/west/bindings/wasi/http/types" - httptest "github.com/rvolosatovs/west/bindings/west/test/http-test" + teststreams "github.com/rvolosatovs/west/bindings/wasi/io/streams" + httpext "github.com/rvolosatovs/west/bindings/wasiext/http/ext" incominghandler "github.com/rvolosatovs/west/tests/go/wasi/bindings/wasi/http/incoming-handler" "github.com/rvolosatovs/west/tests/go/wasi/bindings/wasi/http/types" "github.com/stretchr/testify/assert" - "github.com/ydnar/wasm-tools-go/cm" ) +//go:embed component.wasm +var component []byte + +func init() { + log.SetFlags(0) + slog.SetDefault(slog.New(slog.NewTextHandler(os.Stderr, &slog.HandlerOptions{ + Level: slog.LevelDebug, ReplaceAttr: func(groups []string, a slog.Attr) slog.Attr { + if a.Key == slog.TimeKey { + return slog.Attr{} + } + return a + }, + }))) + + instance, err := west.NewInstance(&west.Config{ + Wasm: component, + }) + if err != nil { + log.Fatalf("failed to construct new instance: %s", err) + } + west.SetInstance(instance) +} + func TestIncomingHandler(t *testing.T) { west.RunTest(t, func() { headers := testtypes.NewFields() @@ -48,22 +78,45 @@ func TestIncomingHandler(t *testing.T) { ), ) req := testtypes.NewOutgoingRequest(headers) - req.SetPathWithQuery(cm.Some("test")) - req.SetMethod(testtypes.MethodGet()) - out := httptest.NewResponseOutparam() + req.SetPathWithQuery(cm.Some("5")) + req.SetMethod(testtypes.MethodPost()) + reqBodyRes := req.Body() + if !assert.Nil(t, reqBodyRes.Err()) { + t.FailNow() + } + reqBody := reqBodyRes.OK() + reqStreamRes := reqBody.Write() + if !assert.Nil(t, reqStreamRes.Err()) { + t.FailNow() + } + reqStream := reqStreamRes.OK() + writeRes := reqStream.BlockingWriteAndFlush(cm.NewList( + unsafe.SliceData([]byte("foo bar baz")), + 11, + )) + if !assert.Nil(t, writeRes.Err()) { + t.FailNow() + } + reqStream.ResourceDrop() + reqBodyFinishRes := testtypes.OutgoingBodyFinish(*reqBody, cm.None[testtypes.Fields]()) + if !assert.Nil(t, reqBodyFinishRes.Err()) { + t.FailNow() + } + + out := httpext.NewResponseOutparam() incominghandler.Exports.Handle( - types.IncomingRequest(httptest.NewIncomingRequest(req)), + types.IncomingRequest(httpext.NewIncomingRequest(req)), types.ResponseOutparam(out.F0), ) out.F1.Subscribe().Block() respOptResRes := out.F1.Get() respResRes := respOptResRes.Some() - if !assert.NotNil(t, respResRes) { + if !assert.NotNil(t, respResRes) || !assert.Nil(t, respResRes.Err()) { t.FailNow() } respRes := respResRes.OK() - if !assert.NotNil(t, respRes) || !assert.Nil(t, respRes.Err()) { - t.FailNow() + if !assert.Nil(t, respRes.Err()) { + t.Fatal(*respRes.Err()) } resp := respRes.OK() assert.Equal(t, testtypes.StatusCode(200), resp.Status()) @@ -82,21 +135,33 @@ func TestIncomingHandler(t *testing.T) { }, }, hs) bodyRes := resp.Consume() - body := bodyRes.OK() - if !assert.NotNil(t, body) { + if !assert.Nil(t, bodyRes.Err()) { t.FailNow() } + + body := bodyRes.OK() bodyStreamRes := body.Stream() - bodyStream := bodyStreamRes.OK() - if !assert.NotNil(t, bodyStream) { + if !assert.Nil(t, bodyStreamRes.Err()) { t.FailNow() } - bufRes := bodyStream.BlockingRead(4096) - buf := bufRes.OK() - if !assert.NotNil(t, buf) { - t.FailNow() + + bodyStream := bodyStreamRes.OK() + var buf []byte + for { + bufRes := bodyStream.BlockingRead(4096) + if bufRes.IsErr() && *bufRes.Err() == teststreams.StreamErrorClosed() { + break + } + if !assert.Nil(t, bufRes.Err()) { + if !assert.False(t, bufRes.Err().Closed()) { + t.FailNow() + } else { + t.Fatal(*bufRes.Err().LastOperationFailed()) + } + } + buf = append(buf, bufRes.OK().Slice()...) } - assert.Equal(t, []byte("foo bar baz"), buf.Slice()) + assert.Equal(t, []byte("🧭🧭🧭🧭🧭foo bar baz"), buf) bodyStream.ResourceDrop() }) } diff --git a/tests/go/wasi/wit/app.wit b/tests/go/wasi/wit/app.wit index 8448761..c753185 100644 --- a/tests/go/wasi/wit/app.wit +++ b/tests/go/wasi/wit/app.wit @@ -1,10 +1,11 @@ package west-test:wasi; world service { - export wasi:http/incoming-handler@0.2.0; + export wasi:http/incoming-handler@0.2.1; // Import all CLI interfaces, which are used by Go libraries - include wasi:cli/imports@0.2.0; + include wasi:cli/imports@0.2.1; - import west-test:fib/fib; + include west-test:fib/guest; + include west-test:leftpad/guest; } diff --git a/tests/go/wasi/wit/deps.lock b/tests/go/wasi/wit/deps.lock index 853fd59..b503d16 100644 --- a/tests/go/wasi/wit/deps.lock +++ b/tests/go/wasi/wit/deps.lock @@ -1,34 +1,40 @@ [cli] -sha256 = "285865a31d777181b075f39e92bcfe59c89cd6bacce660be1b9a627646956258" -sha512 = "da2622210a9e3eea82b99f1a5b8a44ce5443d009cb943f7bca0bf9cf4360829b289913d7ee727c011f0f72994ea7dc8e661ebcc0a6b34b587297d80cd9b3f7e8" +sha256 = "1de50b8e6940e73110cda10b7f90ca87a8fea886f0fa36c748f96dc70671ee38" +sha512 = "bbb6cd3e7b4d3237b6af9bfbb2633ccd2c4ea2a4f37b8c033255c7e0c1cb037be7f22ec1f8ca792cc8ec1942199582943979e646b4b272b85dcff7654eac51d0" [clocks] -sha256 = "468b4d12892fe926b8eb5d398dbf579d566c93231fa44f415440572c695b7613" -sha512 = "e6b53a07221f1413953c9797c68f08b815fdaebf66419bbc1ea3e8b7dece73731062693634731f311a03957b268cf9cc509c518bd15e513c318aa04a8459b93a" +sha256 = "ea9d69ee803bc176e23e5268f5e24a2ac485dd1f62a0ab4c748e9d3f901f576f" +sha512 = "5efc22927c46cd56c41e5549ec775561c7fac2ea0d365abc0b55396d9475a7c9f984077a81f84a44a726f1c008fd2fadbffffa4fa53ecd5fbfd05afd379ab428" [fib] -path = "../../../../../tests/wit/fib" +path = "../../../wit/fib" sha256 = "a818ecd4b5f4e3a092d747d9e69e1c706bd8ac3950dced24d8ae78f96bd5e851" sha512 = "ad9795f9300ae1f7ab8f9dd56da5db7dafc3c15476d6c1768a56a968d9a0aeae435b9e8836405a9673b9a68e3eea8b653d6e19b4b90aba047646f3839712b5b4" [filesystem] -sha256 = "498c465cfd04587db40f970fff2185daa597d074c20b68a8bcbae558f261499b" -sha512 = "ead452f9b7bfb88593a502ec00d76d4228003d51c40fd0408aebc32d35c94673551b00230d730873361567cc209ec218c41fb4e95bad194268592c49e7964347" +sha256 = "cfe8c420e8b857de612ae2a3336680dae16b95c93c8ba3a6ff05b21210966740" +sha512 = "3c00c5544a58658e3e8025677091685286027fd49f37abf198c30b4e83b9e68f19723975aaa98794fba9f425ae9ef4f3dc0f5b9cf59203b5ecfaadf62b296f9a" [http] -url = "https://github.com/WebAssembly/wasi-http/archive/v0.2.0.tar.gz" -sha256 = "8f44402bde16c48e28c47dc53eab0b26af5b3b3482a1852cf77673e0880ba1c1" -sha512 = "760695f9a25c25bf75a25b731cb21c3bda9e288e450edda823324ecbc73d5d798bbb5de2edad999566980836f037463ee9e57d61789d04b3f3e381475b1a9a0f" +url = "https://github.com/WebAssembly/wasi-http/archive/v0.2.1.tar.gz" +sha256 = "ff21e05571af02488371bebc9cb674e30e0613eda22e3c1d8e1aba36cdff5ee8" +sha512 = "1825b56f1718e822acf1b49929ead8f6493752b1d3524ce0974c3acdf656af2fc3fe5c8456b71ffab44583bc3ae7061d5a285d8a7203fcae949d44b3d81e2f2b" deps = ["cli", "clocks", "filesystem", "io", "random", "sockets"] [io] -sha256 = "7210e5653539a15478f894d4da24cc69d61924cbcba21d2804d69314a88e5a4c" -sha512 = "49184a1b0945a889abd52d25271172ed3dc2db6968fcdddb1bab7ee0081f4a3eeee0977ad2291126a37631c0d86eeea75d822fa8af224c422134500bf9f0f2bb" +sha256 = "2a74bd811adc46b5a0f19827ddbde89870e52b17615f4d0873f06fd977250caf" +sha512 = "94624f00c66e66203592cee820f80b1ba91ecdb71f682c154f25eaf71f8d8954197dcb64503bc21e72ed5e812af7eae876df47b7eb727b02db3a74a7ce0aefca" + +[leftpad] +path = "../../../wit/leftpad" +sha256 = "e782b0bd33116f3831dbd131761bc457ec9064037d10e19ffe8e2f70e6dc73a4" +sha512 = "47c1ec78b97c0e170c52397048d360cf2f3dbaf336b9ba3c7045407ef5ec7ecac208cbc06b572c25f005aebcd9230bf20d4c99d54e8576e7327f5c0e53e29e72" +deps = ["io"] [random] -sha256 = "7371d03c037d924caba2587fb2e7c5773a0d3c5fcecbf7971e0e0ba57973c53d" -sha512 = "964c4e8925a53078e4d94ba907b54f89a0b7e154f46823a505391471466c17f53c8692682e5c85771712acd88b348686173fc07c53a3cfe3d301b8cd8ddd0de4" +sha256 = "9e2d5056186f81b2e7f96bc97d2babd0341840f6abb4f170449b70992f1b598f" +sha512 = "67bf41d8d5d4b7af084124ee85196585225785969059f59e2f9ddb77ac1a8095cfe811ae29d076aac817418fa01064d7b9fbc0233930bace680758eeb21e36f8" [sockets] -sha256 = "622bd28bbeb43736375dc02bd003fd3a016ff8ee91e14bab488325c6b38bf966" -sha512 = "5a63c1f36de0c4548e1d2297bdbededb28721cbad94ef7825c469eae29d7451c97e00b4c1d6730ee1ec0c4a5aac922961a2795762d4a0c3bb54e30a391a84bae" +sha256 = "4c361137a7e61e8b9a73da2a0899dd9ad1a0c2dfee7d310cf168704c57b7a07c" +sha512 = "348b4ef381f57aec23d48537df8b69ab8963587dcb056e94c4cd5657e217677a4ee2a545868a5c829d2334cc6b8b0a61d3e72797999f44d78553fbd3a73c5b8d" diff --git a/tests/go/wasi/wit/deps.toml b/tests/go/wasi/wit/deps.toml index a871561..0262433 100644 --- a/tests/go/wasi/wit/deps.toml +++ b/tests/go/wasi/wit/deps.toml @@ -1,2 +1,3 @@ -fib = "../../../../../tests/wit/fib" -http = "https://github.com/WebAssembly/wasi-http/archive/v0.2.0.tar.gz" +fib = "../../../wit/fib" +leftpad = "../../../wit/leftpad" +http = "https://github.com/WebAssembly/wasi-http/archive/v0.2.1.tar.gz" diff --git a/tests/go/wasi/wit/deps/cli/command.wit b/tests/go/wasi/wit/deps/cli/command.wit index d8005bd..dc064a3 100644 --- a/tests/go/wasi/wit/deps/cli/command.wit +++ b/tests/go/wasi/wit/deps/cli/command.wit @@ -1,7 +1,10 @@ -package wasi:cli@0.2.0; +package wasi:cli@0.2.1; +@since(version = 0.2.0) world command { + @since(version = 0.2.0) include imports; + @since(version = 0.2.0) export run; } diff --git a/tests/go/wasi/wit/deps/cli/environment.wit b/tests/go/wasi/wit/deps/cli/environment.wit index 7006523..2f449bd 100644 --- a/tests/go/wasi/wit/deps/cli/environment.wit +++ b/tests/go/wasi/wit/deps/cli/environment.wit @@ -1,3 +1,4 @@ +@since(version = 0.2.0) interface environment { /// Get the POSIX-style environment variables. /// @@ -7,12 +8,15 @@ interface environment { /// Morally, these are a value import, but until value imports are available /// in the component model, this import function should return the same /// values each time it is called. + @since(version = 0.2.0) get-environment: func() -> list>; /// Get the POSIX-style arguments to the program. + @since(version = 0.2.0) get-arguments: func() -> list; /// Return a path that programs should use as their initial current working /// directory, interpreting `.` as shorthand for this. + @since(version = 0.2.0) initial-cwd: func() -> option; } diff --git a/tests/go/wasi/wit/deps/cli/exit.wit b/tests/go/wasi/wit/deps/cli/exit.wit index d0c2b82..427935c 100644 --- a/tests/go/wasi/wit/deps/cli/exit.wit +++ b/tests/go/wasi/wit/deps/cli/exit.wit @@ -1,4 +1,17 @@ +@since(version = 0.2.0) interface exit { /// Exit the current instance and any linked instances. + @since(version = 0.2.0) exit: func(status: result); + + /// Exit the current instance and any linked instances, reporting the + /// specified status code to the host. + /// + /// The meaning of the code depends on the context, with 0 usually meaning + /// "success", and other values indicating various types of failure. + /// + /// This function does not return; the effect is analogous to a trap, but + /// without the connotation that something bad has happened. + @unstable(feature = cli-exit-with-code) + exit-with-code: func(status-code: u8); } diff --git a/tests/go/wasi/wit/deps/cli/imports.wit b/tests/go/wasi/wit/deps/cli/imports.wit index 083b84a..b8339d3 100644 --- a/tests/go/wasi/wit/deps/cli/imports.wit +++ b/tests/go/wasi/wit/deps/cli/imports.wit @@ -1,20 +1,36 @@ -package wasi:cli@0.2.0; +package wasi:cli@0.2.1; +@since(version = 0.2.0) world imports { - include wasi:clocks/imports@0.2.0; - include wasi:filesystem/imports@0.2.0; - include wasi:sockets/imports@0.2.0; - include wasi:random/imports@0.2.0; - include wasi:io/imports@0.2.0; + @since(version = 0.2.0) + include wasi:clocks/imports@0.2.1; + @since(version = 0.2.0) + include wasi:filesystem/imports@0.2.1; + @since(version = 0.2.0) + include wasi:sockets/imports@0.2.1; + @since(version = 0.2.0) + include wasi:random/imports@0.2.1; + @since(version = 0.2.0) + include wasi:io/imports@0.2.1; + @since(version = 0.2.0) import environment; + @since(version = 0.2.0) import exit; + @since(version = 0.2.0) import stdin; + @since(version = 0.2.0) import stdout; + @since(version = 0.2.0) import stderr; + @since(version = 0.2.0) import terminal-input; + @since(version = 0.2.0) import terminal-output; + @since(version = 0.2.0) import terminal-stdin; + @since(version = 0.2.0) import terminal-stdout; + @since(version = 0.2.0) import terminal-stderr; } diff --git a/tests/go/wasi/wit/deps/cli/run.wit b/tests/go/wasi/wit/deps/cli/run.wit index a70ee8c..655346e 100644 --- a/tests/go/wasi/wit/deps/cli/run.wit +++ b/tests/go/wasi/wit/deps/cli/run.wit @@ -1,4 +1,6 @@ +@since(version = 0.2.0) interface run { /// Run the program. + @since(version = 0.2.0) run: func() -> result; } diff --git a/tests/go/wasi/wit/deps/cli/stdio.wit b/tests/go/wasi/wit/deps/cli/stdio.wit index 31ef35b..d1d26eb 100644 --- a/tests/go/wasi/wit/deps/cli/stdio.wit +++ b/tests/go/wasi/wit/deps/cli/stdio.wit @@ -1,17 +1,26 @@ +@since(version = 0.2.0) interface stdin { - use wasi:io/streams@0.2.0.{input-stream}; + @since(version = 0.2.0) + use wasi:io/streams@0.2.1.{input-stream}; + @since(version = 0.2.0) get-stdin: func() -> input-stream; } +@since(version = 0.2.0) interface stdout { - use wasi:io/streams@0.2.0.{output-stream}; + @since(version = 0.2.0) + use wasi:io/streams@0.2.1.{output-stream}; + @since(version = 0.2.0) get-stdout: func() -> output-stream; } +@since(version = 0.2.0) interface stderr { - use wasi:io/streams@0.2.0.{output-stream}; + @since(version = 0.2.0) + use wasi:io/streams@0.2.1.{output-stream}; + @since(version = 0.2.0) get-stderr: func() -> output-stream; } diff --git a/tests/go/wasi/wit/deps/cli/terminal.wit b/tests/go/wasi/wit/deps/cli/terminal.wit index 38c724e..d305498 100644 --- a/tests/go/wasi/wit/deps/cli/terminal.wit +++ b/tests/go/wasi/wit/deps/cli/terminal.wit @@ -3,8 +3,10 @@ /// In the future, this may include functions for disabling echoing, /// disabling input buffering so that keyboard events are sent through /// immediately, querying supported features, and so on. +@since(version = 0.2.0) interface terminal-input { /// The input side of a terminal. + @since(version = 0.2.0) resource terminal-input; } @@ -13,37 +15,48 @@ interface terminal-input { /// In the future, this may include functions for querying the terminal /// size, being notified of terminal size changes, querying supported /// features, and so on. +@since(version = 0.2.0) interface terminal-output { /// The output side of a terminal. + @since(version = 0.2.0) resource terminal-output; } /// An interface providing an optional `terminal-input` for stdin as a /// link-time authority. +@since(version = 0.2.0) interface terminal-stdin { + @since(version = 0.2.0) use terminal-input.{terminal-input}; /// If stdin is connected to a terminal, return a `terminal-input` handle /// allowing further interaction with it. + @since(version = 0.2.0) get-terminal-stdin: func() -> option; } /// An interface providing an optional `terminal-output` for stdout as a /// link-time authority. +@since(version = 0.2.0) interface terminal-stdout { + @since(version = 0.2.0) use terminal-output.{terminal-output}; /// If stdout is connected to a terminal, return a `terminal-output` handle /// allowing further interaction with it. + @since(version = 0.2.0) get-terminal-stdout: func() -> option; } /// An interface providing an optional `terminal-output` for stderr as a /// link-time authority. +@since(version = 0.2.0) interface terminal-stderr { + @since(version = 0.2.0) use terminal-output.{terminal-output}; /// If stderr is connected to a terminal, return a `terminal-output` handle /// allowing further interaction with it. + @since(version = 0.2.0) get-terminal-stderr: func() -> option; } diff --git a/tests/go/wasi/wit/deps/clocks/monotonic-clock.wit b/tests/go/wasi/wit/deps/clocks/monotonic-clock.wit index 4e4dc3a..3c24840 100644 --- a/tests/go/wasi/wit/deps/clocks/monotonic-clock.wit +++ b/tests/go/wasi/wit/deps/clocks/monotonic-clock.wit @@ -1,4 +1,4 @@ -package wasi:clocks@0.2.0; +package wasi:clocks@0.2.1; /// WASI Monotonic Clock is a clock API intended to let users measure elapsed /// time. /// @@ -7,38 +7,43 @@ package wasi:clocks@0.2.0; /// /// A monotonic clock is a clock which has an unspecified initial value, and /// successive reads of the clock will produce non-decreasing values. -/// -/// It is intended for measuring elapsed time. +@since(version = 0.2.0) interface monotonic-clock { - use wasi:io/poll@0.2.0.{pollable}; + @since(version = 0.2.0) + use wasi:io/poll@0.2.1.{pollable}; /// An instant in time, in nanoseconds. An instant is relative to an /// unspecified initial value, and can only be compared to instances from /// the same monotonic-clock. + @since(version = 0.2.0) type instant = u64; /// A duration of time, in nanoseconds. + @since(version = 0.2.0) type duration = u64; /// Read the current value of the clock. /// /// The clock is monotonic, therefore calling this function repeatedly will /// produce a sequence of non-decreasing values. + @since(version = 0.2.0) now: func() -> instant; /// Query the resolution of the clock. Returns the duration of time /// corresponding to a clock tick. + @since(version = 0.2.0) resolution: func() -> duration; /// Create a `pollable` which will resolve once the specified instant - /// occured. + /// has occurred. + @since(version = 0.2.0) subscribe-instant: func( when: instant, ) -> pollable; - /// Create a `pollable` which will resolve once the given duration has - /// elapsed, starting at the time at which this function was called. - /// occured. + /// Create a `pollable` that will resolve after the specified duration has + /// elapsed from the time this function is invoked. + @since(version = 0.2.0) subscribe-duration: func( when: duration, ) -> pollable; diff --git a/tests/go/wasi/wit/deps/clocks/timezone.wit b/tests/go/wasi/wit/deps/clocks/timezone.wit new file mode 100644 index 0000000..212da66 --- /dev/null +++ b/tests/go/wasi/wit/deps/clocks/timezone.wit @@ -0,0 +1,55 @@ +package wasi:clocks@0.2.1; + +@unstable(feature = clocks-timezone) +interface timezone { + @unstable(feature = clocks-timezone) + use wall-clock.{datetime}; + + /// Return information needed to display the given `datetime`. This includes + /// the UTC offset, the time zone name, and a flag indicating whether + /// daylight saving time is active. + /// + /// If the timezone cannot be determined for the given `datetime`, return a + /// `timezone-display` for `UTC` with a `utc-offset` of 0 and no daylight + /// saving time. + @unstable(feature = clocks-timezone) + display: func(when: datetime) -> timezone-display; + + /// The same as `display`, but only return the UTC offset. + @unstable(feature = clocks-timezone) + utc-offset: func(when: datetime) -> s32; + + /// Information useful for displaying the timezone of a specific `datetime`. + /// + /// This information may vary within a single `timezone` to reflect daylight + /// saving time adjustments. + @unstable(feature = clocks-timezone) + record timezone-display { + /// The number of seconds difference between UTC time and the local + /// time of the timezone. + /// + /// The returned value will always be less than 86400 which is the + /// number of seconds in a day (24*60*60). + /// + /// In implementations that do not expose an actual time zone, this + /// should return 0. + utc-offset: s32, + + /// The abbreviated name of the timezone to display to a user. The name + /// `UTC` indicates Coordinated Universal Time. Otherwise, this should + /// reference local standards for the name of the time zone. + /// + /// In implementations that do not expose an actual time zone, this + /// should be the string `UTC`. + /// + /// In time zones that do not have an applicable name, a formatted + /// representation of the UTC offset may be returned, such as `-04:00`. + name: string, + + /// Whether daylight saving time is active. + /// + /// In implementations that do not expose an actual time zone, this + /// should return false. + in-daylight-saving-time: bool, + } +} diff --git a/tests/go/wasi/wit/deps/clocks/wall-clock.wit b/tests/go/wasi/wit/deps/clocks/wall-clock.wit index 440ca0f..6be069a 100644 --- a/tests/go/wasi/wit/deps/clocks/wall-clock.wit +++ b/tests/go/wasi/wit/deps/clocks/wall-clock.wit @@ -1,4 +1,4 @@ -package wasi:clocks@0.2.0; +package wasi:clocks@0.2.1; /// WASI Wall Clock is a clock API intended to let users query the current /// time. The name "wall" makes an analogy to a "clock on the wall", which /// is not necessarily monotonic as it may be reset. @@ -13,8 +13,10 @@ package wasi:clocks@0.2.0; /// monotonic, making it unsuitable for measuring elapsed time. /// /// It is intended for reporting the current date and time for humans. +@since(version = 0.2.0) interface wall-clock { /// A time and date in seconds plus nanoseconds. + @since(version = 0.2.0) record datetime { seconds: u64, nanoseconds: u32, @@ -33,10 +35,12 @@ interface wall-clock { /// /// [POSIX's Seconds Since the Epoch]: https://pubs.opengroup.org/onlinepubs/9699919799/xrat/V4_xbd_chap04.html#tag_21_04_16 /// [Unix Time]: https://en.wikipedia.org/wiki/Unix_time + @since(version = 0.2.0) now: func() -> datetime; /// Query the resolution of the clock. /// /// The nanoseconds field of the output is always less than 1000000000. + @since(version = 0.2.0) resolution: func() -> datetime; } diff --git a/tests/go/wasi/wit/deps/clocks/world.wit b/tests/go/wasi/wit/deps/clocks/world.wit index c022457..9251ac6 100644 --- a/tests/go/wasi/wit/deps/clocks/world.wit +++ b/tests/go/wasi/wit/deps/clocks/world.wit @@ -1,6 +1,11 @@ -package wasi:clocks@0.2.0; +package wasi:clocks@0.2.1; +@since(version = 0.2.0) world imports { + @since(version = 0.2.0) import monotonic-clock; + @since(version = 0.2.0) import wall-clock; + @unstable(feature = clocks-timezone) + import timezone; } diff --git a/tests/go/wasi/wit/deps/filesystem/preopens.wit b/tests/go/wasi/wit/deps/filesystem/preopens.wit index da801f6..ca2f726 100644 --- a/tests/go/wasi/wit/deps/filesystem/preopens.wit +++ b/tests/go/wasi/wit/deps/filesystem/preopens.wit @@ -1,8 +1,11 @@ -package wasi:filesystem@0.2.0; +package wasi:filesystem@0.2.1; +@since(version = 0.2.0) interface preopens { + @since(version = 0.2.0) use types.{descriptor}; /// Return the set of preopened directories, and their path. + @since(version = 0.2.0) get-directories: func() -> list>; } diff --git a/tests/go/wasi/wit/deps/filesystem/types.wit b/tests/go/wasi/wit/deps/filesystem/types.wit index 11108fc..db3d968 100644 --- a/tests/go/wasi/wit/deps/filesystem/types.wit +++ b/tests/go/wasi/wit/deps/filesystem/types.wit @@ -1,4 +1,4 @@ -package wasi:filesystem@0.2.0; +package wasi:filesystem@0.2.1; /// WASI filesystem is a filesystem API primarily intended to let users run WASI /// programs that access their files on their existing filesystems, without /// significant overhead. @@ -23,16 +23,21 @@ package wasi:filesystem@0.2.0; /// [WASI filesystem path resolution]. /// /// [WASI filesystem path resolution]: https://github.com/WebAssembly/wasi-filesystem/blob/main/path-resolution.md +@since(version = 0.2.0) interface types { - use wasi:io/streams@0.2.0.{input-stream, output-stream, error}; - use wasi:clocks/wall-clock@0.2.0.{datetime}; + @since(version = 0.2.0) + use wasi:io/streams@0.2.1.{input-stream, output-stream, error}; + @since(version = 0.2.0) + use wasi:clocks/wall-clock@0.2.1.{datetime}; /// File size or length of a region within a file. + @since(version = 0.2.0) type filesize = u64; /// The type of a filesystem object referenced by a descriptor. /// /// Note: This was called `filetype` in earlier versions of WASI. + @since(version = 0.2.0) enum descriptor-type { /// The type of the descriptor or file is unknown or is different from /// any of the other types specified. @@ -56,6 +61,7 @@ interface types { /// Descriptor flags. /// /// Note: This was called `fdflags` in earlier versions of WASI. + @since(version = 0.2.0) flags descriptor-flags { /// Read mode: Data can be read. read, @@ -77,7 +83,7 @@ interface types { /// WASI. At this time, it should be interpreted as a request, and not a /// requirement. data-integrity-sync, - /// Requests that reads be performed at the same level of integrety + /// Requests that reads be performed at the same level of integrity /// requested for writes. This is similar to `O_RSYNC` in POSIX. /// /// The precise semantics of this operation have not yet been defined for @@ -99,6 +105,7 @@ interface types { /// File attributes. /// /// Note: This was called `filestat` in earlier versions of WASI. + @since(version = 0.2.0) record descriptor-stat { /// File type. %type: descriptor-type, @@ -125,6 +132,7 @@ interface types { } /// Flags determining the method of how paths are resolved. + @since(version = 0.2.0) flags path-flags { /// As long as the resolved path corresponds to a symbolic link, it is /// expanded. @@ -132,6 +140,7 @@ interface types { } /// Open flags used by `open-at`. + @since(version = 0.2.0) flags open-flags { /// Create file if it does not exist, similar to `O_CREAT` in POSIX. create, @@ -144,9 +153,11 @@ interface types { } /// Number of hard links to an inode. + @since(version = 0.2.0) type link-count = u64; /// When setting a timestamp, this gives the value to set it to. + @since(version = 0.2.0) variant new-timestamp { /// Leave the timestamp set to its previous value. no-change, @@ -248,6 +259,7 @@ interface types { } /// File or memory access pattern advisory information. + @since(version = 0.2.0) enum advice { /// The application has no advice to give on its behavior with respect /// to the specified data. @@ -271,6 +283,7 @@ interface types { /// A 128-bit hash value, split into parts because wasm doesn't have a /// 128-bit integer type. + @since(version = 0.2.0) record metadata-hash-value { /// 64 bits of a 128-bit hash value. lower: u64, @@ -281,6 +294,7 @@ interface types { /// A descriptor is a reference to a filesystem object, which may be a file, /// directory, named pipe, special file, or other object on which filesystem /// calls may be made. + @since(version = 0.2.0) resource descriptor { /// Return a stream for reading from a file, if available. /// @@ -290,6 +304,7 @@ interface types { /// file and they do not interfere with each other. /// /// Note: This allows using `read-stream`, which is similar to `read` in POSIX. + @since(version = 0.2.0) read-via-stream: func( /// The offset within the file at which to start reading. offset: filesize, @@ -301,6 +316,7 @@ interface types { /// /// Note: This allows using `write-stream`, which is similar to `write` in /// POSIX. + @since(version = 0.2.0) write-via-stream: func( /// The offset within the file at which to start writing. offset: filesize, @@ -312,11 +328,13 @@ interface types { /// /// Note: This allows using `write-stream`, which is similar to `write` with /// `O_APPEND` in in POSIX. + @since(version = 0.2.0) append-via-stream: func() -> result; /// Provide file advisory information on a descriptor. /// /// This is similar to `posix_fadvise` in POSIX. + @since(version = 0.2.0) advise: func( /// The offset within the file to which the advisory applies. offset: filesize, @@ -332,6 +350,7 @@ interface types { /// opened for writing. /// /// Note: This is similar to `fdatasync` in POSIX. + @since(version = 0.2.0) sync-data: func() -> result<_, error-code>; /// Get flags associated with a descriptor. @@ -340,6 +359,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.2.0) get-flags: func() -> result; /// Get the dynamic type of a descriptor. @@ -352,12 +372,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.2.0) get-type: 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.2.0) set-size: func(size: filesize) -> result<_, error-code>; /// Adjust the timestamps of an open file or directory. @@ -365,6 +387,7 @@ interface types { /// Note: This is similar to `futimens` in POSIX. /// /// Note: This was called `fd_filestat_set_times` in earlier versions of WASI. + @since(version = 0.2.0) set-times: func( /// The desired values of the data access timestamp. data-access-timestamp: new-timestamp, @@ -383,6 +406,7 @@ interface types { /// In the future, this may change to return a `stream`. /// /// Note: This is similar to `pread` in POSIX. + @since(version = 0.2.0) read: func( /// The maximum number of bytes to read. length: filesize, @@ -399,6 +423,7 @@ interface types { /// In the future, this may change to take a `stream`. /// /// Note: This is similar to `pwrite` in POSIX. + @since(version = 0.2.0) write: func( /// Data to write buffer: list, @@ -415,6 +440,7 @@ interface types { /// This always returns a new stream which starts at the beginning of the /// directory. Multiple streams may be active on the same directory, and they /// do not interfere with each other. + @since(version = 0.2.0) read-directory: func() -> result; /// Synchronize the data and metadata of a file to disk. @@ -423,11 +449,13 @@ interface types { /// opened for writing. /// /// Note: This is similar to `fsync` in POSIX. + @since(version = 0.2.0) sync: func() -> result<_, error-code>; /// Create a directory. /// /// Note: This is similar to `mkdirat` in POSIX. + @since(version = 0.2.0) create-directory-at: func( /// The relative path at which to create the directory. path: string, @@ -442,6 +470,7 @@ interface types { /// modified, use `metadata-hash`. /// /// Note: This was called `fd_filestat_get` in earlier versions of WASI. + @since(version = 0.2.0) stat: func() -> result; /// Return the attributes of a file or directory. @@ -451,6 +480,7 @@ interface types { /// discussion of alternatives. /// /// Note: This was called `path_filestat_get` in earlier versions of WASI. + @since(version = 0.2.0) stat-at: func( /// Flags determining the method of how the path is resolved. path-flags: path-flags, @@ -464,6 +494,7 @@ interface types { /// /// Note: This was called `path_filestat_set_times` in earlier versions of /// WASI. + @since(version = 0.2.0) set-times-at: func( /// Flags determining the method of how the path is resolved. path-flags: path-flags, @@ -478,6 +509,7 @@ interface types { /// Create a hard link. /// /// Note: This is similar to `linkat` in POSIX. + @since(version = 0.2.0) link-at: func( /// Flags determining the method of how the path is resolved. old-path-flags: path-flags, @@ -507,6 +539,7 @@ interface types { /// `error-code::read-only`. /// /// Note: This is similar to `openat` in POSIX. + @since(version = 0.2.0) open-at: func( /// Flags determining the method of how the path is resolved. path-flags: path-flags, @@ -524,6 +557,7 @@ interface types { /// filesystem, this function fails with `error-code::not-permitted`. /// /// Note: This is similar to `readlinkat` in POSIX. + @since(version = 0.2.0) readlink-at: func( /// The relative path of the symbolic link from which to read. path: string, @@ -534,6 +568,7 @@ interface types { /// Return `error-code::not-empty` if the directory is not empty. /// /// Note: This is similar to `unlinkat(fd, path, AT_REMOVEDIR)` in POSIX. + @since(version = 0.2.0) remove-directory-at: func( /// The relative path to a directory to remove. path: string, @@ -542,6 +577,7 @@ interface types { /// Rename a filesystem object. /// /// Note: This is similar to `renameat` in POSIX. + @since(version = 0.2.0) rename-at: func( /// The relative source path of the file or directory to rename. old-path: string, @@ -557,6 +593,7 @@ interface types { /// `error-code::not-permitted`. /// /// Note: This is similar to `symlinkat` in POSIX. + @since(version = 0.2.0) symlink-at: func( /// The contents of the symbolic link. old-path: string, @@ -568,6 +605,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.2.0) unlink-file-at: func( /// The relative path to a file to unlink. path: string, @@ -579,6 +617,7 @@ interface types { /// same device (`st_dev`) and inode (`st_ino` or `d_ino`) numbers. /// wasi-filesystem does not expose device and inode numbers, so this function /// may be used instead. + @since(version = 0.2.0) is-same-object: func(other: borrow) -> bool; /// Return a hash of the metadata associated with a filesystem object referred @@ -600,12 +639,14 @@ interface types { /// computed hash. /// /// However, none of these is required. + @since(version = 0.2.0) metadata-hash: 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.2.0) metadata-hash-at: func( /// Flags determining the method of how the path is resolved. path-flags: path-flags, @@ -615,8 +656,10 @@ interface types { } /// A stream of directory entries. + @since(version = 0.2.0) resource directory-entry-stream { /// Read a single directory entry from a `directory-entry-stream`. + @since(version = 0.2.0) read-directory-entry: func() -> result, error-code>; } @@ -630,5 +673,6 @@ interface types { /// /// Note that this function is fallible because not all stream-related /// errors are filesystem-related errors. + @since(version = 0.2.0) filesystem-error-code: func(err: borrow) -> option; } diff --git a/tests/go/wasi/wit/deps/filesystem/world.wit b/tests/go/wasi/wit/deps/filesystem/world.wit index 663f579..af0146c 100644 --- a/tests/go/wasi/wit/deps/filesystem/world.wit +++ b/tests/go/wasi/wit/deps/filesystem/world.wit @@ -1,6 +1,9 @@ -package wasi:filesystem@0.2.0; +package wasi:filesystem@0.2.1; +@since(version = 0.2.0) world imports { + @since(version = 0.2.0) import types; + @since(version = 0.2.0) import preopens; } diff --git a/tests/go/wasi/wit/deps/http/handler.wit b/tests/go/wasi/wit/deps/http/handler.wit index a34a064..6a6c629 100644 --- a/tests/go/wasi/wit/deps/http/handler.wit +++ b/tests/go/wasi/wit/deps/http/handler.wit @@ -1,6 +1,8 @@ /// This interface defines a handler of incoming HTTP Requests. It should /// be exported by components which can respond to HTTP Requests. +@since(version = 0.2.0) interface incoming-handler { + @since(version = 0.2.0) use types.{incoming-request, response-outparam}; /// This function is invoked with an incoming HTTP Request, and a resource @@ -13,6 +15,7 @@ interface incoming-handler { /// The implementor of this function must write a response to the /// `response-outparam` before returning, or else the caller will respond /// with an error on its behalf. + @since(version = 0.2.0) handle: func( request: incoming-request, response-out: response-outparam @@ -21,7 +24,9 @@ interface incoming-handler { /// This interface defines a handler of outgoing HTTP Requests. It should be /// imported by components which wish to make HTTP Requests. +@since(version = 0.2.0) interface outgoing-handler { + @since(version = 0.2.0) use types.{ outgoing-request, request-options, future-incoming-response, error-code }; @@ -36,6 +41,7 @@ interface outgoing-handler { /// This function may return an error if the `outgoing-request` is invalid /// or not allowed to be made. Otherwise, protocol errors are reported /// through the `future-incoming-response`. + @since(version = 0.2.0) handle: func( request: outgoing-request, options: option diff --git a/tests/go/wasi/wit/deps/http/proxy.wit b/tests/go/wasi/wit/deps/http/proxy.wit index 687c24d..415d2ee 100644 --- a/tests/go/wasi/wit/deps/http/proxy.wit +++ b/tests/go/wasi/wit/deps/http/proxy.wit @@ -1,32 +1,50 @@ -package wasi:http@0.2.0; +package wasi:http@0.2.1; -/// The `wasi:http/proxy` world captures a widely-implementable intersection of -/// hosts that includes HTTP forward and reverse proxies. Components targeting -/// this world may concurrently stream in and out any number of incoming and -/// outgoing HTTP requests. -world proxy { +/// The `wasi:http/imports` world imports all the APIs for HTTP proxies. +/// It is intended to be `include`d in other worlds. +@since(version = 0.2.0) +world imports { /// HTTP proxies have access to time and randomness. - include wasi:clocks/imports@0.2.0; - import wasi:random/random@0.2.0; + @since(version = 0.2.0) + import wasi:clocks/monotonic-clock@0.2.1; + @since(version = 0.2.0) + import wasi:clocks/wall-clock@0.2.1; + @since(version = 0.2.0) + import wasi:random/random@0.2.1; /// Proxies have standard output and error streams which are expected to /// terminate in a developer-facing console provided by the host. - import wasi:cli/stdout@0.2.0; - import wasi:cli/stderr@0.2.0; + @since(version = 0.2.0) + import wasi:cli/stdout@0.2.1; + @since(version = 0.2.0) + import wasi:cli/stderr@0.2.1; /// TODO: this is a temporary workaround until component tooling is able to /// gracefully handle the absence of stdin. Hosts must return an eof stream /// for this import, which is what wasi-libc + tooling will do automatically /// when this import is properly removed. - import wasi:cli/stdin@0.2.0; + @since(version = 0.2.0) + import wasi:cli/stdin@0.2.1; /// This is the default handler to use when user code simply wants to make an /// HTTP request (e.g., via `fetch()`). + @since(version = 0.2.0) import outgoing-handler; +} + +/// The `wasi:http/proxy` world captures a widely-implementable intersection of +/// hosts that includes HTTP forward and reverse proxies. Components targeting +/// this world may concurrently stream in and out any number of incoming and +/// outgoing HTTP requests. +@since(version = 0.2.0) +world proxy { + @since(version = 0.2.0) + include imports; /// The host delivers incoming HTTP requests to a component by calling the /// `handle` function of this exported interface. A host may arbitrarily reuse /// or not reuse component instance when delivering incoming HTTP requests and /// thus a component must be able to handle 0..N calls to `handle`. + @since(version = 0.2.0) export incoming-handler; } diff --git a/tests/go/wasi/wit/deps/http/types.wit b/tests/go/wasi/wit/deps/http/types.wit index 755ac6a..3c45cd0 100644 --- a/tests/go/wasi/wit/deps/http/types.wit +++ b/tests/go/wasi/wit/deps/http/types.wit @@ -1,13 +1,19 @@ /// This interface defines all of the types and methods for implementing /// HTTP Requests and Responses, both incoming and outgoing, as well as /// their headers, trailers, and bodies. +@since(version = 0.2.0) interface types { - use wasi:clocks/monotonic-clock@0.2.0.{duration}; - use wasi:io/streams@0.2.0.{input-stream, output-stream}; - use wasi:io/error@0.2.0.{error as io-error}; - use wasi:io/poll@0.2.0.{pollable}; + @since(version = 0.2.0) + use wasi:clocks/monotonic-clock@0.2.1.{duration}; + @since(version = 0.2.0) + use wasi:io/streams@0.2.1.{input-stream, output-stream}; + @since(version = 0.2.0) + use wasi:io/error@0.2.1.{error as io-error}; + @since(version = 0.2.0) + use wasi:io/poll@0.2.1.{pollable}; /// This type corresponds to HTTP standard Methods. + @since(version = 0.2.0) variant method { get, head, @@ -22,6 +28,7 @@ interface types { } /// This type corresponds to HTTP standard Related Schemes. + @since(version = 0.2.0) variant scheme { HTTP, HTTPS, @@ -30,6 +37,7 @@ interface types { /// These cases are inspired by the IANA HTTP Proxy Error Types: /// https://www.iana.org/assignments/http-proxy-status/http-proxy-status.xhtml#table-http-proxy-error-types + @since(version = 0.2.0) variant error-code { DNS-timeout, DNS-error(DNS-error-payload), @@ -78,18 +86,21 @@ interface types { } /// Defines the case payload type for `DNS-error` above: + @since(version = 0.2.0) record DNS-error-payload { rcode: option, info-code: option } /// Defines the case payload type for `TLS-alert-received` above: + @since(version = 0.2.0) record TLS-alert-received-payload { alert-id: option, alert-message: option } /// Defines the case payload type for `HTTP-response-{header,trailer}-size` above: + @since(version = 0.2.0) record field-size-payload { field-name: option, field-size: option @@ -106,10 +117,12 @@ interface types { /// /// Note that this function is fallible because not all io-errors are /// http-related errors. + @since(version = 0.2.0) http-error-code: func(err: borrow) -> option; /// This type enumerates the different kinds of errors that may occur when /// setting or appending to a `fields` resource. + @since(version = 0.2.0) variant header-error { /// This error indicates that a `field-key` or `field-value` was /// syntactically invalid when used with an operation that sets headers in a @@ -126,11 +139,13 @@ interface types { } /// Field keys are always strings. + @since(version = 0.2.0) type field-key = string; /// Field values should always be ASCII strings. However, in /// reality, HTTP implementations often have to interpret malformed values, /// so they are provided as a list of bytes. + @since(version = 0.2.0) type field-value = list; /// This following block defines the `fields` resource which corresponds to @@ -143,11 +158,13 @@ interface types { /// `incoming-request.headers`, `outgoing-request.headers`) might be be /// immutable. In an immutable fields, the `set`, `append`, and `delete` /// operations will fail with `header-error.immutable`. + @since(version = 0.2.0) resource fields { /// Construct an empty HTTP Fields. /// /// The resulting `fields` is mutable. + @since(version = 0.2.0) constructor(); /// Construct an HTTP Fields. @@ -159,42 +176,55 @@ interface types { /// list with the same key. /// /// The tuple is a pair of the field key, represented as a string, and - /// Value, represented as a list of bytes. In a valid Fields, all keys - /// and values are valid UTF-8 strings. However, values are not always - /// well-formed, so they are represented as a raw list of bytes. + /// Value, represented as a list of bytes. /// - /// An error result will be returned if any header or value was - /// syntactically invalid, or if a header was forbidden. + /// An error result will be returned if any `field-key` or `field-value` is + /// syntactically invalid, or if a field is forbidden. + @since(version = 0.2.0) from-list: static func( entries: list> ) -> result; /// Get all of the values corresponding to a key. If the key is not present - /// in this `fields`, an empty list is returned. However, if the key is - /// present but empty, this is represented by a list with one or more - /// empty field-values present. + /// in this `fields` or is syntactically invalid, an empty list is returned. + /// However, if the key is present but empty, this is represented by a list + /// with one or more empty field-values present. + @since(version = 0.2.0) get: func(name: field-key) -> list; /// Returns `true` when the key is present in this `fields`. If the key is /// syntactically invalid, `false` is returned. + @since(version = 0.2.0) has: func(name: field-key) -> bool; /// Set all of the values for a key. Clears any existing values for that /// key, if they have been set. /// /// Fails with `header-error.immutable` if the `fields` are immutable. + /// + /// Fails with `header-error.invalid-syntax` if the `field-key` or any of + /// the `field-value`s are syntactically invalid. + @since(version = 0.2.0) set: func(name: field-key, value: list) -> result<_, header-error>; /// Delete all values for a key. Does nothing if no values for the key /// exist. /// /// Fails with `header-error.immutable` if the `fields` are immutable. + /// + /// Fails with `header-error.invalid-syntax` if the `field-key` is + /// syntactically invalid. + @since(version = 0.2.0) delete: func(name: field-key) -> result<_, header-error>; /// Append a value for a key. Does not change or delete any existing /// values for that key. /// /// Fails with `header-error.immutable` if the `fields` are immutable. + /// + /// Fails with `header-error.invalid-syntax` if the `field-key` or + /// `field-value` are syntactically invalid. + @since(version = 0.2.0) append: func(name: field-key, value: field-value) -> result<_, header-error>; /// Retrieve the full set of keys and values in the Fields. Like the @@ -203,33 +233,42 @@ interface types { /// The outer list represents each key-value pair in the Fields. Keys /// which have multiple values are represented by multiple entries in this /// list with the same key. + @since(version = 0.2.0) entries: func() -> list>; - /// Make a deep copy of the Fields. Equivelant in behavior to calling the + /// Make a deep copy of the Fields. Equivalent in behavior to calling the /// `fields` constructor on the return value of `entries`. The resulting /// `fields` is mutable. + @since(version = 0.2.0) clone: func() -> fields; } /// Headers is an alias for Fields. + @since(version = 0.2.0) type headers = fields; /// Trailers is an alias for Fields. + @since(version = 0.2.0) type trailers = fields; /// Represents an incoming HTTP Request. + @since(version = 0.2.0) resource incoming-request { /// Returns the method of the incoming request. + @since(version = 0.2.0) method: func() -> method; /// Returns the path with query parameters from the request, as a string. + @since(version = 0.2.0) path-with-query: func() -> option; /// Returns the protocol scheme from the request. + @since(version = 0.2.0) scheme: func() -> option; - /// Returns the authority from the request, if it was present. + /// Returns the authority of the Request's target URI, if present. + @since(version = 0.2.0) authority: func() -> option; /// Get the `headers` associated with the request. @@ -240,14 +279,17 @@ interface types { /// The `headers` returned are a child resource: it must be dropped before /// the parent `incoming-request` is dropped. Dropping this /// `incoming-request` before all children are dropped will trap. + @since(version = 0.2.0) headers: func() -> headers; /// Gives the `incoming-body` associated with this request. Will only /// return success at most once, and subsequent calls will return error. + @since(version = 0.2.0) consume: func() -> result; } /// Represents an outgoing HTTP Request. + @since(version = 0.2.0) resource outgoing-request { /// Construct a new `outgoing-request` with a default `method` of `GET`, and @@ -260,6 +302,7 @@ interface types { /// and `authority`, or `headers` which are not permitted to be sent. /// It is the obligation of the `outgoing-handler.handle` implementation /// to reject invalid constructions of `outgoing-request`. + @since(version = 0.2.0) constructor( headers: headers ); @@ -270,38 +313,47 @@ interface types { /// Returns success on the first call: the `outgoing-body` resource for /// this `outgoing-request` can be retrieved at most once. Subsequent /// calls will return error. + @since(version = 0.2.0) body: func() -> result; /// Get the Method for the Request. + @since(version = 0.2.0) method: func() -> method; /// Set the Method for the Request. Fails if the string present in a /// `method.other` argument is not a syntactically valid method. + @since(version = 0.2.0) set-method: func(method: method) -> result; /// Get the combination of the HTTP Path and Query for the Request. /// When `none`, this represents an empty Path and empty Query. + @since(version = 0.2.0) path-with-query: func() -> option; /// Set the combination of the HTTP Path and Query for the Request. /// When `none`, this represents an empty Path and empty Query. Fails is the /// string given is not a syntactically valid path and query uri component. + @since(version = 0.2.0) set-path-with-query: func(path-with-query: option) -> result; /// Get the HTTP Related Scheme for the Request. When `none`, the /// implementation may choose an appropriate default scheme. + @since(version = 0.2.0) scheme: func() -> option; /// Set the HTTP Related Scheme for the Request. When `none`, the /// implementation may choose an appropriate default scheme. Fails if the /// string given is not a syntactically valid uri scheme. + @since(version = 0.2.0) set-scheme: func(scheme: option) -> result; - /// Get the HTTP Authority for the Request. A value of `none` may be used - /// with Related Schemes which do not require an Authority. The HTTP and + /// Get the authority of the Request's target URI. A value of `none` may be used + /// with Related Schemes which do not require an authority. The HTTP and /// HTTPS schemes always require an authority. + @since(version = 0.2.0) authority: func() -> option; - /// Set the HTTP Authority for the Request. A value of `none` may be used - /// with Related Schemes which do not require an Authority. The HTTP and + /// Set the authority of the Request's target URI. A value of `none` may be used + /// with Related Schemes which do not require an authority. The HTTP and /// HTTPS schemes always require an authority. Fails if the string given is - /// not a syntactically valid uri authority. + /// not a syntactically valid URI authority. + @since(version = 0.2.0) set-authority: func(authority: option) -> result; /// Get the headers associated with the Request. @@ -310,8 +362,9 @@ interface types { /// `delete` operations will fail with `header-error.immutable`. /// /// This headers resource is a child: it must be dropped before the parent - /// `outgoing-request` is dropped, or its ownership is transfered to + /// `outgoing-request` is dropped, or its ownership is transferred to /// another component by e.g. `outgoing-handler.handle`. + @since(version = 0.2.0) headers: func() -> headers; } @@ -321,31 +374,39 @@ interface types { /// /// These timeouts are separate from any the user may use to bound a /// blocking call to `wasi:io/poll.poll`. + @since(version = 0.2.0) resource request-options { /// Construct a default `request-options` value. + @since(version = 0.2.0) constructor(); /// The timeout for the initial connect to the HTTP Server. + @since(version = 0.2.0) connect-timeout: func() -> option; /// Set the timeout for the initial connect to the HTTP Server. An error /// return value indicates that this timeout is not supported. + @since(version = 0.2.0) set-connect-timeout: func(duration: option) -> result; /// The timeout for receiving the first byte of the Response body. + @since(version = 0.2.0) first-byte-timeout: func() -> option; /// Set the timeout for receiving the first byte of the Response body. An /// error return value indicates that this timeout is not supported. + @since(version = 0.2.0) set-first-byte-timeout: func(duration: option) -> result; /// The timeout for receiving subsequent chunks of bytes in the Response /// body stream. + @since(version = 0.2.0) between-bytes-timeout: func() -> option; /// Set the timeout for receiving subsequent chunks of bytes in the Response /// body stream. An error return value indicates that this timeout is not /// supported. + @since(version = 0.2.0) set-between-bytes-timeout: func(duration: option) -> result; } @@ -354,6 +415,7 @@ interface types { /// This resource is used by the `wasi:http/incoming-handler` interface to /// allow a Response to be sent corresponding to the Request provided as the /// other argument to `incoming-handler.handle`. + @since(version = 0.2.0) resource response-outparam { /// Set the value of the `response-outparam` to either send a response, @@ -365,6 +427,7 @@ interface types { /// /// The user may provide an `error` to `response` to allow the /// implementation determine how to respond with an HTTP error response. + @since(version = 0.2.0) set: static func( param: response-outparam, response: result, @@ -372,12 +435,15 @@ interface types { } /// This type corresponds to the HTTP standard Status Code. + @since(version = 0.2.0) type status-code = u16; /// Represents an incoming HTTP Response. + @since(version = 0.2.0) resource incoming-response { /// Returns the status code from the incoming response. + @since(version = 0.2.0) status: func() -> status-code; /// Returns the headers from the incoming response. @@ -387,10 +453,12 @@ interface types { /// /// This headers resource is a child: it must be dropped before the parent /// `incoming-response` is dropped. + @since(version = 0.2.0) headers: func() -> headers; /// Returns the incoming body. May be called at most once. Returns error /// if called additional times. + @since(version = 0.2.0) consume: func() -> result; } @@ -402,6 +470,7 @@ interface types { /// an `input-stream` and the delivery of trailers as a `future-trailers`, /// and ensures that the user of this interface may only be consuming either /// the body contents or waiting on trailers at any given time. + @since(version = 0.2.0) resource incoming-body { /// Returns the contents of the body, as a stream of bytes. @@ -419,26 +488,30 @@ interface types { /// backpressure is to be applied when the user is consuming the body, /// and for that backpressure to not inhibit delivery of the trailers if /// the user does not read the entire body. + @since(version = 0.2.0) %stream: func() -> result; /// Takes ownership of `incoming-body`, and returns a `future-trailers`. /// This function will trap if the `input-stream` child is still alive. + @since(version = 0.2.0) finish: static func(this: incoming-body) -> future-trailers; } - /// Represents a future which may eventaully return trailers, or an error. + /// Represents a future which may eventually return trailers, or an error. /// /// In the case that the incoming HTTP Request or Response did not have any /// trailers, this future will resolve to the empty set of trailers once the /// complete Request or Response body has been received. + @since(version = 0.2.0) resource future-trailers { /// Returns a pollable which becomes ready when either the trailers have - /// been received, or an error has occured. When this pollable is ready, + /// been received, or an error has occurred. When this pollable is ready, /// the `get` method will return `some`. + @since(version = 0.2.0) subscribe: func() -> pollable; - /// Returns the contents of the trailers, or an error which occured, + /// Returns the contents of the trailers, or an error which occurred, /// once the future is ready. /// /// The outer `option` represents future readiness. Users can wait on this @@ -450,17 +523,19 @@ interface types { /// /// The inner `result` represents that either the HTTP Request or Response /// body, as well as any trailers, were received successfully, or that an - /// error occured receiving them. The optional `trailers` indicates whether + /// error occurred receiving them. The optional `trailers` indicates whether /// or not trailers were present in the body. /// /// When some `trailers` are returned by this method, the `trailers` /// resource is immutable, and a child. Use of the `set`, `append`, or /// `delete` methods will return an error, and the resource must be /// dropped before the parent `future-trailers` is dropped. + @since(version = 0.2.0) get: func() -> option, error-code>>>; } /// Represents an outgoing HTTP Response. + @since(version = 0.2.0) resource outgoing-response { /// Construct an `outgoing-response`, with a default `status-code` of `200`. @@ -468,13 +543,16 @@ interface types { /// `set-status-code` method. /// /// * `headers` is the HTTP Headers for the Response. + @since(version = 0.2.0) constructor(headers: headers); /// Get the HTTP Status Code for the Response. + @since(version = 0.2.0) status-code: func() -> status-code; /// Set the HTTP Status Code for the Response. Fails if the status-code /// given is not a valid http status code. + @since(version = 0.2.0) set-status-code: func(status-code: status-code) -> result; /// Get the headers associated with the Request. @@ -483,8 +561,9 @@ interface types { /// `delete` operations will fail with `header-error.immutable`. /// /// This headers resource is a child: it must be dropped before the parent - /// `outgoing-request` is dropped, or its ownership is transfered to + /// `outgoing-request` is dropped, or its ownership is transferred to /// another component by e.g. `outgoing-handler.handle`. + @since(version = 0.2.0) headers: func() -> headers; /// Returns the resource corresponding to the outgoing Body for this Response. @@ -492,6 +571,7 @@ interface types { /// Returns success on the first call: the `outgoing-body` resource for /// this `outgoing-response` can be retrieved at most once. Subsequent /// calls will return error. + @since(version = 0.2.0) body: func() -> result; } @@ -507,10 +587,11 @@ interface types { /// /// If the user code drops this resource, as opposed to calling the static /// method `finish`, the implementation should treat the body as incomplete, - /// and that an error has occured. The implementation should propogate this + /// and that an error has occurred. The implementation should propagate this /// error to the HTTP protocol by whatever means it has available, /// including: corrupting the body on the wire, aborting the associated /// Request, or sending a late status code for the Response. + @since(version = 0.2.0) resource outgoing-body { /// Returns a stream for writing the body contents. @@ -522,6 +603,7 @@ interface types { /// Returns success on the first call: the `output-stream` resource for /// this `outgoing-body` may be retrieved at most once. Subsequent calls /// will return error. + @since(version = 0.2.0) write: func() -> result; /// Finalize an outgoing body, optionally providing trailers. This must be @@ -533,21 +615,24 @@ interface types { /// constructed with a Content-Length header, and the contents written /// to the body (via `write`) does not match the value given in the /// Content-Length. + @since(version = 0.2.0) finish: static func( this: outgoing-body, trailers: option ) -> result<_, error-code>; } - /// Represents a future which may eventaully return an incoming HTTP + /// Represents a future which may eventually return an incoming HTTP /// Response, or an error. /// /// This resource is returned by the `wasi:http/outgoing-handler` interface to /// provide the HTTP Response corresponding to the sent Request. + @since(version = 0.2.0) resource future-incoming-response { /// Returns a pollable which becomes ready when either the Response has - /// been received, or an error has occured. When this pollable is ready, + /// been received, or an error has occurred. When this pollable is ready, /// the `get` method will return `some`. + @since(version = 0.2.0) subscribe: func() -> pollable; /// Returns the incoming HTTP Response, or an error, once one is ready. @@ -560,11 +645,11 @@ interface types { /// is `some`, and error on subsequent calls. /// /// The inner `result` represents that either the incoming HTTP Response - /// status and headers have recieved successfully, or that an error - /// occured. Errors may also occur while consuming the response body, + /// status and headers have received successfully, or that an error + /// occurred. Errors may also occur while consuming the response body, /// but those will be reported by the `incoming-body` and its /// `output-stream` child. + @since(version = 0.2.0) get: func() -> option>>; - } } diff --git a/tests/go/wasi/wit/deps/io/error.wit b/tests/go/wasi/wit/deps/io/error.wit index 22e5b64..4ea29c4 100644 --- a/tests/go/wasi/wit/deps/io/error.wit +++ b/tests/go/wasi/wit/deps/io/error.wit @@ -1,6 +1,6 @@ -package wasi:io@0.2.0; - +package wasi:io@0.2.1; +@since(version = 0.2.0) interface error { /// A resource which represents some error information. /// @@ -11,16 +11,15 @@ interface error { /// `wasi:io/streams/stream-error` type. /// /// To provide more specific error information, other interfaces may - /// provide functions to further "downcast" this error into more specific - /// error information. For example, `error`s returned in streams derived - /// from filesystem types to be described using the filesystem's own - /// error-code type, using the function - /// `wasi:filesystem/types/filesystem-error-code`, which takes a parameter - /// `borrow` and returns - /// `option`. + /// offer functions to "downcast" this error into more specific types. For example, + /// errors returned from streams derived from filesystem types can be described using + /// the filesystem's own error-code type. This is done using the function + /// `wasi:filesystem/types/filesystem-error-code`, which takes a `borrow` + /// parameter and returns an `option`. /// /// The set of functions which can "downcast" an `error` into a more /// concrete type is open. + @since(version = 0.2.0) resource error { /// Returns a string that is suitable to assist humans in debugging /// this error. @@ -29,6 +28,7 @@ interface error { /// It may change across platforms, hosts, or other implementation /// details. Parsing this string is a major platform-compatibility /// hazard. + @since(version = 0.2.0) to-debug-string: func() -> string; } } diff --git a/tests/go/wasi/wit/deps/io/poll.wit b/tests/go/wasi/wit/deps/io/poll.wit index ddc67f8..b25ac72 100644 --- a/tests/go/wasi/wit/deps/io/poll.wit +++ b/tests/go/wasi/wit/deps/io/poll.wit @@ -1,14 +1,17 @@ -package wasi:io@0.2.0; +package wasi:io@0.2.1; /// A poll API intended to let users wait for I/O events on multiple handles /// at once. +@since(version = 0.2.0) interface poll { /// `pollable` represents a single I/O event which may be ready, or not. + @since(version = 0.2.0) resource pollable { /// Return the readiness of a pollable. This function never blocks. /// /// Returns `true` when the pollable is ready, and `false` otherwise. + @since(version = 0.2.0) ready: func() -> bool; /// `block` returns immediately if the pollable is ready, and otherwise @@ -16,6 +19,7 @@ interface poll { /// /// This function is equivalent to calling `poll.poll` on a list /// containing only this pollable. + @since(version = 0.2.0) block: func(); } @@ -27,8 +31,9 @@ interface poll { /// The result `list` contains one or more indices of handles in the /// argument list that is ready for I/O. /// - /// If the list contains more elements than can be indexed with a `u32` - /// value, this function traps. + /// This function traps if either: + /// - the list is empty, or: + /// - the list contains more elements than can be indexed with a `u32` value. /// /// A timeout can be implemented by adding a pollable from the /// wasi-clocks API to the list. @@ -36,6 +41,7 @@ interface poll { /// This function does not return a `result`; polling in itself does not /// do any I/O so it doesn't fail. If any of the I/O sources identified by /// the pollables has an error, it is indicated by marking the source as - /// being reaedy for I/O. + /// being ready for I/O. + @since(version = 0.2.0) poll: func(in: list>) -> list; } diff --git a/tests/go/wasi/wit/deps/io/streams.wit b/tests/go/wasi/wit/deps/io/streams.wit index 6d2f871..b697e24 100644 --- a/tests/go/wasi/wit/deps/io/streams.wit +++ b/tests/go/wasi/wit/deps/io/streams.wit @@ -1,15 +1,19 @@ -package wasi:io@0.2.0; +package wasi:io@0.2.1; /// WASI I/O is an I/O abstraction API which is currently focused on providing /// stream types. /// /// In the future, the component model is expected to add built-in stream types; /// when it does, they are expected to subsume this API. +@since(version = 0.2.0) interface streams { + @since(version = 0.2.0) use error.{error}; + @since(version = 0.2.0) use poll.{pollable}; /// An error for input-stream and output-stream operations. + @since(version = 0.2.0) variant stream-error { /// The last operation (a write or flush) failed before completion. /// @@ -29,6 +33,7 @@ interface streams { /// available, which could even be zero. To wait for data to be available, /// use the `subscribe` function to obtain a `pollable` which can be polled /// for using `wasi:io/poll`. + @since(version = 0.2.0) resource input-stream { /// Perform a non-blocking read from the stream. /// @@ -56,6 +61,7 @@ interface streams { /// is not possible to allocate in wasm32, or not desirable to allocate as /// as a return value by the callee. The callee may return a list of bytes /// less than `len` in size while more bytes are available for reading. + @since(version = 0.2.0) read: func( /// The maximum number of bytes to read len: u64 @@ -63,6 +69,7 @@ interface streams { /// Read bytes from a stream, after blocking until at least one byte can /// be read. Except for blocking, behavior is identical to `read`. + @since(version = 0.2.0) blocking-read: func( /// The maximum number of bytes to read len: u64 @@ -72,6 +79,7 @@ interface streams { /// /// Behaves identical to `read`, except instead of returning a list /// of bytes, returns the number of bytes consumed from the stream. + @since(version = 0.2.0) skip: func( /// The maximum number of bytes to skip. len: u64, @@ -79,6 +87,7 @@ interface streams { /// Skip bytes from a stream, after blocking until at least one byte /// can be skipped. Except for blocking behavior, identical to `skip`. + @since(version = 0.2.0) blocking-skip: func( /// The maximum number of bytes to skip. len: u64, @@ -90,6 +99,7 @@ interface streams { /// The created `pollable` is a child resource of the `input-stream`. /// Implementations may trap if the `input-stream` is dropped before /// all derived `pollable`s created with this function are dropped. + @since(version = 0.2.0) subscribe: func() -> pollable; } @@ -102,6 +112,11 @@ interface streams { /// promptly, which could even be zero. To wait for the stream to be ready to /// accept data, the `subscribe` function to obtain a `pollable` which can be /// polled for using `wasi:io/poll`. + /// + /// Dropping an `output-stream` while there's still an active write in + /// progress may result in the data being lost. Before dropping the stream, + /// be sure to fully flush your writes. + @since(version = 0.2.0) resource output-stream { /// Check readiness for writing. This function never blocks. /// @@ -112,6 +127,7 @@ interface streams { /// When this function returns 0 bytes, the `subscribe` pollable will /// become ready when this function will report at least 1 byte, or an /// error. + @since(version = 0.2.0) check-write: func() -> result; /// Perform a write. This function never blocks. @@ -127,6 +143,7 @@ interface streams { /// /// returns Err(closed) without writing if the stream has closed since /// the last call to check-write provided a permit. + @since(version = 0.2.0) write: func( contents: list ) -> result<_, stream-error>; @@ -155,6 +172,7 @@ interface streams { /// // Check for any errors that arose during `flush` /// let _ = this.check-write(); // eliding error handling /// ``` + @since(version = 0.2.0) blocking-write-and-flush: func( contents: list ) -> result<_, stream-error>; @@ -169,14 +187,16 @@ interface streams { /// writes (`check-write` will return `ok(0)`) until the flush has /// completed. The `subscribe` pollable will become ready when the /// flush has completed and the stream can accept more writes. + @since(version = 0.2.0) flush: func() -> result<_, stream-error>; /// Request to flush buffered output, and block until flush completes /// and stream is ready for writing again. + @since(version = 0.2.0) blocking-flush: func() -> result<_, stream-error>; /// Create a `pollable` which will resolve once the output-stream - /// is ready for more writing, or an error has occured. When this + /// is ready for more writing, or an error has occurred. When this /// pollable is ready, `check-write` will return `ok(n)` with n>0, or an /// error. /// @@ -193,6 +213,7 @@ interface streams { /// preconditions (must use check-write first), but instead of /// passing a list of bytes, you simply pass the number of zero-bytes /// that should be written. + @since(version = 0.2.0) write-zeroes: func( /// The number of zero-bytes to write len: u64 @@ -222,6 +243,7 @@ interface streams { /// // Check for any errors that arose during `flush` /// let _ = this.check-write(); // eliding error handling /// ``` + @since(version = 0.2.0) blocking-write-zeroes-and-flush: func( /// The number of zero-bytes to write len: u64 @@ -229,7 +251,7 @@ interface streams { /// Read from one stream and write to another. /// - /// The behavior of splice is equivelant to: + /// The behavior of splice is equivalent to: /// 1. calling `check-write` on the `output-stream` /// 2. calling `read` on the `input-stream` with the smaller of the /// `check-write` permitted length and the `len` provided to `splice` @@ -240,6 +262,7 @@ interface streams { /// /// This function returns the number of bytes transferred; it may be less /// than `len`. + @since(version = 0.2.0) splice: func( /// The stream to read from src: borrow, @@ -252,6 +275,7 @@ interface streams { /// This is similar to `splice`, except that it blocks until the /// `output-stream` is ready for writing, and the `input-stream` /// is ready for reading, before performing the `splice`. + @since(version = 0.2.0) blocking-splice: func( /// The stream to read from src: borrow, diff --git a/tests/go/wasi/wit/deps/io/world.wit b/tests/go/wasi/wit/deps/io/world.wit index 5f0b43f..6405a4e 100644 --- a/tests/go/wasi/wit/deps/io/world.wit +++ b/tests/go/wasi/wit/deps/io/world.wit @@ -1,6 +1,10 @@ -package wasi:io@0.2.0; +package wasi:io@0.2.1; +@since(version = 0.2.0) world imports { + @since(version = 0.2.0) import streams; + + @since(version = 0.2.0) import poll; } diff --git a/tests/go/wasi/wit/deps/leftpad/leftpad.wit b/tests/go/wasi/wit/deps/leftpad/leftpad.wit new file mode 100644 index 0000000..1a137ff --- /dev/null +++ b/tests/go/wasi/wit/deps/leftpad/leftpad.wit @@ -0,0 +1,15 @@ +package west-test:leftpad; + +interface leftpad { + use wasi:io/streams@0.2.1.{input-stream, output-stream, stream-error}; + + leftpad: func(in: input-stream, out: borrow, len: u64, c: char) -> result<_, stream-error>; +} + +world guest { + import leftpad; +} + +world host { + export leftpad; +} diff --git a/tests/go/wasi/wit/deps/random/insecure-seed.wit b/tests/go/wasi/wit/deps/random/insecure-seed.wit index 47210ac..7e708dc 100644 --- a/tests/go/wasi/wit/deps/random/insecure-seed.wit +++ b/tests/go/wasi/wit/deps/random/insecure-seed.wit @@ -1,8 +1,9 @@ -package wasi:random@0.2.0; +package wasi:random@0.2.1; /// The insecure-seed interface for seeding hash-map DoS resistance. /// /// It is intended to be portable at least between Unix-family platforms and /// Windows. +@since(version = 0.2.0) interface insecure-seed { /// Return a 128-bit value that may contain a pseudo-random value. /// @@ -21,5 +22,6 @@ interface insecure-seed { /// This will likely be changed to a value import, to prevent it from being /// called multiple times and potentially used for purposes other than DoS /// protection. + @since(version = 0.2.0) insecure-seed: func() -> tuple; } diff --git a/tests/go/wasi/wit/deps/random/insecure.wit b/tests/go/wasi/wit/deps/random/insecure.wit index c58f4ee..3cdb53d 100644 --- a/tests/go/wasi/wit/deps/random/insecure.wit +++ b/tests/go/wasi/wit/deps/random/insecure.wit @@ -1,8 +1,9 @@ -package wasi:random@0.2.0; +package wasi:random@0.2.1; /// The insecure interface for insecure pseudo-random numbers. /// /// It is intended to be portable at least between Unix-family platforms and /// Windows. +@since(version = 0.2.0) interface insecure { /// Return `len` insecure pseudo-random bytes. /// @@ -12,11 +13,13 @@ interface insecure { /// There are no requirements on the values of the returned bytes, however /// implementations are encouraged to return evenly distributed values with /// a long period. + @since(version = 0.2.0) get-insecure-random-bytes: func(len: u64) -> list; /// Return an insecure pseudo-random `u64` value. /// /// This function returns the same type of pseudo-random data as /// `get-insecure-random-bytes`, represented as a `u64`. + @since(version = 0.2.0) get-insecure-random-u64: func() -> u64; } diff --git a/tests/go/wasi/wit/deps/random/random.wit b/tests/go/wasi/wit/deps/random/random.wit index 0c017f0..2b5035d 100644 --- a/tests/go/wasi/wit/deps/random/random.wit +++ b/tests/go/wasi/wit/deps/random/random.wit @@ -1,8 +1,9 @@ -package wasi:random@0.2.0; +package wasi:random@0.2.1; /// WASI Random is a random data API. /// /// It is intended to be portable at least between Unix-family platforms and /// Windows. +@since(version = 0.2.0) interface random { /// Return `len` cryptographically-secure random or pseudo-random bytes. /// @@ -16,11 +17,13 @@ interface random { /// This function must always return fresh data. Deterministic environments /// must omit this function, rather than implementing it with deterministic /// data. + @since(version = 0.2.0) get-random-bytes: func(len: u64) -> list; /// Return a cryptographically-secure random or pseudo-random `u64` value. /// /// This function returns the same type of data as `get-random-bytes`, /// represented as a `u64`. + @since(version = 0.2.0) get-random-u64: func() -> u64; } diff --git a/tests/go/wasi/wit/deps/random/world.wit b/tests/go/wasi/wit/deps/random/world.wit index 3da3491..c615e96 100644 --- a/tests/go/wasi/wit/deps/random/world.wit +++ b/tests/go/wasi/wit/deps/random/world.wit @@ -1,7 +1,13 @@ -package wasi:random@0.2.0; +package wasi:random@0.2.1; +@since(version = 0.2.0) world imports { + @since(version = 0.2.0) import random; + + @since(version = 0.2.0) import insecure; + + @since(version = 0.2.0) import insecure-seed; } diff --git a/tests/go/wasi/wit/deps/sockets/instance-network.wit b/tests/go/wasi/wit/deps/sockets/instance-network.wit index e455d0f..5f6e6c1 100644 --- a/tests/go/wasi/wit/deps/sockets/instance-network.wit +++ b/tests/go/wasi/wit/deps/sockets/instance-network.wit @@ -1,9 +1,11 @@ /// This interface provides a value-export of the default network handle.. +@since(version = 0.2.0) interface instance-network { + @since(version = 0.2.0) use network.{network}; /// Get a handle to the default network. + @since(version = 0.2.0) instance-network: func() -> network; - } diff --git a/tests/go/wasi/wit/deps/sockets/ip-name-lookup.wit b/tests/go/wasi/wit/deps/sockets/ip-name-lookup.wit index 8e639ec..dc56f30 100644 --- a/tests/go/wasi/wit/deps/sockets/ip-name-lookup.wit +++ b/tests/go/wasi/wit/deps/sockets/ip-name-lookup.wit @@ -1,9 +1,10 @@ - +@since(version = 0.2.0) interface ip-name-lookup { - use wasi:io/poll@0.2.0.{pollable}; + @since(version = 0.2.0) + use wasi:io/poll@0.2.1.{pollable}; + @since(version = 0.2.0) use network.{network, error-code, ip-address}; - /// Resolve an internet host name to a list of IP addresses. /// /// Unicode domain names are automatically converted to ASCII using IDNA encoding. @@ -24,8 +25,10 @@ interface ip-name-lookup { /// - /// - /// - + @since(version = 0.2.0) resolve-addresses: func(network: borrow, name: string) -> result; + @since(version = 0.2.0) resource resolve-address-stream { /// Returns the next address from the resolver. /// @@ -40,12 +43,14 @@ interface ip-name-lookup { /// - `temporary-resolver-failure`: A temporary failure in name resolution occurred. (EAI_AGAIN) /// - `permanent-resolver-failure`: A permanent failure in name resolution occurred. (EAI_FAIL) /// - `would-block`: A result is not available yet. (EWOULDBLOCK, EAGAIN) + @since(version = 0.2.0) resolve-next-address: func() -> result, error-code>; /// Create a `pollable` which will resolve once the stream is ready for I/O. /// /// Note: this function is here for WASI Preview2 only. /// It's planned to be removed when `future` is natively supported in Preview3. + @since(version = 0.2.0) subscribe: func() -> pollable; } } diff --git a/tests/go/wasi/wit/deps/sockets/network.wit b/tests/go/wasi/wit/deps/sockets/network.wit index 9cadf06..8c13b34 100644 --- a/tests/go/wasi/wit/deps/sockets/network.wit +++ b/tests/go/wasi/wit/deps/sockets/network.wit @@ -1,8 +1,9 @@ - +@since(version = 0.2.0) interface network { /// An opaque resource that represents access to (a subset of) the network. /// This enables context-based security for networking. /// There is no need for this to map 1:1 to a physical network interface. + @since(version = 0.2.0) resource network; /// Error codes. @@ -17,6 +18,7 @@ interface network { /// - `concurrency-conflict` /// /// See each individual API for what the POSIX equivalents are. They sometimes differ per API. + @since(version = 0.2.0) enum error-code { /// Unknown error unknown, @@ -103,6 +105,7 @@ interface network { permanent-resolver-failure, } + @since(version = 0.2.0) enum ip-address-family { /// Similar to `AF_INET` in POSIX. ipv4, @@ -111,14 +114,18 @@ interface network { ipv6, } + @since(version = 0.2.0) type ipv4-address = tuple; + @since(version = 0.2.0) type ipv6-address = tuple; + @since(version = 0.2.0) variant ip-address { ipv4(ipv4-address), ipv6(ipv6-address), } + @since(version = 0.2.0) record ipv4-socket-address { /// sin_port port: u16, @@ -126,6 +133,7 @@ interface network { address: ipv4-address, } + @since(version = 0.2.0) record ipv6-socket-address { /// sin6_port port: u16, @@ -137,9 +145,9 @@ interface network { scope-id: u32, } + @since(version = 0.2.0) variant ip-socket-address { ipv4(ipv4-socket-address), ipv6(ipv6-socket-address), } - } diff --git a/tests/go/wasi/wit/deps/sockets/tcp-create-socket.wit b/tests/go/wasi/wit/deps/sockets/tcp-create-socket.wit index c7ddf1f..eedbd30 100644 --- a/tests/go/wasi/wit/deps/sockets/tcp-create-socket.wit +++ b/tests/go/wasi/wit/deps/sockets/tcp-create-socket.wit @@ -1,6 +1,8 @@ - +@since(version = 0.2.0) interface tcp-create-socket { + @since(version = 0.2.0) use network.{network, error-code, ip-address-family}; + @since(version = 0.2.0) use tcp.{tcp-socket}; /// Create a new TCP socket. @@ -23,5 +25,6 @@ interface tcp-create-socket { /// - /// - /// - + @since(version = 0.2.0) create-tcp-socket: func(address-family: ip-address-family) -> result; } diff --git a/tests/go/wasi/wit/deps/sockets/tcp.wit b/tests/go/wasi/wit/deps/sockets/tcp.wit index 5902b9e..bae5a29 100644 --- a/tests/go/wasi/wit/deps/sockets/tcp.wit +++ b/tests/go/wasi/wit/deps/sockets/tcp.wit @@ -1,10 +1,15 @@ - +@since(version = 0.2.0) interface tcp { - use wasi:io/streams@0.2.0.{input-stream, output-stream}; - use wasi:io/poll@0.2.0.{pollable}; - use wasi:clocks/monotonic-clock@0.2.0.{duration}; + @since(version = 0.2.0) + use wasi:io/streams@0.2.1.{input-stream, output-stream}; + @since(version = 0.2.0) + use wasi:io/poll@0.2.1.{pollable}; + @since(version = 0.2.0) + use wasi:clocks/monotonic-clock@0.2.1.{duration}; + @since(version = 0.2.0) use network.{network, error-code, ip-socket-address, ip-address-family}; + @since(version = 0.2.0) enum shutdown-type { /// Similar to `SHUT_RD` in POSIX. receive, @@ -27,8 +32,8 @@ interface tcp { /// - `connect-in-progress` /// - `connected` /// - `closed` - /// See - /// for a more information. + /// See + /// for more information. /// /// Note: Except where explicitly mentioned, whenever this documentation uses /// the term "bound" without backticks it actually means: in the `bound` state *or higher*. @@ -37,6 +42,7 @@ interface tcp { /// In addition to the general error codes documented on the /// `network::error-code` type, TCP socket methods may always return /// `error(invalid-state)` when in the `closed` state. + @since(version = 0.2.0) resource tcp-socket { /// Bind the socket to a specific network on the provided IP address and port. /// @@ -76,13 +82,15 @@ interface tcp { /// - /// - /// - + @since(version = 0.2.0) start-bind: func(network: borrow, local-address: ip-socket-address) -> result<_, error-code>; + @since(version = 0.2.0) finish-bind: func() -> result<_, error-code>; /// Connect to a remote endpoint. /// /// On success: - /// - the socket is transitioned into the `connection` state. + /// - the socket is transitioned into the `connected` state. /// - a pair of streams is returned that can be used to read & write to the connection /// /// After a failed connection attempt, the socket will be in the `closed` @@ -121,7 +129,9 @@ interface tcp { /// - /// - /// - + @since(version = 0.2.0) start-connect: func(network: borrow, remote-address: ip-socket-address) -> result<_, error-code>; + @since(version = 0.2.0) finish-connect: func() -> result, error-code>; /// Start listening for new connections. @@ -149,7 +159,9 @@ interface tcp { /// - /// - /// - + @since(version = 0.2.0) start-listen: func() -> result<_, error-code>; + @since(version = 0.2.0) finish-listen: func() -> result<_, error-code>; /// Accept a new client socket. @@ -178,6 +190,7 @@ interface tcp { /// - /// - /// - + @since(version = 0.2.0) accept: func() -> result, error-code>; /// Get the bound local address. @@ -196,6 +209,7 @@ interface tcp { /// - /// - /// - + @since(version = 0.2.0) local-address: func() -> result; /// Get the remote address. @@ -208,16 +222,19 @@ interface tcp { /// - /// - /// - + @since(version = 0.2.0) remote-address: func() -> result; /// Whether the socket is in the `listening` state. /// /// Equivalent to the SO_ACCEPTCONN socket option. + @since(version = 0.2.0) is-listening: func() -> bool; /// Whether this is a IPv4 or IPv6 socket. /// /// Equivalent to the SO_DOMAIN socket option. + @since(version = 0.2.0) address-family: func() -> ip-address-family; /// Hints the desired listen queue size. Implementations are free to ignore this. @@ -229,6 +246,7 @@ interface tcp { /// - `not-supported`: (set) The platform does not support changing the backlog size after the initial listen. /// - `invalid-argument`: (set) The provided value was 0. /// - `invalid-state`: (set) The socket is in the `connect-in-progress` or `connected` state. + @since(version = 0.2.0) set-listen-backlog-size: func(value: u64) -> result<_, error-code>; /// Enables or disables keepalive. @@ -240,7 +258,9 @@ interface tcp { /// These properties can be configured while `keep-alive-enabled` is false, but only come into effect when `keep-alive-enabled` is true. /// /// Equivalent to the SO_KEEPALIVE socket option. + @since(version = 0.2.0) keep-alive-enabled: func() -> result; + @since(version = 0.2.0) set-keep-alive-enabled: func(value: bool) -> result<_, error-code>; /// Amount of time the connection has to be idle before TCP starts sending keepalive packets. @@ -253,7 +273,9 @@ interface tcp { /// /// # Typical errors /// - `invalid-argument`: (set) The provided value was 0. + @since(version = 0.2.0) keep-alive-idle-time: func() -> result; + @since(version = 0.2.0) set-keep-alive-idle-time: func(value: duration) -> result<_, error-code>; /// The time between keepalive packets. @@ -266,7 +288,9 @@ interface tcp { /// /// # Typical errors /// - `invalid-argument`: (set) The provided value was 0. + @since(version = 0.2.0) keep-alive-interval: func() -> result; + @since(version = 0.2.0) set-keep-alive-interval: func(value: duration) -> result<_, error-code>; /// The maximum amount of keepalive packets TCP should send before aborting the connection. @@ -279,7 +303,9 @@ interface tcp { /// /// # Typical errors /// - `invalid-argument`: (set) The provided value was 0. + @since(version = 0.2.0) keep-alive-count: func() -> result; + @since(version = 0.2.0) set-keep-alive-count: func(value: u32) -> result<_, error-code>; /// Equivalent to the IP_TTL & IPV6_UNICAST_HOPS socket options. @@ -288,7 +314,9 @@ interface tcp { /// /// # Typical errors /// - `invalid-argument`: (set) The TTL value must be 1 or higher. + @since(version = 0.2.0) hop-limit: func() -> result; + @since(version = 0.2.0) set-hop-limit: func(value: u8) -> result<_, error-code>; /// The kernel buffer space reserved for sends/receives on this socket. @@ -301,9 +329,13 @@ interface tcp { /// /// # Typical errors /// - `invalid-argument`: (set) The provided value was 0. + @since(version = 0.2.0) receive-buffer-size: func() -> result; + @since(version = 0.2.0) set-receive-buffer-size: func(value: u64) -> result<_, error-code>; + @since(version = 0.2.0) send-buffer-size: func() -> result; + @since(version = 0.2.0) set-send-buffer-size: func(value: u64) -> result<_, error-code>; /// Create a `pollable` which can be used to poll for, or block on, @@ -318,11 +350,12 @@ interface tcp { /// `subscribe` only has to be called once per socket and can then be /// (re)used for the remainder of the socket's lifetime. /// - /// See - /// for a more information. + /// See + /// for more information. /// /// Note: this function is here for WASI Preview2 only. /// It's planned to be removed when `future` is natively supported in Preview3. + @since(version = 0.2.0) subscribe: func() -> pollable; /// Initiate a graceful shutdown. @@ -335,7 +368,7 @@ interface tcp { /// associated with this socket will be closed and a FIN packet will be sent. /// - `both`: Same effect as `receive` & `send` combined. /// - /// This function is idempotent. Shutting a down a direction more than once + /// This function is idempotent; shutting down a direction more than once /// has no effect and returns `ok`. /// /// The shutdown function does not close (drop) the socket. @@ -348,6 +381,7 @@ interface tcp { /// - /// - /// - + @since(version = 0.2.0) shutdown: func(shutdown-type: shutdown-type) -> result<_, error-code>; } } diff --git a/tests/go/wasi/wit/deps/sockets/udp-create-socket.wit b/tests/go/wasi/wit/deps/sockets/udp-create-socket.wit index 0482d1f..e8eeacb 100644 --- a/tests/go/wasi/wit/deps/sockets/udp-create-socket.wit +++ b/tests/go/wasi/wit/deps/sockets/udp-create-socket.wit @@ -1,6 +1,8 @@ - +@since(version = 0.2.0) interface udp-create-socket { + @since(version = 0.2.0) use network.{network, error-code, ip-address-family}; + @since(version = 0.2.0) use udp.{udp-socket}; /// Create a new UDP socket. @@ -23,5 +25,6 @@ interface udp-create-socket { /// - /// - /// - + @since(version = 0.2.0) create-udp-socket: func(address-family: ip-address-family) -> result; } diff --git a/tests/go/wasi/wit/deps/sockets/udp.wit b/tests/go/wasi/wit/deps/sockets/udp.wit index d987a0a..b289e49 100644 --- a/tests/go/wasi/wit/deps/sockets/udp.wit +++ b/tests/go/wasi/wit/deps/sockets/udp.wit @@ -1,9 +1,12 @@ - +@since(version = 0.2.0) interface udp { - use wasi:io/poll@0.2.0.{pollable}; + @since(version = 0.2.0) + use wasi:io/poll@0.2.1.{pollable}; + @since(version = 0.2.0) use network.{network, error-code, ip-socket-address, ip-address-family}; /// A received datagram. + @since(version = 0.2.0) record incoming-datagram { /// The payload. /// @@ -19,6 +22,7 @@ interface udp { } /// A datagram to be sent out. + @since(version = 0.2.0) record outgoing-datagram { /// The payload. data: list, @@ -33,9 +37,8 @@ interface udp { remote-address: option, } - - /// A UDP socket handle. + @since(version = 0.2.0) resource udp-socket { /// Bind the socket to a specific network on the provided IP address and port. /// @@ -63,7 +66,9 @@ interface udp { /// - /// - /// - + @since(version = 0.2.0) start-bind: func(network: borrow, local-address: ip-socket-address) -> result<_, error-code>; + @since(version = 0.2.0) finish-bind: func() -> result<_, error-code>; /// Set up inbound & outbound communication channels, optionally to a specific peer. @@ -106,6 +111,7 @@ interface udp { /// - /// - /// - + @since(version = 0.2.0) %stream: func(remote-address: option) -> result, error-code>; /// Get the current bound address. @@ -124,6 +130,7 @@ interface udp { /// - /// - /// - + @since(version = 0.2.0) local-address: func() -> result; /// Get the address the socket is currently streaming to. @@ -136,11 +143,13 @@ interface udp { /// - /// - /// - + @since(version = 0.2.0) remote-address: func() -> result; /// Whether this is a IPv4 or IPv6 socket. /// /// Equivalent to the SO_DOMAIN socket option. + @since(version = 0.2.0) address-family: func() -> ip-address-family; /// Equivalent to the IP_TTL & IPV6_UNICAST_HOPS socket options. @@ -149,7 +158,9 @@ interface udp { /// /// # Typical errors /// - `invalid-argument`: (set) The TTL value must be 1 or higher. + @since(version = 0.2.0) unicast-hop-limit: func() -> result; + @since(version = 0.2.0) set-unicast-hop-limit: func(value: u8) -> result<_, error-code>; /// The kernel buffer space reserved for sends/receives on this socket. @@ -162,18 +173,24 @@ interface udp { /// /// # Typical errors /// - `invalid-argument`: (set) The provided value was 0. + @since(version = 0.2.0) receive-buffer-size: func() -> result; + @since(version = 0.2.0) set-receive-buffer-size: func(value: u64) -> result<_, error-code>; + @since(version = 0.2.0) send-buffer-size: func() -> result; + @since(version = 0.2.0) set-send-buffer-size: func(value: u64) -> result<_, error-code>; /// Create a `pollable` which will resolve once the socket is ready for I/O. /// /// Note: this function is here for WASI Preview2 only. /// It's planned to be removed when `future` is natively supported in Preview3. + @since(version = 0.2.0) subscribe: func() -> pollable; } + @since(version = 0.2.0) resource incoming-datagram-stream { /// Receive messages on the socket. /// @@ -198,15 +215,18 @@ interface udp { /// - /// - /// - + @since(version = 0.2.0) receive: func(max-results: u64) -> result, error-code>; /// Create a `pollable` which will resolve once the stream is ready to receive again. /// /// Note: this function is here for WASI Preview2 only. /// It's planned to be removed when `future` is natively supported in Preview3. + @since(version = 0.2.0) subscribe: func() -> pollable; } + @since(version = 0.2.0) resource outgoing-datagram-stream { /// Check readiness for sending. This function never blocks. /// @@ -255,12 +275,14 @@ interface udp { /// - /// - /// - + @since(version = 0.2.0) send: func(datagrams: list) -> result; /// Create a `pollable` which will resolve once the stream is ready to send again. /// /// Note: this function is here for WASI Preview2 only. /// It's planned to be removed when `future` is natively supported in Preview3. + @since(version = 0.2.0) subscribe: func() -> pollable; } } diff --git a/tests/go/wasi/wit/deps/sockets/world.wit b/tests/go/wasi/wit/deps/sockets/world.wit index f8bb92a..a1d4267 100644 --- a/tests/go/wasi/wit/deps/sockets/world.wit +++ b/tests/go/wasi/wit/deps/sockets/world.wit @@ -1,11 +1,19 @@ -package wasi:sockets@0.2.0; +package wasi:sockets@0.2.1; +@since(version = 0.2.0) world imports { + @since(version = 0.2.0) import instance-network; + @since(version = 0.2.0) import network; + @since(version = 0.2.0) import udp; + @since(version = 0.2.0) import udp-create-socket; + @since(version = 0.2.0) import tcp; + @since(version = 0.2.0) import tcp-create-socket; + @since(version = 0.2.0) import ip-name-lookup; } diff --git a/tests/wit/leftpad/deps/io b/tests/wit/leftpad/deps/io new file mode 120000 index 0000000..24be2f4 --- /dev/null +++ b/tests/wit/leftpad/deps/io @@ -0,0 +1 @@ +../../../../wit/deps/io \ No newline at end of file diff --git a/tests/wit/leftpad/leftpad.wit b/tests/wit/leftpad/leftpad.wit new file mode 100644 index 0000000..1a137ff --- /dev/null +++ b/tests/wit/leftpad/leftpad.wit @@ -0,0 +1,15 @@ +package west-test:leftpad; + +interface leftpad { + use wasi:io/streams@0.2.1.{input-stream, output-stream, stream-error}; + + leftpad: func(in: input-stream, out: borrow, len: u64, c: char) -> result<_, stream-error>; +} + +world guest { + import leftpad; +} + +world host { + export leftpad; +} diff --git a/west.go b/west.go index 31d90a6..98efadf 100644 --- a/west.go +++ b/west.go @@ -1,15 +1,7 @@ -//go:generate cargo build -p west-sys --release -//go:generate cargo build -p west-passthrough --target wasm32-unknown-unknown --release -//go:generate wasm-tools component new target/wasm32-unknown-unknown/release/west_passthrough.wasm -o lib/passthrough.wasm -//go:generate go run github.com/ydnar/wasm-tools-go/cmd/wit-bindgen-go@v0.1.5 generate -w imports -o bindings ./wit +//go:generate go run github.com/bytecodealliance/wasm-tools-go/cmd/wit-bindgen-go generate -w imports -o bindings ./wit package west -// #cgo darwin,amd64 LDFLAGS: -L${SRCDIR}/lib/x86_64-darwin -lwest -// #cgo darwin,arm64 LDFLAGS: -L${SRCDIR}/lib/aarch64-darwin -lwest -// #cgo linux,amd64 LDFLAGS: -L${SRCDIR}/lib/x86_64-linux -lwest -// #cgo linux,arm64 LDFLAGS: -L${SRCDIR}/lib/aarch64-linux -lwest -// #cgo windows,amd64 LDFLAGS: -L${SRCDIR}/lib/x86_64-windows -lwest // #include "./include/west.h" // #include import "C" diff --git a/west_darwin_amd64.go b/west_darwin_amd64.go index 5db51fc..1e5f1af 100644 --- a/west_darwin_amd64.go +++ b/west_darwin_amd64.go @@ -1,3 +1,5 @@ +//go:build !dev + //go:generate cp ./target/release/libwest_sys.a ./lib/x86_64-darwin/libwest.a package west diff --git a/west_darwin_arm64.go b/west_darwin_arm64.go index dd14dc1..cf186ec 100644 --- a/west_darwin_arm64.go +++ b/west_darwin_arm64.go @@ -1,3 +1,5 @@ +//go:build !dev + //go:generate cp ./target/release/libwest_sys.a ./lib/aarch64-darwin/libwest.a package west diff --git a/west_linux_amd64.go b/west_linux_amd64.go index 6ff1c45..c513a93 100644 --- a/west_linux_amd64.go +++ b/west_linux_amd64.go @@ -1,3 +1,5 @@ +//go:build !dev + //go:generate cp ./target/release/libwest_sys.a ./lib/x86_64-linux/libwest.a package west diff --git a/west_linux_arm64.go b/west_linux_arm64.go index 34eb09f..3a24e15 100644 --- a/west_linux_arm64.go +++ b/west_linux_arm64.go @@ -1,3 +1,5 @@ +//go:build !dev + //go:generate cp ./target/release/libwest_sys.a ./lib/aarch64-linux/libwest.a package west diff --git a/west_windows_amd64.go b/west_windows_amd64.go index 6bab720..841669c 100644 --- a/west_windows_amd64.go +++ b/west_windows_amd64.go @@ -1,3 +1,5 @@ +//go:build !dev + //go:generate cp ./target/release/libwest_sys.a ./lib/x86_64-windows/libwest.a package west diff --git a/west_windows_arm64.go b/west_windows_arm64.go new file mode 100644 index 0000000..e4385e1 --- /dev/null +++ b/west_windows_arm64.go @@ -0,0 +1,5 @@ +//go:build !dev + +//go:generate cp ./target/release/libwest_sys.a ./lib/aarch64-windows/libwest.a + +package west diff --git a/wit/deps.lock b/wit/deps.lock index 5bd958b..e861d62 100644 --- a/wit/deps.lock +++ b/wit/deps.lock @@ -1,29 +1,37 @@ [cli] -sha256 = "285865a31d777181b075f39e92bcfe59c89cd6bacce660be1b9a627646956258" -sha512 = "da2622210a9e3eea82b99f1a5b8a44ce5443d009cb943f7bca0bf9cf4360829b289913d7ee727c011f0f72994ea7dc8e661ebcc0a6b34b587297d80cd9b3f7e8" +sha256 = "1de50b8e6940e73110cda10b7f90ca87a8fea886f0fa36c748f96dc70671ee38" +sha512 = "bbb6cd3e7b4d3237b6af9bfbb2633ccd2c4ea2a4f37b8c033255c7e0c1cb037be7f22ec1f8ca792cc8ec1942199582943979e646b4b272b85dcff7654eac51d0" [clocks] -sha256 = "468b4d12892fe926b8eb5d398dbf579d566c93231fa44f415440572c695b7613" -sha512 = "e6b53a07221f1413953c9797c68f08b815fdaebf66419bbc1ea3e8b7dece73731062693634731f311a03957b268cf9cc509c518bd15e513c318aa04a8459b93a" +sha256 = "ea9d69ee803bc176e23e5268f5e24a2ac485dd1f62a0ab4c748e9d3f901f576f" +sha512 = "5efc22927c46cd56c41e5549ec775561c7fac2ea0d365abc0b55396d9475a7c9f984077a81f84a44a726f1c008fd2fadbffffa4fa53ecd5fbfd05afd379ab428" [filesystem] -sha256 = "498c465cfd04587db40f970fff2185daa597d074c20b68a8bcbae558f261499b" -sha512 = "ead452f9b7bfb88593a502ec00d76d4228003d51c40fd0408aebc32d35c94673551b00230d730873361567cc209ec218c41fb4e95bad194268592c49e7964347" +sha256 = "cfe8c420e8b857de612ae2a3336680dae16b95c93c8ba3a6ff05b21210966740" +sha512 = "3c00c5544a58658e3e8025677091685286027fd49f37abf198c30b4e83b9e68f19723975aaa98794fba9f425ae9ef4f3dc0f5b9cf59203b5ecfaadf62b296f9a" [http] -url = "https://github.com/WebAssembly/wasi-http/archive/v0.2.0.tar.gz" -sha256 = "8f44402bde16c48e28c47dc53eab0b26af5b3b3482a1852cf77673e0880ba1c1" -sha512 = "760695f9a25c25bf75a25b731cb21c3bda9e288e450edda823324ecbc73d5d798bbb5de2edad999566980836f037463ee9e57d61789d04b3f3e381475b1a9a0f" -deps = ["cli", "clocks", "filesystem", "io", "random", "sockets"] +sha256 = "ff21e05571af02488371bebc9cb674e30e0613eda22e3c1d8e1aba36cdff5ee8" +sha512 = "1825b56f1718e822acf1b49929ead8f6493752b1d3524ce0974c3acdf656af2fc3fe5c8456b71ffab44583bc3ae7061d5a285d8a7203fcae949d44b3d81e2f2b" + +[httpext] +sha256 = "ef3b33fee59fb0faf1e12306979289b898dee3876a21079144e1a5c1ebab0132" +sha512 = "124cbe0e0c97856d3bdb504ea569c212652fe534abd151d29b7957d3ce59435690ecf885a40c0f389871113db308eb0f9d64f0c73153225d55dad0e86a1b14a9" [io] -sha256 = "7210e5653539a15478f894d4da24cc69d61924cbcba21d2804d69314a88e5a4c" -sha512 = "49184a1b0945a889abd52d25271172ed3dc2db6968fcdddb1bab7ee0081f4a3eeee0977ad2291126a37631c0d86eeea75d822fa8af224c422134500bf9f0f2bb" +sha256 = "2a74bd811adc46b5a0f19827ddbde89870e52b17615f4d0873f06fd977250caf" +sha512 = "94624f00c66e66203592cee820f80b1ba91ecdb71f682c154f25eaf71f8d8954197dcb64503bc21e72ed5e812af7eae876df47b7eb727b02db3a74a7ce0aefca" + +[passthrough] +url = "https://github.com/wasiext/passthrough/archive/main.tar.gz" +sha256 = "2b1d396cb65661c8e72a227b595615bfff852e5e1d11a4c757e2edfd88f2d69e" +sha512 = "24548865215c168b13dc51c92b7a96b34d1d37ac9915f639db1e4e7fd0d4a8feff745d038d526974e28a8a8fe34c45f4a5b19282b522bde09d2d67bf653addfc" +deps = ["cli", "clocks", "filesystem", "http", "httpext", "io", "random", "sockets"] [random] -sha256 = "7371d03c037d924caba2587fb2e7c5773a0d3c5fcecbf7971e0e0ba57973c53d" -sha512 = "964c4e8925a53078e4d94ba907b54f89a0b7e154f46823a505391471466c17f53c8692682e5c85771712acd88b348686173fc07c53a3cfe3d301b8cd8ddd0de4" +sha256 = "9e2d5056186f81b2e7f96bc97d2babd0341840f6abb4f170449b70992f1b598f" +sha512 = "67bf41d8d5d4b7af084124ee85196585225785969059f59e2f9ddb77ac1a8095cfe811ae29d076aac817418fa01064d7b9fbc0233930bace680758eeb21e36f8" [sockets] -sha256 = "622bd28bbeb43736375dc02bd003fd3a016ff8ee91e14bab488325c6b38bf966" -sha512 = "5a63c1f36de0c4548e1d2297bdbededb28721cbad94ef7825c469eae29d7451c97e00b4c1d6730ee1ec0c4a5aac922961a2795762d4a0c3bb54e30a391a84bae" +sha256 = "4c361137a7e61e8b9a73da2a0899dd9ad1a0c2dfee7d310cf168704c57b7a07c" +sha512 = "348b4ef381f57aec23d48537df8b69ab8963587dcb056e94c4cd5657e217677a4ee2a545868a5c829d2334cc6b8b0a61d3e72797999f44d78553fbd3a73c5b8d" diff --git a/wit/deps.toml b/wit/deps.toml index 1b375ee..82f2d86 100644 --- a/wit/deps.toml +++ b/wit/deps.toml @@ -1 +1 @@ -http = "https://github.com/WebAssembly/wasi-http/archive/v0.2.0.tar.gz" +passthrough = "https://github.com/wasiext/passthrough/archive/main.tar.gz" diff --git a/wit/deps/cli/command.wit b/wit/deps/cli/command.wit index d8005bd..dc064a3 100644 --- a/wit/deps/cli/command.wit +++ b/wit/deps/cli/command.wit @@ -1,7 +1,10 @@ -package wasi:cli@0.2.0; +package wasi:cli@0.2.1; +@since(version = 0.2.0) world command { + @since(version = 0.2.0) include imports; + @since(version = 0.2.0) export run; } diff --git a/wit/deps/cli/environment.wit b/wit/deps/cli/environment.wit index 7006523..2f449bd 100644 --- a/wit/deps/cli/environment.wit +++ b/wit/deps/cli/environment.wit @@ -1,3 +1,4 @@ +@since(version = 0.2.0) interface environment { /// Get the POSIX-style environment variables. /// @@ -7,12 +8,15 @@ interface environment { /// Morally, these are a value import, but until value imports are available /// in the component model, this import function should return the same /// values each time it is called. + @since(version = 0.2.0) get-environment: func() -> list>; /// Get the POSIX-style arguments to the program. + @since(version = 0.2.0) get-arguments: func() -> list; /// Return a path that programs should use as their initial current working /// directory, interpreting `.` as shorthand for this. + @since(version = 0.2.0) initial-cwd: func() -> option; } diff --git a/wit/deps/cli/exit.wit b/wit/deps/cli/exit.wit index d0c2b82..427935c 100644 --- a/wit/deps/cli/exit.wit +++ b/wit/deps/cli/exit.wit @@ -1,4 +1,17 @@ +@since(version = 0.2.0) interface exit { /// Exit the current instance and any linked instances. + @since(version = 0.2.0) exit: func(status: result); + + /// Exit the current instance and any linked instances, reporting the + /// specified status code to the host. + /// + /// The meaning of the code depends on the context, with 0 usually meaning + /// "success", and other values indicating various types of failure. + /// + /// This function does not return; the effect is analogous to a trap, but + /// without the connotation that something bad has happened. + @unstable(feature = cli-exit-with-code) + exit-with-code: func(status-code: u8); } diff --git a/wit/deps/cli/imports.wit b/wit/deps/cli/imports.wit index 083b84a..b8339d3 100644 --- a/wit/deps/cli/imports.wit +++ b/wit/deps/cli/imports.wit @@ -1,20 +1,36 @@ -package wasi:cli@0.2.0; +package wasi:cli@0.2.1; +@since(version = 0.2.0) world imports { - include wasi:clocks/imports@0.2.0; - include wasi:filesystem/imports@0.2.0; - include wasi:sockets/imports@0.2.0; - include wasi:random/imports@0.2.0; - include wasi:io/imports@0.2.0; + @since(version = 0.2.0) + include wasi:clocks/imports@0.2.1; + @since(version = 0.2.0) + include wasi:filesystem/imports@0.2.1; + @since(version = 0.2.0) + include wasi:sockets/imports@0.2.1; + @since(version = 0.2.0) + include wasi:random/imports@0.2.1; + @since(version = 0.2.0) + include wasi:io/imports@0.2.1; + @since(version = 0.2.0) import environment; + @since(version = 0.2.0) import exit; + @since(version = 0.2.0) import stdin; + @since(version = 0.2.0) import stdout; + @since(version = 0.2.0) import stderr; + @since(version = 0.2.0) import terminal-input; + @since(version = 0.2.0) import terminal-output; + @since(version = 0.2.0) import terminal-stdin; + @since(version = 0.2.0) import terminal-stdout; + @since(version = 0.2.0) import terminal-stderr; } diff --git a/wit/deps/cli/run.wit b/wit/deps/cli/run.wit index a70ee8c..655346e 100644 --- a/wit/deps/cli/run.wit +++ b/wit/deps/cli/run.wit @@ -1,4 +1,6 @@ +@since(version = 0.2.0) interface run { /// Run the program. + @since(version = 0.2.0) run: func() -> result; } diff --git a/wit/deps/cli/stdio.wit b/wit/deps/cli/stdio.wit index 31ef35b..d1d26eb 100644 --- a/wit/deps/cli/stdio.wit +++ b/wit/deps/cli/stdio.wit @@ -1,17 +1,26 @@ +@since(version = 0.2.0) interface stdin { - use wasi:io/streams@0.2.0.{input-stream}; + @since(version = 0.2.0) + use wasi:io/streams@0.2.1.{input-stream}; + @since(version = 0.2.0) get-stdin: func() -> input-stream; } +@since(version = 0.2.0) interface stdout { - use wasi:io/streams@0.2.0.{output-stream}; + @since(version = 0.2.0) + use wasi:io/streams@0.2.1.{output-stream}; + @since(version = 0.2.0) get-stdout: func() -> output-stream; } +@since(version = 0.2.0) interface stderr { - use wasi:io/streams@0.2.0.{output-stream}; + @since(version = 0.2.0) + use wasi:io/streams@0.2.1.{output-stream}; + @since(version = 0.2.0) get-stderr: func() -> output-stream; } diff --git a/wit/deps/cli/terminal.wit b/wit/deps/cli/terminal.wit index 38c724e..d305498 100644 --- a/wit/deps/cli/terminal.wit +++ b/wit/deps/cli/terminal.wit @@ -3,8 +3,10 @@ /// In the future, this may include functions for disabling echoing, /// disabling input buffering so that keyboard events are sent through /// immediately, querying supported features, and so on. +@since(version = 0.2.0) interface terminal-input { /// The input side of a terminal. + @since(version = 0.2.0) resource terminal-input; } @@ -13,37 +15,48 @@ interface terminal-input { /// In the future, this may include functions for querying the terminal /// size, being notified of terminal size changes, querying supported /// features, and so on. +@since(version = 0.2.0) interface terminal-output { /// The output side of a terminal. + @since(version = 0.2.0) resource terminal-output; } /// An interface providing an optional `terminal-input` for stdin as a /// link-time authority. +@since(version = 0.2.0) interface terminal-stdin { + @since(version = 0.2.0) use terminal-input.{terminal-input}; /// If stdin is connected to a terminal, return a `terminal-input` handle /// allowing further interaction with it. + @since(version = 0.2.0) get-terminal-stdin: func() -> option; } /// An interface providing an optional `terminal-output` for stdout as a /// link-time authority. +@since(version = 0.2.0) interface terminal-stdout { + @since(version = 0.2.0) use terminal-output.{terminal-output}; /// If stdout is connected to a terminal, return a `terminal-output` handle /// allowing further interaction with it. + @since(version = 0.2.0) get-terminal-stdout: func() -> option; } /// An interface providing an optional `terminal-output` for stderr as a /// link-time authority. +@since(version = 0.2.0) interface terminal-stderr { + @since(version = 0.2.0) use terminal-output.{terminal-output}; /// If stderr is connected to a terminal, return a `terminal-output` handle /// allowing further interaction with it. + @since(version = 0.2.0) get-terminal-stderr: func() -> option; } diff --git a/wit/deps/clocks/monotonic-clock.wit b/wit/deps/clocks/monotonic-clock.wit index 4e4dc3a..3c24840 100644 --- a/wit/deps/clocks/monotonic-clock.wit +++ b/wit/deps/clocks/monotonic-clock.wit @@ -1,4 +1,4 @@ -package wasi:clocks@0.2.0; +package wasi:clocks@0.2.1; /// WASI Monotonic Clock is a clock API intended to let users measure elapsed /// time. /// @@ -7,38 +7,43 @@ package wasi:clocks@0.2.0; /// /// A monotonic clock is a clock which has an unspecified initial value, and /// successive reads of the clock will produce non-decreasing values. -/// -/// It is intended for measuring elapsed time. +@since(version = 0.2.0) interface monotonic-clock { - use wasi:io/poll@0.2.0.{pollable}; + @since(version = 0.2.0) + use wasi:io/poll@0.2.1.{pollable}; /// An instant in time, in nanoseconds. An instant is relative to an /// unspecified initial value, and can only be compared to instances from /// the same monotonic-clock. + @since(version = 0.2.0) type instant = u64; /// A duration of time, in nanoseconds. + @since(version = 0.2.0) type duration = u64; /// Read the current value of the clock. /// /// The clock is monotonic, therefore calling this function repeatedly will /// produce a sequence of non-decreasing values. + @since(version = 0.2.0) now: func() -> instant; /// Query the resolution of the clock. Returns the duration of time /// corresponding to a clock tick. + @since(version = 0.2.0) resolution: func() -> duration; /// Create a `pollable` which will resolve once the specified instant - /// occured. + /// has occurred. + @since(version = 0.2.0) subscribe-instant: func( when: instant, ) -> pollable; - /// Create a `pollable` which will resolve once the given duration has - /// elapsed, starting at the time at which this function was called. - /// occured. + /// Create a `pollable` that will resolve after the specified duration has + /// elapsed from the time this function is invoked. + @since(version = 0.2.0) subscribe-duration: func( when: duration, ) -> pollable; diff --git a/wit/deps/clocks/timezone.wit b/wit/deps/clocks/timezone.wit new file mode 100644 index 0000000..212da66 --- /dev/null +++ b/wit/deps/clocks/timezone.wit @@ -0,0 +1,55 @@ +package wasi:clocks@0.2.1; + +@unstable(feature = clocks-timezone) +interface timezone { + @unstable(feature = clocks-timezone) + use wall-clock.{datetime}; + + /// Return information needed to display the given `datetime`. This includes + /// the UTC offset, the time zone name, and a flag indicating whether + /// daylight saving time is active. + /// + /// If the timezone cannot be determined for the given `datetime`, return a + /// `timezone-display` for `UTC` with a `utc-offset` of 0 and no daylight + /// saving time. + @unstable(feature = clocks-timezone) + display: func(when: datetime) -> timezone-display; + + /// The same as `display`, but only return the UTC offset. + @unstable(feature = clocks-timezone) + utc-offset: func(when: datetime) -> s32; + + /// Information useful for displaying the timezone of a specific `datetime`. + /// + /// This information may vary within a single `timezone` to reflect daylight + /// saving time adjustments. + @unstable(feature = clocks-timezone) + record timezone-display { + /// The number of seconds difference between UTC time and the local + /// time of the timezone. + /// + /// The returned value will always be less than 86400 which is the + /// number of seconds in a day (24*60*60). + /// + /// In implementations that do not expose an actual time zone, this + /// should return 0. + utc-offset: s32, + + /// The abbreviated name of the timezone to display to a user. The name + /// `UTC` indicates Coordinated Universal Time. Otherwise, this should + /// reference local standards for the name of the time zone. + /// + /// In implementations that do not expose an actual time zone, this + /// should be the string `UTC`. + /// + /// In time zones that do not have an applicable name, a formatted + /// representation of the UTC offset may be returned, such as `-04:00`. + name: string, + + /// Whether daylight saving time is active. + /// + /// In implementations that do not expose an actual time zone, this + /// should return false. + in-daylight-saving-time: bool, + } +} diff --git a/wit/deps/clocks/wall-clock.wit b/wit/deps/clocks/wall-clock.wit index 440ca0f..6be069a 100644 --- a/wit/deps/clocks/wall-clock.wit +++ b/wit/deps/clocks/wall-clock.wit @@ -1,4 +1,4 @@ -package wasi:clocks@0.2.0; +package wasi:clocks@0.2.1; /// WASI Wall Clock is a clock API intended to let users query the current /// time. The name "wall" makes an analogy to a "clock on the wall", which /// is not necessarily monotonic as it may be reset. @@ -13,8 +13,10 @@ package wasi:clocks@0.2.0; /// monotonic, making it unsuitable for measuring elapsed time. /// /// It is intended for reporting the current date and time for humans. +@since(version = 0.2.0) interface wall-clock { /// A time and date in seconds plus nanoseconds. + @since(version = 0.2.0) record datetime { seconds: u64, nanoseconds: u32, @@ -33,10 +35,12 @@ interface wall-clock { /// /// [POSIX's Seconds Since the Epoch]: https://pubs.opengroup.org/onlinepubs/9699919799/xrat/V4_xbd_chap04.html#tag_21_04_16 /// [Unix Time]: https://en.wikipedia.org/wiki/Unix_time + @since(version = 0.2.0) now: func() -> datetime; /// Query the resolution of the clock. /// /// The nanoseconds field of the output is always less than 1000000000. + @since(version = 0.2.0) resolution: func() -> datetime; } diff --git a/wit/deps/clocks/world.wit b/wit/deps/clocks/world.wit index c022457..9251ac6 100644 --- a/wit/deps/clocks/world.wit +++ b/wit/deps/clocks/world.wit @@ -1,6 +1,11 @@ -package wasi:clocks@0.2.0; +package wasi:clocks@0.2.1; +@since(version = 0.2.0) world imports { + @since(version = 0.2.0) import monotonic-clock; + @since(version = 0.2.0) import wall-clock; + @unstable(feature = clocks-timezone) + import timezone; } diff --git a/wit/deps/filesystem/preopens.wit b/wit/deps/filesystem/preopens.wit index da801f6..ca2f726 100644 --- a/wit/deps/filesystem/preopens.wit +++ b/wit/deps/filesystem/preopens.wit @@ -1,8 +1,11 @@ -package wasi:filesystem@0.2.0; +package wasi:filesystem@0.2.1; +@since(version = 0.2.0) interface preopens { + @since(version = 0.2.0) use types.{descriptor}; /// Return the set of preopened directories, and their path. + @since(version = 0.2.0) get-directories: func() -> list>; } diff --git a/wit/deps/filesystem/types.wit b/wit/deps/filesystem/types.wit index 11108fc..db3d968 100644 --- a/wit/deps/filesystem/types.wit +++ b/wit/deps/filesystem/types.wit @@ -1,4 +1,4 @@ -package wasi:filesystem@0.2.0; +package wasi:filesystem@0.2.1; /// WASI filesystem is a filesystem API primarily intended to let users run WASI /// programs that access their files on their existing filesystems, without /// significant overhead. @@ -23,16 +23,21 @@ package wasi:filesystem@0.2.0; /// [WASI filesystem path resolution]. /// /// [WASI filesystem path resolution]: https://github.com/WebAssembly/wasi-filesystem/blob/main/path-resolution.md +@since(version = 0.2.0) interface types { - use wasi:io/streams@0.2.0.{input-stream, output-stream, error}; - use wasi:clocks/wall-clock@0.2.0.{datetime}; + @since(version = 0.2.0) + use wasi:io/streams@0.2.1.{input-stream, output-stream, error}; + @since(version = 0.2.0) + use wasi:clocks/wall-clock@0.2.1.{datetime}; /// File size or length of a region within a file. + @since(version = 0.2.0) type filesize = u64; /// The type of a filesystem object referenced by a descriptor. /// /// Note: This was called `filetype` in earlier versions of WASI. + @since(version = 0.2.0) enum descriptor-type { /// The type of the descriptor or file is unknown or is different from /// any of the other types specified. @@ -56,6 +61,7 @@ interface types { /// Descriptor flags. /// /// Note: This was called `fdflags` in earlier versions of WASI. + @since(version = 0.2.0) flags descriptor-flags { /// Read mode: Data can be read. read, @@ -77,7 +83,7 @@ interface types { /// WASI. At this time, it should be interpreted as a request, and not a /// requirement. data-integrity-sync, - /// Requests that reads be performed at the same level of integrety + /// Requests that reads be performed at the same level of integrity /// requested for writes. This is similar to `O_RSYNC` in POSIX. /// /// The precise semantics of this operation have not yet been defined for @@ -99,6 +105,7 @@ interface types { /// File attributes. /// /// Note: This was called `filestat` in earlier versions of WASI. + @since(version = 0.2.0) record descriptor-stat { /// File type. %type: descriptor-type, @@ -125,6 +132,7 @@ interface types { } /// Flags determining the method of how paths are resolved. + @since(version = 0.2.0) flags path-flags { /// As long as the resolved path corresponds to a symbolic link, it is /// expanded. @@ -132,6 +140,7 @@ interface types { } /// Open flags used by `open-at`. + @since(version = 0.2.0) flags open-flags { /// Create file if it does not exist, similar to `O_CREAT` in POSIX. create, @@ -144,9 +153,11 @@ interface types { } /// Number of hard links to an inode. + @since(version = 0.2.0) type link-count = u64; /// When setting a timestamp, this gives the value to set it to. + @since(version = 0.2.0) variant new-timestamp { /// Leave the timestamp set to its previous value. no-change, @@ -248,6 +259,7 @@ interface types { } /// File or memory access pattern advisory information. + @since(version = 0.2.0) enum advice { /// The application has no advice to give on its behavior with respect /// to the specified data. @@ -271,6 +283,7 @@ interface types { /// A 128-bit hash value, split into parts because wasm doesn't have a /// 128-bit integer type. + @since(version = 0.2.0) record metadata-hash-value { /// 64 bits of a 128-bit hash value. lower: u64, @@ -281,6 +294,7 @@ interface types { /// A descriptor is a reference to a filesystem object, which may be a file, /// directory, named pipe, special file, or other object on which filesystem /// calls may be made. + @since(version = 0.2.0) resource descriptor { /// Return a stream for reading from a file, if available. /// @@ -290,6 +304,7 @@ interface types { /// file and they do not interfere with each other. /// /// Note: This allows using `read-stream`, which is similar to `read` in POSIX. + @since(version = 0.2.0) read-via-stream: func( /// The offset within the file at which to start reading. offset: filesize, @@ -301,6 +316,7 @@ interface types { /// /// Note: This allows using `write-stream`, which is similar to `write` in /// POSIX. + @since(version = 0.2.0) write-via-stream: func( /// The offset within the file at which to start writing. offset: filesize, @@ -312,11 +328,13 @@ interface types { /// /// Note: This allows using `write-stream`, which is similar to `write` with /// `O_APPEND` in in POSIX. + @since(version = 0.2.0) append-via-stream: func() -> result; /// Provide file advisory information on a descriptor. /// /// This is similar to `posix_fadvise` in POSIX. + @since(version = 0.2.0) advise: func( /// The offset within the file to which the advisory applies. offset: filesize, @@ -332,6 +350,7 @@ interface types { /// opened for writing. /// /// Note: This is similar to `fdatasync` in POSIX. + @since(version = 0.2.0) sync-data: func() -> result<_, error-code>; /// Get flags associated with a descriptor. @@ -340,6 +359,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.2.0) get-flags: func() -> result; /// Get the dynamic type of a descriptor. @@ -352,12 +372,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.2.0) get-type: 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.2.0) set-size: func(size: filesize) -> result<_, error-code>; /// Adjust the timestamps of an open file or directory. @@ -365,6 +387,7 @@ interface types { /// Note: This is similar to `futimens` in POSIX. /// /// Note: This was called `fd_filestat_set_times` in earlier versions of WASI. + @since(version = 0.2.0) set-times: func( /// The desired values of the data access timestamp. data-access-timestamp: new-timestamp, @@ -383,6 +406,7 @@ interface types { /// In the future, this may change to return a `stream`. /// /// Note: This is similar to `pread` in POSIX. + @since(version = 0.2.0) read: func( /// The maximum number of bytes to read. length: filesize, @@ -399,6 +423,7 @@ interface types { /// In the future, this may change to take a `stream`. /// /// Note: This is similar to `pwrite` in POSIX. + @since(version = 0.2.0) write: func( /// Data to write buffer: list, @@ -415,6 +440,7 @@ interface types { /// This always returns a new stream which starts at the beginning of the /// directory. Multiple streams may be active on the same directory, and they /// do not interfere with each other. + @since(version = 0.2.0) read-directory: func() -> result; /// Synchronize the data and metadata of a file to disk. @@ -423,11 +449,13 @@ interface types { /// opened for writing. /// /// Note: This is similar to `fsync` in POSIX. + @since(version = 0.2.0) sync: func() -> result<_, error-code>; /// Create a directory. /// /// Note: This is similar to `mkdirat` in POSIX. + @since(version = 0.2.0) create-directory-at: func( /// The relative path at which to create the directory. path: string, @@ -442,6 +470,7 @@ interface types { /// modified, use `metadata-hash`. /// /// Note: This was called `fd_filestat_get` in earlier versions of WASI. + @since(version = 0.2.0) stat: func() -> result; /// Return the attributes of a file or directory. @@ -451,6 +480,7 @@ interface types { /// discussion of alternatives. /// /// Note: This was called `path_filestat_get` in earlier versions of WASI. + @since(version = 0.2.0) stat-at: func( /// Flags determining the method of how the path is resolved. path-flags: path-flags, @@ -464,6 +494,7 @@ interface types { /// /// Note: This was called `path_filestat_set_times` in earlier versions of /// WASI. + @since(version = 0.2.0) set-times-at: func( /// Flags determining the method of how the path is resolved. path-flags: path-flags, @@ -478,6 +509,7 @@ interface types { /// Create a hard link. /// /// Note: This is similar to `linkat` in POSIX. + @since(version = 0.2.0) link-at: func( /// Flags determining the method of how the path is resolved. old-path-flags: path-flags, @@ -507,6 +539,7 @@ interface types { /// `error-code::read-only`. /// /// Note: This is similar to `openat` in POSIX. + @since(version = 0.2.0) open-at: func( /// Flags determining the method of how the path is resolved. path-flags: path-flags, @@ -524,6 +557,7 @@ interface types { /// filesystem, this function fails with `error-code::not-permitted`. /// /// Note: This is similar to `readlinkat` in POSIX. + @since(version = 0.2.0) readlink-at: func( /// The relative path of the symbolic link from which to read. path: string, @@ -534,6 +568,7 @@ interface types { /// Return `error-code::not-empty` if the directory is not empty. /// /// Note: This is similar to `unlinkat(fd, path, AT_REMOVEDIR)` in POSIX. + @since(version = 0.2.0) remove-directory-at: func( /// The relative path to a directory to remove. path: string, @@ -542,6 +577,7 @@ interface types { /// Rename a filesystem object. /// /// Note: This is similar to `renameat` in POSIX. + @since(version = 0.2.0) rename-at: func( /// The relative source path of the file or directory to rename. old-path: string, @@ -557,6 +593,7 @@ interface types { /// `error-code::not-permitted`. /// /// Note: This is similar to `symlinkat` in POSIX. + @since(version = 0.2.0) symlink-at: func( /// The contents of the symbolic link. old-path: string, @@ -568,6 +605,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.2.0) unlink-file-at: func( /// The relative path to a file to unlink. path: string, @@ -579,6 +617,7 @@ interface types { /// same device (`st_dev`) and inode (`st_ino` or `d_ino`) numbers. /// wasi-filesystem does not expose device and inode numbers, so this function /// may be used instead. + @since(version = 0.2.0) is-same-object: func(other: borrow) -> bool; /// Return a hash of the metadata associated with a filesystem object referred @@ -600,12 +639,14 @@ interface types { /// computed hash. /// /// However, none of these is required. + @since(version = 0.2.0) metadata-hash: 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.2.0) metadata-hash-at: func( /// Flags determining the method of how the path is resolved. path-flags: path-flags, @@ -615,8 +656,10 @@ interface types { } /// A stream of directory entries. + @since(version = 0.2.0) resource directory-entry-stream { /// Read a single directory entry from a `directory-entry-stream`. + @since(version = 0.2.0) read-directory-entry: func() -> result, error-code>; } @@ -630,5 +673,6 @@ interface types { /// /// Note that this function is fallible because not all stream-related /// errors are filesystem-related errors. + @since(version = 0.2.0) filesystem-error-code: func(err: borrow) -> option; } diff --git a/wit/deps/filesystem/world.wit b/wit/deps/filesystem/world.wit index 663f579..af0146c 100644 --- a/wit/deps/filesystem/world.wit +++ b/wit/deps/filesystem/world.wit @@ -1,6 +1,9 @@ -package wasi:filesystem@0.2.0; +package wasi:filesystem@0.2.1; +@since(version = 0.2.0) world imports { + @since(version = 0.2.0) import types; + @since(version = 0.2.0) import preopens; } diff --git a/wit/deps/http/handler.wit b/wit/deps/http/handler.wit index a34a064..6a6c629 100644 --- a/wit/deps/http/handler.wit +++ b/wit/deps/http/handler.wit @@ -1,6 +1,8 @@ /// This interface defines a handler of incoming HTTP Requests. It should /// be exported by components which can respond to HTTP Requests. +@since(version = 0.2.0) interface incoming-handler { + @since(version = 0.2.0) use types.{incoming-request, response-outparam}; /// This function is invoked with an incoming HTTP Request, and a resource @@ -13,6 +15,7 @@ interface incoming-handler { /// The implementor of this function must write a response to the /// `response-outparam` before returning, or else the caller will respond /// with an error on its behalf. + @since(version = 0.2.0) handle: func( request: incoming-request, response-out: response-outparam @@ -21,7 +24,9 @@ interface incoming-handler { /// This interface defines a handler of outgoing HTTP Requests. It should be /// imported by components which wish to make HTTP Requests. +@since(version = 0.2.0) interface outgoing-handler { + @since(version = 0.2.0) use types.{ outgoing-request, request-options, future-incoming-response, error-code }; @@ -36,6 +41,7 @@ interface outgoing-handler { /// This function may return an error if the `outgoing-request` is invalid /// or not allowed to be made. Otherwise, protocol errors are reported /// through the `future-incoming-response`. + @since(version = 0.2.0) handle: func( request: outgoing-request, options: option diff --git a/wit/deps/http/proxy.wit b/wit/deps/http/proxy.wit index 687c24d..415d2ee 100644 --- a/wit/deps/http/proxy.wit +++ b/wit/deps/http/proxy.wit @@ -1,32 +1,50 @@ -package wasi:http@0.2.0; +package wasi:http@0.2.1; -/// The `wasi:http/proxy` world captures a widely-implementable intersection of -/// hosts that includes HTTP forward and reverse proxies. Components targeting -/// this world may concurrently stream in and out any number of incoming and -/// outgoing HTTP requests. -world proxy { +/// The `wasi:http/imports` world imports all the APIs for HTTP proxies. +/// It is intended to be `include`d in other worlds. +@since(version = 0.2.0) +world imports { /// HTTP proxies have access to time and randomness. - include wasi:clocks/imports@0.2.0; - import wasi:random/random@0.2.0; + @since(version = 0.2.0) + import wasi:clocks/monotonic-clock@0.2.1; + @since(version = 0.2.0) + import wasi:clocks/wall-clock@0.2.1; + @since(version = 0.2.0) + import wasi:random/random@0.2.1; /// Proxies have standard output and error streams which are expected to /// terminate in a developer-facing console provided by the host. - import wasi:cli/stdout@0.2.0; - import wasi:cli/stderr@0.2.0; + @since(version = 0.2.0) + import wasi:cli/stdout@0.2.1; + @since(version = 0.2.0) + import wasi:cli/stderr@0.2.1; /// TODO: this is a temporary workaround until component tooling is able to /// gracefully handle the absence of stdin. Hosts must return an eof stream /// for this import, which is what wasi-libc + tooling will do automatically /// when this import is properly removed. - import wasi:cli/stdin@0.2.0; + @since(version = 0.2.0) + import wasi:cli/stdin@0.2.1; /// This is the default handler to use when user code simply wants to make an /// HTTP request (e.g., via `fetch()`). + @since(version = 0.2.0) import outgoing-handler; +} + +/// The `wasi:http/proxy` world captures a widely-implementable intersection of +/// hosts that includes HTTP forward and reverse proxies. Components targeting +/// this world may concurrently stream in and out any number of incoming and +/// outgoing HTTP requests. +@since(version = 0.2.0) +world proxy { + @since(version = 0.2.0) + include imports; /// The host delivers incoming HTTP requests to a component by calling the /// `handle` function of this exported interface. A host may arbitrarily reuse /// or not reuse component instance when delivering incoming HTTP requests and /// thus a component must be able to handle 0..N calls to `handle`. + @since(version = 0.2.0) export incoming-handler; } diff --git a/wit/deps/http/types.wit b/wit/deps/http/types.wit index 755ac6a..3c45cd0 100644 --- a/wit/deps/http/types.wit +++ b/wit/deps/http/types.wit @@ -1,13 +1,19 @@ /// This interface defines all of the types and methods for implementing /// HTTP Requests and Responses, both incoming and outgoing, as well as /// their headers, trailers, and bodies. +@since(version = 0.2.0) interface types { - use wasi:clocks/monotonic-clock@0.2.0.{duration}; - use wasi:io/streams@0.2.0.{input-stream, output-stream}; - use wasi:io/error@0.2.0.{error as io-error}; - use wasi:io/poll@0.2.0.{pollable}; + @since(version = 0.2.0) + use wasi:clocks/monotonic-clock@0.2.1.{duration}; + @since(version = 0.2.0) + use wasi:io/streams@0.2.1.{input-stream, output-stream}; + @since(version = 0.2.0) + use wasi:io/error@0.2.1.{error as io-error}; + @since(version = 0.2.0) + use wasi:io/poll@0.2.1.{pollable}; /// This type corresponds to HTTP standard Methods. + @since(version = 0.2.0) variant method { get, head, @@ -22,6 +28,7 @@ interface types { } /// This type corresponds to HTTP standard Related Schemes. + @since(version = 0.2.0) variant scheme { HTTP, HTTPS, @@ -30,6 +37,7 @@ interface types { /// These cases are inspired by the IANA HTTP Proxy Error Types: /// https://www.iana.org/assignments/http-proxy-status/http-proxy-status.xhtml#table-http-proxy-error-types + @since(version = 0.2.0) variant error-code { DNS-timeout, DNS-error(DNS-error-payload), @@ -78,18 +86,21 @@ interface types { } /// Defines the case payload type for `DNS-error` above: + @since(version = 0.2.0) record DNS-error-payload { rcode: option, info-code: option } /// Defines the case payload type for `TLS-alert-received` above: + @since(version = 0.2.0) record TLS-alert-received-payload { alert-id: option, alert-message: option } /// Defines the case payload type for `HTTP-response-{header,trailer}-size` above: + @since(version = 0.2.0) record field-size-payload { field-name: option, field-size: option @@ -106,10 +117,12 @@ interface types { /// /// Note that this function is fallible because not all io-errors are /// http-related errors. + @since(version = 0.2.0) http-error-code: func(err: borrow) -> option; /// This type enumerates the different kinds of errors that may occur when /// setting or appending to a `fields` resource. + @since(version = 0.2.0) variant header-error { /// This error indicates that a `field-key` or `field-value` was /// syntactically invalid when used with an operation that sets headers in a @@ -126,11 +139,13 @@ interface types { } /// Field keys are always strings. + @since(version = 0.2.0) type field-key = string; /// Field values should always be ASCII strings. However, in /// reality, HTTP implementations often have to interpret malformed values, /// so they are provided as a list of bytes. + @since(version = 0.2.0) type field-value = list; /// This following block defines the `fields` resource which corresponds to @@ -143,11 +158,13 @@ interface types { /// `incoming-request.headers`, `outgoing-request.headers`) might be be /// immutable. In an immutable fields, the `set`, `append`, and `delete` /// operations will fail with `header-error.immutable`. + @since(version = 0.2.0) resource fields { /// Construct an empty HTTP Fields. /// /// The resulting `fields` is mutable. + @since(version = 0.2.0) constructor(); /// Construct an HTTP Fields. @@ -159,42 +176,55 @@ interface types { /// list with the same key. /// /// The tuple is a pair of the field key, represented as a string, and - /// Value, represented as a list of bytes. In a valid Fields, all keys - /// and values are valid UTF-8 strings. However, values are not always - /// well-formed, so they are represented as a raw list of bytes. + /// Value, represented as a list of bytes. /// - /// An error result will be returned if any header or value was - /// syntactically invalid, or if a header was forbidden. + /// An error result will be returned if any `field-key` or `field-value` is + /// syntactically invalid, or if a field is forbidden. + @since(version = 0.2.0) from-list: static func( entries: list> ) -> result; /// Get all of the values corresponding to a key. If the key is not present - /// in this `fields`, an empty list is returned. However, if the key is - /// present but empty, this is represented by a list with one or more - /// empty field-values present. + /// in this `fields` or is syntactically invalid, an empty list is returned. + /// However, if the key is present but empty, this is represented by a list + /// with one or more empty field-values present. + @since(version = 0.2.0) get: func(name: field-key) -> list; /// Returns `true` when the key is present in this `fields`. If the key is /// syntactically invalid, `false` is returned. + @since(version = 0.2.0) has: func(name: field-key) -> bool; /// Set all of the values for a key. Clears any existing values for that /// key, if they have been set. /// /// Fails with `header-error.immutable` if the `fields` are immutable. + /// + /// Fails with `header-error.invalid-syntax` if the `field-key` or any of + /// the `field-value`s are syntactically invalid. + @since(version = 0.2.0) set: func(name: field-key, value: list) -> result<_, header-error>; /// Delete all values for a key. Does nothing if no values for the key /// exist. /// /// Fails with `header-error.immutable` if the `fields` are immutable. + /// + /// Fails with `header-error.invalid-syntax` if the `field-key` is + /// syntactically invalid. + @since(version = 0.2.0) delete: func(name: field-key) -> result<_, header-error>; /// Append a value for a key. Does not change or delete any existing /// values for that key. /// /// Fails with `header-error.immutable` if the `fields` are immutable. + /// + /// Fails with `header-error.invalid-syntax` if the `field-key` or + /// `field-value` are syntactically invalid. + @since(version = 0.2.0) append: func(name: field-key, value: field-value) -> result<_, header-error>; /// Retrieve the full set of keys and values in the Fields. Like the @@ -203,33 +233,42 @@ interface types { /// The outer list represents each key-value pair in the Fields. Keys /// which have multiple values are represented by multiple entries in this /// list with the same key. + @since(version = 0.2.0) entries: func() -> list>; - /// Make a deep copy of the Fields. Equivelant in behavior to calling the + /// Make a deep copy of the Fields. Equivalent in behavior to calling the /// `fields` constructor on the return value of `entries`. The resulting /// `fields` is mutable. + @since(version = 0.2.0) clone: func() -> fields; } /// Headers is an alias for Fields. + @since(version = 0.2.0) type headers = fields; /// Trailers is an alias for Fields. + @since(version = 0.2.0) type trailers = fields; /// Represents an incoming HTTP Request. + @since(version = 0.2.0) resource incoming-request { /// Returns the method of the incoming request. + @since(version = 0.2.0) method: func() -> method; /// Returns the path with query parameters from the request, as a string. + @since(version = 0.2.0) path-with-query: func() -> option; /// Returns the protocol scheme from the request. + @since(version = 0.2.0) scheme: func() -> option; - /// Returns the authority from the request, if it was present. + /// Returns the authority of the Request's target URI, if present. + @since(version = 0.2.0) authority: func() -> option; /// Get the `headers` associated with the request. @@ -240,14 +279,17 @@ interface types { /// The `headers` returned are a child resource: it must be dropped before /// the parent `incoming-request` is dropped. Dropping this /// `incoming-request` before all children are dropped will trap. + @since(version = 0.2.0) headers: func() -> headers; /// Gives the `incoming-body` associated with this request. Will only /// return success at most once, and subsequent calls will return error. + @since(version = 0.2.0) consume: func() -> result; } /// Represents an outgoing HTTP Request. + @since(version = 0.2.0) resource outgoing-request { /// Construct a new `outgoing-request` with a default `method` of `GET`, and @@ -260,6 +302,7 @@ interface types { /// and `authority`, or `headers` which are not permitted to be sent. /// It is the obligation of the `outgoing-handler.handle` implementation /// to reject invalid constructions of `outgoing-request`. + @since(version = 0.2.0) constructor( headers: headers ); @@ -270,38 +313,47 @@ interface types { /// Returns success on the first call: the `outgoing-body` resource for /// this `outgoing-request` can be retrieved at most once. Subsequent /// calls will return error. + @since(version = 0.2.0) body: func() -> result; /// Get the Method for the Request. + @since(version = 0.2.0) method: func() -> method; /// Set the Method for the Request. Fails if the string present in a /// `method.other` argument is not a syntactically valid method. + @since(version = 0.2.0) set-method: func(method: method) -> result; /// Get the combination of the HTTP Path and Query for the Request. /// When `none`, this represents an empty Path and empty Query. + @since(version = 0.2.0) path-with-query: func() -> option; /// Set the combination of the HTTP Path and Query for the Request. /// When `none`, this represents an empty Path and empty Query. Fails is the /// string given is not a syntactically valid path and query uri component. + @since(version = 0.2.0) set-path-with-query: func(path-with-query: option) -> result; /// Get the HTTP Related Scheme for the Request. When `none`, the /// implementation may choose an appropriate default scheme. + @since(version = 0.2.0) scheme: func() -> option; /// Set the HTTP Related Scheme for the Request. When `none`, the /// implementation may choose an appropriate default scheme. Fails if the /// string given is not a syntactically valid uri scheme. + @since(version = 0.2.0) set-scheme: func(scheme: option) -> result; - /// Get the HTTP Authority for the Request. A value of `none` may be used - /// with Related Schemes which do not require an Authority. The HTTP and + /// Get the authority of the Request's target URI. A value of `none` may be used + /// with Related Schemes which do not require an authority. The HTTP and /// HTTPS schemes always require an authority. + @since(version = 0.2.0) authority: func() -> option; - /// Set the HTTP Authority for the Request. A value of `none` may be used - /// with Related Schemes which do not require an Authority. The HTTP and + /// Set the authority of the Request's target URI. A value of `none` may be used + /// with Related Schemes which do not require an authority. The HTTP and /// HTTPS schemes always require an authority. Fails if the string given is - /// not a syntactically valid uri authority. + /// not a syntactically valid URI authority. + @since(version = 0.2.0) set-authority: func(authority: option) -> result; /// Get the headers associated with the Request. @@ -310,8 +362,9 @@ interface types { /// `delete` operations will fail with `header-error.immutable`. /// /// This headers resource is a child: it must be dropped before the parent - /// `outgoing-request` is dropped, or its ownership is transfered to + /// `outgoing-request` is dropped, or its ownership is transferred to /// another component by e.g. `outgoing-handler.handle`. + @since(version = 0.2.0) headers: func() -> headers; } @@ -321,31 +374,39 @@ interface types { /// /// These timeouts are separate from any the user may use to bound a /// blocking call to `wasi:io/poll.poll`. + @since(version = 0.2.0) resource request-options { /// Construct a default `request-options` value. + @since(version = 0.2.0) constructor(); /// The timeout for the initial connect to the HTTP Server. + @since(version = 0.2.0) connect-timeout: func() -> option; /// Set the timeout for the initial connect to the HTTP Server. An error /// return value indicates that this timeout is not supported. + @since(version = 0.2.0) set-connect-timeout: func(duration: option) -> result; /// The timeout for receiving the first byte of the Response body. + @since(version = 0.2.0) first-byte-timeout: func() -> option; /// Set the timeout for receiving the first byte of the Response body. An /// error return value indicates that this timeout is not supported. + @since(version = 0.2.0) set-first-byte-timeout: func(duration: option) -> result; /// The timeout for receiving subsequent chunks of bytes in the Response /// body stream. + @since(version = 0.2.0) between-bytes-timeout: func() -> option; /// Set the timeout for receiving subsequent chunks of bytes in the Response /// body stream. An error return value indicates that this timeout is not /// supported. + @since(version = 0.2.0) set-between-bytes-timeout: func(duration: option) -> result; } @@ -354,6 +415,7 @@ interface types { /// This resource is used by the `wasi:http/incoming-handler` interface to /// allow a Response to be sent corresponding to the Request provided as the /// other argument to `incoming-handler.handle`. + @since(version = 0.2.0) resource response-outparam { /// Set the value of the `response-outparam` to either send a response, @@ -365,6 +427,7 @@ interface types { /// /// The user may provide an `error` to `response` to allow the /// implementation determine how to respond with an HTTP error response. + @since(version = 0.2.0) set: static func( param: response-outparam, response: result, @@ -372,12 +435,15 @@ interface types { } /// This type corresponds to the HTTP standard Status Code. + @since(version = 0.2.0) type status-code = u16; /// Represents an incoming HTTP Response. + @since(version = 0.2.0) resource incoming-response { /// Returns the status code from the incoming response. + @since(version = 0.2.0) status: func() -> status-code; /// Returns the headers from the incoming response. @@ -387,10 +453,12 @@ interface types { /// /// This headers resource is a child: it must be dropped before the parent /// `incoming-response` is dropped. + @since(version = 0.2.0) headers: func() -> headers; /// Returns the incoming body. May be called at most once. Returns error /// if called additional times. + @since(version = 0.2.0) consume: func() -> result; } @@ -402,6 +470,7 @@ interface types { /// an `input-stream` and the delivery of trailers as a `future-trailers`, /// and ensures that the user of this interface may only be consuming either /// the body contents or waiting on trailers at any given time. + @since(version = 0.2.0) resource incoming-body { /// Returns the contents of the body, as a stream of bytes. @@ -419,26 +488,30 @@ interface types { /// backpressure is to be applied when the user is consuming the body, /// and for that backpressure to not inhibit delivery of the trailers if /// the user does not read the entire body. + @since(version = 0.2.0) %stream: func() -> result; /// Takes ownership of `incoming-body`, and returns a `future-trailers`. /// This function will trap if the `input-stream` child is still alive. + @since(version = 0.2.0) finish: static func(this: incoming-body) -> future-trailers; } - /// Represents a future which may eventaully return trailers, or an error. + /// Represents a future which may eventually return trailers, or an error. /// /// In the case that the incoming HTTP Request or Response did not have any /// trailers, this future will resolve to the empty set of trailers once the /// complete Request or Response body has been received. + @since(version = 0.2.0) resource future-trailers { /// Returns a pollable which becomes ready when either the trailers have - /// been received, or an error has occured. When this pollable is ready, + /// been received, or an error has occurred. When this pollable is ready, /// the `get` method will return `some`. + @since(version = 0.2.0) subscribe: func() -> pollable; - /// Returns the contents of the trailers, or an error which occured, + /// Returns the contents of the trailers, or an error which occurred, /// once the future is ready. /// /// The outer `option` represents future readiness. Users can wait on this @@ -450,17 +523,19 @@ interface types { /// /// The inner `result` represents that either the HTTP Request or Response /// body, as well as any trailers, were received successfully, or that an - /// error occured receiving them. The optional `trailers` indicates whether + /// error occurred receiving them. The optional `trailers` indicates whether /// or not trailers were present in the body. /// /// When some `trailers` are returned by this method, the `trailers` /// resource is immutable, and a child. Use of the `set`, `append`, or /// `delete` methods will return an error, and the resource must be /// dropped before the parent `future-trailers` is dropped. + @since(version = 0.2.0) get: func() -> option, error-code>>>; } /// Represents an outgoing HTTP Response. + @since(version = 0.2.0) resource outgoing-response { /// Construct an `outgoing-response`, with a default `status-code` of `200`. @@ -468,13 +543,16 @@ interface types { /// `set-status-code` method. /// /// * `headers` is the HTTP Headers for the Response. + @since(version = 0.2.0) constructor(headers: headers); /// Get the HTTP Status Code for the Response. + @since(version = 0.2.0) status-code: func() -> status-code; /// Set the HTTP Status Code for the Response. Fails if the status-code /// given is not a valid http status code. + @since(version = 0.2.0) set-status-code: func(status-code: status-code) -> result; /// Get the headers associated with the Request. @@ -483,8 +561,9 @@ interface types { /// `delete` operations will fail with `header-error.immutable`. /// /// This headers resource is a child: it must be dropped before the parent - /// `outgoing-request` is dropped, or its ownership is transfered to + /// `outgoing-request` is dropped, or its ownership is transferred to /// another component by e.g. `outgoing-handler.handle`. + @since(version = 0.2.0) headers: func() -> headers; /// Returns the resource corresponding to the outgoing Body for this Response. @@ -492,6 +571,7 @@ interface types { /// Returns success on the first call: the `outgoing-body` resource for /// this `outgoing-response` can be retrieved at most once. Subsequent /// calls will return error. + @since(version = 0.2.0) body: func() -> result; } @@ -507,10 +587,11 @@ interface types { /// /// If the user code drops this resource, as opposed to calling the static /// method `finish`, the implementation should treat the body as incomplete, - /// and that an error has occured. The implementation should propogate this + /// and that an error has occurred. The implementation should propagate this /// error to the HTTP protocol by whatever means it has available, /// including: corrupting the body on the wire, aborting the associated /// Request, or sending a late status code for the Response. + @since(version = 0.2.0) resource outgoing-body { /// Returns a stream for writing the body contents. @@ -522,6 +603,7 @@ interface types { /// Returns success on the first call: the `output-stream` resource for /// this `outgoing-body` may be retrieved at most once. Subsequent calls /// will return error. + @since(version = 0.2.0) write: func() -> result; /// Finalize an outgoing body, optionally providing trailers. This must be @@ -533,21 +615,24 @@ interface types { /// constructed with a Content-Length header, and the contents written /// to the body (via `write`) does not match the value given in the /// Content-Length. + @since(version = 0.2.0) finish: static func( this: outgoing-body, trailers: option ) -> result<_, error-code>; } - /// Represents a future which may eventaully return an incoming HTTP + /// Represents a future which may eventually return an incoming HTTP /// Response, or an error. /// /// This resource is returned by the `wasi:http/outgoing-handler` interface to /// provide the HTTP Response corresponding to the sent Request. + @since(version = 0.2.0) resource future-incoming-response { /// Returns a pollable which becomes ready when either the Response has - /// been received, or an error has occured. When this pollable is ready, + /// been received, or an error has occurred. When this pollable is ready, /// the `get` method will return `some`. + @since(version = 0.2.0) subscribe: func() -> pollable; /// Returns the incoming HTTP Response, or an error, once one is ready. @@ -560,11 +645,11 @@ interface types { /// is `some`, and error on subsequent calls. /// /// The inner `result` represents that either the incoming HTTP Response - /// status and headers have recieved successfully, or that an error - /// occured. Errors may also occur while consuming the response body, + /// status and headers have received successfully, or that an error + /// occurred. Errors may also occur while consuming the response body, /// but those will be reported by the `incoming-body` and its /// `output-stream` child. + @since(version = 0.2.0) get: func() -> option>>; - } } diff --git a/wit/deps/httpext/http.wit b/wit/deps/httpext/http.wit new file mode 100644 index 0000000..ee133db --- /dev/null +++ b/wit/deps/httpext/http.wit @@ -0,0 +1,17 @@ +package wasiext:http@0.1.0; + +interface ext { + use wasi:http/types@0.2.1.{response-outparam, future-incoming-response, incoming-request, outgoing-request}; + + new-response-outparam: func() -> tuple; + new-incoming-request: func(req: outgoing-request) -> incoming-request; +} + +world imports { + import ext; +} + +world proxy { + import ext; + export ext; +} diff --git a/wit/deps/io/error.wit b/wit/deps/io/error.wit index 22e5b64..4ea29c4 100644 --- a/wit/deps/io/error.wit +++ b/wit/deps/io/error.wit @@ -1,6 +1,6 @@ -package wasi:io@0.2.0; - +package wasi:io@0.2.1; +@since(version = 0.2.0) interface error { /// A resource which represents some error information. /// @@ -11,16 +11,15 @@ interface error { /// `wasi:io/streams/stream-error` type. /// /// To provide more specific error information, other interfaces may - /// provide functions to further "downcast" this error into more specific - /// error information. For example, `error`s returned in streams derived - /// from filesystem types to be described using the filesystem's own - /// error-code type, using the function - /// `wasi:filesystem/types/filesystem-error-code`, which takes a parameter - /// `borrow` and returns - /// `option`. + /// offer functions to "downcast" this error into more specific types. For example, + /// errors returned from streams derived from filesystem types can be described using + /// the filesystem's own error-code type. This is done using the function + /// `wasi:filesystem/types/filesystem-error-code`, which takes a `borrow` + /// parameter and returns an `option`. /// /// The set of functions which can "downcast" an `error` into a more /// concrete type is open. + @since(version = 0.2.0) resource error { /// Returns a string that is suitable to assist humans in debugging /// this error. @@ -29,6 +28,7 @@ interface error { /// It may change across platforms, hosts, or other implementation /// details. Parsing this string is a major platform-compatibility /// hazard. + @since(version = 0.2.0) to-debug-string: func() -> string; } } diff --git a/wit/deps/io/poll.wit b/wit/deps/io/poll.wit index ddc67f8..b25ac72 100644 --- a/wit/deps/io/poll.wit +++ b/wit/deps/io/poll.wit @@ -1,14 +1,17 @@ -package wasi:io@0.2.0; +package wasi:io@0.2.1; /// A poll API intended to let users wait for I/O events on multiple handles /// at once. +@since(version = 0.2.0) interface poll { /// `pollable` represents a single I/O event which may be ready, or not. + @since(version = 0.2.0) resource pollable { /// Return the readiness of a pollable. This function never blocks. /// /// Returns `true` when the pollable is ready, and `false` otherwise. + @since(version = 0.2.0) ready: func() -> bool; /// `block` returns immediately if the pollable is ready, and otherwise @@ -16,6 +19,7 @@ interface poll { /// /// This function is equivalent to calling `poll.poll` on a list /// containing only this pollable. + @since(version = 0.2.0) block: func(); } @@ -27,8 +31,9 @@ interface poll { /// The result `list` contains one or more indices of handles in the /// argument list that is ready for I/O. /// - /// If the list contains more elements than can be indexed with a `u32` - /// value, this function traps. + /// This function traps if either: + /// - the list is empty, or: + /// - the list contains more elements than can be indexed with a `u32` value. /// /// A timeout can be implemented by adding a pollable from the /// wasi-clocks API to the list. @@ -36,6 +41,7 @@ interface poll { /// This function does not return a `result`; polling in itself does not /// do any I/O so it doesn't fail. If any of the I/O sources identified by /// the pollables has an error, it is indicated by marking the source as - /// being reaedy for I/O. + /// being ready for I/O. + @since(version = 0.2.0) poll: func(in: list>) -> list; } diff --git a/wit/deps/io/streams.wit b/wit/deps/io/streams.wit index 6d2f871..b697e24 100644 --- a/wit/deps/io/streams.wit +++ b/wit/deps/io/streams.wit @@ -1,15 +1,19 @@ -package wasi:io@0.2.0; +package wasi:io@0.2.1; /// WASI I/O is an I/O abstraction API which is currently focused on providing /// stream types. /// /// In the future, the component model is expected to add built-in stream types; /// when it does, they are expected to subsume this API. +@since(version = 0.2.0) interface streams { + @since(version = 0.2.0) use error.{error}; + @since(version = 0.2.0) use poll.{pollable}; /// An error for input-stream and output-stream operations. + @since(version = 0.2.0) variant stream-error { /// The last operation (a write or flush) failed before completion. /// @@ -29,6 +33,7 @@ interface streams { /// available, which could even be zero. To wait for data to be available, /// use the `subscribe` function to obtain a `pollable` which can be polled /// for using `wasi:io/poll`. + @since(version = 0.2.0) resource input-stream { /// Perform a non-blocking read from the stream. /// @@ -56,6 +61,7 @@ interface streams { /// is not possible to allocate in wasm32, or not desirable to allocate as /// as a return value by the callee. The callee may return a list of bytes /// less than `len` in size while more bytes are available for reading. + @since(version = 0.2.0) read: func( /// The maximum number of bytes to read len: u64 @@ -63,6 +69,7 @@ interface streams { /// Read bytes from a stream, after blocking until at least one byte can /// be read. Except for blocking, behavior is identical to `read`. + @since(version = 0.2.0) blocking-read: func( /// The maximum number of bytes to read len: u64 @@ -72,6 +79,7 @@ interface streams { /// /// Behaves identical to `read`, except instead of returning a list /// of bytes, returns the number of bytes consumed from the stream. + @since(version = 0.2.0) skip: func( /// The maximum number of bytes to skip. len: u64, @@ -79,6 +87,7 @@ interface streams { /// Skip bytes from a stream, after blocking until at least one byte /// can be skipped. Except for blocking behavior, identical to `skip`. + @since(version = 0.2.0) blocking-skip: func( /// The maximum number of bytes to skip. len: u64, @@ -90,6 +99,7 @@ interface streams { /// The created `pollable` is a child resource of the `input-stream`. /// Implementations may trap if the `input-stream` is dropped before /// all derived `pollable`s created with this function are dropped. + @since(version = 0.2.0) subscribe: func() -> pollable; } @@ -102,6 +112,11 @@ interface streams { /// promptly, which could even be zero. To wait for the stream to be ready to /// accept data, the `subscribe` function to obtain a `pollable` which can be /// polled for using `wasi:io/poll`. + /// + /// Dropping an `output-stream` while there's still an active write in + /// progress may result in the data being lost. Before dropping the stream, + /// be sure to fully flush your writes. + @since(version = 0.2.0) resource output-stream { /// Check readiness for writing. This function never blocks. /// @@ -112,6 +127,7 @@ interface streams { /// When this function returns 0 bytes, the `subscribe` pollable will /// become ready when this function will report at least 1 byte, or an /// error. + @since(version = 0.2.0) check-write: func() -> result; /// Perform a write. This function never blocks. @@ -127,6 +143,7 @@ interface streams { /// /// returns Err(closed) without writing if the stream has closed since /// the last call to check-write provided a permit. + @since(version = 0.2.0) write: func( contents: list ) -> result<_, stream-error>; @@ -155,6 +172,7 @@ interface streams { /// // Check for any errors that arose during `flush` /// let _ = this.check-write(); // eliding error handling /// ``` + @since(version = 0.2.0) blocking-write-and-flush: func( contents: list ) -> result<_, stream-error>; @@ -169,14 +187,16 @@ interface streams { /// writes (`check-write` will return `ok(0)`) until the flush has /// completed. The `subscribe` pollable will become ready when the /// flush has completed and the stream can accept more writes. + @since(version = 0.2.0) flush: func() -> result<_, stream-error>; /// Request to flush buffered output, and block until flush completes /// and stream is ready for writing again. + @since(version = 0.2.0) blocking-flush: func() -> result<_, stream-error>; /// Create a `pollable` which will resolve once the output-stream - /// is ready for more writing, or an error has occured. When this + /// is ready for more writing, or an error has occurred. When this /// pollable is ready, `check-write` will return `ok(n)` with n>0, or an /// error. /// @@ -193,6 +213,7 @@ interface streams { /// preconditions (must use check-write first), but instead of /// passing a list of bytes, you simply pass the number of zero-bytes /// that should be written. + @since(version = 0.2.0) write-zeroes: func( /// The number of zero-bytes to write len: u64 @@ -222,6 +243,7 @@ interface streams { /// // Check for any errors that arose during `flush` /// let _ = this.check-write(); // eliding error handling /// ``` + @since(version = 0.2.0) blocking-write-zeroes-and-flush: func( /// The number of zero-bytes to write len: u64 @@ -229,7 +251,7 @@ interface streams { /// Read from one stream and write to another. /// - /// The behavior of splice is equivelant to: + /// The behavior of splice is equivalent to: /// 1. calling `check-write` on the `output-stream` /// 2. calling `read` on the `input-stream` with the smaller of the /// `check-write` permitted length and the `len` provided to `splice` @@ -240,6 +262,7 @@ interface streams { /// /// This function returns the number of bytes transferred; it may be less /// than `len`. + @since(version = 0.2.0) splice: func( /// The stream to read from src: borrow, @@ -252,6 +275,7 @@ interface streams { /// This is similar to `splice`, except that it blocks until the /// `output-stream` is ready for writing, and the `input-stream` /// is ready for reading, before performing the `splice`. + @since(version = 0.2.0) blocking-splice: func( /// The stream to read from src: borrow, diff --git a/wit/deps/io/world.wit b/wit/deps/io/world.wit index 5f0b43f..6405a4e 100644 --- a/wit/deps/io/world.wit +++ b/wit/deps/io/world.wit @@ -1,6 +1,10 @@ -package wasi:io@0.2.0; +package wasi:io@0.2.1; +@since(version = 0.2.0) world imports { + @since(version = 0.2.0) import streams; + + @since(version = 0.2.0) import poll; } diff --git a/wit/deps/passthrough/passthrough.wit b/wit/deps/passthrough/passthrough.wit new file mode 100644 index 0000000..76a4faf --- /dev/null +++ b/wit/deps/passthrough/passthrough.wit @@ -0,0 +1,61 @@ +package wasiext:passthrough@0.1.0; + +world passthrough { + export wasi:cli/environment@0.2.1; + export wasi:cli/exit@0.2.1; + export wasi:cli/stderr@0.2.1; + export wasi:cli/stdin@0.2.1; + export wasi:cli/stdout@0.2.1; + export wasi:cli/terminal-input@0.2.1; + export wasi:cli/terminal-output@0.2.1; + export wasi:cli/terminal-stderr@0.2.1; + export wasi:cli/terminal-stdin@0.2.1; + export wasi:cli/terminal-stdout@0.2.1; + export wasi:clocks/monotonic-clock@0.2.1; + export wasi:filesystem/preopens@0.2.1; + export wasi:filesystem/types@0.2.1; + export wasi:http/outgoing-handler@0.2.1; + export wasi:http/types@0.2.1; + export wasi:io/error@0.2.1; + export wasi:io/poll@0.2.1; + export wasi:io/streams@0.2.1; + export wasi:random/insecure-seed@0.2.1; + export wasi:random/insecure@0.2.1; + export wasi:random/random@0.2.1; + export wasi:sockets/instance-network@0.2.1; + export wasi:sockets/ip-name-lookup@0.2.1; + export wasi:sockets/tcp-create-socket@0.2.1; + export wasi:sockets/tcp@0.2.1; + export wasi:sockets/udp-create-socket@0.2.1; + export wasi:sockets/udp@0.2.1; + + import wasi:cli/environment@0.2.1; + import wasi:cli/exit@0.2.1; + import wasi:cli/stderr@0.2.1; + import wasi:cli/stdin@0.2.1; + import wasi:cli/stdout@0.2.1; + import wasi:cli/terminal-input@0.2.1; + import wasi:cli/terminal-output@0.2.1; + import wasi:cli/terminal-stderr@0.2.1; + import wasi:cli/terminal-stdin@0.2.1; + import wasi:cli/terminal-stdout@0.2.1; + import wasi:clocks/monotonic-clock@0.2.1; + import wasi:filesystem/preopens@0.2.1; + import wasi:filesystem/types@0.2.1; + import wasi:http/outgoing-handler@0.2.1; + import wasi:http/types@0.2.1; + import wasi:io/error@0.2.1; + import wasi:io/poll@0.2.1; + import wasi:io/streams@0.2.1; + import wasi:random/insecure-seed@0.2.1; + import wasi:random/insecure@0.2.1; + import wasi:random/random@0.2.1; + import wasi:sockets/instance-network@0.2.1; + import wasi:sockets/ip-name-lookup@0.2.1; + import wasi:sockets/tcp-create-socket@0.2.1; + import wasi:sockets/tcp@0.2.1; + import wasi:sockets/udp-create-socket@0.2.1; + import wasi:sockets/udp@0.2.1; + + include wasiext:http/proxy@0.1.0; +} diff --git a/wit/deps/random/insecure-seed.wit b/wit/deps/random/insecure-seed.wit index 47210ac..7e708dc 100644 --- a/wit/deps/random/insecure-seed.wit +++ b/wit/deps/random/insecure-seed.wit @@ -1,8 +1,9 @@ -package wasi:random@0.2.0; +package wasi:random@0.2.1; /// The insecure-seed interface for seeding hash-map DoS resistance. /// /// It is intended to be portable at least between Unix-family platforms and /// Windows. +@since(version = 0.2.0) interface insecure-seed { /// Return a 128-bit value that may contain a pseudo-random value. /// @@ -21,5 +22,6 @@ interface insecure-seed { /// This will likely be changed to a value import, to prevent it from being /// called multiple times and potentially used for purposes other than DoS /// protection. + @since(version = 0.2.0) insecure-seed: func() -> tuple; } diff --git a/wit/deps/random/insecure.wit b/wit/deps/random/insecure.wit index c58f4ee..3cdb53d 100644 --- a/wit/deps/random/insecure.wit +++ b/wit/deps/random/insecure.wit @@ -1,8 +1,9 @@ -package wasi:random@0.2.0; +package wasi:random@0.2.1; /// The insecure interface for insecure pseudo-random numbers. /// /// It is intended to be portable at least between Unix-family platforms and /// Windows. +@since(version = 0.2.0) interface insecure { /// Return `len` insecure pseudo-random bytes. /// @@ -12,11 +13,13 @@ interface insecure { /// There are no requirements on the values of the returned bytes, however /// implementations are encouraged to return evenly distributed values with /// a long period. + @since(version = 0.2.0) get-insecure-random-bytes: func(len: u64) -> list; /// Return an insecure pseudo-random `u64` value. /// /// This function returns the same type of pseudo-random data as /// `get-insecure-random-bytes`, represented as a `u64`. + @since(version = 0.2.0) get-insecure-random-u64: func() -> u64; } diff --git a/wit/deps/random/random.wit b/wit/deps/random/random.wit index 0c017f0..2b5035d 100644 --- a/wit/deps/random/random.wit +++ b/wit/deps/random/random.wit @@ -1,8 +1,9 @@ -package wasi:random@0.2.0; +package wasi:random@0.2.1; /// WASI Random is a random data API. /// /// It is intended to be portable at least between Unix-family platforms and /// Windows. +@since(version = 0.2.0) interface random { /// Return `len` cryptographically-secure random or pseudo-random bytes. /// @@ -16,11 +17,13 @@ interface random { /// This function must always return fresh data. Deterministic environments /// must omit this function, rather than implementing it with deterministic /// data. + @since(version = 0.2.0) get-random-bytes: func(len: u64) -> list; /// Return a cryptographically-secure random or pseudo-random `u64` value. /// /// This function returns the same type of data as `get-random-bytes`, /// represented as a `u64`. + @since(version = 0.2.0) get-random-u64: func() -> u64; } diff --git a/wit/deps/random/world.wit b/wit/deps/random/world.wit index 3da3491..c615e96 100644 --- a/wit/deps/random/world.wit +++ b/wit/deps/random/world.wit @@ -1,7 +1,13 @@ -package wasi:random@0.2.0; +package wasi:random@0.2.1; +@since(version = 0.2.0) world imports { + @since(version = 0.2.0) import random; + + @since(version = 0.2.0) import insecure; + + @since(version = 0.2.0) import insecure-seed; } diff --git a/wit/deps/sockets/instance-network.wit b/wit/deps/sockets/instance-network.wit index e455d0f..5f6e6c1 100644 --- a/wit/deps/sockets/instance-network.wit +++ b/wit/deps/sockets/instance-network.wit @@ -1,9 +1,11 @@ /// This interface provides a value-export of the default network handle.. +@since(version = 0.2.0) interface instance-network { + @since(version = 0.2.0) use network.{network}; /// Get a handle to the default network. + @since(version = 0.2.0) instance-network: func() -> network; - } diff --git a/wit/deps/sockets/ip-name-lookup.wit b/wit/deps/sockets/ip-name-lookup.wit index 8e639ec..dc56f30 100644 --- a/wit/deps/sockets/ip-name-lookup.wit +++ b/wit/deps/sockets/ip-name-lookup.wit @@ -1,9 +1,10 @@ - +@since(version = 0.2.0) interface ip-name-lookup { - use wasi:io/poll@0.2.0.{pollable}; + @since(version = 0.2.0) + use wasi:io/poll@0.2.1.{pollable}; + @since(version = 0.2.0) use network.{network, error-code, ip-address}; - /// Resolve an internet host name to a list of IP addresses. /// /// Unicode domain names are automatically converted to ASCII using IDNA encoding. @@ -24,8 +25,10 @@ interface ip-name-lookup { /// - /// - /// - + @since(version = 0.2.0) resolve-addresses: func(network: borrow, name: string) -> result; + @since(version = 0.2.0) resource resolve-address-stream { /// Returns the next address from the resolver. /// @@ -40,12 +43,14 @@ interface ip-name-lookup { /// - `temporary-resolver-failure`: A temporary failure in name resolution occurred. (EAI_AGAIN) /// - `permanent-resolver-failure`: A permanent failure in name resolution occurred. (EAI_FAIL) /// - `would-block`: A result is not available yet. (EWOULDBLOCK, EAGAIN) + @since(version = 0.2.0) resolve-next-address: func() -> result, error-code>; /// Create a `pollable` which will resolve once the stream is ready for I/O. /// /// Note: this function is here for WASI Preview2 only. /// It's planned to be removed when `future` is natively supported in Preview3. + @since(version = 0.2.0) subscribe: func() -> pollable; } } diff --git a/wit/deps/sockets/network.wit b/wit/deps/sockets/network.wit index 9cadf06..8c13b34 100644 --- a/wit/deps/sockets/network.wit +++ b/wit/deps/sockets/network.wit @@ -1,8 +1,9 @@ - +@since(version = 0.2.0) interface network { /// An opaque resource that represents access to (a subset of) the network. /// This enables context-based security for networking. /// There is no need for this to map 1:1 to a physical network interface. + @since(version = 0.2.0) resource network; /// Error codes. @@ -17,6 +18,7 @@ interface network { /// - `concurrency-conflict` /// /// See each individual API for what the POSIX equivalents are. They sometimes differ per API. + @since(version = 0.2.0) enum error-code { /// Unknown error unknown, @@ -103,6 +105,7 @@ interface network { permanent-resolver-failure, } + @since(version = 0.2.0) enum ip-address-family { /// Similar to `AF_INET` in POSIX. ipv4, @@ -111,14 +114,18 @@ interface network { ipv6, } + @since(version = 0.2.0) type ipv4-address = tuple; + @since(version = 0.2.0) type ipv6-address = tuple; + @since(version = 0.2.0) variant ip-address { ipv4(ipv4-address), ipv6(ipv6-address), } + @since(version = 0.2.0) record ipv4-socket-address { /// sin_port port: u16, @@ -126,6 +133,7 @@ interface network { address: ipv4-address, } + @since(version = 0.2.0) record ipv6-socket-address { /// sin6_port port: u16, @@ -137,9 +145,9 @@ interface network { scope-id: u32, } + @since(version = 0.2.0) variant ip-socket-address { ipv4(ipv4-socket-address), ipv6(ipv6-socket-address), } - } diff --git a/wit/deps/sockets/tcp-create-socket.wit b/wit/deps/sockets/tcp-create-socket.wit index c7ddf1f..eedbd30 100644 --- a/wit/deps/sockets/tcp-create-socket.wit +++ b/wit/deps/sockets/tcp-create-socket.wit @@ -1,6 +1,8 @@ - +@since(version = 0.2.0) interface tcp-create-socket { + @since(version = 0.2.0) use network.{network, error-code, ip-address-family}; + @since(version = 0.2.0) use tcp.{tcp-socket}; /// Create a new TCP socket. @@ -23,5 +25,6 @@ interface tcp-create-socket { /// - /// - /// - + @since(version = 0.2.0) create-tcp-socket: func(address-family: ip-address-family) -> result; } diff --git a/wit/deps/sockets/tcp.wit b/wit/deps/sockets/tcp.wit index 5902b9e..bae5a29 100644 --- a/wit/deps/sockets/tcp.wit +++ b/wit/deps/sockets/tcp.wit @@ -1,10 +1,15 @@ - +@since(version = 0.2.0) interface tcp { - use wasi:io/streams@0.2.0.{input-stream, output-stream}; - use wasi:io/poll@0.2.0.{pollable}; - use wasi:clocks/monotonic-clock@0.2.0.{duration}; + @since(version = 0.2.0) + use wasi:io/streams@0.2.1.{input-stream, output-stream}; + @since(version = 0.2.0) + use wasi:io/poll@0.2.1.{pollable}; + @since(version = 0.2.0) + use wasi:clocks/monotonic-clock@0.2.1.{duration}; + @since(version = 0.2.0) use network.{network, error-code, ip-socket-address, ip-address-family}; + @since(version = 0.2.0) enum shutdown-type { /// Similar to `SHUT_RD` in POSIX. receive, @@ -27,8 +32,8 @@ interface tcp { /// - `connect-in-progress` /// - `connected` /// - `closed` - /// See - /// for a more information. + /// See + /// for more information. /// /// Note: Except where explicitly mentioned, whenever this documentation uses /// the term "bound" without backticks it actually means: in the `bound` state *or higher*. @@ -37,6 +42,7 @@ interface tcp { /// In addition to the general error codes documented on the /// `network::error-code` type, TCP socket methods may always return /// `error(invalid-state)` when in the `closed` state. + @since(version = 0.2.0) resource tcp-socket { /// Bind the socket to a specific network on the provided IP address and port. /// @@ -76,13 +82,15 @@ interface tcp { /// - /// - /// - + @since(version = 0.2.0) start-bind: func(network: borrow, local-address: ip-socket-address) -> result<_, error-code>; + @since(version = 0.2.0) finish-bind: func() -> result<_, error-code>; /// Connect to a remote endpoint. /// /// On success: - /// - the socket is transitioned into the `connection` state. + /// - the socket is transitioned into the `connected` state. /// - a pair of streams is returned that can be used to read & write to the connection /// /// After a failed connection attempt, the socket will be in the `closed` @@ -121,7 +129,9 @@ interface tcp { /// - /// - /// - + @since(version = 0.2.0) start-connect: func(network: borrow, remote-address: ip-socket-address) -> result<_, error-code>; + @since(version = 0.2.0) finish-connect: func() -> result, error-code>; /// Start listening for new connections. @@ -149,7 +159,9 @@ interface tcp { /// - /// - /// - + @since(version = 0.2.0) start-listen: func() -> result<_, error-code>; + @since(version = 0.2.0) finish-listen: func() -> result<_, error-code>; /// Accept a new client socket. @@ -178,6 +190,7 @@ interface tcp { /// - /// - /// - + @since(version = 0.2.0) accept: func() -> result, error-code>; /// Get the bound local address. @@ -196,6 +209,7 @@ interface tcp { /// - /// - /// - + @since(version = 0.2.0) local-address: func() -> result; /// Get the remote address. @@ -208,16 +222,19 @@ interface tcp { /// - /// - /// - + @since(version = 0.2.0) remote-address: func() -> result; /// Whether the socket is in the `listening` state. /// /// Equivalent to the SO_ACCEPTCONN socket option. + @since(version = 0.2.0) is-listening: func() -> bool; /// Whether this is a IPv4 or IPv6 socket. /// /// Equivalent to the SO_DOMAIN socket option. + @since(version = 0.2.0) address-family: func() -> ip-address-family; /// Hints the desired listen queue size. Implementations are free to ignore this. @@ -229,6 +246,7 @@ interface tcp { /// - `not-supported`: (set) The platform does not support changing the backlog size after the initial listen. /// - `invalid-argument`: (set) The provided value was 0. /// - `invalid-state`: (set) The socket is in the `connect-in-progress` or `connected` state. + @since(version = 0.2.0) set-listen-backlog-size: func(value: u64) -> result<_, error-code>; /// Enables or disables keepalive. @@ -240,7 +258,9 @@ interface tcp { /// These properties can be configured while `keep-alive-enabled` is false, but only come into effect when `keep-alive-enabled` is true. /// /// Equivalent to the SO_KEEPALIVE socket option. + @since(version = 0.2.0) keep-alive-enabled: func() -> result; + @since(version = 0.2.0) set-keep-alive-enabled: func(value: bool) -> result<_, error-code>; /// Amount of time the connection has to be idle before TCP starts sending keepalive packets. @@ -253,7 +273,9 @@ interface tcp { /// /// # Typical errors /// - `invalid-argument`: (set) The provided value was 0. + @since(version = 0.2.0) keep-alive-idle-time: func() -> result; + @since(version = 0.2.0) set-keep-alive-idle-time: func(value: duration) -> result<_, error-code>; /// The time between keepalive packets. @@ -266,7 +288,9 @@ interface tcp { /// /// # Typical errors /// - `invalid-argument`: (set) The provided value was 0. + @since(version = 0.2.0) keep-alive-interval: func() -> result; + @since(version = 0.2.0) set-keep-alive-interval: func(value: duration) -> result<_, error-code>; /// The maximum amount of keepalive packets TCP should send before aborting the connection. @@ -279,7 +303,9 @@ interface tcp { /// /// # Typical errors /// - `invalid-argument`: (set) The provided value was 0. + @since(version = 0.2.0) keep-alive-count: func() -> result; + @since(version = 0.2.0) set-keep-alive-count: func(value: u32) -> result<_, error-code>; /// Equivalent to the IP_TTL & IPV6_UNICAST_HOPS socket options. @@ -288,7 +314,9 @@ interface tcp { /// /// # Typical errors /// - `invalid-argument`: (set) The TTL value must be 1 or higher. + @since(version = 0.2.0) hop-limit: func() -> result; + @since(version = 0.2.0) set-hop-limit: func(value: u8) -> result<_, error-code>; /// The kernel buffer space reserved for sends/receives on this socket. @@ -301,9 +329,13 @@ interface tcp { /// /// # Typical errors /// - `invalid-argument`: (set) The provided value was 0. + @since(version = 0.2.0) receive-buffer-size: func() -> result; + @since(version = 0.2.0) set-receive-buffer-size: func(value: u64) -> result<_, error-code>; + @since(version = 0.2.0) send-buffer-size: func() -> result; + @since(version = 0.2.0) set-send-buffer-size: func(value: u64) -> result<_, error-code>; /// Create a `pollable` which can be used to poll for, or block on, @@ -318,11 +350,12 @@ interface tcp { /// `subscribe` only has to be called once per socket and can then be /// (re)used for the remainder of the socket's lifetime. /// - /// See - /// for a more information. + /// See + /// for more information. /// /// Note: this function is here for WASI Preview2 only. /// It's planned to be removed when `future` is natively supported in Preview3. + @since(version = 0.2.0) subscribe: func() -> pollable; /// Initiate a graceful shutdown. @@ -335,7 +368,7 @@ interface tcp { /// associated with this socket will be closed and a FIN packet will be sent. /// - `both`: Same effect as `receive` & `send` combined. /// - /// This function is idempotent. Shutting a down a direction more than once + /// This function is idempotent; shutting down a direction more than once /// has no effect and returns `ok`. /// /// The shutdown function does not close (drop) the socket. @@ -348,6 +381,7 @@ interface tcp { /// - /// - /// - + @since(version = 0.2.0) shutdown: func(shutdown-type: shutdown-type) -> result<_, error-code>; } } diff --git a/wit/deps/sockets/udp-create-socket.wit b/wit/deps/sockets/udp-create-socket.wit index 0482d1f..e8eeacb 100644 --- a/wit/deps/sockets/udp-create-socket.wit +++ b/wit/deps/sockets/udp-create-socket.wit @@ -1,6 +1,8 @@ - +@since(version = 0.2.0) interface udp-create-socket { + @since(version = 0.2.0) use network.{network, error-code, ip-address-family}; + @since(version = 0.2.0) use udp.{udp-socket}; /// Create a new UDP socket. @@ -23,5 +25,6 @@ interface udp-create-socket { /// - /// - /// - + @since(version = 0.2.0) create-udp-socket: func(address-family: ip-address-family) -> result; } diff --git a/wit/deps/sockets/udp.wit b/wit/deps/sockets/udp.wit index d987a0a..b289e49 100644 --- a/wit/deps/sockets/udp.wit +++ b/wit/deps/sockets/udp.wit @@ -1,9 +1,12 @@ - +@since(version = 0.2.0) interface udp { - use wasi:io/poll@0.2.0.{pollable}; + @since(version = 0.2.0) + use wasi:io/poll@0.2.1.{pollable}; + @since(version = 0.2.0) use network.{network, error-code, ip-socket-address, ip-address-family}; /// A received datagram. + @since(version = 0.2.0) record incoming-datagram { /// The payload. /// @@ -19,6 +22,7 @@ interface udp { } /// A datagram to be sent out. + @since(version = 0.2.0) record outgoing-datagram { /// The payload. data: list, @@ -33,9 +37,8 @@ interface udp { remote-address: option, } - - /// A UDP socket handle. + @since(version = 0.2.0) resource udp-socket { /// Bind the socket to a specific network on the provided IP address and port. /// @@ -63,7 +66,9 @@ interface udp { /// - /// - /// - + @since(version = 0.2.0) start-bind: func(network: borrow, local-address: ip-socket-address) -> result<_, error-code>; + @since(version = 0.2.0) finish-bind: func() -> result<_, error-code>; /// Set up inbound & outbound communication channels, optionally to a specific peer. @@ -106,6 +111,7 @@ interface udp { /// - /// - /// - + @since(version = 0.2.0) %stream: func(remote-address: option) -> result, error-code>; /// Get the current bound address. @@ -124,6 +130,7 @@ interface udp { /// - /// - /// - + @since(version = 0.2.0) local-address: func() -> result; /// Get the address the socket is currently streaming to. @@ -136,11 +143,13 @@ interface udp { /// - /// - /// - + @since(version = 0.2.0) remote-address: func() -> result; /// Whether this is a IPv4 or IPv6 socket. /// /// Equivalent to the SO_DOMAIN socket option. + @since(version = 0.2.0) address-family: func() -> ip-address-family; /// Equivalent to the IP_TTL & IPV6_UNICAST_HOPS socket options. @@ -149,7 +158,9 @@ interface udp { /// /// # Typical errors /// - `invalid-argument`: (set) The TTL value must be 1 or higher. + @since(version = 0.2.0) unicast-hop-limit: func() -> result; + @since(version = 0.2.0) set-unicast-hop-limit: func(value: u8) -> result<_, error-code>; /// The kernel buffer space reserved for sends/receives on this socket. @@ -162,18 +173,24 @@ interface udp { /// /// # Typical errors /// - `invalid-argument`: (set) The provided value was 0. + @since(version = 0.2.0) receive-buffer-size: func() -> result; + @since(version = 0.2.0) set-receive-buffer-size: func(value: u64) -> result<_, error-code>; + @since(version = 0.2.0) send-buffer-size: func() -> result; + @since(version = 0.2.0) set-send-buffer-size: func(value: u64) -> result<_, error-code>; /// Create a `pollable` which will resolve once the socket is ready for I/O. /// /// Note: this function is here for WASI Preview2 only. /// It's planned to be removed when `future` is natively supported in Preview3. + @since(version = 0.2.0) subscribe: func() -> pollable; } + @since(version = 0.2.0) resource incoming-datagram-stream { /// Receive messages on the socket. /// @@ -198,15 +215,18 @@ interface udp { /// - /// - /// - + @since(version = 0.2.0) receive: func(max-results: u64) -> result, error-code>; /// Create a `pollable` which will resolve once the stream is ready to receive again. /// /// Note: this function is here for WASI Preview2 only. /// It's planned to be removed when `future` is natively supported in Preview3. + @since(version = 0.2.0) subscribe: func() -> pollable; } + @since(version = 0.2.0) resource outgoing-datagram-stream { /// Check readiness for sending. This function never blocks. /// @@ -255,12 +275,14 @@ interface udp { /// - /// - /// - + @since(version = 0.2.0) send: func(datagrams: list) -> result; /// Create a `pollable` which will resolve once the stream is ready to send again. /// /// Note: this function is here for WASI Preview2 only. /// It's planned to be removed when `future` is natively supported in Preview3. + @since(version = 0.2.0) subscribe: func() -> pollable; } } diff --git a/wit/deps/sockets/world.wit b/wit/deps/sockets/world.wit index f8bb92a..a1d4267 100644 --- a/wit/deps/sockets/world.wit +++ b/wit/deps/sockets/world.wit @@ -1,11 +1,19 @@ -package wasi:sockets@0.2.0; +package wasi:sockets@0.2.1; +@since(version = 0.2.0) world imports { + @since(version = 0.2.0) import instance-network; + @since(version = 0.2.0) import network; + @since(version = 0.2.0) import udp; + @since(version = 0.2.0) import udp-create-socket; + @since(version = 0.2.0) import tcp; + @since(version = 0.2.0) import tcp-create-socket; + @since(version = 0.2.0) import ip-name-lookup; } diff --git a/wit/west.wit b/wit/west.wit index b0d2aea..d0cd0f0 100644 --- a/wit/west.wit +++ b/wit/west.wit @@ -1,108 +1,5 @@ -package west:test@0.1.0; - -interface http-test { - use wasi:http/types@0.2.0.{response-outparam, future-incoming-response, incoming-request, outgoing-request}; - - new-response-outparam: func() -> tuple; - new-incoming-request: func(req: outgoing-request) -> incoming-request; -} +package west:west@0.1.0; world imports { - import http-test; -} - -world http-test-passthrough { - import http-test; - export http-test; -} - -world wasi-passthrough { - export wasi:cli/environment@0.2.0; - export wasi:cli/stderr@0.2.0; - export wasi:cli/stdin@0.2.0; - export wasi:cli/stdout@0.2.0; - export wasi:cli/terminal-input@0.2.0; - export wasi:cli/terminal-output@0.2.0; - export wasi:cli/terminal-stderr@0.2.0; - export wasi:cli/terminal-stdin@0.2.0; - export wasi:cli/terminal-stdout@0.2.0; - export wasi:clocks/monotonic-clock@0.2.0; - export wasi:filesystem/preopens@0.2.0; - export wasi:filesystem/types@0.2.0; - export wasi:http/outgoing-handler@0.2.0; - export wasi:http/types@0.2.0; - export wasi:io/error@0.2.0; - export wasi:io/poll@0.2.0; - export wasi:io/streams@0.2.0; - export wasi:sockets/ip-name-lookup@0.2.0; - export wasi:sockets/tcp@0.2.0; - export wasi:sockets/udp@0.2.0; - - import wasi:cli/environment@0.2.0; - import wasi:cli/stderr@0.2.0; - import wasi:cli/stdin@0.2.0; - import wasi:cli/stdout@0.2.0; - import wasi:cli/terminal-input@0.2.0; - import wasi:cli/terminal-output@0.2.0; - import wasi:cli/terminal-stderr@0.2.0; - import wasi:cli/terminal-stdin@0.2.0; - import wasi:cli/terminal-stdout@0.2.0; - import wasi:clocks/monotonic-clock@0.2.0; - import wasi:filesystem/preopens@0.2.0; - import wasi:filesystem/types@0.2.0; - import wasi:http/outgoing-handler@0.2.0; - import wasi:http/types@0.2.0; - import wasi:io/error@0.2.0; - import wasi:io/poll@0.2.0; - import wasi:io/streams@0.2.0; - import wasi:sockets/ip-name-lookup@0.2.0; - import wasi:sockets/tcp@0.2.0; - import wasi:sockets/udp@0.2.0; -} - -world passthrough { - export wasi:cli/environment@0.2.0; - export wasi:cli/stderr@0.2.0; - export wasi:cli/stdin@0.2.0; - export wasi:cli/stdout@0.2.0; - export wasi:cli/terminal-input@0.2.0; - export wasi:cli/terminal-output@0.2.0; - export wasi:cli/terminal-stderr@0.2.0; - export wasi:cli/terminal-stdin@0.2.0; - export wasi:cli/terminal-stdout@0.2.0; - export wasi:clocks/monotonic-clock@0.2.0; - export wasi:filesystem/preopens@0.2.0; - export wasi:filesystem/types@0.2.0; - export wasi:http/outgoing-handler@0.2.0; - export wasi:http/types@0.2.0; - export wasi:io/error@0.2.0; - export wasi:io/poll@0.2.0; - export wasi:io/streams@0.2.0; - export wasi:sockets/ip-name-lookup@0.2.0; - export wasi:sockets/tcp@0.2.0; - export wasi:sockets/udp@0.2.0; - - import wasi:cli/environment@0.2.0; - import wasi:cli/stderr@0.2.0; - import wasi:cli/stdin@0.2.0; - import wasi:cli/stdout@0.2.0; - import wasi:cli/terminal-input@0.2.0; - import wasi:cli/terminal-output@0.2.0; - import wasi:cli/terminal-stderr@0.2.0; - import wasi:cli/terminal-stdin@0.2.0; - import wasi:cli/terminal-stdout@0.2.0; - import wasi:clocks/monotonic-clock@0.2.0; - import wasi:filesystem/preopens@0.2.0; - import wasi:filesystem/types@0.2.0; - import wasi:http/outgoing-handler@0.2.0; - import wasi:http/types@0.2.0; - import wasi:io/error@0.2.0; - import wasi:io/poll@0.2.0; - import wasi:io/streams@0.2.0; - import wasi:sockets/ip-name-lookup@0.2.0; - import wasi:sockets/tcp@0.2.0; - import wasi:sockets/udp@0.2.0; - - import http-test; - export http-test; + include wasiext:http/imports@0.1.0; }