From 590f9be698a9b3f3f4fb744a9a505db94ae7ed7f Mon Sep 17 00:00:00 2001 From: Roman Volosatovs Date: Wed, 4 Sep 2024 21:00:32 +0200 Subject: [PATCH] feat: add PoC --- .gitignore | 5 + Cargo.lock | 2907 +++++++++++++++++ Cargo.toml | 54 + build.rs | 53 + crates/passthrough/Cargo.toml | 16 + 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 | 10 + crates/passthrough/src/sockets.rs | 284 ++ crates/passthrough/src/west.rs | 25 + crates/passthrough/wit | 1 + crates/sys/Cargo.toml | 26 + crates/sys/build.rs | 25 + crates/sys/src/ffi.rs | 78 + crates/sys/src/lib.rs | 1385 ++++++++ crates/sys/west.h | 25 + flake.lock | 603 ++++ flake.nix | 175 + go.work | 5 + go.work.sum | 10 + go/bindings/bindings.go | 1990 +++++++++++ go/bindings/wasi/cli/environment/empty.s | 3 + .../wasi/cli/environment/environment.wit.go | 64 + go/bindings/wasi/cli/exit/empty.s | 3 + go/bindings/wasi/cli/exit/exit.wit.go | 25 + go/bindings/wasi/cli/imports/imports.wit.go | 4 + go/bindings/wasi/cli/stderr/empty.s | 3 + go/bindings/wasi/cli/stderr/stderr.wit.go | 24 + go/bindings/wasi/cli/stdin/empty.s | 3 + go/bindings/wasi/cli/stdin/stdin.wit.go | 24 + go/bindings/wasi/cli/stdout/empty.s | 3 + go/bindings/wasi/cli/stdout/stdout.wit.go | 24 + go/bindings/wasi/cli/terminal-input/empty.s | 3 + .../cli/terminal-input/terminal-input.wit.go | 36 + go/bindings/wasi/cli/terminal-output/empty.s | 3 + .../terminal-output/terminal-output.wit.go | 36 + go/bindings/wasi/cli/terminal-stderr/empty.s | 3 + .../terminal-stderr/terminal-stderr.wit.go | 29 + go/bindings/wasi/cli/terminal-stdin/empty.s | 3 + .../cli/terminal-stdin/terminal-stdin.wit.go | 29 + go/bindings/wasi/cli/terminal-stdout/empty.s | 3 + .../terminal-stdout/terminal-stdout.wit.go | 29 + .../wasi/clocks/imports/imports.wit.go | 4 + .../wasi/clocks/monotonic-clock/empty.s | 3 + .../monotonic-clock/monotonic-clock.wit.go | 113 + go/bindings/wasi/clocks/wall-clock/empty.s | 3 + .../wasi/clocks/wall-clock/wall-clock.wit.go | 78 + .../wasi/filesystem/imports/imports.wit.go | 4 + go/bindings/wasi/filesystem/preopens/empty.s | 3 + .../wasi/filesystem/preopens/preopens.wit.go | 25 + go/bindings/wasi/filesystem/types/abi.go | 51 + go/bindings/wasi/filesystem/types/empty.s | 3 + .../wasi/filesystem/types/types.wit.go | 1357 ++++++++ go/bindings/wasi/http/types/abi.go | 273 ++ go/bindings/wasi/http/types/empty.s | 3 + go/bindings/wasi/http/types/types.wit.go | 2141 ++++++++++++ go/bindings/wasi/io/error/empty.s | 3 + go/bindings/wasi/io/error/error.wit.go | 71 + go/bindings/wasi/io/imports/imports.wit.go | 4 + go/bindings/wasi/io/poll/empty.s | 3 + go/bindings/wasi/io/poll/poll.wit.go | 108 + go/bindings/wasi/io/streams/abi.go | 12 + go/bindings/wasi/io/streams/empty.s | 3 + go/bindings/wasi/io/streams/streams.wit.go | 519 +++ .../wasi/random/imports/imports.wit.go | 4 + go/bindings/wasi/random/insecure-seed/empty.s | 3 + .../random/insecure-seed/insecure-seed.wit.go | 41 + go/bindings/wasi/random/insecure/empty.s | 3 + .../wasi/random/insecure/insecure.wit.go | 57 + go/bindings/wasi/random/random/empty.s | 3 + go/bindings/wasi/random/random/random.wit.go | 61 + .../wasi/sockets/imports/imports.wit.go | 4 + .../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 + go/bindings/wasi/sockets/network/abi.go | 12 + go/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/bindings/wasi/sockets/tcp/abi.go | 86 + go/bindings/wasi/sockets/tcp/empty.s | 3 + go/bindings/wasi/sockets/tcp/tcp.wit.go | 848 +++++ .../wasi/sockets/udp-create-socket/empty.s | 3 + .../udp-create-socket.wit.go | 52 + go/bindings/wasi/sockets/udp/abi.go | 101 + go/bindings/wasi/sockets/udp/empty.s | 3 + go/bindings/wasi/sockets/udp/udp.wit.go | 641 ++++ go/bindings/west.go | 7 + go/bindings/west/test/http-test/empty.s | 3 + .../west/test/http-test/http-test.wit.go | 39 + go/bindings/west/test/imports/imports.wit.go | 4 + go/cmd/west-bindgen-go/main.go | 562 ++++ go/go.mod | 15 + go/go.sum | 17 + go/internal/tests/sync/bindings/.gitkeep | 0 go/internal/tests/sync/sync.go | 8 + go/internal/tests/sync/sync_test.go | 834 +++++ go/internal/tests/wasi/bindings/.gitkeep | 0 go/internal/tests/wasi/wasi.go | 64 + go/internal/tests/wasi/wasi_test.go | 102 + go/internal/tests/wasi/wit/app.wit | 10 + go/internal/tests/wasi/wit/deps.lock | 34 + go/internal/tests/wasi/wit/deps.toml | 2 + .../tests/wasi/wit/deps/cli/command.wit | 7 + .../tests/wasi/wit/deps/cli/environment.wit | 18 + go/internal/tests/wasi/wit/deps/cli/exit.wit | 4 + .../tests/wasi/wit/deps/cli/imports.wit | 20 + go/internal/tests/wasi/wit/deps/cli/run.wit | 4 + go/internal/tests/wasi/wit/deps/cli/stdio.wit | 17 + .../tests/wasi/wit/deps/cli/terminal.wit | 49 + .../wasi/wit/deps/clocks/monotonic-clock.wit | 45 + .../tests/wasi/wit/deps/clocks/wall-clock.wit | 42 + .../tests/wasi/wit/deps/clocks/world.wit | 6 + go/internal/tests/wasi/wit/deps/fib/fib.wit | 13 + .../wasi/wit/deps/filesystem/preopens.wit | 8 + .../tests/wasi/wit/deps/filesystem/types.wit | 634 ++++ .../tests/wasi/wit/deps/filesystem/world.wit | 6 + .../tests/wasi/wit/deps/http/handler.wit | 43 + .../tests/wasi/wit/deps/http/proxy.wit | 32 + .../tests/wasi/wit/deps/http/types.wit | 570 ++++ go/internal/tests/wasi/wit/deps/io/error.wit | 34 + go/internal/tests/wasi/wit/deps/io/poll.wit | 41 + .../tests/wasi/wit/deps/io/streams.wit | 262 ++ go/internal/tests/wasi/wit/deps/io/world.wit | 6 + .../wasi/wit/deps/random/insecure-seed.wit | 25 + .../tests/wasi/wit/deps/random/insecure.wit | 22 + .../tests/wasi/wit/deps/random/random.wit | 26 + .../tests/wasi/wit/deps/random/world.wit | 7 + .../wit/deps/sockets/instance-network.wit | 9 + .../wasi/wit/deps/sockets/ip-name-lookup.wit | 51 + .../tests/wasi/wit/deps/sockets/network.wit | 145 + .../wit/deps/sockets/tcp-create-socket.wit | 27 + .../tests/wasi/wit/deps/sockets/tcp.wit | 353 ++ .../wit/deps/sockets/udp-create-socket.wit | 27 + .../tests/wasi/wit/deps/sockets/udp.wit | 266 ++ .../tests/wasi/wit/deps/sockets/world.wit | 11 + go/west.go | 198 ++ go/west_darwin_amd64.go | 3 + go/west_darwin_arm64.go | 3 + go/west_linux_amd64.go | 3 + go/west_linux_arm64.go | 3 + go/west_windows_amd64.go | 3 + include/include.go | 1 + include/west.h | 25 + lib/aarch64-darwin/lib_darwin_arm64.go | 1 + lib/aarch64-linux/lib_linux_arm64.go | 1 + lib/amd64-linux/lib_linux_amd64.go | 1 + lib/lib.go | 1 + lib/x86_64-darwin/lib_darwin_amd64.go | 1 + lib/x86_64-windows/lib_windows_amd64.go | 1 + rust-toolchain.toml | 7 + src/lib.rs | 313 ++ tests/components/sync/Cargo.toml | 16 + tests/components/sync/src/lib.rs | 227 ++ tests/components/wasi/Cargo.toml | 17 + tests/components/wasi/src/lib.rs | 26 + tests/wit/fib/fib.wit | 13 + tests/wit/sync/sync.wit | 96 + wit/deps.lock | 29 + wit/deps.toml | 1 + wit/deps/cli/command.wit | 7 + wit/deps/cli/environment.wit | 18 + wit/deps/cli/exit.wit | 4 + wit/deps/cli/imports.wit | 20 + wit/deps/cli/run.wit | 4 + wit/deps/cli/stdio.wit | 17 + wit/deps/cli/terminal.wit | 49 + wit/deps/clocks/monotonic-clock.wit | 45 + wit/deps/clocks/wall-clock.wit | 42 + wit/deps/clocks/world.wit | 6 + wit/deps/filesystem/preopens.wit | 8 + wit/deps/filesystem/types.wit | 634 ++++ wit/deps/filesystem/world.wit | 6 + wit/deps/http/handler.wit | 43 + wit/deps/http/proxy.wit | 32 + wit/deps/http/types.wit | 570 ++++ wit/deps/io/error.wit | 34 + wit/deps/io/poll.wit | 41 + wit/deps/io/streams.wit | 262 ++ wit/deps/io/world.wit | 6 + wit/deps/random/insecure-seed.wit | 25 + wit/deps/random/insecure.wit | 22 + wit/deps/random/random.wit | 26 + wit/deps/random/world.wit | 7 + wit/deps/sockets/instance-network.wit | 9 + wit/deps/sockets/ip-name-lookup.wit | 51 + wit/deps/sockets/network.wit | 145 + wit/deps/sockets/tcp-create-socket.wit | 27 + wit/deps/sockets/tcp.wit | 353 ++ wit/deps/sockets/udp-create-socket.wit | 27 + wit/deps/sockets/udp.wit | 266 ++ wit/deps/sockets/world.wit | 11 + wit/west.wit | 108 + 200 files changed, 24932 insertions(+) create mode 100644 .gitignore create mode 100644 Cargo.lock create mode 100644 Cargo.toml create mode 100644 build.rs create mode 100644 crates/passthrough/Cargo.toml create mode 100644 crates/passthrough/src/bindings.rs create mode 100644 crates/passthrough/src/cli.rs create mode 100644 crates/passthrough/src/clocks.rs create mode 100644 crates/passthrough/src/filesystem.rs create mode 100644 crates/passthrough/src/http.rs create mode 100644 crates/passthrough/src/io.rs create mode 100644 crates/passthrough/src/lib.rs create mode 100644 crates/passthrough/src/sockets.rs create mode 100644 crates/passthrough/src/west.rs create mode 120000 crates/passthrough/wit create mode 100644 crates/sys/Cargo.toml create mode 100644 crates/sys/build.rs create mode 100644 crates/sys/src/ffi.rs create mode 100644 crates/sys/src/lib.rs create mode 100644 crates/sys/west.h create mode 100644 flake.lock create mode 100644 flake.nix create mode 100644 go.work create mode 100644 go.work.sum create mode 100644 go/bindings/bindings.go create mode 100644 go/bindings/wasi/cli/environment/empty.s create mode 100644 go/bindings/wasi/cli/environment/environment.wit.go create mode 100644 go/bindings/wasi/cli/exit/empty.s create mode 100644 go/bindings/wasi/cli/exit/exit.wit.go create mode 100644 go/bindings/wasi/cli/imports/imports.wit.go create mode 100644 go/bindings/wasi/cli/stderr/empty.s create mode 100644 go/bindings/wasi/cli/stderr/stderr.wit.go create mode 100644 go/bindings/wasi/cli/stdin/empty.s create mode 100644 go/bindings/wasi/cli/stdin/stdin.wit.go create mode 100644 go/bindings/wasi/cli/stdout/empty.s create mode 100644 go/bindings/wasi/cli/stdout/stdout.wit.go create mode 100644 go/bindings/wasi/cli/terminal-input/empty.s create mode 100644 go/bindings/wasi/cli/terminal-input/terminal-input.wit.go create mode 100644 go/bindings/wasi/cli/terminal-output/empty.s create mode 100644 go/bindings/wasi/cli/terminal-output/terminal-output.wit.go create mode 100644 go/bindings/wasi/cli/terminal-stderr/empty.s create mode 100644 go/bindings/wasi/cli/terminal-stderr/terminal-stderr.wit.go create mode 100644 go/bindings/wasi/cli/terminal-stdin/empty.s create mode 100644 go/bindings/wasi/cli/terminal-stdin/terminal-stdin.wit.go create mode 100644 go/bindings/wasi/cli/terminal-stdout/empty.s create mode 100644 go/bindings/wasi/cli/terminal-stdout/terminal-stdout.wit.go create mode 100644 go/bindings/wasi/clocks/imports/imports.wit.go create mode 100644 go/bindings/wasi/clocks/monotonic-clock/empty.s create mode 100644 go/bindings/wasi/clocks/monotonic-clock/monotonic-clock.wit.go create mode 100644 go/bindings/wasi/clocks/wall-clock/empty.s create mode 100644 go/bindings/wasi/clocks/wall-clock/wall-clock.wit.go create mode 100644 go/bindings/wasi/filesystem/imports/imports.wit.go create mode 100644 go/bindings/wasi/filesystem/preopens/empty.s create mode 100644 go/bindings/wasi/filesystem/preopens/preopens.wit.go create mode 100644 go/bindings/wasi/filesystem/types/abi.go create mode 100644 go/bindings/wasi/filesystem/types/empty.s create mode 100644 go/bindings/wasi/filesystem/types/types.wit.go create mode 100644 go/bindings/wasi/http/types/abi.go create mode 100644 go/bindings/wasi/http/types/empty.s create mode 100644 go/bindings/wasi/http/types/types.wit.go create mode 100644 go/bindings/wasi/io/error/empty.s create mode 100644 go/bindings/wasi/io/error/error.wit.go create mode 100644 go/bindings/wasi/io/imports/imports.wit.go create mode 100644 go/bindings/wasi/io/poll/empty.s create mode 100644 go/bindings/wasi/io/poll/poll.wit.go create mode 100644 go/bindings/wasi/io/streams/abi.go create mode 100644 go/bindings/wasi/io/streams/empty.s create mode 100644 go/bindings/wasi/io/streams/streams.wit.go create mode 100644 go/bindings/wasi/random/imports/imports.wit.go create mode 100644 go/bindings/wasi/random/insecure-seed/empty.s create mode 100644 go/bindings/wasi/random/insecure-seed/insecure-seed.wit.go create mode 100644 go/bindings/wasi/random/insecure/empty.s create mode 100644 go/bindings/wasi/random/insecure/insecure.wit.go create mode 100644 go/bindings/wasi/random/random/empty.s create mode 100644 go/bindings/wasi/random/random/random.wit.go create mode 100644 go/bindings/wasi/sockets/imports/imports.wit.go create mode 100644 go/bindings/wasi/sockets/instance-network/empty.s create mode 100644 go/bindings/wasi/sockets/instance-network/instance-network.wit.go create mode 100644 go/bindings/wasi/sockets/ip-name-lookup/abi.go create mode 100644 go/bindings/wasi/sockets/ip-name-lookup/empty.s create mode 100644 go/bindings/wasi/sockets/ip-name-lookup/ip-name-lookup.wit.go create mode 100644 go/bindings/wasi/sockets/network/abi.go create mode 100644 go/bindings/wasi/sockets/network/empty.s create mode 100644 go/bindings/wasi/sockets/network/network.wit.go create mode 100644 go/bindings/wasi/sockets/tcp-create-socket/empty.s create mode 100644 go/bindings/wasi/sockets/tcp-create-socket/tcp-create-socket.wit.go create mode 100644 go/bindings/wasi/sockets/tcp/abi.go create mode 100644 go/bindings/wasi/sockets/tcp/empty.s create mode 100644 go/bindings/wasi/sockets/tcp/tcp.wit.go create mode 100644 go/bindings/wasi/sockets/udp-create-socket/empty.s create mode 100644 go/bindings/wasi/sockets/udp-create-socket/udp-create-socket.wit.go create mode 100644 go/bindings/wasi/sockets/udp/abi.go create mode 100644 go/bindings/wasi/sockets/udp/empty.s create mode 100644 go/bindings/wasi/sockets/udp/udp.wit.go create mode 100644 go/bindings/west.go create mode 100644 go/bindings/west/test/http-test/empty.s create mode 100644 go/bindings/west/test/http-test/http-test.wit.go create mode 100644 go/bindings/west/test/imports/imports.wit.go create mode 100644 go/cmd/west-bindgen-go/main.go create mode 100644 go/go.mod create mode 100644 go/go.sum create mode 100644 go/internal/tests/sync/bindings/.gitkeep create mode 100644 go/internal/tests/sync/sync.go create mode 100644 go/internal/tests/sync/sync_test.go create mode 100644 go/internal/tests/wasi/bindings/.gitkeep create mode 100644 go/internal/tests/wasi/wasi.go create mode 100644 go/internal/tests/wasi/wasi_test.go create mode 100644 go/internal/tests/wasi/wit/app.wit create mode 100644 go/internal/tests/wasi/wit/deps.lock create mode 100644 go/internal/tests/wasi/wit/deps.toml create mode 100644 go/internal/tests/wasi/wit/deps/cli/command.wit create mode 100644 go/internal/tests/wasi/wit/deps/cli/environment.wit create mode 100644 go/internal/tests/wasi/wit/deps/cli/exit.wit create mode 100644 go/internal/tests/wasi/wit/deps/cli/imports.wit create mode 100644 go/internal/tests/wasi/wit/deps/cli/run.wit create mode 100644 go/internal/tests/wasi/wit/deps/cli/stdio.wit create mode 100644 go/internal/tests/wasi/wit/deps/cli/terminal.wit create mode 100644 go/internal/tests/wasi/wit/deps/clocks/monotonic-clock.wit create mode 100644 go/internal/tests/wasi/wit/deps/clocks/wall-clock.wit create mode 100644 go/internal/tests/wasi/wit/deps/clocks/world.wit create mode 100644 go/internal/tests/wasi/wit/deps/fib/fib.wit create mode 100644 go/internal/tests/wasi/wit/deps/filesystem/preopens.wit create mode 100644 go/internal/tests/wasi/wit/deps/filesystem/types.wit create mode 100644 go/internal/tests/wasi/wit/deps/filesystem/world.wit create mode 100644 go/internal/tests/wasi/wit/deps/http/handler.wit create mode 100644 go/internal/tests/wasi/wit/deps/http/proxy.wit create mode 100644 go/internal/tests/wasi/wit/deps/http/types.wit create mode 100644 go/internal/tests/wasi/wit/deps/io/error.wit create mode 100644 go/internal/tests/wasi/wit/deps/io/poll.wit create mode 100644 go/internal/tests/wasi/wit/deps/io/streams.wit create mode 100644 go/internal/tests/wasi/wit/deps/io/world.wit create mode 100644 go/internal/tests/wasi/wit/deps/random/insecure-seed.wit create mode 100644 go/internal/tests/wasi/wit/deps/random/insecure.wit create mode 100644 go/internal/tests/wasi/wit/deps/random/random.wit create mode 100644 go/internal/tests/wasi/wit/deps/random/world.wit create mode 100644 go/internal/tests/wasi/wit/deps/sockets/instance-network.wit create mode 100644 go/internal/tests/wasi/wit/deps/sockets/ip-name-lookup.wit create mode 100644 go/internal/tests/wasi/wit/deps/sockets/network.wit create mode 100644 go/internal/tests/wasi/wit/deps/sockets/tcp-create-socket.wit create mode 100644 go/internal/tests/wasi/wit/deps/sockets/tcp.wit create mode 100644 go/internal/tests/wasi/wit/deps/sockets/udp-create-socket.wit create mode 100644 go/internal/tests/wasi/wit/deps/sockets/udp.wit create mode 100644 go/internal/tests/wasi/wit/deps/sockets/world.wit create mode 100644 go/west.go create mode 100644 go/west_darwin_amd64.go create mode 100644 go/west_darwin_arm64.go create mode 100644 go/west_linux_amd64.go create mode 100644 go/west_linux_arm64.go create mode 100644 go/west_windows_amd64.go create mode 100644 include/include.go create mode 100644 include/west.h create mode 100644 lib/aarch64-darwin/lib_darwin_arm64.go create mode 100644 lib/aarch64-linux/lib_linux_arm64.go create mode 100644 lib/amd64-linux/lib_linux_amd64.go create mode 100644 lib/lib.go create mode 100644 lib/x86_64-darwin/lib_darwin_amd64.go create mode 100644 lib/x86_64-windows/lib_windows_amd64.go create mode 100644 rust-toolchain.toml create mode 100644 src/lib.rs create mode 100644 tests/components/sync/Cargo.toml create mode 100644 tests/components/sync/src/lib.rs create mode 100644 tests/components/wasi/Cargo.toml create mode 100644 tests/components/wasi/src/lib.rs create mode 100644 tests/wit/fib/fib.wit create mode 100644 tests/wit/sync/sync.wit create mode 100644 wit/deps.lock create mode 100644 wit/deps.toml create mode 100644 wit/deps/cli/command.wit create mode 100644 wit/deps/cli/environment.wit create mode 100644 wit/deps/cli/exit.wit create mode 100644 wit/deps/cli/imports.wit create mode 100644 wit/deps/cli/run.wit create mode 100644 wit/deps/cli/stdio.wit create mode 100644 wit/deps/cli/terminal.wit create mode 100644 wit/deps/clocks/monotonic-clock.wit create mode 100644 wit/deps/clocks/wall-clock.wit create mode 100644 wit/deps/clocks/world.wit create mode 100644 wit/deps/filesystem/preopens.wit create mode 100644 wit/deps/filesystem/types.wit create mode 100644 wit/deps/filesystem/world.wit create mode 100644 wit/deps/http/handler.wit create mode 100644 wit/deps/http/proxy.wit create mode 100644 wit/deps/http/types.wit create mode 100644 wit/deps/io/error.wit create mode 100644 wit/deps/io/poll.wit create mode 100644 wit/deps/io/streams.wit create mode 100644 wit/deps/io/world.wit create mode 100644 wit/deps/random/insecure-seed.wit create mode 100644 wit/deps/random/insecure.wit create mode 100644 wit/deps/random/random.wit create mode 100644 wit/deps/random/world.wit create mode 100644 wit/deps/sockets/instance-network.wit create mode 100644 wit/deps/sockets/ip-name-lookup.wit create mode 100644 wit/deps/sockets/network.wit create mode 100644 wit/deps/sockets/tcp-create-socket.wit create mode 100644 wit/deps/sockets/tcp.wit create mode 100644 wit/deps/sockets/udp-create-socket.wit create mode 100644 wit/deps/sockets/udp.wit create mode 100644 wit/deps/sockets/world.wit create mode 100644 wit/west.wit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..684e484 --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +/target +*.wasm +*.a +west_bindings_test.go +/go/internal/tests/*/bindings/* diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 0000000..e7f9367 --- /dev/null +++ b/Cargo.lock @@ -0,0 +1,2907 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "addr2line" +version = "0.22.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6e4503c46a5c0c7844e948c9a4d6acd9f50cccb4de1c48eb9e291ea17470c678" +dependencies = [ + "gimli 0.29.0", +] + +[[package]] +name = "addr2line" +version = "0.24.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f5fb1d8e4442bd405fdfd1dacb42792696b0cf9cb15882e5d097b742a676d375" +dependencies = [ + "gimli 0.31.0", +] + +[[package]] +name = "adler2" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "512761e0bb2578dd7380c6baaa0f4ce03e84f95e960231d1dec8bf4d7d6e2627" + +[[package]] +name = "ahash" +version = "0.8.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e89da841a80418a9b391ebaea17f5c112ffaaa96f621d2c285b5174da76b9011" +dependencies = [ + "cfg-if", + "once_cell", + "version_check", + "zerocopy", +] + +[[package]] +name = "aho-corasick" +version = "1.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e60d3430d3a69478ad0993f19238d2df97c507009a52b3c10addcd7f6bcb916" +dependencies = [ + "memchr", +] + +[[package]] +name = "ambient-authority" +version = "0.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e9d4ee0d472d1cd2e28c97dfa124b3d8d992e10eb0a035f33f5d12e3a177ba3b" + +[[package]] +name = "android_system_properties" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "819e7219dbd41043ac279b19830f2efc897156490d7fd6ea916720117ee66311" +dependencies = [ + "libc", +] + +[[package]] +name = "anstream" +version = "0.6.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "64e15c1ab1f89faffbf04a634d5e1962e9074f2741eef6d97f3c4e322426d526" +dependencies = [ + "anstyle", + "anstyle-parse", + "anstyle-query", + "anstyle-wincon", + "colorchoice", + "is_terminal_polyfill", + "utf8parse", +] + +[[package]] +name = "anstyle" +version = "1.0.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1bec1de6f59aedf83baf9ff929c98f2ad654b97c9510f4e70cf6f661d49fd5b1" + +[[package]] +name = "anstyle-parse" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eb47de1e80c2b463c735db5b217a0ddc39d612e7ac9e2e96a5aed1f57616c1cb" +dependencies = [ + "utf8parse", +] + +[[package]] +name = "anstyle-query" +version = "1.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6d36fc52c7f6c869915e99412912f22093507da8d9e942ceaf66fe4b7c14422a" +dependencies = [ + "windows-sys 0.52.0", +] + +[[package]] +name = "anstyle-wincon" +version = "3.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5bf74e1b6e971609db8ca7a9ce79fd5768ab6ae46441c572e46cf596f59e57f8" +dependencies = [ + "anstyle", + "windows-sys 0.52.0", +] + +[[package]] +name = "anyhow" +version = "1.0.88" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4e1496f8fb1fbf272686b8d37f523dab3e4a7443300055e74cdaa449f3114356" + +[[package]] +name = "arbitrary" +version = "1.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7d5a26814d8dcb93b0e5a0ff3c6d80a8843bafb21b39e8e18a6f05471870e110" + +[[package]] +name = "async-trait" +version = "0.1.82" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a27b8a3a6e1a44fa4c8baf1f653e4172e81486d4941f2237e20dc2d0cf4ddff1" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "atomic-waker" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0" + +[[package]] +name = "autocfg" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" + +[[package]] +name = "backtrace" +version = "0.3.74" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8d82cb332cdfaed17ae235a638438ac4d4839913cc2af585c3c6746e8f8bee1a" +dependencies = [ + "addr2line 0.24.1", + "cfg-if", + "libc", + "miniz_oxide", + "object", + "rustc-demangle", + "windows-targets", +] + +[[package]] +name = "base64" +version = "0.21.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d297deb1925b89f2ccc13d7635fa0714f12c87adce1c75356b39ca9b7178567" + +[[package]] +name = "bitflags" +version = "2.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" + +[[package]] +name = "block-buffer" +version = "0.10.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71" +dependencies = [ + "generic-array", +] + +[[package]] +name = "bumpalo" +version = "3.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c" + +[[package]] +name = "byteorder" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" + +[[package]] +name = "bytes" +version = "1.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8318a53db07bb3f8dca91a600466bdb3f2eaadeedfdbcf02e1accbad9271ba50" + +[[package]] +name = "cap-fs-ext" +version = "3.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eb23061fc1c4ead4e45ca713080fe768e6234e959f5a5c399c39eb41aa34e56e" +dependencies = [ + "cap-primitives", + "cap-std", + "io-lifetimes", + "windows-sys 0.52.0", +] + +[[package]] +name = "cap-net-ext" +version = "3.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f83ae11f116bcbafc5327c6af250341db96b5930046732e1905f7dc65887e0e1" +dependencies = [ + "cap-primitives", + "cap-std", + "rustix", + "smallvec", +] + +[[package]] +name = "cap-primitives" +version = "3.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6d00bd8d26c4270d950eaaa837387964a2089a1c3c349a690a1fa03221d29531" +dependencies = [ + "ambient-authority", + "fs-set-times", + "io-extras", + "io-lifetimes", + "ipnet", + "maybe-owned", + "rustix", + "windows-sys 0.52.0", + "winx", +] + +[[package]] +name = "cap-rand" +version = "3.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dbcb16a619d8b8211ed61f42bd290d2a1ac71277a69cf8417ec0996fa92f5211" +dependencies = [ + "ambient-authority", + "rand", +] + +[[package]] +name = "cap-std" +version = "3.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "19eb8e3d71996828751c1ed3908a439639752ac6bdc874e41469ef7fc15fbd7f" +dependencies = [ + "cap-primitives", + "io-extras", + "io-lifetimes", + "rustix", +] + +[[package]] +name = "cap-time-ext" +version = "3.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61142dc51e25b7acc970ca578ce2c3695eac22bbba46c1073f5f583e78957725" +dependencies = [ + "ambient-authority", + "cap-primitives", + "iana-time-zone", + "once_cell", + "rustix", + "winx", +] + +[[package]] +name = "cbindgen" +version = "0.27.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3fce8dd7fcfcbf3a0a87d8f515194b49d6135acab73e18bd380d1d93bb1a15eb" +dependencies = [ + "clap", + "heck 0.4.1", + "indexmap", + "log", + "proc-macro2", + "quote", + "serde", + "serde_json", + "syn", + "tempfile", + "toml", +] + +[[package]] +name = "cc" +version = "1.1.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b62ac837cdb5cb22e10a256099b4fc502b1dfe560cb282963a974d7abd80e476" +dependencies = [ + "jobserver", + "libc", + "shlex", +] + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "clap" +version = "4.5.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3e5a21b8495e732f1b3c364c9949b201ca7bae518c502c80256c96ad79eaf6ac" +dependencies = [ + "clap_builder", +] + +[[package]] +name = "clap_builder" +version = "4.5.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8cf2dd12af7a047ad9d6da2b6b249759a22a7abc0f474c1dae1777afa4b21a73" +dependencies = [ + "anstream", + "anstyle", + "clap_lex", + "strsim", +] + +[[package]] +name = "clap_lex" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1462739cb27611015575c0c11df5df7601141071f07518d56fcc1be504cbec97" + +[[package]] +name = "cobs" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "67ba02a97a2bd10f4b59b25c7973101c79642302776489e030cd13cdab09ed15" + +[[package]] +name = "colorchoice" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3fd119d74b830634cea2a0f58bbd0d54540518a14397557951e79340abc28c0" + +[[package]] +name = "core-foundation-sys" +version = "0.8.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" + +[[package]] +name = "cpp_demangle" +version = "0.4.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "96e58d342ad113c2b878f16d5d034c03be492ae460cdbc02b7f0f2284d310c7d" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "cpufeatures" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "608697df725056feaccfa42cffdaeeec3fccc4ffc38358ecd19b243e716a78e0" +dependencies = [ + "libc", +] + +[[package]] +name = "cranelift-bforest" +version = "0.111.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b80c3a50b9c4c7e5b5f73c0ed746687774fc9e36ef652b110da8daebf0c6e0e6" +dependencies = [ + "cranelift-entity", +] + +[[package]] +name = "cranelift-bitset" +version = "0.111.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38778758c2ca918b05acb2199134e0c561fb577c50574259b26190b6c2d95ded" +dependencies = [ + "serde", + "serde_derive", +] + +[[package]] +name = "cranelift-codegen" +version = "0.111.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "58258667ad10e468bfc13a8d620f50dfcd4bb35d668123e97defa2549b9ad397" +dependencies = [ + "bumpalo", + "cranelift-bforest", + "cranelift-bitset", + "cranelift-codegen-meta", + "cranelift-codegen-shared", + "cranelift-control", + "cranelift-entity", + "cranelift-isle", + "gimli 0.29.0", + "hashbrown 0.14.5", + "log", + "regalloc2", + "rustc-hash", + "smallvec", + "target-lexicon", +] + +[[package]] +name = "cranelift-codegen-meta" +version = "0.111.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "043f0b702e529dcb07ff92bd7d40e7d5317b5493595172c5eb0983343751ee06" +dependencies = [ + "cranelift-codegen-shared", +] + +[[package]] +name = "cranelift-codegen-shared" +version = "0.111.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7763578888ab53eca5ce7da141953f828e82c2bfadcffc106d10d1866094ffbb" + +[[package]] +name = "cranelift-control" +version = "0.111.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32db15f08c05df570f11e8ab33cb1ec449a64b37c8a3498377b77650bef33d8b" +dependencies = [ + "arbitrary", +] + +[[package]] +name = "cranelift-entity" +version = "0.111.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5289cdb399381a27e7bbfa1b42185916007c3d49aeef70b1d01cb4caa8010130" +dependencies = [ + "cranelift-bitset", + "serde", + "serde_derive", +] + +[[package]] +name = "cranelift-frontend" +version = "0.111.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "31ba8ab24eb9470477e98ddfa3c799a649ac5a0d9a2042868c4c952133c234e8" +dependencies = [ + "cranelift-codegen", + "log", + "smallvec", + "target-lexicon", +] + +[[package]] +name = "cranelift-isle" +version = "0.111.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b72a3c5c166a70426dcb209bdd0bb71a787c1ea76023dc0974fbabca770e8f9" + +[[package]] +name = "cranelift-native" +version = "0.111.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "46a42424c956bbc31fc5c2706073df896156c5420ae8fa2a5d48dbc7b295d71b" +dependencies = [ + "cranelift-codegen", + "libc", + "target-lexicon", +] + +[[package]] +name = "cranelift-wasm" +version = "0.111.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49778df4289933d735b93c30a345513e030cf83101de0036e19b760f8aa09f68" +dependencies = [ + "cranelift-codegen", + "cranelift-entity", + "cranelift-frontend", + "itertools", + "log", + "smallvec", + "wasmparser 0.215.0", + "wasmtime-types", +] + +[[package]] +name = "crc32fast" +version = "1.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a97769d94ddab943e4510d138150169a2758b5ef3eb191a9ee688de3e23ef7b3" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "crossbeam-deque" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "613f8cc01fe9cf1a3eb3d7f488fd2fa8388403e97039e2f73692932e291a770d" +dependencies = [ + "crossbeam-epoch", + "crossbeam-utils", +] + +[[package]] +name = "crossbeam-epoch" +version = "0.9.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b82ac4a3c2ca9c3460964f020e1402edd5753411d7737aa39c3714ad1b5420e" +dependencies = [ + "crossbeam-utils", +] + +[[package]] +name = "crossbeam-utils" +version = "0.8.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "22ec99545bb0ed0ea7bb9b8e1e9122ea386ff8a48c0922e43f36d45ab09e0e80" + +[[package]] +name = "crypto-common" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3" +dependencies = [ + "generic-array", + "typenum", +] + +[[package]] +name = "debugid" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bef552e6f588e446098f6ba40d89ac146c8c7b64aade83c051ee00bb5d2bc18d" +dependencies = [ + "uuid", +] + +[[package]] +name = "digest" +version = "0.10.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" +dependencies = [ + "block-buffer", + "crypto-common", +] + +[[package]] +name = "directories-next" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "339ee130d97a610ea5a5872d2bbb130fdf68884ff09d3028b81bec8a1ac23bbc" +dependencies = [ + "cfg-if", + "dirs-sys-next", +] + +[[package]] +name = "dirs" +version = "4.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ca3aa72a6f96ea37bbc5aa912f6788242832f75369bdfdadcb0e38423f100059" +dependencies = [ + "dirs-sys", +] + +[[package]] +name = "dirs-sys" +version = "0.3.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b1d1d91c932ef41c0f2663aa8b0ca0342d444d842c06914aa0a7e352d0bada6" +dependencies = [ + "libc", + "redox_users", + "winapi", +] + +[[package]] +name = "dirs-sys-next" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ebda144c4fe02d1f7ea1a7d9641b6fc6b580adcfa024ae48797ecdeb6825b4d" +dependencies = [ + "libc", + "redox_users", + "winapi", +] + +[[package]] +name = "either" +version = "1.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "60b1af1c220855b6ceac025d3f6ecdd2b7c4894bfe9cd9bda4fbb4bc7c0d4cf0" + +[[package]] +name = "embedded-io" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ef1a6892d9eef45c8fa6b9e0086428a2cca8491aca8f787c534a3d6d0bcb3ced" + +[[package]] +name = "embedded-io" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "edd0f118536f44f5ccd48bcb8b111bdc3de888b58c74639dfb034a357d0f206d" + +[[package]] +name = "encoding_rs" +version = "0.8.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b45de904aa0b010bce2ab45264d0631681847fa7b6f2eaa7dab7619943bc4f59" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "equivalent" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" + +[[package]] +name = "errno" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "534c5cf6194dfab3db3242765c03bbe257cf92f22b38f6bc0c58d59108a820ba" +dependencies = [ + "libc", + "windows-sys 0.52.0", +] + +[[package]] +name = "fallible-iterator" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2acce4a10f12dc2fb14a218589d4f1f62ef011b2d0cc4b3cb1bba8e94da14649" + +[[package]] +name = "fastrand" +version = "2.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e8c02a5121d4ea3eb16a80748c74f5549a5665e4c21333c6098f283870fbdea6" + +[[package]] +name = "fd-lock" +version = "4.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7e5768da2206272c81ef0b5e951a41862938a6070da63bcea197899942d3b947" +dependencies = [ + "cfg-if", + "rustix", + "windows-sys 0.52.0", +] + +[[package]] +name = "fnv" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" + +[[package]] +name = "form_urlencoded" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e13624c2627564efccf4934284bdd98cbaa14e79b0b5a141218e507b3a823456" +dependencies = [ + "percent-encoding", +] + +[[package]] +name = "fs-set-times" +version = "0.20.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "033b337d725b97690d86893f9de22b67b80dcc4e9ad815f348254c38119db8fb" +dependencies = [ + "io-lifetimes", + "rustix", + "windows-sys 0.52.0", +] + +[[package]] +name = "futures" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "645c6916888f6cb6350d2550b80fb63e734897a8498abe35cfb732b6487804b0" +dependencies = [ + "futures-channel", + "futures-core", + "futures-io", + "futures-sink", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-channel" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eac8f7d7865dcb88bd4373ab671c8cf4508703796caa2b1985a9ca867b3fcb78" +dependencies = [ + "futures-core", + "futures-sink", +] + +[[package]] +name = "futures-core" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dfc6580bb841c5a68e9ef15c77ccc837b40a7504914d52e47b8b0e9bbda25a1d" + +[[package]] +name = "futures-io" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a44623e20b9681a318efdd71c299b6b222ed6f231972bfe2f224ebad6311f0c1" + +[[package]] +name = "futures-sink" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9fb8e00e87438d937621c1c6269e53f536c14d3fbd6a042bb24879e57d474fb5" + +[[package]] +name = "futures-task" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38d84fa142264698cdce1a9f9172cf383a0c82de1bddcf3092901442c4097004" + +[[package]] +name = "futures-util" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3d6401deb83407ab3da39eba7e33987a73c3df0c82b4bb5813ee871c19c41d48" +dependencies = [ + "futures-core", + "futures-sink", + "futures-task", + "pin-project-lite", + "pin-utils", +] + +[[package]] +name = "fxhash" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c31b6d751ae2c7f11320402d34e41349dd1016f8d5d45e48c4312bc8625af50c" +dependencies = [ + "byteorder", +] + +[[package]] +name = "fxprof-processed-profile" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "27d12c0aed7f1e24276a241aadc4cb8ea9f83000f34bc062b7cc2d51e3b0fabd" +dependencies = [ + "bitflags", + "debugid", + "fxhash", + "serde", + "serde_json", +] + +[[package]] +name = "generic-array" +version = "0.14.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" +dependencies = [ + "typenum", + "version_check", +] + +[[package]] +name = "getrandom" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c4567c8db10ae91089c99af84c68c38da3ec2f087c3f82960bcdbf3656b6f4d7" +dependencies = [ + "cfg-if", + "libc", + "wasi", +] + +[[package]] +name = "gimli" +version = "0.29.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "40ecd4077b5ae9fd2e9e169b102c6c330d0605168eb0e8bf79952b256dbefffd" +dependencies = [ + "fallible-iterator", + "indexmap", + "stable_deref_trait", +] + +[[package]] +name = "gimli" +version = "0.31.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32085ea23f3234fc7846555e85283ba4de91e21016dc0455a16286d87a292d64" + +[[package]] +name = "h2" +version = "0.4.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "524e8ac6999421f49a846c2d4411f337e53497d8ec55d67753beffa43c5d9205" +dependencies = [ + "atomic-waker", + "bytes", + "fnv", + "futures-core", + "futures-sink", + "http", + "indexmap", + "slab", + "tokio", + "tokio-util", + "tracing", +] + +[[package]] +name = "hashbrown" +version = "0.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "43a3c133739dddd0d2990f9a4bdf8eb4b21ef50e4851ca85ab661199821d510e" +dependencies = [ + "ahash", +] + +[[package]] +name = "hashbrown" +version = "0.14.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1" +dependencies = [ + "ahash", + "serde", +] + +[[package]] +name = "heck" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" + +[[package]] +name = "heck" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" + +[[package]] +name = "hermit-abi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" + +[[package]] +name = "http" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "21b9ddb458710bc376481b842f5da65cdf31522de232c1ca8146abce2a358258" +dependencies = [ + "bytes", + "fnv", + "itoa", +] + +[[package]] +name = "http-body" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1efedce1fb8e6913f23e0c92de8e62cd5b772a67e7b3946df930a62566c93184" +dependencies = [ + "bytes", + "http", +] + +[[package]] +name = "http-body-util" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "793429d76616a256bcb62c2a2ec2bed781c8307e797e2598c50010f2bee2544f" +dependencies = [ + "bytes", + "futures-util", + "http", + "http-body", + "pin-project-lite", +] + +[[package]] +name = "httparse" +version = "1.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fcc0b4a115bf80b728eb8ea024ad5bd707b615bfed49e0665b6e0f86fd082d9" + +[[package]] +name = "httpdate" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df3b46402a9d5adb4c86a0cf463f42e19994e3ee891101b1841f30a545cb49a9" + +[[package]] +name = "hyper" +version = "1.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "50dfd22e0e76d0f662d429a5f80fcaf3855009297eab6a0a9f8543834744ba05" +dependencies = [ + "bytes", + "futures-channel", + "futures-util", + "h2", + "http", + "http-body", + "httparse", + "httpdate", + "itoa", + "pin-project-lite", + "smallvec", + "tokio", + "want", +] + +[[package]] +name = "iana-time-zone" +version = "0.1.60" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e7ffbb5a1b541ea2561f8c41c087286cc091e21e556a4f09a8f6cbf17b69b141" +dependencies = [ + "android_system_properties", + "core-foundation-sys", + "iana-time-zone-haiku", + "js-sys", + "wasm-bindgen", + "windows-core", +] + +[[package]] +name = "iana-time-zone-haiku" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f31827a206f56af32e590ba56d5d2d085f558508192593743f16b2306495269f" +dependencies = [ + "cc", +] + +[[package]] +name = "id-arena" +version = "2.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "25a2bc672d1148e28034f176e01fffebb08b35768468cc954630da77a1449005" + +[[package]] +name = "idna" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "634d9b1461af396cad843f47fdba5597a4f9e6ddd4bfb6ff5d85028c25cb12f6" +dependencies = [ + "unicode-bidi", + "unicode-normalization", +] + +[[package]] +name = "indexmap" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "68b900aa2f7301e21c36462b170ee99994de34dff39a4a6a528e80e7376d07e5" +dependencies = [ + "equivalent", + "hashbrown 0.14.5", + "serde", +] + +[[package]] +name = "io-extras" +version = "0.18.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c9f046b9af244f13b3bd939f55d16830ac3a201e8a9ba9661bfcb03e2be72b9b" +dependencies = [ + "io-lifetimes", + "windows-sys 0.52.0", +] + +[[package]] +name = "io-lifetimes" +version = "2.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a611371471e98973dbcab4e0ec66c31a10bc356eeb4d54a0e05eac8158fe38c" + +[[package]] +name = "ipnet" +version = "2.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "187674a687eed5fe42285b40c6291f9a01517d415fad1c3cbc6a9f778af7fcd4" + +[[package]] +name = "is_terminal_polyfill" +version = "1.70.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7943c866cc5cd64cbc25b2e01621d07fa8eb2a1a23160ee81ce38704e97b8ecf" + +[[package]] +name = "itertools" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba291022dbbd398a455acf126c1e341954079855bc60dfdda641363bd6922569" +dependencies = [ + "either", +] + +[[package]] +name = "itoa" +version = "1.0.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" + +[[package]] +name = "ittapi" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6b996fe614c41395cdaedf3cf408a9534851090959d90d54a535f675550b64b1" +dependencies = [ + "anyhow", + "ittapi-sys", + "log", +] + +[[package]] +name = "ittapi-sys" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "52f5385394064fa2c886205dba02598013ce83d3e92d33dbdc0c52fe0e7bf4fc" +dependencies = [ + "cc", +] + +[[package]] +name = "jobserver" +version = "0.1.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "48d1dbcbbeb6a7fec7e059840aa538bd62aaccf972c7346c4d9d2059312853d0" +dependencies = [ + "libc", +] + +[[package]] +name = "js-sys" +version = "0.3.70" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1868808506b929d7b0cfa8f75951347aa71bb21144b7791bae35d9bccfcfe37a" +dependencies = [ + "wasm-bindgen", +] + +[[package]] +name = "lazy_static" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" + +[[package]] +name = "leb128" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "884e2677b40cc8c339eaefcb701c32ef1fd2493d71118dc0ca4b6a736c93bd67" + +[[package]] +name = "libc" +version = "0.2.158" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d8adc4bb1803a324070e64a98ae98f38934d91957a99cfb3a43dcbc01bc56439" + +[[package]] +name = "libm" +version = "0.2.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ec2a862134d2a7d32d7983ddcdd1c4923530833c9f2ea1a44fc5fa473989058" + +[[package]] +name = "libredox" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c0ff37bd590ca25063e35af745c343cb7a0271906fb7b37e4813e8f79f00268d" +dependencies = [ + "bitflags", + "libc", +] + +[[package]] +name = "linux-raw-sys" +version = "0.4.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89" + +[[package]] +name = "log" +version = "0.4.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24" + +[[package]] +name = "mach2" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "19b955cdeb2a02b9117f121ce63aa52d08ade45de53e48fe6a38b39c10f6f709" +dependencies = [ + "libc", +] + +[[package]] +name = "matchers" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8263075bb86c5a1b1427b5ae862e8889656f126e9f77c484496e8b47cf5c5558" +dependencies = [ + "regex-automata 0.1.10", +] + +[[package]] +name = "maybe-owned" +version = "0.3.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4facc753ae494aeb6e3c22f839b158aebd4f9270f55cd3c79906c45476c47ab4" + +[[package]] +name = "memchr" +version = "2.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" + +[[package]] +name = "memfd" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b2cffa4ad52c6f791f4f8b15f0c05f9824b2ced1160e88cc393d64fff9a8ac64" +dependencies = [ + "rustix", +] + +[[package]] +name = "miniz_oxide" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2d80299ef12ff69b16a84bb182e3b9df68b5a91574d3d4fa6e41b65deec4df1" +dependencies = [ + "adler2", +] + +[[package]] +name = "mio" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "80e04d1dcff3aae0704555fe5fee3bcfaf3d1fdf8a7e521d5b9d2b42acb52cec" +dependencies = [ + "hermit-abi", + "libc", + "wasi", + "windows-sys 0.52.0", +] + +[[package]] +name = "nu-ansi-term" +version = "0.46.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77a8165726e8236064dbb45459242600304b42a5ea24ee2948e18e023bf7ba84" +dependencies = [ + "overload", + "winapi", +] + +[[package]] +name = "object" +version = "0.36.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "084f1a5821ac4c651660a94a7153d27ac9d8a53736203f58b31945ded098070a" +dependencies = [ + "crc32fast", + "hashbrown 0.14.5", + "indexmap", + "memchr", +] + +[[package]] +name = "once_cell" +version = "1.19.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" + +[[package]] +name = "overload" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b15813163c1d831bf4a13c3610c05c0d03b39feb07f7e09fa234dac9b15aaf39" + +[[package]] +name = "paste" +version = "1.0.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "57c0d7b74b563b49d38dae00a0c37d4d6de9b432382b2892f0574ddcae73fd0a" + +[[package]] +name = "percent-encoding" +version = "2.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e" + +[[package]] +name = "pin-project-lite" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" + +[[package]] +name = "pin-utils" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" + +[[package]] +name = "pkg-config" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d231b230927b5e4ad203db57bbcbee2802f6bce620b1e4a9024a07d94e2907ec" + +[[package]] +name = "postcard" +version = "1.0.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f7f0a8d620d71c457dd1d47df76bb18960378da56af4527aaa10f515eee732e" +dependencies = [ + "cobs", + "embedded-io 0.4.0", + "embedded-io 0.6.1", + "serde", +] + +[[package]] +name = "ppv-lite86" +version = "0.2.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77957b295656769bb8ad2b6a6b09d897d94f05c41b069aede1fcdaa675eaea04" +dependencies = [ + "zerocopy", +] + +[[package]] +name = "prettyplease" +version = "0.2.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "479cf940fbbb3426c32c5d5176f62ad57549a0bb84773423ba8be9d089f5faba" +dependencies = [ + "proc-macro2", + "syn", +] + +[[package]] +name = "proc-macro2" +version = "1.0.86" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5e719e8df665df0d1c8fbfd238015744736151d4445ec0836b8e628aae103b77" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "psm" +version = "0.1.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aa37f80ca58604976033fae9515a8a2989fc13797d953f7c04fb8fa36a11f205" +dependencies = [ + "cc", +] + +[[package]] +name = "quote" +version = "1.0.37" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b5b9d34b8991d19d98081b46eacdd8eb58c6f2b201139f7c5f643cc155a633af" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "rand" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" +dependencies = [ + "libc", + "rand_chacha", + "rand_core", +] + +[[package]] +name = "rand_chacha" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" +dependencies = [ + "ppv-lite86", + "rand_core", +] + +[[package]] +name = "rand_core" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" +dependencies = [ + "getrandom", +] + +[[package]] +name = "rayon" +version = "1.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b418a60154510ca1a002a752ca9714984e21e4241e804d32555251faf8b78ffa" +dependencies = [ + "either", + "rayon-core", +] + +[[package]] +name = "rayon-core" +version = "1.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1465873a3dfdaa8ae7cb14b4383657caab0b3e8a0aa9ae8e04b044854c8dfce2" +dependencies = [ + "crossbeam-deque", + "crossbeam-utils", +] + +[[package]] +name = "redox_users" +version = "0.4.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba009ff324d1fc1b900bd1fdb31564febe58a8ccc8a6fdbb93b543d33b13ca43" +dependencies = [ + "getrandom", + "libredox", + "thiserror", +] + +[[package]] +name = "regalloc2" +version = "0.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ad156d539c879b7a24a363a2016d77961786e71f48f2e2fc8302a92abd2429a6" +dependencies = [ + "hashbrown 0.13.2", + "log", + "rustc-hash", + "slice-group-by", + "smallvec", +] + +[[package]] +name = "regex" +version = "1.10.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4219d74c6b67a3654a9fbebc4b419e22126d13d2f3c4a07ee0cb61ff79a79619" +dependencies = [ + "aho-corasick", + "memchr", + "regex-automata 0.4.7", + "regex-syntax 0.8.4", +] + +[[package]] +name = "regex-automata" +version = "0.1.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c230d73fb8d8c1b9c0b3135c5142a8acee3a0558fb8db5cf1cb65f8d7862132" +dependencies = [ + "regex-syntax 0.6.29", +] + +[[package]] +name = "regex-automata" +version = "0.4.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38caf58cc5ef2fed281f89292ef23f6365465ed9a41b7a7754eb4e26496c92df" +dependencies = [ + "aho-corasick", + "memchr", + "regex-syntax 0.8.4", +] + +[[package]] +name = "regex-syntax" +version = "0.6.29" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f162c6dd7b008981e4d40210aca20b4bd0f9b60ca9271061b07f78537722f2e1" + +[[package]] +name = "regex-syntax" +version = "0.8.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a66a03ae7c801facd77a29370b4faec201768915ac14a721ba36f20bc9c209b" + +[[package]] +name = "ring" +version = "0.17.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c17fa4cb658e3583423e915b9f3acc01cceaee1860e33d59ebae66adc3a2dc0d" +dependencies = [ + "cc", + "cfg-if", + "getrandom", + "libc", + "spin", + "untrusted", + "windows-sys 0.52.0", +] + +[[package]] +name = "rustc-demangle" +version = "0.1.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" + +[[package]] +name = "rustc-hash" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" + +[[package]] +name = "rustix" +version = "0.38.37" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8acb788b847c24f28525660c4d7758620a7210875711f79e7f663cc152726811" +dependencies = [ + "bitflags", + "errno", + "itoa", + "libc", + "linux-raw-sys", + "once_cell", + "windows-sys 0.52.0", +] + +[[package]] +name = "rustls" +version = "0.22.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bf4ef73721ac7bcd79b2b315da7779d8fc09718c6b3d2d1b2d94850eb8c18432" +dependencies = [ + "log", + "ring", + "rustls-pki-types", + "rustls-webpki", + "subtle", + "zeroize", +] + +[[package]] +name = "rustls-pki-types" +version = "1.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fc0a2ce646f8655401bb81e7927b812614bd5d91dbc968696be50603510fcaf0" + +[[package]] +name = "rustls-webpki" +version = "0.102.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "64ca1bc8749bd4cf37b5ce386cc146580777b4e8572c7b97baf22c83f444bee9" +dependencies = [ + "ring", + "rustls-pki-types", + "untrusted", +] + +[[package]] +name = "ryu" +version = "1.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" + +[[package]] +name = "semver" +version = "1.0.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61697e0a1c7e512e84a621326239844a24d8207b4669b41bc18b32ea5cbf988b" +dependencies = [ + "serde", +] + +[[package]] +name = "serde" +version = "1.0.210" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c8e3592472072e6e22e0a54d5904d9febf8508f65fb8552499a1abc7d1078c3a" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.210" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "243902eda00fad750862fc144cea25caca5e20d615af0a81bee94ca738f1df1f" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "serde_json" +version = "1.0.128" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ff5456707a1de34e7e37f2a6fd3d3f808c318259cbd01ab6377795054b483d8" +dependencies = [ + "itoa", + "memchr", + "ryu", + "serde", +] + +[[package]] +name = "serde_spanned" +version = "0.6.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eb5b1b31579f3811bf615c144393417496f152e12ac8b7663bf664f4a815306d" +dependencies = [ + "serde", +] + +[[package]] +name = "sha2" +version = "0.10.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "793db75ad2bcafc3ffa7c68b215fee268f537982cd901d132f89c6343f3a3dc8" +dependencies = [ + "cfg-if", + "cpufeatures", + "digest", +] + +[[package]] +name = "sharded-slab" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f40ca3c46823713e0d4209592e8d6e826aa57e928f09752619fc696c499637f6" +dependencies = [ + "lazy_static", +] + +[[package]] +name = "shellexpand" +version = "2.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7ccc8076840c4da029af4f87e4e8daeb0fca6b87bbb02e10cb60b791450e11e4" +dependencies = [ + "dirs", +] + +[[package]] +name = "shlex" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" + +[[package]] +name = "slab" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" +dependencies = [ + "autocfg", +] + +[[package]] +name = "slice-group-by" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "826167069c09b99d56f31e9ae5c99049e932a98c9dc2dac47645b08dbbf76ba7" + +[[package]] +name = "smallvec" +version = "1.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" +dependencies = [ + "serde", +] + +[[package]] +name = "socket2" +version = "0.5.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce305eb0b4296696835b71df73eb912e0f1ffd2556a501fcede6e0c50349191c" +dependencies = [ + "libc", + "windows-sys 0.52.0", +] + +[[package]] +name = "spdx" +version = "0.10.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "47317bbaf63785b53861e1ae2d11b80d6b624211d42cb20efcd210ee6f8a14bc" +dependencies = [ + "smallvec", +] + +[[package]] +name = "spin" +version = "0.9.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67" + +[[package]] +name = "sptr" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3b9b39299b249ad65f3b7e96443bad61c02ca5cd3589f46cb6d610a0fd6c0d6a" + +[[package]] +name = "stable_deref_trait" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3" + +[[package]] +name = "strsim" +version = "0.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" + +[[package]] +name = "subtle" +version = "2.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" + +[[package]] +name = "syn" +version = "2.0.77" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9f35bcdf61fd8e7be6caf75f429fdca8beb3ed76584befb503b1569faee373ed" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "sync-test-component" +version = "0.1.0" +dependencies = [ + "wit-bindgen", +] + +[[package]] +name = "system-interface" +version = "0.27.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b858526d22750088a9b3cf2e3c2aacebd5377f13adeec02860c30d09113010a6" +dependencies = [ + "bitflags", + "cap-fs-ext", + "cap-std", + "fd-lock", + "io-lifetimes", + "rustix", + "windows-sys 0.52.0", + "winx", +] + +[[package]] +name = "target-lexicon" +version = "0.12.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61c41af27dd6d1e27b1b16b489db798443478cef1f06a660c96db617ba5de3b1" + +[[package]] +name = "tempfile" +version = "3.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "04cbcdd0c794ebb0d4cf35e88edd2f7d2c4c3e9a5a6dab322839b321c6a87a64" +dependencies = [ + "cfg-if", + "fastrand", + "once_cell", + "rustix", + "windows-sys 0.59.0", +] + +[[package]] +name = "termcolor" +version = "1.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "06794f8f6c5c898b3275aebefa6b8a1cb24cd2c6c79397ab15774837a0bc5755" +dependencies = [ + "winapi-util", +] + +[[package]] +name = "thiserror" +version = "1.0.63" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c0342370b38b6a11b6cc11d6a805569958d54cfa061a29969c3b5ce2ea405724" +dependencies = [ + "thiserror-impl", +] + +[[package]] +name = "thiserror-impl" +version = "1.0.63" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4558b58466b9ad7ca0f102865eccc95938dca1a74a856f2b57b6629050da261" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "thread_local" +version = "1.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b9ef9bad013ada3808854ceac7b46812a6465ba368859a37e2100283d2d719c" +dependencies = [ + "cfg-if", + "once_cell", +] + +[[package]] +name = "tinyvec" +version = "1.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "445e881f4f6d382d5f27c034e25eb92edd7c784ceab92a0937db7f2e9471b938" +dependencies = [ + "tinyvec_macros", +] + +[[package]] +name = "tinyvec_macros" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" + +[[package]] +name = "tokio" +version = "1.40.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2b070231665d27ad9ec9b8df639893f46727666c6767db40317fbe920a5d998" +dependencies = [ + "backtrace", + "bytes", + "libc", + "mio", + "pin-project-lite", + "socket2", + "windows-sys 0.52.0", +] + +[[package]] +name = "tokio-rustls" +version = "0.25.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "775e0c0f0adb3a2f22a00c4745d728b479985fc15ee7ca6a2608388c5569860f" +dependencies = [ + "rustls", + "rustls-pki-types", + "tokio", +] + +[[package]] +name = "tokio-util" +version = "0.7.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61e7c3654c13bcd040d4a03abee2c75b1d14a37b423cf5a813ceae1cc903ec6a" +dependencies = [ + "bytes", + "futures-core", + "futures-sink", + "pin-project-lite", + "tokio", +] + +[[package]] +name = "toml" +version = "0.8.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a1ed1f98e3fdc28d6d910e6737ae6ab1a93bf1985935a1193e68f93eeb68d24e" +dependencies = [ + "serde", + "serde_spanned", + "toml_datetime", + "toml_edit", +] + +[[package]] +name = "toml_datetime" +version = "0.6.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0dd7358ecb8fc2f8d014bf86f6f638ce72ba252a2c3a2572f2a795f1d23efb41" +dependencies = [ + "serde", +] + +[[package]] +name = "toml_edit" +version = "0.22.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "583c44c02ad26b0c3f3066fe629275e50627026c51ac2e595cca4c230ce1ce1d" +dependencies = [ + "indexmap", + "serde", + "serde_spanned", + "toml_datetime", + "winnow", +] + +[[package]] +name = "tracing" +version = "0.1.40" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3523ab5a71916ccf420eebdf5521fcef02141234bbc0b8a49f2fdc4544364ef" +dependencies = [ + "pin-project-lite", + "tracing-attributes", + "tracing-core", +] + +[[package]] +name = "tracing-attributes" +version = "0.1.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "tracing-core" +version = "0.1.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c06d3da6113f116aaee68e4d601191614c9053067f9ab7f6edbcb161237daa54" +dependencies = [ + "once_cell", + "valuable", +] + +[[package]] +name = "tracing-log" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ee855f1f400bd0e5c02d150ae5de3840039a3f54b025156404e34c23c03f47c3" +dependencies = [ + "log", + "once_cell", + "tracing-core", +] + +[[package]] +name = "tracing-subscriber" +version = "0.3.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ad0f048c97dbd9faa9b7df56362b8ebcaa52adb06b498c050d2f4e32f90a7a8b" +dependencies = [ + "matchers", + "nu-ansi-term", + "once_cell", + "regex", + "sharded-slab", + "smallvec", + "thread_local", + "tracing", + "tracing-core", + "tracing-log", +] + +[[package]] +name = "try-lock" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b" + +[[package]] +name = "typenum" +version = "1.17.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "42ff0bf0c66b8238c6f3b578df37d0b7848e55df8577b3f74f92a69acceeb825" + +[[package]] +name = "unicode-bidi" +version = "0.3.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08f95100a766bf4f8f28f90d77e0a5461bbdb219042e7679bebe79004fed8d75" + +[[package]] +name = "unicode-ident" +version = "1.0.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e91b56cd4cadaeb79bbf1a5645f6b4f8dc5bde8834ad5894a8db35fda9efa1fe" + +[[package]] +name = "unicode-normalization" +version = "0.1.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a56d1686db2308d901306f92a263857ef59ea39678a5458e7cb17f01415101f5" +dependencies = [ + "tinyvec", +] + +[[package]] +name = "unicode-width" +version = "0.1.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0336d538f7abc86d282a4189614dfaa90810dfc2c6f6427eaf88e16311dd225d" + +[[package]] +name = "unicode-xid" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "229730647fbc343e3a80e463c1db7f78f3855d3f3739bee0dda773c9a037c90a" + +[[package]] +name = "untrusted" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1" + +[[package]] +name = "url" +version = "2.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "22784dbdf76fdde8af1aeda5622b546b422b6fc585325248a2bf9f5e41e94d6c" +dependencies = [ + "form_urlencoded", + "idna", + "percent-encoding", +] + +[[package]] +name = "utf8parse" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821" + +[[package]] +name = "uuid" +version = "1.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "81dfa00651efa65069b0b6b651f4aaa31ba9e3c3ce0137aaad053604ee7e0314" + +[[package]] +name = "valuable" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "830b7e5d4d90034032940e4ace0d9a9a057e7a45cd94e6c007832e39edb82f6d" + +[[package]] +name = "version_check" +version = "0.9.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" + +[[package]] +name = "want" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bfa7760aed19e106de2c7c0b581b509f2f25d3dacaf737cb82ac61bc6d760b0e" +dependencies = [ + "try-lock", +] + +[[package]] +name = "wasi" +version = "0.11.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" + +[[package]] +name = "wasi-preview1-component-adapter-provider" +version = "24.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "36e6cadfa74538edd5409b6f8c79628436529138e9618b7373bec7aae7805835" + +[[package]] +name = "wasi-test-component" +version = "0.1.0" +dependencies = [ + "west-passthrough", + "wit-bindgen", +] + +[[package]] +name = "wasm-bindgen" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a82edfc16a6c469f5f44dc7b571814045d60404b55a0ee849f9bcfa2e63dd9b5" +dependencies = [ + "cfg-if", + "once_cell", + "wasm-bindgen-macro", +] + +[[package]] +name = "wasm-bindgen-backend" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9de396da306523044d3302746f1208fa71d7532227f15e347e2d93e4145dd77b" +dependencies = [ + "bumpalo", + "log", + "once_cell", + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "585c4c91a46b072c92e908d99cb1dcdf95c5218eeb6f3bf1efa991ee7a68cccf" +dependencies = [ + "quote", + "wasm-bindgen-macro-support", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "afc340c74d9005395cf9dd098506f7f44e38f2b4a21c6aaacf9a105ea5e1e836" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-backend", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-shared" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c62a0a307cb4a311d3a07867860911ca130c3494e8c2719593806c08bc5d0484" + +[[package]] +name = "wasm-encoder" +version = "0.215.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4fb56df3e06b8e6b77e37d2969a50ba51281029a9aeb3855e76b7f49b6418847" +dependencies = [ + "leb128", +] + +[[package]] +name = "wasm-encoder" +version = "0.217.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7b88b0814c9a2b323a9b46c687e726996c255ac8b64aa237dd11c81ed4854760" +dependencies = [ + "leb128", + "wasmparser 0.217.0", +] + +[[package]] +name = "wasm-metadata" +version = "0.217.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "65a146bf9a60e9264f0548a2599aa9656dba9a641eff9ab88299dc2a637e483c" +dependencies = [ + "anyhow", + "indexmap", + "serde", + "serde_derive", + "serde_json", + "spdx", + "wasm-encoder 0.217.0", + "wasmparser 0.217.0", +] + +[[package]] +name = "wasmparser" +version = "0.215.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53fbde0881f24199b81cf49b6ff8f9c145ac8eb1b7fc439adb5c099734f7d90e" +dependencies = [ + "ahash", + "bitflags", + "hashbrown 0.14.5", + "indexmap", + "semver", + "serde", +] + +[[package]] +name = "wasmparser" +version = "0.217.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ca917a21307d3adf2b9857b94dd05ebf8496bdcff4437a9b9fb3899d3e6c74e7" +dependencies = [ + "ahash", + "bitflags", + "hashbrown 0.14.5", + "indexmap", + "semver", + "serde", +] + +[[package]] +name = "wasmprinter" +version = "0.215.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d8e9a325d85053408209b3d2ce5eaddd0dd6864d1cff7a007147ba073157defc" +dependencies = [ + "anyhow", + "termcolor", + "wasmparser 0.215.0", +] + +[[package]] +name = "wasmtime" +version = "24.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a5883d64dfc8423c56e3d8df27cffc44db25336aa468e8e0724fddf30a333d7" +dependencies = [ + "addr2line 0.22.0", + "anyhow", + "async-trait", + "bitflags", + "bumpalo", + "cc", + "cfg-if", + "encoding_rs", + "fxprof-processed-profile", + "gimli 0.29.0", + "hashbrown 0.14.5", + "indexmap", + "ittapi", + "libc", + "libm", + "log", + "mach2", + "memfd", + "object", + "once_cell", + "paste", + "postcard", + "psm", + "rayon", + "rustix", + "semver", + "serde", + "serde_derive", + "serde_json", + "smallvec", + "sptr", + "target-lexicon", + "wasm-encoder 0.215.0", + "wasmparser 0.215.0", + "wasmtime-asm-macros", + "wasmtime-cache", + "wasmtime-component-macro", + "wasmtime-component-util", + "wasmtime-cranelift", + "wasmtime-environ", + "wasmtime-fiber", + "wasmtime-jit-debug", + "wasmtime-jit-icache-coherence", + "wasmtime-slab", + "wasmtime-versioned-export-macros", + "wasmtime-winch", + "wat", + "windows-sys 0.52.0", +] + +[[package]] +name = "wasmtime-asm-macros" +version = "24.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1c4dc7e2a379c0dd6be5b55857d14c4b277f43a9c429a9e14403eb61776ae3be" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "wasmtime-cache" +version = "24.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6a5b179f263a318e08c93281ea77cbb95e2a0c8c11e99a6188b53ead77233722" +dependencies = [ + "anyhow", + "base64", + "directories-next", + "log", + "postcard", + "rustix", + "serde", + "serde_derive", + "sha2", + "toml", + "windows-sys 0.52.0", + "zstd", +] + +[[package]] +name = "wasmtime-component-macro" +version = "24.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4b07773d1c3dab5f014ec61316ee317aa424033e17e70a63abdf7c3a47e58fcf" +dependencies = [ + "anyhow", + "proc-macro2", + "quote", + "syn", + "wasmtime-component-util", + "wasmtime-wit-bindgen", + "wit-parser 0.215.0", +] + +[[package]] +name = "wasmtime-component-util" +version = "24.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e38d735320f4e83478369ce649ad8fe87c6b893220902e798547a225fc0c5874" + +[[package]] +name = "wasmtime-cranelift" +version = "24.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e570d831d0785d93d7d8c722b1eb9a34e0d0c1534317666f65892818358a2da9" +dependencies = [ + "anyhow", + "cfg-if", + "cranelift-codegen", + "cranelift-control", + "cranelift-entity", + "cranelift-frontend", + "cranelift-native", + "cranelift-wasm", + "gimli 0.29.0", + "log", + "object", + "target-lexicon", + "thiserror", + "wasmparser 0.215.0", + "wasmtime-environ", + "wasmtime-versioned-export-macros", +] + +[[package]] +name = "wasmtime-environ" +version = "24.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c5fe80dfbd81687431a7d4f25929fae1ae96894786d5c96b14ae41164ee97377" +dependencies = [ + "anyhow", + "cpp_demangle", + "cranelift-bitset", + "cranelift-entity", + "gimli 0.29.0", + "indexmap", + "log", + "object", + "postcard", + "rustc-demangle", + "semver", + "serde", + "serde_derive", + "target-lexicon", + "wasm-encoder 0.215.0", + "wasmparser 0.215.0", + "wasmprinter", + "wasmtime-component-util", + "wasmtime-types", +] + +[[package]] +name = "wasmtime-fiber" +version = "24.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0f39043d13c7b58db69dc9a0feb191a961e75a9ec2402aebf42de183c022bb8a" +dependencies = [ + "anyhow", + "cc", + "cfg-if", + "rustix", + "wasmtime-asm-macros", + "wasmtime-versioned-export-macros", + "windows-sys 0.52.0", +] + +[[package]] +name = "wasmtime-jit-debug" +version = "24.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aec346412363eb26067cb6473281a45bd273cbbcafa3dc862793c946eff6ba7f" +dependencies = [ + "object", + "once_cell", + "rustix", + "wasmtime-versioned-export-macros", +] + +[[package]] +name = "wasmtime-jit-icache-coherence" +version = "24.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d15de8429db996f0d17a4163a35eccc3f874cbfb50f29c379951ea1bbb39452e" +dependencies = [ + "anyhow", + "cfg-if", + "libc", + "windows-sys 0.52.0", +] + +[[package]] +name = "wasmtime-slab" +version = "24.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1f68d38fa6b30c5e1fc7d608263062997306f79e577ebd197ddcd6b0f55d87d1" + +[[package]] +name = "wasmtime-types" +version = "24.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6634e7079d9c5cfc81af8610ed59b488cc5b7f9777a2f4c1667a2565c2e45249" +dependencies = [ + "anyhow", + "cranelift-entity", + "serde", + "serde_derive", + "smallvec", + "wasmparser 0.215.0", +] + +[[package]] +name = "wasmtime-versioned-export-macros" +version = "24.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3850e3511d6c7f11a72d571890b0ed5f6204681f7f050b9de2690e7f13123fed" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "wasmtime-wasi" +version = "24.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "545ae8298ffce025604f7480f9c7d6948c985bef7ce9aee249ef79307813e83c" +dependencies = [ + "anyhow", + "async-trait", + "bitflags", + "bytes", + "cap-fs-ext", + "cap-net-ext", + "cap-rand", + "cap-std", + "cap-time-ext", + "fs-set-times", + "futures", + "io-extras", + "io-lifetimes", + "once_cell", + "rustix", + "system-interface", + "thiserror", + "tokio", + "tracing", + "url", + "wasmtime", + "wiggle", + "windows-sys 0.52.0", +] + +[[package]] +name = "wasmtime-wasi-http" +version = "24.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f5b50208c61fed1ac138b6bf84b8b44c921ba16ac79b1a511804ecd95c98fd73" +dependencies = [ + "anyhow", + "async-trait", + "bytes", + "futures", + "http", + "http-body", + "http-body-util", + "hyper", + "rustls", + "tokio", + "tokio-rustls", + "tracing", + "wasmtime", + "wasmtime-wasi", + "webpki-roots", +] + +[[package]] +name = "wasmtime-winch" +version = "24.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2a25199625effa4c13dd790d64bd56884b014c69829431bfe43991c740bd5bc1" +dependencies = [ + "anyhow", + "cranelift-codegen", + "gimli 0.29.0", + "object", + "target-lexicon", + "wasmparser 0.215.0", + "wasmtime-cranelift", + "wasmtime-environ", + "winch-codegen", +] + +[[package]] +name = "wasmtime-wit-bindgen" +version = "24.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3cb331ac7ed1d5ba49cddcdb6b11973752a857148858bb308777d2fc5584121f" +dependencies = [ + "anyhow", + "heck 0.4.1", + "indexmap", + "wit-parser 0.215.0", +] + +[[package]] +name = "wast" +version = "35.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2ef140f1b49946586078353a453a1d28ba90adfc54dde75710bc1931de204d68" +dependencies = [ + "leb128", +] + +[[package]] +name = "wast" +version = "217.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "79004ecebded92d3c710d4841383368c7f04b63d0992ddd6b0c7d5029b7629b7" +dependencies = [ + "bumpalo", + "leb128", + "memchr", + "unicode-width", + "wasm-encoder 0.217.0", +] + +[[package]] +name = "wat" +version = "1.217.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c126271c3d92ca0f7c63e4e462e40c69cca52fd4245fcda730d1cf558fb55088" +dependencies = [ + "wast 217.0.0", +] + +[[package]] +name = "webpki-roots" +version = "0.26.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0bd24728e5af82c6c4ec1b66ac4844bdf8156257fccda846ec58b42cd0cdbe6a" +dependencies = [ + "rustls-pki-types", +] + +[[package]] +name = "west" +version = "0.1.0-alpha.1" +dependencies = [ + "anyhow", + "http", + "tokio", + "wasi-preview1-component-adapter-provider", + "wasmparser 0.217.0", + "wasmtime", + "wasmtime-wasi", + "wasmtime-wasi-http", + "wit-component", +] + +[[package]] +name = "west-passthrough" +version = "0.1.0-alpha.1" +dependencies = [ + "wit-bindgen", +] + +[[package]] +name = "west-sys" +version = "0.1.0-alpha.1" +dependencies = [ + "anyhow", + "cbindgen", + "tracing", + "tracing-subscriber", + "wasmtime", + "wasmtime-wasi", + "wasmtime-wasi-http", + "west", +] + +[[package]] +name = "wiggle" +version = "24.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cc850ca3c02c5835934d23f28cec4c5a3fb66fe0b4ecd968bbb35609dda5ddc0" +dependencies = [ + "anyhow", + "async-trait", + "bitflags", + "thiserror", + "tracing", + "wasmtime", + "wiggle-macro", +] + +[[package]] +name = "wiggle-generate" +version = "24.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "634b8804a67200bcb43ea8af5f7c53e862439a086b68b16fd333454bc74d5aab" +dependencies = [ + "anyhow", + "heck 0.4.1", + "proc-macro2", + "quote", + "shellexpand", + "syn", + "witx", +] + +[[package]] +name = "wiggle-macro" +version = "24.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "474b7cbdb942c74031e619d66c600bba7f73867c5800fc2c2306cf307649be2f" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "wiggle-generate", +] + +[[package]] +name = "winapi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" +dependencies = [ + "winapi-i686-pc-windows-gnu", + "winapi-x86_64-pc-windows-gnu", +] + +[[package]] +name = "winapi-i686-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" + +[[package]] +name = "winapi-util" +version = "0.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf221c93e13a30d793f7645a0e7762c55d169dbb0a49671918a2319d289b10bb" +dependencies = [ + "windows-sys 0.59.0", +] + +[[package]] +name = "winapi-x86_64-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" + +[[package]] +name = "winch-codegen" +version = "0.22.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "073efe897d9ead7fc609874f94580afc831114af5149b6a90ee0a3a39b497fe0" +dependencies = [ + "anyhow", + "cranelift-codegen", + "gimli 0.29.0", + "regalloc2", + "smallvec", + "target-lexicon", + "wasmparser 0.215.0", + "wasmtime-cranelift", + "wasmtime-environ", +] + +[[package]] +name = "windows-core" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "33ab640c8d7e35bf8ba19b884ba838ceb4fba93a4e8c65a9059d08afcfc683d9" +dependencies = [ + "windows-targets", +] + +[[package]] +name = "windows-sys" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets", +] + +[[package]] +name = "windows-sys" +version = "0.59.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" +dependencies = [ + "windows-targets", +] + +[[package]] +name = "windows-targets" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" +dependencies = [ + "windows_aarch64_gnullvm", + "windows_aarch64_msvc", + "windows_i686_gnu", + "windows_i686_gnullvm", + "windows_i686_msvc", + "windows_x86_64_gnu", + "windows_x86_64_gnullvm", + "windows_x86_64_msvc", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" + +[[package]] +name = "windows_i686_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" + +[[package]] +name = "windows_i686_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" + +[[package]] +name = "winnow" +version = "0.6.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "68a9bda4691f099d435ad181000724da8e5899daa10713c2d432552b9ccd3a6f" +dependencies = [ + "memchr", +] + +[[package]] +name = "winx" +version = "0.36.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f9643b83820c0cd246ecabe5fa454dd04ba4fa67996369466d0747472d337346" +dependencies = [ + "bitflags", + "windows-sys 0.52.0", +] + +[[package]] +name = "wit-bindgen" +version = "0.32.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0eb9327b2afd6af02ab39f8fbde6bfc7d369d14bc8c8688311d3defcda3952bd" +dependencies = [ + "wit-bindgen-rt", + "wit-bindgen-rust-macro", +] + +[[package]] +name = "wit-bindgen-core" +version = "0.32.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fc9cfd3f1b4e29e9a90fe04157764f24ae396cfb8530dae5753de140e73f9e56" +dependencies = [ + "anyhow", + "heck 0.5.0", + "wit-parser 0.217.0", +] + +[[package]] +name = "wit-bindgen-rt" +version = "0.32.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5ca6f307148acf7199e492fd3781cc7b79f8f3eda003c0ac3aa8079449601ccb" +dependencies = [ + "bitflags", +] + +[[package]] +name = "wit-bindgen-rust" +version = "0.32.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf075ae0c89dc391f7d710d70c69bfd018c029c74a54f7ddfd0266dccc8ff0c5" +dependencies = [ + "anyhow", + "heck 0.5.0", + "indexmap", + "prettyplease", + "syn", + "wasm-metadata", + "wit-bindgen-core", + "wit-component", +] + +[[package]] +name = "wit-bindgen-rust-macro" +version = "0.32.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a2ab28d36e4d326bd43d483512348874d4fffa378d8dc1da6dd6521afe2ec4f6" +dependencies = [ + "anyhow", + "prettyplease", + "proc-macro2", + "quote", + "syn", + "wit-bindgen-core", + "wit-bindgen-rust", +] + +[[package]] +name = "wit-component" +version = "0.217.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d7117809905e49db716d81e794f79590c052bf2fdbbcda1731ca0fb28f6f3ddf" +dependencies = [ + "anyhow", + "bitflags", + "indexmap", + "log", + "serde", + "serde_derive", + "serde_json", + "wasm-encoder 0.217.0", + "wasm-metadata", + "wasmparser 0.217.0", + "wit-parser 0.217.0", +] + +[[package]] +name = "wit-parser" +version = "0.215.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "935a97eaffd57c3b413aa510f8f0b550a4a9fe7d59e79cd8b89a83dcb860321f" +dependencies = [ + "anyhow", + "id-arena", + "indexmap", + "log", + "semver", + "serde", + "serde_derive", + "serde_json", + "unicode-xid", + "wasmparser 0.215.0", +] + +[[package]] +name = "wit-parser" +version = "0.217.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fb893dcd6d370cfdf19a0d9adfcd403efb8e544e1a0ea3a8b81a21fe392eaa78" +dependencies = [ + "anyhow", + "id-arena", + "indexmap", + "log", + "semver", + "serde", + "serde_derive", + "serde_json", + "unicode-xid", + "wasmparser 0.217.0", +] + +[[package]] +name = "witx" +version = "0.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e366f27a5cabcddb2706a78296a40b8fcc451e1a6aba2fc1d94b4a01bdaaef4b" +dependencies = [ + "anyhow", + "log", + "thiserror", + "wast 35.0.2", +] + +[[package]] +name = "zerocopy" +version = "0.7.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b9b4fd18abc82b8136838da5d50bae7bdea537c574d8dc1a34ed098d6c166f0" +dependencies = [ + "byteorder", + "zerocopy-derive", +] + +[[package]] +name = "zerocopy-derive" +version = "0.7.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "zeroize" +version = "1.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ced3678a2879b30306d323f4542626697a464a97c0a07c9aebf7ebca65cd4dde" + +[[package]] +name = "zstd" +version = "0.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fcf2b778a664581e31e389454a7072dab1647606d44f7feea22cd5abb9c9f3f9" +dependencies = [ + "zstd-safe", +] + +[[package]] +name = "zstd-safe" +version = "7.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "54a3ab4db68cea366acc5c897c7b4d4d1b8994a9cd6e6f841f8964566a419059" +dependencies = [ + "zstd-sys", +] + +[[package]] +name = "zstd-sys" +version = "2.0.13+zstd.1.5.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38ff0f21cfee8f97d94cef41359e0c89aa6113028ab0291aa8ca0038995a95aa" +dependencies = [ + "cc", + "pkg-config", +] diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..93c00e9 --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,54 @@ +[package] +name = "west" +version = "0.1.0-alpha.1" +description = "WebAssembly component test runtime" + +authors.workspace = true +categories.workspace = true +edition.workspace = true +license.workspace = true +repository.workspace = true + +[workspace] +members = ["crates/*", "tests/components/*"] + +[workspace.package] +authors = ["Roman Volosatovs "] +categories = ["wasm"] +edition = "2021" +homepage = "https://github.com/rvolosatovs/west" +license = "Apache-2.0 WITH LLVM-exception" +repository = "https://github.com/rvolosatovs/west" + +[dependencies] +anyhow = { workspace = true } +http = { workspace = true } +tokio = { workspace = true } +wasi-preview1-component-adapter-provider = { workspace = true } +wasmparser = { workspace = true } +wasmtime = { workspace = true } +wasmtime-wasi = { workspace = true } +wasmtime-wasi-http = { workspace = true } +wit-component = { workspace = true } + +[build-dependencies] +anyhow = { workspace = true } +wasi-preview1-component-adapter-provider = { workspace = true } +wit-component = { workspace = true } + +[workspace.dependencies] +anyhow = "1" +cbindgen = "0.27" +http = "1" +tokio = "1" +tracing = "0.1" +tracing-subscriber = "0.3" +wasi-preview1-component-adapter-provider = "24" +wasmparser = "0.217" +wasmtime = "24" +wasmtime-wasi = "24" +wasmtime-wasi-http = "24" +west-passthrough = { version = "0.1.0-alpha.1", path = "./crates/passthrough" } +west = { version = "0.1.0-alpha.1", path = "." } +wit-bindgen = "0.32" +wit-component = "0.217" diff --git a/build.rs b/build.rs new file mode 100644 index 0000000..5062cc0 --- /dev/null +++ b/build.rs @@ -0,0 +1,53 @@ +use std::path::PathBuf; +use std::process::{Command, Stdio}; +use std::{env, fs}; + +use anyhow::{ensure, Context as _}; +use wasi_preview1_component_adapter_provider::{ + WASI_SNAPSHOT_PREVIEW1_ADAPTER_NAME, WASI_SNAPSHOT_PREVIEW1_REACTOR_ADAPTER, +}; + +fn main() -> anyhow::Result<()> { + println!("cargo:rerun-if-changed=crates/passthrough"); + + let out_dir = env::var("OUT_DIR") + .map(PathBuf::from) + .context("failed to lookup `OUT_DIR`")?; + let status = Command::new(env::var("CARGO").unwrap()) + .args([ + "build", + "-p", + "west-passthrough", + "--release", + "--target", + "wasm32-wasip1", + "--target-dir", + ]) + .arg(&out_dir) + .stderr(Stdio::inherit()) + .stdout(Stdio::inherit()) + .status() + .context("failed to invoke `cargo`")?; + ensure!(status.success(), "`cargo` invocation failed"); + let path = out_dir + .join("wasm32-wasip1") + .join("release") + .join("west_passthrough.wasm"); + let module = fs::read(&path).with_context(|| format!("failed to read `{}`", path.display()))?; + let component = wit_component::ComponentEncoder::default() + .validate(true) + .module(&module) + .context("failed to set core component module")? + .adapter( + WASI_SNAPSHOT_PREVIEW1_ADAPTER_NAME, + WASI_SNAPSHOT_PREVIEW1_REACTOR_ADAPTER, + ) + .context("failed to add WASI adapter")? + .encode() + .with_context(|| format!("failed to encode `{}`", path.display()))?; + + let path = out_dir.join("west_passthrough.wasm"); + fs::write(&path, component).with_context(|| format!("failed to write `{}`", path.display()))?; + + Ok(()) +} diff --git a/crates/passthrough/Cargo.toml b/crates/passthrough/Cargo.toml new file mode 100644 index 0000000..03092c7 --- /dev/null +++ b/crates/passthrough/Cargo.toml @@ -0,0 +1,16 @@ +[package] +name = "west-passthrough" +version = "0.1.0-alpha.1" +description = "WebAssembly component, which reexports WASI from the host" + +authors.workspace = true +categories.workspace = true +edition.workspace = true +license.workspace = true +repository.workspace = true + +[lib] +crate-type = ["rlib", "cdylib"] + +[dependencies] +wit-bindgen = { workspace = true, features = ["realloc", "macros"] } diff --git a/crates/passthrough/src/bindings.rs b/crates/passthrough/src/bindings.rs new file mode 100644 index 0000000..689dc4c --- /dev/null +++ b/crates/passthrough/src/bindings.rs @@ -0,0 +1,94 @@ +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 new file mode 100644 index 0000000..2dc0b04 --- /dev/null +++ b/crates/passthrough/src/cli.rs @@ -0,0 +1,74 @@ +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 new file mode 100644 index 0000000..4811584 --- /dev/null +++ b/crates/passthrough/src/clocks.rs @@ -0,0 +1,24 @@ +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 new file mode 100644 index 0000000..ee6897b --- /dev/null +++ b/crates/passthrough/src/filesystem.rs @@ -0,0 +1,253 @@ +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 new file mode 100644 index 0000000..ed7ff2b --- /dev/null +++ b/crates/passthrough/src/http.rs @@ -0,0 +1,611 @@ +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 new file mode 100644 index 0000000..15c1f3b --- /dev/null +++ b/crates/passthrough/src/io.rs @@ -0,0 +1,148 @@ +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 new file mode 100644 index 0000000..263333a --- /dev/null +++ b/crates/passthrough/src/lib.rs @@ -0,0 +1,10 @@ +mod bindings; +mod cli; +mod clocks; +mod filesystem; +mod http; +mod io; +mod sockets; +mod west; + +pub struct Handler; diff --git a/crates/passthrough/src/sockets.rs b/crates/passthrough/src/sockets.rs new file mode 100644 index 0000000..5f2f5d2 --- /dev/null +++ b/crates/passthrough/src/sockets.rs @@ -0,0 +1,284 @@ +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 new file mode 100644 index 0000000..c4bbebf --- /dev/null +++ b/crates/passthrough/src/west.rs @@ -0,0 +1,25 @@ +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 new file mode 120000 index 0000000..902b548 --- /dev/null +++ b/crates/passthrough/wit @@ -0,0 +1 @@ +../../wit \ No newline at end of file diff --git a/crates/sys/Cargo.toml b/crates/sys/Cargo.toml new file mode 100644 index 0000000..10a7844 --- /dev/null +++ b/crates/sys/Cargo.toml @@ -0,0 +1,26 @@ +[package] +name = "west-sys" +version = "0.1.0-alpha.1" +description = "WebAssembly component test runtime C bindings" + +authors.workspace = true +categories.workspace = true +edition.workspace = true +license.workspace = true +repository.workspace = true + +[lib] +crate-type = ["cdylib", "staticlib"] + +[dependencies] +anyhow = { workspace = true } +tracing = { workspace = true } +tracing-subscriber = { workspace = true, features = ["env-filter", "fmt"] } +wasmtime = { workspace = true } +wasmtime-wasi = { workspace = true } +wasmtime-wasi-http = { workspace = true } +west = { workspace = true } + +[build-dependencies] +anyhow = { workspace = true } +cbindgen = { workspace = true } diff --git a/crates/sys/build.rs b/crates/sys/build.rs new file mode 100644 index 0000000..97e8d73 --- /dev/null +++ b/crates/sys/build.rs @@ -0,0 +1,25 @@ +use std::env; +use std::path::Path; + +use anyhow::Context as _; + +fn main() -> anyhow::Result<()> { + let crate_dir = + env::var("CARGO_MANIFEST_DIR").context("failed to lookup `CARGO_MANIFEST_DIR`")?; + let bindings = cbindgen::generate_with_config( + &crate_dir, + cbindgen::Config { + language: cbindgen::Language::C, + ..Default::default() + }, + ) + .context("failed to generate bindings")?; + bindings.write_to_file( + Path::new(&crate_dir) + .join("..") + .join("..") + .join("include") + .join("west.h"), + ); + Ok(()) +} diff --git a/crates/sys/src/ffi.rs b/crates/sys/src/ffi.rs new file mode 100644 index 0000000..55f5a0e --- /dev/null +++ b/crates/sys/src/ffi.rs @@ -0,0 +1,78 @@ +use core::ffi::{c_char, c_void}; +use core::ptr::{self, null_mut}; + +use std::ffi::CString; +use std::sync::{LazyLock, Mutex}; + +use crate::{call, instantiate, Config, List, PASSTHROUGH_LEN, PASSTHROUGH_PTR}; + +static ERROR: LazyLock>> = LazyLock::new(Mutex::default); + +fn store_error(err: anyhow::Error) { + let _ = ERROR + .lock() + .unwrap() + .insert(CString::new(format!("{err:?}")).expect("failed to construct error string")); +} + +#[no_mangle] +pub extern "C" fn default_config() -> Config { + Config { + wasm: List { + ptr: PASSTHROUGH_PTR, + len: PASSTHROUGH_LEN, + }, + } +} + +#[no_mangle] +pub extern "C" fn error_take(buf: *mut c_char, len: usize) -> usize { + if let Some(err) = ERROR.lock().unwrap().take() { + let len = err.count_bytes().saturating_add(1).min(len); + unsafe { ptr::copy_nonoverlapping(err.as_ptr(), buf, len) }; + len + } else { + 0 + } +} + +#[no_mangle] +pub extern "C" fn error_len() -> usize { + if let Some(err) = ERROR.lock().unwrap().as_ref() { + err.count_bytes().saturating_add(1) + } else { + 0 + } +} + +#[no_mangle] +pub extern "C" fn instance_new(config: Config) -> *mut c_void { + match instantiate(config) { + Ok(instance) => Box::into_raw(Box::new(instance)).cast(), + Err(err) => { + store_error(err); + null_mut() + } + } +} + +#[no_mangle] +pub extern "C" fn instance_free(instance: *mut c_void) { + unsafe { drop(Box::from_raw(instance)) } +} + +#[no_mangle] +pub extern "C" fn instance_call( + instance_ptr: *mut c_void, + instance: *const c_char, + name: *const c_char, + args: *const *mut c_void, +) -> bool { + match call(instance_ptr, instance, name, args) { + Ok(()) => true, + Err(err) => { + store_error(err); + false + } + } +} diff --git a/crates/sys/src/lib.rs b/crates/sys/src/lib.rs new file mode 100644 index 0000000..da63ca6 --- /dev/null +++ b/crates/sys/src/lib.rs @@ -0,0 +1,1385 @@ +use core::alloc::Layout; +use core::ffi::{c_char, c_void, CStr}; +use core::iter::zip; +use core::mem; +use core::ops::{BitOrAssign, Deref, DerefMut, Shl}; +use core::ptr::{copy_nonoverlapping, null, NonNull}; +use core::slice; + +use std::alloc::alloc; +use std::collections::HashSet; +use std::sync::{Arc, LazyLock}; + +use anyhow::{bail, ensure, Context as _}; +use tracing::{instrument, trace_span}; +use tracing_subscriber::EnvFilter; +use wasmtime::component::{types, Resource, ResourceAny, ResourceType, Type, Val}; +use wasmtime::Store; +use wasmtime_wasi::WasiView; + +mod ffi; + +static ENGINE: LazyLock = LazyLock::new(wasmtime::Engine::default); + +pub const PASSTHROUGH_PTR: *const u8 = west::PASSTHROUGH.as_ptr(); +pub const PASSTHROUGH_LEN: usize = west::PASSTHROUGH.len(); + +#[repr(C)] +#[derive(Debug)] +pub struct List { + pub ptr: *const T, + pub len: usize, +} + +#[repr(C)] +#[derive(Debug)] +pub struct Config { + pub wasm: List, +} + +pub struct Instance { + instance: west::Instance, + subscriber: Arc, +} + +impl Deref for Instance { + type Target = west::Instance; + + fn deref(&self) -> &Self::Target { + &self.instance + } +} + +impl DerefMut for Instance { + fn deref_mut(&mut self) -> &mut Self::Target { + &mut self.instance + } +} + +#[instrument(level = "trace")] +fn instantiate(config: Config) -> anyhow::Result { + let Config { wasm } = config; + ensure!(!wasm.ptr.is_null(), "`wasm_ptr` must not be null"); + let wasm = unsafe { slice::from_raw_parts(wasm.ptr, wasm.len) }; + let instance = west::instantiate(west::Config { + engine: ENGINE.clone(), + wasm, + }) + .context("failed to instantiate component")?; + let subscriber = tracing_subscriber::fmt() + .without_time() + .with_env_filter(EnvFilter::from_env("WEST_LOG")) + .finish(); + Ok(Instance { + instance, + subscriber: Arc::new(subscriber), + }) +} + +#[instrument(level = "trace", ret(level = "trace"))] +fn align_of_record(ty: &types::Record) -> usize { + ty.fields().map(|ty| align_of(&ty.ty)).max().unwrap_or(1) +} + +#[instrument(level = "trace", ret(level = "trace"))] +fn align_of_tuple(ty: &types::Tuple) -> usize { + ty.types().map(|ty| align_of(&ty)).max().unwrap_or(1) +} + +#[instrument(level = "trace", skip_all, ret(level = "trace"))] +fn max_case_alignment<'a>(cases: impl IntoIterator>) -> usize { + cases + .into_iter() + .filter_map(|types::Case { ty, .. }| ty.as_ref().map(align_of)) + .max() + .unwrap_or(1) +} + +#[instrument(level = "trace", ret(level = "trace"))] +fn align_of_variant(ty: &types::Variant) -> usize { + let cases = ty.cases(); + let disc = match cases.len() { + ..=0x0000_00ff => 1, + 0x0000_0100..=0x0000_ffff => 2, + 0x0001_0000.. => 4, + }; + max_case_alignment(cases).max(disc) +} + +#[instrument(level = "trace", ret(level = "trace"))] +fn align_of_option(ty: &types::OptionType) -> usize { + align_of(&ty.ty()) +} + +#[instrument(level = "trace", ret(level = "trace"))] +fn align_of_result(ty: &types::ResultType) -> usize { + let ok = ty.ok().as_ref().map_or(1, align_of); + let err = ty.err().as_ref().map_or(1, align_of); + ok.max(err) +} + +#[instrument(level = "trace", ret(level = "trace"))] +fn align_of(ty: &Type) -> usize { + match ty { + Type::Bool | Type::S8 | Type::U8 => 1, + Type::S16 | Type::U16 => 2, + Type::S32 | Type::U32 | Type::Float32 | Type::Char | Type::Own(_) | Type::Borrow(_) => 4, + Type::S64 | Type::U64 | Type::Float64 => 8, + Type::String | Type::List(_) => mem::align_of::<(*const (), usize)>(), + Type::Record(ty) => align_of_record(ty), + Type::Tuple(ty) => align_of_tuple(ty), + Type::Variant(ty) => align_of_variant(ty), + Type::Enum(ty) => match ty.names().len() { + ..=0x0000_00ff => 1, + 0x0000_0100..=0x0000_ffff => 2, + 0x0001_0000.. => 4, + }, + Type::Option(ty) => align_of_option(ty), + Type::Result(ty) => align_of_result(ty), + Type::Flags(ty) => match ty.names().len() { + ..=8 => 1, + 9..=16 => 2, + _ => 4, + }, + } +} + +#[instrument(level = "trace", ret(level = "trace"))] +fn align_to(addr: usize, align: usize) -> usize { + addr.div_ceil(align).saturating_mul(align) +} + +#[instrument(level = "trace", ret(level = "trace"))] +fn size_of_record(ty: &types::Record) -> usize { + let mut size = 0usize; + for types::Field { ty, .. } in ty.fields() { + size = align_to(size, align_of(&ty)).saturating_add(size_of(&ty)); + } + align_to(size, align_of_record(ty)) +} + +#[instrument(level = "trace", ret(level = "trace"))] +fn size_of_tuple(ty: &types::Tuple) -> usize { + let mut size = 0usize; + for ty in ty.types() { + size = align_to(size, align_of(&ty)).saturating_add(size_of(&ty)); + } + align_to(size, align_of_tuple(ty)) +} + +#[instrument(level = "trace", ret(level = "trace"))] +fn size_of_variant(ty: &types::Variant) -> usize { + let cases = ty.cases(); + let size: usize = match cases.len() { + ..=0x0000_00ff => 1, + 0x0000_0100..=0x0000_ffff => 2, + 0x0001_0000.. => 4, + }; + let size = align_to(size, max_case_alignment(ty.cases())); + let size = size.saturating_add( + cases + .map(|types::Case { ty, .. }| ty.as_ref().map(size_of).unwrap_or_default()) + .max() + .unwrap_or_default(), + ); + align_to(size, align_of_variant(ty)) +} + +#[instrument(level = "trace", ret(level = "trace"))] +fn size_of_option(ty: &types::OptionType) -> usize { + let size = size_of(&ty.ty()).saturating_add(1); + align_to(size, align_of_option(ty)) +} + +#[instrument(level = "trace", ret(level = "trace"))] +fn size_of_result(ty: &types::ResultType) -> usize { + let ok = ty.ok().as_ref().map(size_of).unwrap_or_default(); + let err = ty.err().as_ref().map(size_of).unwrap_or_default(); + let size = ok.max(err).saturating_add(1); + align_to(size, align_of_result(ty)) +} + +#[instrument(level = "trace", ret(level = "trace"))] +fn size_of(ty: &Type) -> usize { + match ty { + Type::Bool | Type::S8 | Type::U8 => 1, + Type::S16 | Type::U16 => 2, + Type::S32 | Type::U32 | Type::Float32 | Type::Char | Type::Own(_) | Type::Borrow(_) => 4, + Type::S64 | Type::U64 | Type::Float64 => 8, + Type::String | Type::List(_) => mem::size_of::<(*const (), usize)>(), + Type::Record(ty) => size_of_record(ty), + Type::Tuple(ty) => size_of_tuple(ty), + Type::Variant(ty) => size_of_variant(ty), + Type::Enum(ty) => match ty.names().len() { + ..=0x0000_00ff => 1, + 0x0000_0100..=0x0000_ffff => 2, + 0x0001_0000.. => 4, + }, + Type::Option(ty) => size_of_option(ty), + Type::Result(ty) => size_of_result(ty), + Type::Flags(ty) => match ty.names().len() { + ..=8 => 1, + 9..=16 => 2, + _ => 4, + }, + } +} + +#[instrument(level = "trace", ret(level = "trace"))] +fn args_of_variant(ty: &types::Variant) -> usize { + ty.cases() + .map(|ty| ty.ty.map(|ty| args_of(&ty)).unwrap_or_default()) + .max() + .unwrap_or_default() + .saturating_add(1) +} + +#[instrument(level = "trace", ret(level = "trace"))] +fn args_of_result(ty: &types::ResultType) -> usize { + let ok = ty.ok().as_ref().map(args_of).unwrap_or_default(); + let err = ty.err().as_ref().map(args_of).unwrap_or_default(); + ok.max(err).saturating_add(1) +} + +#[instrument(level = "trace", ret(level = "trace"))] +fn args_of(ty: &Type) -> usize { + match ty { + Type::Bool + | Type::S8 + | Type::U8 + | Type::S16 + | Type::U16 + | Type::S32 + | Type::U32 + | Type::Float32 + | Type::Char + | Type::Own(_) + | Type::Borrow(_) + | Type::S64 + | Type::U64 + | Type::Float64 + | Type::Enum(_) + | Type::Flags(_) => 1, + Type::String | Type::List(_) => 2, + Type::Record(ty) => ty.fields().map(|ty| args_of(&ty.ty)).sum(), + Type::Tuple(ty) => ty.types().map(|ty| args_of(&ty)).sum(), + Type::Variant(ty) => args_of_variant(ty), + Type::Option(ty) => args_of(&ty.ty()).saturating_add(1), + Type::Result(ty) => args_of_result(ty), + } +} + +#[inline] +fn flag_bits<'a, T: BitOrAssign + Shl + From>( + names: impl IntoIterator, + flags: impl IntoIterator, +) -> T { + let mut v = T::from(0); + let flags: HashSet<&str> = flags.into_iter().collect(); + for (i, name) in zip(0u8.., names) { + if flags.contains(name) { + v |= T::from(1) << i; + } + } + v +} + +fn find_enum_discriminant<'a, T>( + iter: impl IntoIterator, + names: impl IntoIterator, + disc: &str, +) -> anyhow::Result { + zip(iter, names) + .find_map(|(i, name)| (name == disc).then_some(i)) + .context("unknown enum discriminant") +} + +fn find_variant_discriminant<'a, T>( + iter: impl IntoIterator, + cases: impl IntoIterator>, + disc: &str, +) -> anyhow::Result<(T, Option)> { + zip(iter, cases) + .find_map(|(i, types::Case { name, ty })| (name == disc).then_some((i, ty))) + .context("unknown variant discriminant") +} + +fn deref_arg(args: *const *mut c_void) -> anyhow::Result<(NonNull, *const *mut c_void)> { + let args: NonNull<*mut c_void> = + NonNull::new(args.cast_mut()).context("argument cannot be null")?; + let data = unsafe { args.read() }; + let data = NonNull::new(data.cast()).context("value cannot be null")?; + Ok((data, args.as_ptr().wrapping_add(1))) +} + +#[instrument(level = "trace", skip(store, ty, src), ret(level = "trace"))] +fn lower( + store: &mut Store, + ty: &Type, + dst: NonNull, + src: Val, +) -> anyhow::Result<*mut c_void> { + match (src, ty) { + (Val::Bool(val), Type::Bool) => { + let dst = dst.cast(); + unsafe { dst.write(val) }; + Ok(dst.as_ptr().wrapping_add(1).cast()) + } + (Val::S8(val), Type::S8) => { + let dst = dst.cast(); + unsafe { dst.write(val) }; + Ok(dst.as_ptr().wrapping_add(1).cast()) + } + (Val::U8(val), Type::U8) => { + let dst = dst.cast(); + unsafe { dst.write(val) }; + Ok(dst.as_ptr().wrapping_add(1).cast()) + } + (Val::S16(val), Type::S16) => { + let dst = dst.cast(); + unsafe { dst.write(val) }; + Ok(dst.as_ptr().wrapping_add(1).cast()) + } + (Val::U16(val), Type::U16) => { + let dst = dst.cast(); + unsafe { dst.write(val) }; + Ok(dst.as_ptr().wrapping_add(1).cast()) + } + (Val::S32(val), Type::S32) => { + let dst = dst.cast(); + unsafe { dst.write(val) }; + Ok(dst.as_ptr().wrapping_add(1).cast()) + } + (Val::U32(val), Type::U32) => { + let dst = dst.cast(); + unsafe { dst.write(val) }; + Ok(dst.as_ptr().wrapping_add(1).cast()) + } + (Val::S64(val), Type::S64) => { + let dst = dst.cast(); + unsafe { dst.write(val) }; + Ok(dst.as_ptr().wrapping_add(1).cast()) + } + (Val::U64(val), Type::U64) => { + let dst = dst.cast(); + unsafe { dst.write(val) }; + Ok(dst.as_ptr().wrapping_add(1).cast()) + } + (Val::Float32(val), Type::Float32) => { + let dst = dst.cast(); + unsafe { dst.write(val) }; + Ok(dst.as_ptr().wrapping_add(1).cast()) + } + (Val::Float64(val), Type::Float64) => { + let dst = dst.cast(); + unsafe { dst.write(val) }; + Ok(dst.as_ptr().wrapping_add(1).cast()) + } + (Val::Char(val), Type::Char) => { + let dst = dst.cast(); + unsafe { dst.write(val) }; + Ok(dst.as_ptr().wrapping_add(1).cast()) + } + (Val::String(val), Type::String) => { + let dst = dst.cast::<(*const u8, usize)>(); + if val.is_empty() { + unsafe { dst.write((null(), 0)) } + } else { + let size = val.len(); + let layout = Layout::from_size_align(size, 1) + .context("failed to construct string memory layout")?; + let data = unsafe { alloc(layout) }; + unsafe { copy_nonoverlapping(val.as_ptr(), data, size) } + unsafe { dst.write((data, size)) } + } + Ok(dst.as_ptr().wrapping_add(1).cast()) + } + (Val::List(vals), Type::List(ty)) => { + let dst = dst.cast::<(*const c_void, usize)>(); + if vals.is_empty() { + unsafe { dst.write((null(), 0)) } + } else { + let ty = ty.ty(); + let len = vals.len(); + let size = size_of(&ty).saturating_mul(len); + let align = align_of(&ty); + let layout = Layout::from_size_align(size, align) + .context("failed to construct list memory layout")?; + let start = unsafe { alloc(layout) }.cast::(); + let mut data = start; + for (i, val) in vals.into_iter().enumerate() { + let dst = NonNull::new(data) + .with_context(|| format!("list element `{i}` cannot be null"))?; + data = lower(store, &ty, dst, val) + .with_context(|| format!("failed to lower list element `{i}`"))?; + } + unsafe { dst.write((start, len)) } + } + Ok(dst.as_ptr().wrapping_add(1).cast()) + } + (Val::Record(vals), Type::Record(ty)) => { + let mut data = dst.as_ptr(); + for (i, (ty, (_, val))) in zip(ty.fields(), vals).enumerate() { + let offset = data.cast::().align_offset(align_of(&ty.ty)); + if offset > 0 { + data = data.wrapping_add(offset).cast(); + } + let dst = NonNull::new(data) + .with_context(|| format!("record field `{i}` cannot be null"))?; + data = lower(store, &ty.ty, dst, val) + .with_context(|| format!("failed to lower record field `{i}`"))?; + } + Ok(data) + } + (Val::Tuple(vals), Type::Tuple(ty)) => { + let mut data = dst.as_ptr(); + for (i, (ty, val)) in zip(ty.types(), vals).enumerate() { + let offset = data.cast::().align_offset(align_of(&ty)); + if offset > 0 { + data = data.wrapping_add(offset).cast(); + } + let dst = NonNull::new(data) + .with_context(|| format!("tuple element `{i}` cannot be null"))?; + data = lower(store, &ty, dst, val) + .with_context(|| format!("failed to lower tuple element `{i}`"))?; + } + Ok(data) + } + (Val::Variant(disc, val), Type::Variant(ty)) => { + let cases = ty.cases(); + let data = dst.cast::().as_ptr().wrapping_add(size_of_variant(ty)); + let align = max_case_alignment(ty.cases()); + let (mut dst, ty) = match cases.len() { + ..=0x0000_00ff => { + let (disc, ty) = find_variant_discriminant(0u8.., cases, &disc)?; + let dst = dst.cast(); + unsafe { dst.write(disc) }; + (dst.as_ptr().wrapping_add(1).cast::(), ty) + } + 0x0000_0100..=0x0000_ffff => { + let (disc, ty) = find_variant_discriminant(0u16.., cases, &disc)?; + let dst = dst.cast(); + unsafe { dst.write(disc) }; + (dst.as_ptr().wrapping_add(1).cast::(), ty) + } + 0x0001_0000..=0xffff_ffff => { + let (disc, ty) = find_variant_discriminant(0u32.., cases, &disc)?; + let dst = dst.cast(); + unsafe { dst.write(disc) }; + (dst.as_ptr().wrapping_add(1).cast::(), ty) + } + 0x1_0000_0000.. => bail!("variant case count does not fit in u32"), + }; + if let Some((ty, val)) = ty.zip(val) { + let offset = dst.cast::().align_offset(align); + if offset > 0 { + dst = dst.wrapping_add(offset).cast(); + } + let dst = NonNull::new(dst).with_context(|| { + format!("variant value for discriminant `{disc}` cannot be null") + })?; + lower(store, &ty, dst, *val).with_context(|| { + format!("failed to lower variant value for discriminant `{disc}`") + })?; + } + Ok(data.cast()) + } + (Val::Enum(disc), Type::Enum(ty)) => { + let names = ty.names(); + match names.len() { + ..=0x0000_00ff => { + let disc = find_enum_discriminant(0u8.., names, &disc)?; + let dst = dst.cast(); + unsafe { dst.write(disc) }; + Ok(dst.as_ptr().wrapping_add(1).cast()) + } + 0x0000_0100..=0x0000_ffff => { + let disc = find_enum_discriminant(0u16.., names, &disc)?; + let dst = dst.cast(); + unsafe { dst.write(disc) }; + Ok(dst.as_ptr().wrapping_add(1).cast()) + } + 0x0001_0000..=0xffff_ffff => { + let disc = find_enum_discriminant(0u32.., names, &disc)?; + let dst = dst.cast(); + unsafe { dst.write(disc) }; + Ok(dst.as_ptr().wrapping_add(1).cast()) + } + 0x1_0000_0000.. => bail!("enum name count does not fit in u32"), + } + } + (Val::Option(val), Type::Option(ty)) => { + let dst = dst.cast::(); + let data = dst.as_ptr().wrapping_add(size_of_option(ty)); + match val { + None => { + unsafe { dst.write(0) }; + } + Some(val) => { + unsafe { dst.write(1) }; + let mut dst = dst.as_ptr().wrapping_add(1); + let offset = dst.align_offset(align_of(&ty.ty())); + if offset > 0 { + dst = dst.wrapping_add(offset); + } + let dst = NonNull::new(dst.cast()) + .context("`option::some` payload cannot be null")?; + lower(store, &ty.ty(), dst, *val).context("failed to lower `option::some`")?; + } + } + Ok(data.cast()) + } + (Val::Result(val), Type::Result(ty)) => { + let dst = dst.cast::(); + let data = dst.as_ptr().wrapping_add(size_of_result(ty)); + let align = align_of_result(ty); + match val { + Ok(val) => { + unsafe { dst.write(0) }; + if let Some((ty, val)) = ty.ok().zip(val) { + let mut dst = dst.as_ptr().wrapping_add(1); + let offset = dst.align_offset(align); + if offset > 0 { + dst = dst.wrapping_add(offset); + } + let dst = NonNull::new(dst.cast()) + .context("typed `result::ok` payload cannot be null")?; + lower(store, &ty, dst, *val).context("failed to lower `result::ok`")?; + } + } + Err(val) => { + unsafe { dst.write(1) }; + if let Some((ty, val)) = ty.err().zip(val) { + let mut dst = dst.as_ptr().wrapping_add(1); + let offset = dst.align_offset(align); + if offset > 0 { + dst = dst.wrapping_add(offset); + } + let dst = NonNull::new(dst.cast()) + .context("typed `result::err` payload cannot be null")?; + lower(store, &ty, dst, *val).context("failed to lower `result::error`")?; + } + } + } + Ok(data.cast()) + } + (Val::Flags(val), Type::Flags(ty)) => { + let names = ty.names(); + let vs = val.iter().map(String::as_str); + match names.len() { + ..=8 => { + let v: u8 = flag_bits(names, vs); + let dst = dst.cast(); + unsafe { dst.write(v) }; + Ok(dst.as_ptr().wrapping_add(1).cast()) + } + 9..=16 => { + let v: u16 = flag_bits(names, vs); + let dst = dst.cast(); + unsafe { dst.write(v) }; + Ok(dst.as_ptr().wrapping_add(1).cast()) + } + 17..=32 => { + let v: u32 = flag_bits(names, vs); + let dst = dst.cast(); + unsafe { dst.write(v) }; + Ok(dst.as_ptr().wrapping_add(1).cast()) + } + _ => bail!("flags with over 32 cases are not currently supported"), + } + } + (Val::Resource(val), Type::Own(..) | Type::Borrow(..)) => { + let dst = dst.cast::(); + let res = store.data_mut().table().push(val)?; + unsafe { dst.write(res.rep()) }; + Ok(dst.as_ptr().wrapping_add(1).cast()) + } + _ => bail!("type mismatch"), + } +} + +#[instrument(level = "trace", skip_all, ret(level = "trace"))] +fn lower_results( + store: &mut Store, + vals: Vec, + tys: &[Type], + args: *const *mut c_void, +) -> anyhow::Result<()> { + if vals.is_empty() { + return Ok(()); + } + let args: NonNull<*mut c_void> = + NonNull::new(args.cast_mut()).context("argument cannot be null")?; + let data = unsafe { args.read() }; + zip(vals, tys) + .enumerate() + .try_fold(data, |data, (i, (val, ty))| -> anyhow::Result<_> { + let data = + NonNull::new(data).with_context(|| format!("result value {i} cannot be null"))?; + lower(store, ty, data, val).with_context(|| format!("failed to lower result value {i}")) + })?; + Ok(()) +} + +#[instrument(level = "trace", skip_all, ret(level = "trace"))] +fn lift_bool(dst: &mut Val, src: NonNull) -> *const c_void { + let src = src.cast::(); + let data = unsafe { src.read() }; + *dst = Val::Bool(data != 0); + src.as_ptr().wrapping_add(1).cast() +} + +#[instrument(level = "trace", skip_all, ret(level = "trace"))] +fn lift_s8(dst: &mut Val, src: NonNull) -> *const c_void { + let src = src.cast::(); + let data = unsafe { src.read() }; + *dst = Val::S8(data); + src.as_ptr().wrapping_add(1).cast() +} + +#[instrument(level = "trace", skip_all, ret(level = "trace"))] +fn lift_u8(dst: &mut Val, src: NonNull) -> *const c_void { + let src = src.cast::(); + let data = unsafe { src.read() }; + *dst = Val::U8(data); + src.as_ptr().wrapping_add(1).cast() +} + +#[instrument(level = "trace", skip_all, ret(level = "trace"))] +fn lift_s16(dst: &mut Val, src: NonNull) -> *const c_void { + let src = src.cast::(); + let data = unsafe { src.read() }; + *dst = Val::S16(data); + src.as_ptr().wrapping_add(1).cast() +} + +#[instrument(level = "trace", skip_all, ret(level = "trace"))] +fn lift_u16(dst: &mut Val, src: NonNull) -> *const c_void { + let src = src.cast::(); + let data = unsafe { src.read() }; + *dst = Val::U16(data); + src.as_ptr().wrapping_add(1).cast() +} + +#[instrument(level = "trace", skip_all, ret(level = "trace"))] +fn lift_s32(dst: &mut Val, src: NonNull) -> *const c_void { + let src = src.cast::(); + *dst = Val::S32(unsafe { src.read() }); + src.as_ptr().wrapping_add(1).cast() +} + +#[instrument(level = "trace", skip_all, ret(level = "trace"))] +fn lift_u32(dst: &mut Val, src: NonNull) -> *const c_void { + let src = src.cast::(); + *dst = Val::U32(unsafe { src.read() }); + src.as_ptr().wrapping_add(1).cast() +} + +#[instrument(level = "trace", skip_all, ret(level = "trace"))] +fn lift_s64(dst: &mut Val, src: NonNull) -> *const c_void { + let src = src.cast::(); + *dst = Val::S64(unsafe { src.read() }); + src.as_ptr().wrapping_add(1).cast() +} + +#[instrument(level = "trace", skip_all, ret(level = "trace"))] +fn lift_u64(dst: &mut Val, src: NonNull) -> *const c_void { + let src = src.cast::(); + *dst = Val::U64(unsafe { src.read() }); + src.as_ptr().wrapping_add(1).cast() +} + +#[instrument(level = "trace", skip_all, ret(level = "trace"))] +fn lift_f32(dst: &mut Val, src: NonNull) -> *const c_void { + let src = src.cast::(); + *dst = Val::Float32(unsafe { src.read() }); + src.as_ptr().wrapping_add(1).cast() +} + +#[instrument(level = "trace", skip_all, ret(level = "trace"))] +fn lift_f64(dst: &mut Val, src: NonNull) -> *const c_void { + let src = src.cast::(); + *dst = Val::Float64(unsafe { src.read() }); + src.as_ptr().wrapping_add(1).cast() +} + +#[instrument(level = "trace", skip_all, ret(level = "trace"))] +fn lift_char(dst: &mut Val, src: NonNull) -> anyhow::Result<*const c_void> { + let src = src.cast::(); + let data = unsafe { src.read() }; + let data = char::from_u32(data).with_context(|| format!("`{data}` is not a valid char"))?; + *dst = Val::Char(data); + Ok(src.as_ptr().wrapping_add(1).cast()) +} + +#[instrument(level = "trace", skip_all, ret(level = "trace"))] +fn lift_string(dst: &mut Val, src: NonNull) -> anyhow::Result<*const c_void> { + let src = src.cast::<(*mut u8, usize)>(); + let (data, len) = unsafe { src.read() }; + if len > 0 { + let data = NonNull::new(data).context("string data pointer cannot be null")?; + let data = NonNull::slice_from_raw_parts(data, len); + let data = String::from_utf8_lossy(unsafe { data.as_ref() }); + *dst = Val::String(data.into()); + } else { + *dst = Val::String(String::default()); + } + Ok(src.as_ptr().wrapping_add(1).cast()) +} + +#[instrument(level = "trace", skip_all, ret(level = "trace"))] +fn lift_list( + store: &mut Store, + dst: &mut Val, + src: NonNull, + ty: &types::List, +) -> anyhow::Result<*const c_void> { + let src = src.cast::<(*const c_void, usize)>(); + let (mut data, len) = unsafe { src.read() }; + if len > 0 { + let mut vs = vec![Val::Bool(false); len]; + let ty = ty.ty(); + let align = align_of(&ty); + for (i, v) in vs.iter_mut().enumerate() { + let offset = data.cast::().align_offset(align); + if offset > 0 { + data = data.wrapping_add(offset).cast(); + } + let src = NonNull::new(data.cast_mut()) + .with_context(|| format!("list element `{i}` pointer cannot be null"))?; + data = lift(store, &ty, v, src) + .with_context(|| format!("failed to lift list element `{i}`"))?; + } + *dst = Val::List(vs); + } else { + *dst = Val::List(Vec::default()); + } + Ok(src.as_ptr().wrapping_add(1).cast()) +} + +#[instrument(level = "trace", skip_all, ret(level = "trace"))] +fn lift_record( + store: &mut Store, + dst: &mut Val, + src: NonNull, + ty: &types::Record, +) -> anyhow::Result<*const c_void> { + let fields = ty.fields(); + let mut vs = Vec::with_capacity(fields.len()); + let mut data = src.as_ptr().cast_const(); + for (i, ty) in fields.enumerate() { + let mut v = Val::Bool(false); + let offset = data.cast::().align_offset(align_of(&ty.ty)); + if offset > 0 { + data = data.wrapping_add(offset).cast(); + } + let src = NonNull::new(data.cast_mut()) + .with_context(|| format!("record field `{i}` pointer cannot be null"))?; + data = lift(store, &ty.ty, &mut v, src) + .with_context(|| format!("failed to lift record field `{i}`"))?; + vs.push((ty.name.to_string(), v)); + } + *dst = Val::Record(vs); + Ok(data) +} + +#[instrument(level = "trace", skip_all, ret(level = "trace"))] +fn lift_tuple( + store: &mut Store, + dst: &mut Val, + src: NonNull, + ty: &types::Tuple, +) -> anyhow::Result<*const c_void> { + let types = ty.types(); + let mut vs = vec![Val::Bool(false); types.len()]; + let mut data = src.as_ptr().cast_const(); + for (i, (ty, v)) in zip(types, &mut vs).enumerate() { + let offset = data.cast::().align_offset(align_of(&ty)); + if offset > 0 { + data = data.wrapping_add(offset).cast(); + } + let src = NonNull::new(data.cast_mut()) + .with_context(|| format!("tuple element `{i}` pointer cannot be null"))?; + data = lift(store, &ty, v, src) + .with_context(|| format!("failed to lift tuple element `{i}`"))?; + } + *dst = Val::Tuple(vs); + Ok(data) +} + +fn read_discriminant(src: NonNull, cases: usize) -> anyhow::Result<(usize, *const c_void)> { + match cases { + ..=0x0000_00ff => { + let data = src.cast::(); + let disc = unsafe { data.read() }; + Ok((disc.into(), data.as_ptr().wrapping_add(1).cast())) + } + 0x0000_0100..=0x0000_ffff => { + let data = src.cast::(); + let disc = unsafe { data.read() }; + Ok((disc.into(), data.as_ptr().wrapping_add(1).cast())) + } + 0x0001_0000..=0xffff_ffff => { + let data = src.cast::(); + let disc = unsafe { data.read() }; + let disc = disc + .try_into() + .with_context(|| format!("discriminant `{disc}` does not fit in usize"))?; + Ok((disc, data.as_ptr().wrapping_add(1).cast())) + } + 0x1_0000_0000.. => bail!("case count does not fit in u32"), + } +} + +fn read_variant_case( + src: NonNull, + ty: &types::Variant, +) -> anyhow::Result<(types::Case, *const c_void)> { + let mut cases = ty.cases(); + let (disc, src) = + read_discriminant(src, cases.len()).context("failed to read variant discriminant")?; + let ty = cases + .nth(disc) + .with_context(|| format!("unknown variant discriminant `{disc}`"))?; + Ok((ty, src)) +} + +#[instrument(level = "trace", skip_all, ret(level = "trace"))] +fn lift_variant( + store: &mut Store, + dst: &mut Val, + src: NonNull, + ty: &types::Variant, +) -> anyhow::Result<*const c_void> { + let size = size_of_variant(ty); + let align = max_case_alignment(ty.cases()); + let (ty, mut data) = read_variant_case(src, ty)?; + let name = ty.name.to_string(); + if let Some(ty) = ty.ty { + let mut v = Val::Bool(false); + let offset = data.cast::().align_offset(align); + if offset > 0 { + data = data.wrapping_add(offset).cast(); + } + let data = NonNull::new(data.cast_mut()) + .with_context(|| format!("variant value cannot be null for variant case `{name}`"))?; + lift(store, &ty, &mut v, data) + .with_context(|| format!("failed to lift variant value for variant case `{name}`"))?; + *dst = Val::Variant(name, Some(Box::new(v))); + } else { + *dst = Val::Variant(name, None); + } + Ok(src.as_ptr().cast::().wrapping_add(size).cast()) +} + +#[instrument(level = "trace", skip_all, ret(level = "trace"))] +fn lift_enum( + dst: &mut Val, + src: NonNull, + ty: &types::Enum, +) -> anyhow::Result<*const c_void> { + let mut names = ty.names(); + let (disc, src) = + read_discriminant(src, names.len()).context("failed to read enum discriminant")?; + let name = names + .nth(disc) + .with_context(|| format!("unknown enum discriminant `{disc}`"))?; + *dst = Val::Enum(name.to_string()); + Ok(src) +} + +#[instrument(level = "trace", skip_all, ret(level = "trace"))] +fn lift_flags( + dst: &mut Val, + src: NonNull, + ty: &types::Flags, +) -> anyhow::Result<*const c_void> { + let names = ty.names(); + let (bits, src) = match names.len() { + ..=8 => { + let data = src.cast::(); + let disc = unsafe { data.read() }; + (disc.into(), data.as_ptr().wrapping_add(1).cast()) + } + 9..=16 => { + let data = src.cast::(); + let disc = unsafe { data.read() }; + (disc.into(), data.as_ptr().wrapping_add(1).cast()) + } + 17..=32 => { + let data = src.cast::(); + let disc = unsafe { data.read() }; + (disc, data.as_ptr().wrapping_add(1).cast()) + } + _ => bail!("flags with over 32 cases are not currently supported"), + }; + let mut vs = Vec::with_capacity(bits.count_ones().try_into().unwrap_or(usize::MAX)); + for (i, name) in zip(0.., names) { + if bits & (1 << i) != 0 { + vs.push(name.to_string()); + } + } + *dst = Val::Flags(vs); + Ok(src) +} + +#[instrument(level = "trace", skip_all, ret(level = "trace"))] +fn lift_option( + store: &mut Store, + dst: &mut Val, + src: NonNull, + ty: &types::OptionType, +) -> anyhow::Result<*const c_void> { + let src = src.cast::(); + let data = src.as_ptr().wrapping_add(size_of_option(ty)); + match unsafe { src.read() } { + 0 => { + *dst = Val::Option(None); + } + 1 => { + let mut v = Val::Bool(false); + let mut src = src.as_ptr().wrapping_add(1); + let offset = src.align_offset(align_of(&ty.ty())); + if offset > 0 { + src = src.wrapping_add(offset); + } + let src = NonNull::new(src.cast()).context("`option::some` payload cannot be null")?; + lift(store, &ty.ty(), &mut v, src)?; + *dst = Val::Option(Some(Box::new(v))); + } + disc => bail!("invalid option discriminant value {disc}"), + } + Ok(data.cast()) +} + +#[instrument(level = "trace", skip_all, ret(level = "trace"))] +fn lift_result( + store: &mut Store, + dst: &mut Val, + src: NonNull, + ty: &types::ResultType, +) -> anyhow::Result<*const c_void> { + let src = src.cast::(); + let data = src.as_ptr().wrapping_add(size_of_result(ty)); + let align = align_of_result(ty); + match unsafe { src.read() } { + 0 => { + if let Some(ty) = ty.ok() { + let mut v = Val::Bool(false); + let mut src = src.as_ptr().wrapping_add(1); + let offset = src.align_offset(align); + if offset > 0 { + src = src.wrapping_add(offset); + } + let src = + NonNull::new(src.cast()).context("`result::ok` payload cannot be null")?; + lift(store, &ty, &mut v, src)?; + *dst = Val::Result(Ok(Some(Box::new(v)))); + } else { + *dst = Val::Result(Ok(None)); + } + } + 1 => { + if let Some(ty) = ty.err() { + let mut v = Val::Bool(false); + let mut src = src.as_ptr().wrapping_add(1); + let offset = src.align_offset(align); + if offset > 0 { + src = src.wrapping_add(offset); + } + let src = + NonNull::new(src.cast()).context("`result::err` payload cannot be null")?; + lift(store, &ty, &mut v, src)?; + *dst = Val::Result(Err(Some(Box::new(v)))); + } else { + *dst = Val::Result(Err(None)); + } + } + disc => bail!("invalid result discriminant value {disc}"), + } + Ok(data.cast()) +} + +#[instrument(level = "trace", skip_all, ret(level = "trace"))] +fn lift_own( + store: &mut Store, + dst: &mut Val, + src: NonNull, + ty: &ResourceType, +) -> anyhow::Result<*const c_void> { + let src = src.cast::(); + let rep = unsafe { src.read() }; + let res = store + .data_mut() + .table() + .delete::(Resource::new_own(rep)) + .context("failed to delete resource from table")?; + ensure!(*ty == res.ty()); + *dst = Val::Resource(res); + Ok(src.as_ptr().wrapping_add(1).cast()) +} + +#[instrument(level = "trace", skip_all, ret(level = "trace"))] +fn lift_borrow( + store: &mut Store, + dst: &mut Val, + src: NonNull, + ty: &ResourceType, +) -> anyhow::Result<*const c_void> { + let src = src.cast::(); + let rep = unsafe { src.read() }; + let res = store + .data_mut() + .table() + .get::(&Resource::new_borrow(rep))?; + ensure!(*ty == res.ty()); + *dst = Val::Resource(*res); + Ok(src.as_ptr().wrapping_add(1).cast()) +} + +#[instrument(level = "trace", skip_all, ret(level = "trace"))] +fn lift( + store: &mut Store, + ty: &Type, + dst: &mut Val, + src: NonNull, +) -> anyhow::Result<*const c_void> { + match ty { + Type::Bool => Ok(lift_bool(dst, src)), + Type::S8 => Ok(lift_s8(dst, src)), + Type::U8 => Ok(lift_u8(dst, src)), + Type::S16 => Ok(lift_s16(dst, src)), + Type::U16 => Ok(lift_u16(dst, src)), + Type::S32 => Ok(lift_s32(dst, src)), + Type::U32 => Ok(lift_u32(dst, src)), + Type::S64 => Ok(lift_s64(dst, src)), + Type::U64 => Ok(lift_u64(dst, src)), + Type::Float32 => Ok(lift_f32(dst, src)), + Type::Float64 => Ok(lift_f64(dst, src)), + Type::Char => lift_char(dst, src), + Type::String => lift_string(dst, src), + Type::List(ty) => lift_list(store, dst, src, ty), + Type::Record(ty) => lift_record(store, dst, src, ty), + Type::Tuple(ty) => lift_tuple(store, dst, src, ty), + Type::Variant(ty) => lift_variant(store, dst, src, ty), + Type::Enum(ty) => lift_enum(dst, src, ty), + Type::Option(ty) => lift_option(store, dst, src, ty), + Type::Result(ty) => lift_result(store, dst, src, ty), + Type::Flags(ty) => lift_flags(dst, src, ty), + Type::Own(ty) => lift_own(store, dst, src, ty), + Type::Borrow(ty) => lift_borrow(store, dst, src, ty), + } +} + +#[instrument(level = "trace", skip_all, ret(level = "trace"))] +fn lift_param( + store: &mut Store, + ty: &Type, + val: &mut Val, + args: *const *mut c_void, +) -> anyhow::Result<*const *mut c_void> { + match ty { + Type::Bool => { + let (data, args) = deref_arg::(args)?; + let data = unsafe { data.read() }; + ensure!(data >= 0); + *val = Val::Bool(data != 0); + Ok(args) + } + Type::S8 => { + let (data, args) = deref_arg::(args)?; + let data = unsafe { data.read() }; + let data = data + .try_into() + .with_context(|| format!("s8 value `{data}` does not fit in i8"))?; + *val = Val::S8(data); + Ok(args) + } + Type::U8 => { + let (data, args) = deref_arg::(args)?; + let data = unsafe { data.read() }; + let data = data + .try_into() + .with_context(|| format!("u8 value `{data}` does not fit in u8"))?; + *val = Val::U8(data); + Ok(args) + } + Type::S16 => { + let (data, args) = deref_arg::(args)?; + let data = unsafe { data.read() }; + let data = data + .try_into() + .with_context(|| format!("s16 value `{data}` does not fit in i16"))?; + *val = Val::S16(data); + Ok(args) + } + Type::U16 => { + let (data, args) = deref_arg::(args)?; + let data = unsafe { data.read() }; + let data = data + .try_into() + .with_context(|| format!("u16 value `{data}` does not fit in u16"))?; + *val = Val::U16(data); + Ok(args) + } + Type::S32 => { + let (data, args) = deref_arg::(args)?; + lift_s32(val, data); + Ok(args) + } + Type::U32 => { + let (data, args) = deref_arg::(args)?; + lift_u32(val, data); + Ok(args) + } + Type::S64 => { + let (data, args) = deref_arg::(args)?; + lift_s64(val, data); + Ok(args) + } + Type::U64 => { + let (data, args) = deref_arg::(args)?; + lift_u64(val, data); + Ok(args) + } + Type::Float32 => { + let (data, args) = deref_arg::(args)?; + lift_f32(val, data); + Ok(args) + } + Type::Float64 => { + let (data, args) = deref_arg::(args)?; + lift_f64(val, data); + Ok(args) + } + Type::Char => { + let (data, args) = deref_arg::(args)?; + lift_char(val, data).context("failed to lift char")?; + Ok(args) + } + Type::String => { + let args = NonNull::new(args.cast_mut()).context("argument cannot be null")?; + let data = unsafe { args.read() }; + let args = args.as_ptr().wrapping_add(1); + let (len, args) = deref_arg::(args)?; + let len = unsafe { len.read() }; + let len = len + .try_into() + .with_context(|| format!("string length value `{len}` does not fit in usize"))?; + if len > 0 { + let data = + NonNull::new(data.cast()).context("string data pointer cannot be null")?; + let data = NonNull::slice_from_raw_parts(data, len); + let data = String::from_utf8_lossy(unsafe { data.as_ref() }); + *val = Val::String(data.into()); + } else { + *val = Val::String(String::default()); + } + Ok(args) + } + Type::List(ty) => { + let args = NonNull::new(args.cast_mut()).context("argument cannot be null")?; + let data = unsafe { args.read() }; + let args = args.as_ptr().wrapping_add(1); + let (len, args) = deref_arg::(args)?; + let len = unsafe { len.read() }; + if len > 0 { + let len = len + .try_into() + .with_context(|| format!("list length value `{len}` does not fit in usize"))?; + let mut vs = vec![Val::Bool(false); len]; + let ty = ty.ty(); + let align = align_of(&ty); + let mut data = data.cast_const(); + for (i, dst) in vs.iter_mut().enumerate() { + let offset = data.cast::().align_offset(align); + if offset > 0 { + data = data.wrapping_add(offset).cast(); + } + let src = NonNull::new(data.cast_mut()) + .with_context(|| format!("list element `{i}` cannot be null"))?; + data = lift(store, &ty, dst, src) + .with_context(|| format!("failed to lift list element `{i}`"))?; + } + *val = Val::List(vs); + } else { + *val = Val::List(Vec::default()); + } + Ok(args) + } + Type::Record(ty) => { + let fields = ty.fields(); + let mut vs = Vec::with_capacity(fields.len()); + let mut args = args; + for (i, ty) in fields.enumerate() { + let mut v = Val::Bool(false); + args = lift_param(store, &ty.ty, &mut v, args) + .with_context(|| format!("failed to lift record field `{i}`"))?; + vs.push((ty.name.to_string(), v)); + } + *val = Val::Record(vs); + Ok(args) + } + Type::Tuple(ty) => { + let types = ty.types(); + let mut vs = vec![Val::Bool(false); types.len()]; + let mut args = args; + for (i, (ty, v)) in zip(types, &mut vs).enumerate() { + args = lift_param(store, &ty, v, args) + .with_context(|| format!("failed to lift tuple element `{i}`"))?; + } + *val = Val::Tuple(vs); + Ok(args) + } + Type::Variant(ty) => { + let (disc, data) = deref_arg::(args)?; + let args = args.wrapping_add(args_of_variant(ty)); + let (ty, _) = read_variant_case(disc, ty)?; + let name = ty.name.to_string(); + if let Some(ty) = ty.ty { + let mut v = Val::Bool(false); + lift_param(store, &ty, &mut v, data).with_context(|| { + format!("failed to lift variant value for variant case `{name}`") + })?; + *val = Val::Variant(name, Some(Box::new(v))); + } else { + *val = Val::Variant(name, None); + } + Ok(args) + } + Type::Enum(ty) => { + let (disc, args) = deref_arg::(args)?; + lift_enum(val, disc, ty)?; + Ok(args) + } + Type::Option(ty) => { + let (disc, args) = deref_arg::(args)?; + match unsafe { disc.read() } { + 0 => { + *val = Val::Option(None); + Ok(args.wrapping_add(args_of(&ty.ty()))) + } + 1 => { + let mut v = Val::Bool(false); + let args = lift_param(store, &ty.ty(), &mut v, args)?; + *val = Val::Option(Some(Box::new(v))); + Ok(args) + } + disc => bail!("invalid option discriminant value {disc}"), + } + } + Type::Result(ty) => { + let (disc, args) = deref_arg::(args)?; + let ok = ty.ok(); + let err = ty.err(); + match unsafe { disc.read() } { + 0 => { + if let Some(ty) = ok.as_ref() { + let mut v = Val::Bool(false); + lift_param(store, ty, &mut v, args)?; + *val = Val::Result(Ok(Some(Box::new(v)))); + } else { + *val = Val::Result(Ok(None)); + } + } + 1 => { + if let Some(ty) = err.as_ref() { + let mut v = Val::Bool(false); + lift_param(store, ty, &mut v, args)?; + *val = Val::Result(Err(Some(Box::new(v)))); + } else { + *val = Val::Result(Err(None)); + } + } + disc => bail!("invalid result discriminant value {disc}"), + } + Ok(args.wrapping_add( + ok.as_ref() + .map(args_of) + .unwrap_or_default() + .max(err.as_ref().map(args_of).unwrap_or_default()), + )) + } + + Type::Flags(ty) => { + let (bits, args) = deref_arg::(args)?; + lift_flags(val, bits, ty)?; + Ok(args) + } + Type::Own(ty) => { + let (rep, args) = deref_arg::(args)?; + lift_own(store, val, rep, ty)?; + Ok(args) + } + Type::Borrow(ty) => { + let (rep, args) = deref_arg::(args)?; + lift_borrow(store, val, rep, ty)?; + Ok(args) + } + } +} + +#[instrument(level = "trace", skip_all, ret(level = "trace"))] +fn lift_params( + store: &mut Store, + tys: &[Type], + args: *const *mut c_void, +) -> anyhow::Result<(Vec, *const *mut c_void)> { + if tys.is_empty() { + return Ok((vec![], args)); + } + let mut vals = vec![Val::Bool(false); tys.len()]; + let results = zip(&mut vals, tys).enumerate().try_fold( + args, + |args, (i, (val, ty))| -> anyhow::Result<_> { + lift_param(store, ty, val, args) + .with_context(|| format!("failed to lift parameter {i}")) + }, + )?; + Ok((vals, results)) +} + +#[instrument(level = "trace", ret(level = "trace"))] +fn call( + instance_ptr: *mut c_void, + instance: *const c_char, + name: *const c_char, + args: *const *mut c_void, +) -> anyhow::Result<()> { + let mut inst = + NonNull::new(instance_ptr.cast::()).context("`instance_ptr` must not be null")?; + ensure!(!instance.is_null(), "`instance` must not be null"); + ensure!(!name.is_null(), "`name` must not be null"); + let instance = unsafe { CStr::from_ptr(instance) } + .to_str() + .context("`instance` is not valid UTF-8")?; + let name = unsafe { CStr::from_ptr(name) } + .to_str() + .context("`name` is not valid UTF-8")?; + let inst = unsafe { inst.as_mut() }; + let _log = tracing::subscriber::set_default(Arc::clone(&inst.subscriber)); + let _span = trace_span!("call", "instance" = instance, "name" = name).entered(); + if let Some(ty) = name.strip_prefix("[resource-drop]") { + let (rep, _) = deref_arg::(args)?; + let rep = unsafe { rep.read() }; + let store = inst.store(); + let res = WasiView::table(store.data_mut()) + .delete::(Resource::new_own(rep)) + .with_context(|| format!("failed to delete `{ty}` from table"))?; + res.resource_drop(store) + .with_context(|| format!("failed to drop `{ty}`"))?; + } else { + let mut func = inst + .func(instance, name) + .context("failed to lookup function")?; + let tys = func.params(); + let (params, args) = + lift_params(func.store(), &tys, args).context("failed to lift parameters")?; + let results_ty = func.results(); + let mut results = vec![Val::Bool(false); results_ty.len()]; + func.call(¶ms, &mut results)?; + lower_results(func.store(), results, &results_ty, args) + .context("failed to lower results")?; + } + Ok(()) +} diff --git a/crates/sys/west.h b/crates/sys/west.h new file mode 100644 index 0000000..8ed096b --- /dev/null +++ b/crates/sys/west.h @@ -0,0 +1,25 @@ +#include +#include +#include +#include + +typedef struct List_u8 { + const uint8_t *ptr; + uintptr_t len; +} List_u8; + +typedef struct Config { + struct List_u8 wasm; +} Config; + +struct Config default_config(void); + +uintptr_t error_take(char *buf, uintptr_t len); + +uintptr_t error_len(void); + +void *instance_new(struct Config config); + +void instance_free(void *instance); + +bool instance_call(void *instance_ptr, const char *instance, const char *name, void *const *args); diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..0f75221 --- /dev/null +++ b/flake.lock @@ -0,0 +1,603 @@ +{ + "nodes": { + "advisory-db": { + "flake": false, + "locked": { + "lastModified": 1725883717, + "narHash": "sha256-QifFNLfu5bzKPO4iznCj1h+nHhqGZ8NR2Lo7tzh9FRc=", + "owner": "rustsec", + "repo": "advisory-db", + "rev": "7fbf1e630ae52b7b364791a107b5bee5ff929496", + "type": "github" + }, + "original": { + "owner": "rustsec", + "repo": "advisory-db", + "type": "github" + } + }, + "crane": { + "inputs": { + "nixpkgs": "nixpkgs" + }, + "locked": { + "lastModified": 1717383740, + "narHash": "sha256-559HbY4uhNeoYvK3H6AMZAtVfmR3y8plXZ1x6ON/cWU=", + "owner": "ipetkov", + "repo": "crane", + "rev": "b65673fce97d277934488a451724be94cc62499a", + "type": "github" + }, + "original": { + "owner": "ipetkov", + "ref": "v0.17.3", + "repo": "crane", + "type": "github" + } + }, + "crane_2": { + "inputs": { + "flake-compat": "flake-compat", + "flake-utils": [ + "nixify", + "nix-log", + "nixify", + "flake-utils" + ], + "nixpkgs": [ + "nixify", + "nix-log", + "nixify", + "nixpkgs" + ], + "rust-overlay": [ + "nixify", + "nix-log", + "nixify", + "rust-overlay" + ] + }, + "locked": { + "lastModified": 1679255352, + "narHash": "sha256-nkGwGuNkhNrnN33S4HIDV5NzkzMLU5mNStRn9sZwq8c=", + "owner": "rvolosatovs", + "repo": "crane", + "rev": "cec65880599a4ec6426186e24342e663464f5933", + "type": "github" + }, + "original": { + "owner": "rvolosatovs", + "ref": "feat/wit", + "repo": "crane", + "type": "github" + } + }, + "fenix": { + "inputs": { + "nixpkgs": [ + "nixify", + "nixpkgs-nixos" + ], + "rust-analyzer-src": "rust-analyzer-src" + }, + "locked": { + "lastModified": 1724653830, + "narHash": "sha256-88f0KK8h6tGIP4Na5RJDKs0S+7WsGGaCGNkLj/bPV3g=", + "owner": "nix-community", + "repo": "fenix", + "rev": "9ecf5e7d800ace001320da8acadd4a3deb872a83", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "fenix", + "type": "github" + } + }, + "fenix_2": { + "inputs": { + "nixpkgs": [ + "nixify", + "nix-log", + "nixify", + "nixpkgs" + ], + "rust-analyzer-src": "rust-analyzer-src_2" + }, + "locked": { + "lastModified": 1679552560, + "narHash": "sha256-L9Se/F1iLQBZFGrnQJO8c9wE5z0Mf8OiycPGP9Y96hA=", + "owner": "nix-community", + "repo": "fenix", + "rev": "fb49a9f5605ec512da947a21cc7e4551a3950397", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "fenix", + "type": "github" + } + }, + "flake-compat": { + "flake": false, + "locked": { + "lastModified": 1673956053, + "narHash": "sha256-4gtG9iQuiKITOjNQQeQIpoIB6b16fm+504Ch3sNKLd8=", + "owner": "edolstra", + "repo": "flake-compat", + "rev": "35bb57c0c8d8b62bbfd284272c928ceb64ddbde9", + "type": "github" + }, + "original": { + "owner": "edolstra", + "repo": "flake-compat", + "type": "github" + } + }, + "flake-utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1710146030, + "narHash": "sha256-SZ5L6eA7HJ/nmkzGG7/ISclqe6oZdOZTNoesiInkXPQ=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "b1d9ab70662946ef0850d488da1c9019f3a9752a", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "flake-utils_2": { + "locked": { + "lastModified": 1678901627, + "narHash": "sha256-U02riOqrKKzwjsxc/400XnElV+UtPUQWpANPlyazjH0=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "93a2b84fc4b70d9e089d029deacc3583435c2ed6", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "macos-sdk": { + "flake": false, + "locked": { + "lastModified": 1694769349, + "narHash": "sha256-TEvVJy+NMPyzgWSk/6S29ZMQR+ICFxSdS3tw247uhFc=", + "type": "tarball", + "url": "https://github.com/roblabla/MacOSX-SDKs/releases/download/macosx14.0/MacOSX14.0.sdk.tar.xz" + }, + "original": { + "type": "tarball", + "url": "https://github.com/roblabla/MacOSX-SDKs/releases/download/macosx14.0/MacOSX14.0.sdk.tar.xz" + } + }, + "nix-filter": { + "locked": { + "lastModified": 1710156097, + "narHash": "sha256-1Wvk8UP7PXdf8bCCaEoMnOT1qe5/Duqgj+rL8sRQsSM=", + "owner": "numtide", + "repo": "nix-filter", + "rev": "3342559a24e85fc164b295c3444e8a139924675b", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "nix-filter", + "type": "github" + } + }, + "nix-filter_2": { + "locked": { + "lastModified": 1678109515, + "narHash": "sha256-C2X+qC80K2C1TOYZT8nabgo05Dw2HST/pSn6s+n6BO8=", + "owner": "numtide", + "repo": "nix-filter", + "rev": "aa9ff6ce4a7f19af6415fb3721eaa513ea6c763c", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "nix-filter", + "type": "github" + } + }, + "nix-flake-tests": { + "locked": { + "lastModified": 1677844186, + "narHash": "sha256-ErJZ/Gs1rxh561CJeWP5bohA2IcTq1rDneu1WT6CVII=", + "owner": "antifuchs", + "repo": "nix-flake-tests", + "rev": "bbd9216bd0f6495bb961a8eb8392b7ef55c67afb", + "type": "github" + }, + "original": { + "owner": "antifuchs", + "repo": "nix-flake-tests", + "type": "github" + } + }, + "nix-flake-tests_2": { + "locked": { + "lastModified": 1677844186, + "narHash": "sha256-ErJZ/Gs1rxh561CJeWP5bohA2IcTq1rDneu1WT6CVII=", + "owner": "antifuchs", + "repo": "nix-flake-tests", + "rev": "bbd9216bd0f6495bb961a8eb8392b7ef55c67afb", + "type": "github" + }, + "original": { + "owner": "antifuchs", + "repo": "nix-flake-tests", + "type": "github" + } + }, + "nix-log": { + "inputs": { + "nix-flake-tests": "nix-flake-tests", + "nixify": "nixify_2", + "nixlib": "nixlib_2" + }, + "locked": { + "lastModified": 1681933283, + "narHash": "sha256-phDsQdaoUEI4DUTErR6Tz7lS0y3kXvDwwbqtxpzd0eo=", + "owner": "rvolosatovs", + "repo": "nix-log", + "rev": "833d31e3c1a677eac81ba87e777afa5076071d66", + "type": "github" + }, + "original": { + "owner": "rvolosatovs", + "repo": "nix-log", + "type": "github" + } + }, + "nix-log_2": { + "inputs": { + "nix-flake-tests": "nix-flake-tests_2", + "nixify": [ + "wit-deps", + "nixify" + ], + "nixlib": [ + "wit-deps", + "nixlib" + ] + }, + "locked": { + "lastModified": 1681933283, + "narHash": "sha256-phDsQdaoUEI4DUTErR6Tz7lS0y3kXvDwwbqtxpzd0eo=", + "owner": "rvolosatovs", + "repo": "nix-log", + "rev": "833d31e3c1a677eac81ba87e777afa5076071d66", + "type": "github" + }, + "original": { + "owner": "rvolosatovs", + "repo": "nix-log", + "type": "github" + } + }, + "nixify": { + "inputs": { + "advisory-db": "advisory-db", + "crane": "crane", + "fenix": "fenix", + "flake-utils": "flake-utils", + "macos-sdk": "macos-sdk", + "nix-filter": "nix-filter", + "nix-log": "nix-log", + "nixlib": [ + "nixlib" + ], + "nixpkgs-darwin": "nixpkgs-darwin", + "nixpkgs-nixos": "nixpkgs-nixos", + "rust-overlay": "rust-overlay_2" + }, + "locked": { + "lastModified": 1726249589, + "narHash": "sha256-hrKxnBGful/D5uQml/g9inDlZ72FIH+YDAzVg8UadNo=", + "owner": "rvolosatovs", + "repo": "nixify", + "rev": "e003f9a952081763eb1e11797c8babf82a1cb265", + "type": "github" + }, + "original": { + "owner": "rvolosatovs", + "repo": "nixify", + "type": "github" + } + }, + "nixify_2": { + "inputs": { + "crane": "crane_2", + "fenix": "fenix_2", + "flake-utils": "flake-utils_2", + "nix-filter": "nix-filter_2", + "nixlib": "nixlib", + "nixpkgs": "nixpkgs_2", + "rust-overlay": "rust-overlay" + }, + "locked": { + "lastModified": 1679748566, + "narHash": "sha256-yA4yIJjNCOLoUh0py9S3SywwbPnd/6NPYbXad+JeOl0=", + "owner": "rvolosatovs", + "repo": "nixify", + "rev": "80e823959511a42dfec4409fef406a14ae8240f3", + "type": "github" + }, + "original": { + "owner": "rvolosatovs", + "repo": "nixify", + "type": "github" + } + }, + "nixlib": { + "locked": { + "lastModified": 1679187309, + "narHash": "sha256-H8udmkg5wppL11d/05MMzOMryiYvc403axjDNZy1/TQ=", + "owner": "nix-community", + "repo": "nixpkgs.lib", + "rev": "44214417fe4595438b31bdb9469be92536a61455", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "nixpkgs.lib", + "type": "github" + } + }, + "nixlib_2": { + "locked": { + "lastModified": 1679791877, + "narHash": "sha256-tTV1Mf0hPWIMtqyU16Kd2JUBDWvfHlDC9pF57vcbgpQ=", + "owner": "nix-community", + "repo": "nixpkgs.lib", + "rev": "cc060ddbf652a532b54057081d5abd6144d01971", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "nixpkgs.lib", + "type": "github" + } + }, + "nixlib_3": { + "locked": { + "lastModified": 1725757153, + "narHash": "sha256-c1a6iLmCVPFI9EUVMrBN8xdmFxFXEjcVwiTSVmqajOs=", + "owner": "nix-community", + "repo": "nixpkgs.lib", + "rev": "68584f89dd0eb16fea5d80ae127f3f681f6a5df7", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "nixpkgs.lib", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1714656196, + "narHash": "sha256-kjQkA98lMcsom6Gbhw8SYzmwrSo+2nruiTcTZp5jK7o=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "94035b482d181af0a0f8f77823a790b256b7c3cc", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs-darwin": { + "locked": { + "lastModified": 1724615852, + "narHash": "sha256-CB8YqljFSCXwW51LKAZYIQNsKypppHfraotRSYXDU7Q=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "bb8bdb47b718645b2f198a6cf9dff98d967d0fd4", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "nixpkgs-24.05-darwin", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs-nixos": { + "locked": { + "lastModified": 1724316499, + "narHash": "sha256-Qb9MhKBUTCfWg/wqqaxt89Xfi6qTD3XpTzQ9eXi3JmE=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "797f7dc49e0bc7fab4b57c021cdf68f595e47841", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "nixos-24.05", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs-unstable": { + "locked": { + "lastModified": 1726142289, + "narHash": "sha256-Jks8O42La+nm5AMTSq/PvM5O+fUAhIy0Ce1QYqLkyZ4=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "280db3decab4cbeb22a4599bd472229ab74d25e1", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs_2": { + "locked": { + "lastModified": 1679577639, + "narHash": "sha256-7u7bsNP0ApBnLgsHVROQ5ytoMqustmMVMgtaFS/P7EU=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "8f1bcd72727c5d4cd775545595d068be410f2a7e", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "nixpkgs-22.11-darwin", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "nixify": "nixify", + "nixlib": "nixlib_3", + "nixpkgs-unstable": "nixpkgs-unstable", + "wit-deps": "wit-deps" + } + }, + "rust-analyzer-src": { + "flake": false, + "locked": { + "lastModified": 1724586512, + "narHash": "sha256-mrfwk6nO8N2WtCq3sB2zhd2QN1HMKzeSESzOA6lSsQg=", + "owner": "rust-lang", + "repo": "rust-analyzer", + "rev": "7106cd3be50b2a43c1d9f2787bf22d4369c2b25b", + "type": "github" + }, + "original": { + "owner": "rust-lang", + "ref": "nightly", + "repo": "rust-analyzer", + "type": "github" + } + }, + "rust-analyzer-src_2": { + "flake": false, + "locked": { + "lastModified": 1679520343, + "narHash": "sha256-AJGSGWRfoKWD5IVTu1wEsR990wHbX0kIaolPqNMEh0c=", + "owner": "rust-lang", + "repo": "rust-analyzer", + "rev": "eb791f31e688ae00908eb75d4c704ef60c430a92", + "type": "github" + }, + "original": { + "owner": "rust-lang", + "ref": "nightly", + "repo": "rust-analyzer", + "type": "github" + } + }, + "rust-overlay": { + "inputs": { + "flake-utils": [ + "nixify", + "nix-log", + "nixify", + "flake-utils" + ], + "nixpkgs": [ + "nixify", + "nix-log", + "nixify", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1679537973, + "narHash": "sha256-R6borgcKeyMIjjPeeYsfo+mT8UdS+OwwbhhStdCfEjg=", + "owner": "oxalica", + "repo": "rust-overlay", + "rev": "fbc7ae3f14d32e78c0e8d7865f865cc28a46b232", + "type": "github" + }, + "original": { + "owner": "oxalica", + "repo": "rust-overlay", + "type": "github" + } + }, + "rust-overlay_2": { + "inputs": { + "nixpkgs": [ + "nixify", + "nixpkgs-nixos" + ] + }, + "locked": { + "lastModified": 1724638882, + "narHash": "sha256-ap2jIQi/FuUHR6HCht6ASWhoz8EiB99XmI8Esot38VE=", + "owner": "oxalica", + "repo": "rust-overlay", + "rev": "19b70f147b9c67a759e35824b241f1ed92e46694", + "type": "github" + }, + "original": { + "owner": "oxalica", + "repo": "rust-overlay", + "type": "github" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + }, + "wit-deps": { + "inputs": { + "nix-log": "nix-log_2", + "nixify": [ + "nixify" + ], + "nixlib": [ + "nixlib" + ] + }, + "locked": { + "lastModified": 1700564022, + "narHash": "sha256-1vU6go1MLuFIB1up2jn6hlIHSfaRr+7/Yf0Cj4hShAU=", + "owner": "bytecodealliance", + "repo": "wit-deps", + "rev": "5c24e323fc57314f98f69ca5c417f565993a8bb1", + "type": "github" + }, + "original": { + "owner": "bytecodealliance", + "ref": "v0.3.5", + "repo": "wit-deps", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..bc85a9a --- /dev/null +++ b/flake.nix @@ -0,0 +1,175 @@ +{ + nixConfig.extra-substituters = [ + "https://west.cachix.org" + "https://nixify.cachix.org" + "https://crane.cachix.org" + "https://wasmcloud.cachix.org" + "https://bytecodealliance.cachix.org" + "https://nix-community.cachix.org" + "https://cache.garnix.io" + ]; + nixConfig.extra-trusted-public-keys = [ + "west.cachix.org-1:F8ZwKSRWiSCh+rMyZAP7xhgUP6ZW88AGXE7KOR30Fg0=" + "nixify.cachix.org-1:95SiUQuf8Ij0hwDweALJsLtnMyv/otZamWNRp1Q1pXw=" + "crane.cachix.org-1:8Scfpmn9w+hGdXH/Q9tTLiYAE/2dnJYRJP7kl80GuRk=" + "wasmcloud.cachix.org-1:9gRBzsKh+x2HbVVspreFg/6iFRiD4aOcUQfXVDl3hiM=" + "bytecodealliance.cachix.org-1:0SBgh//n2n0heh0sDFhTm+ZKBRy2sInakzFGfzN531Y=" + "nix-community.cachix.org-1:mB9FSh9qf2dCimDSUo8Zy7bkq5CX+/rkCWyvRCYg3Fs=" + "cache.garnix.io:CTFPyKSLcx5RMJKfLo5EEPUObbA78b0YQ2DTCJXqr9g=" + ]; + + inputs.nixify.inputs.nixlib.follows = "nixlib"; + inputs.nixify.url = "github:rvolosatovs/nixify"; + inputs.nixlib.url = "github:nix-community/nixpkgs.lib"; + inputs.nixpkgs-unstable.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; + inputs.wit-deps.inputs.nixify.follows = "nixify"; + inputs.wit-deps.inputs.nixlib.follows = "nixlib"; + inputs.wit-deps.url = "github:bytecodealliance/wit-deps/v0.3.5"; + + outputs = { + nixify, + nixlib, + nixpkgs-unstable, + wit-deps, + ... + }: + with builtins; + with nixlib.lib; + with nixify.lib; + rust.mkFlake { + src = ./.; + name = "west"; + + overlays = [ + wit-deps.overlays.fenix + wit-deps.overlays.default + ( + final: prev: { + pkgsUnstable = import nixpkgs-unstable { + inherit + (final.stdenv.hostPlatform) + system + ; + + inherit + (final) + config + ; + }; + } + ) + ]; + + excludePaths = [ + ".envrc" + ".github" + ".gitignore" + "ADOPTERS.md" + "CODE_OF_CONDUCT.md" + "CONTRIBUTING.md" + "flake.nix" + "LICENSE" + "README.md" + "SECURITY.md" + ]; + + doCheck = false; # testing is performed in checks via `nextest` + + build.packages = [ + "west-sys" + ]; + + targets.arm-unknown-linux-gnueabihf = false; + targets.arm-unknown-linux-musleabihf = false; + targets.armv7-unknown-linux-gnueabihf = false; + targets.armv7-unknown-linux-musleabihf = false; + targets.powerpc64le-unknown-linux-gnu = false; + targets.s390x-unknown-linux-gnu = false; + targets.wasm32-unknown-unknown = false; + targets.wasm32-wasi = false; + + clippy.deny = ["warnings"]; + clippy.workspace = true; + + test.allTargets = true; + test.workspace = true; + + buildOverrides = { + pkgs, + pkgsCross ? pkgs, + ... + }: { + buildInputs ? [], + depsBuildBuild ? [], + nativeBuildInputs ? [], + nativeCheckInputs ? [], + preCheck ? "", + ... + } @ args: + with pkgs.lib; let + darwin2darwin = pkgs.stdenv.hostPlatform.isDarwin && pkgsCross.stdenv.hostPlatform.isDarwin; + + depsBuildBuild' = + depsBuildBuild + ++ optional pkgs.stdenv.hostPlatform.isDarwin pkgs.darwin.apple_sdk.frameworks.SystemConfiguration + ++ optional darwin2darwin pkgs.xcbuild.xcrun; + in + { + buildInputs = + buildInputs + ++ optional pkgs.stdenv.hostPlatform.isDarwin pkgs.libiconv; + + depsBuildBuild = depsBuildBuild'; + } + // optionalAttrs (args ? cargoArtifacts) { + preCheck = + '' + export GOCACHE=$TMPDIR/gocache + export GOMODCACHE=$TMPDIR/gomod + export GOPATH=$TMPDIR/go + export HOME=$TMPDIR/home + '' + + preCheck; + + depsBuildBuild = + depsBuildBuild' + ++ optionals darwin2darwin [ + pkgs.darwin.apple_sdk.frameworks.CoreFoundation + pkgs.darwin.apple_sdk.frameworks.CoreServices + ]; + + nativeCheckInputs = + nativeCheckInputs + ++ [ + pkgs.pkgsUnstable.go + ]; + }; + + withPackages = { + hostRustToolchain, + packages, + ... + }: + packages + // { + rust = hostRustToolchain; + }; + + withDevShells = { + devShells, + pkgs, + ... + }: + extendDerivations { + buildInputs = [ + pkgs.wit-deps + + pkgs.pkgsUnstable.cargo-audit + pkgs.pkgsUnstable.go_1_23 + pkgs.pkgsUnstable.wasm-tools + pkgs.pkgsUnstable.wasmtime + ]; + } + devShells; + }; +} diff --git a/go.work b/go.work new file mode 100644 index 0000000..5fe307d --- /dev/null +++ b/go.work @@ -0,0 +1,5 @@ +go 1.23.0 + +use ./go + +replace github.com/rvolosatovs/west/go v0.0.1 => ./go diff --git a/go.work.sum b/go.work.sum new file mode 100644 index 0000000..0d87c6a --- /dev/null +++ b/go.work.sum @@ -0,0 +1,10 @@ +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/go.mod h1:0kK/RUFHyh+yIKSfWxwheGndfnrvYSmYFVeKCh03ZUc= +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= diff --git a/go/bindings/bindings.go b/go/bindings/bindings.go new file mode 100644 index 0000000..72d3188 --- /dev/null +++ b/go/bindings/bindings.go @@ -0,0 +1,1990 @@ +// Code generated by west-bindgen-go DO NOT EDIT + +package bindings + +import ( + west "github.com/rvolosatovs/west/go" + github_com__rvolosatovs__west__go__bindings__wasi__clocks__monotonic___clock "github.com/rvolosatovs/west/go/bindings/wasi/clocks/monotonic-clock" + github_com__rvolosatovs__west__go__bindings__wasi__http__types "github.com/rvolosatovs/west/go/bindings/wasi/http/types" + github_com__rvolosatovs__west__go__bindings__wasi__io__poll "github.com/rvolosatovs/west/go/bindings/wasi/io/poll" + github_com__rvolosatovs__west__go__bindings__wasi__io__streams "github.com/rvolosatovs/west/go/bindings/wasi/io/streams" + github_com__ydnar__wasm___tools___go__cm "github.com/ydnar/wasm-tools-go/cm" + "runtime" + "unsafe" +) + +const _ string = runtime.Compiler + +var _ unsafe.Pointer + +//go:linkname wasmimport_Now github.com/rvolosatovs/west/go/bindings/wasi/clocks/monotonic-clock.wasmimport_Now +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 { + ptr := unsafe.Pointer(&result0) + __p.Pin(ptr) + return ptr + }()) + }); __err != nil { + west.CurrentErrorHandler()(__err) + } + return +} + +//go:linkname wasmimport_Resolution github.com/rvolosatovs/west/go/bindings/wasi/clocks/monotonic-clock.wasmimport_Resolution +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 { + ptr := unsafe.Pointer(&result0) + __p.Pin(ptr) + return ptr + }()) + }); __err != nil { + west.CurrentErrorHandler()(__err) + } + return +} + +//go:linkname wasmimport_SubscribeDuration github.com/rvolosatovs/west/go/bindings/wasi/clocks/monotonic-clock.wasmimport_SubscribeDuration +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 { + ptr := unsafe.Pointer(&when0) + __p.Pin(ptr) + return ptr + }(), func() unsafe.Pointer { + ptr := unsafe.Pointer(&result0) + __p.Pin(ptr) + return ptr + }()) + }); __err != nil { + west.CurrentErrorHandler()(__err) + } + return +} + +//go:linkname wasmimport_SubscribeInstant github.com/rvolosatovs/west/go/bindings/wasi/clocks/monotonic-clock.wasmimport_SubscribeInstant +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 { + ptr := unsafe.Pointer(&when0) + __p.Pin(ptr) + return ptr + }(), func() unsafe.Pointer { + ptr := unsafe.Pointer(&result0) + __p.Pin(ptr) + return ptr + }()) + }); __err != nil { + west.CurrentErrorHandler()(__err) + } + return +} + +//go:linkname wasmimport_NewFields github.com/rvolosatovs/west/go/bindings/wasi/http/types.wasmimport_NewFields +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 { + ptr := unsafe.Pointer(&result0) + __p.Pin(ptr) + return ptr + }()) + }); __err != nil { + west.CurrentErrorHandler()(__err) + } + return +} + +//go:linkname wasmimport_NewOutgoingRequest github.com/rvolosatovs/west/go/bindings/wasi/http/types.wasmimport_NewOutgoingRequest +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 { + ptr := unsafe.Pointer(&headers0) + __p.Pin(ptr) + return ptr + }(), func() unsafe.Pointer { + ptr := unsafe.Pointer(&result0) + __p.Pin(ptr) + return ptr + }()) + }); __err != nil { + west.CurrentErrorHandler()(__err) + } + return +} + +//go:linkname wasmimport_NewOutgoingResponse github.com/rvolosatovs/west/go/bindings/wasi/http/types.wasmimport_NewOutgoingResponse +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 { + ptr := unsafe.Pointer(&headers0) + __p.Pin(ptr) + return ptr + }(), func() unsafe.Pointer { + ptr := unsafe.Pointer(&result0) + __p.Pin(ptr) + return ptr + }()) + }); __err != nil { + west.CurrentErrorHandler()(__err) + } + return +} + +//go:linkname wasmimport_NewRequestOptions github.com/rvolosatovs/west/go/bindings/wasi/http/types.wasmimport_NewRequestOptions +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 { + ptr := unsafe.Pointer(&result0) + __p.Pin(ptr) + return ptr + }()) + }); __err != nil { + west.CurrentErrorHandler()(__err) + } + return +} + +//go:linkname wasmimport_FieldsAppend github.com/rvolosatovs/west/go/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__go__bindings__wasi__http__types.HeaderError, struct{}, github_com__rvolosatovs__west__go__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 { + ptr := unsafe.Pointer(&self0) + __p.Pin(ptr) + return ptr + }(), func() unsafe.Pointer { + ptr := unsafe.Pointer(name0) + __p.Pin(ptr) + return ptr + }(), func() unsafe.Pointer { + ptr := unsafe.Pointer(&name1) + __p.Pin(ptr) + return ptr + }(), func() unsafe.Pointer { + ptr := unsafe.Pointer(value0) + __p.Pin(ptr) + return ptr + }(), func() unsafe.Pointer { + ptr := unsafe.Pointer(&value1) + __p.Pin(ptr) + return ptr + }(), func() unsafe.Pointer { + ptr := unsafe.Pointer(result) + __p.Pin(ptr) + return ptr + }()) + }); __err != nil { + west.CurrentErrorHandler()(__err) + } + return +} + +//go:linkname wasmimport_FieldsClone github.com/rvolosatovs/west/go/bindings/wasi/http/types.wasmimport_FieldsClone +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 { + ptr := unsafe.Pointer(&self0) + __p.Pin(ptr) + return ptr + }(), func() unsafe.Pointer { + ptr := unsafe.Pointer(&result0) + __p.Pin(ptr) + return ptr + }()) + }); __err != nil { + west.CurrentErrorHandler()(__err) + } + return +} + +//go:linkname wasmimport_FieldsDelete github.com/rvolosatovs/west/go/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__go__bindings__wasi__http__types.HeaderError, struct{}, github_com__rvolosatovs__west__go__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 { + ptr := unsafe.Pointer(&self0) + __p.Pin(ptr) + return ptr + }(), func() unsafe.Pointer { + ptr := unsafe.Pointer(name0) + __p.Pin(ptr) + return ptr + }(), func() unsafe.Pointer { + ptr := unsafe.Pointer(&name1) + __p.Pin(ptr) + return ptr + }(), func() unsafe.Pointer { + ptr := unsafe.Pointer(result) + __p.Pin(ptr) + return ptr + }()) + }); __err != nil { + west.CurrentErrorHandler()(__err) + } + return +} + +//go:linkname wasmimport_FieldsEntries github.com/rvolosatovs/west/go/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__go__bindings__wasi__http__types.FieldKey, github_com__rvolosatovs__west__go__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 { + ptr := unsafe.Pointer(&self0) + __p.Pin(ptr) + return ptr + }(), func() unsafe.Pointer { + ptr := unsafe.Pointer(result) + __p.Pin(ptr) + return ptr + }()) + }); __err != nil { + west.CurrentErrorHandler()(__err) + } + return +} + +//go:linkname wasmimport_FieldsGet github.com/rvolosatovs/west/go/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__go__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 { + ptr := unsafe.Pointer(&self0) + __p.Pin(ptr) + return ptr + }(), func() unsafe.Pointer { + ptr := unsafe.Pointer(name0) + __p.Pin(ptr) + return ptr + }(), func() unsafe.Pointer { + ptr := unsafe.Pointer(&name1) + __p.Pin(ptr) + return ptr + }(), func() unsafe.Pointer { + ptr := unsafe.Pointer(result) + __p.Pin(ptr) + return ptr + }()) + }); __err != nil { + west.CurrentErrorHandler()(__err) + } + return +} + +//go:linkname wasmimport_FieldsHas github.com/rvolosatovs/west/go/bindings/wasi/http/types.wasmimport_FieldsHas +func wasmimport_FieldsHas(self0 uint32, name0 *uint8, name1 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.has", func() unsafe.Pointer { + ptr := unsafe.Pointer(&self0) + __p.Pin(ptr) + return ptr + }(), func() unsafe.Pointer { + ptr := unsafe.Pointer(name0) + __p.Pin(ptr) + return ptr + }(), func() unsafe.Pointer { + ptr := unsafe.Pointer(&name1) + __p.Pin(ptr) + return ptr + }(), func() unsafe.Pointer { + ptr := unsafe.Pointer(&result0) + __p.Pin(ptr) + return ptr + }()) + }); __err != nil { + west.CurrentErrorHandler()(__err) + } + return +} + +//go:linkname wasmimport_FieldsSet github.com/rvolosatovs/west/go/bindings/wasi/http/types.wasmimport_FieldsSet +func wasmimport_FieldsSet(self0 uint32, name0 *uint8, name1 uint32, value0 *github_com__rvolosatovs__west__go__bindings__wasi__http__types.FieldValue, value1 uint32, result *github_com__ydnar__wasm___tools___go__cm.Result[github_com__rvolosatovs__west__go__bindings__wasi__http__types.HeaderError, struct{}, github_com__rvolosatovs__west__go__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 { + ptr := unsafe.Pointer(&self0) + __p.Pin(ptr) + return ptr + }(), func() unsafe.Pointer { + ptr := unsafe.Pointer(name0) + __p.Pin(ptr) + return ptr + }(), func() unsafe.Pointer { + ptr := unsafe.Pointer(&name1) + __p.Pin(ptr) + return ptr + }(), func() unsafe.Pointer { + ptr := unsafe.Pointer(value0) + __p.Pin(ptr) + return ptr + }(), func() unsafe.Pointer { + ptr := unsafe.Pointer(&value1) + __p.Pin(ptr) + return ptr + }(), func() unsafe.Pointer { + ptr := unsafe.Pointer(result) + __p.Pin(ptr) + return ptr + }()) + }); __err != nil { + west.CurrentErrorHandler()(__err) + } + return +} + +//go:linkname wasmimport_FutureIncomingResponseGet github.com/rvolosatovs/west/go/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__go__bindings__wasi__http__types.ErrorCodeShape, github_com__rvolosatovs__west__go__bindings__wasi__http__types.IncomingResponse, github_com__rvolosatovs__west__go__bindings__wasi__http__types.ErrorCode], github_com__ydnar__wasm___tools___go__cm.Result[github_com__rvolosatovs__west__go__bindings__wasi__http__types.ErrorCodeShape, github_com__rvolosatovs__west__go__bindings__wasi__http__types.IncomingResponse, github_com__rvolosatovs__west__go__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 { + ptr := unsafe.Pointer(&self0) + __p.Pin(ptr) + return ptr + }(), func() unsafe.Pointer { + ptr := unsafe.Pointer(result) + __p.Pin(ptr) + return ptr + }()) + }); __err != nil { + west.CurrentErrorHandler()(__err) + } + return +} + +//go:linkname wasmimport_FutureIncomingResponseSubscribe github.com/rvolosatovs/west/go/bindings/wasi/http/types.wasmimport_FutureIncomingResponseSubscribe +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 { + ptr := unsafe.Pointer(&self0) + __p.Pin(ptr) + return ptr + }(), func() unsafe.Pointer { + ptr := unsafe.Pointer(&result0) + __p.Pin(ptr) + return ptr + }()) + }); __err != nil { + west.CurrentErrorHandler()(__err) + } + return +} + +//go:linkname wasmimport_FutureTrailersGet github.com/rvolosatovs/west/go/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__go__bindings__wasi__http__types.ErrorCodeShape, github_com__ydnar__wasm___tools___go__cm.Option[github_com__rvolosatovs__west__go__bindings__wasi__http__types.Fields], github_com__rvolosatovs__west__go__bindings__wasi__http__types.ErrorCode], github_com__ydnar__wasm___tools___go__cm.Result[github_com__rvolosatovs__west__go__bindings__wasi__http__types.ErrorCodeShape, github_com__ydnar__wasm___tools___go__cm.Option[github_com__rvolosatovs__west__go__bindings__wasi__http__types.Fields], github_com__rvolosatovs__west__go__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 { + ptr := unsafe.Pointer(&self0) + __p.Pin(ptr) + return ptr + }(), func() unsafe.Pointer { + ptr := unsafe.Pointer(result) + __p.Pin(ptr) + return ptr + }()) + }); __err != nil { + west.CurrentErrorHandler()(__err) + } + return +} + +//go:linkname wasmimport_FutureTrailersSubscribe github.com/rvolosatovs/west/go/bindings/wasi/http/types.wasmimport_FutureTrailersSubscribe +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 { + ptr := unsafe.Pointer(&self0) + __p.Pin(ptr) + return ptr + }(), func() unsafe.Pointer { + ptr := unsafe.Pointer(&result0) + __p.Pin(ptr) + return ptr + }()) + }); __err != nil { + west.CurrentErrorHandler()(__err) + } + return +} + +//go:linkname wasmimport_IncomingBodyStream github.com/rvolosatovs/west/go/bindings/wasi/http/types.wasmimport_IncomingBodyStream +func wasmimport_IncomingBodyStream(self0 uint32, result *github_com__ydnar__wasm___tools___go__cm.Result[github_com__rvolosatovs__west__go__bindings__wasi__io__streams.InputStream, github_com__rvolosatovs__west__go__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 { + ptr := unsafe.Pointer(&self0) + __p.Pin(ptr) + return ptr + }(), func() unsafe.Pointer { + ptr := unsafe.Pointer(result) + __p.Pin(ptr) + return ptr + }()) + }); __err != nil { + west.CurrentErrorHandler()(__err) + } + return +} + +//go:linkname wasmimport_IncomingRequestAuthority github.com/rvolosatovs/west/go/bindings/wasi/http/types.wasmimport_IncomingRequestAuthority +func wasmimport_IncomingRequestAuthority(self0 uint32, result *github_com__ydnar__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 { + ptr := unsafe.Pointer(&self0) + __p.Pin(ptr) + return ptr + }(), func() unsafe.Pointer { + ptr := unsafe.Pointer(result) + __p.Pin(ptr) + return ptr + }()) + }); __err != nil { + west.CurrentErrorHandler()(__err) + } + return +} + +//go:linkname wasmimport_IncomingRequestConsume github.com/rvolosatovs/west/go/bindings/wasi/http/types.wasmimport_IncomingRequestConsume +func wasmimport_IncomingRequestConsume(self0 uint32, result *github_com__ydnar__wasm___tools___go__cm.Result[github_com__rvolosatovs__west__go__bindings__wasi__http__types.IncomingBody, github_com__rvolosatovs__west__go__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 { + ptr := unsafe.Pointer(&self0) + __p.Pin(ptr) + return ptr + }(), func() unsafe.Pointer { + ptr := unsafe.Pointer(result) + __p.Pin(ptr) + return ptr + }()) + }); __err != nil { + west.CurrentErrorHandler()(__err) + } + return +} + +//go:linkname wasmimport_IncomingRequestHeaders github.com/rvolosatovs/west/go/bindings/wasi/http/types.wasmimport_IncomingRequestHeaders +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 { + ptr := unsafe.Pointer(&self0) + __p.Pin(ptr) + return ptr + }(), func() unsafe.Pointer { + ptr := unsafe.Pointer(&result0) + __p.Pin(ptr) + return ptr + }()) + }); __err != nil { + west.CurrentErrorHandler()(__err) + } + return +} + +//go:linkname wasmimport_IncomingRequestMethod github.com/rvolosatovs/west/go/bindings/wasi/http/types.wasmimport_IncomingRequestMethod +func wasmimport_IncomingRequestMethod(self0 uint32, result *github_com__rvolosatovs__west__go__bindings__wasi__http__types.Method) { + 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 { + ptr := unsafe.Pointer(&self0) + __p.Pin(ptr) + return ptr + }(), func() unsafe.Pointer { + ptr := unsafe.Pointer(result) + __p.Pin(ptr) + return ptr + }()) + }); __err != nil { + west.CurrentErrorHandler()(__err) + } + return +} + +//go:linkname wasmimport_IncomingRequestPathWithQuery github.com/rvolosatovs/west/go/bindings/wasi/http/types.wasmimport_IncomingRequestPathWithQuery +func wasmimport_IncomingRequestPathWithQuery(self0 uint32, result *github_com__ydnar__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 { + ptr := unsafe.Pointer(&self0) + __p.Pin(ptr) + return ptr + }(), func() unsafe.Pointer { + ptr := unsafe.Pointer(result) + __p.Pin(ptr) + return ptr + }()) + }); __err != nil { + west.CurrentErrorHandler()(__err) + } + return +} + +//go:linkname wasmimport_IncomingRequestScheme github.com/rvolosatovs/west/go/bindings/wasi/http/types.wasmimport_IncomingRequestScheme +func wasmimport_IncomingRequestScheme(self0 uint32, result *github_com__ydnar__wasm___tools___go__cm.Option[github_com__rvolosatovs__west__go__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 { + ptr := unsafe.Pointer(&self0) + __p.Pin(ptr) + return ptr + }(), func() unsafe.Pointer { + ptr := unsafe.Pointer(result) + __p.Pin(ptr) + return ptr + }()) + }); __err != nil { + west.CurrentErrorHandler()(__err) + } + return +} + +//go:linkname wasmimport_IncomingResponseConsume github.com/rvolosatovs/west/go/bindings/wasi/http/types.wasmimport_IncomingResponseConsume +func wasmimport_IncomingResponseConsume(self0 uint32, result *github_com__ydnar__wasm___tools___go__cm.Result[github_com__rvolosatovs__west__go__bindings__wasi__http__types.IncomingBody, github_com__rvolosatovs__west__go__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 { + ptr := unsafe.Pointer(&self0) + __p.Pin(ptr) + return ptr + }(), func() unsafe.Pointer { + ptr := unsafe.Pointer(result) + __p.Pin(ptr) + return ptr + }()) + }); __err != nil { + west.CurrentErrorHandler()(__err) + } + return +} + +//go:linkname wasmimport_IncomingResponseHeaders github.com/rvolosatovs/west/go/bindings/wasi/http/types.wasmimport_IncomingResponseHeaders +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 { + ptr := unsafe.Pointer(&self0) + __p.Pin(ptr) + return ptr + }(), func() unsafe.Pointer { + ptr := unsafe.Pointer(&result0) + __p.Pin(ptr) + return ptr + }()) + }); __err != nil { + west.CurrentErrorHandler()(__err) + } + return +} + +//go:linkname wasmimport_IncomingResponseStatus github.com/rvolosatovs/west/go/bindings/wasi/http/types.wasmimport_IncomingResponseStatus +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 { + ptr := unsafe.Pointer(&self0) + __p.Pin(ptr) + return ptr + }(), func() unsafe.Pointer { + ptr := unsafe.Pointer(&result0) + __p.Pin(ptr) + return ptr + }()) + }); __err != nil { + west.CurrentErrorHandler()(__err) + } + return +} + +//go:linkname wasmimport_OutgoingBodyWrite github.com/rvolosatovs/west/go/bindings/wasi/http/types.wasmimport_OutgoingBodyWrite +func wasmimport_OutgoingBodyWrite(self0 uint32, result *github_com__ydnar__wasm___tools___go__cm.Result[github_com__rvolosatovs__west__go__bindings__wasi__io__streams.OutputStream, github_com__rvolosatovs__west__go__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 { + ptr := unsafe.Pointer(&self0) + __p.Pin(ptr) + return ptr + }(), func() unsafe.Pointer { + ptr := unsafe.Pointer(result) + __p.Pin(ptr) + return ptr + }()) + }); __err != nil { + west.CurrentErrorHandler()(__err) + } + return +} + +//go:linkname wasmimport_OutgoingRequestAuthority github.com/rvolosatovs/west/go/bindings/wasi/http/types.wasmimport_OutgoingRequestAuthority +func wasmimport_OutgoingRequestAuthority(self0 uint32, result *github_com__ydnar__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 { + ptr := unsafe.Pointer(&self0) + __p.Pin(ptr) + return ptr + }(), func() unsafe.Pointer { + ptr := unsafe.Pointer(result) + __p.Pin(ptr) + return ptr + }()) + }); __err != nil { + west.CurrentErrorHandler()(__err) + } + return +} + +//go:linkname wasmimport_OutgoingRequestBody github.com/rvolosatovs/west/go/bindings/wasi/http/types.wasmimport_OutgoingRequestBody +func wasmimport_OutgoingRequestBody(self0 uint32, result *github_com__ydnar__wasm___tools___go__cm.Result[github_com__rvolosatovs__west__go__bindings__wasi__http__types.OutgoingBody, github_com__rvolosatovs__west__go__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 { + ptr := unsafe.Pointer(&self0) + __p.Pin(ptr) + return ptr + }(), func() unsafe.Pointer { + ptr := unsafe.Pointer(result) + __p.Pin(ptr) + return ptr + }()) + }); __err != nil { + west.CurrentErrorHandler()(__err) + } + return +} + +//go:linkname wasmimport_OutgoingRequestHeaders github.com/rvolosatovs/west/go/bindings/wasi/http/types.wasmimport_OutgoingRequestHeaders +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 { + ptr := unsafe.Pointer(&self0) + __p.Pin(ptr) + return ptr + }(), func() unsafe.Pointer { + ptr := unsafe.Pointer(&result0) + __p.Pin(ptr) + return ptr + }()) + }); __err != nil { + west.CurrentErrorHandler()(__err) + } + return +} + +//go:linkname wasmimport_OutgoingRequestMethod github.com/rvolosatovs/west/go/bindings/wasi/http/types.wasmimport_OutgoingRequestMethod +func wasmimport_OutgoingRequestMethod(self0 uint32, result *github_com__rvolosatovs__west__go__bindings__wasi__http__types.Method) { + 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 { + ptr := unsafe.Pointer(&self0) + __p.Pin(ptr) + return ptr + }(), func() unsafe.Pointer { + ptr := unsafe.Pointer(result) + __p.Pin(ptr) + return ptr + }()) + }); __err != nil { + west.CurrentErrorHandler()(__err) + } + return +} + +//go:linkname wasmimport_OutgoingRequestPathWithQuery github.com/rvolosatovs/west/go/bindings/wasi/http/types.wasmimport_OutgoingRequestPathWithQuery +func wasmimport_OutgoingRequestPathWithQuery(self0 uint32, result *github_com__ydnar__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 { + ptr := unsafe.Pointer(&self0) + __p.Pin(ptr) + return ptr + }(), func() unsafe.Pointer { + ptr := unsafe.Pointer(result) + __p.Pin(ptr) + return ptr + }()) + }); __err != nil { + west.CurrentErrorHandler()(__err) + } + return +} + +//go:linkname wasmimport_OutgoingRequestScheme github.com/rvolosatovs/west/go/bindings/wasi/http/types.wasmimport_OutgoingRequestScheme +func wasmimport_OutgoingRequestScheme(self0 uint32, result *github_com__ydnar__wasm___tools___go__cm.Option[github_com__rvolosatovs__west__go__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 { + ptr := unsafe.Pointer(&self0) + __p.Pin(ptr) + return ptr + }(), func() unsafe.Pointer { + ptr := unsafe.Pointer(result) + __p.Pin(ptr) + return ptr + }()) + }); __err != nil { + west.CurrentErrorHandler()(__err) + } + return +} + +//go:linkname wasmimport_OutgoingRequestSetAuthority github.com/rvolosatovs/west/go/bindings/wasi/http/types.wasmimport_OutgoingRequestSetAuthority +func wasmimport_OutgoingRequestSetAuthority(self0 uint32, authority0 uint32, authority1 *uint8, authority2 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.set-authority", func() unsafe.Pointer { + ptr := unsafe.Pointer(&self0) + __p.Pin(ptr) + return ptr + }(), func() unsafe.Pointer { + ptr := unsafe.Pointer(&authority0) + __p.Pin(ptr) + return ptr + }(), func() unsafe.Pointer { + ptr := unsafe.Pointer(authority1) + __p.Pin(ptr) + return ptr + }(), func() unsafe.Pointer { + ptr := unsafe.Pointer(&authority2) + __p.Pin(ptr) + return ptr + }(), func() unsafe.Pointer { + ptr := unsafe.Pointer(&result0) + __p.Pin(ptr) + return ptr + }()) + }); __err != nil { + west.CurrentErrorHandler()(__err) + } + return +} + +//go:linkname wasmimport_OutgoingRequestSetMethod github.com/rvolosatovs/west/go/bindings/wasi/http/types.wasmimport_OutgoingRequestSetMethod +func wasmimport_OutgoingRequestSetMethod(self0 uint32, method0 uint32, method1 *uint8, method2 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.set-method", func() unsafe.Pointer { + ptr := unsafe.Pointer(&self0) + __p.Pin(ptr) + return ptr + }(), func() unsafe.Pointer { + ptr := unsafe.Pointer(&method0) + __p.Pin(ptr) + return ptr + }(), func() unsafe.Pointer { + ptr := unsafe.Pointer(method1) + __p.Pin(ptr) + return ptr + }(), func() unsafe.Pointer { + ptr := unsafe.Pointer(&method2) + __p.Pin(ptr) + return ptr + }(), func() unsafe.Pointer { + ptr := unsafe.Pointer(&result0) + __p.Pin(ptr) + return ptr + }()) + }); __err != nil { + west.CurrentErrorHandler()(__err) + } + return +} + +//go:linkname wasmimport_OutgoingRequestSetPathWithQuery github.com/rvolosatovs/west/go/bindings/wasi/http/types.wasmimport_OutgoingRequestSetPathWithQuery +func wasmimport_OutgoingRequestSetPathWithQuery(self0 uint32, pathWithQuery0 uint32, pathWithQuery1 *uint8, pathWithQuery2 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.set-path-with-query", func() unsafe.Pointer { + ptr := unsafe.Pointer(&self0) + __p.Pin(ptr) + return ptr + }(), func() unsafe.Pointer { + ptr := unsafe.Pointer(&pathWithQuery0) + __p.Pin(ptr) + return ptr + }(), func() unsafe.Pointer { + ptr := unsafe.Pointer(pathWithQuery1) + __p.Pin(ptr) + return ptr + }(), func() unsafe.Pointer { + ptr := unsafe.Pointer(&pathWithQuery2) + __p.Pin(ptr) + return ptr + }(), func() unsafe.Pointer { + ptr := unsafe.Pointer(&result0) + __p.Pin(ptr) + return ptr + }()) + }); __err != nil { + west.CurrentErrorHandler()(__err) + } + return +} + +//go:linkname wasmimport_OutgoingRequestSetScheme github.com/rvolosatovs/west/go/bindings/wasi/http/types.wasmimport_OutgoingRequestSetScheme +func wasmimport_OutgoingRequestSetScheme(self0 uint32, scheme0 uint32, scheme1 uint32, scheme2 *uint8, scheme3 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.set-scheme", func() unsafe.Pointer { + ptr := unsafe.Pointer(&self0) + __p.Pin(ptr) + return ptr + }(), func() unsafe.Pointer { + ptr := unsafe.Pointer(&scheme0) + __p.Pin(ptr) + return ptr + }(), func() unsafe.Pointer { + ptr := unsafe.Pointer(&scheme1) + __p.Pin(ptr) + return ptr + }(), func() unsafe.Pointer { + ptr := unsafe.Pointer(scheme2) + __p.Pin(ptr) + return ptr + }(), func() unsafe.Pointer { + ptr := unsafe.Pointer(&scheme3) + __p.Pin(ptr) + return ptr + }(), func() unsafe.Pointer { + ptr := unsafe.Pointer(&result0) + __p.Pin(ptr) + return ptr + }()) + }); __err != nil { + west.CurrentErrorHandler()(__err) + } + return +} + +//go:linkname wasmimport_OutgoingResponseBody github.com/rvolosatovs/west/go/bindings/wasi/http/types.wasmimport_OutgoingResponseBody +func wasmimport_OutgoingResponseBody(self0 uint32, result *github_com__ydnar__wasm___tools___go__cm.Result[github_com__rvolosatovs__west__go__bindings__wasi__http__types.OutgoingBody, github_com__rvolosatovs__west__go__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 { + ptr := unsafe.Pointer(&self0) + __p.Pin(ptr) + return ptr + }(), func() unsafe.Pointer { + ptr := unsafe.Pointer(result) + __p.Pin(ptr) + return ptr + }()) + }); __err != nil { + west.CurrentErrorHandler()(__err) + } + return +} + +//go:linkname wasmimport_OutgoingResponseHeaders github.com/rvolosatovs/west/go/bindings/wasi/http/types.wasmimport_OutgoingResponseHeaders +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 { + ptr := unsafe.Pointer(&self0) + __p.Pin(ptr) + return ptr + }(), func() unsafe.Pointer { + ptr := unsafe.Pointer(&result0) + __p.Pin(ptr) + return ptr + }()) + }); __err != nil { + west.CurrentErrorHandler()(__err) + } + return +} + +//go:linkname wasmimport_OutgoingResponseSetStatusCode github.com/rvolosatovs/west/go/bindings/wasi/http/types.wasmimport_OutgoingResponseSetStatusCode +func wasmimport_OutgoingResponseSetStatusCode(self0 uint32, statusCode0 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.set-status-code", func() unsafe.Pointer { + ptr := unsafe.Pointer(&self0) + __p.Pin(ptr) + return ptr + }(), func() unsafe.Pointer { + ptr := unsafe.Pointer(&statusCode0) + __p.Pin(ptr) + return ptr + }(), func() unsafe.Pointer { + ptr := unsafe.Pointer(&result0) + __p.Pin(ptr) + return ptr + }()) + }); __err != nil { + west.CurrentErrorHandler()(__err) + } + return +} + +//go:linkname wasmimport_OutgoingResponseStatusCode github.com/rvolosatovs/west/go/bindings/wasi/http/types.wasmimport_OutgoingResponseStatusCode +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 { + ptr := unsafe.Pointer(&self0) + __p.Pin(ptr) + return ptr + }(), func() unsafe.Pointer { + ptr := unsafe.Pointer(&result0) + __p.Pin(ptr) + return ptr + }()) + }); __err != nil { + west.CurrentErrorHandler()(__err) + } + return +} + +//go:linkname wasmimport_RequestOptionsBetweenBytesTimeout github.com/rvolosatovs/west/go/bindings/wasi/http/types.wasmimport_RequestOptionsBetweenBytesTimeout +func wasmimport_RequestOptionsBetweenBytesTimeout(self0 uint32, result *github_com__ydnar__wasm___tools___go__cm.Option[github_com__rvolosatovs__west__go__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 { + ptr := unsafe.Pointer(&self0) + __p.Pin(ptr) + return ptr + }(), func() unsafe.Pointer { + ptr := unsafe.Pointer(result) + __p.Pin(ptr) + return ptr + }()) + }); __err != nil { + west.CurrentErrorHandler()(__err) + } + return +} + +//go:linkname wasmimport_RequestOptionsConnectTimeout github.com/rvolosatovs/west/go/bindings/wasi/http/types.wasmimport_RequestOptionsConnectTimeout +func wasmimport_RequestOptionsConnectTimeout(self0 uint32, result *github_com__ydnar__wasm___tools___go__cm.Option[github_com__rvolosatovs__west__go__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 { + ptr := unsafe.Pointer(&self0) + __p.Pin(ptr) + return ptr + }(), func() unsafe.Pointer { + ptr := unsafe.Pointer(result) + __p.Pin(ptr) + return ptr + }()) + }); __err != nil { + west.CurrentErrorHandler()(__err) + } + return +} + +//go:linkname wasmimport_RequestOptionsFirstByteTimeout github.com/rvolosatovs/west/go/bindings/wasi/http/types.wasmimport_RequestOptionsFirstByteTimeout +func wasmimport_RequestOptionsFirstByteTimeout(self0 uint32, result *github_com__ydnar__wasm___tools___go__cm.Option[github_com__rvolosatovs__west__go__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 { + ptr := unsafe.Pointer(&self0) + __p.Pin(ptr) + return ptr + }(), func() unsafe.Pointer { + ptr := unsafe.Pointer(result) + __p.Pin(ptr) + return ptr + }()) + }); __err != nil { + west.CurrentErrorHandler()(__err) + } + return +} + +//go:linkname wasmimport_RequestOptionsSetBetweenBytesTimeout github.com/rvolosatovs/west/go/bindings/wasi/http/types.wasmimport_RequestOptionsSetBetweenBytesTimeout +func wasmimport_RequestOptionsSetBetweenBytesTimeout(self0 uint32, duration0 uint32, duration1 uint64) (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]request-options.set-between-bytes-timeout", func() unsafe.Pointer { + ptr := unsafe.Pointer(&self0) + __p.Pin(ptr) + return ptr + }(), func() unsafe.Pointer { + ptr := unsafe.Pointer(&duration0) + __p.Pin(ptr) + return ptr + }(), func() unsafe.Pointer { + ptr := unsafe.Pointer(&duration1) + __p.Pin(ptr) + return ptr + }(), func() unsafe.Pointer { + ptr := unsafe.Pointer(&result0) + __p.Pin(ptr) + return ptr + }()) + }); __err != nil { + west.CurrentErrorHandler()(__err) + } + return +} + +//go:linkname wasmimport_RequestOptionsSetConnectTimeout github.com/rvolosatovs/west/go/bindings/wasi/http/types.wasmimport_RequestOptionsSetConnectTimeout +func wasmimport_RequestOptionsSetConnectTimeout(self0 uint32, duration0 uint32, duration1 uint64) (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]request-options.set-connect-timeout", func() unsafe.Pointer { + ptr := unsafe.Pointer(&self0) + __p.Pin(ptr) + return ptr + }(), func() unsafe.Pointer { + ptr := unsafe.Pointer(&duration0) + __p.Pin(ptr) + return ptr + }(), func() unsafe.Pointer { + ptr := unsafe.Pointer(&duration1) + __p.Pin(ptr) + return ptr + }(), func() unsafe.Pointer { + ptr := unsafe.Pointer(&result0) + __p.Pin(ptr) + return ptr + }()) + }); __err != nil { + west.CurrentErrorHandler()(__err) + } + return +} + +//go:linkname wasmimport_RequestOptionsSetFirstByteTimeout github.com/rvolosatovs/west/go/bindings/wasi/http/types.wasmimport_RequestOptionsSetFirstByteTimeout +func wasmimport_RequestOptionsSetFirstByteTimeout(self0 uint32, duration0 uint32, duration1 uint64) (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]request-options.set-first-byte-timeout", func() unsafe.Pointer { + ptr := unsafe.Pointer(&self0) + __p.Pin(ptr) + return ptr + }(), func() unsafe.Pointer { + ptr := unsafe.Pointer(&duration0) + __p.Pin(ptr) + return ptr + }(), func() unsafe.Pointer { + ptr := unsafe.Pointer(&duration1) + __p.Pin(ptr) + return ptr + }(), func() unsafe.Pointer { + ptr := unsafe.Pointer(&result0) + __p.Pin(ptr) + return ptr + }()) + }); __err != nil { + west.CurrentErrorHandler()(__err) + } + return +} + +//go:linkname wasmimport_FieldsResourceDrop github.com/rvolosatovs/west/go/bindings/wasi/http/types.wasmimport_FieldsResourceDrop +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 { + ptr := unsafe.Pointer(&self0) + __p.Pin(ptr) + return ptr + }()) + }); __err != nil { + west.CurrentErrorHandler()(__err) + } + return +} + +//go:linkname wasmimport_FutureIncomingResponseResourceDrop github.com/rvolosatovs/west/go/bindings/wasi/http/types.wasmimport_FutureIncomingResponseResourceDrop +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 { + ptr := unsafe.Pointer(&self0) + __p.Pin(ptr) + return ptr + }()) + }); __err != nil { + west.CurrentErrorHandler()(__err) + } + return +} + +//go:linkname wasmimport_FutureTrailersResourceDrop github.com/rvolosatovs/west/go/bindings/wasi/http/types.wasmimport_FutureTrailersResourceDrop +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 { + ptr := unsafe.Pointer(&self0) + __p.Pin(ptr) + return ptr + }()) + }); __err != nil { + west.CurrentErrorHandler()(__err) + } + return +} + +//go:linkname wasmimport_IncomingBodyResourceDrop github.com/rvolosatovs/west/go/bindings/wasi/http/types.wasmimport_IncomingBodyResourceDrop +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 { + ptr := unsafe.Pointer(&self0) + __p.Pin(ptr) + return ptr + }()) + }); __err != nil { + west.CurrentErrorHandler()(__err) + } + return +} + +//go:linkname wasmimport_IncomingRequestResourceDrop github.com/rvolosatovs/west/go/bindings/wasi/http/types.wasmimport_IncomingRequestResourceDrop +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 { + ptr := unsafe.Pointer(&self0) + __p.Pin(ptr) + return ptr + }()) + }); __err != nil { + west.CurrentErrorHandler()(__err) + } + return +} + +//go:linkname wasmimport_IncomingResponseResourceDrop github.com/rvolosatovs/west/go/bindings/wasi/http/types.wasmimport_IncomingResponseResourceDrop +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 { + ptr := unsafe.Pointer(&self0) + __p.Pin(ptr) + return ptr + }()) + }); __err != nil { + west.CurrentErrorHandler()(__err) + } + return +} + +//go:linkname wasmimport_OutgoingBodyResourceDrop github.com/rvolosatovs/west/go/bindings/wasi/http/types.wasmimport_OutgoingBodyResourceDrop +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 { + ptr := unsafe.Pointer(&self0) + __p.Pin(ptr) + return ptr + }()) + }); __err != nil { + west.CurrentErrorHandler()(__err) + } + return +} + +//go:linkname wasmimport_OutgoingRequestResourceDrop github.com/rvolosatovs/west/go/bindings/wasi/http/types.wasmimport_OutgoingRequestResourceDrop +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 { + ptr := unsafe.Pointer(&self0) + __p.Pin(ptr) + return ptr + }()) + }); __err != nil { + west.CurrentErrorHandler()(__err) + } + return +} + +//go:linkname wasmimport_OutgoingResponseResourceDrop github.com/rvolosatovs/west/go/bindings/wasi/http/types.wasmimport_OutgoingResponseResourceDrop +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 { + ptr := unsafe.Pointer(&self0) + __p.Pin(ptr) + return ptr + }()) + }); __err != nil { + west.CurrentErrorHandler()(__err) + } + return +} + +//go:linkname wasmimport_RequestOptionsResourceDrop github.com/rvolosatovs/west/go/bindings/wasi/http/types.wasmimport_RequestOptionsResourceDrop +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 { + ptr := unsafe.Pointer(&self0) + __p.Pin(ptr) + return ptr + }()) + }); __err != nil { + west.CurrentErrorHandler()(__err) + } + return +} + +//go:linkname wasmimport_ResponseOutparamResourceDrop github.com/rvolosatovs/west/go/bindings/wasi/http/types.wasmimport_ResponseOutparamResourceDrop +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 { + ptr := unsafe.Pointer(&self0) + __p.Pin(ptr) + return ptr + }()) + }); __err != nil { + west.CurrentErrorHandler()(__err) + } + return +} + +//go:linkname wasmimport_FieldsFromList github.com/rvolosatovs/west/go/bindings/wasi/http/types.wasmimport_FieldsFromList +func wasmimport_FieldsFromList(entries0 *github_com__ydnar__wasm___tools___go__cm.Tuple[github_com__rvolosatovs__west__go__bindings__wasi__http__types.FieldKey, github_com__rvolosatovs__west__go__bindings__wasi__http__types.FieldValue], entries1 uint32, result *github_com__ydnar__wasm___tools___go__cm.Result[github_com__rvolosatovs__west__go__bindings__wasi__http__types.Fields, github_com__rvolosatovs__west__go__bindings__wasi__http__types.Fields, github_com__rvolosatovs__west__go__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 { + ptr := unsafe.Pointer(entries0) + __p.Pin(ptr) + return ptr + }(), func() unsafe.Pointer { + ptr := unsafe.Pointer(&entries1) + __p.Pin(ptr) + return ptr + }(), func() unsafe.Pointer { + ptr := unsafe.Pointer(result) + __p.Pin(ptr) + return ptr + }()) + }); __err != nil { + west.CurrentErrorHandler()(__err) + } + return +} + +//go:linkname wasmimport_IncomingBodyFinish github.com/rvolosatovs/west/go/bindings/wasi/http/types.wasmimport_IncomingBodyFinish +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 { + ptr := unsafe.Pointer(&this0) + __p.Pin(ptr) + return ptr + }(), func() unsafe.Pointer { + ptr := unsafe.Pointer(&result0) + __p.Pin(ptr) + return ptr + }()) + }); __err != nil { + west.CurrentErrorHandler()(__err) + } + return +} + +//go:linkname wasmimport_OutgoingBodyFinish github.com/rvolosatovs/west/go/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__go__bindings__wasi__http__types.ErrorCode, struct{}, github_com__rvolosatovs__west__go__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 { + ptr := unsafe.Pointer(&this0) + __p.Pin(ptr) + return ptr + }(), func() unsafe.Pointer { + ptr := unsafe.Pointer(&trailers0) + __p.Pin(ptr) + return ptr + }(), func() unsafe.Pointer { + ptr := unsafe.Pointer(&trailers1) + __p.Pin(ptr) + return ptr + }(), func() unsafe.Pointer { + ptr := unsafe.Pointer(result) + __p.Pin(ptr) + return ptr + }()) + }); __err != nil { + west.CurrentErrorHandler()(__err) + } + return +} + +//go:linkname wasmimport_ResponseOutparamSet github.com/rvolosatovs/west/go/bindings/wasi/http/types.wasmimport_ResponseOutparamSet +func wasmimport_ResponseOutparamSet(param0 uint32, response0 uint32, response1 uint32, response2 uint32, response3 uint64, response4 uint32, response5 uint32, response6 uint32, response7 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]response-outparam.set", func() unsafe.Pointer { + ptr := unsafe.Pointer(¶m0) + __p.Pin(ptr) + return ptr + }(), func() unsafe.Pointer { + ptr := unsafe.Pointer(&response0) + __p.Pin(ptr) + return ptr + }(), func() unsafe.Pointer { + ptr := unsafe.Pointer(&response1) + __p.Pin(ptr) + return ptr + }(), func() unsafe.Pointer { + ptr := unsafe.Pointer(&response2) + __p.Pin(ptr) + return ptr + }(), func() unsafe.Pointer { + ptr := unsafe.Pointer(&response3) + __p.Pin(ptr) + return ptr + }(), func() unsafe.Pointer { + ptr := unsafe.Pointer(&response4) + __p.Pin(ptr) + return ptr + }(), func() unsafe.Pointer { + ptr := unsafe.Pointer(&response5) + __p.Pin(ptr) + return ptr + }(), func() unsafe.Pointer { + ptr := unsafe.Pointer(&response6) + __p.Pin(ptr) + return ptr + }(), func() unsafe.Pointer { + ptr := unsafe.Pointer(&response7) + __p.Pin(ptr) + return ptr + }()) + }); __err != nil { + west.CurrentErrorHandler()(__err) + } + return +} + +//go:linkname wasmimport_HTTPErrorCode github.com/rvolosatovs/west/go/bindings/wasi/http/types.wasmimport_HTTPErrorCode +func wasmimport_HTTPErrorCode(err0 uint32, result *github_com__ydnar__wasm___tools___go__cm.Option[github_com__rvolosatovs__west__go__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 { + ptr := unsafe.Pointer(&err0) + __p.Pin(ptr) + return ptr + }(), func() unsafe.Pointer { + ptr := unsafe.Pointer(result) + __p.Pin(ptr) + return ptr + }()) + }); __err != nil { + west.CurrentErrorHandler()(__err) + } + return +} + +//go:linkname wasmimport_ErrorToDebugString github.com/rvolosatovs/west/go/bindings/wasi/io/error.wasmimport_ErrorToDebugString +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 { + ptr := unsafe.Pointer(&self0) + __p.Pin(ptr) + return ptr + }(), func() unsafe.Pointer { + ptr := unsafe.Pointer(result) + __p.Pin(ptr) + return ptr + }()) + }); __err != nil { + west.CurrentErrorHandler()(__err) + } + return +} + +//go:linkname wasmimport_ErrorResourceDrop github.com/rvolosatovs/west/go/bindings/wasi/io/error.wasmimport_ErrorResourceDrop +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 { + ptr := unsafe.Pointer(&self0) + __p.Pin(ptr) + return ptr + }()) + }); __err != nil { + west.CurrentErrorHandler()(__err) + } + return +} + +//go:linkname wasmimport_PollableBlock github.com/rvolosatovs/west/go/bindings/wasi/io/poll.wasmimport_PollableBlock +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 { + ptr := unsafe.Pointer(&self0) + __p.Pin(ptr) + return ptr + }()) + }); __err != nil { + west.CurrentErrorHandler()(__err) + } + return +} + +//go:linkname wasmimport_PollableReady github.com/rvolosatovs/west/go/bindings/wasi/io/poll.wasmimport_PollableReady +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 { + ptr := unsafe.Pointer(&self0) + __p.Pin(ptr) + return ptr + }(), func() unsafe.Pointer { + ptr := unsafe.Pointer(&result0) + __p.Pin(ptr) + return ptr + }()) + }); __err != nil { + west.CurrentErrorHandler()(__err) + } + return +} + +//go:linkname wasmimport_PollableResourceDrop github.com/rvolosatovs/west/go/bindings/wasi/io/poll.wasmimport_PollableResourceDrop +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 { + ptr := unsafe.Pointer(&self0) + __p.Pin(ptr) + return ptr + }()) + }); __err != nil { + west.CurrentErrorHandler()(__err) + } + return +} + +//go:linkname wasmimport_Poll github.com/rvolosatovs/west/go/bindings/wasi/io/poll.wasmimport_Poll +func wasmimport_Poll(in0 *github_com__rvolosatovs__west__go__bindings__wasi__io__poll.Pollable, in1 uint32, result *github_com__ydnar__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 { + ptr := unsafe.Pointer(in0) + __p.Pin(ptr) + return ptr + }(), func() unsafe.Pointer { + ptr := unsafe.Pointer(&in1) + __p.Pin(ptr) + return ptr + }(), func() unsafe.Pointer { + ptr := unsafe.Pointer(result) + __p.Pin(ptr) + return ptr + }()) + }); __err != nil { + west.CurrentErrorHandler()(__err) + } + return +} + +//go:linkname wasmimport_InputStreamBlockingRead github.com/rvolosatovs/west/go/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__go__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 { + ptr := unsafe.Pointer(&self0) + __p.Pin(ptr) + return ptr + }(), func() unsafe.Pointer { + ptr := unsafe.Pointer(&len0) + __p.Pin(ptr) + return ptr + }(), func() unsafe.Pointer { + ptr := unsafe.Pointer(result) + __p.Pin(ptr) + return ptr + }()) + }); __err != nil { + west.CurrentErrorHandler()(__err) + } + return +} + +//go:linkname wasmimport_InputStreamBlockingSkip github.com/rvolosatovs/west/go/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__go__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 { + ptr := unsafe.Pointer(&self0) + __p.Pin(ptr) + return ptr + }(), func() unsafe.Pointer { + ptr := unsafe.Pointer(&len0) + __p.Pin(ptr) + return ptr + }(), func() unsafe.Pointer { + ptr := unsafe.Pointer(result) + __p.Pin(ptr) + return ptr + }()) + }); __err != nil { + west.CurrentErrorHandler()(__err) + } + return +} + +//go:linkname wasmimport_InputStreamRead github.com/rvolosatovs/west/go/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__go__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 { + ptr := unsafe.Pointer(&self0) + __p.Pin(ptr) + return ptr + }(), func() unsafe.Pointer { + ptr := unsafe.Pointer(&len0) + __p.Pin(ptr) + return ptr + }(), func() unsafe.Pointer { + ptr := unsafe.Pointer(result) + __p.Pin(ptr) + return ptr + }()) + }); __err != nil { + west.CurrentErrorHandler()(__err) + } + return +} + +//go:linkname wasmimport_InputStreamSkip github.com/rvolosatovs/west/go/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__go__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 { + ptr := unsafe.Pointer(&self0) + __p.Pin(ptr) + return ptr + }(), func() unsafe.Pointer { + ptr := unsafe.Pointer(&len0) + __p.Pin(ptr) + return ptr + }(), func() unsafe.Pointer { + ptr := unsafe.Pointer(result) + __p.Pin(ptr) + return ptr + }()) + }); __err != nil { + west.CurrentErrorHandler()(__err) + } + return +} + +//go:linkname wasmimport_InputStreamSubscribe github.com/rvolosatovs/west/go/bindings/wasi/io/streams.wasmimport_InputStreamSubscribe +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 { + ptr := unsafe.Pointer(&self0) + __p.Pin(ptr) + return ptr + }(), func() unsafe.Pointer { + ptr := unsafe.Pointer(&result0) + __p.Pin(ptr) + return ptr + }()) + }); __err != nil { + west.CurrentErrorHandler()(__err) + } + return +} + +//go:linkname wasmimport_OutputStreamBlockingFlush github.com/rvolosatovs/west/go/bindings/wasi/io/streams.wasmimport_OutputStreamBlockingFlush +func wasmimport_OutputStreamBlockingFlush(self0 uint32, result *github_com__ydnar__wasm___tools___go__cm.Result[github_com__rvolosatovs__west__go__bindings__wasi__io__streams.StreamError, struct{}, github_com__rvolosatovs__west__go__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 { + ptr := unsafe.Pointer(&self0) + __p.Pin(ptr) + return ptr + }(), func() unsafe.Pointer { + ptr := unsafe.Pointer(result) + __p.Pin(ptr) + return ptr + }()) + }); __err != nil { + west.CurrentErrorHandler()(__err) + } + return +} + +//go:linkname wasmimport_OutputStreamBlockingSplice github.com/rvolosatovs/west/go/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__go__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 { + ptr := unsafe.Pointer(&self0) + __p.Pin(ptr) + return ptr + }(), func() unsafe.Pointer { + ptr := unsafe.Pointer(&src0) + __p.Pin(ptr) + return ptr + }(), func() unsafe.Pointer { + ptr := unsafe.Pointer(&len0) + __p.Pin(ptr) + return ptr + }(), func() unsafe.Pointer { + ptr := unsafe.Pointer(result) + __p.Pin(ptr) + return ptr + }()) + }); __err != nil { + west.CurrentErrorHandler()(__err) + } + return +} + +//go:linkname wasmimport_OutputStreamBlockingWriteAndFlush github.com/rvolosatovs/west/go/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__go__bindings__wasi__io__streams.StreamError, struct{}, github_com__rvolosatovs__west__go__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 { + ptr := unsafe.Pointer(&self0) + __p.Pin(ptr) + return ptr + }(), func() unsafe.Pointer { + ptr := unsafe.Pointer(contents0) + __p.Pin(ptr) + return ptr + }(), func() unsafe.Pointer { + ptr := unsafe.Pointer(&contents1) + __p.Pin(ptr) + return ptr + }(), func() unsafe.Pointer { + ptr := unsafe.Pointer(result) + __p.Pin(ptr) + return ptr + }()) + }); __err != nil { + west.CurrentErrorHandler()(__err) + } + return +} + +//go:linkname wasmimport_OutputStreamBlockingWriteZeroesAndFlush github.com/rvolosatovs/west/go/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__go__bindings__wasi__io__streams.StreamError, struct{}, github_com__rvolosatovs__west__go__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 { + ptr := unsafe.Pointer(&self0) + __p.Pin(ptr) + return ptr + }(), func() unsafe.Pointer { + ptr := unsafe.Pointer(&len0) + __p.Pin(ptr) + return ptr + }(), func() unsafe.Pointer { + ptr := unsafe.Pointer(result) + __p.Pin(ptr) + return ptr + }()) + }); __err != nil { + west.CurrentErrorHandler()(__err) + } + return +} + +//go:linkname wasmimport_OutputStreamCheckWrite github.com/rvolosatovs/west/go/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__go__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 { + ptr := unsafe.Pointer(&self0) + __p.Pin(ptr) + return ptr + }(), func() unsafe.Pointer { + ptr := unsafe.Pointer(result) + __p.Pin(ptr) + return ptr + }()) + }); __err != nil { + west.CurrentErrorHandler()(__err) + } + return +} + +//go:linkname wasmimport_OutputStreamFlush github.com/rvolosatovs/west/go/bindings/wasi/io/streams.wasmimport_OutputStreamFlush +func wasmimport_OutputStreamFlush(self0 uint32, result *github_com__ydnar__wasm___tools___go__cm.Result[github_com__rvolosatovs__west__go__bindings__wasi__io__streams.StreamError, struct{}, github_com__rvolosatovs__west__go__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 { + ptr := unsafe.Pointer(&self0) + __p.Pin(ptr) + return ptr + }(), func() unsafe.Pointer { + ptr := unsafe.Pointer(result) + __p.Pin(ptr) + return ptr + }()) + }); __err != nil { + west.CurrentErrorHandler()(__err) + } + return +} + +//go:linkname wasmimport_OutputStreamSplice github.com/rvolosatovs/west/go/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__go__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 { + ptr := unsafe.Pointer(&self0) + __p.Pin(ptr) + return ptr + }(), func() unsafe.Pointer { + ptr := unsafe.Pointer(&src0) + __p.Pin(ptr) + return ptr + }(), func() unsafe.Pointer { + ptr := unsafe.Pointer(&len0) + __p.Pin(ptr) + return ptr + }(), func() unsafe.Pointer { + ptr := unsafe.Pointer(result) + __p.Pin(ptr) + return ptr + }()) + }); __err != nil { + west.CurrentErrorHandler()(__err) + } + return +} + +//go:linkname wasmimport_OutputStreamSubscribe github.com/rvolosatovs/west/go/bindings/wasi/io/streams.wasmimport_OutputStreamSubscribe +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 { + ptr := unsafe.Pointer(&self0) + __p.Pin(ptr) + return ptr + }(), func() unsafe.Pointer { + ptr := unsafe.Pointer(&result0) + __p.Pin(ptr) + return ptr + }()) + }); __err != nil { + west.CurrentErrorHandler()(__err) + } + return +} + +//go:linkname wasmimport_OutputStreamWrite github.com/rvolosatovs/west/go/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__go__bindings__wasi__io__streams.StreamError, struct{}, github_com__rvolosatovs__west__go__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 { + ptr := unsafe.Pointer(&self0) + __p.Pin(ptr) + return ptr + }(), func() unsafe.Pointer { + ptr := unsafe.Pointer(contents0) + __p.Pin(ptr) + return ptr + }(), func() unsafe.Pointer { + ptr := unsafe.Pointer(&contents1) + __p.Pin(ptr) + return ptr + }(), func() unsafe.Pointer { + ptr := unsafe.Pointer(result) + __p.Pin(ptr) + return ptr + }()) + }); __err != nil { + west.CurrentErrorHandler()(__err) + } + return +} + +//go:linkname wasmimport_OutputStreamWriteZeroes github.com/rvolosatovs/west/go/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__go__bindings__wasi__io__streams.StreamError, struct{}, github_com__rvolosatovs__west__go__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 { + ptr := unsafe.Pointer(&self0) + __p.Pin(ptr) + return ptr + }(), func() unsafe.Pointer { + ptr := unsafe.Pointer(&len0) + __p.Pin(ptr) + return ptr + }(), func() unsafe.Pointer { + ptr := unsafe.Pointer(result) + __p.Pin(ptr) + return ptr + }()) + }); __err != nil { + west.CurrentErrorHandler()(__err) + } + return +} + +//go:linkname wasmimport_InputStreamResourceDrop github.com/rvolosatovs/west/go/bindings/wasi/io/streams.wasmimport_InputStreamResourceDrop +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 { + ptr := unsafe.Pointer(&self0) + __p.Pin(ptr) + return ptr + }()) + }); __err != nil { + west.CurrentErrorHandler()(__err) + } + return +} + +//go:linkname wasmimport_OutputStreamResourceDrop github.com/rvolosatovs/west/go/bindings/wasi/io/streams.wasmimport_OutputStreamResourceDrop +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 { + ptr := unsafe.Pointer(&self0) + __p.Pin(ptr) + return ptr + }()) + }); __err != nil { + west.CurrentErrorHandler()(__err) + } + return +} + +//go:linkname wasmimport_NewIncomingRequest github.com/rvolosatovs/west/go/bindings/west/test/http-test.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 { + ptr := unsafe.Pointer(&req0) + __p.Pin(ptr) + return ptr + }(), func() unsafe.Pointer { + ptr := unsafe.Pointer(&result0) + __p.Pin(ptr) + return ptr + }()) + }); __err != nil { + west.CurrentErrorHandler()(__err) + } + return +} + +//go:linkname wasmimport_NewResponseOutparam github.com/rvolosatovs/west/go/bindings/west/test/http-test.wasmimport_NewResponseOutparam +func wasmimport_NewResponseOutparam(result *github_com__ydnar__wasm___tools___go__cm.Tuple[github_com__rvolosatovs__west__go__bindings__wasi__http__types.ResponseOutparam, github_com__rvolosatovs__west__go__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 { + ptr := unsafe.Pointer(result) + __p.Pin(ptr) + return ptr + }()) + }); __err != nil { + west.CurrentErrorHandler()(__err) + } + return +} diff --git a/go/bindings/wasi/cli/environment/empty.s b/go/bindings/wasi/cli/environment/empty.s new file mode 100644 index 0000000..5444f20 --- /dev/null +++ b/go/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/go/bindings/wasi/cli/environment/environment.wit.go b/go/bindings/wasi/cli/environment/environment.wit.go new file mode 100644 index 0000000..a582bdf --- /dev/null +++ b/go/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.0". +package environment + +import ( + "github.com/ydnar/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.0 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.0 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.0 initial-cwd +//go:noescape +func wasmimport_InitialCWD(result *cm.Option[string]) diff --git a/go/bindings/wasi/cli/exit/empty.s b/go/bindings/wasi/cli/exit/empty.s new file mode 100644 index 0000000..5444f20 --- /dev/null +++ b/go/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/go/bindings/wasi/cli/exit/exit.wit.go b/go/bindings/wasi/cli/exit/exit.wit.go new file mode 100644 index 0000000..bf46d1b --- /dev/null +++ b/go/bindings/wasi/cli/exit/exit.wit.go @@ -0,0 +1,25 @@ +// Code generated by wit-bindgen-go. DO NOT EDIT. + +// Package exit represents the imported interface "wasi:cli/exit@0.2.0". +package exit + +import ( + "github.com/ydnar/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.0 exit +//go:noescape +func wasmimport_Exit(status0 uint32) diff --git a/go/bindings/wasi/cli/imports/imports.wit.go b/go/bindings/wasi/cli/imports/imports.wit.go new file mode 100644 index 0000000..84b4fd2 --- /dev/null +++ b/go/bindings/wasi/cli/imports/imports.wit.go @@ -0,0 +1,4 @@ +// Code generated by wit-bindgen-go. DO NOT EDIT. + +// Package imports represents the world "wasi:cli/imports@0.2.0". +package imports diff --git a/go/bindings/wasi/cli/stderr/empty.s b/go/bindings/wasi/cli/stderr/empty.s new file mode 100644 index 0000000..5444f20 --- /dev/null +++ b/go/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/go/bindings/wasi/cli/stderr/stderr.wit.go b/go/bindings/wasi/cli/stderr/stderr.wit.go new file mode 100644 index 0000000..5346589 --- /dev/null +++ b/go/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.0". +package stderr + +import ( + "github.com/rvolosatovs/west/go/bindings/wasi/io/streams" + "github.com/ydnar/wasm-tools-go/cm" +) + +// 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.0 get-stderr +//go:noescape +func wasmimport_GetStderr() (result0 uint32) diff --git a/go/bindings/wasi/cli/stdin/empty.s b/go/bindings/wasi/cli/stdin/empty.s new file mode 100644 index 0000000..5444f20 --- /dev/null +++ b/go/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/go/bindings/wasi/cli/stdin/stdin.wit.go b/go/bindings/wasi/cli/stdin/stdin.wit.go new file mode 100644 index 0000000..4a2c99d --- /dev/null +++ b/go/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.0". +package stdin + +import ( + "github.com/rvolosatovs/west/go/bindings/wasi/io/streams" + "github.com/ydnar/wasm-tools-go/cm" +) + +// 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.0 get-stdin +//go:noescape +func wasmimport_GetStdin() (result0 uint32) diff --git a/go/bindings/wasi/cli/stdout/empty.s b/go/bindings/wasi/cli/stdout/empty.s new file mode 100644 index 0000000..5444f20 --- /dev/null +++ b/go/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/go/bindings/wasi/cli/stdout/stdout.wit.go b/go/bindings/wasi/cli/stdout/stdout.wit.go new file mode 100644 index 0000000..2c27c52 --- /dev/null +++ b/go/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.0". +package stdout + +import ( + "github.com/rvolosatovs/west/go/bindings/wasi/io/streams" + "github.com/ydnar/wasm-tools-go/cm" +) + +// 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.0 get-stdout +//go:noescape +func wasmimport_GetStdout() (result0 uint32) diff --git a/go/bindings/wasi/cli/terminal-input/empty.s b/go/bindings/wasi/cli/terminal-input/empty.s new file mode 100644 index 0000000..5444f20 --- /dev/null +++ b/go/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/go/bindings/wasi/cli/terminal-input/terminal-input.wit.go b/go/bindings/wasi/cli/terminal-input/terminal-input.wit.go new file mode 100644 index 0000000..9dca7df --- /dev/null +++ b/go/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.0". +// +// 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/ydnar/wasm-tools-go/cm" +) + +// TerminalInput represents the imported resource "wasi:cli/terminal-input@0.2.0#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.0 [resource-drop]terminal-input +//go:noescape +func wasmimport_TerminalInputResourceDrop(self0 uint32) diff --git a/go/bindings/wasi/cli/terminal-output/empty.s b/go/bindings/wasi/cli/terminal-output/empty.s new file mode 100644 index 0000000..5444f20 --- /dev/null +++ b/go/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/go/bindings/wasi/cli/terminal-output/terminal-output.wit.go b/go/bindings/wasi/cli/terminal-output/terminal-output.wit.go new file mode 100644 index 0000000..b6ff728 --- /dev/null +++ b/go/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.0". +// +// 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/ydnar/wasm-tools-go/cm" +) + +// TerminalOutput represents the imported resource "wasi:cli/terminal-output@0.2.0#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.0 [resource-drop]terminal-output +//go:noescape +func wasmimport_TerminalOutputResourceDrop(self0 uint32) diff --git a/go/bindings/wasi/cli/terminal-stderr/empty.s b/go/bindings/wasi/cli/terminal-stderr/empty.s new file mode 100644 index 0000000..5444f20 --- /dev/null +++ b/go/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/go/bindings/wasi/cli/terminal-stderr/terminal-stderr.wit.go b/go/bindings/wasi/cli/terminal-stderr/terminal-stderr.wit.go new file mode 100644 index 0000000..a9f8d5b --- /dev/null +++ b/go/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.0". +// +// An interface providing an optional `terminal-output` for stderr as a +// link-time authority. +package terminalstderr + +import ( + terminaloutput "github.com/rvolosatovs/west/go/bindings/wasi/cli/terminal-output" + "github.com/ydnar/wasm-tools-go/cm" +) + +// 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.0 get-terminal-stderr +//go:noescape +func wasmimport_GetTerminalStderr(result *cm.Option[terminaloutput.TerminalOutput]) diff --git a/go/bindings/wasi/cli/terminal-stdin/empty.s b/go/bindings/wasi/cli/terminal-stdin/empty.s new file mode 100644 index 0000000..5444f20 --- /dev/null +++ b/go/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/go/bindings/wasi/cli/terminal-stdin/terminal-stdin.wit.go b/go/bindings/wasi/cli/terminal-stdin/terminal-stdin.wit.go new file mode 100644 index 0000000..d99c239 --- /dev/null +++ b/go/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.0". +// +// An interface providing an optional `terminal-input` for stdin as a +// link-time authority. +package terminalstdin + +import ( + terminalinput "github.com/rvolosatovs/west/go/bindings/wasi/cli/terminal-input" + "github.com/ydnar/wasm-tools-go/cm" +) + +// 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.0 get-terminal-stdin +//go:noescape +func wasmimport_GetTerminalStdin(result *cm.Option[terminalinput.TerminalInput]) diff --git a/go/bindings/wasi/cli/terminal-stdout/empty.s b/go/bindings/wasi/cli/terminal-stdout/empty.s new file mode 100644 index 0000000..5444f20 --- /dev/null +++ b/go/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/go/bindings/wasi/cli/terminal-stdout/terminal-stdout.wit.go b/go/bindings/wasi/cli/terminal-stdout/terminal-stdout.wit.go new file mode 100644 index 0000000..ed7ca8e --- /dev/null +++ b/go/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.0". +// +// An interface providing an optional `terminal-output` for stdout as a +// link-time authority. +package terminalstdout + +import ( + terminaloutput "github.com/rvolosatovs/west/go/bindings/wasi/cli/terminal-output" + "github.com/ydnar/wasm-tools-go/cm" +) + +// 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.0 get-terminal-stdout +//go:noescape +func wasmimport_GetTerminalStdout(result *cm.Option[terminaloutput.TerminalOutput]) diff --git a/go/bindings/wasi/clocks/imports/imports.wit.go b/go/bindings/wasi/clocks/imports/imports.wit.go new file mode 100644 index 0000000..a5a5c71 --- /dev/null +++ b/go/bindings/wasi/clocks/imports/imports.wit.go @@ -0,0 +1,4 @@ +// Code generated by wit-bindgen-go. DO NOT EDIT. + +// Package imports represents the world "wasi:clocks/imports@0.2.0". +package imports diff --git a/go/bindings/wasi/clocks/monotonic-clock/empty.s b/go/bindings/wasi/clocks/monotonic-clock/empty.s new file mode 100644 index 0000000..5444f20 --- /dev/null +++ b/go/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/go/bindings/wasi/clocks/monotonic-clock/monotonic-clock.wit.go b/go/bindings/wasi/clocks/monotonic-clock/monotonic-clock.wit.go new file mode 100644 index 0000000..804fc20 --- /dev/null +++ b/go/bindings/wasi/clocks/monotonic-clock/monotonic-clock.wit.go @@ -0,0 +1,113 @@ +// Code generated by wit-bindgen-go. DO NOT EDIT. + +// Package monotonicclock represents the imported interface "wasi:clocks/monotonic-clock@0.2.0". +// +// 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. +// +// It is intended for measuring elapsed time. +package monotonicclock + +import ( + "github.com/rvolosatovs/west/go/bindings/wasi/io/poll" + "github.com/ydnar/wasm-tools-go/cm" +) + +// Instant represents the u64 "wasi:clocks/monotonic-clock@0.2.0#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.0#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.0 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.0 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. +// +// 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.0 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. +// +// 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.0 subscribe-duration +//go:noescape +func wasmimport_SubscribeDuration(when0 uint64) (result0 uint32) diff --git a/go/bindings/wasi/clocks/wall-clock/empty.s b/go/bindings/wasi/clocks/wall-clock/empty.s new file mode 100644 index 0000000..5444f20 --- /dev/null +++ b/go/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/go/bindings/wasi/clocks/wall-clock/wall-clock.wit.go b/go/bindings/wasi/clocks/wall-clock/wall-clock.wit.go new file mode 100644 index 0000000..a59a313 --- /dev/null +++ b/go/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.0". +// +// 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.0#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.0 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.0 resolution +//go:noescape +func wasmimport_Resolution(result *DateTime) diff --git a/go/bindings/wasi/filesystem/imports/imports.wit.go b/go/bindings/wasi/filesystem/imports/imports.wit.go new file mode 100644 index 0000000..f39bdfc --- /dev/null +++ b/go/bindings/wasi/filesystem/imports/imports.wit.go @@ -0,0 +1,4 @@ +// Code generated by wit-bindgen-go. DO NOT EDIT. + +// Package imports represents the world "wasi:filesystem/imports@0.2.0". +package imports diff --git a/go/bindings/wasi/filesystem/preopens/empty.s b/go/bindings/wasi/filesystem/preopens/empty.s new file mode 100644 index 0000000..5444f20 --- /dev/null +++ b/go/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/go/bindings/wasi/filesystem/preopens/preopens.wit.go b/go/bindings/wasi/filesystem/preopens/preopens.wit.go new file mode 100644 index 0000000..40c0008 --- /dev/null +++ b/go/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.0". +package preopens + +import ( + "github.com/rvolosatovs/west/go/bindings/wasi/filesystem/types" + "github.com/ydnar/wasm-tools-go/cm" +) + +// 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.0 get-directories +//go:noescape +func wasmimport_GetDirectories(result *cm.List[cm.Tuple[types.Descriptor, string]]) diff --git a/go/bindings/wasi/filesystem/types/abi.go b/go/bindings/wasi/filesystem/types/abi.go new file mode 100644 index 0000000..f800bcd --- /dev/null +++ b/go/bindings/wasi/filesystem/types/abi.go @@ -0,0 +1,51 @@ +// Code generated by wit-bindgen-go. DO NOT EDIT. + +package types + +import ( + wallclock "github.com/rvolosatovs/west/go/bindings/wasi/clocks/wall-clock" + "github.com/ydnar/wasm-tools-go/cm" + "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/go/bindings/wasi/filesystem/types/empty.s b/go/bindings/wasi/filesystem/types/empty.s new file mode 100644 index 0000000..5444f20 --- /dev/null +++ b/go/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/go/bindings/wasi/filesystem/types/types.wit.go b/go/bindings/wasi/filesystem/types/types.wit.go new file mode 100644 index 0000000..d5f036c --- /dev/null +++ b/go/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.0". +// +// 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 ( + wallclock "github.com/rvolosatovs/west/go/bindings/wasi/clocks/wall-clock" + ioerror "github.com/rvolosatovs/west/go/bindings/wasi/io/error" + "github.com/rvolosatovs/west/go/bindings/wasi/io/streams" + "github.com/ydnar/wasm-tools-go/cm" +) + +// FileSize represents the u64 "wasi:filesystem/types@0.2.0#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". +// +// 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.0#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 integrety + // 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.0#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.0#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.0#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". +// +// 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.0#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.0#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.0#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.0#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.0#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.0#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.0 [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.0 [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.0 [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.0 [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.0 [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.0 [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.0 [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.0 [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.0 [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.0 [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.0 [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.0 [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.0 [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.0 [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.0 [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.0 [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.0 [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.0 [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.0 [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.0 [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.0 [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.0 [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.0 [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.0 [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.0 [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.0 [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.0 [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.0 [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". +// +// 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.0 [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.0 [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.0 filesystem-error-code +//go:noescape +func wasmimport_FilesystemErrorCode(err0 uint32, result *cm.Option[ErrorCode]) diff --git a/go/bindings/wasi/http/types/abi.go b/go/bindings/wasi/http/types/abi.go new file mode 100644 index 0000000..fcdb1b1 --- /dev/null +++ b/go/bindings/wasi/http/types/abi.go @@ -0,0 +1,273 @@ +// Code generated by wit-bindgen-go. DO NOT EDIT. + +package types + +import ( + monotonicclock "github.com/rvolosatovs/west/go/bindings/wasi/clocks/monotonic-clock" + "github.com/ydnar/wasm-tools-go/cm" + "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/go/bindings/wasi/http/types/empty.s b/go/bindings/wasi/http/types/empty.s new file mode 100644 index 0000000..5444f20 --- /dev/null +++ b/go/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/go/bindings/wasi/http/types/types.wit.go b/go/bindings/wasi/http/types/types.wit.go new file mode 100644 index 0000000..042d4f1 --- /dev/null +++ b/go/bindings/wasi/http/types/types.wit.go @@ -0,0 +1,2141 @@ +// Code generated by wit-bindgen-go. DO NOT EDIT. + +// Package types represents the imported interface "wasi:http/types@0.2.0". +// +// 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 ( + monotonicclock "github.com/rvolosatovs/west/go/bindings/wasi/clocks/monotonic-clock" + ioerror "github.com/rvolosatovs/west/go/bindings/wasi/io/error" + "github.com/rvolosatovs/west/go/bindings/wasi/io/poll" + "github.com/rvolosatovs/west/go/bindings/wasi/io/streams" + "github.com/ydnar/wasm-tools-go/cm" +) + +// Method represents the variant "wasi:http/types@0.2.0#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.0#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.0#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.0#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.0#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.0#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.0#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.0#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". +// +// 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.0#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.0 [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.0 [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. 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. +// +// An error result will be returned if any header or value was +// syntactically invalid, or if a header was 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.0 [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. +// +// 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.0 [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 +// `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.0 [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. +// +// 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.0 [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.0 [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. +// +// 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.0 [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.0 [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. +// +// 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.0 [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". +// +// 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.0 [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. +// +// 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.0 [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.0 [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.0 [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.0 [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.0 [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.0 [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". +// +// 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.0 [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.0 [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 +// 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.0 [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.0 [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 transfered 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.0 [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.0 [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.0 [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.0 [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 +// 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.0 [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.0 [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.0 [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.0 [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". +// +// 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.0 [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.0 [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.0 [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.0 [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.0 [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.0 [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.0 [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.0 [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". +// +// 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.0 [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.0 [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". +// +// 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". +// +// 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.0 [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.0 [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.0 [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.0 [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". +// +// 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.0 [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.0 [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.0 [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". +// +// Represents a future which may eventaully 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.0 [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, +// 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 occured 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.0 [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, +// 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.0 [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". +// +// 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.0 [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.0 [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.0 [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 transfered 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.0 [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.0 [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.0 [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". +// +// 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 occured. The implementation should propogate 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.0 [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.0 [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.0 [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". +// +// Represents a future which may eventaully 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.0 [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 recieved successfully, or that an error +// occured. 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.0 [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, +// 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.0 [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.0 http-error-code +//go:noescape +func wasmimport_HTTPErrorCode(err0 uint32, result *cm.Option[ErrorCode]) diff --git a/go/bindings/wasi/io/error/empty.s b/go/bindings/wasi/io/error/empty.s new file mode 100644 index 0000000..5444f20 --- /dev/null +++ b/go/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/go/bindings/wasi/io/error/error.wit.go b/go/bindings/wasi/io/error/error.wit.go new file mode 100644 index 0000000..96d18cf --- /dev/null +++ b/go/bindings/wasi/io/error/error.wit.go @@ -0,0 +1,71 @@ +// Code generated by wit-bindgen-go. DO NOT EDIT. + +// Package ioerror represents the imported interface "wasi:io/error@0.2.0". +package ioerror + +import ( + "github.com/ydnar/wasm-tools-go/cm" +) + +// Error represents the imported resource "wasi:io/error@0.2.0#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 +// 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`. +// +// 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.0 [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.0 [method]error.to-debug-string +//go:noescape +func wasmimport_ErrorToDebugString(self0 uint32, result *string) diff --git a/go/bindings/wasi/io/imports/imports.wit.go b/go/bindings/wasi/io/imports/imports.wit.go new file mode 100644 index 0000000..dab34b9 --- /dev/null +++ b/go/bindings/wasi/io/imports/imports.wit.go @@ -0,0 +1,4 @@ +// Code generated by wit-bindgen-go. DO NOT EDIT. + +// Package imports represents the world "wasi:io/imports@0.2.0". +package imports diff --git a/go/bindings/wasi/io/poll/empty.s b/go/bindings/wasi/io/poll/empty.s new file mode 100644 index 0000000..5444f20 --- /dev/null +++ b/go/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/go/bindings/wasi/io/poll/poll.wit.go b/go/bindings/wasi/io/poll/poll.wit.go new file mode 100644 index 0000000..ba22e54 --- /dev/null +++ b/go/bindings/wasi/io/poll/poll.wit.go @@ -0,0 +1,108 @@ +// Code generated by wit-bindgen-go. DO NOT EDIT. + +// Package poll represents the imported interface "wasi:io/poll@0.2.0". +// +// 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" +) + +// Pollable represents the imported resource "wasi:io/poll@0.2.0#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.0 [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.0 [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.0 [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. +// +// If the list contains more elements than can be indexed with a `u32` +// value, this function traps. +// +// 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 reaedy 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.0 poll +//go:noescape +func wasmimport_Poll(in0 *Pollable, in1 uint32, result *cm.List[uint32]) diff --git a/go/bindings/wasi/io/streams/abi.go b/go/bindings/wasi/io/streams/abi.go new file mode 100644 index 0000000..5f15002 --- /dev/null +++ b/go/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/go/bindings/wasi/io/streams/empty.s b/go/bindings/wasi/io/streams/empty.s new file mode 100644 index 0000000..5444f20 --- /dev/null +++ b/go/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/go/bindings/wasi/io/streams/streams.wit.go b/go/bindings/wasi/io/streams/streams.wit.go new file mode 100644 index 0000000..d88bcfa --- /dev/null +++ b/go/bindings/wasi/io/streams/streams.wit.go @@ -0,0 +1,519 @@ +// Code generated by wit-bindgen-go. DO NOT EDIT. + +// Package streams represents the imported interface "wasi:io/streams@0.2.0". +// +// 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 ( + ioerror "github.com/rvolosatovs/west/go/bindings/wasi/io/error" + "github.com/rvolosatovs/west/go/bindings/wasi/io/poll" + "github.com/ydnar/wasm-tools-go/cm" +) + +// StreamError represents the imported variant "wasi:io/streams@0.2.0#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.0#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.0 [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.0 [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.0 [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.0 [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.0 [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.0 [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". +// +// 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`. +// +// 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.0 [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.0 [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.0 [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.0 [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.0 [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.0 [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.0 [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 equivelant 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.0 [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 +// 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.0 [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.0 [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.0 [method]output-stream.write-zeroes +//go:noescape +func wasmimport_OutputStreamWriteZeroes(self0 uint32, len0 uint64, result *cm.Result[StreamError, struct{}, StreamError]) diff --git a/go/bindings/wasi/random/imports/imports.wit.go b/go/bindings/wasi/random/imports/imports.wit.go new file mode 100644 index 0000000..3f0247b --- /dev/null +++ b/go/bindings/wasi/random/imports/imports.wit.go @@ -0,0 +1,4 @@ +// Code generated by wit-bindgen-go. DO NOT EDIT. + +// Package imports represents the world "wasi:random/imports@0.2.0". +package imports diff --git a/go/bindings/wasi/random/insecure-seed/empty.s b/go/bindings/wasi/random/insecure-seed/empty.s new file mode 100644 index 0000000..5444f20 --- /dev/null +++ b/go/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/go/bindings/wasi/random/insecure-seed/insecure-seed.wit.go b/go/bindings/wasi/random/insecure-seed/insecure-seed.wit.go new file mode 100644 index 0000000..3b8f33c --- /dev/null +++ b/go/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.0". +// +// 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.0 insecure-seed +//go:noescape +func wasmimport_InsecureSeed(result *[2]uint64) diff --git a/go/bindings/wasi/random/insecure/empty.s b/go/bindings/wasi/random/insecure/empty.s new file mode 100644 index 0000000..5444f20 --- /dev/null +++ b/go/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/go/bindings/wasi/random/insecure/insecure.wit.go b/go/bindings/wasi/random/insecure/insecure.wit.go new file mode 100644 index 0000000..4f813bf --- /dev/null +++ b/go/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.0". +// +// 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/ydnar/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.0 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.0 get-insecure-random-u64 +//go:noescape +func wasmimport_GetInsecureRandomU64() (result0 uint64) diff --git a/go/bindings/wasi/random/random/empty.s b/go/bindings/wasi/random/random/empty.s new file mode 100644 index 0000000..5444f20 --- /dev/null +++ b/go/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/go/bindings/wasi/random/random/random.wit.go b/go/bindings/wasi/random/random/random.wit.go new file mode 100644 index 0000000..04b2319 --- /dev/null +++ b/go/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.0". +// +// 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/ydnar/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.0 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.0 get-random-u64 +//go:noescape +func wasmimport_GetRandomU64() (result0 uint64) diff --git a/go/bindings/wasi/sockets/imports/imports.wit.go b/go/bindings/wasi/sockets/imports/imports.wit.go new file mode 100644 index 0000000..1b52e62 --- /dev/null +++ b/go/bindings/wasi/sockets/imports/imports.wit.go @@ -0,0 +1,4 @@ +// Code generated by wit-bindgen-go. DO NOT EDIT. + +// Package imports represents the world "wasi:sockets/imports@0.2.0". +package imports diff --git a/go/bindings/wasi/sockets/instance-network/empty.s b/go/bindings/wasi/sockets/instance-network/empty.s new file mode 100644 index 0000000..5444f20 --- /dev/null +++ b/go/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/go/bindings/wasi/sockets/instance-network/instance-network.wit.go b/go/bindings/wasi/sockets/instance-network/instance-network.wit.go new file mode 100644 index 0000000..a25c5f9 --- /dev/null +++ b/go/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.0". +// +// This interface provides a value-export of the default network handle.. +package instancenetwork + +import ( + "github.com/rvolosatovs/west/go/bindings/wasi/sockets/network" + "github.com/ydnar/wasm-tools-go/cm" +) + +// 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.0 instance-network +//go:noescape +func wasmimport_InstanceNetwork() (result0 uint32) diff --git a/go/bindings/wasi/sockets/ip-name-lookup/abi.go b/go/bindings/wasi/sockets/ip-name-lookup/abi.go new file mode 100644 index 0000000..7cc1912 --- /dev/null +++ b/go/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/rvolosatovs/west/go/bindings/wasi/sockets/network" + "github.com/ydnar/wasm-tools-go/cm" + "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/go/bindings/wasi/sockets/ip-name-lookup/empty.s b/go/bindings/wasi/sockets/ip-name-lookup/empty.s new file mode 100644 index 0000000..5444f20 --- /dev/null +++ b/go/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/go/bindings/wasi/sockets/ip-name-lookup/ip-name-lookup.wit.go b/go/bindings/wasi/sockets/ip-name-lookup/ip-name-lookup.wit.go new file mode 100644 index 0000000..7fdc971 --- /dev/null +++ b/go/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.0". +package ipnamelookup + +import ( + "github.com/rvolosatovs/west/go/bindings/wasi/io/poll" + "github.com/rvolosatovs/west/go/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". +// +// 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.0 [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.0 [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.0 [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.0 resolve-addresses +//go:noescape +func wasmimport_ResolveAddresses(network0 uint32, name0 *uint8, name1 uint32, result *cm.Result[ResolveAddressStream, ResolveAddressStream, network.ErrorCode]) diff --git a/go/bindings/wasi/sockets/network/abi.go b/go/bindings/wasi/sockets/network/abi.go new file mode 100644 index 0000000..54820be --- /dev/null +++ b/go/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/go/bindings/wasi/sockets/network/empty.s b/go/bindings/wasi/sockets/network/empty.s new file mode 100644 index 0000000..5444f20 --- /dev/null +++ b/go/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/go/bindings/wasi/sockets/network/network.wit.go b/go/bindings/wasi/sockets/network/network.wit.go new file mode 100644 index 0000000..4597e24 --- /dev/null +++ b/go/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.0". +package network + +import ( + "github.com/ydnar/wasm-tools-go/cm" +) + +// Network represents the imported resource "wasi:sockets/network@0.2.0#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.0 [resource-drop]network +//go:noescape +func wasmimport_NetworkResourceDrop(self0 uint32) + +// ErrorCode represents the enum "wasi:sockets/network@0.2.0#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.0#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.0#ipv4-address". +// +// type ipv4-address = tuple +type IPv4Address [4]uint8 + +// IPv6Address represents the tuple "wasi:sockets/network@0.2.0#ipv6-address". +// +// type ipv6-address = tuple +type IPv6Address [8]uint16 + +// IPAddress represents the variant "wasi:sockets/network@0.2.0#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.0#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.0#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.0#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/go/bindings/wasi/sockets/tcp-create-socket/empty.s b/go/bindings/wasi/sockets/tcp-create-socket/empty.s new file mode 100644 index 0000000..5444f20 --- /dev/null +++ b/go/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/go/bindings/wasi/sockets/tcp-create-socket/tcp-create-socket.wit.go b/go/bindings/wasi/sockets/tcp-create-socket/tcp-create-socket.wit.go new file mode 100644 index 0000000..7259f53 --- /dev/null +++ b/go/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.0". +package tcpcreatesocket + +import ( + "github.com/rvolosatovs/west/go/bindings/wasi/sockets/network" + "github.com/rvolosatovs/west/go/bindings/wasi/sockets/tcp" + "github.com/ydnar/wasm-tools-go/cm" +) + +// 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.0 create-tcp-socket +//go:noescape +func wasmimport_CreateTCPSocket(addressFamily0 uint32, result *cm.Result[tcp.TCPSocket, tcp.TCPSocket, network.ErrorCode]) diff --git a/go/bindings/wasi/sockets/tcp/abi.go b/go/bindings/wasi/sockets/tcp/abi.go new file mode 100644 index 0000000..61d723b --- /dev/null +++ b/go/bindings/wasi/sockets/tcp/abi.go @@ -0,0 +1,86 @@ +// Code generated by wit-bindgen-go. DO NOT EDIT. + +package tcp + +import ( + "github.com/rvolosatovs/west/go/bindings/wasi/io/streams" + "github.com/rvolosatovs/west/go/bindings/wasi/sockets/network" + "github.com/ydnar/wasm-tools-go/cm" + "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/go/bindings/wasi/sockets/tcp/empty.s b/go/bindings/wasi/sockets/tcp/empty.s new file mode 100644 index 0000000..5444f20 --- /dev/null +++ b/go/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/go/bindings/wasi/sockets/tcp/tcp.wit.go b/go/bindings/wasi/sockets/tcp/tcp.wit.go new file mode 100644 index 0000000..aa63fa1 --- /dev/null +++ b/go/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.0". +package tcp + +import ( + monotonicclock "github.com/rvolosatovs/west/go/bindings/wasi/clocks/monotonic-clock" + "github.com/rvolosatovs/west/go/bindings/wasi/io/poll" + "github.com/rvolosatovs/west/go/bindings/wasi/io/streams" + "github.com/rvolosatovs/west/go/bindings/wasi/sockets/network" + "github.com/ydnar/wasm-tools-go/cm" +) + +// ShutdownType represents the enum "wasi:sockets/tcp@0.2.0#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.0#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 a 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.0 [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.0 [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.0 [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.0 [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.0 [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.0 [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.0 [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.0 [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.0 [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.0 [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.0 [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.0 [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.0 [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.0 [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.0 [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.0 [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.0 [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.0 [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.0 [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.0 [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.0 [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.0 [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.0 [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.0 [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 a 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.0 [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.0 [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 `connection` 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.0 [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.0 [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 a 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.0 [method]tcp-socket.subscribe +//go:noescape +func wasmimport_TCPSocketSubscribe(self0 uint32) (result0 uint32) diff --git a/go/bindings/wasi/sockets/udp-create-socket/empty.s b/go/bindings/wasi/sockets/udp-create-socket/empty.s new file mode 100644 index 0000000..5444f20 --- /dev/null +++ b/go/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/go/bindings/wasi/sockets/udp-create-socket/udp-create-socket.wit.go b/go/bindings/wasi/sockets/udp-create-socket/udp-create-socket.wit.go new file mode 100644 index 0000000..0901d84 --- /dev/null +++ b/go/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.0". +package udpcreatesocket + +import ( + "github.com/rvolosatovs/west/go/bindings/wasi/sockets/network" + "github.com/rvolosatovs/west/go/bindings/wasi/sockets/udp" + "github.com/ydnar/wasm-tools-go/cm" +) + +// 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.0 create-udp-socket +//go:noescape +func wasmimport_CreateUDPSocket(addressFamily0 uint32, result *cm.Result[udp.UDPSocket, udp.UDPSocket, network.ErrorCode]) diff --git a/go/bindings/wasi/sockets/udp/abi.go b/go/bindings/wasi/sockets/udp/abi.go new file mode 100644 index 0000000..57e722a --- /dev/null +++ b/go/bindings/wasi/sockets/udp/abi.go @@ -0,0 +1,101 @@ +// Code generated by wit-bindgen-go. DO NOT EDIT. + +package udp + +import ( + "github.com/rvolosatovs/west/go/bindings/wasi/sockets/network" + "github.com/ydnar/wasm-tools-go/cm" + "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/go/bindings/wasi/sockets/udp/empty.s b/go/bindings/wasi/sockets/udp/empty.s new file mode 100644 index 0000000..5444f20 --- /dev/null +++ b/go/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/go/bindings/wasi/sockets/udp/udp.wit.go b/go/bindings/wasi/sockets/udp/udp.wit.go new file mode 100644 index 0000000..c1030ce --- /dev/null +++ b/go/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.0". +package udp + +import ( + "github.com/rvolosatovs/west/go/bindings/wasi/io/poll" + "github.com/rvolosatovs/west/go/bindings/wasi/sockets/network" + "github.com/ydnar/wasm-tools-go/cm" +) + +// IncomingDatagram represents the record "wasi:sockets/udp@0.2.0#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.0#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.0#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.0 [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.0 [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.0 [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.0 [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.0 [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.0 [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.0 [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.0 [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.0 [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.0 [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.0 [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.0 [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.0 [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.0 [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". +// +// 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.0 [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.0 [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.0 [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". +// +// 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.0 [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.0 [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.0 [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.0 [method]outgoing-datagram-stream.subscribe +//go:noescape +func wasmimport_OutgoingDatagramStreamSubscribe(self0 uint32) (result0 uint32) diff --git a/go/bindings/west.go b/go/bindings/west.go new file mode 100644 index 0000000..14978d7 --- /dev/null +++ b/go/bindings/west.go @@ -0,0 +1,7 @@ +//go:generate go run ../cmd/west-bindgen-go -package bindings -output bindings.go + +package bindings + +import ( + _ "github.com/rvolosatovs/west/go/bindings/west/test/http-test" +) diff --git a/go/bindings/west/test/http-test/empty.s b/go/bindings/west/test/http-test/empty.s new file mode 100644 index 0000000..5444f20 --- /dev/null +++ b/go/bindings/west/test/http-test/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/go/bindings/west/test/http-test/http-test.wit.go b/go/bindings/west/test/http-test/http-test.wit.go new file mode 100644 index 0000000..bd057c7 --- /dev/null +++ b/go/bindings/west/test/http-test/http-test.wit.go @@ -0,0 +1,39 @@ +// Code generated by wit-bindgen-go. DO NOT EDIT. + +// Package httptest represents the imported interface "west:test/http-test@0.1.0". +package httptest + +import ( + "github.com/rvolosatovs/west/go/bindings/wasi/http/types" + "github.com/ydnar/wasm-tools-go/cm" +) + +// NewResponseOutparam represents the imported function "new-response-outparam". +// +// new-response-outparam: func() -> tuple +// +//go:nosplit +func NewResponseOutparam() (result cm.Tuple[types.ResponseOutparam, types.FutureIncomingResponse]) { + wasmimport_NewResponseOutparam(&result) + return +} + +//go:wasmimport west:test/http-test@0.1.0 new-response-outparam +//go:noescape +func wasmimport_NewResponseOutparam(result *cm.Tuple[types.ResponseOutparam, types.FutureIncomingResponse]) + +// NewIncomingRequest represents the imported function "new-incoming-request". +// +// new-incoming-request: func(req: outgoing-request) -> incoming-request +// +//go:nosplit +func NewIncomingRequest(req types.OutgoingRequest) (result types.IncomingRequest) { + req0 := cm.Reinterpret[uint32](req) + result0 := wasmimport_NewIncomingRequest((uint32)(req0)) + result = cm.Reinterpret[types.IncomingRequest]((uint32)(result0)) + return +} + +//go:wasmimport west:test/http-test@0.1.0 new-incoming-request +//go:noescape +func wasmimport_NewIncomingRequest(req0 uint32) (result0 uint32) diff --git a/go/bindings/west/test/imports/imports.wit.go b/go/bindings/west/test/imports/imports.wit.go new file mode 100644 index 0000000..7594946 --- /dev/null +++ b/go/bindings/west/test/imports/imports.wit.go @@ -0,0 +1,4 @@ +// Code generated by wit-bindgen-go. DO NOT EDIT. + +// Package imports represents the world "west:test/imports@0.1.0". +package imports diff --git a/go/cmd/west-bindgen-go/main.go b/go/cmd/west-bindgen-go/main.go new file mode 100644 index 0000000..a2a7e4f --- /dev/null +++ b/go/cmd/west-bindgen-go/main.go @@ -0,0 +1,562 @@ +package main + +import ( + "bytes" + "flag" + "fmt" + "go/ast" + "go/format" + "go/printer" + "go/token" + "go/types" + "log" + "os" + "path/filepath" + "sort" + "strings" + + "golang.org/x/tools/go/packages" +) + +var ( + output = flag.String("output", "west_bindings_test.go", "output file path from the root of the package directory") + gofmt = flag.Bool("gofmt", true, "whether to format the generated code") + pkgName = flag.String("package", "", "package name, defaults to test package at path specified") + + unsafePointerTy = &ast.SelectorExpr{ + X: &ast.Ident{Name: "unsafe"}, + Sel: &ast.Ident{Name: "Pointer"}, + } + instanceTy = &ast.SelectorExpr{ + X: &ast.Ident{Name: "west"}, + Sel: &ast.Ident{Name: "Instance"}, + } + instancePtrTy = &ast.StarExpr{X: instanceTy} + + pinnerVar = &ast.Ident{Name: "__p"} + errVar = &ast.Ident{Name: "__err"} + instanceVar = &ast.Ident{Name: "__instance"} + + ptrVar = &ast.Ident{Name: "ptr"} + + pinMethod = &ast.SelectorExpr{ + X: pinnerVar, + Sel: &ast.Ident{Name: "Pin"}, + } + + normalizer = strings.NewReplacer("-", "___", "/", "__", ".", "_") +) + +func init() { + log.SetFlags(0) + flag.Parse() +} + +type wasmImport struct { + instance string + name string + decl *ast.FuncDecl +} + +func importType(fs *token.FileSet, imports map[string]*ast.Ident, expr *ast.Expr, ty types.Type) error { + switch ty := ty.(type) { + case *types.Basic: + return nil + case *types.Pointer: + switch e := (*expr).(type) { + case *ast.StarExpr: + return importType(fs, imports, &e.X, ty.Elem()) + default: + pos := fs.Position(e.Pos()) + return fmt.Errorf("%s:%d: unexpected pointer type expression AST type %T for type %s", pos.Filename, pos.Line, e, ty) + } + case *types.Array: + switch e := (*expr).(type) { + case *ast.ArrayType: + return importType(fs, imports, &e.Elt, ty.Elem()) + default: + pos := fs.Position(e.Pos()) + return fmt.Errorf("%s:%d: unexpected array type expression AST type %T for type %s", pos.Filename, pos.Line, e, ty) + } + case *types.Struct: + n := ty.NumFields() + if n == 0 { + return nil + } + pos := fs.Position((*expr).Pos()) + return fmt.Errorf("%s:%d: anonymous structs are not currently supported", pos.Filename, pos.Line) + + case *types.Named: + pkg := ty.Obj().Pkg() + if pkg != nil { + path := pkg.Path() + imports[path] = &ast.Ident{Name: normalizer.Replace(path)} + } + tys := ty.TypeArgs() + switch e := (*expr).(type) { + case *ast.Ident: + if pkg != nil { + *expr = &ast.SelectorExpr{ + X: imports[pkg.Path()], + Sel: e, + } + } + return nil + case *ast.SelectorExpr: + if pkg != nil { + e.X = imports[pkg.Path()] + } + return nil + case *ast.IndexExpr: + switch e := e.X.(type) { + case *ast.Ident: + if pkg != nil { + *expr = &ast.SelectorExpr{ + X: imports[pkg.Path()], + Sel: e, + } + } + case *ast.SelectorExpr: + if pkg != nil { + e.X = imports[pkg.Path()] + } + default: + pos := fs.Position(e.Pos()) + return fmt.Errorf("%s:%d: unexpected named type expression AST index type %T for type %s", pos.Filename, pos.Line, e, ty) + } + n := tys.Len() + if n != 1 { + pos := fs.Position(e.Pos()) + return fmt.Errorf("%s:%d: mismatched type argument count %d in index AST expression for type %s", pos.Filename, pos.Line, n, ty) + } + return importType(fs, imports, &e.Index, tys.At(0)) + + case *ast.IndexListExpr: + switch e := e.X.(type) { + case *ast.Ident: + if pkg != nil { + *expr = &ast.SelectorExpr{ + X: imports[pkg.Path()], + Sel: e, + } + } + case *ast.SelectorExpr: + if pkg != nil { + e.X = imports[pkg.Path()] + } + default: + pos := fs.Position(e.Pos()) + return fmt.Errorf("%s:%d: unexpected named type expression AST index type %T for type %s", pos.Filename, pos.Line, e, ty) + } + n := tys.Len() + if n != len(e.Indices) { + pos := fs.Position(e.Pos()) + return fmt.Errorf("%s:%d: mismatched type argument count %d in index list AST expression for type %s", pos.Filename, pos.Line, len(e.Indices), ty) + } + for i := 0; i < n; i++ { + if err := importType(fs, imports, &e.Indices[i], tys.At(i)); err != nil { + return err + } + } + return nil + default: + pos := fs.Position(e.Pos()) + return fmt.Errorf("%s:%d: unexpected named type expression AST type %T for type %s", pos.Filename, pos.Line, e, ty) + } + default: + log.Printf("unhandled type: %T", ty) + return nil + } +} + +func generate(path string) error { + fpath := filepath.Join(path, *output) + if err := os.RemoveAll(fpath); err != nil { + return fmt.Errorf("failed to remove file at `%s`: %w", fpath, err) + } + pkgs, err := packages.Load(&packages.Config{ + Mode: packages.NeedName | + packages.NeedFiles | + packages.NeedImports | + packages.NeedDeps | + packages.NeedTypes | + packages.NeedTypesInfo | + packages.NeedSyntax, + }, path) + if err != nil { + return fmt.Errorf("failed to import `%s`: %w", path, err) + } + if len(pkgs) != 1 { + return fmt.Errorf("loaded unexpected amount of packages from `%s`, expected 1, got %d", path, len(pkgs)) + } + pkg := pkgs[0] + + file, err := os.Create(fpath) + if err != nil { + return fmt.Errorf("failed to create file at `%s`: %w", fpath, err) + } + defer file.Close() + + allPkgs := make(map[string]*packages.Package, len(pkg.Imports)) + imports := pkg.Imports + for len(imports) > 0 { + next := make(map[string]*packages.Package, len(imports)) + for p, pkg := range imports { + if _, ok := allPkgs[p]; ok { + continue + } + allPkgs[p] = pkg + for p, pkg := range pkg.Imports { + if _, ok := allPkgs[p]; ok { + continue + } + next[p] = pkg + } + } + imports = next + } + + goImports := map[string]*ast.Ident{} + var wasmImports []wasmImport + for _, pkg := range allPkgs { + for _, f := range pkg.Syntax { + for _, decl := range f.Decls { + decl, ok := decl.(*ast.FuncDecl) + if !ok || decl.Body != nil || decl.Doc == nil { + continue + } + + var dir *ast.Comment + for _, doc := range decl.Doc.List { + if !strings.HasPrefix(doc.Text, "//go:wasmimport") { + continue + } + dir = doc + break + } + if dir == nil { + continue + } + + instance, name, ok := strings.Cut(strings.TrimPrefix(dir.Text, "//go:wasmimport "), " ") + if !ok { + pos := pkg.Fset.Position(dir.Pos()) + return fmt.Errorf("%s:%d: unexpected `go:wasmimport` directive format: %s", pos.Filename, pos.Line, dir.Text) + } + + var callArgs []ast.Expr + appendArg := func(arg *ast.Field) error { + ty, ok := pkg.TypesInfo.Types[arg.Type] + if !ok { + pos := pkg.Fset.Position(arg.Type.Pos()) + return fmt.Errorf("%s:%d: unknown type: %s", pos.Filename, pos.Line, arg.Type) + } + _, isPtr := ty.Type.(*types.Pointer) + if err := importType(pkg.Fset, goImports, &arg.Type, ty.Type); err != nil { + return err + } + var args []ast.Expr + for _, name := range arg.Names { + args = append(args, name) + + callExprs := []ast.Expr{name} + if !isPtr { + callExprs = []ast.Expr{ + &ast.UnaryExpr{ + Op: token.AND, + X: name, + }, + } + } + callArgs = append(callArgs, &ast.CallExpr{ + Fun: &ast.FuncLit{ + Type: &ast.FuncType{ + Results: &ast.FieldList{List: []*ast.Field{{ + Type: unsafePointerTy, + }}}, + }, + Body: &ast.BlockStmt{ + List: []ast.Stmt{ + &ast.AssignStmt{ + Lhs: []ast.Expr{ptrVar}, + Tok: token.DEFINE, + Rhs: []ast.Expr{ + &ast.CallExpr{ + Fun: unsafePointerTy, + Args: callExprs, + }, + }, + }, + &ast.ExprStmt{ + X: &ast.CallExpr{ + Fun: pinMethod, + Args: []ast.Expr{ptrVar}, + }, + }, + &ast.ReturnStmt{Results: []ast.Expr{ptrVar}}, + }, + }, + }, + }) + } + return nil + } + + if decl.Type.Params != nil { + for _, p := range decl.Type.Params.List { + if err := appendArg(p); err != nil { + return err + } + } + } + if decl.Type.Results != nil { + for _, r := range decl.Type.Results.List { + if err := appendArg(r); err != nil { + return err + } + } + } + decl.Doc.List = []*ast.Comment{{ + Text: fmt.Sprintf(`//go:linkname %s %s.%s`, decl.Name.Name, pkg.PkgPath, decl.Name.Name), + }} + decl.Body = &ast.BlockStmt{ + List: []ast.Stmt{ + &ast.DeclStmt{ + Decl: &ast.GenDecl{ + Tok: token.VAR, + Specs: []ast.Spec{ + &ast.ValueSpec{ + Names: []*ast.Ident{pinnerVar}, + Type: &ast.SelectorExpr{ + X: &ast.Ident{Name: "runtime"}, + Sel: &ast.Ident{Name: "Pinner"}, + }, + }, + }, + }, + }, + &ast.DeferStmt{ + Call: &ast.CallExpr{ + Fun: &ast.SelectorExpr{ + X: pinnerVar, + Sel: &ast.Ident{Name: "Unpin"}, + }, + }, + }, + &ast.IfStmt{ + Init: &ast.AssignStmt{ + Lhs: []ast.Expr{ + errVar, + }, + Tok: token.DEFINE, + Rhs: []ast.Expr{ + &ast.CallExpr{ + Fun: &ast.SelectorExpr{ + X: &ast.Ident{Name: "west"}, + Sel: &ast.Ident{Name: "WithCurrentInstance"}, + }, + Args: []ast.Expr{ + &ast.FuncLit{ + Type: &ast.FuncType{ + Params: &ast.FieldList{ + List: []*ast.Field{ + { + Names: []*ast.Ident{instanceVar}, + Type: instancePtrTy, + }, + }, + }, + Results: &ast.FieldList{ + List: []*ast.Field{ + { + Type: &ast.Ident{Name: "error"}, + }, + }, + }, + }, + Body: &ast.BlockStmt{ + List: []ast.Stmt{ + &ast.ReturnStmt{ + Results: []ast.Expr{ + &ast.CallExpr{ + Fun: &ast.SelectorExpr{ + X: instanceVar, + Sel: &ast.Ident{Name: "Call"}, + }, + Args: append( + []ast.Expr{ + &ast.BasicLit{Kind: token.STRING, Value: fmt.Sprintf(`"%s"`, instance)}, + &ast.BasicLit{Kind: token.STRING, Value: fmt.Sprintf(`"%s"`, name)}, + }, + callArgs..., + ), + }, + }, + }, + }, + }, + }, + }, + }, + }, + }, + Cond: &ast.BinaryExpr{ + X: errVar, + Op: token.NEQ, + Y: &ast.Ident{Name: "nil"}, + }, + Body: &ast.BlockStmt{ + List: []ast.Stmt{ + &ast.ExprStmt{ + X: &ast.CallExpr{ + Fun: &ast.CallExpr{ + Fun: &ast.SelectorExpr{ + X: &ast.Ident{Name: "west"}, + Sel: &ast.Ident{Name: "CurrentErrorHandler"}, + }, + }, + Args: []ast.Expr{ + errVar, + }, + }, + }, + }, + }, + }, + &ast.ReturnStmt{}, + }, + } + + i := sort.Search(len(wasmImports), func(i int) bool { + if instance == wasmImports[i].instance { + return name <= wasmImports[i].name + } + return instance <= wasmImports[i].instance + }) + wi := wasmImport{ + instance: instance, + name: name, + decl: decl, + } + if i < len(wasmImports) { + wasmImports = append(wasmImports[:i], append([]wasmImport{wi}, wasmImports[i:]...)...) + } else if i == len(wasmImports) { + wasmImports = append(wasmImports, wi) + } + } + } + } + if len(wasmImports) == 0 { + log.Println("no `wasmimport` directives found, skip generation") + return nil + } + name := *pkgName + if name == "" { + name = pkg.Name + if pkg.Name != "main" { + name = fmt.Sprintf("%s_test", pkg.Name) + } + } + importSpecs := []*ast.ImportSpec{ + { + Path: &ast.BasicLit{Kind: token.STRING, Value: `"runtime"`}, + }, + { + Path: &ast.BasicLit{Kind: token.STRING, Value: `"unsafe"`}, + }, + { + Name: &ast.Ident{Name: "west"}, + Path: &ast.BasicLit{Kind: token.STRING, Value: `"github.com/rvolosatovs/west/go"`}, + }, + } + for path, name := range goImports { + importSpecs = append(importSpecs, &ast.ImportSpec{ + Name: name, + Path: &ast.BasicLit{Kind: token.STRING, Value: fmt.Sprintf(`"%s"`, path)}, + }) + } + importGenSpecs := make([]ast.Spec, len(importSpecs)) + for i := range importSpecs { + importGenSpecs[i] = importSpecs[i] + } + decls := []ast.Decl{ + &ast.GenDecl{ + Tok: token.IMPORT, + Specs: importGenSpecs, + }, + &ast.GenDecl{ + Tok: token.CONST, + Specs: []ast.Spec{ + &ast.ValueSpec{ + Names: []*ast.Ident{{Name: "_"}}, + Type: &ast.Ident{Name: "string"}, + Values: []ast.Expr{ + &ast.SelectorExpr{ + X: &ast.Ident{Name: "runtime"}, + Sel: &ast.Ident{Name: "Compiler"}, + }, + }, + }, + }, + }, + &ast.GenDecl{ + Tok: token.VAR, + Specs: []ast.Spec{ + &ast.ValueSpec{ + Names: []*ast.Ident{{Name: "_"}}, + Type: unsafePointerTy, + }, + }, + }, + } + for _, wi := range wasmImports { + decls = append(decls, wi.decl) + } + var buf bytes.Buffer + buf.WriteString("// Code generated by west-bindgen-go DO NOT EDIT\n\n") + f := &ast.File{ + Name: &ast.Ident{Name: name}, + Imports: importSpecs, + Decls: decls, + } + ast.SortImports(pkg.Fset, f) + write := printer.Fprint + if *gofmt { + write = format.Node + } + if err := write(&buf, pkg.Fset, f); err != nil { + return fmt.Errorf("failed to write AST: %w", err) + } + b := buf.Bytes() + if *gofmt { + b, err = format.Source(b) + if err != nil { + return fmt.Errorf("failed to format generated code: %w", err) + } + } + + _, err = file.Write(b) + if err != nil { + return fmt.Errorf("failed to write file: %w", err) + } + return nil +} + +func run() error { + args := flag.Args() + if len(args) == 0 { + args = []string{"."} + } + for _, path := range args { + if err := generate(path); err != nil { + return fmt.Errorf("failed to generate bindings for `%s`:\n%w", path, err) + } + } + return nil +} + +func main() { + if err := run(); err != nil { + log.Fatalf("failed to run: %s", err) + } +} diff --git a/go/go.mod b/go/go.mod new file mode 100644 index 0000000..6798b10 --- /dev/null +++ b/go/go.mod @@ -0,0 +1,15 @@ +module github.com/rvolosatovs/west/go + +go 1.23.0 + +require 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 + github.com/stretchr/testify v1.9.0 // indirect + github.com/ydnar/wasm-tools-go v0.1.5 // indirect + golang.org/x/mod v0.20.0 // indirect + golang.org/x/sync v0.8.0 // indirect + gopkg.in/yaml.v3 v3.0.1 // indirect +) diff --git a/go/go.sum b/go/go.sum new file mode 100644 index 0000000..49fa4f3 --- /dev/null +++ b/go/go.sum @@ -0,0 +1,17 @@ +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/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= +golang.org/x/tools v0.24.0/go.mod h1:YhNqVBIfWHdzvTLs0d8LCuMhkKUgSUKldakyV7W/WDQ= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/go/internal/tests/sync/bindings/.gitkeep b/go/internal/tests/sync/bindings/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/go/internal/tests/sync/sync.go b/go/internal/tests/sync/sync.go new file mode 100644 index 0000000..589a7b5 --- /dev/null +++ b/go/internal/tests/sync/sync.go @@ -0,0 +1,8 @@ +//go:generate go run github.com/ydnar/wasm-tools-go/cmd/wit-bindgen-go@v0.1.5 generate -w guest -o bindings ../../../../tests/wit/sync +//go:generate go run ../../../cmd/west-bindgen-go + +package sync + +import ( + _ "github.com/rvolosatovs/west/go/internal/tests/sync/bindings/west-test/sync/sync" +) diff --git a/go/internal/tests/sync/sync_test.go b/go/internal/tests/sync/sync_test.go new file mode 100644 index 0000000..e318b31 --- /dev/null +++ b/go/internal/tests/sync/sync_test.go @@ -0,0 +1,834 @@ +//go:generate cargo build -p sync-test-component --target wasm32-wasip1 +//go:generate cp ../../../../target/wasm32-wasip1/debug/sync_test_component.wasm component.wasm + +package sync_test + +import ( + _ "embed" + "log" + stdsync "sync" + "testing" + "unsafe" + + west "github.com/rvolosatovs/west/go" + "github.com/rvolosatovs/west/go/internal/tests/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) + + instance, err := west.NewInstance(&west.Config{ + Wasm: component, + }) + if err != nil { + log.Fatalf("failed to construct new instance: %s", err) + } + west.SetInstance(instance) +} + +func TestIdentityBool(t *testing.T) { + west.RunTest(t, func() { + assert.Equal(t, true, + sync.IdentityBool(true), + ) + }) +} + +func TestIdentityU8(t *testing.T) { + west.RunTest(t, func() { + assert.Equal(t, uint8(42), + sync.IdentityU8(42), + ) + }) +} + +func TestIdentityU16(t *testing.T) { + west.RunTest(t, func() { + assert.Equal(t, uint16(42), + sync.IdentityU16(42), + ) + }) +} + +func TestIdentityU32(t *testing.T) { + west.RunTest(t, func() { + assert.Equal(t, uint32(42), + sync.IdentityU32(42), + ) + }) +} + +func TestIdentityU64(t *testing.T) { + west.RunTest(t, func() { + assert.Equal(t, uint64(42), + sync.IdentityU64(42), + ) + }) +} + +func TestIdentityS8(t *testing.T) { + west.RunTest(t, func() { + assert.Equal(t, int8(-42), + sync.IdentityS8(-42), + ) + }) +} + +func TestIdentityS16(t *testing.T) { + west.RunTest(t, func() { + assert.Equal(t, int16(-42), + sync.IdentityS16(-42), + ) + }) +} + +func TestIdentityS32(t *testing.T) { + west.RunTest(t, func() { + assert.Equal(t, int32(-42), + sync.IdentityS32(-42), + ) + }) +} + +func TestIdentityS64(t *testing.T) { + west.RunTest(t, func() { + assert.Equal(t, int64(-42), + sync.IdentityS64(-42), + ) + }) +} + +func TestIdentityF32(t *testing.T) { + west.RunTest(t, func() { + assert.Equal(t, float32(-42.42), + sync.IdentityF32(-42.42), + ) + }) +} + +func TestIdentityF64(t *testing.T) { + west.RunTest(t, func() { + assert.Equal(t, float64(-42.42), + sync.IdentityF64(-42.42), + ) + }) +} + +func TestIdentityChar(t *testing.T) { + west.RunTest(t, func() { + assert.Equal(t, '🤡', + sync.IdentityChar('🤡'), + ) + }) +} + +func TestIdentityString(t *testing.T) { + t.Run("empty", func(t *testing.T) { + west.RunTest(t, func() { + assert.Equal(t, "", + sync.IdentityString(""), + ) + }) + }) + t.Run("foo", func(t *testing.T) { + west.RunTest(t, func() { + assert.Equal(t, "foo", + sync.IdentityString("foo"), + ) + }) + }) +} + +func TestIdentityFlags(t *testing.T) { + t.Run("a", func(t *testing.T) { + west.RunTest(t, func() { + assert.Equal(t, sync.AbcA, + sync.IdentityFlags(sync.AbcA), + ) + }) + }) + t.Run("c", func(t *testing.T) { + west.RunTest(t, func() { + assert.Equal(t, sync.AbcC, + sync.IdentityFlags(sync.AbcC), + ) + }) + }) + t.Run("a|c", func(t *testing.T) { + west.RunTest(t, func() { + assert.Equal(t, sync.AbcA|sync.AbcC, + sync.IdentityFlags(sync.AbcA|sync.AbcC), + ) + }) + }) + t.Run("a|b|c", func(t *testing.T) { + west.RunTest(t, func() { + assert.Equal(t, sync.AbcA|sync.AbcB|sync.AbcC, + sync.IdentityFlags(sync.AbcA|sync.AbcB|sync.AbcC), + ) + }) + }) +} + +func TestIdentityEnum(t *testing.T) { + t.Run("foo", func(t *testing.T) { + west.RunTest(t, func() { + assert.Equal(t, sync.FoobarFoo, + sync.IdentityEnum(sync.FoobarFoo), + ) + }) + }) + t.Run("bar", func(t *testing.T) { + west.RunTest(t, func() { + assert.Equal(t, sync.FoobarBar, + sync.IdentityEnum(sync.FoobarBar), + ) + }) + }) +} + +func TestIdentityVariant(t *testing.T) { + t.Run("empty", func(t *testing.T) { + west.RunTest(t, func() { + assert.Equal(t, sync.VarEmpty(), + sync.IdentityVariant(sync.VarEmpty()), + ) + }) + }) + t.Run("var", func(t *testing.T) { + t.Run("empty", func(t *testing.T) { + west.RunTest(t, func() { + expected := sync.VarVar(sync.Rec{}) + assert.Equal(t, expected, + sync.IdentityVariant(expected), + ) + }) + }) + t.Run("foo", func(t *testing.T) { + west.RunTest(t, func() { + expected := sync.VarVar(sync.Rec{ + Nested: sync.RecNested{ + Foo: "foo", + }, + }) + assert.Equal(t, expected, + sync.IdentityVariant(expected), + ) + }) + }) + }) +} + +func TestIdentityOptionString(t *testing.T) { + t.Run("none", func(t *testing.T) { + west.RunTest(t, func() { + expected := cm.None[string]() + assert.Equal(t, expected, + sync.IdentityOptionString(expected), + ) + }) + }) + t.Run("some('')", func(t *testing.T) { + west.RunTest(t, func() { + expected := cm.Some("") + assert.Equal(t, expected, + sync.IdentityOptionString(expected), + ) + }) + }) + t.Run("some(foo)", func(t *testing.T) { + west.RunTest(t, func() { + expected := cm.Some("foo") + assert.Equal(t, expected, + sync.IdentityOptionString(expected), + ) + }) + }) + t.Run("some(foobar)", func(t *testing.T) { + west.RunTest(t, func() { + expected := cm.Some("foobar") + assert.Equal(t, expected, + sync.IdentityOptionString(expected), + ) + }) + }) +} + +func TestIdentityResultString(t *testing.T) { + t.Run("ok('')", func(t *testing.T) { + west.RunTest(t, func() { + expected := cm.OK[cm.Result[string, string, struct{}]]("") + assert.Equal(t, expected, + sync.IdentityResultString(expected), + ) + }) + }) + t.Run("ok(foo)", func(t *testing.T) { + west.RunTest(t, func() { + expected := cm.OK[cm.Result[string, string, struct{}]]("foo") + assert.Equal(t, expected, + sync.IdentityResultString(expected), + ) + }) + }) + t.Run("err", func(t *testing.T) { + west.RunTest(t, func() { + expected := cm.Err[cm.Result[string, string, struct{}]](struct{}{}) + assert.Equal(t, expected, + sync.IdentityResultString(expected), + ) + }) + }) +} + +func TestIdentityRecordPrimitives(t *testing.T) { + west.RunTest(t, func() { + expected := sync.Primitives{ + A: 1, B: 2, C: 3, D: 4, E: 5, F: 6, G: 7, H: 8, I: 9, J: 10, K: true, L: '🤡', M: "test", + } + assert.Equal(t, expected, + sync.IdentityRecordPrimitives(expected), + ) + }) +} + +func TestIdentityRecordRec(t *testing.T) { + t.Run("empty", func(t *testing.T) { + west.RunTest(t, func() { + expected := sync.Rec{} + assert.Equal(t, expected, + sync.IdentityRecordRec(expected), + ) + }) + }) + t.Run("foo", func(t *testing.T) { + west.RunTest(t, func() { + expected := sync.Rec{ + Nested: sync.RecNested{ + Foo: "foo", + }, + } + assert.Equal(t, expected, + sync.IdentityRecordRec(expected), + ) + }) + }) +} + +func TestIdentityTuple(t *testing.T) { + west.RunTest(t, func() { + expected := cm.Tuple13[uint8, uint16, uint32, uint64, int8, int16, int32, int64, float32, float64, bool, rune, string]{ + F0: 1, F1: 2, F2: 3, F3: 4, F4: 5, F5: 6, F6: 7, F7: 8, F8: 9, F9: 10, F10: true, F11: '🤡', F12: "test", + } + assert.Equal(t, + sync.IdentityTuple(expected), + expected, + ) + }) +} + +func TestIdentityListBool(t *testing.T) { + t.Run("[]", func(t *testing.T) { + west.RunTest(t, func() { + assert.Equal(t, []bool(nil), + sync.IdentityListBool(cm.NewList[bool](nil, 0)).Slice(), + ) + }) + }) + t.Run("[true false true]", func(t *testing.T) { + west.RunTest(t, func() { + expected := []bool{true, false, true} + assert.Equal(t, expected, + sync.IdentityListBool(cm.NewList(unsafe.SliceData(expected), 3)).Slice(), + ) + }) + }) +} + +func TestIdentityListU16(t *testing.T) { + t.Run("[]", func(t *testing.T) { + west.RunTest(t, func() { + assert.Equal(t, []uint16(nil), + sync.IdentityListU16(cm.NewList[uint16](nil, 0)).Slice(), + ) + }) + }) + t.Run("[1 2 3 4]", func(t *testing.T) { + west.RunTest(t, func() { + expected := []uint16{1, 2, 3, 4} + assert.Equal(t, expected, + sync.IdentityListU16(cm.NewList(unsafe.SliceData(expected), 4)).Slice(), + ) + }) + }) +} + +func TestIdentityListString(t *testing.T) { + t.Run("[]", func(t *testing.T) { + west.RunTest(t, func() { + assert.Equal(t, []string(nil), + sync.IdentityListString(cm.NewList[string](nil, 0)).Slice(), + ) + }) + }) + t.Run("[foo bar baz]", func(t *testing.T) { + west.RunTest(t, func() { + expected := []string{"foo", "bar", "baz"} + assert.Equal(t, expected, + sync.IdentityListString(cm.NewList(unsafe.SliceData(expected), 3)).Slice(), + ) + }) + }) +} + +func TestIdentityListEnum(t *testing.T) { + t.Run("[]", func(t *testing.T) { + west.RunTest(t, func() { + assert.Equal(t, []sync.Foobar(nil), + sync.IdentityListEnum(cm.NewList[sync.Foobar](nil, 0)).Slice(), + ) + }) + }) + t.Run("[foo]", func(t *testing.T) { + west.RunTest(t, func() { + expected := []sync.Foobar{sync.FoobarFoo} + assert.Equal(t, expected, + sync.IdentityListEnum(cm.NewList(unsafe.SliceData(expected), 1)).Slice(), + ) + }) + }) + t.Run("[foo bar foo]", func(t *testing.T) { + west.RunTest(t, func() { + expected := []sync.Foobar{sync.FoobarFoo, sync.FoobarBar, sync.FoobarFoo} + assert.Equal(t, expected, + sync.IdentityListEnum(cm.NewList(unsafe.SliceData(expected), 3)).Slice(), + ) + }) + }) +} + +func TestIdentityListFlags(t *testing.T) { + t.Run("[]", func(t *testing.T) { + west.RunTest(t, func() { + assert.Equal(t, []sync.Abc(nil), + sync.IdentityListFlags(cm.NewList[sync.Abc](nil, 0)).Slice(), + ) + }) + }) + t.Run("[a]", func(t *testing.T) { + west.RunTest(t, func() { + expected := []sync.Abc{sync.AbcA} + assert.Equal(t, expected, + sync.IdentityListFlags(cm.NewList(unsafe.SliceData(expected), 1)).Slice(), + ) + }) + }) + t.Run("[b]", func(t *testing.T) { + west.RunTest(t, func() { + expected := []sync.Abc{sync.AbcB} + assert.Equal(t, expected, + sync.IdentityListFlags(cm.NewList(unsafe.SliceData(expected), 1)).Slice(), + ) + }) + }) + t.Run("[a|b]", func(t *testing.T) { + west.RunTest(t, func() { + expected := []sync.Abc{sync.AbcA | sync.AbcB} + assert.Equal(t, expected, + sync.IdentityListFlags(cm.NewList(unsafe.SliceData(expected), 1)).Slice(), + ) + }) + }) + t.Run("[a a]", func(t *testing.T) { + west.RunTest(t, func() { + expected := []sync.Abc{sync.AbcA, sync.AbcA} + assert.Equal(t, expected, + sync.IdentityListFlags(cm.NewList(unsafe.SliceData(expected), 2)).Slice(), + ) + }) + }) + t.Run("[a a|c a|b|c]", func(t *testing.T) { + west.RunTest(t, func() { + expected := []sync.Abc{sync.AbcA, sync.AbcA | sync.AbcC, sync.AbcA | sync.AbcB | sync.AbcC} + assert.Equal(t, expected, + sync.IdentityListFlags(cm.NewList(unsafe.SliceData(expected), 3)).Slice(), + ) + }) + }) +} + +func TestIdentityListRecordPrimitives(t *testing.T) { + t.Run("[]", func(t *testing.T) { + west.RunTest(t, func() { + assert.Equal(t, []sync.Primitives(nil), + sync.IdentityListRecordPrimitives(cm.NewList[sync.Primitives](nil, 0)).Slice(), + ) + }) + }) + t.Run("1", func(t *testing.T) { + west.RunTest(t, func() { + expected := []sync.Primitives{ + { + A: 1, B: 2, C: 3, D: 4, E: 5, F: 6, G: 7, H: 8, I: 9, J: 10, K: true, L: '🤡', M: "test", + }, + } + assert.Equal(t, expected, + sync.IdentityListRecordPrimitives(cm.NewList(unsafe.SliceData(expected), 1)).Slice(), + ) + }) + }) + t.Run("3", func(t *testing.T) { + west.RunTest(t, func() { + expected := []sync.Primitives{ + { + A: 1, B: 2, C: 3, D: 4, E: 5, F: 6, G: 7, H: 8, I: 9, J: 10, K: true, L: '🤡', M: "test", + }, + {}, + { + A: 1, B: 2, C: 3, D: 4, E: 5, F: 6, G: 7, H: 8, I: 9, J: 10, K: false, L: 'a', M: "foobar", + }, + } + assert.Equal(t, expected, + sync.IdentityListRecordPrimitives(cm.NewList(unsafe.SliceData(expected), 3)).Slice(), + ) + }) + }) +} + +func TestIdentityListVariant(t *testing.T) { + t.Run("[]", func(t *testing.T) { + west.RunTest(t, func() { + assert.Equal(t, []sync.Var(nil), + sync.IdentityListVariant(cm.NewList[sync.Var](nil, 0)).Slice(), + ) + }) + }) + t.Run("[empty]", func(t *testing.T) { + west.RunTest(t, func() { + expected := []sync.Var{sync.VarEmpty()} + assert.Equal(t, expected, + sync.IdentityListVariant(cm.NewList(unsafe.SliceData(expected), 1)).Slice(), + ) + }) + }) + t.Run("[var(empty)]", func(t *testing.T) { + west.RunTest(t, func() { + expected := []sync.Var{sync.VarVar(sync.Rec{})} + assert.Equal(t, expected, + sync.IdentityListVariant(cm.NewList(unsafe.SliceData(expected), 1)).Slice(), + ) + }) + }) + t.Run("[var(foo)]", func(t *testing.T) { + west.RunTest(t, func() { + expected := []sync.Var{sync.VarVar(sync.Rec{ + Nested: sync.RecNested{ + Foo: "foo", + }, + })} + assert.Equal(t, expected, + sync.IdentityListVariant(cm.NewList(unsafe.SliceData(expected), 1)).Slice(), + ) + }) + }) + t.Run("[var(foo), empty]", func(t *testing.T) { + west.RunTest(t, func() { + expected := []sync.Var{ + sync.VarVar(sync.Rec{ + Nested: sync.RecNested{ + Foo: "foo", + }, + }), + sync.VarEmpty(), + } + assert.Equal(t, expected, + sync.IdentityListVariant(cm.NewList(unsafe.SliceData(expected), 2)).Slice(), + ) + }) + }) + t.Run("[var(foo), empty, var(bar), var(empty), var(baz)]", func(t *testing.T) { + west.RunTest(t, func() { + expected := []sync.Var{ + sync.VarVar(sync.Rec{ + Nested: sync.RecNested{ + Foo: "foo", + }, + }), + sync.VarEmpty(), + sync.VarVar(sync.Rec{ + Nested: sync.RecNested{ + Foo: "bar", + }, + }), + sync.VarVar(sync.Rec{}), + sync.VarVar(sync.Rec{ + Nested: sync.RecNested{ + Foo: "baz", + }, + }), + } + assert.Equal(t, expected, + sync.IdentityListVariant(cm.NewList(unsafe.SliceData(expected), 5)).Slice(), + ) + }) + }) +} + +func TestIdentityListOptionString(t *testing.T) { + t.Run("[]", func(t *testing.T) { + west.RunTest(t, func() { + assert.Equal(t, []cm.Option[string](nil), + sync.IdentityListOptionString(cm.NewList[cm.Option[string]](nil, 0)).Slice(), + ) + }) + }) + t.Run("[none]", func(t *testing.T) { + west.RunTest(t, func() { + expected := []cm.Option[string]{cm.None[string]()} + assert.Equal(t, expected, + sync.IdentityListOptionString(cm.NewList(unsafe.SliceData(expected), 1)).Slice(), + ) + }) + }) + t.Run("[some(foo)]", func(t *testing.T) { + west.RunTest(t, func() { + expected := []cm.Option[string]{cm.Some("foo")} + assert.Equal(t, expected, + sync.IdentityListOptionString(cm.NewList(unsafe.SliceData(expected), 1)).Slice(), + ) + }) + }) + t.Run("[some(foo) some(bar)]", func(t *testing.T) { + west.RunTest(t, func() { + expected := []cm.Option[string]{ + cm.Some("foo"), + cm.Some("bar"), + } + assert.Equal(t, expected, + sync.IdentityListOptionString(cm.NewList(unsafe.SliceData(expected), 2)).Slice(), + ) + }) + }) + t.Run("[none none]", func(t *testing.T) { + west.RunTest(t, func() { + expected := []cm.Option[string]{ + cm.None[string](), + cm.None[string](), + } + assert.Equal(t, expected, + sync.IdentityListOptionString(cm.NewList(unsafe.SliceData(expected), 2)).Slice(), + ) + }) + }) + t.Run("[some(foobar) none]", func(t *testing.T) { + west.RunTest(t, func() { + expected := []cm.Option[string]{ + cm.Some("foo"), + cm.None[string](), + } + assert.Equal(t, expected, + sync.IdentityListOptionString(cm.NewList(unsafe.SliceData(expected), 2)).Slice(), + ) + }) + }) + t.Run("[none some(foo)]", func(t *testing.T) { + west.RunTest(t, func() { + expected := []cm.Option[string]{ + cm.None[string](), + cm.Some("foo"), + } + assert.Equal(t, expected, + sync.IdentityListOptionString(cm.NewList(unsafe.SliceData(expected), 2)).Slice(), + ) + }) + }) + t.Run("[none none none]", func(t *testing.T) { + west.RunTest(t, func() { + expected := []cm.Option[string]{ + cm.None[string](), + cm.None[string](), + cm.None[string](), + } + assert.Equal(t, expected, + sync.IdentityListOptionString(cm.NewList(unsafe.SliceData(expected), 3)).Slice(), + ) + }) + }) + t.Run("[none some(foo) some('') none]", func(t *testing.T) { + west.RunTest(t, func() { + expected := []cm.Option[string]{ + cm.None[string](), + cm.Some("foo"), + cm.Some(""), + cm.None[string](), + } + assert.Equal(t, expected, + sync.IdentityListOptionString(cm.NewList(unsafe.SliceData(expected), 4)).Slice(), + ) + }) + }) + t.Run("[none some(foo) some('') none some(bar) some(baz) none some('')]", func(t *testing.T) { + west.RunTest(t, func() { + expected := []cm.Option[string]{ + cm.None[string](), + cm.Some("foo"), + cm.Some(""), + cm.None[string](), + cm.Some("bar"), + cm.Some("baz"), + cm.None[string](), + cm.Some(""), + } + assert.Equal(t, expected, + sync.IdentityListOptionString(cm.NewList(unsafe.SliceData(expected), 8)).Slice(), + ) + }) + }) +} + +func TestIdentityListResultString(t *testing.T) { + t.Run("[]", func(t *testing.T) { + west.RunTest(t, func() { + assert.Equal(t, []cm.Result[string, string, struct{}](nil), + sync.IdentityListResultString(cm.NewList[cm.Result[string, string, struct{}]](nil, 0)).Slice(), + ) + }) + }) + t.Run("[err]", func(t *testing.T) { + west.RunTest(t, func() { + expected := []cm.Result[string, string, struct{}]{cm.Err[cm.Result[string, string, struct{}]](struct{}{})} + assert.Equal(t, expected, + sync.IdentityListResultString(cm.NewList(unsafe.SliceData(expected), 1)).Slice(), + ) + }) + }) + t.Run("[ok(foo)]", func(t *testing.T) { + west.RunTest(t, func() { + expected := []cm.Result[string, string, struct{}]{cm.OK[cm.Result[string, string, struct{}]]("foo")} + assert.Equal(t, expected, + sync.IdentityListResultString(cm.NewList(unsafe.SliceData(expected), 1)).Slice(), + ) + }) + }) + t.Run("[ok(foo) ok(bar)]", func(t *testing.T) { + west.RunTest(t, func() { + expected := []cm.Result[string, string, struct{}]{ + cm.OK[cm.Result[string, string, struct{}]]("foo"), + cm.OK[cm.Result[string, string, struct{}]]("bar"), + } + assert.Equal(t, expected, + sync.IdentityListResultString(cm.NewList(unsafe.SliceData(expected), 2)).Slice(), + ) + }) + }) + t.Run("[ok(foo) ok(bar) err]", func(t *testing.T) { + west.RunTest(t, func() { + expected := []cm.Result[string, string, struct{}]{ + cm.OK[cm.Result[string, string, struct{}]]("foo"), + cm.OK[cm.Result[string, string, struct{}]]("bar"), + cm.Err[cm.Result[string, string, struct{}]](struct{}{}), + } + assert.Equal(t, expected, + sync.IdentityListResultString(cm.NewList(unsafe.SliceData(expected), 3)).Slice(), + ) + }) + }) + t.Run("[ok(foo) ok(bar) err ok() ok() err ok(baz)]", func(t *testing.T) { + west.RunTest(t, func() { + expected := []cm.Result[string, string, struct{}]{ + cm.OK[cm.Result[string, string, struct{}]]("foo"), + cm.OK[cm.Result[string, string, struct{}]]("bar"), + cm.Err[cm.Result[string, string, struct{}]](struct{}{}), + cm.OK[cm.Result[string, string, struct{}]](""), + cm.OK[cm.Result[string, string, struct{}]](""), + cm.Err[cm.Result[string, string, struct{}]](struct{}{}), + cm.OK[cm.Result[string, string, struct{}]]("baz"), + } + assert.Equal(t, expected, + sync.IdentityListResultString(cm.NewList(unsafe.SliceData(expected), 7)).Slice(), + ) + }) + }) +} + +func TestIdentityListListString(t *testing.T) { + t.Run("[]", func(t *testing.T) { + west.RunTest(t, func() { + assert.Equal(t, []cm.List[string](nil), + sync.IdentityListListString(cm.NewList[cm.List[string]](nil, 0)).Slice(), + ) + }) + }) + t.Run("[[foo bar][baz]]", func(t *testing.T) { + west.RunTest(t, func() { + expected := []cm.List[string]{ + cm.NewList( + unsafe.SliceData([]string{"foo", "bar"}), + 2, + ), + cm.NewList( + unsafe.SliceData([]string{"baz"}), + 1, + ), + } + assert.Equal(t, expected, + sync.IdentityListListString(cm.NewList(unsafe.SliceData(expected), 2)).Slice(), + ) + }) + }) + t.Run("[[foo '' bar][]['']]", func(t *testing.T) { + west.RunTest(t, func() { + expected := []cm.List[string]{ + cm.NewList( + unsafe.SliceData([]string{"foo", "", "bar"}), + 3, + ), + cm.NewList[string]( + nil, + 0, + ), + cm.NewList( + unsafe.SliceData([]string{""}), + 1, + ), + } + assert.Equal(t, expected, + sync.IdentityListListString(cm.NewList(unsafe.SliceData(expected), 3)).Slice(), + ) + }) + }) +} + +func TestIdentityPrimitives(t *testing.T) { + west.RunTest(t, func() { + assert.Equal(t, + sync.IdentityPrimitives(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, true, '🤡', "test"), + cm.Tuple13[uint8, uint16, uint32, uint64, int8, int16, int32, int64, float32, float64, bool, rune, string]{ + F0: 1, F1: 2, F2: 3, F3: 4, F4: 5, F5: 6, F6: 7, F7: 8, F8: 9, F9: 10, F10: true, F11: '🤡', F12: "test", + }) + }) +} + +func TestRes(t *testing.T) { + west.RunTest(t, func() { + res := sync.NewRes() + assert.Equal(t, res.Foo(), "foo") + assert.Equal(t, res.Foo(), "foo") + assert.Equal(t, res.Foo(), "foo") + res.ResourceDrop() + + for _, res := range sync.ResMakeList().Slice() { + assert.Equal(t, res.Foo(), "foo") + assert.Equal(t, res.Foo(), "foo") + assert.Equal(t, res.Foo(), "foo") + res.ResourceDrop() + } + }) +} diff --git a/go/internal/tests/wasi/bindings/.gitkeep b/go/internal/tests/wasi/bindings/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/go/internal/tests/wasi/wasi.go b/go/internal/tests/wasi/wasi.go new file mode 100644 index 0000000..f1b8e8d --- /dev/null +++ b/go/internal/tests/wasi/wasi.go @@ -0,0 +1,64 @@ +//go:generate go run github.com/ydnar/wasm-tools-go/cmd/wit-bindgen-go@v0.1.5 generate -w service -o bindings ./wit + +package wasi + +import ( + "log/slog" + "unsafe" + + incominghandler "github.com/rvolosatovs/west/go/internal/tests/wasi/bindings/wasi/http/incoming-handler" + "github.com/rvolosatovs/west/go/internal/tests/wasi/bindings/wasi/http/types" + "github.com/ydnar/wasm-tools-go/cm" +) + +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") + res := 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"))) + } + 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]](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()) + 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/go/internal/tests/wasi/wasi_test.go b/go/internal/tests/wasi/wasi_test.go new file mode 100644 index 0000000..96a06d7 --- /dev/null +++ b/go/internal/tests/wasi/wasi_test.go @@ -0,0 +1,102 @@ +//go:generate go run ../../../cmd/west-bindgen-go + +package wasi_test + +import ( + "testing" + "unsafe" + + west "github.com/rvolosatovs/west/go" + _ "github.com/rvolosatovs/west/go/bindings" + testtypes "github.com/rvolosatovs/west/go/bindings/wasi/http/types" + httptest "github.com/rvolosatovs/west/go/bindings/west/test/http-test" + incominghandler "github.com/rvolosatovs/west/go/internal/tests/wasi/bindings/wasi/http/incoming-handler" + "github.com/rvolosatovs/west/go/internal/tests/wasi/bindings/wasi/http/types" + "github.com/stretchr/testify/assert" + "github.com/ydnar/wasm-tools-go/cm" +) + +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 := httptest.NewResponseOutparam() + incominghandler.Exports.Handle( + types.IncomingRequest(httptest.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/go/internal/tests/wasi/wit/app.wit b/go/internal/tests/wasi/wit/app.wit new file mode 100644 index 0000000..8448761 --- /dev/null +++ b/go/internal/tests/wasi/wit/app.wit @@ -0,0 +1,10 @@ +package west-test:wasi; + +world service { + export wasi:http/incoming-handler@0.2.0; + + // Import all CLI interfaces, which are used by Go libraries + include wasi:cli/imports@0.2.0; + + import west-test:fib/fib; +} diff --git a/go/internal/tests/wasi/wit/deps.lock b/go/internal/tests/wasi/wit/deps.lock new file mode 100644 index 0000000..853fd59 --- /dev/null +++ b/go/internal/tests/wasi/wit/deps.lock @@ -0,0 +1,34 @@ +[cli] +sha256 = "285865a31d777181b075f39e92bcfe59c89cd6bacce660be1b9a627646956258" +sha512 = "da2622210a9e3eea82b99f1a5b8a44ce5443d009cb943f7bca0bf9cf4360829b289913d7ee727c011f0f72994ea7dc8e661ebcc0a6b34b587297d80cd9b3f7e8" + +[clocks] +sha256 = "468b4d12892fe926b8eb5d398dbf579d566c93231fa44f415440572c695b7613" +sha512 = "e6b53a07221f1413953c9797c68f08b815fdaebf66419bbc1ea3e8b7dece73731062693634731f311a03957b268cf9cc509c518bd15e513c318aa04a8459b93a" + +[fib] +path = "../../../../../tests/wit/fib" +sha256 = "a818ecd4b5f4e3a092d747d9e69e1c706bd8ac3950dced24d8ae78f96bd5e851" +sha512 = "ad9795f9300ae1f7ab8f9dd56da5db7dafc3c15476d6c1768a56a968d9a0aeae435b9e8836405a9673b9a68e3eea8b653d6e19b4b90aba047646f3839712b5b4" + +[filesystem] +sha256 = "498c465cfd04587db40f970fff2185daa597d074c20b68a8bcbae558f261499b" +sha512 = "ead452f9b7bfb88593a502ec00d76d4228003d51c40fd0408aebc32d35c94673551b00230d730873361567cc209ec218c41fb4e95bad194268592c49e7964347" + +[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"] + +[io] +sha256 = "7210e5653539a15478f894d4da24cc69d61924cbcba21d2804d69314a88e5a4c" +sha512 = "49184a1b0945a889abd52d25271172ed3dc2db6968fcdddb1bab7ee0081f4a3eeee0977ad2291126a37631c0d86eeea75d822fa8af224c422134500bf9f0f2bb" + +[random] +sha256 = "7371d03c037d924caba2587fb2e7c5773a0d3c5fcecbf7971e0e0ba57973c53d" +sha512 = "964c4e8925a53078e4d94ba907b54f89a0b7e154f46823a505391471466c17f53c8692682e5c85771712acd88b348686173fc07c53a3cfe3d301b8cd8ddd0de4" + +[sockets] +sha256 = "622bd28bbeb43736375dc02bd003fd3a016ff8ee91e14bab488325c6b38bf966" +sha512 = "5a63c1f36de0c4548e1d2297bdbededb28721cbad94ef7825c469eae29d7451c97e00b4c1d6730ee1ec0c4a5aac922961a2795762d4a0c3bb54e30a391a84bae" diff --git a/go/internal/tests/wasi/wit/deps.toml b/go/internal/tests/wasi/wit/deps.toml new file mode 100644 index 0000000..a871561 --- /dev/null +++ b/go/internal/tests/wasi/wit/deps.toml @@ -0,0 +1,2 @@ +fib = "../../../../../tests/wit/fib" +http = "https://github.com/WebAssembly/wasi-http/archive/v0.2.0.tar.gz" diff --git a/go/internal/tests/wasi/wit/deps/cli/command.wit b/go/internal/tests/wasi/wit/deps/cli/command.wit new file mode 100644 index 0000000..d8005bd --- /dev/null +++ b/go/internal/tests/wasi/wit/deps/cli/command.wit @@ -0,0 +1,7 @@ +package wasi:cli@0.2.0; + +world command { + include imports; + + export run; +} diff --git a/go/internal/tests/wasi/wit/deps/cli/environment.wit b/go/internal/tests/wasi/wit/deps/cli/environment.wit new file mode 100644 index 0000000..7006523 --- /dev/null +++ b/go/internal/tests/wasi/wit/deps/cli/environment.wit @@ -0,0 +1,18 @@ +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. + get-environment: func() -> list>; + + /// Get the POSIX-style arguments to the program. + get-arguments: func() -> list; + + /// Return a path that programs should use as their initial current working + /// directory, interpreting `.` as shorthand for this. + initial-cwd: func() -> option; +} diff --git a/go/internal/tests/wasi/wit/deps/cli/exit.wit b/go/internal/tests/wasi/wit/deps/cli/exit.wit new file mode 100644 index 0000000..d0c2b82 --- /dev/null +++ b/go/internal/tests/wasi/wit/deps/cli/exit.wit @@ -0,0 +1,4 @@ +interface exit { + /// Exit the current instance and any linked instances. + exit: func(status: result); +} diff --git a/go/internal/tests/wasi/wit/deps/cli/imports.wit b/go/internal/tests/wasi/wit/deps/cli/imports.wit new file mode 100644 index 0000000..083b84a --- /dev/null +++ b/go/internal/tests/wasi/wit/deps/cli/imports.wit @@ -0,0 +1,20 @@ +package wasi:cli@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; + + import environment; + import exit; + import stdin; + import stdout; + import stderr; + import terminal-input; + import terminal-output; + import terminal-stdin; + import terminal-stdout; + import terminal-stderr; +} diff --git a/go/internal/tests/wasi/wit/deps/cli/run.wit b/go/internal/tests/wasi/wit/deps/cli/run.wit new file mode 100644 index 0000000..a70ee8c --- /dev/null +++ b/go/internal/tests/wasi/wit/deps/cli/run.wit @@ -0,0 +1,4 @@ +interface run { + /// Run the program. + run: func() -> result; +} diff --git a/go/internal/tests/wasi/wit/deps/cli/stdio.wit b/go/internal/tests/wasi/wit/deps/cli/stdio.wit new file mode 100644 index 0000000..31ef35b --- /dev/null +++ b/go/internal/tests/wasi/wit/deps/cli/stdio.wit @@ -0,0 +1,17 @@ +interface stdin { + use wasi:io/streams@0.2.0.{input-stream}; + + get-stdin: func() -> input-stream; +} + +interface stdout { + use wasi:io/streams@0.2.0.{output-stream}; + + get-stdout: func() -> output-stream; +} + +interface stderr { + use wasi:io/streams@0.2.0.{output-stream}; + + get-stderr: func() -> output-stream; +} diff --git a/go/internal/tests/wasi/wit/deps/cli/terminal.wit b/go/internal/tests/wasi/wit/deps/cli/terminal.wit new file mode 100644 index 0000000..38c724e --- /dev/null +++ b/go/internal/tests/wasi/wit/deps/cli/terminal.wit @@ -0,0 +1,49 @@ +/// 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. +interface terminal-input { + /// The input side of a terminal. + 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. +interface terminal-output { + /// The output side of a terminal. + resource terminal-output; +} + +/// An interface providing an optional `terminal-input` for stdin as a +/// link-time authority. +interface terminal-stdin { + use terminal-input.{terminal-input}; + + /// If stdin is connected to a terminal, return a `terminal-input` handle + /// allowing further interaction with it. + get-terminal-stdin: func() -> option; +} + +/// An interface providing an optional `terminal-output` for stdout as a +/// link-time authority. +interface terminal-stdout { + use terminal-output.{terminal-output}; + + /// If stdout is connected to a terminal, return a `terminal-output` handle + /// allowing further interaction with it. + get-terminal-stdout: func() -> option; +} + +/// An interface providing an optional `terminal-output` for stderr as a +/// link-time authority. +interface terminal-stderr { + use terminal-output.{terminal-output}; + + /// If stderr is connected to a terminal, return a `terminal-output` handle + /// allowing further interaction with it. + get-terminal-stderr: func() -> option; +} diff --git a/go/internal/tests/wasi/wit/deps/clocks/monotonic-clock.wit b/go/internal/tests/wasi/wit/deps/clocks/monotonic-clock.wit new file mode 100644 index 0000000..4e4dc3a --- /dev/null +++ b/go/internal/tests/wasi/wit/deps/clocks/monotonic-clock.wit @@ -0,0 +1,45 @@ +package wasi:clocks@0.2.0; +/// 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. +/// +/// It is intended for measuring elapsed time. +interface monotonic-clock { + use wasi:io/poll@0.2.0.{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. + type instant = u64; + + /// A duration of time, in nanoseconds. + 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. + now: func() -> instant; + + /// Query the resolution of the clock. Returns the duration of time + /// corresponding to a clock tick. + resolution: func() -> duration; + + /// Create a `pollable` which will resolve once the specified instant + /// occured. + 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. + subscribe-duration: func( + when: duration, + ) -> pollable; +} diff --git a/go/internal/tests/wasi/wit/deps/clocks/wall-clock.wit b/go/internal/tests/wasi/wit/deps/clocks/wall-clock.wit new file mode 100644 index 0000000..440ca0f --- /dev/null +++ b/go/internal/tests/wasi/wit/deps/clocks/wall-clock.wit @@ -0,0 +1,42 @@ +package wasi:clocks@0.2.0; +/// 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. +interface wall-clock { + /// A time and date in seconds plus nanoseconds. + 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 + now: func() -> datetime; + + /// Query the resolution of the clock. + /// + /// The nanoseconds field of the output is always less than 1000000000. + resolution: func() -> datetime; +} diff --git a/go/internal/tests/wasi/wit/deps/clocks/world.wit b/go/internal/tests/wasi/wit/deps/clocks/world.wit new file mode 100644 index 0000000..c022457 --- /dev/null +++ b/go/internal/tests/wasi/wit/deps/clocks/world.wit @@ -0,0 +1,6 @@ +package wasi:clocks@0.2.0; + +world imports { + import monotonic-clock; + import wall-clock; +} diff --git a/go/internal/tests/wasi/wit/deps/fib/fib.wit b/go/internal/tests/wasi/wit/deps/fib/fib.wit new file mode 100644 index 0000000..f621d77 --- /dev/null +++ b/go/internal/tests/wasi/wit/deps/fib/fib.wit @@ -0,0 +1,13 @@ +package west-test:fib; + +interface fib { + fib: func(n: u32) -> u64; +} + +world guest { + import fib; +} + +world host { + export fib; +} diff --git a/go/internal/tests/wasi/wit/deps/filesystem/preopens.wit b/go/internal/tests/wasi/wit/deps/filesystem/preopens.wit new file mode 100644 index 0000000..da801f6 --- /dev/null +++ b/go/internal/tests/wasi/wit/deps/filesystem/preopens.wit @@ -0,0 +1,8 @@ +package wasi:filesystem@0.2.0; + +interface preopens { + use types.{descriptor}; + + /// Return the set of preopened directories, and their path. + get-directories: func() -> list>; +} diff --git a/go/internal/tests/wasi/wit/deps/filesystem/types.wit b/go/internal/tests/wasi/wit/deps/filesystem/types.wit new file mode 100644 index 0000000..11108fc --- /dev/null +++ b/go/internal/tests/wasi/wit/deps/filesystem/types.wit @@ -0,0 +1,634 @@ +package wasi:filesystem@0.2.0; +/// 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 +interface types { + use wasi:io/streams@0.2.0.{input-stream, output-stream, error}; + use wasi:clocks/wall-clock@0.2.0.{datetime}; + + /// File size or length of a region within a file. + type filesize = u64; + + /// The type of a filesystem object referenced by a descriptor. + /// + /// Note: This was called `filetype` in earlier versions of WASI. + 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. + 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 integrety + /// 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. + 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. + 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`. + 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. + type link-count = u64; + + /// When setting a timestamp, this gives the value to set it to. + 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. + 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. + 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. + 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. + 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. + 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. + append-via-stream: func() -> result; + + /// Provide file advisory information on a descriptor. + /// + /// This is similar to `posix_fadvise` in POSIX. + 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. + 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. + 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. + 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. + 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. + 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. + 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. + 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. + 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. + sync: func() -> result<_, error-code>; + + /// Create a directory. + /// + /// Note: This is similar to `mkdirat` in POSIX. + 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. + 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. + 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. + 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. + 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. + 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. + 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. + 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. + 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. + 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. + 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. + 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. + 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`. + 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. + resource directory-entry-stream { + /// Read a single directory entry from a `directory-entry-stream`. + 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. + filesystem-error-code: func(err: borrow) -> option; +} diff --git a/go/internal/tests/wasi/wit/deps/filesystem/world.wit b/go/internal/tests/wasi/wit/deps/filesystem/world.wit new file mode 100644 index 0000000..663f579 --- /dev/null +++ b/go/internal/tests/wasi/wit/deps/filesystem/world.wit @@ -0,0 +1,6 @@ +package wasi:filesystem@0.2.0; + +world imports { + import types; + import preopens; +} diff --git a/go/internal/tests/wasi/wit/deps/http/handler.wit b/go/internal/tests/wasi/wit/deps/http/handler.wit new file mode 100644 index 0000000..a34a064 --- /dev/null +++ b/go/internal/tests/wasi/wit/deps/http/handler.wit @@ -0,0 +1,43 @@ +/// This interface defines a handler of incoming HTTP Requests. It should +/// be exported by components which can respond to HTTP Requests. +interface incoming-handler { + 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. + 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. +interface outgoing-handler { + 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`. + handle: func( + request: outgoing-request, + options: option + ) -> result; +} diff --git a/go/internal/tests/wasi/wit/deps/http/proxy.wit b/go/internal/tests/wasi/wit/deps/http/proxy.wit new file mode 100644 index 0000000..687c24d --- /dev/null +++ b/go/internal/tests/wasi/wit/deps/http/proxy.wit @@ -0,0 +1,32 @@ +package wasi:http@0.2.0; + +/// 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 { + /// HTTP proxies have access to time and randomness. + include wasi:clocks/imports@0.2.0; + import wasi:random/random@0.2.0; + + /// 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; + + /// 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; + + /// This is the default handler to use when user code simply wants to make an + /// HTTP request (e.g., via `fetch()`). + import outgoing-handler; + + /// 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`. + export incoming-handler; +} diff --git a/go/internal/tests/wasi/wit/deps/http/types.wit b/go/internal/tests/wasi/wit/deps/http/types.wit new file mode 100644 index 0000000..755ac6a --- /dev/null +++ b/go/internal/tests/wasi/wit/deps/http/types.wit @@ -0,0 +1,570 @@ +/// 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. +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}; + + /// This type corresponds to HTTP standard Methods. + variant method { + get, + head, + post, + put, + delete, + connect, + options, + trace, + patch, + other(string) + } + + /// This type corresponds to HTTP standard Related Schemes. + 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 + 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: + record DNS-error-payload { + rcode: option, + info-code: option + } + + /// Defines the case payload type for `TLS-alert-received` above: + record TLS-alert-received-payload { + alert-id: option, + alert-message: option + } + + /// Defines the case payload type for `HTTP-response-{header,trailer}-size` above: + 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. + 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. + 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. + 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. + 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`. + resource fields { + + /// Construct an empty HTTP Fields. + /// + /// The resulting `fields` is mutable. + 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. 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. + /// + /// An error result will be returned if any header or value was + /// syntactically invalid, or if a header was forbidden. + 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. + 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. + 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. + 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. + 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. + 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. + entries: func() -> list>; + + /// Make a deep copy of the Fields. Equivelant in behavior to calling the + /// `fields` constructor on the return value of `entries`. The resulting + /// `fields` is mutable. + clone: func() -> fields; + } + + /// Headers is an alias for Fields. + type headers = fields; + + /// Trailers is an alias for Fields. + type trailers = fields; + + /// Represents an incoming HTTP Request. + resource incoming-request { + + /// Returns the method of the incoming request. + method: func() -> method; + + /// Returns the path with query parameters from the request, as a string. + path-with-query: func() -> option; + + /// Returns the protocol scheme from the request. + scheme: func() -> option; + + /// Returns the authority from the request, if it was present. + 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. + headers: func() -> headers; + + /// Gives the `incoming-body` associated with this request. Will only + /// return success at most once, and subsequent calls will return error. + consume: func() -> result; + } + + /// Represents an outgoing HTTP Request. + 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 + ); + + /// 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; + + /// Get the Method for the Request. + 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. + 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. + 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. + 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. + 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. + 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 + /// HTTPS schemes always require an authority. + 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 + /// HTTPS schemes always require an authority. Fails if the string given is + /// not a syntactically valid uri authority. + 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 transfered to + /// another component by e.g. `outgoing-handler.handle`. + 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`. + resource request-options { + /// Construct a default `request-options` value. + constructor(); + + /// The timeout for the initial connect to the HTTP Server. + 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. + set-connect-timeout: func(duration: option) -> result; + + /// The timeout for receiving the first byte of the Response body. + 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. + set-first-byte-timeout: func(duration: option) -> result; + + /// The timeout for receiving subsequent chunks of bytes in the Response + /// body stream. + 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. + 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`. + 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. + set: static func( + param: response-outparam, + response: result, + ); + } + + /// This type corresponds to the HTTP standard Status Code. + type status-code = u16; + + /// Represents an incoming HTTP Response. + resource incoming-response { + + /// Returns the status code from the incoming response. + 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. + headers: func() -> headers; + + /// Returns the incoming body. May be called at most once. Returns error + /// if called additional times. + 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. + 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. + %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. + finish: static func(this: incoming-body) -> future-trailers; + } + + /// Represents a future which may eventaully 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 { + + /// Returns a pollable which becomes ready when either the trailers have + /// been received, or an error has occured. When this pollable is ready, + /// the `get` method will return `some`. + subscribe: func() -> pollable; + + /// Returns the contents of the trailers, or an error which occured, + /// 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 occured 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>>>; + } + + /// Represents an outgoing HTTP Response. + 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); + + /// Get the HTTP Status Code for the Response. + 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. + 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 transfered to + /// another component by e.g. `outgoing-handler.handle`. + 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. + 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 occured. The implementation should propogate 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 { + + /// 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; + + /// 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>; + } + + /// Represents a future which may eventaully 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 { + /// Returns a pollable which becomes ready when either the Response has + /// been received, or an error has occured. When this pollable is ready, + /// the `get` method will return `some`. + 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 recieved successfully, or that an error + /// occured. 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>>; + + } +} diff --git a/go/internal/tests/wasi/wit/deps/io/error.wit b/go/internal/tests/wasi/wit/deps/io/error.wit new file mode 100644 index 0000000..22e5b64 --- /dev/null +++ b/go/internal/tests/wasi/wit/deps/io/error.wit @@ -0,0 +1,34 @@ +package wasi:io@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 + /// 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`. + /// + /// The set of functions which can "downcast" an `error` into a more + /// concrete type is open. + 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. + to-debug-string: func() -> string; + } +} diff --git a/go/internal/tests/wasi/wit/deps/io/poll.wit b/go/internal/tests/wasi/wit/deps/io/poll.wit new file mode 100644 index 0000000..ddc67f8 --- /dev/null +++ b/go/internal/tests/wasi/wit/deps/io/poll.wit @@ -0,0 +1,41 @@ +package wasi:io@0.2.0; + +/// A poll API intended to let users wait for I/O events on multiple handles +/// at once. +interface poll { + /// `pollable` represents a single I/O event which may be ready, or not. + resource pollable { + + /// Return the readiness of a pollable. This function never blocks. + /// + /// Returns `true` when the pollable is ready, and `false` otherwise. + 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. + 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. + /// + /// If the list contains more elements than can be indexed with a `u32` + /// value, this function traps. + /// + /// 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 reaedy for I/O. + poll: func(in: list>) -> list; +} diff --git a/go/internal/tests/wasi/wit/deps/io/streams.wit b/go/internal/tests/wasi/wit/deps/io/streams.wit new file mode 100644 index 0000000..6d2f871 --- /dev/null +++ b/go/internal/tests/wasi/wit/deps/io/streams.wit @@ -0,0 +1,262 @@ +package wasi:io@0.2.0; + +/// 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. +interface streams { + use error.{error}; + use poll.{pollable}; + + /// An error for input-stream and output-stream operations. + 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`. + 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. + 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`. + 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. + 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`. + 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. + 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`. + 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. + 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. + 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 + /// ``` + 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. + flush: func() -> result<_, stream-error>; + + /// Request to flush buffered output, and block until flush completes + /// and stream is ready for writing again. + 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 + /// 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. + 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 + /// ``` + 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 equivelant 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( + /// 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`. + blocking-splice: func( + /// The stream to read from + src: borrow, + /// The number of bytes to splice + len: u64, + ) -> result; + } +} diff --git a/go/internal/tests/wasi/wit/deps/io/world.wit b/go/internal/tests/wasi/wit/deps/io/world.wit new file mode 100644 index 0000000..5f0b43f --- /dev/null +++ b/go/internal/tests/wasi/wit/deps/io/world.wit @@ -0,0 +1,6 @@ +package wasi:io@0.2.0; + +world imports { + import streams; + import poll; +} diff --git a/go/internal/tests/wasi/wit/deps/random/insecure-seed.wit b/go/internal/tests/wasi/wit/deps/random/insecure-seed.wit new file mode 100644 index 0000000..47210ac --- /dev/null +++ b/go/internal/tests/wasi/wit/deps/random/insecure-seed.wit @@ -0,0 +1,25 @@ +package wasi:random@0.2.0; +/// The insecure-seed interface for seeding hash-map DoS resistance. +/// +/// It is intended to be portable at least between Unix-family platforms and +/// Windows. +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. + insecure-seed: func() -> tuple; +} diff --git a/go/internal/tests/wasi/wit/deps/random/insecure.wit b/go/internal/tests/wasi/wit/deps/random/insecure.wit new file mode 100644 index 0000000..c58f4ee --- /dev/null +++ b/go/internal/tests/wasi/wit/deps/random/insecure.wit @@ -0,0 +1,22 @@ +package wasi:random@0.2.0; +/// The insecure interface for insecure pseudo-random numbers. +/// +/// It is intended to be portable at least between Unix-family platforms and +/// Windows. +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. + 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`. + get-insecure-random-u64: func() -> u64; +} diff --git a/go/internal/tests/wasi/wit/deps/random/random.wit b/go/internal/tests/wasi/wit/deps/random/random.wit new file mode 100644 index 0000000..0c017f0 --- /dev/null +++ b/go/internal/tests/wasi/wit/deps/random/random.wit @@ -0,0 +1,26 @@ +package wasi:random@0.2.0; +/// WASI Random is a random data API. +/// +/// It is intended to be portable at least between Unix-family platforms and +/// Windows. +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. + 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`. + get-random-u64: func() -> u64; +} diff --git a/go/internal/tests/wasi/wit/deps/random/world.wit b/go/internal/tests/wasi/wit/deps/random/world.wit new file mode 100644 index 0000000..3da3491 --- /dev/null +++ b/go/internal/tests/wasi/wit/deps/random/world.wit @@ -0,0 +1,7 @@ +package wasi:random@0.2.0; + +world imports { + import random; + import insecure; + import insecure-seed; +} diff --git a/go/internal/tests/wasi/wit/deps/sockets/instance-network.wit b/go/internal/tests/wasi/wit/deps/sockets/instance-network.wit new file mode 100644 index 0000000..e455d0f --- /dev/null +++ b/go/internal/tests/wasi/wit/deps/sockets/instance-network.wit @@ -0,0 +1,9 @@ + +/// This interface provides a value-export of the default network handle.. +interface instance-network { + use network.{network}; + + /// Get a handle to the default network. + instance-network: func() -> network; + +} diff --git a/go/internal/tests/wasi/wit/deps/sockets/ip-name-lookup.wit b/go/internal/tests/wasi/wit/deps/sockets/ip-name-lookup.wit new file mode 100644 index 0000000..8e639ec --- /dev/null +++ b/go/internal/tests/wasi/wit/deps/sockets/ip-name-lookup.wit @@ -0,0 +1,51 @@ + +interface ip-name-lookup { + use wasi:io/poll@0.2.0.{pollable}; + 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: + /// - + /// - + /// - + /// - + resolve-addresses: func(network: borrow, name: string) -> result; + + 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) + 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. + subscribe: func() -> pollable; + } +} diff --git a/go/internal/tests/wasi/wit/deps/sockets/network.wit b/go/internal/tests/wasi/wit/deps/sockets/network.wit new file mode 100644 index 0000000..9cadf06 --- /dev/null +++ b/go/internal/tests/wasi/wit/deps/sockets/network.wit @@ -0,0 +1,145 @@ + +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. + 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. + 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, + } + + enum ip-address-family { + /// Similar to `AF_INET` in POSIX. + ipv4, + + /// Similar to `AF_INET6` in POSIX. + ipv6, + } + + type ipv4-address = tuple; + type ipv6-address = tuple; + + variant ip-address { + ipv4(ipv4-address), + ipv6(ipv6-address), + } + + record ipv4-socket-address { + /// sin_port + port: u16, + /// sin_addr + address: ipv4-address, + } + + record ipv6-socket-address { + /// sin6_port + port: u16, + /// sin6_flowinfo + flow-info: u32, + /// sin6_addr + address: ipv6-address, + /// sin6_scope_id + scope-id: u32, + } + + variant ip-socket-address { + ipv4(ipv4-socket-address), + ipv6(ipv6-socket-address), + } + +} diff --git a/go/internal/tests/wasi/wit/deps/sockets/tcp-create-socket.wit b/go/internal/tests/wasi/wit/deps/sockets/tcp-create-socket.wit new file mode 100644 index 0000000..c7ddf1f --- /dev/null +++ b/go/internal/tests/wasi/wit/deps/sockets/tcp-create-socket.wit @@ -0,0 +1,27 @@ + +interface tcp-create-socket { + use network.{network, error-code, ip-address-family}; + 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 + /// - + /// - + /// - + /// - + create-tcp-socket: func(address-family: ip-address-family) -> result; +} diff --git a/go/internal/tests/wasi/wit/deps/sockets/tcp.wit b/go/internal/tests/wasi/wit/deps/sockets/tcp.wit new file mode 100644 index 0000000..5902b9e --- /dev/null +++ b/go/internal/tests/wasi/wit/deps/sockets/tcp.wit @@ -0,0 +1,353 @@ + +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}; + use network.{network, error-code, ip-socket-address, ip-address-family}; + + 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 a 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 { + /// 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>; + finish-bind: func() -> result<_, error-code>; + + /// Connect to a remote endpoint. + /// + /// On success: + /// - the socket is transitioned into the `connection` 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>; + 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 + /// - + /// - + /// - + /// - + start-listen: func() -> result<_, error-code>; + 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 + /// - + /// - + /// - + /// - + 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 + /// - + /// - + /// - + /// - + local-address: func() -> result; + + /// Get the remote address. + /// + /// # Typical errors + /// - `invalid-state`: The socket is not connected to a remote address. (ENOTCONN) + /// + /// # References + /// - + /// - + /// - + /// - + remote-address: func() -> result; + + /// Whether the socket is in the `listening` state. + /// + /// Equivalent to the SO_ACCEPTCONN socket option. + is-listening: func() -> bool; + + /// Whether this is a IPv4 or IPv6 socket. + /// + /// Equivalent to the SO_DOMAIN socket option. + 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. + 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. + keep-alive-enabled: func() -> result; + 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. + keep-alive-idle-time: func() -> result; + 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. + keep-alive-interval: func() -> result; + 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. + keep-alive-count: func() -> result; + 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. + hop-limit: func() -> result; + 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. + receive-buffer-size: func() -> result; + set-receive-buffer-size: func(value: u64) -> result<_, error-code>; + send-buffer-size: func() -> result; + 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 a 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; + + /// 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 a 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>; + } +} diff --git a/go/internal/tests/wasi/wit/deps/sockets/udp-create-socket.wit b/go/internal/tests/wasi/wit/deps/sockets/udp-create-socket.wit new file mode 100644 index 0000000..0482d1f --- /dev/null +++ b/go/internal/tests/wasi/wit/deps/sockets/udp-create-socket.wit @@ -0,0 +1,27 @@ + +interface udp-create-socket { + use network.{network, error-code, ip-address-family}; + 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: + /// - + /// - + /// - + /// - + create-udp-socket: func(address-family: ip-address-family) -> result; +} diff --git a/go/internal/tests/wasi/wit/deps/sockets/udp.wit b/go/internal/tests/wasi/wit/deps/sockets/udp.wit new file mode 100644 index 0000000..d987a0a --- /dev/null +++ b/go/internal/tests/wasi/wit/deps/sockets/udp.wit @@ -0,0 +1,266 @@ + +interface udp { + use wasi:io/poll@0.2.0.{pollable}; + use network.{network, error-code, ip-socket-address, ip-address-family}; + + /// A received datagram. + 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. + 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. + 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 + /// - + /// - + /// - + /// - + start-bind: func(network: borrow, local-address: ip-socket-address) -> result<_, error-code>; + 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 + /// - + /// - + /// - + /// - + %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 + /// - + /// - + /// - + /// - + 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 + /// - + /// - + /// - + /// - + remote-address: func() -> result; + + /// Whether this is a IPv4 or IPv6 socket. + /// + /// Equivalent to the SO_DOMAIN socket option. + 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. + unicast-hop-limit: func() -> result; + 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. + receive-buffer-size: func() -> result; + set-receive-buffer-size: func(value: u64) -> result<_, error-code>; + send-buffer-size: func() -> result; + 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. + subscribe: func() -> pollable; + } + + 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 + /// - + /// - + /// - + /// - + /// - + /// - + /// - + /// - + 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. + subscribe: func() -> pollable; + } + + 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 + /// - + /// - + /// - + /// - + /// - + /// - + /// - + /// - + 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. + subscribe: func() -> pollable; + } +} diff --git a/go/internal/tests/wasi/wit/deps/sockets/world.wit b/go/internal/tests/wasi/wit/deps/sockets/world.wit new file mode 100644 index 0000000..f8bb92a --- /dev/null +++ b/go/internal/tests/wasi/wit/deps/sockets/world.wit @@ -0,0 +1,11 @@ +package wasi:sockets@0.2.0; + +world imports { + import instance-network; + import network; + import udp; + import udp-create-socket; + import tcp; + import tcp-create-socket; + import ip-name-lookup; +} diff --git a/go/west.go b/go/west.go new file mode 100644 index 0000000..c1e18ad --- /dev/null +++ b/go/west.go @@ -0,0 +1,198 @@ +//go:generate cargo build -p west-sys --release +//go:generate go run github.com/ydnar/wasm-tools-go/cmd/wit-bindgen-go@v0.1.5 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" + +import ( + "errors" + "fmt" + "log" + "runtime" + "sync" + "sync/atomic" + "testing" + "unsafe" +) + +var ( + errorHandlerMu sync.RWMutex + errorHandler atomic.Value + + instanceMu sync.RWMutex + instance *Instance +) + +func init() { + errorHandler.Store(func(err error) { + log.Fatalf("failed to call instance: %s", err) + }) +} + +func setErrorHandler(f func(error)) func(error) { + return errorHandler.Swap(f).(func(error)) +} + +func SetErrorHandler(f func(error)) func(error) { + errorHandlerMu.Lock() + defer errorHandlerMu.Unlock() + return setErrorHandler(f) +} + +func WithErrorHandler(handler func(error), f func()) { + errorHandlerMu.Lock() + defer errorHandlerMu.Unlock() + + handler = setErrorHandler(handler) + defer setErrorHandler(handler) + + f() +} + +func CurrentErrorHandler() func(error) { + return errorHandler.Load().(func(error)) +} + +func WithCurrentErrorHandler(f func(func(error))) { + errorHandlerMu.RLock() + defer errorHandlerMu.RUnlock() + f(CurrentErrorHandler()) +} + +func setInstance(i *Instance) *Instance { + i, instance = instance, i + return i +} + +func SetInstance(i *Instance) *Instance { + instanceMu.Lock() + defer instanceMu.Unlock() + + return setInstance(i) +} + +func WithInstance(i *Instance, f func()) { + instanceMu.Lock() + defer instanceMu.Unlock() + + i = setInstance(i) + defer setInstance(i) + + f() +} + +func withCurrentInstance[T any](f func(*Instance) T, handleErr func(error)) T { + instanceMu.RLock() + defer instanceMu.RUnlock() + if instance == nil { + instanceMu.RUnlock() + func() { + instanceMu.Lock() + defer instanceMu.Unlock() + + if instance == nil { + i, err := NewInstance(nil) + if err != nil { + handleErr(err) + } + instance = i + } + }() + instanceMu.RLock() + } + return f(instance) +} + +func WithCurrentInstance[T any](f func(*Instance) T) T { + return withCurrentInstance(f, func(err error) { + log.Fatal(err) + }) +} + +func RunTest(t *testing.T, f func()) { + WithErrorHandler( + func(err error) { + t.Fatalf("failed to call instance: %s", err) + }, + func() { + withCurrentInstance( + func(_ *Instance) struct{} { + f() + return struct{}{} + }, + func(err error) { + t.Fatal(err) + }, + ) + }, + ) +} + +type Instance struct { + ptr unsafe.Pointer +} + +type Config struct { + Wasm []byte +} + +func NewInstance(conf *Config) (*Instance, error) { + var pinner runtime.Pinner + defer pinner.Unpin() + + c := C.default_config() + if conf != nil { + if len(conf.Wasm) > 0 { + ptr := unsafe.SliceData(conf.Wasm) + pinner.Pin(ptr) + + c.wasm = C.List_u8{ + ptr: (*C.uchar)(ptr), + len: C.ulong(len(conf.Wasm)), + } + } + } + ptr := C.instance_new(c) + if ptr == nil { + n := C.error_len() + buf := make([]C.char, n) + if n = C.error_take(unsafe.SliceData(buf), n); n > 0 { + err := errors.New(C.GoStringN(unsafe.SliceData(buf), C.int(n))) + return nil, fmt.Errorf("failed to create an instance: %w", err) + } else { + return nil, errors.New("failed to create an instance") + } + } + instance := &Instance{ptr: ptr} + runtime.SetFinalizer(instance, func(instance *Instance) { + C.instance_free(instance.ptr) + }) + return instance, nil +} + +func (i Instance) Call(instance string, name string, args ...unsafe.Pointer) error { + instanceC := C.CString(instance) + defer C.free(unsafe.Pointer(instanceC)) + nameC := C.CString(name) + defer C.free(unsafe.Pointer(nameC)) + + if !C.instance_call(i.ptr, instanceC, nameC, unsafe.SliceData(args)) { + n := C.error_len() + buf := make([]C.char, n) + if n = C.error_take(unsafe.SliceData(buf), n); n > 0 { + err := errors.New(C.GoStringN(unsafe.SliceData(buf), C.int(n))) + return fmt.Errorf("failed to call function on an instance: %w", err) + } else { + return errors.New("failed to call function on an instance") + } + } + return nil +} diff --git a/go/west_darwin_amd64.go b/go/west_darwin_amd64.go new file mode 100644 index 0000000..53b5f6d --- /dev/null +++ b/go/west_darwin_amd64.go @@ -0,0 +1,3 @@ +//go:generate cp ../target/release/libwest_sys.a ../lib/x86_64-darwin/libwest.a + +package west diff --git a/go/west_darwin_arm64.go b/go/west_darwin_arm64.go new file mode 100644 index 0000000..b158cb7 --- /dev/null +++ b/go/west_darwin_arm64.go @@ -0,0 +1,3 @@ +//go:generate cp ../target/release/libwest_sys.a ../lib/aarch64-darwin/libwest.a + +package west diff --git a/go/west_linux_amd64.go b/go/west_linux_amd64.go new file mode 100644 index 0000000..3d2030e --- /dev/null +++ b/go/west_linux_amd64.go @@ -0,0 +1,3 @@ +//go:generate cp ../target/release/libwest_sys.a ../lib/x86_64-linux/libwest.a + +package west diff --git a/go/west_linux_arm64.go b/go/west_linux_arm64.go new file mode 100644 index 0000000..62cf813 --- /dev/null +++ b/go/west_linux_arm64.go @@ -0,0 +1,3 @@ +//go:generate cp ../target/release/libwest_sys.a ../lib/aarch64-linux/libwest.a + +package west diff --git a/go/west_windows_amd64.go b/go/west_windows_amd64.go new file mode 100644 index 0000000..caafb82 --- /dev/null +++ b/go/west_windows_amd64.go @@ -0,0 +1,3 @@ +//go:generate cp ../target/release/libwest_sys.a ../lib/x86_64-windows/libwest.a + +package west diff --git a/include/include.go b/include/include.go new file mode 100644 index 0000000..8e731cd --- /dev/null +++ b/include/include.go @@ -0,0 +1 @@ +package include diff --git a/include/west.h b/include/west.h new file mode 100644 index 0000000..8ed096b --- /dev/null +++ b/include/west.h @@ -0,0 +1,25 @@ +#include +#include +#include +#include + +typedef struct List_u8 { + const uint8_t *ptr; + uintptr_t len; +} List_u8; + +typedef struct Config { + struct List_u8 wasm; +} Config; + +struct Config default_config(void); + +uintptr_t error_take(char *buf, uintptr_t len); + +uintptr_t error_len(void); + +void *instance_new(struct Config config); + +void instance_free(void *instance); + +bool instance_call(void *instance_ptr, const char *instance, const char *name, void *const *args); diff --git a/lib/aarch64-darwin/lib_darwin_arm64.go b/lib/aarch64-darwin/lib_darwin_arm64.go new file mode 100644 index 0000000..55c21f8 --- /dev/null +++ b/lib/aarch64-darwin/lib_darwin_arm64.go @@ -0,0 +1 @@ +package lib diff --git a/lib/aarch64-linux/lib_linux_arm64.go b/lib/aarch64-linux/lib_linux_arm64.go new file mode 100644 index 0000000..55c21f8 --- /dev/null +++ b/lib/aarch64-linux/lib_linux_arm64.go @@ -0,0 +1 @@ +package lib diff --git a/lib/amd64-linux/lib_linux_amd64.go b/lib/amd64-linux/lib_linux_amd64.go new file mode 100644 index 0000000..55c21f8 --- /dev/null +++ b/lib/amd64-linux/lib_linux_amd64.go @@ -0,0 +1 @@ +package lib diff --git a/lib/lib.go b/lib/lib.go new file mode 100644 index 0000000..55c21f8 --- /dev/null +++ b/lib/lib.go @@ -0,0 +1 @@ +package lib diff --git a/lib/x86_64-darwin/lib_darwin_amd64.go b/lib/x86_64-darwin/lib_darwin_amd64.go new file mode 100644 index 0000000..55c21f8 --- /dev/null +++ b/lib/x86_64-darwin/lib_darwin_amd64.go @@ -0,0 +1 @@ +package lib diff --git a/lib/x86_64-windows/lib_windows_amd64.go b/lib/x86_64-windows/lib_windows_amd64.go new file mode 100644 index 0000000..55c21f8 --- /dev/null +++ b/lib/x86_64-windows/lib_windows_amd64.go @@ -0,0 +1 @@ +package lib diff --git a/rust-toolchain.toml b/rust-toolchain.toml new file mode 100644 index 0000000..c320587 --- /dev/null +++ b/rust-toolchain.toml @@ -0,0 +1,7 @@ +[toolchain] +channel = "stable" +components = ["clippy", "rust-src", "rustfmt"] +targets = [ + "wasm32-unknown-unknown", + "wasm32-wasip1" +] diff --git a/src/lib.rs b/src/lib.rs new file mode 100644 index 0000000..8e30c6d --- /dev/null +++ b/src/lib.rs @@ -0,0 +1,313 @@ +use core::time::Duration; + +use anyhow::Context as _; +use wasi_preview1_component_adapter_provider::{ + WASI_SNAPSHOT_PREVIEW1_ADAPTER_NAME, WASI_SNAPSHOT_PREVIEW1_REACTOR_ADAPTER, +}; +use wasmtime::component::{Component, Linker, Resource, ResourceTable, Type, TypedFunc, Val}; +use wasmtime::{Engine, Store}; +use wasmtime_wasi::{WasiCtx, WasiCtxBuilder, WasiView}; +use wasmtime_wasi_http::types::HostIncomingRequest; +use wasmtime_wasi_http::{WasiHttpCtx, WasiHttpView}; + +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, + }, + world: "http-test-passthrough", + }); +} + +pub const PASSTHROUGH: &[u8] = include_bytes!(concat!(env!("OUT_DIR"), "/west_passthrough.wasm")); + +struct Ctx { + wasi: WasiCtx, + http: WasiHttpCtx, + table: ResourceTable, +} + +impl WasiView for Ctx { + fn ctx(&mut self) -> &mut WasiCtx { + &mut self.wasi + } + fn table(&mut self) -> &mut ResourceTable { + &mut self.table + } +} + +impl WasiHttpView for Ctx { + fn ctx(&mut self) -> &mut WasiHttpCtx { + &mut self.http + } + fn table(&mut self) -> &mut ResourceTable { + &mut self.table + } +} + +impl bindings::west::test::http_test::Host for Ctx { + fn new_response_outparam( + &mut self, + ) -> wasmtime::Result<( + Resource, + Resource, + )> { + let (res_tx, res_rx) = tokio::sync::oneshot::channel(); + let out = WasiHttpView::new_response_outparam(self, res_tx) + .context("failed to construct `response-outparam`")?; + let res = WasiHttpView::table(self) + .push( + wasmtime_wasi_http::types::HostFutureIncomingResponse::Pending( + wasmtime_wasi::runtime::spawn(async { + match res_rx.await.context("failed to receive response")? { + Ok(resp) => Ok(Ok(wasmtime_wasi_http::types::IncomingResponse { + resp, + worker: None, + between_bytes_timeout: Duration::from_secs(1), + })), + Err(err) => Ok(Err(err)), + } + }), + ), + ) + .context("failed to push `future-incoming-response` into resource table")?; + Ok((out, res)) + } + + fn new_incoming_request( + &mut self, + req: Resource, + ) -> wasmtime::Result> { + let wasmtime_wasi_http::types::HostOutgoingRequest { + method, + scheme, + authority, + path_with_query, + headers, + body, + } = WasiHttpView::table(self) + .delete(req) + .context("failed to delete outgoing request")?; + + let uri = http::Uri::builder(); + let uri = match &scheme { + None | Some(wasmtime_wasi_http::bindings::http::types::Scheme::Http) => { + uri.scheme(http::uri::Scheme::HTTP) + } + Some(wasmtime_wasi_http::bindings::http::types::Scheme::Https) => { + uri.scheme(http::uri::Scheme::HTTPS) + } + Some(wasmtime_wasi_http::bindings::http::types::Scheme::Other(scheme)) => { + uri.scheme(scheme.as_str()) + } + }; + let uri = if let Some(path_with_query) = path_with_query { + uri.path_and_query(path_with_query) + } else { + uri.path_and_query("/") + }; + let uri = if let Some(authority) = authority { + uri.authority(authority) + } else { + uri.authority("west") + }; + let uri = uri.build().context("failed to build URI")?; + let mut req = http::Request::builder(); + if let Some(h) = req.headers_mut() { + *h = headers; + } + let req = match &method { + wasmtime_wasi_http::bindings::http::types::Method::Get => req.method(http::Method::GET), + wasmtime_wasi_http::bindings::http::types::Method::Head => { + req.method(http::Method::HEAD) + } + wasmtime_wasi_http::bindings::http::types::Method::Post => { + req.method(http::Method::POST) + } + wasmtime_wasi_http::bindings::http::types::Method::Put => req.method(http::Method::PUT), + wasmtime_wasi_http::bindings::http::types::Method::Delete => { + req.method(http::Method::DELETE) + } + wasmtime_wasi_http::bindings::http::types::Method::Connect => { + req.method(http::Method::CONNECT) + } + wasmtime_wasi_http::bindings::http::types::Method::Options => { + req.method(http::Method::OPTIONS) + } + wasmtime_wasi_http::bindings::http::types::Method::Trace => { + req.method(http::Method::TRACE) + } + wasmtime_wasi_http::bindings::http::types::Method::Patch => { + req.method(http::Method::PATCH) + } + wasmtime_wasi_http::bindings::http::types::Method::Other(other) => { + req.method(other.as_str()) + } + }; + let req = req + .uri(uri) + .body(()) + .context("failed to build HTTP request")?; + let (parts, ()) = req.into_parts(); + + let req = HostIncomingRequest::new( + self, + parts, + scheme.unwrap_or(wasmtime_wasi_http::bindings::http::types::Scheme::Http), + body.map(|body| { + wasmtime_wasi_http::body::HostIncomingBody::new(body, Duration::from_secs(1)) + }), + ) + .context("failed to construct `incoming-request`")?; + WasiHttpView::table(self) + .push(req) + .context("failed to push `incoming-request` into resource table") + } +} + +pub struct Config<'a> { + pub engine: Engine, + pub wasm: &'a [u8], +} + +impl Default for Config<'_> { + fn default() -> Self { + Self { + engine: Engine::default(), + wasm: PASSTHROUGH, + } + } +} + +pub struct Func<'a> { + func: wasmtime::component::Func, + store: &'a mut Store, +} + +impl Func<'_> { + pub fn params(&self) -> Box<[Type]> { + self.func.params(&self.store) + } + + pub fn results(&self) -> Box<[Type]> { + self.func.results(&self.store) + } + + pub fn call(&mut self, params: &[Val], results: &mut [Val]) -> anyhow::Result<()> { + self.func + .call(&mut self.store, params, results) + .context("failed to call function")?; + self.func + .post_return(&mut self.store) + .context("failed to invoke `post-return`") + } + + pub fn store(&mut self) -> &mut Store { + &mut self.store + } +} + +pub struct Instance { + instance: wasmtime::component::Instance, + store: Store, +} + +impl Instance { + pub fn func(&mut self, instance: &str, name: &str) -> anyhow::Result { + let idx = self + .instance + .get_export(&mut self.store, None, instance) + .with_context(|| format!("export `{instance}` not found"))?; + let idx = self + .instance + .get_export(&mut self.store, Some(&idx), name) + .with_context(|| format!("export `{name}` not found"))?; + let func = self + .instance + .get_func(&mut self.store, idx) + .with_context(|| format!("function export `{name}` not found"))?; + Ok(Func { + func, + store: &mut self.store, + }) + } + + pub fn call( + &mut self, + instance: &str, + name: &str, + params: &[Val], + results: &mut [Val], + ) -> anyhow::Result<()> { + let mut func = self + .func(instance, name) + .context("failed to lookup function")?; + func.call(params, results) + .context("failed to call function") + } + + pub fn call_http_response_outparam_set( + &mut self, + out: Resource, + res: Result< + Resource, + wasmtime_wasi_http::bindings::http::types::ErrorCode, + >, + ) -> anyhow::Result<()> { + let func = self + .func("wasi:http/types@0.2.0", "[static]response-outparam.set") + .context("failed to lookup function")?; + let func = unsafe { TypedFunc::new_unchecked(func.func) }; + func.call(&mut self.store, (out.rep(), res)) + .context("failed to call function") + } + + pub fn store(&mut self) -> &mut Store { + &mut self.store + } +} + +pub fn instantiate(Config { engine, wasm }: Config) -> anyhow::Result { + let wasm = if wasmparser::Parser::is_core_wasm(&wasm) { + let wasm = wit_component::ComponentEncoder::default() + .module(&wasm) + .context("failed to set core component module")? + .adapter( + WASI_SNAPSHOT_PREVIEW1_ADAPTER_NAME, + WASI_SNAPSHOT_PREVIEW1_REACTOR_ADAPTER, + ) + .context("failed to add WASI preview1 adapter")? + .encode() + .context("failed to encode a component from module")?; + let wasm = wasm.as_slice(); + return instantiate(Config { engine, wasm }); + } else { + wasm + }; + let wasm = Component::new(&engine, wasm).context("failed to compile component")?; + + let mut linker = Linker::::new(&engine); + 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)?; + + let wasi = WasiCtxBuilder::new() + .inherit_env() + .inherit_stdout() + .inherit_stderr() + .inherit_network() + .build(); + let http = WasiHttpCtx::new(); + let table = ResourceTable::new(); + let mut store = Store::new(&engine, Ctx { wasi, http, table }); + let instance = linker + .instantiate(&mut store, &wasm) + .context("failed to instantiate component")?; + Ok(Instance { instance, store }) +} diff --git a/tests/components/sync/Cargo.toml b/tests/components/sync/Cargo.toml new file mode 100644 index 0000000..0418adb --- /dev/null +++ b/tests/components/sync/Cargo.toml @@ -0,0 +1,16 @@ +[package] +name = "sync-test-component" +version = "0.1.0" +publish = false + +authors.workspace = true +categories.workspace = true +edition.workspace = true +license.workspace = true +repository.workspace = true + +[lib] +crate-type = ["cdylib"] + +[dependencies] +wit-bindgen = { workspace = true, features = ["realloc", "macros"] } diff --git a/tests/components/sync/src/lib.rs b/tests/components/sync/src/lib.rs new file mode 100644 index 0000000..da1b419 --- /dev/null +++ b/tests/components/sync/src/lib.rs @@ -0,0 +1,227 @@ +mod bindings { + use crate::Handler; + + wit_bindgen::generate!({ + world: "host", + path: "../../wit/sync", + with: { + "west-test:sync/sync": generate, + } + }); + export!(Handler); +} +use bindings::exports::west_test::sync::sync::{Abc, Foobar, Primitives, Rec, Var}; + +struct Handler; + +struct Res; + +impl bindings::exports::west_test::sync::sync::GuestRes for Res { + fn new() -> Res { + Res + } + + fn foo(&self) -> String { + "foo".into() + } + + fn make_list() -> Vec { + vec![ + bindings::exports::west_test::sync::sync::Res::new(Res), + bindings::exports::west_test::sync::sync::Res::new(Res), + bindings::exports::west_test::sync::sync::Res::new(Res), + bindings::exports::west_test::sync::sync::Res::new(Res), + bindings::exports::west_test::sync::sync::Res::new(Res), + ] + } +} + +impl bindings::exports::west_test::sync::sync::Guest for Handler { + type Res = Res; + + fn identity_bool(arg: bool) -> bool { + arg + } + + fn identity_u8(arg: u8) -> u8 { + arg + } + + fn identity_u16(arg: u16) -> u16 { + arg + } + + fn identity_u32(arg: u32) -> u32 { + arg + } + + fn identity_u64(arg: u64) -> u64 { + arg + } + + fn identity_s8(arg: i8) -> i8 { + arg + } + + fn identity_s16(arg: i16) -> i16 { + arg + } + + fn identity_s32(arg: i32) -> i32 { + arg + } + + fn identity_s64(arg: i64) -> i64 { + arg + } + + fn identity_f32(arg: f32) -> f32 { + arg + } + + fn identity_f64(arg: f64) -> f64 { + arg + } + + fn identity_char(arg: char) -> char { + arg + } + + fn identity_string(arg: String) -> String { + arg + } + + fn identity_flags(arg: Abc) -> Abc { + arg + } + + fn identity_variant(arg: Var) -> Var { + arg + } + + fn identity_enum(arg: Foobar) -> Foobar { + arg + } + + fn identity_option_string(arg: Option) -> Option { + arg + } + + fn identity_result_string(arg: Result) -> Result { + arg + } + + fn identity_tuple( + arg: ( + u8, + u16, + u32, + u64, + i8, + i16, + i32, + i64, + f32, + f64, + bool, + char, + String, + ), + ) -> ( + u8, + u16, + u32, + u64, + i8, + i16, + i32, + i64, + f32, + f64, + bool, + char, + String, + ) { + arg + } + + fn identity_list_bool(arg: Vec) -> Vec { + arg + } + + fn identity_list_enum(arg: Vec) -> Vec { + arg + } + + fn identity_list_flags(arg: Vec) -> Vec { + arg + } + + fn identity_list_variant(arg: Vec) -> Vec { + arg + } + + fn identity_list_string(arg: Vec) -> Vec { + arg + } + + fn identity_list_list_string(arg: Vec>) -> Vec> { + arg + } + + fn identity_list_u16(arg: Vec) -> Vec { + arg + } + + fn identity_record_rec(arg: Rec) -> Rec { + arg + } + + fn identity_record_primitives(arg: Primitives) -> Primitives { + arg + } + + fn identity_list_record_primitives(arg: Vec) -> Vec { + arg + } + + fn identity_list_option_string(arg: Vec>) -> Vec> { + arg + } + + fn identity_list_result_string(arg: Vec>) -> Vec> { + arg + } + + fn identity_primitives( + a: u8, + b: u16, + c: u32, + d: u64, + e: i8, + f: i16, + g: i32, + h: i64, + i: f32, + j: f64, + l: bool, + m: char, + n: String, + ) -> ( + u8, + u16, + u32, + u64, + i8, + i16, + i32, + i64, + f32, + f64, + bool, + char, + String, + ) { + (a, b, c, d, e, f, g, h, i, j, l, m, n) + } +} diff --git a/tests/components/wasi/Cargo.toml b/tests/components/wasi/Cargo.toml new file mode 100644 index 0000000..1f4537b --- /dev/null +++ b/tests/components/wasi/Cargo.toml @@ -0,0 +1,17 @@ +[package] +name = "wasi-test-component" +version = "0.1.0" +publish = false + +authors.workspace = true +categories.workspace = true +edition.workspace = true +license.workspace = true +repository.workspace = true + +[lib] +crate-type = ["cdylib"] + +[dependencies] +west-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 new file mode 100644 index 0000000..4af5de0 --- /dev/null +++ b/tests/components/wasi/src/lib.rs @@ -0,0 +1,26 @@ +mod bindings { + use crate::Handler; + + wit_bindgen::generate!({ + world: "host", + path: "../../wit/fib", + with: { + "west-test:fib/fib": generate, + } + }); + export!(Handler); +} + +use west_passthrough as _; + +pub struct Handler; + +impl bindings::exports::west_test::fib::fib::Guest for Handler { + fn fib(n: u32) -> u64 { + match n { + 0 => 0, + 1 | 2 => 1, + n => Self::fib(n - 2) + Self::fib(n - 1), + } + } +} diff --git a/tests/wit/fib/fib.wit b/tests/wit/fib/fib.wit new file mode 100644 index 0000000..f621d77 --- /dev/null +++ b/tests/wit/fib/fib.wit @@ -0,0 +1,13 @@ +package west-test:fib; + +interface fib { + fib: func(n: u32) -> u64; +} + +world guest { + import fib; +} + +world host { + export fib; +} diff --git a/tests/wit/sync/sync.wit b/tests/wit/sync/sync.wit new file mode 100644 index 0000000..214a2b1 --- /dev/null +++ b/tests/wit/sync/sync.wit @@ -0,0 +1,96 @@ +package west-test:sync; + +interface sync { + flags abc { + a, + b, + c, + } + + record rec-nested { + foo: string, + } + + record rec { + nested: rec-nested, + } + + variant var { + var(rec), + empty, + } + + enum foobar { + foo, + bar, + } + + record primitives { + a: u8, + b: u16, + c: u32, + d: u64, + e: s8, + f: s16, + g: s32, + h: s64, + i: f32, + j: f64, + k: bool, + l: char, + m: string, + } + + resource res { + constructor(); + foo: func() -> string; + make-list: static func() -> list; + } + + identity-bool: func(arg: bool) -> bool; + identity-s8: func(arg: s8) -> s8; + identity-u8: func(arg: u8) -> u8; + identity-s16: func(arg: s16) -> s16; + identity-u16: func(arg: u16) -> u16; + identity-s32: func(arg: s32) -> s32; + identity-u32: func(arg: u32) -> u32; + identity-s64: func(arg: s64) -> s64; + identity-u64: func(arg: u64) -> u64; + identity-f32: func(arg: f32) -> f32; + identity-f64: func(arg: f64) -> f64; + identity-char: func(arg: char) -> char; + identity-string: func(arg: string) -> string; + + identity-flags: func(arg: abc) -> abc; + identity-enum: func(arg: foobar) -> foobar; + identity-variant: func(arg: var) -> var; + identity-option-string: func(arg: option) -> option; + identity-result-string: func(arg: result) -> result; + identity-record-primitives: func(arg: primitives) -> primitives; + identity-record-rec: func(arg: rec) -> rec; + identity-tuple: func(arg: tuple) -> tuple; + + identity-list-bool: func(arg: list) -> list; + identity-list-u16: func(arg: list) -> list; + identity-list-string: func(arg: list) -> list; + + identity-list-enum: func(arg: list) -> list; + identity-list-flags: func(arg: list) -> list; + identity-list-record-primitives: func(arg: list) -> list; + identity-list-variant: func(arg: list) -> list; + + identity-list-option-string: func(arg: list>) -> list>; + identity-list-result-string: func(arg: list>) -> list>; + + identity-list-list-string: func(arg: list>) -> list>; + + identity-primitives: func(a: u8, b: u16, c: u32, d: u64, e: s8, f: s16, g: s32, h: s64, i: f32, j: f64, k: bool, l: char, m: string) -> tuple; +} + +world guest { + import sync; +} + +world host { + export sync; +} diff --git a/wit/deps.lock b/wit/deps.lock new file mode 100644 index 0000000..5bd958b --- /dev/null +++ b/wit/deps.lock @@ -0,0 +1,29 @@ +[cli] +sha256 = "285865a31d777181b075f39e92bcfe59c89cd6bacce660be1b9a627646956258" +sha512 = "da2622210a9e3eea82b99f1a5b8a44ce5443d009cb943f7bca0bf9cf4360829b289913d7ee727c011f0f72994ea7dc8e661ebcc0a6b34b587297d80cd9b3f7e8" + +[clocks] +sha256 = "468b4d12892fe926b8eb5d398dbf579d566c93231fa44f415440572c695b7613" +sha512 = "e6b53a07221f1413953c9797c68f08b815fdaebf66419bbc1ea3e8b7dece73731062693634731f311a03957b268cf9cc509c518bd15e513c318aa04a8459b93a" + +[filesystem] +sha256 = "498c465cfd04587db40f970fff2185daa597d074c20b68a8bcbae558f261499b" +sha512 = "ead452f9b7bfb88593a502ec00d76d4228003d51c40fd0408aebc32d35c94673551b00230d730873361567cc209ec218c41fb4e95bad194268592c49e7964347" + +[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"] + +[io] +sha256 = "7210e5653539a15478f894d4da24cc69d61924cbcba21d2804d69314a88e5a4c" +sha512 = "49184a1b0945a889abd52d25271172ed3dc2db6968fcdddb1bab7ee0081f4a3eeee0977ad2291126a37631c0d86eeea75d822fa8af224c422134500bf9f0f2bb" + +[random] +sha256 = "7371d03c037d924caba2587fb2e7c5773a0d3c5fcecbf7971e0e0ba57973c53d" +sha512 = "964c4e8925a53078e4d94ba907b54f89a0b7e154f46823a505391471466c17f53c8692682e5c85771712acd88b348686173fc07c53a3cfe3d301b8cd8ddd0de4" + +[sockets] +sha256 = "622bd28bbeb43736375dc02bd003fd3a016ff8ee91e14bab488325c6b38bf966" +sha512 = "5a63c1f36de0c4548e1d2297bdbededb28721cbad94ef7825c469eae29d7451c97e00b4c1d6730ee1ec0c4a5aac922961a2795762d4a0c3bb54e30a391a84bae" diff --git a/wit/deps.toml b/wit/deps.toml new file mode 100644 index 0000000..1b375ee --- /dev/null +++ b/wit/deps.toml @@ -0,0 +1 @@ +http = "https://github.com/WebAssembly/wasi-http/archive/v0.2.0.tar.gz" diff --git a/wit/deps/cli/command.wit b/wit/deps/cli/command.wit new file mode 100644 index 0000000..d8005bd --- /dev/null +++ b/wit/deps/cli/command.wit @@ -0,0 +1,7 @@ +package wasi:cli@0.2.0; + +world command { + include imports; + + export run; +} diff --git a/wit/deps/cli/environment.wit b/wit/deps/cli/environment.wit new file mode 100644 index 0000000..7006523 --- /dev/null +++ b/wit/deps/cli/environment.wit @@ -0,0 +1,18 @@ +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. + get-environment: func() -> list>; + + /// Get the POSIX-style arguments to the program. + get-arguments: func() -> list; + + /// Return a path that programs should use as their initial current working + /// directory, interpreting `.` as shorthand for this. + initial-cwd: func() -> option; +} diff --git a/wit/deps/cli/exit.wit b/wit/deps/cli/exit.wit new file mode 100644 index 0000000..d0c2b82 --- /dev/null +++ b/wit/deps/cli/exit.wit @@ -0,0 +1,4 @@ +interface exit { + /// Exit the current instance and any linked instances. + exit: func(status: result); +} diff --git a/wit/deps/cli/imports.wit b/wit/deps/cli/imports.wit new file mode 100644 index 0000000..083b84a --- /dev/null +++ b/wit/deps/cli/imports.wit @@ -0,0 +1,20 @@ +package wasi:cli@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; + + import environment; + import exit; + import stdin; + import stdout; + import stderr; + import terminal-input; + import terminal-output; + import terminal-stdin; + import terminal-stdout; + import terminal-stderr; +} diff --git a/wit/deps/cli/run.wit b/wit/deps/cli/run.wit new file mode 100644 index 0000000..a70ee8c --- /dev/null +++ b/wit/deps/cli/run.wit @@ -0,0 +1,4 @@ +interface run { + /// Run the program. + run: func() -> result; +} diff --git a/wit/deps/cli/stdio.wit b/wit/deps/cli/stdio.wit new file mode 100644 index 0000000..31ef35b --- /dev/null +++ b/wit/deps/cli/stdio.wit @@ -0,0 +1,17 @@ +interface stdin { + use wasi:io/streams@0.2.0.{input-stream}; + + get-stdin: func() -> input-stream; +} + +interface stdout { + use wasi:io/streams@0.2.0.{output-stream}; + + get-stdout: func() -> output-stream; +} + +interface stderr { + use wasi:io/streams@0.2.0.{output-stream}; + + get-stderr: func() -> output-stream; +} diff --git a/wit/deps/cli/terminal.wit b/wit/deps/cli/terminal.wit new file mode 100644 index 0000000..38c724e --- /dev/null +++ b/wit/deps/cli/terminal.wit @@ -0,0 +1,49 @@ +/// 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. +interface terminal-input { + /// The input side of a terminal. + 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. +interface terminal-output { + /// The output side of a terminal. + resource terminal-output; +} + +/// An interface providing an optional `terminal-input` for stdin as a +/// link-time authority. +interface terminal-stdin { + use terminal-input.{terminal-input}; + + /// If stdin is connected to a terminal, return a `terminal-input` handle + /// allowing further interaction with it. + get-terminal-stdin: func() -> option; +} + +/// An interface providing an optional `terminal-output` for stdout as a +/// link-time authority. +interface terminal-stdout { + use terminal-output.{terminal-output}; + + /// If stdout is connected to a terminal, return a `terminal-output` handle + /// allowing further interaction with it. + get-terminal-stdout: func() -> option; +} + +/// An interface providing an optional `terminal-output` for stderr as a +/// link-time authority. +interface terminal-stderr { + use terminal-output.{terminal-output}; + + /// If stderr is connected to a terminal, return a `terminal-output` handle + /// allowing further interaction with it. + get-terminal-stderr: func() -> option; +} diff --git a/wit/deps/clocks/monotonic-clock.wit b/wit/deps/clocks/monotonic-clock.wit new file mode 100644 index 0000000..4e4dc3a --- /dev/null +++ b/wit/deps/clocks/monotonic-clock.wit @@ -0,0 +1,45 @@ +package wasi:clocks@0.2.0; +/// 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. +/// +/// It is intended for measuring elapsed time. +interface monotonic-clock { + use wasi:io/poll@0.2.0.{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. + type instant = u64; + + /// A duration of time, in nanoseconds. + 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. + now: func() -> instant; + + /// Query the resolution of the clock. Returns the duration of time + /// corresponding to a clock tick. + resolution: func() -> duration; + + /// Create a `pollable` which will resolve once the specified instant + /// occured. + 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. + subscribe-duration: func( + when: duration, + ) -> pollable; +} diff --git a/wit/deps/clocks/wall-clock.wit b/wit/deps/clocks/wall-clock.wit new file mode 100644 index 0000000..440ca0f --- /dev/null +++ b/wit/deps/clocks/wall-clock.wit @@ -0,0 +1,42 @@ +package wasi:clocks@0.2.0; +/// 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. +interface wall-clock { + /// A time and date in seconds plus nanoseconds. + 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 + now: func() -> datetime; + + /// Query the resolution of the clock. + /// + /// The nanoseconds field of the output is always less than 1000000000. + resolution: func() -> datetime; +} diff --git a/wit/deps/clocks/world.wit b/wit/deps/clocks/world.wit new file mode 100644 index 0000000..c022457 --- /dev/null +++ b/wit/deps/clocks/world.wit @@ -0,0 +1,6 @@ +package wasi:clocks@0.2.0; + +world imports { + import monotonic-clock; + import wall-clock; +} diff --git a/wit/deps/filesystem/preopens.wit b/wit/deps/filesystem/preopens.wit new file mode 100644 index 0000000..da801f6 --- /dev/null +++ b/wit/deps/filesystem/preopens.wit @@ -0,0 +1,8 @@ +package wasi:filesystem@0.2.0; + +interface preopens { + use types.{descriptor}; + + /// Return the set of preopened directories, and their path. + get-directories: func() -> list>; +} diff --git a/wit/deps/filesystem/types.wit b/wit/deps/filesystem/types.wit new file mode 100644 index 0000000..11108fc --- /dev/null +++ b/wit/deps/filesystem/types.wit @@ -0,0 +1,634 @@ +package wasi:filesystem@0.2.0; +/// 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 +interface types { + use wasi:io/streams@0.2.0.{input-stream, output-stream, error}; + use wasi:clocks/wall-clock@0.2.0.{datetime}; + + /// File size or length of a region within a file. + type filesize = u64; + + /// The type of a filesystem object referenced by a descriptor. + /// + /// Note: This was called `filetype` in earlier versions of WASI. + 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. + 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 integrety + /// 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. + 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. + 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`. + 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. + type link-count = u64; + + /// When setting a timestamp, this gives the value to set it to. + 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. + 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. + 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. + 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. + 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. + 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. + append-via-stream: func() -> result; + + /// Provide file advisory information on a descriptor. + /// + /// This is similar to `posix_fadvise` in POSIX. + 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. + 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. + 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. + 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. + 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. + 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. + 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. + 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. + 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. + sync: func() -> result<_, error-code>; + + /// Create a directory. + /// + /// Note: This is similar to `mkdirat` in POSIX. + 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. + 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. + 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. + 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. + 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. + 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. + 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. + 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. + 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. + 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. + 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. + 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. + 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`. + 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. + resource directory-entry-stream { + /// Read a single directory entry from a `directory-entry-stream`. + 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. + filesystem-error-code: func(err: borrow) -> option; +} diff --git a/wit/deps/filesystem/world.wit b/wit/deps/filesystem/world.wit new file mode 100644 index 0000000..663f579 --- /dev/null +++ b/wit/deps/filesystem/world.wit @@ -0,0 +1,6 @@ +package wasi:filesystem@0.2.0; + +world imports { + import types; + import preopens; +} diff --git a/wit/deps/http/handler.wit b/wit/deps/http/handler.wit new file mode 100644 index 0000000..a34a064 --- /dev/null +++ b/wit/deps/http/handler.wit @@ -0,0 +1,43 @@ +/// This interface defines a handler of incoming HTTP Requests. It should +/// be exported by components which can respond to HTTP Requests. +interface incoming-handler { + 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. + 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. +interface outgoing-handler { + 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`. + handle: func( + request: outgoing-request, + options: option + ) -> result; +} diff --git a/wit/deps/http/proxy.wit b/wit/deps/http/proxy.wit new file mode 100644 index 0000000..687c24d --- /dev/null +++ b/wit/deps/http/proxy.wit @@ -0,0 +1,32 @@ +package wasi:http@0.2.0; + +/// 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 { + /// HTTP proxies have access to time and randomness. + include wasi:clocks/imports@0.2.0; + import wasi:random/random@0.2.0; + + /// 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; + + /// 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; + + /// This is the default handler to use when user code simply wants to make an + /// HTTP request (e.g., via `fetch()`). + import outgoing-handler; + + /// 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`. + export incoming-handler; +} diff --git a/wit/deps/http/types.wit b/wit/deps/http/types.wit new file mode 100644 index 0000000..755ac6a --- /dev/null +++ b/wit/deps/http/types.wit @@ -0,0 +1,570 @@ +/// 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. +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}; + + /// This type corresponds to HTTP standard Methods. + variant method { + get, + head, + post, + put, + delete, + connect, + options, + trace, + patch, + other(string) + } + + /// This type corresponds to HTTP standard Related Schemes. + 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 + 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: + record DNS-error-payload { + rcode: option, + info-code: option + } + + /// Defines the case payload type for `TLS-alert-received` above: + record TLS-alert-received-payload { + alert-id: option, + alert-message: option + } + + /// Defines the case payload type for `HTTP-response-{header,trailer}-size` above: + 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. + 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. + 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. + 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. + 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`. + resource fields { + + /// Construct an empty HTTP Fields. + /// + /// The resulting `fields` is mutable. + 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. 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. + /// + /// An error result will be returned if any header or value was + /// syntactically invalid, or if a header was forbidden. + 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. + 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. + 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. + 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. + 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. + 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. + entries: func() -> list>; + + /// Make a deep copy of the Fields. Equivelant in behavior to calling the + /// `fields` constructor on the return value of `entries`. The resulting + /// `fields` is mutable. + clone: func() -> fields; + } + + /// Headers is an alias for Fields. + type headers = fields; + + /// Trailers is an alias for Fields. + type trailers = fields; + + /// Represents an incoming HTTP Request. + resource incoming-request { + + /// Returns the method of the incoming request. + method: func() -> method; + + /// Returns the path with query parameters from the request, as a string. + path-with-query: func() -> option; + + /// Returns the protocol scheme from the request. + scheme: func() -> option; + + /// Returns the authority from the request, if it was present. + 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. + headers: func() -> headers; + + /// Gives the `incoming-body` associated with this request. Will only + /// return success at most once, and subsequent calls will return error. + consume: func() -> result; + } + + /// Represents an outgoing HTTP Request. + 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 + ); + + /// 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; + + /// Get the Method for the Request. + 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. + 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. + 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. + 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. + 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. + 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 + /// HTTPS schemes always require an authority. + 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 + /// HTTPS schemes always require an authority. Fails if the string given is + /// not a syntactically valid uri authority. + 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 transfered to + /// another component by e.g. `outgoing-handler.handle`. + 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`. + resource request-options { + /// Construct a default `request-options` value. + constructor(); + + /// The timeout for the initial connect to the HTTP Server. + 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. + set-connect-timeout: func(duration: option) -> result; + + /// The timeout for receiving the first byte of the Response body. + 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. + set-first-byte-timeout: func(duration: option) -> result; + + /// The timeout for receiving subsequent chunks of bytes in the Response + /// body stream. + 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. + 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`. + 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. + set: static func( + param: response-outparam, + response: result, + ); + } + + /// This type corresponds to the HTTP standard Status Code. + type status-code = u16; + + /// Represents an incoming HTTP Response. + resource incoming-response { + + /// Returns the status code from the incoming response. + 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. + headers: func() -> headers; + + /// Returns the incoming body. May be called at most once. Returns error + /// if called additional times. + 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. + 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. + %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. + finish: static func(this: incoming-body) -> future-trailers; + } + + /// Represents a future which may eventaully 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 { + + /// Returns a pollable which becomes ready when either the trailers have + /// been received, or an error has occured. When this pollable is ready, + /// the `get` method will return `some`. + subscribe: func() -> pollable; + + /// Returns the contents of the trailers, or an error which occured, + /// 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 occured 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>>>; + } + + /// Represents an outgoing HTTP Response. + 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); + + /// Get the HTTP Status Code for the Response. + 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. + 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 transfered to + /// another component by e.g. `outgoing-handler.handle`. + 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. + 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 occured. The implementation should propogate 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 { + + /// 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; + + /// 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>; + } + + /// Represents a future which may eventaully 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 { + /// Returns a pollable which becomes ready when either the Response has + /// been received, or an error has occured. When this pollable is ready, + /// the `get` method will return `some`. + 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 recieved successfully, or that an error + /// occured. 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>>; + + } +} diff --git a/wit/deps/io/error.wit b/wit/deps/io/error.wit new file mode 100644 index 0000000..22e5b64 --- /dev/null +++ b/wit/deps/io/error.wit @@ -0,0 +1,34 @@ +package wasi:io@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 + /// 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`. + /// + /// The set of functions which can "downcast" an `error` into a more + /// concrete type is open. + 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. + to-debug-string: func() -> string; + } +} diff --git a/wit/deps/io/poll.wit b/wit/deps/io/poll.wit new file mode 100644 index 0000000..ddc67f8 --- /dev/null +++ b/wit/deps/io/poll.wit @@ -0,0 +1,41 @@ +package wasi:io@0.2.0; + +/// A poll API intended to let users wait for I/O events on multiple handles +/// at once. +interface poll { + /// `pollable` represents a single I/O event which may be ready, or not. + resource pollable { + + /// Return the readiness of a pollable. This function never blocks. + /// + /// Returns `true` when the pollable is ready, and `false` otherwise. + 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. + 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. + /// + /// If the list contains more elements than can be indexed with a `u32` + /// value, this function traps. + /// + /// 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 reaedy for I/O. + poll: func(in: list>) -> list; +} diff --git a/wit/deps/io/streams.wit b/wit/deps/io/streams.wit new file mode 100644 index 0000000..6d2f871 --- /dev/null +++ b/wit/deps/io/streams.wit @@ -0,0 +1,262 @@ +package wasi:io@0.2.0; + +/// 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. +interface streams { + use error.{error}; + use poll.{pollable}; + + /// An error for input-stream and output-stream operations. + 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`. + 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. + 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`. + 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. + 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`. + 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. + 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`. + 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. + 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. + 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 + /// ``` + 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. + flush: func() -> result<_, stream-error>; + + /// Request to flush buffered output, and block until flush completes + /// and stream is ready for writing again. + 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 + /// 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. + 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 + /// ``` + 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 equivelant 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( + /// 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`. + blocking-splice: func( + /// The stream to read from + src: borrow, + /// The number of bytes to splice + len: u64, + ) -> result; + } +} diff --git a/wit/deps/io/world.wit b/wit/deps/io/world.wit new file mode 100644 index 0000000..5f0b43f --- /dev/null +++ b/wit/deps/io/world.wit @@ -0,0 +1,6 @@ +package wasi:io@0.2.0; + +world imports { + import streams; + import poll; +} diff --git a/wit/deps/random/insecure-seed.wit b/wit/deps/random/insecure-seed.wit new file mode 100644 index 0000000..47210ac --- /dev/null +++ b/wit/deps/random/insecure-seed.wit @@ -0,0 +1,25 @@ +package wasi:random@0.2.0; +/// The insecure-seed interface for seeding hash-map DoS resistance. +/// +/// It is intended to be portable at least between Unix-family platforms and +/// Windows. +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. + insecure-seed: func() -> tuple; +} diff --git a/wit/deps/random/insecure.wit b/wit/deps/random/insecure.wit new file mode 100644 index 0000000..c58f4ee --- /dev/null +++ b/wit/deps/random/insecure.wit @@ -0,0 +1,22 @@ +package wasi:random@0.2.0; +/// The insecure interface for insecure pseudo-random numbers. +/// +/// It is intended to be portable at least between Unix-family platforms and +/// Windows. +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. + 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`. + get-insecure-random-u64: func() -> u64; +} diff --git a/wit/deps/random/random.wit b/wit/deps/random/random.wit new file mode 100644 index 0000000..0c017f0 --- /dev/null +++ b/wit/deps/random/random.wit @@ -0,0 +1,26 @@ +package wasi:random@0.2.0; +/// WASI Random is a random data API. +/// +/// It is intended to be portable at least between Unix-family platforms and +/// Windows. +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. + 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`. + get-random-u64: func() -> u64; +} diff --git a/wit/deps/random/world.wit b/wit/deps/random/world.wit new file mode 100644 index 0000000..3da3491 --- /dev/null +++ b/wit/deps/random/world.wit @@ -0,0 +1,7 @@ +package wasi:random@0.2.0; + +world imports { + import random; + import insecure; + import insecure-seed; +} diff --git a/wit/deps/sockets/instance-network.wit b/wit/deps/sockets/instance-network.wit new file mode 100644 index 0000000..e455d0f --- /dev/null +++ b/wit/deps/sockets/instance-network.wit @@ -0,0 +1,9 @@ + +/// This interface provides a value-export of the default network handle.. +interface instance-network { + use network.{network}; + + /// Get a handle to the default network. + instance-network: func() -> network; + +} diff --git a/wit/deps/sockets/ip-name-lookup.wit b/wit/deps/sockets/ip-name-lookup.wit new file mode 100644 index 0000000..8e639ec --- /dev/null +++ b/wit/deps/sockets/ip-name-lookup.wit @@ -0,0 +1,51 @@ + +interface ip-name-lookup { + use wasi:io/poll@0.2.0.{pollable}; + 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: + /// - + /// - + /// - + /// - + resolve-addresses: func(network: borrow, name: string) -> result; + + 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) + 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. + subscribe: func() -> pollable; + } +} diff --git a/wit/deps/sockets/network.wit b/wit/deps/sockets/network.wit new file mode 100644 index 0000000..9cadf06 --- /dev/null +++ b/wit/deps/sockets/network.wit @@ -0,0 +1,145 @@ + +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. + 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. + 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, + } + + enum ip-address-family { + /// Similar to `AF_INET` in POSIX. + ipv4, + + /// Similar to `AF_INET6` in POSIX. + ipv6, + } + + type ipv4-address = tuple; + type ipv6-address = tuple; + + variant ip-address { + ipv4(ipv4-address), + ipv6(ipv6-address), + } + + record ipv4-socket-address { + /// sin_port + port: u16, + /// sin_addr + address: ipv4-address, + } + + record ipv6-socket-address { + /// sin6_port + port: u16, + /// sin6_flowinfo + flow-info: u32, + /// sin6_addr + address: ipv6-address, + /// sin6_scope_id + scope-id: u32, + } + + 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 new file mode 100644 index 0000000..c7ddf1f --- /dev/null +++ b/wit/deps/sockets/tcp-create-socket.wit @@ -0,0 +1,27 @@ + +interface tcp-create-socket { + use network.{network, error-code, ip-address-family}; + 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 + /// - + /// - + /// - + /// - + create-tcp-socket: func(address-family: ip-address-family) -> result; +} diff --git a/wit/deps/sockets/tcp.wit b/wit/deps/sockets/tcp.wit new file mode 100644 index 0000000..5902b9e --- /dev/null +++ b/wit/deps/sockets/tcp.wit @@ -0,0 +1,353 @@ + +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}; + use network.{network, error-code, ip-socket-address, ip-address-family}; + + 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 a 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 { + /// 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>; + finish-bind: func() -> result<_, error-code>; + + /// Connect to a remote endpoint. + /// + /// On success: + /// - the socket is transitioned into the `connection` 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>; + 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 + /// - + /// - + /// - + /// - + start-listen: func() -> result<_, error-code>; + 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 + /// - + /// - + /// - + /// - + 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 + /// - + /// - + /// - + /// - + local-address: func() -> result; + + /// Get the remote address. + /// + /// # Typical errors + /// - `invalid-state`: The socket is not connected to a remote address. (ENOTCONN) + /// + /// # References + /// - + /// - + /// - + /// - + remote-address: func() -> result; + + /// Whether the socket is in the `listening` state. + /// + /// Equivalent to the SO_ACCEPTCONN socket option. + is-listening: func() -> bool; + + /// Whether this is a IPv4 or IPv6 socket. + /// + /// Equivalent to the SO_DOMAIN socket option. + 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. + 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. + keep-alive-enabled: func() -> result; + 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. + keep-alive-idle-time: func() -> result; + 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. + keep-alive-interval: func() -> result; + 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. + keep-alive-count: func() -> result; + 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. + hop-limit: func() -> result; + 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. + receive-buffer-size: func() -> result; + set-receive-buffer-size: func(value: u64) -> result<_, error-code>; + send-buffer-size: func() -> result; + 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 a 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; + + /// 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 a 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>; + } +} diff --git a/wit/deps/sockets/udp-create-socket.wit b/wit/deps/sockets/udp-create-socket.wit new file mode 100644 index 0000000..0482d1f --- /dev/null +++ b/wit/deps/sockets/udp-create-socket.wit @@ -0,0 +1,27 @@ + +interface udp-create-socket { + use network.{network, error-code, ip-address-family}; + 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: + /// - + /// - + /// - + /// - + create-udp-socket: func(address-family: ip-address-family) -> result; +} diff --git a/wit/deps/sockets/udp.wit b/wit/deps/sockets/udp.wit new file mode 100644 index 0000000..d987a0a --- /dev/null +++ b/wit/deps/sockets/udp.wit @@ -0,0 +1,266 @@ + +interface udp { + use wasi:io/poll@0.2.0.{pollable}; + use network.{network, error-code, ip-socket-address, ip-address-family}; + + /// A received datagram. + 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. + 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. + 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 + /// - + /// - + /// - + /// - + start-bind: func(network: borrow, local-address: ip-socket-address) -> result<_, error-code>; + 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 + /// - + /// - + /// - + /// - + %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 + /// - + /// - + /// - + /// - + 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 + /// - + /// - + /// - + /// - + remote-address: func() -> result; + + /// Whether this is a IPv4 or IPv6 socket. + /// + /// Equivalent to the SO_DOMAIN socket option. + 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. + unicast-hop-limit: func() -> result; + 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. + receive-buffer-size: func() -> result; + set-receive-buffer-size: func(value: u64) -> result<_, error-code>; + send-buffer-size: func() -> result; + 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. + subscribe: func() -> pollable; + } + + 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 + /// - + /// - + /// - + /// - + /// - + /// - + /// - + /// - + 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. + subscribe: func() -> pollable; + } + + 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 + /// - + /// - + /// - + /// - + /// - + /// - + /// - + /// - + 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. + subscribe: func() -> pollable; + } +} diff --git a/wit/deps/sockets/world.wit b/wit/deps/sockets/world.wit new file mode 100644 index 0000000..f8bb92a --- /dev/null +++ b/wit/deps/sockets/world.wit @@ -0,0 +1,11 @@ +package wasi:sockets@0.2.0; + +world imports { + import instance-network; + import network; + import udp; + import udp-create-socket; + import tcp; + import tcp-create-socket; + import ip-name-lookup; +} diff --git a/wit/west.wit b/wit/west.wit new file mode 100644 index 0000000..b0d2aea --- /dev/null +++ b/wit/west.wit @@ -0,0 +1,108 @@ +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; +} + +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; +}