From cad0e94d5be00fa31939bc0b282e2457a771f7f1 Mon Sep 17 00:00:00 2001 From: Ryan Levick Date: Tue, 3 Sep 2024 12:15:16 +0200 Subject: [PATCH 1/6] Update Rust composition example Signed-off-by: Ryan Levick --- examples/rust/Cargo.lock | 175 ++-- examples/rust/Cargo.toml | 11 +- examples/rust/README.md | 6 +- examples/rust/compose.yml | 7 - examples/rust/spin.toml | 2 +- examples/rust/src/bindings.rs | 18 + examples/rust/src/lib.rs | 19 +- examples/wit/command-extended.wit | 56 +- examples/wit/delegate.wit | 2 +- examples/wit/deps/cli-2023-10-18/command.wit | 7 + .../wit/deps/cli-2023-10-18/environment.wit | 18 + examples/wit/deps/cli-2023-10-18/exit.wit | 4 + .../deps/{cli => cli-2023-10-18}/reactor.wit | 0 examples/wit/deps/cli-2023-10-18/run.wit | 4 + examples/wit/deps/cli-2023-10-18/stdio.wit | 17 + examples/wit/deps/cli-2023-10-18/terminal.wit | 47 + examples/wit/deps/cli-2023-11-10/command.wit | 7 + .../wit/deps/cli-2023-11-10/environment.wit | 18 + examples/wit/deps/cli-2023-11-10/exit.wit | 4 + examples/wit/deps/cli-2023-11-10/reactor.wit | 31 + examples/wit/deps/cli-2023-11-10/run.wit | 4 + examples/wit/deps/cli-2023-11-10/stdio.wit | 17 + examples/wit/deps/cli-2023-11-10/terminal.wit | 47 + examples/wit/deps/cli/command.wit | 4 +- examples/wit/deps/cli/imports.wit | 20 + examples/wit/deps/cli/stdio.wit | 6 +- examples/wit/deps/cli/terminal.wit | 18 +- .../clocks-2023-10-18/monotonic-clock.wit | 32 + .../timezone.wit | 0 .../wit/deps/clocks-2023-10-18/wall-clock.wit | 41 + examples/wit/deps/clocks-2023-10-18/world.wit | 7 + .../clocks-2023-11-10/monotonic-clock.wit | 45 + .../wit/deps/clocks-2023-11-10/wall-clock.wit | 42 + examples/wit/deps/clocks-2023-11-10/world.wit | 6 + examples/wit/deps/clocks/monotonic-clock.wit | 29 +- examples/wit/deps/clocks/wall-clock.wit | 1 + examples/wit/deps/clocks/world.wit | 3 +- .../deps/filesystem-2023-10-18/preopens.wit | 6 + .../wit/deps/filesystem-2023-10-18/types.wit | 810 ++++++++++++++++++ .../wit/deps/filesystem-2023-10-18/world.wit | 6 + .../deps/filesystem-2023-11-10/preopens.wit | 8 + .../wit/deps/filesystem-2023-11-10/types.wit | 634 ++++++++++++++ .../wit/deps/filesystem-2023-11-10/world.wit | 6 + examples/wit/deps/filesystem/preopens.wit | 2 + examples/wit/deps/filesystem/types.wit | 182 +--- examples/wit/deps/filesystem/world.wit | 2 +- .../incoming-handler.wit | 0 .../outgoing-handler.wit | 0 examples/wit/deps/http-2023-10-18/proxy.wit | 34 + examples/wit/deps/http-2023-10-18/types.wit | 208 +++++ examples/wit/deps/http-2023-11-10/handler.wit | 43 + examples/wit/deps/http-2023-11-10/proxy.wit | 33 + examples/wit/deps/http-2023-11-10/types.wit | 559 ++++++++++++ examples/wit/deps/http/handler.wit | 43 + examples/wit/deps/http/proxy.wit | 48 +- examples/wit/deps/http/types.wit | 610 ++++++++++--- examples/wit/deps/io-2023-10-18/poll.wit | 32 + examples/wit/deps/io-2023-10-18/streams.wit | 287 +++++++ examples/wit/deps/io-2023-10-18/world.wit | 1 + examples/wit/deps/io-2023-11-10/error.wit | 34 + examples/wit/deps/io-2023-11-10/poll.wit | 41 + examples/wit/deps/io-2023-11-10/streams.wit | 251 ++++++ examples/wit/deps/io-2023-11-10/world.wit | 6 + examples/wit/deps/io/error.wit | 34 + examples/wit/deps/io/poll.wit | 27 +- examples/wit/deps/io/streams.wit | 123 ++- examples/wit/deps/io/world.wit | 2 +- examples/wit/deps/logging/logging.wit | 37 - examples/wit/deps/logging/world.wit | 5 - .../deps/random-2023-10-18/insecure-seed.wit | 24 + .../wit/deps/random-2023-10-18/insecure.wit | 21 + .../wit/deps/random-2023-10-18/random.wit | 25 + examples/wit/deps/random-2023-10-18/world.wit | 7 + .../deps/random-2023-11-10/insecure-seed.wit | 25 + .../wit/deps/random-2023-11-10/insecure.wit | 22 + .../wit/deps/random-2023-11-10/random.wit | 26 + examples/wit/deps/random-2023-11-10/world.wit | 7 + examples/wit/deps/random/insecure-seed.wit | 1 + examples/wit/deps/random/insecure.wit | 1 + examples/wit/deps/random/random.wit | 1 + examples/wit/deps/random/world.wit | 2 +- .../sockets-2023-10-18/instance-network.wit | 9 + .../sockets-2023-10-18/ip-name-lookup.wit | 61 ++ .../wit/deps/sockets-2023-10-18/network.wit | 146 ++++ .../sockets-2023-10-18/tcp-create-socket.wit | 26 + examples/wit/deps/sockets-2023-10-18/tcp.wit | 268 ++++++ .../sockets-2023-10-18/udp-create-socket.wit | 26 + examples/wit/deps/sockets-2023-10-18/udp.wit | 213 +++++ .../wit/deps/sockets-2023-10-18/world.wit | 11 + .../sockets-2023-11-10/instance-network.wit | 9 + .../sockets-2023-11-10/ip-name-lookup.wit | 51 ++ .../wit/deps/sockets-2023-11-10/network.wit | 147 ++++ .../sockets-2023-11-10/tcp-create-socket.wit | 26 + examples/wit/deps/sockets-2023-11-10/tcp.wit | 321 +++++++ .../sockets-2023-11-10/udp-create-socket.wit | 26 + examples/wit/deps/sockets-2023-11-10/udp.wit | 277 ++++++ .../wit/deps/sockets-2023-11-10/world.wit | 11 + .../wit/deps/sockets/instance-network.wit | 6 +- examples/wit/deps/sockets/ip-name-lookup.wit | 98 +-- examples/wit/deps/sockets/network.wit | 271 +++--- .../wit/deps/sockets/tcp-create-socket.wit | 45 +- examples/wit/deps/sockets/tcp.wit | 577 +++++++------ .../wit/deps/sockets/udp-create-socket.wit | 45 +- examples/wit/deps/sockets/udp.wit | 473 +++++----- examples/wit/deps/sockets/world.wit | 2 +- examples/wit/deps/spin@unversioned/config.wit | 12 + .../wit/deps/spin@unversioned/http-types.wit | 44 + examples/wit/deps/spin@unversioned/http.wit | 5 + .../deps/spin@unversioned/inbound-http.wit | 5 + .../deps/spin@unversioned/inbound-redis.wit | 6 + .../wit/deps/spin@unversioned/key-value.wit | 80 ++ examples/wit/deps/spin@unversioned/llm.wit | 70 ++ examples/wit/deps/spin@unversioned/mysql.wit | 19 + .../wit/deps/spin@unversioned/postgres.wit | 19 + .../wit/deps/spin@unversioned/rdbms-types.wit | 65 ++ .../wit/deps/spin@unversioned/redis-types.wit | 24 + examples/wit/deps/spin@unversioned/redis.wit | 31 + examples/wit/deps/spin@unversioned/sqlite.wit | 52 ++ examples/wit/deps/spin@unversioned/world.wit | 29 + examples/wit/main.wit | 53 +- examples/wit/proxy.wit | 4 +- examples/wit/test.wit | 56 +- src/bindings.rs | 18 + 123 files changed, 7412 insertions(+), 1376 deletions(-) delete mode 100644 examples/rust/compose.yml create mode 100644 examples/rust/src/bindings.rs create mode 100644 examples/wit/deps/cli-2023-10-18/command.wit create mode 100644 examples/wit/deps/cli-2023-10-18/environment.wit create mode 100644 examples/wit/deps/cli-2023-10-18/exit.wit rename examples/wit/deps/{cli => cli-2023-10-18}/reactor.wit (100%) create mode 100644 examples/wit/deps/cli-2023-10-18/run.wit create mode 100644 examples/wit/deps/cli-2023-10-18/stdio.wit create mode 100644 examples/wit/deps/cli-2023-10-18/terminal.wit create mode 100644 examples/wit/deps/cli-2023-11-10/command.wit create mode 100644 examples/wit/deps/cli-2023-11-10/environment.wit create mode 100644 examples/wit/deps/cli-2023-11-10/exit.wit create mode 100644 examples/wit/deps/cli-2023-11-10/reactor.wit create mode 100644 examples/wit/deps/cli-2023-11-10/run.wit create mode 100644 examples/wit/deps/cli-2023-11-10/stdio.wit create mode 100644 examples/wit/deps/cli-2023-11-10/terminal.wit create mode 100644 examples/wit/deps/cli/imports.wit create mode 100644 examples/wit/deps/clocks-2023-10-18/monotonic-clock.wit rename examples/wit/deps/{clocks => clocks-2023-10-18}/timezone.wit (100%) create mode 100644 examples/wit/deps/clocks-2023-10-18/wall-clock.wit create mode 100644 examples/wit/deps/clocks-2023-10-18/world.wit create mode 100644 examples/wit/deps/clocks-2023-11-10/monotonic-clock.wit create mode 100644 examples/wit/deps/clocks-2023-11-10/wall-clock.wit create mode 100644 examples/wit/deps/clocks-2023-11-10/world.wit create mode 100644 examples/wit/deps/filesystem-2023-10-18/preopens.wit create mode 100644 examples/wit/deps/filesystem-2023-10-18/types.wit create mode 100644 examples/wit/deps/filesystem-2023-10-18/world.wit create mode 100644 examples/wit/deps/filesystem-2023-11-10/preopens.wit create mode 100644 examples/wit/deps/filesystem-2023-11-10/types.wit create mode 100644 examples/wit/deps/filesystem-2023-11-10/world.wit rename examples/wit/deps/{http => http-2023-10-18}/incoming-handler.wit (100%) rename examples/wit/deps/{http => http-2023-10-18}/outgoing-handler.wit (100%) create mode 100644 examples/wit/deps/http-2023-10-18/proxy.wit create mode 100644 examples/wit/deps/http-2023-10-18/types.wit create mode 100644 examples/wit/deps/http-2023-11-10/handler.wit create mode 100644 examples/wit/deps/http-2023-11-10/proxy.wit create mode 100644 examples/wit/deps/http-2023-11-10/types.wit create mode 100644 examples/wit/deps/http/handler.wit create mode 100644 examples/wit/deps/io-2023-10-18/poll.wit create mode 100644 examples/wit/deps/io-2023-10-18/streams.wit create mode 100644 examples/wit/deps/io-2023-10-18/world.wit create mode 100644 examples/wit/deps/io-2023-11-10/error.wit create mode 100644 examples/wit/deps/io-2023-11-10/poll.wit create mode 100644 examples/wit/deps/io-2023-11-10/streams.wit create mode 100644 examples/wit/deps/io-2023-11-10/world.wit create mode 100644 examples/wit/deps/io/error.wit delete mode 100644 examples/wit/deps/logging/logging.wit delete mode 100644 examples/wit/deps/logging/world.wit create mode 100644 examples/wit/deps/random-2023-10-18/insecure-seed.wit create mode 100644 examples/wit/deps/random-2023-10-18/insecure.wit create mode 100644 examples/wit/deps/random-2023-10-18/random.wit create mode 100644 examples/wit/deps/random-2023-10-18/world.wit create mode 100644 examples/wit/deps/random-2023-11-10/insecure-seed.wit create mode 100644 examples/wit/deps/random-2023-11-10/insecure.wit create mode 100644 examples/wit/deps/random-2023-11-10/random.wit create mode 100644 examples/wit/deps/random-2023-11-10/world.wit create mode 100644 examples/wit/deps/sockets-2023-10-18/instance-network.wit create mode 100644 examples/wit/deps/sockets-2023-10-18/ip-name-lookup.wit create mode 100644 examples/wit/deps/sockets-2023-10-18/network.wit create mode 100644 examples/wit/deps/sockets-2023-10-18/tcp-create-socket.wit create mode 100644 examples/wit/deps/sockets-2023-10-18/tcp.wit create mode 100644 examples/wit/deps/sockets-2023-10-18/udp-create-socket.wit create mode 100644 examples/wit/deps/sockets-2023-10-18/udp.wit create mode 100644 examples/wit/deps/sockets-2023-10-18/world.wit create mode 100644 examples/wit/deps/sockets-2023-11-10/instance-network.wit create mode 100644 examples/wit/deps/sockets-2023-11-10/ip-name-lookup.wit create mode 100644 examples/wit/deps/sockets-2023-11-10/network.wit create mode 100644 examples/wit/deps/sockets-2023-11-10/tcp-create-socket.wit create mode 100644 examples/wit/deps/sockets-2023-11-10/tcp.wit create mode 100644 examples/wit/deps/sockets-2023-11-10/udp-create-socket.wit create mode 100644 examples/wit/deps/sockets-2023-11-10/udp.wit create mode 100644 examples/wit/deps/sockets-2023-11-10/world.wit create mode 100644 examples/wit/deps/spin@unversioned/config.wit create mode 100644 examples/wit/deps/spin@unversioned/http-types.wit create mode 100644 examples/wit/deps/spin@unversioned/http.wit create mode 100644 examples/wit/deps/spin@unversioned/inbound-http.wit create mode 100644 examples/wit/deps/spin@unversioned/inbound-redis.wit create mode 100644 examples/wit/deps/spin@unversioned/key-value.wit create mode 100644 examples/wit/deps/spin@unversioned/llm.wit create mode 100644 examples/wit/deps/spin@unversioned/mysql.wit create mode 100644 examples/wit/deps/spin@unversioned/postgres.wit create mode 100644 examples/wit/deps/spin@unversioned/rdbms-types.wit create mode 100644 examples/wit/deps/spin@unversioned/redis-types.wit create mode 100644 examples/wit/deps/spin@unversioned/redis.wit create mode 100644 examples/wit/deps/spin@unversioned/sqlite.wit create mode 100644 examples/wit/deps/spin@unversioned/world.wit create mode 100644 src/bindings.rs diff --git a/examples/rust/Cargo.lock b/examples/rust/Cargo.lock index 3f0907b..061360c 100644 --- a/examples/rust/Cargo.lock +++ b/examples/rust/Cargo.lock @@ -16,7 +16,7 @@ checksum = "a66537f1bb974b254c98ed142ff995236e81b9d0fe4db0575f46612cb15eb0f9" dependencies = [ "proc-macro2", "quote", - "syn 2.0.38", + "syn 2.0.77", ] [[package]] @@ -37,27 +37,6 @@ version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a2bd12c1caf447e69cd4528f47f94d203fd2582878ecb9e9465484c4148a8223" -[[package]] -name = "cargo-component-bindings" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2c93fc8ee50afcd1b61250ede654a5776c58a24a7cf71a899f64f1b5b5be4ab9" -dependencies = [ - "cargo-component-macro", - "wit-bindgen", -] - -[[package]] -name = "cargo-component-macro" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0ae9626a6422ce81803eebd1d84fdc03426fe3951fe54f3094d0d2c2a2174727" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.38", -] - [[package]] name = "equivalent" version = "1.0.1" @@ -81,9 +60,9 @@ dependencies = [ [[package]] name = "futures" -version = "0.3.28" +version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "23342abe12aba583913b2e62f22225ff9c950774065e4bfb61a19cd9770fec40" +checksum = "645c6916888f6cb6350d2550b80fb63e734897a8498abe35cfb732b6487804b0" dependencies = [ "futures-channel", "futures-core", @@ -96,9 +75,9 @@ dependencies = [ [[package]] name = "futures-channel" -version = "0.3.28" +version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "955518d47e09b25bbebc7a18df10b81f0c766eaf4c4f1cccef2fca5f2a4fb5f2" +checksum = "eac8f7d7865dcb88bd4373ab671c8cf4508703796caa2b1985a9ca867b3fcb78" dependencies = [ "futures-core", "futures-sink", @@ -106,15 +85,15 @@ dependencies = [ [[package]] name = "futures-core" -version = "0.3.28" +version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4bca583b7e26f571124fe5b7561d49cb2868d79116cfa0eefce955557c6fee8c" +checksum = "dfc6580bb841c5a68e9ef15c77ccc837b40a7504914d52e47b8b0e9bbda25a1d" [[package]] name = "futures-executor" -version = "0.3.28" +version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ccecee823288125bd88b4d7f565c9e58e41858e47ab72e8ea2d64e93624386e0" +checksum = "a576fc72ae164fca6b9db127eaa9a9dda0d61316034f33a0a0d4eda41f02b01d" dependencies = [ "futures-core", "futures-task", @@ -123,38 +102,38 @@ dependencies = [ [[package]] name = "futures-io" -version = "0.3.28" +version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4fff74096e71ed47f8e023204cfd0aa1289cd54ae5430a9523be060cdb849964" +checksum = "a44623e20b9681a318efdd71c299b6b222ed6f231972bfe2f224ebad6311f0c1" [[package]] name = "futures-macro" -version = "0.3.28" +version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "89ca545a94061b6365f2c7355b4b32bd20df3ff95f02da9329b34ccc3bd6ee72" +checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" dependencies = [ "proc-macro2", "quote", - "syn 2.0.38", + "syn 2.0.77", ] [[package]] name = "futures-sink" -version = "0.3.28" +version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f43be4fe21a13b9781a69afa4985b0f6ee0e1afab2c6f454a8cf30e2b2237b6e" +checksum = "9fb8e00e87438d937621c1c6269e53f536c14d3fbd6a042bb24879e57d474fb5" [[package]] name = "futures-task" -version = "0.3.28" +version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "76d3d132be6c0e6aa1534069c705a74a5997a356c0dc2f86a47765e5617c5b65" +checksum = "38d84fa142264698cdce1a9f9172cf383a0c82de1bddcf3092901442c4097004" [[package]] name = "futures-util" -version = "0.3.28" +version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "26b01e40b772d54cf6c6d721c1d1abd0647a0106a12ecaa1c186273392a69533" +checksum = "3d6401deb83407ab3da39eba7e33987a73c3df0c82b4bb5813ee871c19c41d48" dependencies = [ "futures-channel", "futures-core", @@ -170,9 +149,9 @@ dependencies = [ [[package]] name = "hashbrown" -version = "0.14.2" +version = "0.14.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f93e7192158dbcda357bdec5fb5788eebf8bbac027f3f33e719d29135ae84156" +checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1" [[package]] name = "heck" @@ -185,9 +164,9 @@ dependencies = [ [[package]] name = "http" -version = "0.2.9" +version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bd6effc99afb63425aff9b05836f029929e345a6148a14b7ecd5ab67af944482" +checksum = "21b9ddb458710bc376481b842f5da65cdf31522de232c1ca8146abce2a358258" dependencies = [ "bytes", "fnv", @@ -261,18 +240,18 @@ checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" [[package]] name = "proc-macro2" -version = "1.0.69" +version = "1.0.86" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "134c189feb4956b20f6f547d2cf727d4c0fe06722b20a0eec87ed445a97f92da" +checksum = "5e719e8df665df0d1c8fbfd238015744736151d4445ec0836b8e628aae103b77" dependencies = [ "unicode-ident", ] [[package]] name = "quote" -version = "1.0.33" +version = "1.0.37" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5267fca4496028628a95160fc423a33e8b2e6af8a5302579e322e4b520293cae" +checksum = "b5b9d34b8991d19d98081b46eacdd8eb58c6f2b201139f7c5f643cc155a633af" dependencies = [ "proc-macro2", ] @@ -316,7 +295,7 @@ checksum = "1e48d1f918009ce3145511378cf68d613e3b3d9137d67272562080d68a2b32d5" dependencies = [ "proc-macro2", "quote", - "syn 2.0.38", + "syn 2.0.77", ] [[package]] @@ -374,11 +353,21 @@ dependencies = [ "smallvec", ] +[[package]] +name = "spin-executor" +version = "3.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2df1a5e2cc70a628c9ea6914770c234cc4a292218091e6707ae8be68b4a5de76" +dependencies = [ + "futures", + "once_cell", + "wit-bindgen", +] + [[package]] name = "spin-fileserver-example" version = "0.1.0" dependencies = [ - "cargo-component-bindings", "futures", "spin-sdk", "wit-bindgen", @@ -386,12 +375,12 @@ dependencies = [ [[package]] name = "spin-macro" -version = "0.1.0" -source = "git+https://github.com/fermyon/spin#671f5998b2ce70976c3a26c6502e71b0b79cd35a" +version = "3.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ef3d03e5a205a641d85ace3af1604b39dba63d3ffe3865a71bda02fb482ae60a" dependencies = [ "anyhow", "bytes", - "http", "proc-macro2", "quote", "syn 1.0.109", @@ -399,8 +388,9 @@ dependencies = [ [[package]] name = "spin-sdk" -version = "2.0.0-pre0" -source = "git+https://github.com/fermyon/spin#671f5998b2ce70976c3a26c6502e71b0b79cd35a" +version = "3.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed97f54a15f2d8b1fa15e436d88bacb95a5b379a3e0f8fbd8042eb8696ca048a" dependencies = [ "anyhow", "async-trait", @@ -412,6 +402,7 @@ dependencies = [ "routefinder", "serde", "serde_json", + "spin-executor", "spin-macro", "thiserror", "wit-bindgen", @@ -436,9 +427,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.38" +version = "2.0.77" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e96b79aaa137db8f61e26363a0c9b47d8b4ec75da28b7d1d614c2303e232408b" +checksum = "9f35bcdf61fd8e7be6caf75f429fdca8beb3ed76584befb503b1569faee373ed" dependencies = [ "proc-macro2", "quote", @@ -462,7 +453,7 @@ checksum = "266b2e40bc00e5a6c09c3584011e08b06f123c00362c92b975ba9843aaaa14b8" dependencies = [ "proc-macro2", "quote", - "syn 2.0.38", + "syn 2.0.77", ] [[package]] @@ -491,18 +482,27 @@ checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" [[package]] name = "wasm-encoder" -version = "0.35.0" +version = "0.38.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0ad2b51884de9c7f4fe2fd1043fccb8dcad4b1e29558146ee57a144d15779f3f" +dependencies = [ + "leb128", +] + +[[package]] +name = "wasm-encoder" +version = "0.41.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9ca90ba1b5b0a70d3d49473c5579951f3bddc78d47b59256d2f9d4922b150aca" +checksum = "972f97a5d8318f908dded23594188a90bcd09365986b1163e66d70170e5287ae" dependencies = [ "leb128", ] [[package]] name = "wasm-metadata" -version = "0.10.9" +version = "0.10.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "14abc161bfda5b519aa229758b68f2a52b45a12b993808665c857d1a9a00223c" +checksum = "18ebaa7bd0f9e7a5e5dd29b9a998acf21c4abed74265524dd7e85934597bfb10" dependencies = [ "anyhow", "indexmap", @@ -510,25 +510,36 @@ dependencies = [ "serde_derive", "serde_json", "spdx", - "wasm-encoder", - "wasmparser", + "wasm-encoder 0.41.2", + "wasmparser 0.121.2", ] [[package]] name = "wasmparser" -version = "0.115.0" +version = "0.118.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e06c0641a4add879ba71ccb3a1e4278fd546f76f1eafb21d8f7b07733b547cd5" +checksum = "77f1154f1ab868e2a01d9834a805faca7bf8b50d041b4ca714d005d0dab1c50c" dependencies = [ "indexmap", "semver", ] +[[package]] +name = "wasmparser" +version = "0.121.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9dbe55c8f9d0dbd25d9447a5a889ff90c0cc3feaa7395310d3d826b2c703eaab" +dependencies = [ + "bitflags", + "indexmap", + "semver", +] + [[package]] name = "wit-bindgen" -version = "0.13.0" +version = "0.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c7d92ce0ca6b6074059413a9581a637550c3a740581c854f9847ec293c8aed71" +checksum = "b76f1d099678b4f69402a421e888bbe71bf20320c2f3f3565d0e7484dbe5bc20" dependencies = [ "bitflags", "wit-bindgen-rust-macro", @@ -536,9 +547,9 @@ dependencies = [ [[package]] name = "wit-bindgen-core" -version = "0.13.0" +version = "0.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "565b945ae074886071eccf9cdaf8ccd7b959c2b0d624095bea5fe62003e8b3e0" +checksum = "75d55e1a488af2981fb0edac80d8d20a51ac36897a1bdef4abde33c29c1b6d0d" dependencies = [ "anyhow", "wit-component", @@ -547,9 +558,9 @@ dependencies = [ [[package]] name = "wit-bindgen-rust" -version = "0.13.1" +version = "0.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "92a75f1427fe517d6476e95d5f1b90415273eac83b5a077fcce07920116959f0" +checksum = "a01ff9cae7bf5736750d94d91eb8a49f5e3a04aff1d1a3218287d9b2964510f8" dependencies = [ "anyhow", "heck", @@ -560,14 +571,14 @@ dependencies = [ [[package]] name = "wit-bindgen-rust-macro" -version = "0.13.0" +version = "0.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a91835ea4231da1fe7971679d505ba14be7826e192b6357f08465866ef482e08" +checksum = "804a98e2538393d47aa7da65a7348116d6ff403b426665152b70a168c0146d49" dependencies = [ "anyhow", "proc-macro2", "quote", - "syn 2.0.38", + "syn 2.0.77", "wit-bindgen-core", "wit-bindgen-rust", "wit-component", @@ -575,9 +586,9 @@ dependencies = [ [[package]] name = "wit-component" -version = "0.16.0" +version = "0.18.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e87488b57a08e2cbbd076b325acbe7f8666965af174d69d5929cd373bd54547f" +checksum = "5b8a35a2a9992898c9d27f1664001860595a4bc99d32dd3599d547412e17d7e2" dependencies = [ "anyhow", "bitflags", @@ -586,17 +597,17 @@ dependencies = [ "serde", "serde_derive", "serde_json", - "wasm-encoder", + "wasm-encoder 0.38.1", "wasm-metadata", - "wasmparser", + "wasmparser 0.118.2", "wit-parser", ] [[package]] name = "wit-parser" -version = "0.12.1" +version = "0.13.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f6ace9943d89bbf3dbbc71b966da0e7302057b311f36a4ac3d65ddfef17b52cf" +checksum = "316b36a9f0005f5aa4b03c39bc3728d045df136f8c13a73b7db4510dec725e08" dependencies = [ "anyhow", "id-arena", diff --git a/examples/rust/Cargo.toml b/examples/rust/Cargo.toml index eb4f48d..505c5a7 100644 --- a/examples/rust/Cargo.toml +++ b/examples/rust/Cargo.toml @@ -6,14 +6,9 @@ edition = "2021" [lib] crate-type = ["cdylib"] -[package.metadata.component] -package = "component:spin-fileserver-example" -adapter = "../../adapters/fd1e948d/wasi_snapshot_preview1.reactor.wasm" - [dependencies] -cargo-component-bindings = "0.4.0" -wit-bindgen = "0.13.0" -spin-sdk = { git = "https://github.com/fermyon/spin" } -futures = "0.3.28" +wit-bindgen = "0.16.0" +spin-sdk = "3.0.1" +futures = "0.3.30" [workspace] diff --git a/examples/rust/README.md b/examples/rust/README.md index e5fd17a..27fdf79 100644 --- a/examples/rust/README.md +++ b/examples/rust/README.md @@ -11,8 +11,7 @@ component for serving static files. - [Spin v2.0+](https://developer.fermyon.com/spin/install) - [Rust](https://rustup.rs/), including the `wasm32-wasi` target - [cargo-component](https://github.com/bytecodealliance/cargo-component) -- [wasm-tools](https://github.com/bytecodealliance/wasm-tools/) - - Note that you'll need [this fork](https://github.com/dicej/wasm-tools/tree/wasm-compose-resource-imports) until [this PR](https://github.com/bytecodealliance/wasm-tools/pull/1261) has been merged and released. +- [wac](https://github.com/bytecodealliance/wac) - [curl](https://curl.se/download.html) or a web browser for testing Once you have Rust installed, the following should give you everything else: @@ -20,8 +19,7 @@ Once you have Rust installed, the following should give you everything else: ```shell rustup target add wasm32-wasi cargo install cargo-component -cargo install --locked --git https://github.com/dicej/wasm-tools \ - --branch wasm-compose-resource-imports wasm-tools +cargo install wac-cli ``` ## Building and Running diff --git a/examples/rust/compose.yml b/examples/rust/compose.yml deleted file mode 100644 index ac83a85..0000000 --- a/examples/rust/compose.yml +++ /dev/null @@ -1,7 +0,0 @@ -search-paths: - - ../../target/wasm32-wasi/release - -instantiations: - $input: - arguments: - wasi:http/incoming-handler@0.2.0-rc-2023-10-18: spin_static_fs diff --git a/examples/rust/spin.toml b/examples/rust/spin.toml index 9c94b2c..ea2e412 100644 --- a/examples/rust/spin.toml +++ b/examples/rust/spin.toml @@ -14,5 +14,5 @@ component = "spin-fileserver-example" source = "target/wasm32-wasi/release/composed.wasm" files = [{ source = "../static", destination = "/" }] [component.spin-fileserver-example.build] -command = "cargo component build --release && (cd .. && cargo component build --release) && RUST_LOG=error wasm-tools compose target/wasm32-wasi/release/spin_fileserver_example.wasm -c compose.yml -o target/wasm32-wasi/release/composed.wasm" +command = "cargo component build --release && (cd .. && cargo component build --release) && RUST_LOG=error wac plug --plug ../../target/wasm32-wasi/release/spin_static_fs.wasm target/wasm32-wasi/release/spin_fileserver_example.wasm -o target/wasm32-wasi/release/composed.wasm" watch = ["src/**/*.rs", "Cargo.toml"] diff --git a/examples/rust/src/bindings.rs b/examples/rust/src/bindings.rs new file mode 100644 index 0000000..e3292cc --- /dev/null +++ b/examples/rust/src/bindings.rs @@ -0,0 +1,18 @@ +// Generated by `wit-bindgen` 0.25.0. DO NOT EDIT! +// Options used: + +#[cfg(target_arch = "wasm32")] +#[link_section = "component-type:wit-bindgen:0.25.0:spin-fileserver-example:encoded world"] +#[doc(hidden)] +pub static __WIT_BINDGEN_COMPONENT_TYPE: [u8; 209] = *b"\ +\0asm\x0d\0\x01\0\0\x19\x16wit-component-encoding\x04\0\x07D\x01A\x02\x01A\0\x04\ +\x019component:spin-fileserver-example/spin-fileserver-example\x04\0\x0b\x1d\x01\ +\0\x17spin-fileserver-example\x03\0\0\0G\x09producers\x01\x0cprocessed-by\x02\x0d\ +wit-component\x070.208.1\x10wit-bindgen-rust\x060.25.0"; + +#[inline(never)] +#[doc(hidden)] +#[cfg(target_arch = "wasm32")] +pub fn __link_custom_section_describing_imports() { + wit_bindgen_rt::maybe_link_cabi_realloc(); +} diff --git a/examples/rust/src/lib.rs b/examples/rust/src/lib.rs index 886f843..8f36ef7 100644 --- a/examples/rust/src/lib.rs +++ b/examples/rust/src/lib.rs @@ -1,5 +1,5 @@ use { - bindings::wasi::http::incoming_handler, + bindings::wasi::http0_2_0::incoming_handler, futures::SinkExt, spin_sdk::{ http::{Fields, IncomingRequest, Method, OutgoingResponse, ResponseOutparam}, @@ -12,9 +12,7 @@ mod bindings { path: "../wit", world: "delegate", with: { - "wasi:http/types@0.2.0-rc-2023-10-18": spin_sdk::wit::wasi::http::types, - "wasi:io/streams@0.2.0-rc-2023-10-18": spin_sdk::wit::wasi::io::streams, - "wasi:io/poll@0.2.0-rc-2023-10-18": spin_sdk::wit::wasi::io, + "wasi:http/types@0.2.0": ::spin_sdk::wit::wasi::http::types, } }); } @@ -23,10 +21,11 @@ mod bindings { async fn handle_request(request: IncomingRequest, response_out: ResponseOutparam) { match (request.method(), request.path_with_query().as_deref()) { (Method::Get, Some("/hello")) => { - let response = OutgoingResponse::new( - 200, - &Fields::new(&[("content-type".to_string(), b"text/plain".to_vec())]), - ); + let fields = Fields::new(); + fields + .append(&"content-type".to_owned(), &b"text/plain".to_vec()) + .unwrap(); + let response = OutgoingResponse::new(fields); let mut body = response.take_body(); @@ -43,7 +42,9 @@ async fn handle_request(request: IncomingRequest, response_out: ResponseOutparam } _ => { - response_out.set(OutgoingResponse::new(405, &Fields::new(&[]))); + let response = OutgoingResponse::new(Fields::new()); + response.set_status_code(405).unwrap(); + response_out.set(response); } } } diff --git a/examples/wit/command-extended.wit b/examples/wit/command-extended.wit index 0661779..eb4fedd 100644 --- a/examples/wit/command-extended.wit +++ b/examples/wit/command-extended.wit @@ -1,37 +1,35 @@ // All of the same imports and exports available in the wasi:cli/command world // with addition of HTTP proxy related imports: world command-extended { - import wasi:clocks/wall-clock@0.2.0-rc-2023-10-18; - import wasi:clocks/monotonic-clock@0.2.0-rc-2023-10-18; - import wasi:clocks/timezone@0.2.0-rc-2023-10-18; - import wasi:filesystem/types@0.2.0-rc-2023-10-18; - import wasi:filesystem/preopens@0.2.0-rc-2023-10-18; - import wasi:sockets/instance-network@0.2.0-rc-2023-10-18; - import wasi:sockets/ip-name-lookup@0.2.0-rc-2023-10-18; - import wasi:sockets/network@0.2.0-rc-2023-10-18; - import wasi:sockets/tcp-create-socket@0.2.0-rc-2023-10-18; - import wasi:sockets/tcp@0.2.0-rc-2023-10-18; - import wasi:sockets/udp-create-socket@0.2.0-rc-2023-10-18; - import wasi:sockets/udp@0.2.0-rc-2023-10-18; - import wasi:random/random@0.2.0-rc-2023-10-18; - import wasi:random/insecure@0.2.0-rc-2023-10-18; - import wasi:random/insecure-seed@0.2.0-rc-2023-10-18; - import wasi:io/poll@0.2.0-rc-2023-10-18; - import wasi:io/streams@0.2.0-rc-2023-10-18; - import wasi:cli/environment@0.2.0-rc-2023-10-18; - import wasi:cli/exit@0.2.0-rc-2023-10-18; - import wasi:cli/stdin@0.2.0-rc-2023-10-18; - import wasi:cli/stdout@0.2.0-rc-2023-10-18; - import wasi:cli/stderr@0.2.0-rc-2023-10-18; - import wasi:cli/terminal-input@0.2.0-rc-2023-10-18; - import wasi:cli/terminal-output@0.2.0-rc-2023-10-18; - import wasi:cli/terminal-stdin@0.2.0-rc-2023-10-18; - import wasi:cli/terminal-stdout@0.2.0-rc-2023-10-18; - import wasi:cli/terminal-stderr@0.2.0-rc-2023-10-18; + import wasi:clocks/wall-clock@0.2.0; + import wasi:clocks/monotonic-clock@0.2.0; + import wasi:filesystem/types@0.2.0; + import wasi:filesystem/preopens@0.2.0; + import wasi:sockets/instance-network@0.2.0; + import wasi:sockets/ip-name-lookup@0.2.0; + import wasi:sockets/network@0.2.0; + import wasi:sockets/tcp-create-socket@0.2.0; + import wasi:sockets/tcp@0.2.0; + import wasi:sockets/udp-create-socket@0.2.0; + import wasi:sockets/udp@0.2.0; + import wasi:random/random@0.2.0; + import wasi:random/insecure@0.2.0; + import wasi:random/insecure-seed@0.2.0; + import wasi:io/poll@0.2.0; + import wasi:io/streams@0.2.0; + import wasi:cli/environment@0.2.0; + import wasi:cli/exit@0.2.0; + import wasi:cli/stdin@0.2.0; + import wasi:cli/stdout@0.2.0; + import wasi:cli/stderr@0.2.0; + import wasi:cli/terminal-input@0.2.0; + import wasi:cli/terminal-output@0.2.0; + import wasi:cli/terminal-stdin@0.2.0; + import wasi:cli/terminal-stdout@0.2.0; + import wasi:cli/terminal-stderr@0.2.0; // We should replace all others with `include self.command` // as soon as the unioning of worlds is available: // https://github.com/WebAssembly/component-model/issues/169 - import wasi:logging/logging@0.2.0-rc-2023-10-18; - import wasi:http/outgoing-handler@0.2.0-rc-2023-10-18; + import wasi:http/outgoing-handler@0.2.0; } diff --git a/examples/wit/delegate.wit b/examples/wit/delegate.wit index 5f90303..40edc0c 100644 --- a/examples/wit/delegate.wit +++ b/examples/wit/delegate.wit @@ -1,3 +1,3 @@ world delegate { - import wasi:http/incoming-handler@0.2.0-rc-2023-10-18; + import wasi:http/incoming-handler@0.2.0; } diff --git a/examples/wit/deps/cli-2023-10-18/command.wit b/examples/wit/deps/cli-2023-10-18/command.wit new file mode 100644 index 0000000..d7ea2d9 --- /dev/null +++ b/examples/wit/deps/cli-2023-10-18/command.wit @@ -0,0 +1,7 @@ +package wasi:cli@0.2.0-rc-2023-10-18; + +world command { + include reactor; + + export run; +} diff --git a/examples/wit/deps/cli-2023-10-18/environment.wit b/examples/wit/deps/cli-2023-10-18/environment.wit new file mode 100644 index 0000000..7006523 --- /dev/null +++ b/examples/wit/deps/cli-2023-10-18/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/examples/wit/deps/cli-2023-10-18/exit.wit b/examples/wit/deps/cli-2023-10-18/exit.wit new file mode 100644 index 0000000..d0c2b82 --- /dev/null +++ b/examples/wit/deps/cli-2023-10-18/exit.wit @@ -0,0 +1,4 @@ +interface exit { + /// Exit the current instance and any linked instances. + exit: func(status: result); +} diff --git a/examples/wit/deps/cli/reactor.wit b/examples/wit/deps/cli-2023-10-18/reactor.wit similarity index 100% rename from examples/wit/deps/cli/reactor.wit rename to examples/wit/deps/cli-2023-10-18/reactor.wit diff --git a/examples/wit/deps/cli-2023-10-18/run.wit b/examples/wit/deps/cli-2023-10-18/run.wit new file mode 100644 index 0000000..a70ee8c --- /dev/null +++ b/examples/wit/deps/cli-2023-10-18/run.wit @@ -0,0 +1,4 @@ +interface run { + /// Run the program. + run: func() -> result; +} diff --git a/examples/wit/deps/cli-2023-10-18/stdio.wit b/examples/wit/deps/cli-2023-10-18/stdio.wit new file mode 100644 index 0000000..513ca92 --- /dev/null +++ b/examples/wit/deps/cli-2023-10-18/stdio.wit @@ -0,0 +1,17 @@ +interface stdin { + use wasi:io/streams@0.2.0-rc-2023-10-18.{input-stream}; + + get-stdin: func() -> input-stream; +} + +interface stdout { + use wasi:io/streams@0.2.0-rc-2023-10-18.{output-stream}; + + get-stdout: func() -> output-stream; +} + +interface stderr { + use wasi:io/streams@0.2.0-rc-2023-10-18.{output-stream}; + + get-stderr: func() -> output-stream; +} diff --git a/examples/wit/deps/cli-2023-10-18/terminal.wit b/examples/wit/deps/cli-2023-10-18/terminal.wit new file mode 100644 index 0000000..4749576 --- /dev/null +++ b/examples/wit/deps/cli-2023-10-18/terminal.wit @@ -0,0 +1,47 @@ +interface terminal-input { + /// The input side of a terminal. + resource 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-output { + /// The output side of a terminal. + resource 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. +} + +/// 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/examples/wit/deps/cli-2023-11-10/command.wit b/examples/wit/deps/cli-2023-11-10/command.wit new file mode 100644 index 0000000..74811d3 --- /dev/null +++ b/examples/wit/deps/cli-2023-11-10/command.wit @@ -0,0 +1,7 @@ +package wasi:cli@0.2.0-rc-2023-11-10; + +world command { + include reactor; + + export run; +} diff --git a/examples/wit/deps/cli-2023-11-10/environment.wit b/examples/wit/deps/cli-2023-11-10/environment.wit new file mode 100644 index 0000000..7006523 --- /dev/null +++ b/examples/wit/deps/cli-2023-11-10/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/examples/wit/deps/cli-2023-11-10/exit.wit b/examples/wit/deps/cli-2023-11-10/exit.wit new file mode 100644 index 0000000..d0c2b82 --- /dev/null +++ b/examples/wit/deps/cli-2023-11-10/exit.wit @@ -0,0 +1,4 @@ +interface exit { + /// Exit the current instance and any linked instances. + exit: func(status: result); +} diff --git a/examples/wit/deps/cli-2023-11-10/reactor.wit b/examples/wit/deps/cli-2023-11-10/reactor.wit new file mode 100644 index 0000000..eafa2fd --- /dev/null +++ b/examples/wit/deps/cli-2023-11-10/reactor.wit @@ -0,0 +1,31 @@ +package wasi:cli@0.2.0-rc-2023-11-10; + +world reactor { + import wasi:clocks/wall-clock@0.2.0-rc-2023-11-10; + import wasi:clocks/monotonic-clock@0.2.0-rc-2023-11-10; + import wasi:filesystem/types@0.2.0-rc-2023-11-10; + import wasi:filesystem/preopens@0.2.0-rc-2023-11-10; + import wasi:sockets/instance-network@0.2.0-rc-2023-11-10; + import wasi:sockets/ip-name-lookup@0.2.0-rc-2023-11-10; + import wasi:sockets/network@0.2.0-rc-2023-11-10; + import wasi:sockets/tcp-create-socket@0.2.0-rc-2023-11-10; + import wasi:sockets/tcp@0.2.0-rc-2023-11-10; + import wasi:sockets/udp-create-socket@0.2.0-rc-2023-11-10; + import wasi:sockets/udp@0.2.0-rc-2023-11-10; + import wasi:random/random@0.2.0-rc-2023-11-10; + import wasi:random/insecure@0.2.0-rc-2023-11-10; + import wasi:random/insecure-seed@0.2.0-rc-2023-11-10; + import wasi:io/poll@0.2.0-rc-2023-11-10; + import wasi:io/streams@0.2.0-rc-2023-11-10; + + 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/examples/wit/deps/cli-2023-11-10/run.wit b/examples/wit/deps/cli-2023-11-10/run.wit new file mode 100644 index 0000000..a70ee8c --- /dev/null +++ b/examples/wit/deps/cli-2023-11-10/run.wit @@ -0,0 +1,4 @@ +interface run { + /// Run the program. + run: func() -> result; +} diff --git a/examples/wit/deps/cli-2023-11-10/stdio.wit b/examples/wit/deps/cli-2023-11-10/stdio.wit new file mode 100644 index 0000000..1b653b6 --- /dev/null +++ b/examples/wit/deps/cli-2023-11-10/stdio.wit @@ -0,0 +1,17 @@ +interface stdin { + use wasi:io/streams@0.2.0-rc-2023-11-10.{input-stream}; + + get-stdin: func() -> input-stream; +} + +interface stdout { + use wasi:io/streams@0.2.0-rc-2023-11-10.{output-stream}; + + get-stdout: func() -> output-stream; +} + +interface stderr { + use wasi:io/streams@0.2.0-rc-2023-11-10.{output-stream}; + + get-stderr: func() -> output-stream; +} diff --git a/examples/wit/deps/cli-2023-11-10/terminal.wit b/examples/wit/deps/cli-2023-11-10/terminal.wit new file mode 100644 index 0000000..4749576 --- /dev/null +++ b/examples/wit/deps/cli-2023-11-10/terminal.wit @@ -0,0 +1,47 @@ +interface terminal-input { + /// The input side of a terminal. + resource 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-output { + /// The output side of a terminal. + resource 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. +} + +/// 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/examples/wit/deps/cli/command.wit b/examples/wit/deps/cli/command.wit index d7ea2d9..d8005bd 100644 --- a/examples/wit/deps/cli/command.wit +++ b/examples/wit/deps/cli/command.wit @@ -1,7 +1,7 @@ -package wasi:cli@0.2.0-rc-2023-10-18; +package wasi:cli@0.2.0; world command { - include reactor; + include imports; export run; } diff --git a/examples/wit/deps/cli/imports.wit b/examples/wit/deps/cli/imports.wit new file mode 100644 index 0000000..083b84a --- /dev/null +++ b/examples/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/examples/wit/deps/cli/stdio.wit b/examples/wit/deps/cli/stdio.wit index 513ca92..31ef35b 100644 --- a/examples/wit/deps/cli/stdio.wit +++ b/examples/wit/deps/cli/stdio.wit @@ -1,17 +1,17 @@ interface stdin { - use wasi:io/streams@0.2.0-rc-2023-10-18.{input-stream}; + use wasi:io/streams@0.2.0.{input-stream}; get-stdin: func() -> input-stream; } interface stdout { - use wasi:io/streams@0.2.0-rc-2023-10-18.{output-stream}; + use wasi:io/streams@0.2.0.{output-stream}; get-stdout: func() -> output-stream; } interface stderr { - use wasi:io/streams@0.2.0-rc-2023-10-18.{output-stream}; + use wasi:io/streams@0.2.0.{output-stream}; get-stderr: func() -> output-stream; } diff --git a/examples/wit/deps/cli/terminal.wit b/examples/wit/deps/cli/terminal.wit index 4749576..38c724e 100644 --- a/examples/wit/deps/cli/terminal.wit +++ b/examples/wit/deps/cli/terminal.wit @@ -1,19 +1,21 @@ +/// 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; - - // 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. } +/// 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; - - // In the future, this may include functions for querying the terminal - // size, being notified of terminal size changes, querying supported - // features, and so on. } /// An interface providing an optional `terminal-input` for stdin as a diff --git a/examples/wit/deps/clocks-2023-10-18/monotonic-clock.wit b/examples/wit/deps/clocks-2023-10-18/monotonic-clock.wit new file mode 100644 index 0000000..c0ecb52 --- /dev/null +++ b/examples/wit/deps/clocks-2023-10-18/monotonic-clock.wit @@ -0,0 +1,32 @@ +/// 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-rc-2023-10-18.{pollable}; + + /// A timestamp in nanoseconds. + type instant = 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. + resolution: func() -> instant; + + /// Create a `pollable` which will resolve once the specified time has been + /// reached. + subscribe: func( + when: instant, + absolute: bool + ) -> pollable; +} diff --git a/examples/wit/deps/clocks/timezone.wit b/examples/wit/deps/clocks-2023-10-18/timezone.wit similarity index 100% rename from examples/wit/deps/clocks/timezone.wit rename to examples/wit/deps/clocks-2023-10-18/timezone.wit diff --git a/examples/wit/deps/clocks-2023-10-18/wall-clock.wit b/examples/wit/deps/clocks-2023-10-18/wall-clock.wit new file mode 100644 index 0000000..c395649 --- /dev/null +++ b/examples/wit/deps/clocks-2023-10-18/wall-clock.wit @@ -0,0 +1,41 @@ +/// 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/examples/wit/deps/clocks-2023-10-18/world.wit b/examples/wit/deps/clocks-2023-10-18/world.wit new file mode 100644 index 0000000..cdfb51d --- /dev/null +++ b/examples/wit/deps/clocks-2023-10-18/world.wit @@ -0,0 +1,7 @@ +package wasi:clocks@0.2.0-rc-2023-10-18; + +world imports { + import monotonic-clock; + import wall-clock; + import timezone; +} diff --git a/examples/wit/deps/clocks-2023-11-10/monotonic-clock.wit b/examples/wit/deps/clocks-2023-11-10/monotonic-clock.wit new file mode 100644 index 0000000..09ef32c --- /dev/null +++ b/examples/wit/deps/clocks-2023-11-10/monotonic-clock.wit @@ -0,0 +1,45 @@ +package wasi:clocks@0.2.0-rc-2023-11-10; +/// 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-rc-2023-11-10.{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/examples/wit/deps/clocks-2023-11-10/wall-clock.wit b/examples/wit/deps/clocks-2023-11-10/wall-clock.wit new file mode 100644 index 0000000..8abb9a0 --- /dev/null +++ b/examples/wit/deps/clocks-2023-11-10/wall-clock.wit @@ -0,0 +1,42 @@ +package wasi:clocks@0.2.0-rc-2023-11-10; +/// 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/examples/wit/deps/clocks-2023-11-10/world.wit b/examples/wit/deps/clocks-2023-11-10/world.wit new file mode 100644 index 0000000..8fa080f --- /dev/null +++ b/examples/wit/deps/clocks-2023-11-10/world.wit @@ -0,0 +1,6 @@ +package wasi:clocks@0.2.0-rc-2023-11-10; + +world imports { + import monotonic-clock; + import wall-clock; +} diff --git a/examples/wit/deps/clocks/monotonic-clock.wit b/examples/wit/deps/clocks/monotonic-clock.wit index c0ecb52..4e4dc3a 100644 --- a/examples/wit/deps/clocks/monotonic-clock.wit +++ b/examples/wit/deps/clocks/monotonic-clock.wit @@ -1,3 +1,4 @@ +package wasi:clocks@0.2.0; /// WASI Monotonic Clock is a clock API intended to let users measure elapsed /// time. /// @@ -9,24 +10,36 @@ /// /// It is intended for measuring elapsed time. interface monotonic-clock { - use wasi:io/poll@0.2.0-rc-2023-10-18.{pollable}; + use wasi:io/poll@0.2.0.{pollable}; - /// A timestamp in nanoseconds. + /// 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. - resolution: 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 time has been - /// reached. - subscribe: func( + /// Create a `pollable` which will resolve once the specified instant + /// occured. + subscribe-instant: func( when: instant, - absolute: bool + ) -> 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/examples/wit/deps/clocks/wall-clock.wit b/examples/wit/deps/clocks/wall-clock.wit index c395649..440ca0f 100644 --- a/examples/wit/deps/clocks/wall-clock.wit +++ b/examples/wit/deps/clocks/wall-clock.wit @@ -1,3 +1,4 @@ +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. diff --git a/examples/wit/deps/clocks/world.wit b/examples/wit/deps/clocks/world.wit index cdfb51d..c022457 100644 --- a/examples/wit/deps/clocks/world.wit +++ b/examples/wit/deps/clocks/world.wit @@ -1,7 +1,6 @@ -package wasi:clocks@0.2.0-rc-2023-10-18; +package wasi:clocks@0.2.0; world imports { import monotonic-clock; import wall-clock; - import timezone; } diff --git a/examples/wit/deps/filesystem-2023-10-18/preopens.wit b/examples/wit/deps/filesystem-2023-10-18/preopens.wit new file mode 100644 index 0000000..3f787ac --- /dev/null +++ b/examples/wit/deps/filesystem-2023-10-18/preopens.wit @@ -0,0 +1,6 @@ +interface preopens { + use types.{descriptor}; + + /// Return the set of preopened directories, and their path. + get-directories: func() -> list>; +} diff --git a/examples/wit/deps/filesystem-2023-10-18/types.wit b/examples/wit/deps/filesystem-2023-10-18/types.wit new file mode 100644 index 0000000..af36135 --- /dev/null +++ b/examples/wit/deps/filesystem-2023-10-18/types.wit @@ -0,0 +1,810 @@ +/// 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-rc-2023-10-18.{input-stream, output-stream, error}; + use wasi:clocks/wall-clock@0.2.0-rc-2023-10-18.{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, + } + + /// Permissions mode used by `open-at`, `change-file-permissions-at`, and + /// similar. + flags modes { + /// True if the resource is considered readable by the containing + /// filesystem. + readable, + /// True if the resource is considered writable by the containing + /// filesystem. + writable, + /// True if the resource is considered executable by the containing + /// filesystem. This does not apply to directories. + executable, + } + + /// Access type used by `access-at`. + variant access-type { + /// Test for readability, writeability, or executability. + access(modes), + + /// Test whether the path exists. + exists, + } + + /// 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, + /// Permissions to use when creating a new file. + modes: modes + ) -> 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>; + + /// Check accessibility of a filesystem path. + /// + /// Check whether the given filesystem path names an object which is + /// readable, writable, or executable, or whether it exists. + /// + /// This does not a guarantee that subsequent accesses will succeed, as + /// filesystem permissions may be modified asynchronously by external + /// entities. + /// + /// Note: This is similar to `faccessat` with the `AT_EACCESS` flag in POSIX. + access-at: func( + /// Flags determining the method of how the path is resolved. + path-flags: path-flags, + /// The relative path to check. + path: string, + /// The type of check to perform. + %type: access-type + ) -> 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>; + + /// Change the permissions of a filesystem object that is not a directory. + /// + /// Note that the ultimate meanings of these permissions is + /// filesystem-specific. + /// + /// Note: This is similar to `fchmodat` in POSIX. + change-file-permissions-at: func( + /// Flags determining the method of how the path is resolved. + path-flags: path-flags, + /// The relative path to operate on. + path: string, + /// The new permissions for the filesystem object. + modes: modes, + ) -> result<_, error-code>; + + /// Change the permissions of a directory. + /// + /// Note that the ultimate meanings of these permissions is + /// filesystem-specific. + /// + /// Unlike in POSIX, the `executable` flag is not reinterpreted as a "search" + /// flag. `read` on a directory implies readability and searchability, and + /// `execute` is not valid for directories. + /// + /// Note: This is similar to `fchmodat` in POSIX. + change-directory-permissions-at: func( + /// Flags determining the method of how the path is resolved. + path-flags: path-flags, + /// The relative path to operate on. + path: string, + /// The new permissions for the directory. + modes: modes, + ) -> result<_, error-code>; + + /// Request a shared advisory lock for an open file. + /// + /// This requests a *shared* lock; more than one shared lock can be held for + /// a file at the same time. + /// + /// If the open file has an exclusive lock, this function downgrades the lock + /// to a shared lock. If it has a shared lock, this function has no effect. + /// + /// This requests an *advisory* lock, meaning that the file could be accessed + /// by other programs that don't hold the lock. + /// + /// It is unspecified how shared locks interact with locks acquired by + /// non-WASI programs. + /// + /// This function blocks until the lock can be acquired. + /// + /// Not all filesystems support locking; on filesystems which don't support + /// locking, this function returns `error-code::unsupported`. + /// + /// Note: This is similar to `flock(fd, LOCK_SH)` in Unix. + lock-shared: func() -> result<_, error-code>; + + /// Request an exclusive advisory lock for an open file. + /// + /// This requests an *exclusive* lock; no other locks may be held for the + /// file while an exclusive lock is held. + /// + /// If the open file has a shared lock and there are no exclusive locks held + /// for the file, this function upgrades the lock to an exclusive lock. If the + /// open file already has an exclusive lock, this function has no effect. + /// + /// This requests an *advisory* lock, meaning that the file could be accessed + /// by other programs that don't hold the lock. + /// + /// It is unspecified whether this function succeeds if the file descriptor + /// is not opened for writing. It is unspecified how exclusive locks interact + /// with locks acquired by non-WASI programs. + /// + /// This function blocks until the lock can be acquired. + /// + /// Not all filesystems support locking; on filesystems which don't support + /// locking, this function returns `error-code::unsupported`. + /// + /// Note: This is similar to `flock(fd, LOCK_EX)` in Unix. + lock-exclusive: func() -> result<_, error-code>; + + /// Request a shared advisory lock for an open file. + /// + /// This requests a *shared* lock; more than one shared lock can be held for + /// a file at the same time. + /// + /// If the open file has an exclusive lock, this function downgrades the lock + /// to a shared lock. If it has a shared lock, this function has no effect. + /// + /// This requests an *advisory* lock, meaning that the file could be accessed + /// by other programs that don't hold the lock. + /// + /// It is unspecified how shared locks interact with locks acquired by + /// non-WASI programs. + /// + /// This function returns `error-code::would-block` if the lock cannot be + /// acquired. + /// + /// Not all filesystems support locking; on filesystems which don't support + /// locking, this function returns `error-code::unsupported`. + /// + /// Note: This is similar to `flock(fd, LOCK_SH | LOCK_NB)` in Unix. + try-lock-shared: func() -> result<_, error-code>; + + /// Request an exclusive advisory lock for an open file. + /// + /// This requests an *exclusive* lock; no other locks may be held for the + /// file while an exclusive lock is held. + /// + /// If the open file has a shared lock and there are no exclusive locks held + /// for the file, this function upgrades the lock to an exclusive lock. If the + /// open file already has an exclusive lock, this function has no effect. + /// + /// This requests an *advisory* lock, meaning that the file could be accessed + /// by other programs that don't hold the lock. + /// + /// It is unspecified whether this function succeeds if the file descriptor + /// is not opened for writing. It is unspecified how exclusive locks interact + /// with locks acquired by non-WASI programs. + /// + /// This function returns `error-code::would-block` if the lock cannot be + /// acquired. + /// + /// Not all filesystems support locking; on filesystems which don't support + /// locking, this function returns `error-code::unsupported`. + /// + /// Note: This is similar to `flock(fd, LOCK_EX | LOCK_NB)` in Unix. + try-lock-exclusive: func() -> result<_, error-code>; + + /// Release a shared or exclusive lock on an open file. + /// + /// Note: This is similar to `flock(fd, LOCK_UN)` in Unix. + unlock: func() -> 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/examples/wit/deps/filesystem-2023-10-18/world.wit b/examples/wit/deps/filesystem-2023-10-18/world.wit new file mode 100644 index 0000000..3f953f8 --- /dev/null +++ b/examples/wit/deps/filesystem-2023-10-18/world.wit @@ -0,0 +1,6 @@ +package wasi:filesystem@0.2.0-rc-2023-10-18; + +world imports { + import types; + import preopens; +} diff --git a/examples/wit/deps/filesystem-2023-11-10/preopens.wit b/examples/wit/deps/filesystem-2023-11-10/preopens.wit new file mode 100644 index 0000000..95ec678 --- /dev/null +++ b/examples/wit/deps/filesystem-2023-11-10/preopens.wit @@ -0,0 +1,8 @@ +package wasi:filesystem@0.2.0-rc-2023-11-10; + +interface preopens { + use types.{descriptor}; + + /// Return the set of preopened directories, and their path. + get-directories: func() -> list>; +} diff --git a/examples/wit/deps/filesystem-2023-11-10/types.wit b/examples/wit/deps/filesystem-2023-11-10/types.wit new file mode 100644 index 0000000..059722a --- /dev/null +++ b/examples/wit/deps/filesystem-2023-11-10/types.wit @@ -0,0 +1,634 @@ +package wasi:filesystem@0.2.0-rc-2023-11-10; +/// 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-rc-2023-11-10.{input-stream, output-stream, error}; + use wasi:clocks/wall-clock@0.2.0-rc-2023-11-10.{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/examples/wit/deps/filesystem-2023-11-10/world.wit b/examples/wit/deps/filesystem-2023-11-10/world.wit new file mode 100644 index 0000000..285e0ba --- /dev/null +++ b/examples/wit/deps/filesystem-2023-11-10/world.wit @@ -0,0 +1,6 @@ +package wasi:filesystem@0.2.0-rc-2023-11-10; + +world imports { + import types; + import preopens; +} diff --git a/examples/wit/deps/filesystem/preopens.wit b/examples/wit/deps/filesystem/preopens.wit index 3f787ac..da801f6 100644 --- a/examples/wit/deps/filesystem/preopens.wit +++ b/examples/wit/deps/filesystem/preopens.wit @@ -1,3 +1,5 @@ +package wasi:filesystem@0.2.0; + interface preopens { use types.{descriptor}; diff --git a/examples/wit/deps/filesystem/types.wit b/examples/wit/deps/filesystem/types.wit index af36135..11108fc 100644 --- a/examples/wit/deps/filesystem/types.wit +++ b/examples/wit/deps/filesystem/types.wit @@ -1,3 +1,4 @@ +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. @@ -23,8 +24,8 @@ /// /// [WASI filesystem path resolution]: https://github.com/WebAssembly/wasi-filesystem/blob/main/path-resolution.md interface types { - use wasi:io/streams@0.2.0-rc-2023-10-18.{input-stream, output-stream, error}; - use wasi:clocks/wall-clock@0.2.0-rc-2023-10-18.{datetime}; + 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; @@ -142,29 +143,6 @@ interface types { truncate, } - /// Permissions mode used by `open-at`, `change-file-permissions-at`, and - /// similar. - flags modes { - /// True if the resource is considered readable by the containing - /// filesystem. - readable, - /// True if the resource is considered writable by the containing - /// filesystem. - writable, - /// True if the resource is considered executable by the containing - /// filesystem. This does not apply to directories. - executable, - } - - /// Access type used by `access-at`. - variant access-type { - /// Test for readability, writeability, or executability. - access(modes), - - /// Test whether the path exists. - exists, - } - /// Number of hard links to an inode. type link-count = u64; @@ -538,8 +516,6 @@ interface types { open-flags: open-flags, /// Flags to use for the resulting descriptor. %flags: descriptor-flags, - /// Permissions to use when creating a new file. - modes: modes ) -> result; /// Read the contents of a symbolic link. @@ -588,25 +564,6 @@ interface types { new-path: string, ) -> result<_, error-code>; - /// Check accessibility of a filesystem path. - /// - /// Check whether the given filesystem path names an object which is - /// readable, writable, or executable, or whether it exists. - /// - /// This does not a guarantee that subsequent accesses will succeed, as - /// filesystem permissions may be modified asynchronously by external - /// entities. - /// - /// Note: This is similar to `faccessat` with the `AT_EACCESS` flag in POSIX. - access-at: func( - /// Flags determining the method of how the path is resolved. - path-flags: path-flags, - /// The relative path to check. - path: string, - /// The type of check to perform. - %type: access-type - ) -> result<_, error-code>; - /// Unlink a filesystem object that is not a directory. /// /// Return `error-code::is-directory` if the path refers to a directory. @@ -616,139 +573,6 @@ interface types { path: string, ) -> result<_, error-code>; - /// Change the permissions of a filesystem object that is not a directory. - /// - /// Note that the ultimate meanings of these permissions is - /// filesystem-specific. - /// - /// Note: This is similar to `fchmodat` in POSIX. - change-file-permissions-at: func( - /// Flags determining the method of how the path is resolved. - path-flags: path-flags, - /// The relative path to operate on. - path: string, - /// The new permissions for the filesystem object. - modes: modes, - ) -> result<_, error-code>; - - /// Change the permissions of a directory. - /// - /// Note that the ultimate meanings of these permissions is - /// filesystem-specific. - /// - /// Unlike in POSIX, the `executable` flag is not reinterpreted as a "search" - /// flag. `read` on a directory implies readability and searchability, and - /// `execute` is not valid for directories. - /// - /// Note: This is similar to `fchmodat` in POSIX. - change-directory-permissions-at: func( - /// Flags determining the method of how the path is resolved. - path-flags: path-flags, - /// The relative path to operate on. - path: string, - /// The new permissions for the directory. - modes: modes, - ) -> result<_, error-code>; - - /// Request a shared advisory lock for an open file. - /// - /// This requests a *shared* lock; more than one shared lock can be held for - /// a file at the same time. - /// - /// If the open file has an exclusive lock, this function downgrades the lock - /// to a shared lock. If it has a shared lock, this function has no effect. - /// - /// This requests an *advisory* lock, meaning that the file could be accessed - /// by other programs that don't hold the lock. - /// - /// It is unspecified how shared locks interact with locks acquired by - /// non-WASI programs. - /// - /// This function blocks until the lock can be acquired. - /// - /// Not all filesystems support locking; on filesystems which don't support - /// locking, this function returns `error-code::unsupported`. - /// - /// Note: This is similar to `flock(fd, LOCK_SH)` in Unix. - lock-shared: func() -> result<_, error-code>; - - /// Request an exclusive advisory lock for an open file. - /// - /// This requests an *exclusive* lock; no other locks may be held for the - /// file while an exclusive lock is held. - /// - /// If the open file has a shared lock and there are no exclusive locks held - /// for the file, this function upgrades the lock to an exclusive lock. If the - /// open file already has an exclusive lock, this function has no effect. - /// - /// This requests an *advisory* lock, meaning that the file could be accessed - /// by other programs that don't hold the lock. - /// - /// It is unspecified whether this function succeeds if the file descriptor - /// is not opened for writing. It is unspecified how exclusive locks interact - /// with locks acquired by non-WASI programs. - /// - /// This function blocks until the lock can be acquired. - /// - /// Not all filesystems support locking; on filesystems which don't support - /// locking, this function returns `error-code::unsupported`. - /// - /// Note: This is similar to `flock(fd, LOCK_EX)` in Unix. - lock-exclusive: func() -> result<_, error-code>; - - /// Request a shared advisory lock for an open file. - /// - /// This requests a *shared* lock; more than one shared lock can be held for - /// a file at the same time. - /// - /// If the open file has an exclusive lock, this function downgrades the lock - /// to a shared lock. If it has a shared lock, this function has no effect. - /// - /// This requests an *advisory* lock, meaning that the file could be accessed - /// by other programs that don't hold the lock. - /// - /// It is unspecified how shared locks interact with locks acquired by - /// non-WASI programs. - /// - /// This function returns `error-code::would-block` if the lock cannot be - /// acquired. - /// - /// Not all filesystems support locking; on filesystems which don't support - /// locking, this function returns `error-code::unsupported`. - /// - /// Note: This is similar to `flock(fd, LOCK_SH | LOCK_NB)` in Unix. - try-lock-shared: func() -> result<_, error-code>; - - /// Request an exclusive advisory lock for an open file. - /// - /// This requests an *exclusive* lock; no other locks may be held for the - /// file while an exclusive lock is held. - /// - /// If the open file has a shared lock and there are no exclusive locks held - /// for the file, this function upgrades the lock to an exclusive lock. If the - /// open file already has an exclusive lock, this function has no effect. - /// - /// This requests an *advisory* lock, meaning that the file could be accessed - /// by other programs that don't hold the lock. - /// - /// It is unspecified whether this function succeeds if the file descriptor - /// is not opened for writing. It is unspecified how exclusive locks interact - /// with locks acquired by non-WASI programs. - /// - /// This function returns `error-code::would-block` if the lock cannot be - /// acquired. - /// - /// Not all filesystems support locking; on filesystems which don't support - /// locking, this function returns `error-code::unsupported`. - /// - /// Note: This is similar to `flock(fd, LOCK_EX | LOCK_NB)` in Unix. - try-lock-exclusive: func() -> result<_, error-code>; - - /// Release a shared or exclusive lock on an open file. - /// - /// Note: This is similar to `flock(fd, LOCK_UN)` in Unix. - unlock: func() -> 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 diff --git a/examples/wit/deps/filesystem/world.wit b/examples/wit/deps/filesystem/world.wit index 3f953f8..663f579 100644 --- a/examples/wit/deps/filesystem/world.wit +++ b/examples/wit/deps/filesystem/world.wit @@ -1,4 +1,4 @@ -package wasi:filesystem@0.2.0-rc-2023-10-18; +package wasi:filesystem@0.2.0; world imports { import types; diff --git a/examples/wit/deps/http/incoming-handler.wit b/examples/wit/deps/http-2023-10-18/incoming-handler.wit similarity index 100% rename from examples/wit/deps/http/incoming-handler.wit rename to examples/wit/deps/http-2023-10-18/incoming-handler.wit diff --git a/examples/wit/deps/http/outgoing-handler.wit b/examples/wit/deps/http-2023-10-18/outgoing-handler.wit similarity index 100% rename from examples/wit/deps/http/outgoing-handler.wit rename to examples/wit/deps/http-2023-10-18/outgoing-handler.wit diff --git a/examples/wit/deps/http-2023-10-18/proxy.wit b/examples/wit/deps/http-2023-10-18/proxy.wit new file mode 100644 index 0000000..dde0659 --- /dev/null +++ b/examples/wit/deps/http-2023-10-18/proxy.wit @@ -0,0 +1,34 @@ +package wasi:http@0.2.0-rc-2023-10-18; + +// 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. + import wasi:clocks/wall-clock@0.2.0-rc-2023-10-18; + import wasi:clocks/monotonic-clock@0.2.0-rc-2023-10-18; + import wasi:clocks/timezone@0.2.0-rc-2023-10-18; + import wasi:random/random@0.2.0-rc-2023-10-18; + + // 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-rc-2023-10-18; + import wasi:cli/stderr@0.2.0-rc-2023-10-18; + + // 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-rc-2023-10-18; + + // 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/examples/wit/deps/http-2023-10-18/types.wit b/examples/wit/deps/http-2023-10-18/types.wit new file mode 100644 index 0000000..2471f04 --- /dev/null +++ b/examples/wit/deps/http-2023-10-18/types.wit @@ -0,0 +1,208 @@ +/// The `wasi:http/types` interface is meant to be imported by components to +/// define the HTTP resource types and operations used by the component's +/// imported and exported interfaces. +interface types { + use wasi:io/streams@0.2.0-rc-2023-10-18.{input-stream, output-stream}; + use wasi:io/poll@0.2.0-rc-2023-10-18.{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) + } + + // TODO: perhaps better align with HTTP semantics? + /// This type enumerates the different kinds of errors that may occur when + /// initially returning a response. + variant error { + invalid-url(string), + timeout-error(string), + protocol-error(string), + unexpected-error(string) + } + + /// This following block defines the `fields` resource which corresponds to + /// HTTP standard Fields. + resource fields { + // Multiple values for a header are multiple entries in the list with the + // same key. + constructor(entries: list>>); + + // Values off wire are not necessarily well formed, so they are given by + // list instead of string. + get: func(name: string) -> list>; + + // Values off wire are not necessarily well formed, so they are given by + // list instead of string. + set: func(name: string, value: list>); + delete: func(name: string); + append: func(name: string, value: list); + + // Values off wire are not necessarily well formed, so they are given by + // list instead of string. + entries: func() -> list>>; + + // Deep copy of all contents in a fields. + clone: func() -> fields; + } + + type headers = fields; + type trailers = fields; + + /// The following block defines the `incoming-request` and `outgoing-request` + /// resource types that correspond to HTTP standard Requests. + /// + /// The `consume` and `write` methods may only be called once (and + /// return failure thereafter). + resource incoming-request { + method: func() -> method; + + path-with-query: func() -> option; + + scheme: func() -> option; + + authority: func() -> option; + + headers: func() -> /* child */ headers; + + /// Returns the input-stream child at most once. + /// + /// If called more than once, subsequent calls return an error. + consume: func() -> result; + } + + resource outgoing-request { + constructor( + method: method, + path-with-query: option, + scheme: option, + authority: option, + headers: borrow + ); + + /// Will return the outgoing-body child at most once. + /// + /// If called more than once, subsequent calls return an error. + write: func() -> result< /* child */ outgoing-body>; + } + + /// Additional optional parameters that can be set when making a request. + record request-options { + // The following timeouts are specific to the HTTP protocol and work + // independently of the overall timeouts passed to `io.poll.poll-list`. + + /// The timeout for the initial connect. + connect-timeout-ms: option, + + /// The timeout for receiving the first byte of the response body. + first-byte-timeout-ms: option, + + /// The timeout for receiving the next chunk of bytes in the response body + /// stream. + between-bytes-timeout-ms: option + } + + /// The following block defines a special resource type used by the + /// `wasi:http/incoming-handler` interface. When resource types are added, this + /// block can be replaced by a proper `resource response-outparam { ... }` + /// definition. Later, with Preview3, the need for an outparam goes away entirely + /// (the `wasi:http/handler` interface used for both incoming and outgoing can + /// simply return a `stream`). + resource response-outparam { + set: static func(param: response-outparam, response: result); + } + + // This type corresponds to the HTTP standard Status Code. + type status-code = u16; + + /// The following block defines the `incoming-response` and `outgoing-response` + /// resource types that correspond to HTTP standard Responses. + /// + /// The `consume` and `write` methods may only be called once (and return failure thereafter). + resource incoming-response { + status: func() -> status-code; + + headers: func() -> /* child */ headers; + + // May be called at most once. returns error if called additional times. + // TODO: make incoming-request-consume work the same way, giving a child + // incoming-body. + consume: func() -> result; + } + + resource incoming-body { + // returned input-stream is a child - the implementation may trap if + // incoming-body is dropped (or consumed by call to + // incoming-body-finish) before the input-stream is dropped. + // May be called at most once. returns error if called additional times. + %stream: func() -> result; + + // takes ownership of incoming-body. this will trap if the + // incoming-body-stream child is still alive! + finish: static func(this: incoming-body) -> + /* transitive child of the incoming-response of incoming-body */ future-trailers; + } + + resource future-trailers { + /// Pollable that resolves when the body has been fully read, and the trailers + /// are ready to be consumed. + subscribe: func() -> /* child */ pollable; + + /// Retrieve reference to trailers, if they are ready. + get: func() -> option>; + } + + resource outgoing-response { + constructor(status-code: status-code, headers: borrow); + + /// Will give the child outgoing-response at most once. subsequent calls will + /// return an error. + write: func() -> result; + } + + resource outgoing-body { + /// Will give the child output-stream at most once. subsequent calls will + /// return an 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. + finish: static func(this: outgoing-body, trailers: option); + } + + /// The following block defines a special resource type used by the + /// `wasi:http/outgoing-handler` interface to emulate + /// `future>` in advance of Preview3. Given a + /// `future-incoming-response`, the client can call the non-blocking `get` + /// method to get the result if it is available. If the result is not available, + /// the client can call `listen` to get a `pollable` that can be passed to + /// `wasi:io/poll.poll-list`. + resource future-incoming-response { + /// option indicates readiness. + /// outer result indicates you are allowed to get the + /// incoming-response-or-error at most once. subsequent calls after ready + /// will return an error here. + /// inner result indicates whether the incoming-response was available, or an + /// error occured. + get: func() -> option>>; + + subscribe: func() -> /* child */ pollable; + } +} diff --git a/examples/wit/deps/http-2023-11-10/handler.wit b/examples/wit/deps/http-2023-11-10/handler.wit new file mode 100644 index 0000000..a34a064 --- /dev/null +++ b/examples/wit/deps/http-2023-11-10/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/examples/wit/deps/http-2023-11-10/proxy.wit b/examples/wit/deps/http-2023-11-10/proxy.wit new file mode 100644 index 0000000..453f590 --- /dev/null +++ b/examples/wit/deps/http-2023-11-10/proxy.wit @@ -0,0 +1,33 @@ +package wasi:http@0.2.0-rc-2023-11-10; + +/// 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. + import wasi:clocks/wall-clock@0.2.0-rc-2023-11-10; + import wasi:clocks/monotonic-clock@0.2.0-rc-2023-11-10; + import wasi:random/random@0.2.0-rc-2023-11-10; + + /// 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-rc-2023-11-10; + import wasi:cli/stderr@0.2.0-rc-2023-11-10; + + /// 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-rc-2023-11-10; + + /// 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/examples/wit/deps/http-2023-11-10/types.wit b/examples/wit/deps/http-2023-11-10/types.wit new file mode 100644 index 0000000..1dd4214 --- /dev/null +++ b/examples/wit/deps/http-2023-11-10/types.wit @@ -0,0 +1,559 @@ +/// 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-rc-2023-11-10.{duration}; + use wasi:io/streams@0.2.0-rc-2023-11-10.{input-stream, output-stream}; + use wasi:io/error@0.2.0-rc-2023-11-10.{error as io-error}; + use wasi:io/poll@0.2.0-rc-2023-11-10.{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. + get: func(name: field-key) -> list; + + /// 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 an + /// optional timeout, with the unit in milliseconds, 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-ms: 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-ms: func(ms: option) -> result; + + /// The timeout for receiving the first byte of the Response body. + first-byte-timeout-ms: 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-ms: func(ms: option) -> result; + + /// The timeout for receiving subsequent chunks of bytes in the Response + /// body stream. + between-bytes-timeout-ms: 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-ms: func(ms: 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 `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/examples/wit/deps/http/handler.wit b/examples/wit/deps/http/handler.wit new file mode 100644 index 0000000..a34a064 --- /dev/null +++ b/examples/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/examples/wit/deps/http/proxy.wit b/examples/wit/deps/http/proxy.wit index dde0659..687c24d 100644 --- a/examples/wit/deps/http/proxy.wit +++ b/examples/wit/deps/http/proxy.wit @@ -1,34 +1,32 @@ -package wasi:http@0.2.0-rc-2023-10-18; +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. +/// 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. - import wasi:clocks/wall-clock@0.2.0-rc-2023-10-18; - import wasi:clocks/monotonic-clock@0.2.0-rc-2023-10-18; - import wasi:clocks/timezone@0.2.0-rc-2023-10-18; - import wasi:random/random@0.2.0-rc-2023-10-18; + /// 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-rc-2023-10-18; - import wasi:cli/stderr@0.2.0-rc-2023-10-18; + /// 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-rc-2023-10-18; + /// 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()`). + /// 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`. + /// 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/examples/wit/deps/http/types.wit b/examples/wit/deps/http/types.wit index 2cd2fe2..755ac6a 100644 --- a/examples/wit/deps/http/types.wit +++ b/examples/wit/deps/http/types.wit @@ -1,11 +1,13 @@ -// The `wasi:http/types` interface is meant to be imported by components to -// define the HTTP resource types and operations used by the component's -// imported and exported interfaces. +/// 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:io/streams@0.2.0-rc-2023-10-18.{input-stream, output-stream}; - use wasi:io/poll@0.2.0-rc-2023-10-18.{pollable}; + 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. + /// This type corresponds to HTTP standard Methods. variant method { get, head, @@ -19,196 +21,550 @@ interface types { other(string) } - // This type corresponds to HTTP standard Related Schemes. + /// This type corresponds to HTTP standard Related Schemes. variant scheme { HTTP, HTTPS, other(string) } - // TODO: perhaps better align with HTTP semantics? - // This type enumerates the different kinds of errors that may occur when - // initially returning a response. - variant error { - invalid-url(string), - timeout-error(string), - protocol-error(string), - unexpected-error(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) } - // This following block defines the `fields` resource which corresponds to - // HTTP standard Fields. Soon, when resource types are added, the `type - // fields = u32` type alias can be replaced by a proper `resource fields` - // definition containing all the functions using the method syntactic sugar. - resource fields { - // Multiple values for a header are multiple entries in the list with the - // same key. - constructor(entries: list>>); + /// 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 + } - // Values off wire are not necessarily well formed, so they are given by - // list instead of string. - get: func(name: string) -> list>; + /// Defines the case payload type for `HTTP-response-{header,trailer}-size` above: + record field-size-payload { + field-name: option, + field-size: option + } - // Values off wire are not necessarily well formed, so they are given by - // list instead of string. - set: func(name: string, value: list>); - delete: func(name: string); - append: func(name: string, value: list); + /// 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, + } - // Values off wire are not necessarily well formed, so they are given by - // list instead of string. - entries: func() -> list>>; + /// 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 { - // Deep copy of all contents in a 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; - // The following block defines the `incoming-request` and `outgoing-request` - // resource types that correspond to HTTP standard Requests. Soon, when - // resource types are added, the `u32` type aliases can be replaced by - // proper `resource` type definitions containing all the functions as - // methods. Later, Preview2 will allow both types to be merged together into - // a single `request` type (that uses the single `stream` type mentioned - // above). The `consume` and `write` methods may only be called once (and - // return failure thereafter). + /// 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; - headers: func() -> /* child */ headers; - // Will return the input-stream child at most once. If called more than - // once, subsequent calls will return error. - + /// 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( - method: method, - path-with-query: option, - scheme: option, - authority: option, - headers: borrow + headers: headers ); - // Will return the outgoing-body child at most once. If called more than - // once, subsequent calls will return error. - write: func() -> result< /* child */ outgoing-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; - // Additional optional parameters that can be set when making a request. - record request-options { - // The following timeouts are specific to the HTTP protocol and work - // independently of the overall timeouts passed to `io.poll.poll-list`. + /// 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; - // The timeout for the initial connect. - connect-timeout-ms: option, + /// 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; - // The timeout for receiving the first byte of the response body. - first-byte-timeout-ms: option, + /// 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; + } - // The timeout for receiving the next chunk of bytes in the response body - // stream. - between-bytes-timeout-ms: option + /// 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; } - // The following block defines a special resource type used by the - // `wasi:http/incoming-handler` interface. When resource types are added, this - // block can be replaced by a proper `resource response-outparam { ... }` - // definition. Later, with Preview3, the need for an outparam goes away entirely - // (the `wasi:http/handler` interface used for both incoming and outgoing can - // simply return a `stream`). + /// 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: static func(param: response-outparam, response: result); + + /// 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. + /// This type corresponds to the HTTP standard Status Code. type status-code = u16; - // The following block defines the `incoming-response` and `outgoing-response` - // resource types that correspond to HTTP standard Responses. Soon, when - // resource types are added, the `u32` type aliases can be replaced by proper - // `resource` type definitions containing all the functions as methods. Later, - // Preview2 will allow both types to be merged together into a single `response` - // type (that uses the single `stream` type mentioned above). The `consume` and - // `write` methods may only be called once (and return failure thereafter). + /// Represents an incoming HTTP Response. resource incoming-response { - status: func() -> status-code; - headers: func() -> /* child */ headers; + /// Returns the status code from the incoming response. + status: func() -> status-code; - // May be called at most once. returns error if called additional times. - // TODO: make incoming-request-consume work the same way, giving a child - // incoming-body. + /// 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 { - // returned input-stream is a child - the implementation may trap if - // incoming-body is dropped (or consumed by call to - // incoming-body-finish) before the input-stream is dropped. - // May be called at most once. returns error if called additional times. - %stream: func() -> result; - // takes ownership of incoming-body. this will trap if the - // incoming-body-stream child is still alive! - finish: static func(this: incoming-body) -> - /* transitive child of the incoming-response of incoming-body */ future-trailers; + /// 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 { - /// Pollable that resolves when the body has been fully read, and the trailers - /// are ready to be consumed. - subscribe: func() -> /* child */ pollable; - /// Retrieve reference to trailers, if they are ready. - get: func() -> option>; + /// 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 { - constructor(status-code: status-code, headers: borrow); - /// Will give the child outgoing-response at most once. subsequent calls will - /// return an error. - write: func() -> result; + /// 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 { - /// Will give the child output-stream at most once. subsequent calls will - /// return an error. - write: func() -> result; + + /// 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 + /// 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. - finish: static func(this: outgoing-body, trailers: option); + /// + /// 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>; } - /// The following block defines a special resource type used by the - /// `wasi:http/outgoing-handler` interface to emulate - /// `future>` in advance of Preview3. Given a - /// `future-incoming-response`, the client can call the non-blocking `get` - /// method to get the result if it is available. If the result is not available, - /// the client can call `listen` to get a `pollable` that can be passed to - /// `wasi:io/poll.poll-list`. + /// 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 { - /// option indicates readiness. - /// outer result indicates you are allowed to get the - /// incoming-response-or-error at most once. subsequent calls after ready - /// will return an error here. - /// inner result indicates whether the incoming-response was available, or an - /// error occured. - get: func() -> option>>; - - subscribe: func() -> /* child */ pollable; + /// 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/examples/wit/deps/io-2023-10-18/poll.wit b/examples/wit/deps/io-2023-10-18/poll.wit new file mode 100644 index 0000000..74835e6 --- /dev/null +++ b/examples/wit/deps/io-2023-10-18/poll.wit @@ -0,0 +1,32 @@ +/// A poll API intended to let users wait for I/O events on multiple handles +/// at once. +interface poll { + /// A "pollable" handle. + resource pollable; + + /// 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-list: func(in: list>) -> list; + + /// Poll for completion on a single pollable. + /// + /// This function is similar to `poll-list`, but operates on only a single + /// pollable. When it returns, the handle is ready for I/O. + poll-one: func(in: borrow); +} diff --git a/examples/wit/deps/io-2023-10-18/streams.wit b/examples/wit/deps/io-2023-10-18/streams.wit new file mode 100644 index 0000000..c9600b7 --- /dev/null +++ b/examples/wit/deps/io-2023-10-18/streams.wit @@ -0,0 +1,287 @@ +/// 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 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 + } + + /// Contextual error information about the last failure that happened on + /// a read, write, or flush from an `input-stream` or `output-stream`. + /// + /// This type is returned through the `stream-error` type whenever an + /// operation on a stream directly fails or an error is discovered + /// after-the-fact, for example when a write's failure shows up through a + /// later `flush` or `check-write`. + /// + /// Interfaces such as `wasi:filesystem/types` provide functionality to + /// further "downcast" this error into interface-specific error information. + resource error { + /// Returns a string that's suitable to assist humans in debugging this + /// error. + /// + /// The returned string will change across platforms and hosts which + /// means that parsing it, for example, would be a + /// platform-compatibility hazard. + to-debug-string: func() -> string; + } + + /// 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. + /// + /// This function returns a list of bytes containing the data that was + /// read, along with a `stream-status` which, indicates whether further + /// reads are expected to produce data. The returned list will contain up to + /// `len` bytes; it may return fewer than requested, but not more. An + /// empty list and `stream-status:open` indicates no more data is + /// available at this time, and that the pollable given by `subscribe` + /// will be ready when more data is available. + /// + /// Once a stream has reached the end, subsequent calls to `read` or + /// `skip` will always report `stream-status:ended` rather than producing more + /// data. + /// + /// When the caller gives a `len` of 0, it represents a request to read 0 + /// bytes. This read should always succeed and return an empty list and + /// the current `stream-status`. + /// + /// 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, identical to `read`. + blocking-read: func( + /// The maximum number of bytes to read + len: u64 + ) -> result, stream-error>; + + /// Skip bytes from a stream. + /// + /// This is similar to the `read` function, but avoids copying the + /// bytes into the instance. + /// + /// Once a stream has reached the end, subsequent calls to read or + /// `skip` will always report end-of-stream rather than producing more + /// data. + /// + /// This function returns the number of bytes skipped, along with a + /// `stream-status` indicating whether the end of the stream was + /// reached. The returned value will be at most `len`; it may be less. + 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. + /// + /// 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 + /// poll-one(pollable); + /// 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` + /// poll-one(pollable); + /// // 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 + /// poll-one(pollable); + /// 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` + /// poll-one(pollable); + /// // 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. + /// + /// This function returns the number of bytes transferred; it may be less + /// than `len`. + /// + /// Unlike other I/O functions, this function blocks until all the data + /// read from the input stream has been written to the output stream. + splice: func( + /// The stream to read from + src: input-stream, + /// 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 at least + /// one byte can be read. + blocking-splice: func( + /// The stream to read from + src: input-stream, + /// The number of bytes to splice + len: u64, + ) -> result; + + /// Forward the entire contents of an input stream to an output stream. + /// + /// This function repeatedly reads from the input stream and writes + /// the data to the output stream, until the end of the input stream + /// is reached, or an error is encountered. + /// + /// Unlike other I/O functions, this function blocks until the end + /// of the input stream is seen and all the data has been written to + /// the output stream. + /// + /// This function returns the number of bytes transferred, and the status of + /// the output stream. + forward: func( + /// The stream to read from + src: input-stream + ) -> result; + } +} diff --git a/examples/wit/deps/io-2023-10-18/world.wit b/examples/wit/deps/io-2023-10-18/world.wit new file mode 100644 index 0000000..a0bcd31 --- /dev/null +++ b/examples/wit/deps/io-2023-10-18/world.wit @@ -0,0 +1 @@ +package wasi:io@0.2.0-rc-2023-10-18; diff --git a/examples/wit/deps/io-2023-11-10/error.wit b/examples/wit/deps/io-2023-11-10/error.wit new file mode 100644 index 0000000..31918ac --- /dev/null +++ b/examples/wit/deps/io-2023-11-10/error.wit @@ -0,0 +1,34 @@ +package wasi:io@0.2.0-rc-2023-11-10; + + +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/examples/wit/deps/io-2023-11-10/poll.wit b/examples/wit/deps/io-2023-11-10/poll.wit new file mode 100644 index 0000000..bddde3c --- /dev/null +++ b/examples/wit/deps/io-2023-11-10/poll.wit @@ -0,0 +1,41 @@ +package wasi:io@0.2.0-rc-2023-11-10; + +/// A poll API intended to let users wait for I/O events on multiple handles +/// at once. +interface poll { + /// `pollable` epresents 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/examples/wit/deps/io-2023-11-10/streams.wit b/examples/wit/deps/io-2023-11-10/streams.wit new file mode 100644 index 0000000..e7e1b68 --- /dev/null +++ b/examples/wit/deps/io-2023-11-10/streams.wit @@ -0,0 +1,251 @@ +package wasi:io@0.2.0-rc-2023-11-10; + +/// 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. + /// + /// 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. + /// + /// 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 + /// poll-one(pollable); + /// 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` + /// poll-one(pollable); + /// // 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 + /// poll-one(pollable); + /// 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` + /// poll-one(pollable); + /// // 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/examples/wit/deps/io-2023-11-10/world.wit b/examples/wit/deps/io-2023-11-10/world.wit new file mode 100644 index 0000000..8243da2 --- /dev/null +++ b/examples/wit/deps/io-2023-11-10/world.wit @@ -0,0 +1,6 @@ +package wasi:io@0.2.0-rc-2023-11-10; + +world imports { + import streams; + import poll; +} diff --git a/examples/wit/deps/io/error.wit b/examples/wit/deps/io/error.wit new file mode 100644 index 0000000..22e5b64 --- /dev/null +++ b/examples/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/examples/wit/deps/io/poll.wit b/examples/wit/deps/io/poll.wit index 047389d..ddc67f8 100644 --- a/examples/wit/deps/io/poll.wit +++ b/examples/wit/deps/io/poll.wit @@ -1,10 +1,23 @@ -package wasi:io@0.2.0-rc-2023-10-18; +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 { - /// A "pollable" handle. - resource pollable; + /// `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. /// @@ -24,11 +37,5 @@ interface poll { /// 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-list: func(in: list>) -> list; - - /// Poll for completion on a single pollable. - /// - /// This function is similar to `poll-list`, but operates on only a single - /// pollable. When it returns, the handle is ready for I/O. - poll-one: func(in: borrow); + poll: func(in: list>) -> list; } diff --git a/examples/wit/deps/io/streams.wit b/examples/wit/deps/io/streams.wit index d0e8f5c..6d2f871 100644 --- a/examples/wit/deps/io/streams.wit +++ b/examples/wit/deps/io/streams.wit @@ -1,4 +1,4 @@ -package wasi:io@0.2.0-rc-2023-10-18; +package wasi:io@0.2.0; /// WASI I/O is an I/O abstraction API which is currently focused on providing /// stream types. @@ -6,6 +6,7 @@ package wasi:io@0.2.0-rc-2023-10-18; /// 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. @@ -20,26 +21,6 @@ interface streams { closed } - /// Contextual error information about the last failure that happened on - /// a read, write, or flush from an `input-stream` or `output-stream`. - /// - /// This type is returned through the `stream-error` type whenever an - /// operation on a stream directly fails or an error is discovered - /// after-the-fact, for example when a write's failure shows up through a - /// later `flush` or `check-write`. - /// - /// Interfaces such as `wasi:filesystem/types` provide functionality to - /// further "downcast" this error into interface-specific error information. - resource error { - /// Returns a string that's suitable to assist humans in debugging this - /// error. - /// - /// The returned string will change across platforms and hosts which - /// means that parsing it, for example, would be a - /// platform-compatibility hazard. - to-debug-string: func() -> string; - } - /// An input bytestream. /// /// `input-stream`s are *non-blocking* to the extent practical on underlying @@ -51,21 +32,25 @@ interface streams { resource input-stream { /// Perform a non-blocking read from the stream. /// - /// This function returns a list of bytes containing the data that was - /// read, along with a `stream-status` which, indicates whether further - /// reads are expected to produce data. The returned list will contain up to - /// `len` bytes; it may return fewer than requested, but not more. An - /// empty list and `stream-status:open` indicates no more data is - /// available at this time, and that the pollable given by `subscribe` - /// will be ready when more data is available. + /// 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. /// - /// Once a stream has reached the end, subsequent calls to `read` or - /// `skip` will always report `stream-status:ended` rather than producing more - /// data. + /// 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. This read should always succeed and return an empty list and - /// the current `stream-status`. + /// 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 @@ -77,24 +62,16 @@ interface streams { ) -> result, stream-error>; /// Read bytes from a stream, after blocking until at least one byte can - /// be read. Except for blocking, identical to `read`. + /// 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. - /// - /// This is similar to the `read` function, but avoids copying the - /// bytes into the instance. + /// Skip bytes from a stream. Returns number of bytes skipped. /// - /// Once a stream has reached the end, subsequent calls to read or - /// `skip` will always report end-of-stream rather than producing more - /// data. - /// - /// This function returns the number of bytes skipped, along with a - /// `stream-status` indicating whether the end of the stream was - /// reached. The returned value will be at most `len`; it may be less. + /// 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, @@ -139,6 +116,12 @@ interface streams { /// 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. /// @@ -159,7 +142,7 @@ interface streams { /// let pollable = this.subscribe(); /// while !contents.is_empty() { /// // Wait for the stream to become writable - /// poll-one(pollable); + /// pollable.block(); /// let Ok(n) = this.check-write(); // eliding error handling /// let len = min(n, contents.len()); /// let (chunk, rest) = contents.split_at(len); @@ -168,7 +151,7 @@ interface streams { /// } /// this.flush(); /// // Wait for completion of `flush` - /// poll-one(pollable); + /// pollable.block(); /// // Check for any errors that arose during `flush` /// let _ = this.check-write(); // eliding error handling /// ``` @@ -206,7 +189,7 @@ interface streams { /// Write zeroes to a stream. /// - /// this should be used precisely like `write` with the exact same + /// 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. @@ -227,7 +210,7 @@ interface streams { /// let pollable = this.subscribe(); /// while num_zeroes != 0 { /// // Wait for the stream to become writable - /// poll-one(pollable); + /// pollable.block(); /// let Ok(n) = this.check-write(); // eliding error handling /// let len = min(n, num_zeroes); /// this.write-zeroes(len); // eliding error handling @@ -235,7 +218,7 @@ interface streams { /// } /// this.flush(); /// // Wait for completion of `flush` - /// poll-one(pollable); + /// pollable.block(); /// // Check for any errors that arose during `flush` /// let _ = this.check-write(); // eliding error handling /// ``` @@ -246,44 +229,34 @@ interface streams { /// 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`. - /// - /// Unlike other I/O functions, this function blocks until all the data - /// read from the input stream has been written to the output stream. splice: func( /// The stream to read from - src: input-stream, + 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 at least - /// one byte can be read. + /// 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: input-stream, + src: borrow, /// The number of bytes to splice len: u64, ) -> result; - - /// Forward the entire contents of an input stream to an output stream. - /// - /// This function repeatedly reads from the input stream and writes - /// the data to the output stream, until the end of the input stream - /// is reached, or an error is encountered. - /// - /// Unlike other I/O functions, this function blocks until the end - /// of the input stream is seen and all the data has been written to - /// the output stream. - /// - /// This function returns the number of bytes transferred, and the status of - /// the output stream. - forward: func( - /// The stream to read from - src: input-stream - ) -> result; } } diff --git a/examples/wit/deps/io/world.wit b/examples/wit/deps/io/world.wit index 3627c9d..5f0b43f 100644 --- a/examples/wit/deps/io/world.wit +++ b/examples/wit/deps/io/world.wit @@ -1,4 +1,4 @@ -package wasi:io@0.2.0-rc-2023-10-18; +package wasi:io@0.2.0; world imports { import streams; diff --git a/examples/wit/deps/logging/logging.wit b/examples/wit/deps/logging/logging.wit deleted file mode 100644 index b897a5a..0000000 --- a/examples/wit/deps/logging/logging.wit +++ /dev/null @@ -1,37 +0,0 @@ -package wasi:logging@0.2.0-rc-2023-10-18; - -/// WASI Logging is a logging API intended to let users emit log messages with -/// simple priority levels and context values. -interface logging { - /// A log level, describing a kind of message. - enum level { - /// Describes messages about the values of variables and the flow of - /// control within a program. - trace, - - /// Describes messages likely to be of interest to someone debugging a - /// program. - debug, - - /// Describes messages likely to be of interest to someone monitoring a - /// program. - info, - - /// Describes messages indicating hazardous situations. - warn, - - /// Describes messages indicating serious errors. - error, - - /// Describes messages indicating fatal errors. - critical, - } - - /// Emit a log message. - /// - /// A log message has a `level` describing what kind of message is being - /// sent, a context, which is an uninterpreted string meant to help - /// consumers group similar messages, and a string containing the message - /// text. - log: func(level: level, context: string, message: string); -} diff --git a/examples/wit/deps/logging/world.wit b/examples/wit/deps/logging/world.wit deleted file mode 100644 index a0fb255..0000000 --- a/examples/wit/deps/logging/world.wit +++ /dev/null @@ -1,5 +0,0 @@ -package wasi:logging@0.2.0-rc-2023-10-18; - -world imports { - import logging; -} diff --git a/examples/wit/deps/random-2023-10-18/insecure-seed.wit b/examples/wit/deps/random-2023-10-18/insecure-seed.wit new file mode 100644 index 0000000..139aed1 --- /dev/null +++ b/examples/wit/deps/random-2023-10-18/insecure-seed.wit @@ -0,0 +1,24 @@ +/// 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/examples/wit/deps/random-2023-10-18/insecure.wit b/examples/wit/deps/random-2023-10-18/insecure.wit new file mode 100644 index 0000000..2ffd223 --- /dev/null +++ b/examples/wit/deps/random-2023-10-18/insecure.wit @@ -0,0 +1,21 @@ +/// 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/examples/wit/deps/random-2023-10-18/random.wit b/examples/wit/deps/random-2023-10-18/random.wit new file mode 100644 index 0000000..2c3c6a8 --- /dev/null +++ b/examples/wit/deps/random-2023-10-18/random.wit @@ -0,0 +1,25 @@ +/// 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/examples/wit/deps/random-2023-10-18/world.wit b/examples/wit/deps/random-2023-10-18/world.wit new file mode 100644 index 0000000..dcbff93 --- /dev/null +++ b/examples/wit/deps/random-2023-10-18/world.wit @@ -0,0 +1,7 @@ +package wasi:random@0.2.0-rc-2023-10-18; + +world imports { + import random; + import insecure; + import insecure-seed; +} diff --git a/examples/wit/deps/random-2023-11-10/insecure-seed.wit b/examples/wit/deps/random-2023-11-10/insecure-seed.wit new file mode 100644 index 0000000..f76e87d --- /dev/null +++ b/examples/wit/deps/random-2023-11-10/insecure-seed.wit @@ -0,0 +1,25 @@ +package wasi:random@0.2.0-rc-2023-11-10; +/// 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/examples/wit/deps/random-2023-11-10/insecure.wit b/examples/wit/deps/random-2023-11-10/insecure.wit new file mode 100644 index 0000000..ec7b997 --- /dev/null +++ b/examples/wit/deps/random-2023-11-10/insecure.wit @@ -0,0 +1,22 @@ +package wasi:random@0.2.0-rc-2023-11-10; +/// 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/examples/wit/deps/random-2023-11-10/random.wit b/examples/wit/deps/random-2023-11-10/random.wit new file mode 100644 index 0000000..7a7dfa2 --- /dev/null +++ b/examples/wit/deps/random-2023-11-10/random.wit @@ -0,0 +1,26 @@ +package wasi:random@0.2.0-rc-2023-11-10; +/// 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/examples/wit/deps/random-2023-11-10/world.wit b/examples/wit/deps/random-2023-11-10/world.wit new file mode 100644 index 0000000..49e5743 --- /dev/null +++ b/examples/wit/deps/random-2023-11-10/world.wit @@ -0,0 +1,7 @@ +package wasi:random@0.2.0-rc-2023-11-10; + +world imports { + import random; + import insecure; + import insecure-seed; +} diff --git a/examples/wit/deps/random/insecure-seed.wit b/examples/wit/deps/random/insecure-seed.wit index 139aed1..47210ac 100644 --- a/examples/wit/deps/random/insecure-seed.wit +++ b/examples/wit/deps/random/insecure-seed.wit @@ -1,3 +1,4 @@ +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 diff --git a/examples/wit/deps/random/insecure.wit b/examples/wit/deps/random/insecure.wit index 2ffd223..c58f4ee 100644 --- a/examples/wit/deps/random/insecure.wit +++ b/examples/wit/deps/random/insecure.wit @@ -1,3 +1,4 @@ +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 diff --git a/examples/wit/deps/random/random.wit b/examples/wit/deps/random/random.wit index 2c3c6a8..0c017f0 100644 --- a/examples/wit/deps/random/random.wit +++ b/examples/wit/deps/random/random.wit @@ -1,3 +1,4 @@ +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 diff --git a/examples/wit/deps/random/world.wit b/examples/wit/deps/random/world.wit index dcbff93..3da3491 100644 --- a/examples/wit/deps/random/world.wit +++ b/examples/wit/deps/random/world.wit @@ -1,4 +1,4 @@ -package wasi:random@0.2.0-rc-2023-10-18; +package wasi:random@0.2.0; world imports { import random; diff --git a/examples/wit/deps/sockets-2023-10-18/instance-network.wit b/examples/wit/deps/sockets-2023-10-18/instance-network.wit new file mode 100644 index 0000000..14e4479 --- /dev/null +++ b/examples/wit/deps/sockets-2023-10-18/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/examples/wit/deps/sockets-2023-10-18/ip-name-lookup.wit b/examples/wit/deps/sockets-2023-10-18/ip-name-lookup.wit new file mode 100644 index 0000000..f2dab32 --- /dev/null +++ b/examples/wit/deps/sockets-2023-10-18/ip-name-lookup.wit @@ -0,0 +1,61 @@ + +interface ip-name-lookup { + use wasi:io/poll@0.2.0-rc-2023-10-18.{pollable}; + use network.{network, error-code, ip-address, ip-address-family}; + + + /// Resolve an internet host name to a list of IP addresses. + /// + /// See the wasi-socket proposal README.md for a comparison with getaddrinfo. + /// + /// # Parameters + /// - `name`: The name to look up. IP addresses are not allowed. Unicode domain names are automatically converted + /// to ASCII using IDNA encoding. + /// - `address-family`: If provided, limit the results to addresses of this specific address family. + /// - `include-unavailable`: When set to true, this function will also return addresses of which the runtime + /// thinks (or knows) can't be connected to at the moment. For example, this will return IPv6 addresses on + /// systems without an active IPv6 interface. Notes: + /// - Even when no public IPv6 interfaces are present or active, names like "localhost" can still resolve to an IPv6 address. + /// - Whatever is "available" or "unavailable" is volatile and can change everytime a network cable is unplugged. + /// + /// 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. + /// + /// At the moment, the stream never completes successfully with 0 items. Ie. the first call + /// to `resolve-next-address` never returns `ok(none)`. This may change in the future. + /// + /// # Typical errors + /// - `invalid-argument`: `name` is a syntactically invalid domain name. + /// - `invalid-argument`: `name` is an IP address. + /// - `not-supported`: The specified `address-family` is not supported. (EAI_FAMILY) + /// + /// # References: + /// - + /// - + /// - + /// - + resolve-addresses: func(network: borrow, name: string, address-family: option, include-unavailable: bool) -> 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/examples/wit/deps/sockets-2023-10-18/network.wit b/examples/wit/deps/sockets-2023-10-18/network.wit new file mode 100644 index 0000000..fc51604 --- /dev/null +++ b/examples/wit/deps/sockets-2023-10-18/network.wit @@ -0,0 +1,146 @@ + +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 { + // ### GENERAL ERRORS ### + + /// 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, + + + + // ### TCP & UDP SOCKET ERRORS ### + + /// 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, + + + // ### TCP SOCKET ERRORS ### + + /// The connection was forcefully rejected + connection-refused, + + /// The connection was reset. + connection-reset, + + /// A connection was aborted. + connection-aborted, + + // ### UDP SOCKET ERRORS ### + datagram-too-large, + + + // ### NAME LOOKUP ERRORS ### + + /// 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 { + port: u16, // sin_port + address: ipv4-address, // sin_addr + } + + record ipv6-socket-address { + port: u16, // sin6_port + flow-info: u32, // sin6_flowinfo + address: ipv6-address, // sin6_addr + scope-id: u32, // sin6_scope_id + } + + variant ip-socket-address { + ipv4(ipv4-socket-address), + ipv6(ipv6-socket-address), + } + +} diff --git a/examples/wit/deps/sockets-2023-10-18/tcp-create-socket.wit b/examples/wit/deps/sockets-2023-10-18/tcp-create-socket.wit new file mode 100644 index 0000000..a9a3373 --- /dev/null +++ b/examples/wit/deps/sockets-2023-10-18/tcp-create-socket.wit @@ -0,0 +1,26 @@ + +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. + /// + /// 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`/`listen`/`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/examples/wit/deps/sockets-2023-10-18/tcp.wit b/examples/wit/deps/sockets-2023-10-18/tcp.wit new file mode 100644 index 0000000..448f629 --- /dev/null +++ b/examples/wit/deps/sockets-2023-10-18/tcp.wit @@ -0,0 +1,268 @@ + +interface tcp { + use wasi:io/streams@0.2.0-rc-2023-10-18.{input-stream, output-stream}; + use wasi:io/poll@0.2.0-rc-2023-10-18.{pollable}; + 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 handle. + 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. + /// + /// When a socket is not explicitly bound, the first invocation to a listen or connect operation will + /// implicitly bind the socket. + /// + /// Unlike in POSIX, this function is async. This enables interactive WASI hosts to inject permission prompts. + /// + /// # Typical `start` 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, but the socket has `ipv6-only` enabled. (EINVAL) + /// - `invalid-state`: The socket is already bound. (EINVAL) + /// + /// # Typical `finish` errors + /// - `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) + /// + /// # 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 + /// + /// POSIX mentions: + /// > If connect() fails, the state of the socket is unspecified. Conforming applications should + /// > close the file descriptor and create a new socket before attempting to reconnect. + /// + /// WASI prescribes the following behavior: + /// - If `connect` fails because an input/state validation error, the socket should remain usable. + /// - If a connection was actually attempted but failed, the socket should become unusable for further network communication. + /// Besides `drop`, any method after such a failure may return an error. + /// + /// # Typical `start` 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, but the socket has `ipv6-only` enabled. (EINVAL, EADDRNOTAVAIL on Illumos) + /// - `invalid-argument`: `remote-address` is a non-IPv4-mapped IPv6 address, but the socket was bound to a specific IPv4-mapped IPv6 address. (or vice versa) + /// - `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 Connection state. (EISCONN) + /// - `invalid-state`: The socket is already in the Listener state. (EOPNOTSUPP, EINVAL on Windows) + /// + /// # Typical `finish` errors + /// - `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) + /// - `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) + /// + /// # 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 Listener state. + /// + /// Unlike POSIX: + /// - this function is async. This enables interactive WASI hosts to inject permission prompts. + /// - the socket must already be explicitly bound. + /// + /// # Typical `start` errors + /// - `invalid-state`: The socket is not bound to any local address. (EDESTADDRREQ) + /// - `invalid-state`: The socket is already in the Connection state. (EISCONN, EINVAL on BSD) + /// - `invalid-state`: The socket is already in the Listener state. + /// + /// # Typical `finish` errors + /// - `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) + /// + /// # 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 Connection state. The following properties are inherited from the listener socket: + /// - `address-family` + /// - `ipv6-only` + /// - `keep-alive` + /// - `no-delay` + /// - `unicast-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 Listener 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 this is a IPv4 or IPv6 socket. + /// + /// Equivalent to the SO_DOMAIN socket option. + address-family: func() -> ip-address-family; + + /// Whether IPv4 compatibility (dual-stack) mode is disabled or not. + /// + /// Equivalent to the IPV6_V6ONLY socket option. + /// + /// # Typical errors + /// - `invalid-state`: (set) The socket is already bound. + /// - `not-supported`: (get/set) `this` socket is an IPv4 socket. + /// - `not-supported`: (set) Host does not support dual-stack sockets. (Implementations are not required to.) + ipv6-only: func() -> result; + set-ipv6-only: func(value: bool) -> result<_, error-code>; + + /// Hints the desired listen queue size. Implementations are free to ignore this. + /// + /// # Typical errors + /// - `not-supported`: (set) The platform does not support changing the backlog size after the initial listen. + /// - `invalid-state`: (set) The socket is already in the Connection state. + set-listen-backlog-size: func(value: u64) -> result<_, error-code>; + + /// Equivalent to the SO_KEEPALIVE socket option. + keep-alive: func() -> result; + set-keep-alive: func(value: bool) -> result<_, error-code>; + + /// Equivalent to the TCP_NODELAY socket option. + /// + /// The default value is `false`. + no-delay: func() -> result; + set-no-delay: func(value: bool) -> result<_, error-code>; + + /// Equivalent to the IP_TTL & IPV6_UNICAST_HOPS socket options. + /// + /// # Typical errors + /// - `invalid-argument`: (set) The TTL value must be 1 or higher. + /// - `invalid-state`: (set) The socket is already in the Connection state. + /// - `invalid-state`: (set) The socket is already in the Listener state. + 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. + /// + /// Note #1: an implementation may choose to cap or round the buffer size when setting the value. + /// In other words, after setting a value, reading the same setting back may return a different value. + /// + /// Note #2: there is not necessarily a direct relationship between the kernel buffer size and the bytes of + /// actual data to be sent/received by the application, because the kernel might also use the buffer space + /// for internal metadata structures. + /// + /// Equivalent to the SO_RCVBUF and SO_SNDBUF socket options. + /// + /// # Typical errors + /// - `invalid-state`: (set) The socket is already in the Connection state. + /// - `invalid-state`: (set) The socket is already in the Listener state. + 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; + + /// Initiate a graceful shutdown. + /// + /// - receive: the socket is not expecting to receive any more data from the peer. All subsequent read + /// operations on the `input-stream` associated with this socket will return an End Of Stream indication. + /// Any data still in the receive queue at time of calling `shutdown` will be discarded. + /// - send: the socket is not expecting to send any more data to the peer. All subsequent write + /// operations on the `output-stream` associated with this socket will return an error. + /// - both: same effect as receive & send combined. + /// + /// The shutdown function does not close (drop) the socket. + /// + /// # Typical errors + /// - `invalid-state`: The socket is not in the Connection state. (ENOTCONN) + /// + /// # References + /// - + /// - + /// - + /// - + shutdown: func(shutdown-type: shutdown-type) -> result<_, error-code>; + } +} diff --git a/examples/wit/deps/sockets-2023-10-18/udp-create-socket.wit b/examples/wit/deps/sockets-2023-10-18/udp-create-socket.wit new file mode 100644 index 0000000..e026359 --- /dev/null +++ b/examples/wit/deps/sockets-2023-10-18/udp-create-socket.wit @@ -0,0 +1,26 @@ + +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. + /// + /// 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-udp-socket: func(address-family: ip-address-family) -> result; +} diff --git a/examples/wit/deps/sockets-2023-10-18/udp.wit b/examples/wit/deps/sockets-2023-10-18/udp.wit new file mode 100644 index 0000000..91a8c6c --- /dev/null +++ b/examples/wit/deps/sockets-2023-10-18/udp.wit @@ -0,0 +1,213 @@ + +interface udp { + use wasi:io/poll@0.2.0-rc-2023-10-18.{pollable}; + use network.{network, error-code, ip-socket-address, ip-address-family}; + + + record datagram { + data: list, // Theoretical max size: ~64 KiB. In practice, typically less than 1500 bytes. + remote-address: ip-socket-address, + + /// Possible future additions: + /// local-address: ip-socket-address, // IP_PKTINFO / IP_RECVDSTADDR / IPV6_PKTINFO + /// local-interface: u32, // IP_PKTINFO / IP_RECVIF + /// ttl: u8, // IP_RECVTTL + /// dscp: u6, // IP_RECVTOS + /// ecn: u2, // IP_RECVTOS + } + + + + /// 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 TCP/UDP port is zero, the socket will be bound to a random free port. + /// + /// When a socket is not explicitly bound, the first invocation to connect will implicitly bind the socket. + /// + /// Unlike in POSIX, this function is async. This enables interactive WASI hosts to inject permission prompts. + /// + /// # Typical `start` errors + /// - `invalid-argument`: The `local-address` has the wrong address family. (EAFNOSUPPORT, EFAULT on Windows) + /// - `invalid-state`: The socket is already bound. (EINVAL) + /// + /// # Typical `finish` errors + /// - `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) + /// + /// # References + /// - + /// - + /// - + /// - + start-bind: func(network: borrow, local-address: ip-socket-address) -> result<_, error-code>; + finish-bind: func() -> result<_, error-code>; + + /// Set the destination address. + /// + /// The local-address is updated based on the best network path to `remote-address`. + /// + /// When a destination address is set: + /// - all receive operations will only return datagrams sent from the provided `remote-address`. + /// - the `send` function can only be used to send to this destination. + /// + /// Note that this function does not generate any network traffic and the peer is not aware of this "connection". + /// + /// Unlike in POSIX, this function is async. This enables interactive WASI hosts to inject permission prompts. + /// + /// # Typical `start` errors + /// - `invalid-argument`: The `remote-address` has the wrong address family. (EAFNOSUPPORT) + /// - `invalid-argument`: `remote-address` is a non-IPv4-mapped IPv6 address, but the socket was bound to a specific IPv4-mapped IPv6 address. (or vice versa) + /// - `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 already bound to a different network. The `network` passed to `connect` must be identical to the one passed to `bind`. + /// + /// # Typical `finish` errors + /// - `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) + /// + /// # References + /// - + /// - + /// - + /// - + start-connect: func(network: borrow, remote-address: ip-socket-address) -> result<_, error-code>; + finish-connect: func() -> result<_, error-code>; + + /// 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. + /// If `max-results` is 0, this function returns successfully with an empty list. + /// + /// # Typical errors + /// - `invalid-state`: The socket is not bound to any local address. (EINVAL) + /// - `remote-unreachable`: The remote address is not reachable. (ECONNREFUSED, ECONNRESET, ENETRESET on Windows, EHOSTUNREACH, EHOSTDOWN, ENETUNREACH, ENETDOWN) + /// - `would-block`: There is no pending data available to be read at the moment. (EWOULDBLOCK, EAGAIN) + /// + /// # References + /// - + /// - + /// - + /// - + /// - + /// - + /// - + /// - + receive: func(max-results: u64) -> result, error-code>; + + /// 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 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)`. + /// + /// The remote address option is required. To send a message to the "connected" peer, + /// call `remote-address` to get their address. + /// + /// # Typical errors + /// - `invalid-argument`: The `remote-address` has the wrong address family. (EAFNOSUPPORT) + /// - `invalid-argument`: `remote-address` is a non-IPv4-mapped IPv6 address, but the socket was bound to a specific IPv4-mapped IPv6 address. (or vice versa) + /// - `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 the `datagram.remote-address` does not match the address passed to `connect`. (EISCONN) + /// - `invalid-state`: The socket is not bound to any local address. Unlike POSIX, this function does not perform an implicit bind. + /// - `remote-unreachable`: The remote address is not reachable. (ECONNREFUSED, ECONNRESET, ENETRESET on Windows, EHOSTUNREACH, EHOSTDOWN, ENETUNREACH, ENETDOWN) + /// - `datagram-too-large`: The datagram is too large. (EMSGSIZE) + /// - `would-block`: The send buffer is currently full. (EWOULDBLOCK, EAGAIN) + /// + /// # References + /// - + /// - + /// - + /// - + /// - + /// - + /// - + /// - + send: func(datagrams: list) -> result; + + /// 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 set with `connect`. + /// + /// # Typical errors + /// - `invalid-state`: The socket is not connected to a 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; + + /// Whether IPv4 compatibility (dual-stack) mode is disabled or not. + /// + /// Equivalent to the IPV6_V6ONLY socket option. + /// + /// # Typical errors + /// - `not-supported`: (get/set) `this` socket is an IPv4 socket. + /// - `invalid-state`: (set) The socket is already bound. + /// - `not-supported`: (set) Host does not support dual-stack sockets. (Implementations are not required to.) + ipv6-only: func() -> result; + set-ipv6-only: func(value: bool) -> result<_, error-code>; + + /// Equivalent to the IP_TTL & IPV6_UNICAST_HOPS socket options. + 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. + /// + /// Note #1: an implementation may choose to cap or round the buffer size when setting the value. + /// In other words, after setting a value, reading the same setting back may return a different value. + /// + /// Note #2: there is not necessarily a direct relationship between the kernel buffer size and the bytes of + /// actual data to be sent/received by the application, because the kernel might also use the buffer space + /// for internal metadata structures. + /// + /// Equivalent to the SO_RCVBUF and SO_SNDBUF socket options. + 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; + } +} diff --git a/examples/wit/deps/sockets-2023-10-18/world.wit b/examples/wit/deps/sockets-2023-10-18/world.wit new file mode 100644 index 0000000..d16530c --- /dev/null +++ b/examples/wit/deps/sockets-2023-10-18/world.wit @@ -0,0 +1,11 @@ +package wasi:sockets@0.2.0-rc-2023-10-18; + +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/examples/wit/deps/sockets-2023-11-10/instance-network.wit b/examples/wit/deps/sockets-2023-11-10/instance-network.wit new file mode 100644 index 0000000..e455d0f --- /dev/null +++ b/examples/wit/deps/sockets-2023-11-10/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/examples/wit/deps/sockets-2023-11-10/ip-name-lookup.wit b/examples/wit/deps/sockets-2023-11-10/ip-name-lookup.wit new file mode 100644 index 0000000..931ccf7 --- /dev/null +++ b/examples/wit/deps/sockets-2023-11-10/ip-name-lookup.wit @@ -0,0 +1,51 @@ + +interface ip-name-lookup { + use wasi:io/poll@0.2.0-rc-2023-11-10.{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/examples/wit/deps/sockets-2023-11-10/network.wit b/examples/wit/deps/sockets-2023-11-10/network.wit new file mode 100644 index 0000000..6bb07cd --- /dev/null +++ b/examples/wit/deps/sockets-2023-11-10/network.wit @@ -0,0 +1,147 @@ + +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 { + // ### GENERAL ERRORS ### + + /// 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, + + + + // ### TCP & UDP SOCKET ERRORS ### + + /// 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, + + + // ### TCP SOCKET ERRORS ### + + /// The connection was forcefully rejected + connection-refused, + + /// The connection was reset. + connection-reset, + + /// A connection was aborted. + connection-aborted, + + + // ### UDP SOCKET ERRORS ### + datagram-too-large, + + + // ### NAME LOOKUP ERRORS ### + + /// 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 { + port: u16, // sin_port + address: ipv4-address, // sin_addr + } + + record ipv6-socket-address { + port: u16, // sin6_port + flow-info: u32, // sin6_flowinfo + address: ipv6-address, // sin6_addr + scope-id: u32, // sin6_scope_id + } + + variant ip-socket-address { + ipv4(ipv4-socket-address), + ipv6(ipv6-socket-address), + } + +} diff --git a/examples/wit/deps/sockets-2023-11-10/tcp-create-socket.wit b/examples/wit/deps/sockets-2023-11-10/tcp-create-socket.wit new file mode 100644 index 0000000..768a07c --- /dev/null +++ b/examples/wit/deps/sockets-2023-11-10/tcp-create-socket.wit @@ -0,0 +1,26 @@ + +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. + /// + /// 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`/`listen`/`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/examples/wit/deps/sockets-2023-11-10/tcp.wit b/examples/wit/deps/sockets-2023-11-10/tcp.wit new file mode 100644 index 0000000..b01b65e --- /dev/null +++ b/examples/wit/deps/sockets-2023-11-10/tcp.wit @@ -0,0 +1,321 @@ + +interface tcp { + use wasi:io/streams@0.2.0-rc-2023-11-10.{input-stream, output-stream}; + use wasi:io/poll@0.2.0-rc-2023-11-10.{pollable}; + use wasi:clocks/monotonic-clock@0.2.0-rc-2023-11-10.{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 handle. + 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. + /// + /// When a socket is not explicitly bound, the first invocation to a listen or connect operation will + /// implicitly bind the socket. + /// + /// Unlike in POSIX, this function is async. This enables interactive WASI hosts to inject permission prompts. + /// + /// # Typical `start` 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, but the socket has `ipv6-only` enabled. (EINVAL) + /// - `invalid-state`: The socket is already bound. (EINVAL) + /// + /// # Typical `finish` errors + /// - `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) + /// + /// # 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 + /// + /// POSIX mentions: + /// > If connect() fails, the state of the socket is unspecified. Conforming applications should + /// > close the file descriptor and create a new socket before attempting to reconnect. + /// + /// WASI prescribes the following behavior: + /// - If `connect` fails because an input/state validation error, the socket should remain usable. + /// - If a connection was actually attempted but failed, the socket should become unusable for further network communication. + /// Besides `drop`, any method after such a failure may return an error. + /// + /// # Typical `start` 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, but the socket has `ipv6-only` enabled. (EINVAL, EADDRNOTAVAIL on Illumos) + /// - `invalid-argument`: `remote-address` is a non-IPv4-mapped IPv6 address, but the socket was bound to a specific IPv4-mapped IPv6 address. (or vice versa) + /// - `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 Connection state. (EISCONN) + /// - `invalid-state`: The socket is already in the Listener state. (EOPNOTSUPP, EINVAL on Windows) + /// + /// # Typical `finish` errors + /// - `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) + /// + /// # 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 Listener state. + /// + /// Unlike POSIX: + /// - this function is async. This enables interactive WASI hosts to inject permission prompts. + /// - the socket must already be explicitly bound. + /// + /// # Typical `start` errors + /// - `invalid-state`: The socket is not bound to any local address. (EDESTADDRREQ) + /// - `invalid-state`: The socket is already in the Connection state. (EISCONN, EINVAL on BSD) + /// - `invalid-state`: The socket is already in the Listener state. + /// + /// # Typical `finish` errors + /// - `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) + /// + /// # 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 Connection state. The following properties are inherited from the listener socket: + /// - `address-family` + /// - `ipv6-only` + /// - `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 Listener 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 listening for new connections. + /// + /// 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; + + /// Whether IPv4 compatibility (dual-stack) mode is disabled or not. + /// + /// Equivalent to the IPV6_V6ONLY socket option. + /// + /// # Typical errors + /// - `invalid-state`: (set) The socket is already bound. + /// - `not-supported`: (get/set) `this` socket is an IPv4 socket. + /// - `not-supported`: (set) Host does not support dual-stack sockets. (Implementations are not required to.) + ipv6-only: func() -> result; + set-ipv6-only: func(value: bool) -> result<_, error-code>; + + /// 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 already in the Connection 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. + /// - `invalid-state`: (set) The socket is already in the Connection state. + /// - `invalid-state`: (set) The socket is already in the Listener state. + 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. + /// - `invalid-state`: (set) The socket is already in the Connection state. + /// - `invalid-state`: (set) The socket is already in the Listener state. + 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; + + /// Initiate a graceful shutdown. + /// + /// - receive: the socket is not expecting to receive any more data from the peer. All subsequent read + /// operations on the `input-stream` associated with this socket will return an End Of Stream indication. + /// Any data still in the receive queue at time of calling `shutdown` will be discarded. + /// - send: the socket is not expecting to send any more data to the peer. All subsequent write + /// operations on the `output-stream` associated with this socket will return an error. + /// - both: same effect as receive & send combined. + /// + /// The shutdown function does not close (drop) the socket. + /// + /// # Typical errors + /// - `invalid-state`: The socket is not in the Connection state. (ENOTCONN) + /// + /// # References + /// - + /// - + /// - + /// - + shutdown: func(shutdown-type: shutdown-type) -> result<_, error-code>; + } +} diff --git a/examples/wit/deps/sockets-2023-11-10/udp-create-socket.wit b/examples/wit/deps/sockets-2023-11-10/udp-create-socket.wit new file mode 100644 index 0000000..cc58234 --- /dev/null +++ b/examples/wit/deps/sockets-2023-11-10/udp-create-socket.wit @@ -0,0 +1,26 @@ + +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. + /// + /// 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/examples/wit/deps/sockets-2023-11-10/udp.wit b/examples/wit/deps/sockets-2023-11-10/udp.wit new file mode 100644 index 0000000..c8dafad --- /dev/null +++ b/examples/wit/deps/sockets-2023-11-10/udp.wit @@ -0,0 +1,277 @@ + +interface udp { + use wasi:io/poll@0.2.0-rc-2023-11-10.{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. + /// + /// Unlike in POSIX, this function is async. This enables interactive WASI hosts to inject permission prompts. + /// + /// # Typical `start` errors + /// - `invalid-argument`: The `local-address` has the wrong address family. (EAFNOSUPPORT, EFAULT on Windows) + /// - `invalid-state`: The socket is already bound. (EINVAL) + /// + /// # Typical `finish` errors + /// - `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) + /// + /// # 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`: `remote-address` is a non-IPv4-mapped IPv6 address, but the socket was bound to a specific IPv4-mapped IPv6 address. (or vice versa) + /// - `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; + + /// Whether IPv4 compatibility (dual-stack) mode is disabled or not. + /// + /// Equivalent to the IPV6_V6ONLY socket option. + /// + /// # Typical errors + /// - `not-supported`: (get/set) `this` socket is an IPv4 socket. + /// - `invalid-state`: (set) The socket is already bound. + /// - `not-supported`: (set) Host does not support dual-stack sockets. (Implementations are not required to.) + ipv6-only: func() -> result; + set-ipv6-only: func(value: bool) -> 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. + 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`: `remote-address` is a non-IPv4-mapped IPv6 address, but the socket was bound to a specific IPv4-mapped IPv6 address. (or vice versa) + /// - `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/examples/wit/deps/sockets-2023-11-10/world.wit b/examples/wit/deps/sockets-2023-11-10/world.wit new file mode 100644 index 0000000..49ad8d3 --- /dev/null +++ b/examples/wit/deps/sockets-2023-11-10/world.wit @@ -0,0 +1,11 @@ +package wasi:sockets@0.2.0-rc-2023-11-10; + +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/examples/wit/deps/sockets/instance-network.wit b/examples/wit/deps/sockets/instance-network.wit index 14e4479..e455d0f 100644 --- a/examples/wit/deps/sockets/instance-network.wit +++ b/examples/wit/deps/sockets/instance-network.wit @@ -1,9 +1,9 @@ /// This interface provides a value-export of the default network handle.. interface instance-network { - use network.{network}; + use network.{network}; - /// Get a handle to the default network. - instance-network: func() -> network; + /// Get a handle to the default network. + instance-network: func() -> network; } diff --git a/examples/wit/deps/sockets/ip-name-lookup.wit b/examples/wit/deps/sockets/ip-name-lookup.wit index f2dab32..8e639ec 100644 --- a/examples/wit/deps/sockets/ip-name-lookup.wit +++ b/examples/wit/deps/sockets/ip-name-lookup.wit @@ -1,61 +1,51 @@ interface ip-name-lookup { - use wasi:io/poll@0.2.0-rc-2023-10-18.{pollable}; - use network.{network, error-code, ip-address, ip-address-family}; + 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. - /// - /// See the wasi-socket proposal README.md for a comparison with getaddrinfo. - /// - /// # Parameters - /// - `name`: The name to look up. IP addresses are not allowed. Unicode domain names are automatically converted - /// to ASCII using IDNA encoding. - /// - `address-family`: If provided, limit the results to addresses of this specific address family. - /// - `include-unavailable`: When set to true, this function will also return addresses of which the runtime - /// thinks (or knows) can't be connected to at the moment. For example, this will return IPv6 addresses on - /// systems without an active IPv6 interface. Notes: - /// - Even when no public IPv6 interfaces are present or active, names like "localhost" can still resolve to an IPv6 address. - /// - Whatever is "available" or "unavailable" is volatile and can change everytime a network cable is unplugged. - /// - /// 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. - /// - /// At the moment, the stream never completes successfully with 0 items. Ie. the first call - /// to `resolve-next-address` never returns `ok(none)`. This may change in the future. - /// - /// # Typical errors - /// - `invalid-argument`: `name` is a syntactically invalid domain name. - /// - `invalid-argument`: `name` is an IP address. - /// - `not-supported`: The specified `address-family` is not supported. (EAI_FAMILY) - /// - /// # References: - /// - - /// - - /// - - /// - - resolve-addresses: func(network: borrow, name: string, address-family: option, include-unavailable: bool) -> result; + /// 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>; + 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; - } + /// 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/examples/wit/deps/sockets/network.wit b/examples/wit/deps/sockets/network.wit index fc51604..9cadf06 100644 --- a/examples/wit/deps/sockets/network.wit +++ b/examples/wit/deps/sockets/network.wit @@ -1,146 +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; + /// 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 { - // ### GENERAL ERRORS ### + /// 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, - /// Unknown error - unknown, + /// Access denied. + /// + /// POSIX equivalent: EACCES, EPERM + access-denied, - /// 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), + } - /// The operation is not supported. - /// - /// POSIX equivalent: EOPNOTSUPP - not-supported, + record ipv4-socket-address { + /// sin_port + port: u16, + /// sin_addr + address: ipv4-address, + } - /// One of the arguments is invalid. - /// - /// POSIX equivalent: EINVAL - invalid-argument, + record ipv6-socket-address { + /// sin6_port + port: u16, + /// sin6_flowinfo + flow-info: u32, + /// sin6_addr + address: ipv6-address, + /// sin6_scope_id + scope-id: u32, + } - /// 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, - - - - // ### TCP & UDP SOCKET ERRORS ### - - /// 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, - - - // ### TCP SOCKET ERRORS ### - - /// The connection was forcefully rejected - connection-refused, - - /// The connection was reset. - connection-reset, - - /// A connection was aborted. - connection-aborted, - - // ### UDP SOCKET ERRORS ### - datagram-too-large, - - - // ### NAME LOOKUP ERRORS ### - - /// 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 { - port: u16, // sin_port - address: ipv4-address, // sin_addr - } - - record ipv6-socket-address { - port: u16, // sin6_port - flow-info: u32, // sin6_flowinfo - address: ipv6-address, // sin6_addr - scope-id: u32, // sin6_scope_id - } - - variant ip-socket-address { - ipv4(ipv4-socket-address), - ipv6(ipv6-socket-address), - } + variant ip-socket-address { + ipv4(ipv4-socket-address), + ipv6(ipv6-socket-address), + } } diff --git a/examples/wit/deps/sockets/tcp-create-socket.wit b/examples/wit/deps/sockets/tcp-create-socket.wit index a9a3373..c7ddf1f 100644 --- a/examples/wit/deps/sockets/tcp-create-socket.wit +++ b/examples/wit/deps/sockets/tcp-create-socket.wit @@ -1,26 +1,27 @@ interface tcp-create-socket { - use network.{network, error-code, ip-address-family}; - use tcp.{tcp-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. - /// - /// 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`/`listen`/`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; + /// 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/examples/wit/deps/sockets/tcp.wit b/examples/wit/deps/sockets/tcp.wit index 448f629..5902b9e 100644 --- a/examples/wit/deps/sockets/tcp.wit +++ b/examples/wit/deps/sockets/tcp.wit @@ -1,268 +1,353 @@ interface tcp { - use wasi:io/streams@0.2.0-rc-2023-10-18.{input-stream, output-stream}; - use wasi:io/poll@0.2.0-rc-2023-10-18.{pollable}; - use network.{network, error-code, ip-socket-address, ip-address-family}; + 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, + enum shutdown-type { + /// Similar to `SHUT_RD` in POSIX. + receive, - /// Similar to `SHUT_WR` in POSIX. - send, + /// Similar to `SHUT_WR` in POSIX. + send, - /// Similar to `SHUT_RDWR` in POSIX. - both, - } + /// 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>; - /// A TCP socket handle. - 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. - /// - /// When a socket is not explicitly bound, the first invocation to a listen or connect operation will - /// implicitly bind the socket. - /// - /// Unlike in POSIX, this function is async. This enables interactive WASI hosts to inject permission prompts. - /// - /// # Typical `start` 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, but the socket has `ipv6-only` enabled. (EINVAL) - /// - `invalid-state`: The socket is already bound. (EINVAL) - /// - /// # Typical `finish` errors - /// - `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) - /// - /// # References - /// - - /// - - /// - - /// - - start-bind: func(network: borrow, local-address: ip-socket-address) -> result<_, error-code>; - finish-bind: 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>; - /// 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 - /// - /// POSIX mentions: - /// > If connect() fails, the state of the socket is unspecified. Conforming applications should - /// > close the file descriptor and create a new socket before attempting to reconnect. - /// - /// WASI prescribes the following behavior: - /// - If `connect` fails because an input/state validation error, the socket should remain usable. - /// - If a connection was actually attempted but failed, the socket should become unusable for further network communication. - /// Besides `drop`, any method after such a failure may return an error. - /// - /// # Typical `start` 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, but the socket has `ipv6-only` enabled. (EINVAL, EADDRNOTAVAIL on Illumos) - /// - `invalid-argument`: `remote-address` is a non-IPv4-mapped IPv6 address, but the socket was bound to a specific IPv4-mapped IPv6 address. (or vice versa) - /// - `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 Connection state. (EISCONN) - /// - `invalid-state`: The socket is already in the Listener state. (EOPNOTSUPP, EINVAL on Windows) - /// - /// # Typical `finish` errors - /// - `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) - /// - `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) - /// - /// # References - /// - - /// - - /// - - /// - - start-connect: func(network: borrow, remote-address: ip-socket-address) -> result<_, error-code>; - finish-connect: 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>; - /// Start listening for new connections. - /// - /// Transitions the socket into the Listener state. - /// - /// Unlike POSIX: - /// - this function is async. This enables interactive WASI hosts to inject permission prompts. - /// - the socket must already be explicitly bound. - /// - /// # Typical `start` errors - /// - `invalid-state`: The socket is not bound to any local address. (EDESTADDRREQ) - /// - `invalid-state`: The socket is already in the Connection state. (EISCONN, EINVAL on BSD) - /// - `invalid-state`: The socket is already in the Listener state. - /// - /// # Typical `finish` errors - /// - `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) - /// - /// # References - /// - - /// - - /// - - /// - - start-listen: func() -> result<_, error-code>; - finish-listen: 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; - /// Accept a new client socket. - /// - /// The returned socket is bound and in the Connection state. The following properties are inherited from the listener socket: - /// - `address-family` - /// - `ipv6-only` - /// - `keep-alive` - /// - `no-delay` - /// - `unicast-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 Listener 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 remote address. + /// + /// # Typical errors + /// - `invalid-state`: The socket is not connected to a remote address. (ENOTCONN) + /// + /// # References + /// - + /// - + /// - + /// - + remote-address: func() -> result; - /// 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; + /// Whether the socket is in the `listening` state. + /// + /// Equivalent to the SO_ACCEPTCONN socket option. + is-listening: func() -> bool; - /// Get the remote address. - /// - /// # Typical errors - /// - `invalid-state`: The socket is not connected to a 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; - /// 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>; - /// Whether IPv4 compatibility (dual-stack) mode is disabled or not. - /// - /// Equivalent to the IPV6_V6ONLY socket option. - /// - /// # Typical errors - /// - `invalid-state`: (set) The socket is already bound. - /// - `not-supported`: (get/set) `this` socket is an IPv4 socket. - /// - `not-supported`: (set) Host does not support dual-stack sockets. (Implementations are not required to.) - ipv6-only: func() -> result; - set-ipv6-only: func(value: bool) -> 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>; - /// Hints the desired listen queue size. Implementations are free to ignore this. - /// - /// # Typical errors - /// - `not-supported`: (set) The platform does not support changing the backlog size after the initial listen. - /// - `invalid-state`: (set) The socket is already in the Connection state. - set-listen-backlog-size: func(value: u64) -> 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>; - /// Equivalent to the SO_KEEPALIVE socket option. - keep-alive: func() -> result; - set-keep-alive: func(value: bool) -> 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>; - /// Equivalent to the TCP_NODELAY socket option. - /// - /// The default value is `false`. - no-delay: func() -> result; - set-no-delay: func(value: bool) -> 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. - /// - /// # Typical errors - /// - `invalid-argument`: (set) The TTL value must be 1 or higher. - /// - `invalid-state`: (set) The socket is already in the Connection state. - /// - `invalid-state`: (set) The socket is already in the Listener state. - unicast-hop-limit: func() -> result; - set-unicast-hop-limit: func(value: u8) -> 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. - /// - /// Note #1: an implementation may choose to cap or round the buffer size when setting the value. - /// In other words, after setting a value, reading the same setting back may return a different value. - /// - /// Note #2: there is not necessarily a direct relationship between the kernel buffer size and the bytes of - /// actual data to be sent/received by the application, because the kernel might also use the buffer space - /// for internal metadata structures. - /// - /// Equivalent to the SO_RCVBUF and SO_SNDBUF socket options. - /// - /// # Typical errors - /// - `invalid-state`: (set) The socket is already in the Connection state. - /// - `invalid-state`: (set) The socket is already in the Listener state. - 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>; + /// 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; + /// 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 more data from the peer. All subsequent read - /// operations on the `input-stream` associated with this socket will return an End Of Stream indication. - /// Any data still in the receive queue at time of calling `shutdown` will be discarded. - /// - send: the socket is not expecting to send any more data to the peer. All subsequent write - /// operations on the `output-stream` associated with this socket will return an error. - /// - both: same effect as receive & send combined. - /// - /// The shutdown function does not close (drop) the socket. - /// - /// # Typical errors - /// - `invalid-state`: The socket is not in the Connection state. (ENOTCONN) - /// - /// # References - /// - - /// - - /// - - /// - - shutdown: func(shutdown-type: shutdown-type) -> result<_, error-code>; - } + /// 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/examples/wit/deps/sockets/udp-create-socket.wit b/examples/wit/deps/sockets/udp-create-socket.wit index e026359..0482d1f 100644 --- a/examples/wit/deps/sockets/udp-create-socket.wit +++ b/examples/wit/deps/sockets/udp-create-socket.wit @@ -1,26 +1,27 @@ interface udp-create-socket { - use network.{network, error-code, ip-address-family}; - use udp.{udp-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. - /// - /// 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-udp-socket: func(address-family: ip-address-family) -> result; + /// 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/examples/wit/deps/sockets/udp.wit b/examples/wit/deps/sockets/udp.wit index 91a8c6c..d987a0a 100644 --- a/examples/wit/deps/sockets/udp.wit +++ b/examples/wit/deps/sockets/udp.wit @@ -1,213 +1,266 @@ interface udp { - use wasi:io/poll@0.2.0-rc-2023-10-18.{pollable}; - use network.{network, error-code, ip-socket-address, ip-address-family}; - - - record datagram { - data: list, // Theoretical max size: ~64 KiB. In practice, typically less than 1500 bytes. - remote-address: ip-socket-address, - - /// Possible future additions: - /// local-address: ip-socket-address, // IP_PKTINFO / IP_RECVDSTADDR / IPV6_PKTINFO - /// local-interface: u32, // IP_PKTINFO / IP_RECVIF - /// ttl: u8, // IP_RECVTTL - /// dscp: u6, // IP_RECVTOS - /// ecn: u2, // IP_RECVTOS - } - - - - /// 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 TCP/UDP port is zero, the socket will be bound to a random free port. - /// - /// When a socket is not explicitly bound, the first invocation to connect will implicitly bind the socket. - /// - /// Unlike in POSIX, this function is async. This enables interactive WASI hosts to inject permission prompts. - /// - /// # Typical `start` errors - /// - `invalid-argument`: The `local-address` has the wrong address family. (EAFNOSUPPORT, EFAULT on Windows) - /// - `invalid-state`: The socket is already bound. (EINVAL) - /// - /// # Typical `finish` errors - /// - `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) - /// - /// # References - /// - - /// - - /// - - /// - - start-bind: func(network: borrow, local-address: ip-socket-address) -> result<_, error-code>; - finish-bind: func() -> result<_, error-code>; - - /// Set the destination address. - /// - /// The local-address is updated based on the best network path to `remote-address`. - /// - /// When a destination address is set: - /// - all receive operations will only return datagrams sent from the provided `remote-address`. - /// - the `send` function can only be used to send to this destination. - /// - /// Note that this function does not generate any network traffic and the peer is not aware of this "connection". - /// - /// Unlike in POSIX, this function is async. This enables interactive WASI hosts to inject permission prompts. - /// - /// # Typical `start` errors - /// - `invalid-argument`: The `remote-address` has the wrong address family. (EAFNOSUPPORT) - /// - `invalid-argument`: `remote-address` is a non-IPv4-mapped IPv6 address, but the socket was bound to a specific IPv4-mapped IPv6 address. (or vice versa) - /// - `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 already bound to a different network. The `network` passed to `connect` must be identical to the one passed to `bind`. - /// - /// # Typical `finish` errors - /// - `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) - /// - /// # References - /// - - /// - - /// - - /// - - start-connect: func(network: borrow, remote-address: ip-socket-address) -> result<_, error-code>; - finish-connect: func() -> result<_, error-code>; - - /// 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. - /// If `max-results` is 0, this function returns successfully with an empty list. - /// - /// # Typical errors - /// - `invalid-state`: The socket is not bound to any local address. (EINVAL) - /// - `remote-unreachable`: The remote address is not reachable. (ECONNREFUSED, ECONNRESET, ENETRESET on Windows, EHOSTUNREACH, EHOSTDOWN, ENETUNREACH, ENETDOWN) - /// - `would-block`: There is no pending data available to be read at the moment. (EWOULDBLOCK, EAGAIN) - /// - /// # References - /// - - /// - - /// - - /// - - /// - - /// - - /// - - /// - - receive: func(max-results: u64) -> result, error-code>; - - /// 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 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)`. - /// - /// The remote address option is required. To send a message to the "connected" peer, - /// call `remote-address` to get their address. - /// - /// # Typical errors - /// - `invalid-argument`: The `remote-address` has the wrong address family. (EAFNOSUPPORT) - /// - `invalid-argument`: `remote-address` is a non-IPv4-mapped IPv6 address, but the socket was bound to a specific IPv4-mapped IPv6 address. (or vice versa) - /// - `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 the `datagram.remote-address` does not match the address passed to `connect`. (EISCONN) - /// - `invalid-state`: The socket is not bound to any local address. Unlike POSIX, this function does not perform an implicit bind. - /// - `remote-unreachable`: The remote address is not reachable. (ECONNREFUSED, ECONNRESET, ENETRESET on Windows, EHOSTUNREACH, EHOSTDOWN, ENETUNREACH, ENETDOWN) - /// - `datagram-too-large`: The datagram is too large. (EMSGSIZE) - /// - `would-block`: The send buffer is currently full. (EWOULDBLOCK, EAGAIN) - /// - /// # References - /// - - /// - - /// - - /// - - /// - - /// - - /// - - /// - - send: func(datagrams: list) -> result; - - /// 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 set with `connect`. - /// - /// # Typical errors - /// - `invalid-state`: The socket is not connected to a 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; - - /// Whether IPv4 compatibility (dual-stack) mode is disabled or not. - /// - /// Equivalent to the IPV6_V6ONLY socket option. - /// - /// # Typical errors - /// - `not-supported`: (get/set) `this` socket is an IPv4 socket. - /// - `invalid-state`: (set) The socket is already bound. - /// - `not-supported`: (set) Host does not support dual-stack sockets. (Implementations are not required to.) - ipv6-only: func() -> result; - set-ipv6-only: func(value: bool) -> result<_, error-code>; - - /// Equivalent to the IP_TTL & IPV6_UNICAST_HOPS socket options. - 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. - /// - /// Note #1: an implementation may choose to cap or round the buffer size when setting the value. - /// In other words, after setting a value, reading the same setting back may return a different value. - /// - /// Note #2: there is not necessarily a direct relationship between the kernel buffer size and the bytes of - /// actual data to be sent/received by the application, because the kernel might also use the buffer space - /// for internal metadata structures. - /// - /// Equivalent to the SO_RCVBUF and SO_SNDBUF socket options. - 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; - } + 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/examples/wit/deps/sockets/world.wit b/examples/wit/deps/sockets/world.wit index d16530c..f8bb92a 100644 --- a/examples/wit/deps/sockets/world.wit +++ b/examples/wit/deps/sockets/world.wit @@ -1,4 +1,4 @@ -package wasi:sockets@0.2.0-rc-2023-10-18; +package wasi:sockets@0.2.0; world imports { import instance-network; diff --git a/examples/wit/deps/spin@unversioned/config.wit b/examples/wit/deps/spin@unversioned/config.wit new file mode 100644 index 0000000..ac465fb --- /dev/null +++ b/examples/wit/deps/spin@unversioned/config.wit @@ -0,0 +1,12 @@ +interface config { + // Get a configuration value for the current component. + // The config key must match one defined in in the component manifest. + get-config: func(key: string) -> result; + + variant error { + provider(string), + invalid-key(string), + invalid-schema(string), + other(string), + } +} diff --git a/examples/wit/deps/spin@unversioned/http-types.wit b/examples/wit/deps/spin@unversioned/http-types.wit new file mode 100644 index 0000000..c941cc9 --- /dev/null +++ b/examples/wit/deps/spin@unversioned/http-types.wit @@ -0,0 +1,44 @@ +interface http-types { + type http-status = u16; + + type body = list; + + type headers = list>; + + type params = list>; + + type uri = string; + + enum method { + get, + post, + put, + delete, + patch, + head, + options, + } + + record request { + method: method, + uri: uri, + headers: headers, + params: params, + body: option, + } + + record response { + status: http-status, + headers: option, + body: option, + } + + enum http-error { + success, + destination-not-allowed, + invalid-url, + request-error, + runtime-error, + too-many-requests, + } +} diff --git a/examples/wit/deps/spin@unversioned/http.wit b/examples/wit/deps/spin@unversioned/http.wit new file mode 100644 index 0000000..6ca943c --- /dev/null +++ b/examples/wit/deps/spin@unversioned/http.wit @@ -0,0 +1,5 @@ +interface http { + use http-types.{request, response, http-error}; + + send-request: func(req: request) -> result; +} diff --git a/examples/wit/deps/spin@unversioned/inbound-http.wit b/examples/wit/deps/spin@unversioned/inbound-http.wit new file mode 100644 index 0000000..968c576 --- /dev/null +++ b/examples/wit/deps/spin@unversioned/inbound-http.wit @@ -0,0 +1,5 @@ +interface inbound-http { + use http-types.{request, response}; + + handle-request: func(req: request) -> response; +} diff --git a/examples/wit/deps/spin@unversioned/inbound-redis.wit b/examples/wit/deps/spin@unversioned/inbound-redis.wit new file mode 100644 index 0000000..a991e5d --- /dev/null +++ b/examples/wit/deps/spin@unversioned/inbound-redis.wit @@ -0,0 +1,6 @@ +interface inbound-redis { + use redis-types.{payload, error}; + + // The entrypoint for a Redis handler. + handle-message: func(message: payload) -> result<_, error>; +} diff --git a/examples/wit/deps/spin@unversioned/key-value.wit b/examples/wit/deps/spin@unversioned/key-value.wit new file mode 100644 index 0000000..314a758 --- /dev/null +++ b/examples/wit/deps/spin@unversioned/key-value.wit @@ -0,0 +1,80 @@ +interface key-value { + // A handle to an open key-value store + type store = u32; + + // The set of errors which may be raised by functions in this interface + variant error { + // Too many stores have been opened simultaneously. Closing one or more + // stores prior to retrying may address this. + store-table-full, + + // The host does not recognize the store name requested. Defining and + // configuring a store with that name in a runtime configuration file + // may address this. + no-such-store, + + // The requesting component does not have access to the specified store + // (which may or may not exist). + access-denied, + + // The store handle provided is not recognized, i.e. it was either never + // opened or has been closed. + invalid-store, + + // No key-value tuple exists for the specified key in the specified + // store. + no-such-key, + + // Some implementation-specific error has occurred (e.g. I/O) + io(string) + } + + // Open the store with the specified name. + // + // If `name` is "default", the default store is opened. Otherwise, + // `name` must refer to a store defined and configured in a runtime + // configuration file supplied with the application. + // + // `error::no-such-store` will be raised if the `name` is not recognized. + open: func(name: string) -> result; + + // Get the value associated with the specified `key` from the specified + // `store`. + // + // `error::invalid-store` will be raised if `store` is not a valid handle + // to an open store, and `error::no-such-key` will be raised if there is no + // tuple for `key` in `store`. + get: func(store: store, key: string) -> result, error>; + + // Set the `value` associated with the specified `key` in the specified + // `store`, overwriting any existing value. + // + // `error::invalid-store` will be raised if `store` is not a valid handle + // to an open store. + set: func(store: store, key: string, value: list) -> result<_, error>; + + // Delete the tuple with the specified `key` from the specified `store`. + // + // `error::invalid-store` will be raised if `store` is not a valid handle + // to an open store. No error is raised if a tuple did not previously + // exist for `key`. + delete: func(store: store, key: string) -> result<_, error>; + + // Return whether a tuple exists for the specified `key` in the specified + // `store`. + // + // `error::invalid-store` will be raised if `store` is not a valid handle + // to an open store. + exists: func(store: store, key: string) -> result; + + // Return a list of all the keys in the specified `store`. + // + // `error::invalid-store` will be raised if `store` is not a valid handle + // to an open store. + get-keys: func(store: store) -> result, error>; + + // Close the specified `store`. + // + // This has no effect if `store` is not a valid handle to an open store. + close: func(store: store); +} diff --git a/examples/wit/deps/spin@unversioned/llm.wit b/examples/wit/deps/spin@unversioned/llm.wit new file mode 100644 index 0000000..ffed09c --- /dev/null +++ b/examples/wit/deps/spin@unversioned/llm.wit @@ -0,0 +1,70 @@ +// A WASI interface dedicated to performing inferencing for Large Language Models. +interface llm { + /// A Large Language Model. + type inferencing-model = string; + + /// Inference request parameters + record inferencing-params { + /// The maximum tokens that should be inferred. + /// + /// Note: the backing implementation may return less tokens. + max-tokens: u32, + /// The amount the model should avoid repeating tokens. + repeat-penalty: float32, + /// The number of tokens the model should apply the repeat penalty to. + repeat-penalty-last-n-token-count: u32, + /// The randomness with which the next token is selected. + temperature: float32, + /// The number of possible next tokens the model will choose from. + top-k: u32, + /// The probability total of next tokens the model will choose from. + top-p: float32 + } + + /// The set of errors which may be raised by functions in this interface + variant error { + model-not-supported, + runtime-error(string), + invalid-input(string) + } + + /// An inferencing result + record inferencing-result { + /// The text generated by the model + // TODO: this should be a stream + text: string, + /// Usage information about the inferencing request + usage: inferencing-usage + } + + /// Usage information related to the inferencing result + record inferencing-usage { + /// Number of tokens in the prompt + prompt-token-count: u32, + /// Number of tokens generated by the inferencing operation + generated-token-count: u32 + } + + /// Perform inferencing using the provided model and prompt with the given optional params + infer: func(model: inferencing-model, prompt: string, params: option) -> result; + + /// The model used for generating embeddings + type embedding-model = string; + + /// Generate embeddings for the supplied list of text + generate-embeddings: func(model: embedding-model, text: list) -> result; + + /// Result of generating embeddings + record embeddings-result { + /// The embeddings generated by the request + embeddings: list>, + /// Usage related to the embeddings generation request + usage: embeddings-usage + } + + /// Usage related to an embeddings generation request + record embeddings-usage { + /// Number of tokens in the prompt + prompt-token-count: u32, + } +} diff --git a/examples/wit/deps/spin@unversioned/mysql.wit b/examples/wit/deps/spin@unversioned/mysql.wit new file mode 100644 index 0000000..dd1b9c3 --- /dev/null +++ b/examples/wit/deps/spin@unversioned/mysql.wit @@ -0,0 +1,19 @@ +interface mysql { + use rdbms-types.{parameter-value, row-set}; + + // General purpose error. + variant mysql-error { + success, + connection-failed(string), + bad-parameter(string), + query-failed(string), + value-conversion-failed(string), + other-error(string) + } + + // query the database: select + query: func(address: string, statement: string, params: list) -> result; + + // execute command to the database: insert, update, delete + execute: func(address: string, statement: string, params: list) -> result<_, mysql-error>; +} diff --git a/examples/wit/deps/spin@unversioned/postgres.wit b/examples/wit/deps/spin@unversioned/postgres.wit new file mode 100644 index 0000000..e82ef42 --- /dev/null +++ b/examples/wit/deps/spin@unversioned/postgres.wit @@ -0,0 +1,19 @@ +interface postgres { + use rdbms-types.{parameter-value, row-set}; + + // General purpose error. + variant pg-error { + success, + connection-failed(string), + bad-parameter(string), + query-failed(string), + value-conversion-failed(string), + other-error(string) + } + + // query the database: select + query: func(address: string, statement: string, params: list) -> result; + + // execute command to the database: insert, update, delete + execute: func(address: string, statement: string, params: list) -> result; +} diff --git a/examples/wit/deps/spin@unversioned/rdbms-types.wit b/examples/wit/deps/spin@unversioned/rdbms-types.wit new file mode 100644 index 0000000..7af0420 --- /dev/null +++ b/examples/wit/deps/spin@unversioned/rdbms-types.wit @@ -0,0 +1,65 @@ +interface rdbms-types { + enum db-data-type { + boolean, + int8, + int16, + int32, + int64, + uint8, + uint16, + uint32, + uint64, + floating32, + floating64, + str, + binary, + other, + } + + variant db-value { + boolean(bool), + int8(s8), + int16(s16), + int32(s32), + int64(s64), + uint8(u8), + uint16(u16), + uint32(u32), + uint64(u64), + floating32(float32), + floating64(float64), + str(string), + binary(list), + db-null, + unsupported, + } + + variant parameter-value { + boolean(bool), + int8(s8), + int16(s16), + int32(s32), + int64(s64), + uint8(u8), + uint16(u16), + uint32(u32), + uint64(u64), + floating32(float32), + floating64(float64), + str(string), + binary(list), + db-null, + } + + record column { + name: string, + data-type: db-data-type, + } + + type row = list; + + record row-set { + columns: list, + rows: list, + } +} diff --git a/examples/wit/deps/spin@unversioned/redis-types.wit b/examples/wit/deps/spin@unversioned/redis-types.wit new file mode 100644 index 0000000..6970f63 --- /dev/null +++ b/examples/wit/deps/spin@unversioned/redis-types.wit @@ -0,0 +1,24 @@ +interface redis-types { + // General purpose error. + enum error { + success, + error, + } + + /// The message payload. + type payload = list; + + /// A parameter type for the general-purpose `execute` function. + variant redis-parameter { + int64(s64), + binary(payload) + } + + /// A return type for the general-purpose `execute` function. + variant redis-result { + nil, + status(string), + int64(s64), + binary(payload) + } +} diff --git a/examples/wit/deps/spin@unversioned/redis.wit b/examples/wit/deps/spin@unversioned/redis.wit new file mode 100644 index 0000000..1b64906 --- /dev/null +++ b/examples/wit/deps/spin@unversioned/redis.wit @@ -0,0 +1,31 @@ +interface redis { + use redis-types.{payload, redis-parameter, redis-result, error}; + + // Publish a Redis message to the specificed channel and return an error, if any. + publish: func(address: string, channel: string, payload: payload) -> result<_, error>; + + // Get the value of a key. + get: func(address: string, key: string) -> result; + + // Set key to value. If key alreads holds a value, it is overwritten. + set: func(address: string, key: string, value: payload) -> result<_, error>; + + // Increments the number stored at key by one. If the key does not exist, it is set to 0 before performing the operation. + // An error is returned if the key contains a value of the wrong type or contains a string that can not be represented as integer. + incr: func(address: string, key: string) -> result; + + // Removes the specified keys. A key is ignored if it does not exist. + del: func(address: string, keys: list) -> result; + + // Add the specified `values` to the set named `key`, returning the number of newly-added values. + sadd: func(address: string, key: string, values: list) -> result; + + // Retrieve the contents of the set named `key`. + smembers: func(address: string, key: string) -> result, error>; + + // Remove the specified `values` from the set named `key`, returning the number of newly-removed values. + srem: func(address: string, key: string, values: list) -> result; + + // Execute an arbitrary Redis command and receive the result. + execute: func(address: string, command: string, arguments: list) -> result, error>; +} diff --git a/examples/wit/deps/spin@unversioned/sqlite.wit b/examples/wit/deps/spin@unversioned/sqlite.wit new file mode 100644 index 0000000..7e2908f --- /dev/null +++ b/examples/wit/deps/spin@unversioned/sqlite.wit @@ -0,0 +1,52 @@ +interface sqlite { + // A handle to an open sqlite instance + type connection = u32; + + // The set of errors which may be raised by functions in this interface + variant error { + // The host does not recognize the database name requested. + no-such-database, + // The requesting component does not have access to the specified database (which may or may not exist). + access-denied, + // The provided connection is not valid + invalid-connection, + // The database has reached its capacity + database-full, + // Some implementation-specific error has occurred (e.g. I/O) + io(string) + } + + // Open a connection to a named database instance. + // + // If `database` is "default", the default instance is opened. + // + // `error::no-such-database` will be raised if the `name` is not recognized. + open: func(database: string) -> result; + + // Execute a statement returning back data if there is any + execute: func(conn: connection, statement: string, parameters: list) -> result; + + // Close the specified `connection`. + close: func(conn: connection); + + // A result of a query + record query-result { + // The names of the columns retrieved in the query + columns: list, + // the row results each containing the values for all the columns for a given row + rows: list, + } + + // A set of values for each of the columns in a query-result + record row-result { + values: list + } + + variant value { + integer(s64), + real(float64), + text(string), + blob(list), + null + } +} diff --git a/examples/wit/deps/spin@unversioned/world.wit b/examples/wit/deps/spin@unversioned/world.wit new file mode 100644 index 0000000..603a760 --- /dev/null +++ b/examples/wit/deps/spin@unversioned/world.wit @@ -0,0 +1,29 @@ +package fermyon:spin; + +world host { + include platform; + + export inbound-http; + export inbound-redis; +} + +world redis-trigger { + include platform; + export inbound-redis; +} + +world http-trigger { + include platform; + export inbound-http; +} + +world platform { + import config; + import http; + import postgres; + import mysql; + import sqlite; + import redis; + import key-value; + import llm; +} diff --git a/examples/wit/main.wit b/examples/wit/main.wit index f3a4e60..eb9ac37 100644 --- a/examples/wit/main.wit +++ b/examples/wit/main.wit @@ -3,31 +3,30 @@ package wasmtime:wasi; // All of the same imports available in the wasi:cli/command world, but no // export required: world preview1-adapter-reactor { - import wasi:clocks/wall-clock@0.2.0-rc-2023-10-18; - import wasi:clocks/monotonic-clock@0.2.0-rc-2023-10-18; - import wasi:clocks/timezone@0.2.0-rc-2023-10-18; - import wasi:filesystem/types@0.2.0-rc-2023-10-18; - import wasi:filesystem/preopens@0.2.0-rc-2023-10-18; - import wasi:sockets/instance-network@0.2.0-rc-2023-10-18; - import wasi:sockets/ip-name-lookup@0.2.0-rc-2023-10-18; - import wasi:sockets/network@0.2.0-rc-2023-10-18; - import wasi:sockets/tcp-create-socket@0.2.0-rc-2023-10-18; - import wasi:sockets/tcp@0.2.0-rc-2023-10-18; - import wasi:sockets/udp-create-socket@0.2.0-rc-2023-10-18; - import wasi:sockets/udp@0.2.0-rc-2023-10-18; - import wasi:random/random@0.2.0-rc-2023-10-18; - import wasi:random/insecure@0.2.0-rc-2023-10-18; - import wasi:random/insecure-seed@0.2.0-rc-2023-10-18; - import wasi:io/poll@0.2.0-rc-2023-10-18; - import wasi:io/streams@0.2.0-rc-2023-10-18; - import wasi:cli/environment@0.2.0-rc-2023-10-18; - import wasi:cli/exit@0.2.0-rc-2023-10-18; - import wasi:cli/stdin@0.2.0-rc-2023-10-18; - import wasi:cli/stdout@0.2.0-rc-2023-10-18; - import wasi:cli/stderr@0.2.0-rc-2023-10-18; - import wasi:cli/terminal-input@0.2.0-rc-2023-10-18; - import wasi:cli/terminal-output@0.2.0-rc-2023-10-18; - import wasi:cli/terminal-stdin@0.2.0-rc-2023-10-18; - import wasi:cli/terminal-stdout@0.2.0-rc-2023-10-18; - import wasi:cli/terminal-stderr@0.2.0-rc-2023-10-18; + import wasi:clocks/wall-clock@0.2.0; + import wasi:clocks/monotonic-clock@0.2.0; + import wasi:filesystem/types@0.2.0; + import wasi:filesystem/preopens@0.2.0; + import wasi:sockets/instance-network@0.2.0; + import wasi:sockets/ip-name-lookup@0.2.0; + import wasi:sockets/network@0.2.0; + import wasi:sockets/tcp-create-socket@0.2.0; + import wasi:sockets/tcp@0.2.0; + import wasi:sockets/udp-create-socket@0.2.0; + import wasi:sockets/udp@0.2.0; + import wasi:random/random@0.2.0; + import wasi:random/insecure@0.2.0; + import wasi:random/insecure-seed@0.2.0; + import wasi:io/poll@0.2.0; + import wasi:io/streams@0.2.0; + import wasi:cli/environment@0.2.0; + import wasi:cli/exit@0.2.0; + import wasi:cli/stdin@0.2.0; + import wasi:cli/stdout@0.2.0; + import wasi:cli/stderr@0.2.0; + import wasi:cli/terminal-input@0.2.0; + import wasi:cli/terminal-output@0.2.0; + import wasi:cli/terminal-stdin@0.2.0; + import wasi:cli/terminal-stdout@0.2.0; + import wasi:cli/terminal-stderr@0.2.0; } diff --git a/examples/wit/proxy.wit b/examples/wit/proxy.wit index 5993828..1628ccd 100644 --- a/examples/wit/proxy.wit +++ b/examples/wit/proxy.wit @@ -1,5 +1,5 @@ world proxy { - include wasi:http/proxy@0.2.0-rc-2023-10-18; + include wasi:http/proxy@0.2.0; - import wasi:http/incoming-handler@0.2.0-rc-2023-10-18; + import wasi:http/incoming-handler@0.2.0; } diff --git a/examples/wit/test.wit b/examples/wit/test.wit index 3db5e08..6bc2a18 100644 --- a/examples/wit/test.wit +++ b/examples/wit/test.wit @@ -1,46 +1,46 @@ // only used as part of `test-programs` world test-reactor { - import wasi:cli/environment@0.2.0-rc-2023-10-18; - import wasi:io/poll@0.2.0-rc-2023-10-18; - import wasi:io/streams@0.2.0-rc-2023-10-18; - import wasi:filesystem/types@0.2.0-rc-2023-10-18; - import wasi:filesystem/preopens@0.2.0-rc-2023-10-18; - import wasi:cli/exit@0.2.0-rc-2023-10-18; + import wasi:cli/environment@0.2.0; + import wasi:io/poll@0.2.0; + import wasi:io/streams@0.2.0; + import wasi:filesystem/types@0.2.0; + import wasi:filesystem/preopens@0.2.0; + import wasi:cli/exit@0.2.0; export add-strings: func(s: list) -> u32; export get-strings: func() -> list; - use wasi:io/streams@0.2.0-rc-2023-10-18.{output-stream}; + use wasi:io/streams@0.2.0.{output-stream}; export write-strings-to: func(o: output-stream) -> result; - use wasi:filesystem/types@0.2.0-rc-2023-10-18.{descriptor-stat}; + use wasi:filesystem/types@0.2.0.{descriptor-stat}; export pass-an-imported-record: func(d: descriptor-stat) -> string; } world test-command { - import wasi:io/poll@0.2.0-rc-2023-10-18; - import wasi:io/streams@0.2.0-rc-2023-10-18; - import wasi:cli/environment@0.2.0-rc-2023-10-18; - import wasi:cli/stdin@0.2.0-rc-2023-10-18; - import wasi:cli/stdout@0.2.0-rc-2023-10-18; - import wasi:cli/stderr@0.2.0-rc-2023-10-18; + import wasi:io/poll@0.2.0; + import wasi:io/streams@0.2.0; + import wasi:cli/environment@0.2.0; + import wasi:cli/stdin@0.2.0; + import wasi:cli/stdout@0.2.0; + import wasi:cli/stderr@0.2.0; } world test-command-with-sockets { - import wasi:io/poll@0.2.0-rc-2023-10-18; - import wasi:io/streams@0.2.0-rc-2023-10-18; - import wasi:cli/environment@0.2.0-rc-2023-10-18; - import wasi:cli/stdin@0.2.0-rc-2023-10-18; - import wasi:cli/stdout@0.2.0-rc-2023-10-18; - import wasi:cli/stderr@0.2.0-rc-2023-10-18; - import wasi:sockets/tcp@0.2.0-rc-2023-10-18; - import wasi:sockets/tcp-create-socket@0.2.0-rc-2023-10-18; - import wasi:sockets/udp@0.2.0-rc-2023-10-18; - import wasi:sockets/udp-create-socket@0.2.0-rc-2023-10-18; - import wasi:sockets/network@0.2.0-rc-2023-10-18; - import wasi:sockets/instance-network@0.2.0-rc-2023-10-18; - import wasi:sockets/ip-name-lookup@0.2.0-rc-2023-10-18; - import wasi:clocks/monotonic-clock@0.2.0-rc-2023-10-18; + import wasi:io/poll@0.2.0; + import wasi:io/streams@0.2.0; + import wasi:cli/environment@0.2.0; + import wasi:cli/stdin@0.2.0; + import wasi:cli/stdout@0.2.0; + import wasi:cli/stderr@0.2.0; + import wasi:sockets/tcp@0.2.0; + import wasi:sockets/tcp-create-socket@0.2.0; + import wasi:sockets/udp@0.2.0; + import wasi:sockets/udp-create-socket@0.2.0; + import wasi:sockets/network@0.2.0; + import wasi:sockets/instance-network@0.2.0; + import wasi:sockets/ip-name-lookup@0.2.0; + import wasi:clocks/monotonic-clock@0.2.0; } diff --git a/src/bindings.rs b/src/bindings.rs new file mode 100644 index 0000000..0da7e33 --- /dev/null +++ b/src/bindings.rs @@ -0,0 +1,18 @@ +// Generated by `wit-bindgen` 0.25.0. DO NOT EDIT! +// Options used: + +#[cfg(target_arch = "wasm32")] +#[link_section = "component-type:wit-bindgen:0.25.0:spin-static-fs:encoded world"] +#[doc(hidden)] +pub static __WIT_BINDGEN_COMPONENT_TYPE: [u8; 182] = *b"\ +\0asm\x0d\0\x01\0\0\x19\x16wit-component-encoding\x04\0\x072\x01A\x02\x01A\0\x04\ +\x01'component:spin-static-fs/spin-static-fs\x04\0\x0b\x14\x01\0\x0espin-static-\ +fs\x03\0\0\0G\x09producers\x01\x0cprocessed-by\x02\x0dwit-component\x070.208.1\x10\ +wit-bindgen-rust\x060.25.0"; + +#[inline(never)] +#[doc(hidden)] +#[cfg(target_arch = "wasm32")] +pub fn __link_custom_section_describing_imports() { + wit_bindgen_rt::maybe_link_cabi_realloc(); +} From 53e4769192c1de0335a938d5b10b8a67f2750e5f Mon Sep 17 00:00:00 2001 From: Ryan Levick Date: Tue, 3 Sep 2024 12:41:32 +0200 Subject: [PATCH 2/6] Somewhat fix the JS examples Signed-off-by: Ryan Levick --- examples/javascript/.gitignore | 1 + examples/javascript/README.md | 16 +- examples/javascript/app.mjs | 18 +- examples/javascript/build.mjs | 1 - examples/javascript/compose.yml | 7 - examples/javascript/package-lock.json | 542 ++++++++++++++++++++++++++ examples/javascript/package.json | 5 + examples/javascript/spin.toml | 2 +- 8 files changed, 561 insertions(+), 31 deletions(-) create mode 100644 examples/javascript/.gitignore delete mode 100644 examples/javascript/compose.yml create mode 100644 examples/javascript/package-lock.json create mode 100644 examples/javascript/package.json diff --git a/examples/javascript/.gitignore b/examples/javascript/.gitignore new file mode 100644 index 0000000..40b878d --- /dev/null +++ b/examples/javascript/.gitignore @@ -0,0 +1 @@ +node_modules/ \ No newline at end of file diff --git a/examples/javascript/README.md b/examples/javascript/README.md index 37a120d..eb1864a 100644 --- a/examples/javascript/README.md +++ b/examples/javascript/README.md @@ -11,28 +11,18 @@ component for serving static files. - [Spin v2.0+](https://developer.fermyon.com/spin/install) - [Rust](https://rustup.rs/) - [cargo-component](https://github.com/bytecodealliance/cargo-component) -- [wasm-tools](https://github.com/bytecodealliance/wasm-tools/) - - Note that you'll need [this fork](https://github.com/dicej/wasm-tools/tree/wasm-compose-resource-imports) until [this PR](https://github.com/bytecodealliance/wasm-tools/pull/1261) has been merged and released. +- [wac](https://github.com/bytecodealliance/wac) - [NodeJS](https://nodejs.org/en/download) - [componentize-js](https://github.com/dicej/componentize-js) - [curl](https://curl.se/download.html) or a web browser for testing Once you have Rust and NodeJS installed, the following should give you everything else: -*NOTE*: Until https://github.com/bytecodealliance/componentize-js/pull/69 has -been merged, you'll need to build and install `componentize-js` from source -using -https://github.com/dicej/componentize-js/tree/imported-resource-destructors -instead of the `npm install` command below. See the README.md in that -repository for instructions. - ```shell rustup target add wasm32-wasi cargo install cargo-component -cargo install --locked --git https://github.com/dicej/wasm-tools \ - --branch wasm-compose-resource-imports wasm-tools -# See NOTE above for installing `componentize-js` -# npm install @bytecodealliance/componentize-js +cargo install wac-cli +npm install -g @bytecodealliance/jco @bytecodealliance/componentize-js ``` ## Building and Running diff --git a/examples/javascript/app.mjs b/examples/javascript/app.mjs index 6e8553f..9ccb402 100644 --- a/examples/javascript/app.mjs +++ b/examples/javascript/app.mjs @@ -1,5 +1,5 @@ -import { handle as spinFileserverHandle } from "wasi:http/incoming-handler@0.2.0-rc-2023-10-18" -import { OutgoingResponse, ResponseOutparam, OutgoingBody, Fields } from "wasi:http/types@0.2.0-rc-2023-10-18" +import { handle as spinFileserverHandle } from "wasi:http/incoming-handler@0.2.0" +import { OutgoingResponse, ResponseOutparam, OutgoingBody, Fields } from "wasi:http/types@0.2.0" const encoder = new TextEncoder() const disposeSymbol = Symbol.dispose || Symbol.for('dispose') @@ -10,14 +10,13 @@ function handle(request, responseOut) { if (method.tag === "get") { if (path === "/hello") { - const response = new OutgoingResponse( - 200, - new Fields([["content-type", encoder.encode("text/plain")]]) - ) - + const fields = new Fields() + fields.append("content-type", encoder.encode("text/plain")) + const response = new OutgoingResponse(fields) + const responseBody = response.write() ResponseOutparam.set(responseOut, { tag: "ok", val: response }) - + const responseStream = responseBody.write() responseStream.blockingWriteAndFlush(encoder.encode("Hello, world!")) responseStream[disposeSymbol]() @@ -26,7 +25,8 @@ function handle(request, responseOut) { spinFileserverHandle(request, responseOut) } } else { - const response = new OutgoingResponse(400, new Fields([])) + const response = new OutgoingResponse(new Fields([])) + response.setSatusCode(400) ResponseOutparam.set(responseOut, { tag: "ok", val: response }) OutgoingBody.finish(response.write()) } diff --git a/examples/javascript/build.mjs b/examples/javascript/build.mjs index ab0b255..0250c49 100644 --- a/examples/javascript/build.mjs +++ b/examples/javascript/build.mjs @@ -6,7 +6,6 @@ const { component } = await componentize( { witPath: "../wit", worldName: "proxy", - preview2Adapter: "../../adapters/fd1e948d/wasi_snapshot_preview1.reactor.wasm", enableStdout: true, } ); diff --git a/examples/javascript/compose.yml b/examples/javascript/compose.yml deleted file mode 100644 index ac83a85..0000000 --- a/examples/javascript/compose.yml +++ /dev/null @@ -1,7 +0,0 @@ -search-paths: - - ../../target/wasm32-wasi/release - -instantiations: - $input: - arguments: - wasi:http/incoming-handler@0.2.0-rc-2023-10-18: spin_static_fs diff --git a/examples/javascript/package-lock.json b/examples/javascript/package-lock.json new file mode 100644 index 0000000..fa282e8 --- /dev/null +++ b/examples/javascript/package-lock.json @@ -0,0 +1,542 @@ +{ + "name": "javascript", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "dependencies": { + "@bytecodealliance/componentize-js": "^0.11.4" + } + }, + "node_modules/@bytecodealliance/componentize-js": { + "version": "0.11.4", + "resolved": "https://registry.npmjs.org/@bytecodealliance/componentize-js/-/componentize-js-0.11.4.tgz", + "integrity": "sha512-infeu0iVWdUu/cJncWnAahq/jdIVypPUe6K9T6e0xVUGmPm0sVpij86AF0VjgD3y8UBHcE6Hv4e54AuRXe6rTw==", + "dependencies": { + "@bytecodealliance/jco": "1.4.4", + "@bytecodealliance/wizer": "^7.0.4", + "es-module-lexer": "^1.5.4" + } + }, + "node_modules/@bytecodealliance/jco": { + "version": "1.4.4", + "resolved": "https://registry.npmjs.org/@bytecodealliance/jco/-/jco-1.4.4.tgz", + "integrity": "sha512-Gu9VzU99rptKnRgx1KSMUIy56BoVWy6uKCoKZwLL+nvEM9kSLtvEp2CLSSnpOxXaFIpTLhmNhSu7j8h965C8zw==", + "dependencies": { + "@bytecodealliance/preview2-shim": "^0.16.5", + "binaryen": "^118.0.0", + "chalk-template": "^1", + "commander": "^12", + "mkdirp": "^3", + "ora": "^8", + "terser": "^5" + }, + "bin": { + "jco": "src/jco.js" + } + }, + "node_modules/@bytecodealliance/preview2-shim": { + "version": "0.16.5", + "resolved": "https://registry.npmjs.org/@bytecodealliance/preview2-shim/-/preview2-shim-0.16.5.tgz", + "integrity": "sha512-1YThPyZ/gWZBgmJ3nEsnBXLxgSV3VOW3vLfyxe/RTKk9fWkTKaUouuZHWBvP0aFN7Hnat733rUeSYAUjEUNONQ==" + }, + "node_modules/@bytecodealliance/wizer": { + "version": "7.0.4", + "resolved": "https://registry.npmjs.org/@bytecodealliance/wizer/-/wizer-7.0.4.tgz", + "integrity": "sha512-DaEoFCNxS4srJa9hqVkC2twvQqvvMWv4R+mEmTRtOB0Rt4d1hDcKJmjy/lIcrJHmzJu/dSZtTNaRpBwoCD/yLg==", + "bin": { + "wizer": "wizer.js" + }, + "engines": { + "node": ">=16" + }, + "optionalDependencies": { + "@bytecodealliance/wizer-darwin-arm64": "7.0.4", + "@bytecodealliance/wizer-darwin-x64": "7.0.4", + "@bytecodealliance/wizer-linux-arm64": "7.0.4", + "@bytecodealliance/wizer-linux-s390x": "7.0.4", + "@bytecodealliance/wizer-linux-x64": "7.0.4", + "@bytecodealliance/wizer-win32-x64": "7.0.4" + } + }, + "node_modules/@bytecodealliance/wizer-darwin-arm64": { + "version": "7.0.4", + "resolved": "https://registry.npmjs.org/@bytecodealliance/wizer-darwin-arm64/-/wizer-darwin-arm64-7.0.4.tgz", + "integrity": "sha512-9HO2k49riA+35i/av6pR3APdkCr6MSLZedmw4/106NPg6HTASoCx6pInNibUvVPah3ALMZAl4adjKUAOFdYuLw==", + "cpu": [ + "arm64" + ], + "optional": true, + "os": [ + "darwin" + ], + "bin": { + "wizer-darwin-arm64": "wizer" + } + }, + "node_modules/@bytecodealliance/wizer-darwin-x64": { + "version": "7.0.4", + "resolved": "https://registry.npmjs.org/@bytecodealliance/wizer-darwin-x64/-/wizer-darwin-x64-7.0.4.tgz", + "integrity": "sha512-/9QNAQ8/DCWpdb+S/gGMXdq/nw3Q/XUMvvn85T4N55lMj59XLgGE220cqWDueW1iiAFH/cNtJKjsy/Y3BSlP7g==", + "cpu": [ + "x64" + ], + "optional": true, + "os": [ + "darwin" + ], + "bin": { + "wizer-darwin-x64": "wizer" + } + }, + "node_modules/@bytecodealliance/wizer-linux-arm64": { + "version": "7.0.4", + "resolved": "https://registry.npmjs.org/@bytecodealliance/wizer-linux-arm64/-/wizer-linux-arm64-7.0.4.tgz", + "integrity": "sha512-EAIyuHR2EO/z2ecAMdBvtL3+fopOO2LZ9rTDaRX1MMJUv8D7lXYTSOksOiOnrMwsguRDIVbC1Z/ot5gw5LwoTw==", + "cpu": [ + "arm64" + ], + "optional": true, + "os": [ + "linux" + ], + "bin": { + "wizer-linux-arm64": "wizer" + } + }, + "node_modules/@bytecodealliance/wizer-linux-s390x": { + "version": "7.0.4", + "resolved": "https://registry.npmjs.org/@bytecodealliance/wizer-linux-s390x/-/wizer-linux-s390x-7.0.4.tgz", + "integrity": "sha512-otkIzM8H3ouub4ug1Y3ZhzywSiaHLiJzTLFm8tdK0l2397ygPmFKQycQxAM36+qFx58R8zDA63GZXOORbrYWeA==", + "cpu": [ + "s390x" + ], + "optional": true, + "os": [ + "linux" + ], + "bin": { + "wizer-linux-s390x": "wizer" + } + }, + "node_modules/@bytecodealliance/wizer-linux-x64": { + "version": "7.0.4", + "resolved": "https://registry.npmjs.org/@bytecodealliance/wizer-linux-x64/-/wizer-linux-x64-7.0.4.tgz", + "integrity": "sha512-SEBfjvl5S4eYEZOdyPs13TYX7873Ir1ZFS4mAM9b8dbAmx8p3hOITg2jBstCrIu7qSu3TrhOfv96tEMZDGoSKA==", + "cpu": [ + "x64" + ], + "optional": true, + "os": [ + "linux" + ], + "bin": { + "wizer-linux-x64": "wizer" + } + }, + "node_modules/@bytecodealliance/wizer-win32-x64": { + "version": "7.0.4", + "resolved": "https://registry.npmjs.org/@bytecodealliance/wizer-win32-x64/-/wizer-win32-x64-7.0.4.tgz", + "integrity": "sha512-Jp+/iOcvUuewGJr8aLozb1xVcIOCyv3/AL54Ir+mziWec6IA5hXwa6NZ5MY4GiQXcOryKfatzllP1JbqtYD4yw==", + "cpu": [ + "x64" + ], + "optional": true, + "os": [ + "win32" + ], + "bin": { + "wizer-win32-x64": "wizer" + } + }, + "node_modules/@jridgewell/gen-mapping": { + "version": "0.3.5", + "resolved": "https://registry.npmjs.org/@jridgewell/gen-mapping/-/gen-mapping-0.3.5.tgz", + "integrity": "sha512-IzL8ZoEDIBRWEzlCcRhOaCupYyN5gdIK+Q6fbFdPDg6HqX6jpkItn7DFIpW9LQzXG6Df9sA7+OKnq0qlz/GaQg==", + "dependencies": { + "@jridgewell/set-array": "^1.2.1", + "@jridgewell/sourcemap-codec": "^1.4.10", + "@jridgewell/trace-mapping": "^0.3.24" + }, + "engines": { + "node": ">=6.0.0" + } + }, + "node_modules/@jridgewell/resolve-uri": { + "version": "3.1.2", + "resolved": "https://registry.npmjs.org/@jridgewell/resolve-uri/-/resolve-uri-3.1.2.tgz", + "integrity": "sha512-bRISgCIjP20/tbWSPWMEi54QVPRZExkuD9lJL+UIxUKtwVJA8wW1Trb1jMs1RFXo1CBTNZ/5hpC9QvmKWdopKw==", + "engines": { + "node": ">=6.0.0" + } + }, + "node_modules/@jridgewell/set-array": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/@jridgewell/set-array/-/set-array-1.2.1.tgz", + "integrity": "sha512-R8gLRTZeyp03ymzP/6Lil/28tGeGEzhx1q2k703KGWRAI1VdvPIXdG70VJc2pAMw3NA6JKL5hhFu1sJX0Mnn/A==", + "engines": { + "node": ">=6.0.0" + } + }, + "node_modules/@jridgewell/source-map": { + "version": "0.3.6", + "resolved": "https://registry.npmjs.org/@jridgewell/source-map/-/source-map-0.3.6.tgz", + "integrity": "sha512-1ZJTZebgqllO79ue2bm3rIGud/bOe0pP5BjSRCRxxYkEZS8STV7zN84UBbiYu7jy+eCKSnVIUgoWWE/tt+shMQ==", + "dependencies": { + "@jridgewell/gen-mapping": "^0.3.5", + "@jridgewell/trace-mapping": "^0.3.25" + } + }, + "node_modules/@jridgewell/sourcemap-codec": { + "version": "1.5.0", + "resolved": "https://registry.npmjs.org/@jridgewell/sourcemap-codec/-/sourcemap-codec-1.5.0.tgz", + "integrity": "sha512-gv3ZRaISU3fjPAgNsriBRqGWQL6quFx04YMPW/zD8XMLsU32mhCCbfbO6KZFLjvYpCZ8zyDEgqsgf+PwPaM7GQ==" + }, + "node_modules/@jridgewell/trace-mapping": { + "version": "0.3.25", + "resolved": "https://registry.npmjs.org/@jridgewell/trace-mapping/-/trace-mapping-0.3.25.tgz", + "integrity": "sha512-vNk6aEwybGtawWmy/PzwnGDOjCkLWSD2wqvjGGAgOAwCGWySYXfYoxt00IJkTF+8Lb57DwOb3Aa0o9CApepiYQ==", + "dependencies": { + "@jridgewell/resolve-uri": "^3.1.0", + "@jridgewell/sourcemap-codec": "^1.4.14" + } + }, + "node_modules/acorn": { + "version": "8.12.1", + "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.12.1.tgz", + "integrity": "sha512-tcpGyI9zbizT9JbV6oYE477V6mTlXvvi0T0G3SNIYE2apm/G5huBa1+K89VGeovbg+jycCrfhl3ADxErOuO6Jg==", + "bin": { + "acorn": "bin/acorn" + }, + "engines": { + "node": ">=0.4.0" + } + }, + "node_modules/ansi-regex": { + "version": "6.0.1", + "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-6.0.1.tgz", + "integrity": "sha512-n5M855fKb2SsfMIiFFoVrABHJC8QtHwVx+mHWP3QcEqBHYienj5dHSgjbxtC0WEZXYt4wcD6zrQElDPhFuZgfA==", + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://github.com/chalk/ansi-regex?sponsor=1" + } + }, + "node_modules/binaryen": { + "version": "118.0.0", + "resolved": "https://registry.npmjs.org/binaryen/-/binaryen-118.0.0.tgz", + "integrity": "sha512-KzekjPjpLE1zk29BKQSHNWLSHPYAfa80lcsIi5bDnev8vyfDyiMCVFPjaplhfXIKs7LI3r1RPyhoAj4qsRQwwg==", + "bin": { + "wasm-as": "bin/wasm-as", + "wasm-ctor-eval": "bin/wasm-ctor-eval", + "wasm-dis": "bin/wasm-dis", + "wasm-merge": "bin/wasm-merge", + "wasm-metadce": "bin/wasm-metadce", + "wasm-opt": "bin/wasm-opt", + "wasm-reduce": "bin/wasm-reduce", + "wasm-shell": "bin/wasm-shell", + "wasm2js": "bin/wasm2js" + } + }, + "node_modules/buffer-from": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/buffer-from/-/buffer-from-1.1.2.tgz", + "integrity": "sha512-E+XQCRwSbaaiChtv6k6Dwgc+bx+Bs6vuKJHHl5kox/BaKbhiXzqQOwK4cO22yElGp2OCmjwVhT3HmxgyPGnJfQ==" + }, + "node_modules/chalk": { + "version": "5.3.0", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-5.3.0.tgz", + "integrity": "sha512-dLitG79d+GV1Nb/VYcCDFivJeK1hiukt9QjRNVOsUtTy1rR1YJsmpGGTZ3qJos+uw7WmWF4wUwBd9jxjocFC2w==", + "engines": { + "node": "^12.17.0 || ^14.13 || >=16.0.0" + }, + "funding": { + "url": "https://github.com/chalk/chalk?sponsor=1" + } + }, + "node_modules/chalk-template": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/chalk-template/-/chalk-template-1.1.0.tgz", + "integrity": "sha512-T2VJbcDuZQ0Tb2EWwSotMPJjgpy1/tGee1BTpUNsGZ/qgNjV2t7Mvu+d4600U564nbLesN1x2dPL+xii174Ekg==", + "dependencies": { + "chalk": "^5.2.0" + }, + "engines": { + "node": ">=14.16" + }, + "funding": { + "url": "https://github.com/chalk/chalk-template?sponsor=1" + } + }, + "node_modules/cli-cursor": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/cli-cursor/-/cli-cursor-5.0.0.tgz", + "integrity": "sha512-aCj4O5wKyszjMmDT4tZj93kxyydN/K5zPWSCe6/0AV/AA1pqe5ZBIw0a2ZfPQV7lL5/yb5HsUreJ6UFAF1tEQw==", + "dependencies": { + "restore-cursor": "^5.0.0" + }, + "engines": { + "node": ">=18" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/cli-spinners": { + "version": "2.9.2", + "resolved": "https://registry.npmjs.org/cli-spinners/-/cli-spinners-2.9.2.tgz", + "integrity": "sha512-ywqV+5MmyL4E7ybXgKys4DugZbX0FC6LnwrhjuykIjnK9k8OQacQ7axGKnjDXWNhns0xot3bZI5h55H8yo9cJg==", + "engines": { + "node": ">=6" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/commander": { + "version": "12.1.0", + "resolved": "https://registry.npmjs.org/commander/-/commander-12.1.0.tgz", + "integrity": "sha512-Vw8qHK3bZM9y/P10u3Vib8o/DdkvA2OtPtZvD871QKjy74Wj1WSKFILMPRPSdUSx5RFK1arlJzEtA4PkFgnbuA==", + "engines": { + "node": ">=18" + } + }, + "node_modules/emoji-regex": { + "version": "10.4.0", + "resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-10.4.0.tgz", + "integrity": "sha512-EC+0oUMY1Rqm4O6LLrgjtYDvcVYTy7chDnM4Q7030tP4Kwj3u/pR6gP9ygnp2CJMK5Gq+9Q2oqmrFJAz01DXjw==" + }, + "node_modules/es-module-lexer": { + "version": "1.5.4", + "resolved": "https://registry.npmjs.org/es-module-lexer/-/es-module-lexer-1.5.4.tgz", + "integrity": "sha512-MVNK56NiMrOwitFB7cqDwq0CQutbw+0BvLshJSse0MUNU+y1FC3bUS/AQg7oUng+/wKrrki7JfmwtVHkVfPLlw==" + }, + "node_modules/get-east-asian-width": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/get-east-asian-width/-/get-east-asian-width-1.2.0.tgz", + "integrity": "sha512-2nk+7SIVb14QrgXFHcm84tD4bKQz0RxPuMT8Ag5KPOq7J5fEmAg0UbXdTOSHqNuHSU28k55qnceesxXRZGzKWA==", + "engines": { + "node": ">=18" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/is-interactive": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/is-interactive/-/is-interactive-2.0.0.tgz", + "integrity": "sha512-qP1vozQRI+BMOPcjFzrjXuQvdak2pHNUMZoeG2eRbiSqyvbEf/wQtEOTOX1guk6E3t36RkaqiSt8A/6YElNxLQ==", + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/is-unicode-supported": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/is-unicode-supported/-/is-unicode-supported-2.0.0.tgz", + "integrity": "sha512-FRdAyx5lusK1iHG0TWpVtk9+1i+GjrzRffhDg4ovQ7mcidMQ6mj+MhKPmvh7Xwyv5gIS06ns49CA7Sqg7lC22Q==", + "engines": { + "node": ">=18" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/log-symbols": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/log-symbols/-/log-symbols-6.0.0.tgz", + "integrity": "sha512-i24m8rpwhmPIS4zscNzK6MSEhk0DUWa/8iYQWxhffV8jkI4Phvs3F+quL5xvS0gdQR0FyTCMMH33Y78dDTzzIw==", + "dependencies": { + "chalk": "^5.3.0", + "is-unicode-supported": "^1.3.0" + }, + "engines": { + "node": ">=18" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/log-symbols/node_modules/is-unicode-supported": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/is-unicode-supported/-/is-unicode-supported-1.3.0.tgz", + "integrity": "sha512-43r2mRvz+8JRIKnWJ+3j8JtjRKZ6GmjzfaE/qiBJnikNnYv/6bagRJ1kUhNk8R5EX/GkobD+r+sfxCPJsiKBLQ==", + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/mimic-function": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/mimic-function/-/mimic-function-5.0.1.tgz", + "integrity": "sha512-VP79XUPxV2CigYP3jWwAUFSku2aKqBH7uTAapFWCBqutsbmDo96KY5o8uh6U+/YSIn5OxJnXp73beVkpqMIGhA==", + "engines": { + "node": ">=18" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/mkdirp": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-3.0.1.tgz", + "integrity": "sha512-+NsyUUAZDmo6YVHzL/stxSu3t9YS1iljliy3BSDrXJ/dkn1KYdmtZODGGjLcc9XLgVVpH4KshHB8XmZgMhaBXg==", + "bin": { + "mkdirp": "dist/cjs/src/bin.js" + }, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/sponsors/isaacs" + } + }, + "node_modules/onetime": { + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/onetime/-/onetime-7.0.0.tgz", + "integrity": "sha512-VXJjc87FScF88uafS3JllDgvAm+c/Slfz06lorj2uAY34rlUu0Nt+v8wreiImcrgAjjIHp1rXpTDlLOGw29WwQ==", + "dependencies": { + "mimic-function": "^5.0.0" + }, + "engines": { + "node": ">=18" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/ora": { + "version": "8.1.0", + "resolved": "https://registry.npmjs.org/ora/-/ora-8.1.0.tgz", + "integrity": "sha512-GQEkNkH/GHOhPFXcqZs3IDahXEQcQxsSjEkK4KvEEST4t7eNzoMjxTzef+EZ+JluDEV+Raoi3WQ2CflnRdSVnQ==", + "dependencies": { + "chalk": "^5.3.0", + "cli-cursor": "^5.0.0", + "cli-spinners": "^2.9.2", + "is-interactive": "^2.0.0", + "is-unicode-supported": "^2.0.0", + "log-symbols": "^6.0.0", + "stdin-discarder": "^0.2.2", + "string-width": "^7.2.0", + "strip-ansi": "^7.1.0" + }, + "engines": { + "node": ">=18" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/restore-cursor": { + "version": "5.1.0", + "resolved": "https://registry.npmjs.org/restore-cursor/-/restore-cursor-5.1.0.tgz", + "integrity": "sha512-oMA2dcrw6u0YfxJQXm342bFKX/E4sG9rbTzO9ptUcR/e8A33cHuvStiYOwH7fszkZlZ1z/ta9AAoPk2F4qIOHA==", + "dependencies": { + "onetime": "^7.0.0", + "signal-exit": "^4.1.0" + }, + "engines": { + "node": ">=18" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/signal-exit": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-4.1.0.tgz", + "integrity": "sha512-bzyZ1e88w9O1iNJbKnOlvYTrWPDl46O1bG0D3XInv+9tkPrxrN8jUUTiFlDkkmKWgn1M6CfIA13SuGqOa9Korw==", + "engines": { + "node": ">=14" + }, + "funding": { + "url": "https://github.com/sponsors/isaacs" + } + }, + "node_modules/source-map": { + "version": "0.6.1", + "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz", + "integrity": "sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==", + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/source-map-support": { + "version": "0.5.21", + "resolved": "https://registry.npmjs.org/source-map-support/-/source-map-support-0.5.21.tgz", + "integrity": "sha512-uBHU3L3czsIyYXKX88fdrGovxdSCoTGDRZ6SYXtSRxLZUzHg5P/66Ht6uoUlHu9EZod+inXhKo3qQgwXUT/y1w==", + "dependencies": { + "buffer-from": "^1.0.0", + "source-map": "^0.6.0" + } + }, + "node_modules/stdin-discarder": { + "version": "0.2.2", + "resolved": "https://registry.npmjs.org/stdin-discarder/-/stdin-discarder-0.2.2.tgz", + "integrity": "sha512-UhDfHmA92YAlNnCfhmq0VeNL5bDbiZGg7sZ2IvPsXubGkiNa9EC+tUTsjBRsYUAz87btI6/1wf4XoVvQ3uRnmQ==", + "engines": { + "node": ">=18" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/string-width": { + "version": "7.2.0", + "resolved": "https://registry.npmjs.org/string-width/-/string-width-7.2.0.tgz", + "integrity": "sha512-tsaTIkKW9b4N+AEj+SVA+WhJzV7/zMhcSu78mLKWSk7cXMOSHsBKFWUs0fWwq8QyK3MgJBQRX6Gbi4kYbdvGkQ==", + "dependencies": { + "emoji-regex": "^10.3.0", + "get-east-asian-width": "^1.0.0", + "strip-ansi": "^7.1.0" + }, + "engines": { + "node": ">=18" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/strip-ansi": { + "version": "7.1.0", + "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-7.1.0.tgz", + "integrity": "sha512-iq6eVVI64nQQTRYq2KtEg2d2uU7LElhTJwsH4YzIHZshxlgZms/wIc4VoDQTlG/IvVIrBKG06CrZnp0qv7hkcQ==", + "dependencies": { + "ansi-regex": "^6.0.1" + }, + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://github.com/chalk/strip-ansi?sponsor=1" + } + }, + "node_modules/terser": { + "version": "5.31.6", + "resolved": "https://registry.npmjs.org/terser/-/terser-5.31.6.tgz", + "integrity": "sha512-PQ4DAriWzKj+qgehQ7LK5bQqCFNMmlhjR2PFFLuqGCpuCAauxemVBWwWOxo3UIwWQx8+Pr61Df++r76wDmkQBg==", + "dependencies": { + "@jridgewell/source-map": "^0.3.3", + "acorn": "^8.8.2", + "commander": "^2.20.0", + "source-map-support": "~0.5.20" + }, + "bin": { + "terser": "bin/terser" + }, + "engines": { + "node": ">=10" + } + }, + "node_modules/terser/node_modules/commander": { + "version": "2.20.3", + "resolved": "https://registry.npmjs.org/commander/-/commander-2.20.3.tgz", + "integrity": "sha512-GpVkmM8vF2vQUkj2LvZmD35JxeJOLCwJ9cUkugyk2nuhbv3+mJvpLYYt+0+USMxE+oj+ey/lJEnhZw75x/OMcQ==" + } + } +} diff --git a/examples/javascript/package.json b/examples/javascript/package.json new file mode 100644 index 0000000..b6a2a95 --- /dev/null +++ b/examples/javascript/package.json @@ -0,0 +1,5 @@ +{ + "dependencies": { + "@bytecodealliance/componentize-js": "^0.11.4" + } +} diff --git a/examples/javascript/spin.toml b/examples/javascript/spin.toml index 2613a71..05100ab 100644 --- a/examples/javascript/spin.toml +++ b/examples/javascript/spin.toml @@ -14,5 +14,5 @@ component = "spin-fileserver-example" source = "composed.wasm" files = [{ source = "../static", destination = "/" }] [component.spin-fileserver-example.build] -command = "node build.mjs && (cd .. && cargo component build --release) && RUST_LOG=error wasm-tools compose http.wasm -c compose.yml -o composed.wasm" +command = "npm install && node build.mjs && (cd .. && cargo component build --release) && RUST_LOG=error wac plug --plug ../../target/wasm32-wasi/release/spin_static_fs.wasm http.wasm -o composed.wasm" watch = ["*.js"] From ba65a0f0440a8e7596622dc5e3658ead6f2e7ded Mon Sep 17 00:00:00 2001 From: Ryan Levick Date: Tue, 3 Sep 2024 12:49:37 +0200 Subject: [PATCH 3/6] Fix python example Signed-off-by: Ryan Levick --- examples/python/.gitignore | 3 +++ examples/python/README.md | 10 ++++------ examples/python/app.py | 16 +++++++++------- examples/python/compose.yml | 7 ------- examples/python/spin.toml | 2 +- 5 files changed, 17 insertions(+), 21 deletions(-) create mode 100644 examples/python/.gitignore delete mode 100644 examples/python/compose.yml diff --git a/examples/python/.gitignore b/examples/python/.gitignore new file mode 100644 index 0000000..9700e81 --- /dev/null +++ b/examples/python/.gitignore @@ -0,0 +1,3 @@ +__pycache__ +http.wasm +composed.wasm \ No newline at end of file diff --git a/examples/python/README.md b/examples/python/README.md index cd7b8bf..79f3697 100644 --- a/examples/python/README.md +++ b/examples/python/README.md @@ -11,11 +11,10 @@ component for serving static files. - [Spin v2.0+](https://developer.fermyon.com/spin/install) - [Rust](https://rustup.rs/) - [cargo-component](https://github.com/bytecodealliance/cargo-component) -- [wasm-tools](https://github.com/bytecodealliance/wasm-tools/) - - Note that you'll need [this fork](https://github.com/dicej/wasm-tools/tree/wasm-compose-resource-imports) until [this PR](https://github.com/bytecodealliance/wasm-tools/pull/1261) has been merged and released. +- [wac](https://github.com/bytecodealliance/wac) - [Python](https://www.python.org/downloads/) 3.11 or later - [pip](https://pip.pypa.io/en/stable/installation/) -- [componentize-py](https://pypi.org/project/componentize-py/) 0.6.0 +- [componentize-py](https://pypi.org/project/componentize-py/) - [curl](https://curl.se/download.html) or a web browser for testing Once you have Rust, Python, and pip installed, the following should give you everything else: @@ -23,9 +22,8 @@ Once you have Rust, Python, and pip installed, the following should give you eve ```shell rustup target add wasm32-wasi cargo install cargo-component -cargo install --locked --git https://github.com/dicej/wasm-tools \ - --branch wasm-compose-resource-imports wasm-tools -pip install componentize-py==0.6.0 +cargo install wac-cli +pip install componentize-py ``` ## Building and Running diff --git a/examples/python/app.py b/examples/python/app.py index ef6f874..b73121b 100644 --- a/examples/python/app.py +++ b/examples/python/app.py @@ -4,9 +4,10 @@ from proxy import exports from proxy.types import Ok from proxy.imports import types, incoming_handler -from proxy.imports.types import MethodGet, IncomingRequest, ResponseOutparam, OutgoingResponse, Fields, OutgoingBody +from proxy.imports.types import Method_Get, IncomingRequest, ResponseOutparam, OutgoingResponse, Fields, OutgoingBody from poll_loop import Stream, Sink, PollLoop + class IncomingHandler(exports.IncomingHandler): def handle(self, request: IncomingRequest, response_out: ResponseOutparam): # Dispatch the request using `asyncio`, backed by a custom event loop @@ -15,21 +16,23 @@ def handle(self, request: IncomingRequest, response_out: ResponseOutparam): asyncio.set_event_loop(loop) loop.run_until_complete(handle_async(request, response_out)) + async def handle_async(request: IncomingRequest, response_out: ResponseOutparam): method = request.method() path = request.path_with_query() - if isinstance(method, MethodGet) and path == "/hello": - response = OutgoingResponse(200, Fields([("content-type", b"text/plain")])) + if isinstance(method, Method_Get) and path == "/hello": + response = OutgoingResponse(200, Fields( + [("content-type", b"text/plain")])) response_body = response.write() - + ResponseOutparam.set(response_out, Ok(response)) sink = Sink(response_body) await sink.send(b"Hello, world!") sink.close() - - elif isinstance(method, MethodGet): + + elif isinstance(method, Method_Get): # Delegate to spin-fileserver component. incoming_handler.handle(request, response_out) @@ -37,4 +40,3 @@ async def handle_async(request: IncomingRequest, response_out: ResponseOutparam) response = OutgoingResponse(400, Fields([])) ResponseOutparam.set(response_out, Ok(response)) OutgoingBody.finish(response.write(), None) - diff --git a/examples/python/compose.yml b/examples/python/compose.yml deleted file mode 100644 index ac83a85..0000000 --- a/examples/python/compose.yml +++ /dev/null @@ -1,7 +0,0 @@ -search-paths: - - ../../target/wasm32-wasi/release - -instantiations: - $input: - arguments: - wasi:http/incoming-handler@0.2.0-rc-2023-10-18: spin_static_fs diff --git a/examples/python/spin.toml b/examples/python/spin.toml index fd987c4..26a16b9 100644 --- a/examples/python/spin.toml +++ b/examples/python/spin.toml @@ -14,5 +14,5 @@ component = "spin-fileserver-example" source = "composed.wasm" files = [{ source = "../static", destination = "/" }] [component.spin-fileserver-example.build] -command = "componentize-py -d ../wit -w proxy componentize app -o http.wasm && (cd .. && cargo component build --release) && RUST_LOG=error wasm-tools compose http.wasm -c compose.yml -o composed.wasm" +command = "componentize-py -d ../wit -w proxy componentize app -o http.wasm && (cd .. && cargo component build --release) && RUST_LOG=error wac plug --plug ../../target/wasm32-wasi/release/spin_static_fs.wasm http.wasm -o composed.wasm" watch = ["*.py"] From 18e59e096e6837f451335819a9924a654a05e79e Mon Sep 17 00:00:00 2001 From: Ryan Levick Date: Tue, 3 Sep 2024 12:53:32 +0200 Subject: [PATCH 4/6] Remove unnecessary wit Signed-off-by: Ryan Levick --- Cargo.toml | 4 - .../wasi_snapshot_preview1.reactor.wasm | Bin 109309 -> 0 bytes examples/rust/src/lib.rs | 2 +- examples/wit/deps/cli-2023-10-18/command.wit | 7 - .../wit/deps/cli-2023-10-18/environment.wit | 18 - examples/wit/deps/cli-2023-10-18/exit.wit | 4 - examples/wit/deps/cli-2023-10-18/reactor.wit | 32 - examples/wit/deps/cli-2023-10-18/run.wit | 4 - examples/wit/deps/cli-2023-10-18/stdio.wit | 17 - examples/wit/deps/cli-2023-10-18/terminal.wit | 47 - examples/wit/deps/cli-2023-11-10/command.wit | 7 - .../wit/deps/cli-2023-11-10/environment.wit | 18 - examples/wit/deps/cli-2023-11-10/exit.wit | 4 - examples/wit/deps/cli-2023-11-10/reactor.wit | 31 - examples/wit/deps/cli-2023-11-10/run.wit | 4 - examples/wit/deps/cli-2023-11-10/stdio.wit | 17 - examples/wit/deps/cli-2023-11-10/terminal.wit | 47 - .../clocks-2023-10-18/monotonic-clock.wit | 32 - .../wit/deps/clocks-2023-10-18/timezone.wit | 48 -- .../wit/deps/clocks-2023-10-18/wall-clock.wit | 41 - examples/wit/deps/clocks-2023-10-18/world.wit | 7 - .../clocks-2023-11-10/monotonic-clock.wit | 45 - .../wit/deps/clocks-2023-11-10/wall-clock.wit | 42 - examples/wit/deps/clocks-2023-11-10/world.wit | 6 - .../deps/filesystem-2023-10-18/preopens.wit | 6 - .../wit/deps/filesystem-2023-10-18/types.wit | 810 ------------------ .../wit/deps/filesystem-2023-10-18/world.wit | 6 - .../deps/filesystem-2023-11-10/preopens.wit | 8 - .../wit/deps/filesystem-2023-11-10/types.wit | 634 -------------- .../wit/deps/filesystem-2023-11-10/world.wit | 6 - .../deps/http-2023-10-18/incoming-handler.wit | 24 - .../deps/http-2023-10-18/outgoing-handler.wit | 20 - examples/wit/deps/http-2023-10-18/proxy.wit | 34 - examples/wit/deps/http-2023-10-18/types.wit | 208 ----- examples/wit/deps/http-2023-11-10/handler.wit | 43 - examples/wit/deps/http-2023-11-10/proxy.wit | 33 - examples/wit/deps/http-2023-11-10/types.wit | 559 ------------ examples/wit/deps/io-2023-10-18/poll.wit | 32 - examples/wit/deps/io-2023-10-18/streams.wit | 287 ------- examples/wit/deps/io-2023-10-18/world.wit | 1 - examples/wit/deps/io-2023-11-10/error.wit | 34 - examples/wit/deps/io-2023-11-10/poll.wit | 41 - examples/wit/deps/io-2023-11-10/streams.wit | 251 ------ examples/wit/deps/io-2023-11-10/world.wit | 6 - .../deps/random-2023-10-18/insecure-seed.wit | 24 - .../wit/deps/random-2023-10-18/insecure.wit | 21 - .../wit/deps/random-2023-10-18/random.wit | 25 - examples/wit/deps/random-2023-10-18/world.wit | 7 - .../deps/random-2023-11-10/insecure-seed.wit | 25 - .../wit/deps/random-2023-11-10/insecure.wit | 22 - .../wit/deps/random-2023-11-10/random.wit | 26 - examples/wit/deps/random-2023-11-10/world.wit | 7 - .../sockets-2023-10-18/instance-network.wit | 9 - .../sockets-2023-10-18/ip-name-lookup.wit | 61 -- .../wit/deps/sockets-2023-10-18/network.wit | 146 ---- .../sockets-2023-10-18/tcp-create-socket.wit | 26 - examples/wit/deps/sockets-2023-10-18/tcp.wit | 268 ------ .../sockets-2023-10-18/udp-create-socket.wit | 26 - examples/wit/deps/sockets-2023-10-18/udp.wit | 213 ----- .../wit/deps/sockets-2023-10-18/world.wit | 11 - .../sockets-2023-11-10/instance-network.wit | 9 - .../sockets-2023-11-10/ip-name-lookup.wit | 51 -- .../wit/deps/sockets-2023-11-10/network.wit | 147 ---- .../sockets-2023-11-10/tcp-create-socket.wit | 26 - examples/wit/deps/sockets-2023-11-10/tcp.wit | 321 ------- .../sockets-2023-11-10/udp-create-socket.wit | 26 - examples/wit/deps/sockets-2023-11-10/udp.wit | 277 ------ .../wit/deps/sockets-2023-11-10/world.wit | 11 - examples/wit/deps/spin@unversioned/config.wit | 12 - .../wit/deps/spin@unversioned/http-types.wit | 44 - examples/wit/deps/spin@unversioned/http.wit | 5 - .../deps/spin@unversioned/inbound-http.wit | 5 - .../deps/spin@unversioned/inbound-redis.wit | 6 - .../wit/deps/spin@unversioned/key-value.wit | 80 -- examples/wit/deps/spin@unversioned/llm.wit | 70 -- examples/wit/deps/spin@unversioned/mysql.wit | 19 - .../wit/deps/spin@unversioned/postgres.wit | 19 - .../wit/deps/spin@unversioned/rdbms-types.wit | 65 -- .../wit/deps/spin@unversioned/redis-types.wit | 24 - examples/wit/deps/spin@unversioned/redis.wit | 31 - examples/wit/deps/spin@unversioned/sqlite.wit | 52 -- examples/wit/deps/spin@unversioned/world.wit | 29 - examples/wit/main.wit | 33 +- 83 files changed, 2 insertions(+), 5804 deletions(-) delete mode 100644 adapters/fd1e948d/wasi_snapshot_preview1.reactor.wasm delete mode 100644 examples/wit/deps/cli-2023-10-18/command.wit delete mode 100644 examples/wit/deps/cli-2023-10-18/environment.wit delete mode 100644 examples/wit/deps/cli-2023-10-18/exit.wit delete mode 100644 examples/wit/deps/cli-2023-10-18/reactor.wit delete mode 100644 examples/wit/deps/cli-2023-10-18/run.wit delete mode 100644 examples/wit/deps/cli-2023-10-18/stdio.wit delete mode 100644 examples/wit/deps/cli-2023-10-18/terminal.wit delete mode 100644 examples/wit/deps/cli-2023-11-10/command.wit delete mode 100644 examples/wit/deps/cli-2023-11-10/environment.wit delete mode 100644 examples/wit/deps/cli-2023-11-10/exit.wit delete mode 100644 examples/wit/deps/cli-2023-11-10/reactor.wit delete mode 100644 examples/wit/deps/cli-2023-11-10/run.wit delete mode 100644 examples/wit/deps/cli-2023-11-10/stdio.wit delete mode 100644 examples/wit/deps/cli-2023-11-10/terminal.wit delete mode 100644 examples/wit/deps/clocks-2023-10-18/monotonic-clock.wit delete mode 100644 examples/wit/deps/clocks-2023-10-18/timezone.wit delete mode 100644 examples/wit/deps/clocks-2023-10-18/wall-clock.wit delete mode 100644 examples/wit/deps/clocks-2023-10-18/world.wit delete mode 100644 examples/wit/deps/clocks-2023-11-10/monotonic-clock.wit delete mode 100644 examples/wit/deps/clocks-2023-11-10/wall-clock.wit delete mode 100644 examples/wit/deps/clocks-2023-11-10/world.wit delete mode 100644 examples/wit/deps/filesystem-2023-10-18/preopens.wit delete mode 100644 examples/wit/deps/filesystem-2023-10-18/types.wit delete mode 100644 examples/wit/deps/filesystem-2023-10-18/world.wit delete mode 100644 examples/wit/deps/filesystem-2023-11-10/preopens.wit delete mode 100644 examples/wit/deps/filesystem-2023-11-10/types.wit delete mode 100644 examples/wit/deps/filesystem-2023-11-10/world.wit delete mode 100644 examples/wit/deps/http-2023-10-18/incoming-handler.wit delete mode 100644 examples/wit/deps/http-2023-10-18/outgoing-handler.wit delete mode 100644 examples/wit/deps/http-2023-10-18/proxy.wit delete mode 100644 examples/wit/deps/http-2023-10-18/types.wit delete mode 100644 examples/wit/deps/http-2023-11-10/handler.wit delete mode 100644 examples/wit/deps/http-2023-11-10/proxy.wit delete mode 100644 examples/wit/deps/http-2023-11-10/types.wit delete mode 100644 examples/wit/deps/io-2023-10-18/poll.wit delete mode 100644 examples/wit/deps/io-2023-10-18/streams.wit delete mode 100644 examples/wit/deps/io-2023-10-18/world.wit delete mode 100644 examples/wit/deps/io-2023-11-10/error.wit delete mode 100644 examples/wit/deps/io-2023-11-10/poll.wit delete mode 100644 examples/wit/deps/io-2023-11-10/streams.wit delete mode 100644 examples/wit/deps/io-2023-11-10/world.wit delete mode 100644 examples/wit/deps/random-2023-10-18/insecure-seed.wit delete mode 100644 examples/wit/deps/random-2023-10-18/insecure.wit delete mode 100644 examples/wit/deps/random-2023-10-18/random.wit delete mode 100644 examples/wit/deps/random-2023-10-18/world.wit delete mode 100644 examples/wit/deps/random-2023-11-10/insecure-seed.wit delete mode 100644 examples/wit/deps/random-2023-11-10/insecure.wit delete mode 100644 examples/wit/deps/random-2023-11-10/random.wit delete mode 100644 examples/wit/deps/random-2023-11-10/world.wit delete mode 100644 examples/wit/deps/sockets-2023-10-18/instance-network.wit delete mode 100644 examples/wit/deps/sockets-2023-10-18/ip-name-lookup.wit delete mode 100644 examples/wit/deps/sockets-2023-10-18/network.wit delete mode 100644 examples/wit/deps/sockets-2023-10-18/tcp-create-socket.wit delete mode 100644 examples/wit/deps/sockets-2023-10-18/tcp.wit delete mode 100644 examples/wit/deps/sockets-2023-10-18/udp-create-socket.wit delete mode 100644 examples/wit/deps/sockets-2023-10-18/udp.wit delete mode 100644 examples/wit/deps/sockets-2023-10-18/world.wit delete mode 100644 examples/wit/deps/sockets-2023-11-10/instance-network.wit delete mode 100644 examples/wit/deps/sockets-2023-11-10/ip-name-lookup.wit delete mode 100644 examples/wit/deps/sockets-2023-11-10/network.wit delete mode 100644 examples/wit/deps/sockets-2023-11-10/tcp-create-socket.wit delete mode 100644 examples/wit/deps/sockets-2023-11-10/tcp.wit delete mode 100644 examples/wit/deps/sockets-2023-11-10/udp-create-socket.wit delete mode 100644 examples/wit/deps/sockets-2023-11-10/udp.wit delete mode 100644 examples/wit/deps/sockets-2023-11-10/world.wit delete mode 100644 examples/wit/deps/spin@unversioned/config.wit delete mode 100644 examples/wit/deps/spin@unversioned/http-types.wit delete mode 100644 examples/wit/deps/spin@unversioned/http.wit delete mode 100644 examples/wit/deps/spin@unversioned/inbound-http.wit delete mode 100644 examples/wit/deps/spin@unversioned/inbound-redis.wit delete mode 100644 examples/wit/deps/spin@unversioned/key-value.wit delete mode 100644 examples/wit/deps/spin@unversioned/llm.wit delete mode 100644 examples/wit/deps/spin@unversioned/mysql.wit delete mode 100644 examples/wit/deps/spin@unversioned/postgres.wit delete mode 100644 examples/wit/deps/spin@unversioned/rdbms-types.wit delete mode 100644 examples/wit/deps/spin@unversioned/redis-types.wit delete mode 100644 examples/wit/deps/spin@unversioned/redis.wit delete mode 100644 examples/wit/deps/spin@unversioned/sqlite.wit delete mode 100644 examples/wit/deps/spin@unversioned/world.wit diff --git a/Cargo.toml b/Cargo.toml index 15fd2e3..144aeff 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,10 +7,6 @@ authors = ["Fermyon Engineering "] [lib] crate-type = ["cdylib"] -[package.metadata.component] -package = "component:spin-fileserver-example" -adapter = "adapters/fd1e948d/wasi_snapshot_preview1.reactor.wasm" - [dependencies] cargo-component-bindings = "0.4.0" # Helpful crate to manage errors. diff --git a/adapters/fd1e948d/wasi_snapshot_preview1.reactor.wasm b/adapters/fd1e948d/wasi_snapshot_preview1.reactor.wasm deleted file mode 100644 index e102337c095f384c5cc20e442cf7bdedfed2e0a5..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 109309 zcmeFa3xH%-T_=1`-FkNQqvn-NW+rgEGf5_o>Zz*kuI^3(Of^(U1WkA-C}O7`x2CJ7 zyQ`a$oklC*VQlk`<-*{ zz2{a}_w*!FiSRX{r|#>#{^$Sx|IayArL!t5%MuSoj@~8CTX$LFzPn=Q@4N3jt|R=% zK7Swnjh#O)f1~)tZGu1epLJKJgt7>KKvb=nE-+l5O|5g3N1>VY!`9NOCuA)V}^LmZTlzh!$;zo}_ zmPY3|=JWWMV8C7EKaQWU-L*6ERd==3J{Pg98_!lc&6^s{6}NM)({)#mueaUSy1Ujn zk((?`=CbWtwva1KW%Idges1if+s)RSZMW8KwVQ6ovaXlKYb&kVsm}4Um6esOyzWjh2s+`8KrE?2y4 z)$J~|>MyUmom#uO4(Lo)>SvlA*NW`CmaAVz2yL`$ZnoZTt-ss@^tr6N)@`55cDil1 zvT9j7uklEqes#{R)w1`KnpNx^o|pF-60z-K5agOZb<_ZtE@(pYopaer*NX4FTUYdq zFQCzjnXi5wYlDfNdHfygN1bhVt+MKJgo&Mx@X9_w>zrF%X|A1OP05|t)DJ5+)?`H_ z776*C;MCK-9)*x;va?Yof2_JzYA3Zk&8x*kYO|7yl_II214E8S(G1ZW`!3aA^Q4K+R1Y{2N0X6F&Gs*0{D?Upx5Xy%O z>)NyPy83m=*~O?a=V@5 z-P(G;N_w>$e3n&3ENk5FjC*&puV{$!g=K|+hSB$H$O9T)Tl@M9bIaM;OKAJhP}8K% z&Jfh`W{alx_13^XY*ED)Q@*JR&b=P@_L{zL+l7=6$w;F+QDS^S7%E?-#oSywncaCs zzHWxm2MYRRZON^j$|~b$N2ZH!%Z2MvHN95{I3ipvij*nemwb;v$&ICWqov;WAIPkXwv z-#M~>#7gZufQtkB?ET|*#(CP_xSg>r8@?jjPN&oHIR2TKu;X!?Ri*I1bn3u9YoC?c zkN;h@e}6P4)`bx9L$ULsWTlONEZ*{;#9QNqeNsbfuCBM*U0+dqmU`;m9eVogB-Eti~SsJT%OcmxrGPBU(zyH zN4q*K@3dKGt!3n`vdtvmtyY>=$6{;EZ8aL!dTPDhsx3QBF`NWkrNK?|K%~;dt&iPX?PhQO^7lJIuXat{2GgnM}}i*ejnv4 z8(&5ov0OU8T(X?VsnZkqaCyRZB6py``(KFyC~TFItc%Zu|NMEV7ZhELL|I|9!5-ol5QR`;!bws_! zxBqMZ&DQ1k{puHf>XKJdeT`tiRDhOy@<9L8T+{xF_=7=Gc~1BSnU zA#4U@NlE|om+yG5M@gRtZM^Z1KjkP&`pReC@?T%|m3Nb{h%-<$zf%legUeh^<+Q080S_Ipsu_Cn6<0mu$m{6#0!~m;83cSQ@vI0_}i_ z*kLAOhna}o!$j~p#6)b9iM-AOyX`R%`PyS5wq_!Bz(nkYFcXpAdrZVukd)5?Ch|wN zh!{-VhYT4qI4D`>u}E?}N=OwWNhew!5rZA}Z(Ly53xEIU18@7I&;H3rhKNk|!dD-C z;2-|Sn|}P`UzNxN5Pba|Z~K3L`-{K$j}n>Wa1Uw*)E@+c9nP;_U^u0}`}8}0-=YWr za%ehGB0zS1c>AtLGC*~RJSo?b270FdAsRyYkaXToHgmoW$s9q|ANd_?*^tK;h|;G5 z3sf*rQTpFK_-)Av1}Fr-O&Iu-Cd)q;6;XqmL_9tV?)<3a$+n>eS`O|ER8uau1FWr<#Al= zS7Ldb+$%}NF!tOLE1h;CJ}#Gt%Mr!VBLPQ`ggJU7%+Vt~938Ji96e%kbRV4}9!Hn2 zJ&qnBhd%5?dUPsuAf!{tGM-K)%dp$fJ_D{k*kSnSH0WXcc2w9NIz4KgnlSLm5yv7Q z|5tm$me#_t$S3~Q9*+(SKw`m~wKI_uKp}h*r7Z!&VuBb0DF%B$vNPgF6p}1b$}DI8 zon)bK02Cv`Ko#KI{)uRjRjRwpgk5A~!x4=i&q6tEHr$K`4YOeiw}#np18z;T;VQm1 z@B@=wIvkh{zO2xI)vp8m(6WNnn6g5D=gA5Wk63jtP7JE+zSQ2L>!#EuR7|PO;h0ie z566?*TMj3=jQNaa-YYFF%-S%BTe6F!Bzecnk~+yvODX`vm$$48(kp9gzc#g9DZBUY>|aE`*M=&%4ZsI$fA%_Tk>7 z8PcF(YCmbr=)XU4|E;3j1?1nS4Eguy6OeyD(O>?dN=J~@N%@DycIDsJqWfDy z{{6QtSy*wAT8auT)Ou(v?>TL8!Urz33^o@{ax}XLw}D*8&UGOJ_3@$QB_JU z4Z6D$k;9OOYzZQgt=%o%w$k;mT#8UgTHsa?nX%G(AS)?wcV(sXZ&z0SsE9<)NAAqt#9H@6c=G2K?XJ;0yh5O(BH(#_Dtjy0zlzay8056gY z)(c1EC)NZNyMxO!5$m1_Xjua+Hy=dXXqU{d%U!~0ok!QI^)Du$D-1C=yfcb{u{&834$r5 zBjYi43w6ft@M9@4$aXJsA~Z1Z%pgS=H%=_`IoWj>#nJINv{9(bG>}12ziDOOB9-Ro zagl@-gvY~tBS^vW%gk$777a(UR#K8}Y#398yHw^US#&%`X&^m6H{wTIL&xCUHLM|r zQIa5tauBzsHI(6NgQdc|h)()J6koH`K@|PkvxcNUh*g>q2v%uY%estbEz2_cnPC|L z3`0blxDzL6#WMH{2j_daVx`9(vrl`ju0ajhcMlADz;7^|z7GT2dhF_qG@8#BBN^zJ z2f>7a2cqpI@jLQfAd`SPiGS!F%)CjW6R4CE_)t!HWDZdaeNV0wxpf4%LWMO0 z$kLUp8Ti8v(m8E}KQp)wQ!ZQFOu0I8LB}*+dz35P@T@XSx#)o5=h9_7 z%9UmGGh^Z~sG)Jvs$^}7a?zNFSKxJ;a0fbGpKu2~-oG#uI6B0{CI>6j^#EO{h8c(g zSpl;6=3_Pq*|8KMe;T*GcT8$~jPa1fKdU~>yq2N>G8NS8L^8i4g$f9J|2X3C#4}uH z94qr9k_8AkAr5{Z>M76JAIVVhvG0k&ynqQD_9jOV8J~p@e5aZ)k#WiqrWm;aw?js&jbXsO%mlRQ`*ZMr;|6J&u&m->_EzS{DIX?a$=@*oiw(G!TUnNAVdW8N z<3KoBrR$cn7F`e%@se=jrN_kSl6^bmgg8BFTM@xzj+sbuLA-V%vGAz%fRjL(48_^u zaa?AtgXNOwvO#D$Q0OJ;-hv-3SmvCNQklc8ft<&1YYG;ra~gsLN+;A|U(5My)Kn_< zO9Q2(l5C;GL_G7)Qffv(J2dDVTqH|^UKW^X%ASf3!#t$Kr~lScc^r z^}ikT*nC9P;T%0WkMN`#O>minM{t>hr^|SRC(HDM61eN2rpOnXgC0i79*cR{`@g(Jh^cHzx??##uE}DBk6_n3-`j6B~BlnNH~dw|9Jk@xQm=7@#j~t+-C?T0iSZ=3vy(*h6F-Sr8_dJ8 zZWhqeoH(KY=mIbdj*LJfGh$;THki2S*Th833%LfCA^Z?_WdTmeB?U()9g$qaz7-D%BJ@$5 z)=2=R=;`uJ)^!*>WLMa}j|66d?HQoQ172|h(K!%g3{o1r;vz!^z4S!ZgdkRko>-+x zPYisS^rXv#=t(~daUIappoY;)PXimqBhe5VYA;;`2-wdo?lFkrm^KY!_~fKSiW5Cy z9Ru$YkrN@jqjSxP0eK*kfT(2#a1&cwl?kAWO|9@aeza)00rqSNT|x#l6V*)7!fY?o zW?_9sP}4`3ty2GFqDa_)W|d)dkyU!=@>Jx$`RFp}VSJhD%&6yYeprNDT0YL0yb5du zj0H~&`L4SfbiFm6qKCK9ov6o*j^CE#B@ zd4B>D0KV=A1vH$<3r1i=&qN*)+JRMVLn|NAK~3y zj}>G&9b?i|nX=eF@Z7@TVA)s!>n9khxQKzsRi?}9bH&xw072zUGO#n_#EPmVg; z>yuwN?~LFNg`oyqXXoIWKYY)`m^0>#y!i0={xnJttI`LTophhlL#i|sg6nKYl^$_M zoFSCnhtepYxD)yjdXkW7J@hoB`qYzD^+@<2a=>0dv^q)D0}7Uca1KBFX6+n)_Rpff z!pY3qFif01vo@>;N=J&!y;5W@2<4!UOZ_nm_0rSN;Ifa9=1PhtuG*FV!yZp&=(?P$YnAG`E;B z1v^pyIC1LG00|WayobgMp_=&+vF4B;0v;F;eAf4503q&8?k2_PVd2GQv|{x6uq7Vx zJa7Gsq{s>Wx0$<`c2bn?F(NfJBd`X~O&d{`IG%bT8GMxaA+iTlNy9;gW27yPyO1p| z(Q{C4>|X2y#i3_m6$aECLQe3W5OV4=A>7o@4AcY&q*J#?SKVxj4|Ke}h&ZtE{%JgB z!xoR67uY3AhfIG5&fTboVninXr%}xe|3PaBiLeMXb?7-I8+P-pBT<&Zoq)d1pEJ06 zWL%J+3Ke3#A5tdsAf!v;gAgs?mg@0+_kM7EXdyC=50O}Ox-=Zr6;*ZFs;-FS&0bw; z)|GJ5AEZD6*OyUT))hxxGF%9JH{z1Rpn)j;2MA~+4H|$4Ap>s|p6+KJos)c~SipyK z%cap}C%ND}_zXcaVW=3n4L_-y1uQQIe0vT*iD!yKvQmDV@V|{0BM#mU-z*R^bRsa4 zBzt3)9z;Gnk@?@GF>PR6eJdnyV45@ZN!CA&AI_*tdN_;neNwqzOo%%ClRcJFwcvo_EH`OISA12UNe z2Zd;)q8rbm{jK33C!LP2m`PSn1UiOIt2Ro-A3hce#Bl-Mb{^}0n41Ya0V;ZVFp3hr ze>Fvth5H^dNppA-QY>}-6sY(X6~aBHeP$rwD2OHoK}%vbWdZD#gP?E4`D!XkPLJ{KAjJKK!co@N4zyT+YDm@ko?ML#LbqRkgvSsAKv-KPyYfJg=*lZ z^}?pDCS;KP|L6|-Pt5)MM<4vqfBWnof9&tkZQ_}kw9a9fN$Yx8S8PA5h*mh6t~6Lw zdn~5C)7#9^C8C`{PSySKCuJ3iVh@j`y z;>L->Vf9)6XshJLO$TbO{~if(zJ9Mlu|lH{tqLr@gp<}y(Z9SATk=DAXz zg~wWlxH;@fouaQaP_5}`HFb!q_}b7R;A-ug{-J%4`n88~(k;p=O&x+&hA~c7>0z8K zqw6s+&Q=&Vm|^%BH|Sw}I2NqALjWkGEkhR!>&p}I3v0|u<4tH)nd+~nDho1A)QM*y zWf_X8sT)IQCB|yq*w0;s%EpuhJeH1<1fn}oknv^a_1alNjTZr3$HepSw%5pm=+=14q|J$hj5;CPnARGst8qc`?B_uw??4}rv|!{xL~tiF zAjWBN0_VwEGjE{h)q&woboXpQI4*$rup6Z<2$PW3UsMm4SRZ?YF#<_AGz&57$fdBJ ziwi99VEkAhii$gNYr7;mZB#8=OgKZCcd)^Mr+52G_%_+j^m&*{IDHWRtZ0)#WhsC|bJ^D{?Ii!T=)kr(`iO7{N*a zd78}NMABMDA%^5VC`VMRI^xHw9k>-3^T3omau59O^gMH^I-3|c%zY`c4a^B+Qy3D) zVKziWDS2#YD;R4wlyXvrR&Auz`)o-1p}yr)>OnowHwQHg-{9V6-u9vk(%_a8W*FR> zC_ICEs|g!q|KFIf+YbNKg-)87pFW>>J1o;&dj_LTcpvY zA4G$=+#>Tv>HTBcwzgv<=?Btc%nLDmsn-{(gh%hcTK>s}F*?u3VxF3zu`yFmrjgTt z9#4Xkr5t2DQS8KJ7P-uS8bXKT;p}sKibubLJah6x`vnt2hsWVzl+{2#feoQnH9*IU zBBT(bt6r&rnYT)z2xVt(WQfmhfhbH-prQ-%!_1okEpU$VkV~PDpi+KZj6i>L62-`V zw!(!jF-AX;lZP0(eJ2Aa_6gk{LH_4nUDw%jj7npO2{3Dn2(`VGhPJ(M{+DM8>lU14wpH-R+UzhP1zSKMQGgI#*;SFjSzTDE<7Ldfb#|2iOXp)yC!vV%ip9cqEDM#IY zN!}vuL_;86`kH!@^PY@ipnEbOArC;X4=PyV6u1qwv61rlp5Z8iHZp%pzcI#L}gQJm%KwrW0_cJqCkh|@7 zESbFmvjO-4t2zlKpBPF`Y~dTiS;CY)9Uz`45!4#WR_Q385YzzAL`)V!Y9*e1T|HAz z7^c#|hE>9x8Nbz|@Z@>LO18|vWcrAHmRVLACVuZq{}c7HDhz~~)$H>(lgwd zS?dbVPM0H7k_F?rS$J*B8h}5DCvzA?M2r}nH+rF;(celm>+QRSnBOM~R6;POgKyH) zz=gETyZuN`E@Y(lgC2*{{SF(H))wV$<~2$>v8T}mq@HTK3`5zE3h!PXjR=c_hJ#|u zp)CletYWUwTN0lSAqY*ned%wb6EBf@fUU6!R!EqkNwpUeK|*^4Qw-3=bb1%LkPJj7 zIS?)bldX8blpv&VBnSZ(8CE1PotQVJ-dg~ZNUFLA{y(TZ?l+~h{;2(}I*r^DW6}kD z%n7@V9o(B@OqcP*m@K288Dh-vhI=`|gBp~t)NeDW2~4|=qG2?KQm=dNDfL^9W`L98 z8}QroKZi*$4R}tHX~1)m!cjE2#KJS+`w#13EWqZ$K-FRf=^%O~#6qTv5^h8C>vg+2!bL?&1GK*ymxOGqx z#Zd^w;e1EMC*M&K7vz4zknzDfwEhB~d=W?;7V}V&&BTh{bZbA1sPnA_mFZy^t_t(DO#)HA zn@;T=i9lT~ggN2W4b1fpV-D@1&7LT&x*%l5*B*EDG`)}~>T#uye={ChI<_f`8aQNZ zbjBzTaOYyfgOIDR4q@PH1%fw5Seq}y>I0NYe>-NjIW!3GWLRxb8i))CzENtY zG9W1PDzNV<2Z3Se@F6q@9pp1$>o?(8uTJnxW{Nca+xX=6dmmHW$>T^CBCC@;DH8P3ft0^ zh}wCY(x3+AGu^=tDhNeFtpJAgNhR16!%P2XI|x^VQ$`$lm`ikA*u+jjPeTbylJVnU zgXJjELFRUF+c5zziu?y&%XsEp632mqr^dOQGcNbbm0ph$QkN|_-6X=txrZDS94INn zeo$7VIW5FQxQN&meq@A1`b{I5ANBnuDCR&{f~q6kJ4cyM0>2}O*{iIl61oSEMUJ6% zj0bBD_(w0RF*51&p;jg{y5-0+4|y%BZtKpYrh}t^oh3hpO&ZDkm>f1J zX5Ru9+oH#6`v>}N4}hLBTs%u&Xxydhb2;R0cg+sTn9`rKX43E9Cj4 zWFhaN;bTUCX#ut>WywGX-8vM#;gks(q{yIk3L|HLTk8gfQINb+|^gSt|v3;J>b^2|wU%^wb#VX&zLz0bIY zlTULgBnoo5BcAQ2lg3GNxnqJMWh`M#>m`f{XN1cg6I{ZGwegI*%;9H<%Nwzn!WrXoM`R+X<&G&3C%GS4k*r@9%sfUeC>@c>l3e%b#iUZy&k{t@Y5eH)gd7%C z8gzFIw+7vz(GcCC^$^`5KFz**`*QjinotY8^lOjm5?tWLDov_ml_u5cG9J;%GWwZ8 zbAa*Q@sxCy4RSy}9~t<7Od{hf1?wJDipu_nv2*}hxldeL#)gQB#74FsA}tG;W8iL7 zIuL=+z*9P$4eVuNs>JRgbOc|du>Fck&;i)-656Wez{l+49w-6y63^UEbyuQZl&BZ% za3#5;M7*`CbqMuXrHOj1(nLL7CWLzW zSs3-?a(2i@GBULpX2RFDp|tBgN(VaLUQ!#_cppjx3kbN3J!NurjeJ8UN0+FFCk9uy z9OO%bpJ~pC6w+a^>{RK~Q1Ec$vrdh-spH}{FzFOID_%c8z_e&-3>#^EaKb9ZxR(}S zEoDL*xPZ;IqS#Xl7hUYO#S0;K*(%wYS4t}^1ur`g8x?ZZOxj5Yvxi0J?2F!|4Ikdl z?q#jpn2V9tu6fwFnYWU+A|uQ}7rz5CA2I=-?eV^#&6bjCD_WOZR;9r9RhmSqG!5?0 zhss>!4HhTgP_479j(Fuq7YI(^!O#BK|ibp z3DEIKKh-}Fshk>#qpEY@{NI{uzj1IC8DPEG#q$m*vHAtWC20lm=Ly1;_ zM9_NIANH(-kDHW9Qqt5(2JbmDElpy07NSq+F`77Gno%^w89u@_{4JXIBS6a4>v(o# zTvr1b6NQ_HD;EbN;yv_( z4j9{P>nc6^k!AEVgMKiThnP?o5@B&NE`>q>td?N|9k5SJgCFo9=gm+2*=86Mm};H) zg9!^I{>Vx85`VUuutE0UPyE@Y|2Ze#llT+wN&JcTB>u=@d5J$y#jtj#W!7>qZQ*>Z z9Zbtp>n?uVuDiI8Eiq8{xX*_N?JmAQycpS6SRTKkf@Q)~DX6HxS!t*$Qk|fkp_LA} zzym#oFR`j!Dk3Z^0~T0UEGx^rU1K1$k)#YJ$vhO?g#s2*GTw+1{`%sODnQCJRB6cI zkSdVjYeN;F!qv~3)ht=R_Ec$)orY8aR%xmNx=ctF(9goEfV5`K?K038FLo4IvjZKk zkAZ_8?-#>)C^1iE))+`U>Q$BTETk&;tYc!J0vL!mg$1qFU&llg!!wCl#4`lYtolT z$NSVu&Ufxg&H%G~FWk3>^5-{NY=NScac8i70Tv#IbM6$POcA7ib8lw3pp0izr0f#}Pf#KJ zB2YV)Cq^L|vX&*!x)@43qj2>d7w}o0Mto@$-c861Ec~*$3m-5So<={XY#Luk&@dAt z=Y5=cyPP^C@|+lvnd;9$4VfP$-6L*|-I^)Bl(SD}M;{B-d81k9F~82Y1$E+B!DA6w z=R^JK#PpBCBf-^2IFa2MV_LH8q&`(KN}o~23#RRHkc)oeUOmG}4i+0qW1*iPR+|`o z-o)NV?(Gdlm!1LlCiB>NJ|u>T(DuY0v@C;k*t^=WH9wfTFe)P%2d}a;}BTrVrG!B@?LI0a!%Iv!#{EcZyOvEK)Lvfjk5b2JO z@GZ(?9>`&N(h;nJ3^q%PlNs(=07JwlaAuE>no@w*bZTR9=ct`PX5gS%%Qpf5Bh>Cu zV<7V|`><6EIWvqcWHI~6iBYxui9Ie^PE2oW1n)QHKT6#!7D`w`P5v4M3x*EAf;F?x z;i&l}AvbNNEYCbldBVNuuwx-Z#iI*CK?jBW^PrHy>|n`>c^*{MX7Zz4-eh!;#}cB0 znM=_@IUP!1sZKI7!nsc9jzw>kJx=Hzk21bDSO)sn7oM;|667B}watI#scrrjF5J9K zG=y5C7Tb|QFs+bDg~;sV&7BkbfY**(wYUFXs3aL@-}f9w-rzoG|4YY5NgtACkRj+r zwy^e_t5dY5#?YQrLge`s;L%i~Mw#d=Pw2$a7Q7mQkBhNmuHGTB@ydaqz|Iob?E$BB zP(F-se`|Oe#=z@|xIw1YkY{HP7MtG?0Q8fOS~vR)=vz=7@Pi`TsROij%;nIuOw8rb zv`kF*yT_2du*epc$$)u|9~jwgXy1WO$bgl!u8e?{HwG_awZ$0T5)uCC2S`^E+ETT! zXI(X4&{xzxn?6CW;mtfB4hyfA3%Z?GJs@nYGyXSHJkXZ}`m*f8iIuf!(6n`aeGU zzQ1|x5C6%>{ucLa{cC^rx%a;Aeee3zU*TR?e~sQPS{^8?p9RAAEut?-Bpi+haJT_= z8y59dxHT+l98(*D19p1}!2t`I%#){nB!B}H0{t@RQWW!%etRm&@G;lsDNQE4x=NeM za_PKxOdPmk?^-?ES4Z(iE*IctF<9M%z3sUuK(0%{A|lw*SRwEpsf~gqV&N2C%P)mv zK^WsbkYrG6_I}m_&Y;(@4R#p5;-;E zUMm+!8oX97s`OZ`TvVx_1vETZLGYiu>Y`nxTRjS z1onW*8q_&`zv3~3{-^8pbSbW7T3mI>j|ASpKwPkt;VOpuf~5?HacjCnaZFne1CN^w z{Igz{WXz8lNH|w8nEakD#dMdTkrGP&>WUk{3K`NpkW*9c1}suS*h_xVcgYN*@TXXtY$9kRYd44o9AgFt45Y_f$(t{4ZI8 z8$I*m(xr%_Uep^1T5A?EOsD{%^rt|~@gcNvx@55PA>KlKao03?@u`2s1z&xH7u-4P zJvg>bZrsJE)Z)2imv{YDbuIOLDP4>7LF1zje-XJdfE?%Jtx57AR^-MTk8*X{lXB=Po&wI5pWvRq8{n}HeEGDKMMuVnPejhtvB&O*y zo=;wu(a!?Zd0wC(W&ATA<;rZ#C=`YFDn$Vf6(|Y_w<2hIlf^55<+(JExD}9^-1J98 zOkgAF&@o)7RPzydY;Xn;_IbgYZ(JuLCuB1dSYS;_g@iR7S--(}5^c6qIYCVCUH2tvvEtkf@om7k*!w=TWIrxcl zX`JN@^B`x-8Nt#x)`o2Wm@5PJpX|>o z;tKG<4tjRwM!2{hiogU0h$hmC7tmu#h+&lsdBG5Q1-+jWQT3jaqamtziB3Ht>Pfn0 zB0CC$cc}E7%uoAdu2Yb%R{Q@k1xYPw^SMSey%^$|35_c%yUA~Y{dM52hNlw*`|thw z6Dq|?b0yqKuEaH69?qrj4%MIZp0h$^Z}_;#E9{4fe~~+kf0JzJXZ(hebb=?qu`ol( ziUB7gz2OEK-(caqOmJ3`e$(l8sNp``@I!v>nj4b&sW_v_@g!%Iha}>?WOd~HvPpc# zGTvy@8$pv!KTh|vev9O7dYb?&QlW4{EkJR~bOJ`-$OX6R9t5KYs!8ARB-Qy)tJ_ig zBYyj&Z|-RiE{^t@f#fyG_Voc7U^NQLnm_3FHTwJQ|C9*q|GvZiFq*x8y}QcLV}0<12Jl_)qXOHiv<+BSNN75!mu(QXFt;4 zAArkH5+a$8@NF@I_&gdIUS=QEwiE0u&=tVKPgL!rjmm+BYOgHWAKlJvp~{7NDmg04 zi&E|;YYabQz78${ocSRNTY6V~RC-}ZmirYsGTs2~XKf;)N;v{Oh1$Aus+4Q@)*hDA}d(cE*Dujt(Q(B$MJ$2llUmzyVXmDaY$|_`g04CHM z>gXhGkU1kth-ST;^W(s^B)>bHc^~gJ{^5Ik7~|qtS+!n)ff z^S8DF$M7a_AeWT=+#Vcq6Y_rGAe>}zhtMQ0ZUW9v`oLizxo0d4WyvBEjz8spI)Y*M z0unt{fE-qUq~z-d$mG_5RC7qJPVx;E`tU&750Gz5h=jkDea_d@IcLSl+j(jle&y+D zu!J7uJ@&fI`~t@Tus{|3NNyqus-P?K(8Uck#^;^ACTRPohM1EjillAFrW-Y*b)(!Ki^ zG$eNtwoCsr=pB?;uXjI$kAr@_6L+B=EvX*8MU-sl=XS}~a|y$^U-w?gyjk79x6(Bn zbP!u-L)bnHYnnP#>0$Kz*9lP0|HHX)?uv-3_vI$!{@y8^rZ>(CfHWo1#<*~Hs(pf( zk5ILGu2+9bRN~1x(1xtcPe?|=Bbe`x+$=s1(6QOyAqb_mbCdO1UW4g;8oz|Xqx$y~ z`~}!Ql9PlB3k7>6V7KV|1r12Ml)G8{3_l?nzn-ml%trdhWqe(|E#>rLG}R8_MAnJ< zC-6%0JT?kE1j^Bon+50B1e7Rsm#L~SG+25FX=d0=03D#F47y@hpgcSjG*bFf&eKeO zEQ;-2{KJ^IH?KCIIV3qOu#^XKWEV^yfX2(w39xXC4r16J7*Ezw-Y&uD9#E+k{Z<|gM2a{_!>Oj*WCrO5{4JV1-RL5I@{)UKll5Dex;wH5HcVEFF zs-Vn;uYBfn@BYAtf9wcD zw^*S(Sczs!3K6t`i2%ESI_$TP(yzB8iBPw-VS#Q#iyn`A-Ns^2CPZm82iJ$zqS^)K zp}!LGVe=)%hwKwTJWvz&9|3J80X*4T6?BJ7=`rhhNW&5^ZU}AwU5^lL@{o3*{_?~S zq0MiK5lA<0pt=e)kG_C_Wv5t`f+ja0m>A+B^(3K*$|N-D$pJKzA!uTKw1Otm#n$jfh=wXnwGzFG&@Z|tsyj$sZ!CaFYXyqx`Z!Z0? zkP5Aav1(0bp?TvYdzS1(YJ}7#lwQH@+AvWOUyr5cN_$(WmJ)rrL8AQT2oJeJ>`gzqVm~CLUU|QRsgoYz;1YF%bH0I`GyTNskb7089}0Ua zwNM~UK;6Sat6x&86o3Y4Nlclg1 zsGu|@e&?HA7wXw3pR%4kXjs{%;Ur;}`DMRfFtZiJsHjVi0$HHkBoJT$Xl#I$@6>nt z06_^OWlt*@`M?1g6Yhr1(hb?TeH<&F@;W0YB`O;#MPT4#5^#qplKn`_do`Qf@l@GU zXbp2jZ)wQ2a=}J_WdMz?hm7!ul3W^1Grt;YP=VbWCGJ9_B)l&(tOd<`bYl|7(Vu8;77u} z6rPvEv0y!rS{X|K-uNXPG8CbD@8|2>fXG%T#Pme+RQ%q{)EPDw4&a4*Y`_)W4MyfL z6!ug?`2*h~{ruL$fN#AX|9r&cK42a3AU+d0@kIZF7^JuEYU`+oU~AcUBAFUW508wF zW%lgdxBtLpmmj?1(BUIjKJDqw_{3GxH3|E56m&JZOwv9sM#s{n1pbov8^T`(fBW#a zAAgtO?+W}K!rx*19l_s~_Zv&9&!6&1(ZAUGE zyzx>(uA?nQ@q=mx%By}qnbSU(7uNtU5~0uJbP8}OkJk&nsg2SQ+gEFj(`*8 z!%}bmR751<{f90QDUHF-0h&pL4C=6Box+Bh6Y#*t@LGC7@zO!a9HuE8RZ!sQT*L;N z%gAW3X>P((1lJ2JN(ADaD7F(U-E(>ZCm!0e1sG6RZNxgI8x)H*ZW|F?gLHagh>m_J zd#KIsPDDBCxWzg_ZRZ7W#Y>;+Q|6s)n4RT$RFPiMl~4qzSCu(mG- z*7jDgw)??4dQq_E*S)Zo#yut;Cn!>%2TCN>v6C|JMBs5HCFdZDiwOiEOzU2QWajz&A%M%Swad0qPlL00~I~*z+F8P7?9phy>a&lf>rW z1S-&j4zQ2U(H$S~Jc$CuG@hco29L(mFoIa=pBIS5N|^YVw>_1k4?unuJLp5#QG%NY zE^%4Xn+o^6@>LHcSELUd5F^^CUtu=S8o9&)kcW+v6yJwp2 z*?hKAudH|7cDC(SYTZ`bwhnIf%Bpl$M=W6_{;!{jKop769bzFS+L1)Zt+m$bowMn+ z%34d`oQqn?dZp`jo2#yES>go#qL#hZIt%T@8fv?p*2+e=*;<3PCaynQ=`?Sut+Z;V zI>*meR#vj|`b2KBFqzA?YuQ4sFqO^cviZ4~B^HvXd%d-?QmL-Ewh&8}SQldboH!vO z&9#UH4JgIe*_CFeE28SL5SA{L1r$Wg7LIJR**eZ|`!l(hTQPLEvr+BT+Rdsf;_@xTC=tdNNn^ofHvU6exmiz1hnm;jczU5YBV}-_Z88#%BtJByt$UGSI(_8 zPcC({oywW!+Q}>@?0nS9@b?t}Rkq&jtglqg$-xQPd%+rB8kQi>Rt#4q6^0^H}9BFNI%_m|BQzxPwccqcEI#KJ&m#w)@*^kLj95CY<4 zZON^j%ARdEyRO(LmaU-sdy`-gUGSbx+S(tr4)-swN*;(>ll|ZO5RxBeD{J*^V`ZbW zBn||<+q!o3>19#t=ml!m9|m;-L{INuCVijF*cFXOEgHday zf7LyMRo@$9J}8=Tal)2}x7Y5pYged-F+E56*9aWD;lCnJ_yq!pD5B73-^N)M?|8RjxCFiAq~PM z!KwH><+Bb8QQKaI7$@USHo!bO%~wD|CBiXuO6_b=_c$DfjLgh^%?W zO?KNGYc;$?G4NloUR5k3AkH`xisK}Q!;2yJZnuVh;S%$(+CqnHYcCjhyi%*VosQUN z#ofChpgZK)Y4uP8XFum=NOrW=+Mry$Oq@!Hc05YeC2hR9Jj&Ti9gv{%>VV*aI9^>p zcvwD0+s#H39jCaU2vRRE$4_^olg0F|opg;C;pyU6wsnO#ZKu{+`eTTApowLr{MtkU zgBV$J&j$6_)?w&Is>e#&vSM$FvS5a7$kZ#v>eU(|>9ehkm3mgh@Km*R_Z`I z4|$^1jn27b9d9TsVy8D+-AYVCaa1Bux7Er5`A)hAnky^r$;wK$dJc%uA=0eX+%&}f zdb@QJ%2x;1KW!Yl6wX$|j;&*2l@at3nFamyr zT0~a1+FCnF04Wkl;z|xMfeUtZA2g(m24uK zn<8kT1+JU}3z7o|gxpi3UH9&;q}wdPJX~wHIsk@b0zgNp2xMzOWZQbWSdF9I_G)Ei zNCCIotgOV_5J|1o)L8&OyXLy}R2@=JUJ)Q|ccTMZh*#=lE4DQb^oXH{Zu@KugTYVK z+6S!zgao=@s&tmJ=-dXryb8?+NI>=FvK~b8H5;*XHO2d~I3^sAeP0__N?*#l&X7t$ zg;Fueo@rKeE#i97v{A(k{i?VzYF*`t52Fet)r>l_p8UMlLJ?o)8bvA?Geo#iW|B$+ zx*e5L&F^*`YSqc^Qc6Q^!a8oKL1u*jY{wP3pk;jM3q#{Wa#!fR-HOO#m@uq^5{3RH zPP)JhvO6(_5^1x*01f)){bn)){e0H zzGG&8$o#}C71vf|?mR{^&ygr4;#wcf9=6;RwJz^7)ubMr$F>Y5*eF~DdAsd7AJuM& zS_k_SmUtqbA)42qf@hj=e3qeC8eoyM>SH@_qi>%$qnJ#sh+i9}SnCiJ*YxRw5^({a z$yT~_K8QnRcYYlVz2E3555%*5pcw*mOt;FChx#2H#Qb^#j zo}B`vAEmWjDHYM{=lf_9)E5S-uTLAD_jEK=@SQ#{+>9zxvpBF7xocerb$nNUy4qNi z0Fr70zAA0gk~c{pr)(d*)(VuYNebFd2bxxg0KFq>6}B$nQ+0N8v3|2kMIzgQHV%6~ z-+xr{6JKNHSH2ZyKp2{r)JlxXe3Pi(XQ2vx+uryRz(n5+1{7;`m)!QX791(Qv21(~ zC96Ztsa0KuB_Zwvb{{pF&+h`Soj!mIX$RtkK6-7&4vSUv6V#z9I7crMOV@}~PeT{} zizHv=82AIr`a{$(<#!^ixN1#7X%4|WN}W%~A;10cXVwRY)u(XxXL1`jKT(1!_ei9kFiHAqNN080E3o z(I%uId{Z~}HVnrn8BYJUhsDAkc)ix#?%7uR6x>m(2RwUmL{nScU2D2^sd4)1X~t7A zp_Xr~0zkA?;f2#maDp5fPxiw>Qrl>Qcht@SGHVSOlwGOznmW5-A&hwSQmnWcvT9{* zLQRLRyT4MeQ_as(bFMbmq;WRtJw%<*MfZ{i!aUemgOCLkL$ThArq_UyG?m(J10U5h zp+^uZ<~Nn9)WP>snL62q%gwhy_DCkks^RB6!@3V)>Y=h%Kz!;UENXi1HrnnXGJuM7 zPWQg*(YyinNVK_rW}5#Lqt>40Iy~5FsEx{Ma|Je)En3lg@jto?@TK=2s3Tg*AJqR- zFN?v;1Z-1Tvxr-=a*+hu4h8kwR*D84t&Sf|=r-d}*<~9V_WH4HrA0fcK26aIff?Uu zo%2d1lbsq6E!(WaOV08|Z|?l^BYtm&b#F$|8;-WOr7_RRs$O)CYYgq{co_i!B|IF4 z_ny=Pw~qG&Ze-~kgkuFBVCB`Wxv*d)&I{WXc}X)~Q@vmGZF7um8s?L{4ZzCV&9f*L zu3+DKob8*sD;+)X&l%O*%G(244b2@~P7$%UKf=I+beYCG4<8JJYKXpvW#k*iJToC} z!Hes&#{MP28j1J>9;`||uVU2jy{4_PsCCR^u-@nTOOL?@9>$DVvc;*CXbzz>``DSN zH*I^Af59hjMF@Lgbi;L1CxKVafY3;U=jngl)6*E(;Q=q~;7{#(R#Grr0H-$A`%dgW zZ|cG*DHd)ctS{1A7oKV9unQrkoWI_gmVpiqs1IGpV9gd2J}g%41pEmu+*;69*Xq$K z1U5W4ou!R#9UegKh(ZsBx;2mH!1I?d3qS@7wvRTO_IQ)9cLX{BJT7_y)7C!2T^dv} z34YyHELrUL5NZ!U_EjF^<3@9>2|oZCIKAA;QVW_K)g0Vx)7Kk}YE+w=k&DZSgs|{i zk;@MPm#*Mol+@p2!8`0LEJg*oA6^ZI4Uf3-m1>4jH+N0IkKeB=x+d=<(aeaJeMENT zO0y$RGi-dL2};`au6R27oi;yr`nMLE5;5L?aA6>d@c(S{3(UENdcEQ?+5aS)>=7E=(;Rx7nrD=h@B z;I0$b^he24t_vx;0%8zH`;V9v8ed&)xG;=n;pD2j2ohDeR2#Uq!qB^yVDK5KQIzd%E`A*vK5I67y8b{)+Pk^Q-p;ccpTQZ`ge4PD(&x9vM?KPKuUH=j7VHn=%cJSl%H6aoHdeZwvlc{; z@2xVb(G&{#7mBTqraZ8A_FI=5UO%HKsZdZ@CIT&R)ViYon8HHGl&D6HJwoSD0C1pj zKOpo7ox|wNd9yP|3{GIQ6G)FMJx(y{37xIx1Z*=XM$f>#WvV(n z5(#`hZ4~X#r+qm*%31LpxkkBuEO(-3lxNwfFC&e@Y_wkm5Z*q|4t?IkvnQgK&$C0{ z!HwU`->)*%{!t6k(dXG_Nk0eZ>R!%^ulh2ngW$Zw1|PU|oENBV)O!(}HyF@n&dYZf z=DdfPRR%r?_mRw}f!&*-_eMq6WJI%rTx|Gt5HK4x-fR@7nM`(#qliS-k@6_A<|smM z`&M`*veQr@;_B-b>qLxDy1d-AGtG8ujgBV~5$hekL-N)LN8x#-I!NId##kd?%Z3Q*qN#81- zu3Zv+Y{$Sakz(IF-FkD44v7iBR{5xJwaB%Uo{m15B8IH@P=-x8PEFGJRue^hloida=nJ>keOsQz<7f{;PAV?wOl1@8S}ryIFR+mYLxSn z!|Qq3x1OV5G?(>sMl48G2DU)Y3tM@SPDM1b?ImFSR@BTz`wnF5DZB<9xV(29x(6^E zdf)VRVP9_-ILYWkA1G`y+sB?jgPi*<8{7&Bt`iGUq#DG!NI-I9G6OM6Phu3=R%ic617)uPCRP-ZmkUD^>_dG|AaRDF7|M*$-sm5e9;_5|2~IJImM~p_NNXN{AX0)yU=5IRekzR4cSGzRLEK!qRmJZnf#SpwvCnAVrNj{$R zw51fCgK=av*H>I@GbSdb!60Gc&!2kR-}1;s#nVt^mD2wO_kyzjoJt z?XLaO>%n%{e(kRP+Fkp_1g+h*UoSV7N$jruT3x^JYCqqzYe0_44Yc3oDxC7}+AnP6 zVL*quH@j=U)Kcf&wO_$@7zT>?OT>29e!bjVHg!&|>Gzf2wO_kyzoanTUHhe0f$pyTqH49f_G`OUx4Ub(FNFmVfW|)xhiz` z=mL3am66HBoiBEeE|6#MU{BWFqYJ!E39jw4Y54BZ1&pxvfz0mF1vpP*_vnH)&bX7O zMFlC5yGIx79$ny{Y_QFy11Z>r(alE}VCNv?A@^#OYt7=<*qMkBRSF9 z#|_If%9o)(z##+j$VX8h<58WLuUBx+L1iu5ooGzM`n0FvXJ8vc~s%GxK z*t@6aR+}y+`-=^|2@dvfEM2oJHXwKXEyU%1h`UE*dplR{9+7RFtZrnZ?jDhSF-K(Y ziVbX=_AMngcF%|72@JdE!+k5C4@WOW+&edf*T%tWyxn}zmiM&hcnWm}SReh8;q5+T zEyLbnb67^c;UDq3gXUS7C!a`-LvK+m&j7x$r_+dTu!6}xAEO%^6|*>){k$Q7otdAZOV8{p!Q&j4HW zNi-q$EqB80W#5wVZ^5Fa1i&GgM!gUMPu>||8GQy=ST4z7ga#(Z&^s{M`7Pv<6l7Zr zI=OoWn7=7^aF~#{8X7xh^K1yQdj=Sek=#84tP8;{PjL+$r#K<>nTL9{+qd-@V0*xM zQ^r|cmyYvdjhIpIMR4ALY#;9#VEeRpH^gQQkMX5Cn|eRZ7vr30eeCq(XZT1$H>%Sn z%T}Cz_t@#jbL{kG2&mAm>zO1bMJI4jTDP)>m~(`IWgK*7ueHt!n4v>(O|(`vc>WDe zJ41{e9OCSfyJjaVRrvxZVP5FS<72@E zo2$(h^MzWmI8&RRn=8)c%Jy9s-JCJ7DIjvsfEtaddZkjxP3Py`TEm?xN8O8Vp?5%i znyJ-t^EiI2Hto(Aa#M4aa%^qK&E#_pKRITmdv4wB&DW}hs+*ewTxMpUF3H}Osj}MXO<{FJgwT@2Jr>CpcMtS7y699op-1%u{ zTQB;Vl0C4mRccey)kdyXtj$#1dbK?IRtblE?(xInb}rF+B4j;Vn{sRU0*E_5<4)z~ z%42U+oytG{PTe7o+1kZd=c?t*$|ahkX)>FhiJ8jHPv>*)%UowHycDY^W=BX&oxO2H$ zp;DcjX-v&dO_vXJE)^o=I_Fkbnro*vH##*_uT1A^(>Zr;+I6Sh@@1EfA8oA3Hp!(o zH(UpSHR|*8#aga5GgZiyFW)(l6`HNtj?^YP`GQIB^S(LJgXV=CMwy?V$yMvQe6=uL zK6q-!ur*uD8!T_@#%A+{-0Tb}3Onc(Ds$y4cHWq$V)yEaTQ*j!U_QE)@E|GM)~k|)0)q-%|)0}twy6Tw|I18 zwt7_l1LLBD(@k+*=Y#sud{KV7((D)}Mq#!(pKr|9@-F0RwN@-2Y3_Jhi|X8P{gW?J zDN~OY<(aNM7*wm~<_h)7oLi|BrwTLE}iu3b@M$w&d8?YszVLbhg3)U|+ zQXEg-Q4R4bsBpeGKU1%{(+!~VEKsfN+`UbOVT*BlB{4rERhBc&%Az9Y9+*!}&A7Q~ zu!#l`+nukJ$Io4=mWxt9UEH$iLVa$!3WXdvT+2;WbLELwT&kvL)#0;Sw_R@(^3_Vd zUd+|OMJjIjs!Jw&h&6I?Vh^OjuPSqeT482(ra0Yb%#@E_vLn~Y@^pkBKA)F2Ka}8MKl{x&*&y;WI zUMj%m$^7~c6J#-6oUIq9rz-XNJhZYK&s?fjr*Ql<jYE`#do_rk*k*%Dc7vcwnTtDYi0p3c}Mutd* zW2zSjx%^bEUdcnLm@QUekR5;djyp1iJ4U@m2%-ds)HBjiwJj6u2~BDCl&R_*S)#f z`63;0z{7cHY18GYx5)10<}V66>77! z^7KnC3Mr@EyPIA4PY*g48jXBmb|yFFPUq)l=H|*X7mtp>4IdrlbqF2jr}ALd1&p9t zhiWrZF78~nAj0RTeI!)$r2MBIV)mo4TA@*xEzTBa@(s5LsaT%fxhXB1oH3i^kR&#eKClUxzhaE6+WVMoHqE8kKY(0&X34Nipx%X6L4Ib+OdPtavIgCsXVyY%{v$M zW{V*QK|Wtwa%-m+`+27!e&!m}g(*1w>iMZgzI@BhBV$`O*w+t^cB%!qJL_{UXro>z zKV#>vtu0$BO#9GOwhc}YhpxY|NyyJnyY(6pFXt*V^KN0PSbpZtz3^MMo)22@*JfjO z4rVEa3{OR_IFlQgS*Lcy|H6E^^sH@) z&M$1Nu9xU{oAIsisd}SQEFct7otiHci{*vewy7YWzg@0%E=e1nWWTgnVSTjctCdE6 z3bBP;qgZk08s%rJp}BW+b+k9M=Om?34Vhhj<~9wfK?dgd>=N9MIj9SBh&UGJD#f|- zt)sFgMsqrgsPDOH?HAz9ZMR;q@=d-3jKQ6%*J@R;FTitZx>70MzQ?Q7Z|6HkWWW~# zlFdGERNd0FW6RG^HR=dvGrstp3m5K0D0YqbUbR}UP0!BE!x=t5H(MxwSDMuk-0-8^ zk;Dx>LhhYA8J`grUt9(6o?Xh%Oy%cl`D(2&RV~&4#22u7YQc2Kzig~Fp?MT z3vOxqNPGFk`@;|0&67*r&UcUTDFdIh%24)urk zSIzga3wR^%5z$$s$M|K0@Vcb!?@!>81z)}$JPLW`Rnft*Zi^RdEzbAM{5+sNH9J$A zg@Ywm{(&J~Asc(U)OPZ-+iE+(_q}o6+aV?^i29m}4)zCdCnuYD19hlfX?77s;~l@7 zob*dD?7N1owa`Um4Pe%w$IcYy@`d^N@?D%V(A>sq73Bzkj_aPP$_q?ljTc>aWu;E2 zN+`L{-Ubizg$3rBAh+Q=5j50ndUgq1DqoqJ%GL67@W$t6%8diu_inK_l5%p7d~DAB z5;jJ_m;NJvo|`H8f~MZGx}>dnYD7NeEb`5YYNt0cv6|Lj5d+qcr-Bx=GryIQcZQdJ zJ#DyCPcwz3wn)9NJtQvy_m101cOU}mi|3l|O1(RzJ)S__jWiY3MRn-QnUuUi`2NgU zb=h&(>UWRGr=6vZZoPGO?c5I7H8WAbBd4Yd@JZGSwfs!Z&DG1V*m>r}_AW%JA}Nm+ zxyT&Czs2fw19AHTT)wUs)3t8J{9NPC#%`R2uk+%VE z4u5nl=T`FN^E-FXZx5&*uM`x59GWT=rluSD*-B%6s(in=WCQYiG_y-HdH6>WD1*2! zRvS}u{6kTpPnk_5esb0B0-~Ge$_?fXk7qqA*T~4CRad!wE^c=qgboL ztbDatzC?JC@9{K2>denD9G0JHZi<{g_koxm;g(^&z>0-4|n5oW} zUn73-2@LL{TuQS`bF*%vmWNxmI9+9yP5HIrc{^^MMyO%31M_BKJ5K>>Q!oQyZ~vcSu4OlF8;Y7n+jtYCD6%b(MHVSi4@gNQrFFpU z(jY<7MO$FNmx2K_BV#;H(QinbrfrhG-|u((C0+J+dag9KM|Pq*LW_YHV_PD1De{u% zo_p>B{=m2hAW3>tRG0tQHR zhu!RX=^a6)ZWSoYj2fNt`#CN+0`~|3^E4OH$xK@FCVTmb`)v}IZKStMo?*pvqHc2^ zg2N6af_aNwIcdko6{I*NG{RILJmyFu9i`1(_R^sKGTPnnsv)FHLGtRTfw62B%-ihh zpbljd4xmS3t)f?wq!V6=)ZAm&2lbfmV@q_Z5Y5TNRcE0a%41n7gl^v4XRi+H{80;9#v*E~aYBKi)R>3|y{30@$|_m0D%{vd zSx9JGFN0H1zb1*|<{=9`rk||yqofu#xGbvR66JNskuP)R{U-not7GV4vapF!ay}`* zAWGS z@@k~p==_gq^}+wok@iQld2{wUeruakQ#yhqLgMD)c(1t%pXHEWu1d*C{S`E>m@X%9Ff^8x~2l{(M_pRM1fT!7jYl#d5$0_$WxU%yR|8mA%f z=<+ONs*L7~_1hFc0+u|@z(9csPonvf{Y8HFxSX$$Z32^kW8-qIW1>X$cAUdAFVE{~ z9|}A{#e$*p`4R}B1Gg@hL>Bq=XjDxcXucT{S1~j~@L5f_W+k2tw?(1?iWXP;(n)Dc zZoXoF_YO(5DbN3LNQZFu21*W2Hm=KHFsVRcb!b3Bq@m=c4i<5#HD9wkG_<1S3ER1- zcc|iPG`iY+9`16hMITfM^&f1I1sBTcOem#wiD2ZLwVIO!(C5x-&TY`h8k=v|Y7QjJ zs2~wYoFQ@Gpq%@TohCp?>`xpcc>125ZrJJlzkgt7>H3m!#~ik|{>aYKZAbt86BC$u zAt)8OEZ|Azi^A1)HLfOQLojibMUILri085b2={09%rs8X+b>K~V@)-1SZDLG+nZDi zR1$(Pm?Dm!`kgo6N)m|AqA?tbXEM{~SEe4{PNUtlz8%rfNsqiQl(!{_C*+*XZ~yi{ z7=?B!Rai(VI7Gs;p!I%dTVo^;U|aeJJGFekpUp5};;9_py*sAY1lDw?Mw}hz?78NH z^b!Yedh^+%Z*SwuVRhl=R)sIP-b3vnd+It02RAy^hU{r7CiKsXkrpFy?m`5NObX@X zx#p`Nc)rck7dBozvp`A+(^N*gfM|Ai^WqugJxIj6eXFXSt#&VN?M`mZwn44`1L-&E AVgLXD diff --git a/examples/rust/src/lib.rs b/examples/rust/src/lib.rs index 8f36ef7..c8451be 100644 --- a/examples/rust/src/lib.rs +++ b/examples/rust/src/lib.rs @@ -1,5 +1,5 @@ use { - bindings::wasi::http0_2_0::incoming_handler, + bindings::wasi::http::incoming_handler, futures::SinkExt, spin_sdk::{ http::{Fields, IncomingRequest, Method, OutgoingResponse, ResponseOutparam}, diff --git a/examples/wit/deps/cli-2023-10-18/command.wit b/examples/wit/deps/cli-2023-10-18/command.wit deleted file mode 100644 index d7ea2d9..0000000 --- a/examples/wit/deps/cli-2023-10-18/command.wit +++ /dev/null @@ -1,7 +0,0 @@ -package wasi:cli@0.2.0-rc-2023-10-18; - -world command { - include reactor; - - export run; -} diff --git a/examples/wit/deps/cli-2023-10-18/environment.wit b/examples/wit/deps/cli-2023-10-18/environment.wit deleted file mode 100644 index 7006523..0000000 --- a/examples/wit/deps/cli-2023-10-18/environment.wit +++ /dev/null @@ -1,18 +0,0 @@ -interface environment { - /// Get the POSIX-style environment variables. - /// - /// Each environment variable is provided as a pair of string variable names - /// and string value. - /// - /// Morally, these are a value import, but until value imports are available - /// in the component model, this import function should return the same - /// values each time it is called. - 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/examples/wit/deps/cli-2023-10-18/exit.wit b/examples/wit/deps/cli-2023-10-18/exit.wit deleted file mode 100644 index d0c2b82..0000000 --- a/examples/wit/deps/cli-2023-10-18/exit.wit +++ /dev/null @@ -1,4 +0,0 @@ -interface exit { - /// Exit the current instance and any linked instances. - exit: func(status: result); -} diff --git a/examples/wit/deps/cli-2023-10-18/reactor.wit b/examples/wit/deps/cli-2023-10-18/reactor.wit deleted file mode 100644 index 904b994..0000000 --- a/examples/wit/deps/cli-2023-10-18/reactor.wit +++ /dev/null @@ -1,32 +0,0 @@ -package wasi:cli@0.2.0-rc-2023-10-18; - -world reactor { - import wasi:clocks/wall-clock@0.2.0-rc-2023-10-18; - import wasi:clocks/monotonic-clock@0.2.0-rc-2023-10-18; - import wasi:clocks/timezone@0.2.0-rc-2023-10-18; - import wasi:filesystem/types@0.2.0-rc-2023-10-18; - import wasi:filesystem/preopens@0.2.0-rc-2023-10-18; - import wasi:sockets/instance-network@0.2.0-rc-2023-10-18; - import wasi:sockets/ip-name-lookup@0.2.0-rc-2023-10-18; - import wasi:sockets/network@0.2.0-rc-2023-10-18; - import wasi:sockets/tcp-create-socket@0.2.0-rc-2023-10-18; - import wasi:sockets/tcp@0.2.0-rc-2023-10-18; - import wasi:sockets/udp-create-socket@0.2.0-rc-2023-10-18; - import wasi:sockets/udp@0.2.0-rc-2023-10-18; - import wasi:random/random@0.2.0-rc-2023-10-18; - import wasi:random/insecure@0.2.0-rc-2023-10-18; - import wasi:random/insecure-seed@0.2.0-rc-2023-10-18; - import wasi:io/poll@0.2.0-rc-2023-10-18; - import wasi:io/streams@0.2.0-rc-2023-10-18; - - 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/examples/wit/deps/cli-2023-10-18/run.wit b/examples/wit/deps/cli-2023-10-18/run.wit deleted file mode 100644 index a70ee8c..0000000 --- a/examples/wit/deps/cli-2023-10-18/run.wit +++ /dev/null @@ -1,4 +0,0 @@ -interface run { - /// Run the program. - run: func() -> result; -} diff --git a/examples/wit/deps/cli-2023-10-18/stdio.wit b/examples/wit/deps/cli-2023-10-18/stdio.wit deleted file mode 100644 index 513ca92..0000000 --- a/examples/wit/deps/cli-2023-10-18/stdio.wit +++ /dev/null @@ -1,17 +0,0 @@ -interface stdin { - use wasi:io/streams@0.2.0-rc-2023-10-18.{input-stream}; - - get-stdin: func() -> input-stream; -} - -interface stdout { - use wasi:io/streams@0.2.0-rc-2023-10-18.{output-stream}; - - get-stdout: func() -> output-stream; -} - -interface stderr { - use wasi:io/streams@0.2.0-rc-2023-10-18.{output-stream}; - - get-stderr: func() -> output-stream; -} diff --git a/examples/wit/deps/cli-2023-10-18/terminal.wit b/examples/wit/deps/cli-2023-10-18/terminal.wit deleted file mode 100644 index 4749576..0000000 --- a/examples/wit/deps/cli-2023-10-18/terminal.wit +++ /dev/null @@ -1,47 +0,0 @@ -interface terminal-input { - /// The input side of a terminal. - resource 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-output { - /// The output side of a terminal. - resource 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. -} - -/// 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/examples/wit/deps/cli-2023-11-10/command.wit b/examples/wit/deps/cli-2023-11-10/command.wit deleted file mode 100644 index 74811d3..0000000 --- a/examples/wit/deps/cli-2023-11-10/command.wit +++ /dev/null @@ -1,7 +0,0 @@ -package wasi:cli@0.2.0-rc-2023-11-10; - -world command { - include reactor; - - export run; -} diff --git a/examples/wit/deps/cli-2023-11-10/environment.wit b/examples/wit/deps/cli-2023-11-10/environment.wit deleted file mode 100644 index 7006523..0000000 --- a/examples/wit/deps/cli-2023-11-10/environment.wit +++ /dev/null @@ -1,18 +0,0 @@ -interface environment { - /// Get the POSIX-style environment variables. - /// - /// Each environment variable is provided as a pair of string variable names - /// and string value. - /// - /// Morally, these are a value import, but until value imports are available - /// in the component model, this import function should return the same - /// values each time it is called. - 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/examples/wit/deps/cli-2023-11-10/exit.wit b/examples/wit/deps/cli-2023-11-10/exit.wit deleted file mode 100644 index d0c2b82..0000000 --- a/examples/wit/deps/cli-2023-11-10/exit.wit +++ /dev/null @@ -1,4 +0,0 @@ -interface exit { - /// Exit the current instance and any linked instances. - exit: func(status: result); -} diff --git a/examples/wit/deps/cli-2023-11-10/reactor.wit b/examples/wit/deps/cli-2023-11-10/reactor.wit deleted file mode 100644 index eafa2fd..0000000 --- a/examples/wit/deps/cli-2023-11-10/reactor.wit +++ /dev/null @@ -1,31 +0,0 @@ -package wasi:cli@0.2.0-rc-2023-11-10; - -world reactor { - import wasi:clocks/wall-clock@0.2.0-rc-2023-11-10; - import wasi:clocks/monotonic-clock@0.2.0-rc-2023-11-10; - import wasi:filesystem/types@0.2.0-rc-2023-11-10; - import wasi:filesystem/preopens@0.2.0-rc-2023-11-10; - import wasi:sockets/instance-network@0.2.0-rc-2023-11-10; - import wasi:sockets/ip-name-lookup@0.2.0-rc-2023-11-10; - import wasi:sockets/network@0.2.0-rc-2023-11-10; - import wasi:sockets/tcp-create-socket@0.2.0-rc-2023-11-10; - import wasi:sockets/tcp@0.2.0-rc-2023-11-10; - import wasi:sockets/udp-create-socket@0.2.0-rc-2023-11-10; - import wasi:sockets/udp@0.2.0-rc-2023-11-10; - import wasi:random/random@0.2.0-rc-2023-11-10; - import wasi:random/insecure@0.2.0-rc-2023-11-10; - import wasi:random/insecure-seed@0.2.0-rc-2023-11-10; - import wasi:io/poll@0.2.0-rc-2023-11-10; - import wasi:io/streams@0.2.0-rc-2023-11-10; - - 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/examples/wit/deps/cli-2023-11-10/run.wit b/examples/wit/deps/cli-2023-11-10/run.wit deleted file mode 100644 index a70ee8c..0000000 --- a/examples/wit/deps/cli-2023-11-10/run.wit +++ /dev/null @@ -1,4 +0,0 @@ -interface run { - /// Run the program. - run: func() -> result; -} diff --git a/examples/wit/deps/cli-2023-11-10/stdio.wit b/examples/wit/deps/cli-2023-11-10/stdio.wit deleted file mode 100644 index 1b653b6..0000000 --- a/examples/wit/deps/cli-2023-11-10/stdio.wit +++ /dev/null @@ -1,17 +0,0 @@ -interface stdin { - use wasi:io/streams@0.2.0-rc-2023-11-10.{input-stream}; - - get-stdin: func() -> input-stream; -} - -interface stdout { - use wasi:io/streams@0.2.0-rc-2023-11-10.{output-stream}; - - get-stdout: func() -> output-stream; -} - -interface stderr { - use wasi:io/streams@0.2.0-rc-2023-11-10.{output-stream}; - - get-stderr: func() -> output-stream; -} diff --git a/examples/wit/deps/cli-2023-11-10/terminal.wit b/examples/wit/deps/cli-2023-11-10/terminal.wit deleted file mode 100644 index 4749576..0000000 --- a/examples/wit/deps/cli-2023-11-10/terminal.wit +++ /dev/null @@ -1,47 +0,0 @@ -interface terminal-input { - /// The input side of a terminal. - resource 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-output { - /// The output side of a terminal. - resource 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. -} - -/// 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/examples/wit/deps/clocks-2023-10-18/monotonic-clock.wit b/examples/wit/deps/clocks-2023-10-18/monotonic-clock.wit deleted file mode 100644 index c0ecb52..0000000 --- a/examples/wit/deps/clocks-2023-10-18/monotonic-clock.wit +++ /dev/null @@ -1,32 +0,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-rc-2023-10-18.{pollable}; - - /// A timestamp in nanoseconds. - type instant = 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. - resolution: func() -> instant; - - /// Create a `pollable` which will resolve once the specified time has been - /// reached. - subscribe: func( - when: instant, - absolute: bool - ) -> pollable; -} diff --git a/examples/wit/deps/clocks-2023-10-18/timezone.wit b/examples/wit/deps/clocks-2023-10-18/timezone.wit deleted file mode 100644 index e717e7b..0000000 --- a/examples/wit/deps/clocks-2023-10-18/timezone.wit +++ /dev/null @@ -1,48 +0,0 @@ -interface timezone { - use wall-clock.{datetime}; - - /// Return information needed to display the given `datetime`. This includes - /// the UTC offset, the time zone name, and a flag indicating whether - /// daylight saving time is active. - /// - /// If the timezone cannot be determined for the given `datetime`, return a - /// `timezone-display` for `UTC` with a `utc-offset` of 0 and no daylight - /// saving time. - display: func(when: datetime) -> timezone-display; - - /// The same as `display`, but only return the UTC offset. - utc-offset: func(when: datetime) -> s32; - - /// Information useful for displaying the timezone of a specific `datetime`. - /// - /// This information may vary within a single `timezone` to reflect daylight - /// saving time adjustments. - record timezone-display { - /// The number of seconds difference between UTC time and the local - /// time of the timezone. - /// - /// The returned value will always be less than 86400 which is the - /// number of seconds in a day (24*60*60). - /// - /// In implementations that do not expose an actual time zone, this - /// should return 0. - utc-offset: s32, - - /// The abbreviated name of the timezone to display to a user. The name - /// `UTC` indicates Coordinated Universal Time. Otherwise, this should - /// reference local standards for the name of the time zone. - /// - /// In implementations that do not expose an actual time zone, this - /// should be the string `UTC`. - /// - /// In time zones that do not have an applicable name, a formatted - /// representation of the UTC offset may be returned, such as `-04:00`. - name: string, - - /// Whether daylight saving time is active. - /// - /// In implementations that do not expose an actual time zone, this - /// should return false. - in-daylight-saving-time: bool, - } -} diff --git a/examples/wit/deps/clocks-2023-10-18/wall-clock.wit b/examples/wit/deps/clocks-2023-10-18/wall-clock.wit deleted file mode 100644 index c395649..0000000 --- a/examples/wit/deps/clocks-2023-10-18/wall-clock.wit +++ /dev/null @@ -1,41 +0,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/examples/wit/deps/clocks-2023-10-18/world.wit b/examples/wit/deps/clocks-2023-10-18/world.wit deleted file mode 100644 index cdfb51d..0000000 --- a/examples/wit/deps/clocks-2023-10-18/world.wit +++ /dev/null @@ -1,7 +0,0 @@ -package wasi:clocks@0.2.0-rc-2023-10-18; - -world imports { - import monotonic-clock; - import wall-clock; - import timezone; -} diff --git a/examples/wit/deps/clocks-2023-11-10/monotonic-clock.wit b/examples/wit/deps/clocks-2023-11-10/monotonic-clock.wit deleted file mode 100644 index 09ef32c..0000000 --- a/examples/wit/deps/clocks-2023-11-10/monotonic-clock.wit +++ /dev/null @@ -1,45 +0,0 @@ -package wasi:clocks@0.2.0-rc-2023-11-10; -/// 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-rc-2023-11-10.{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/examples/wit/deps/clocks-2023-11-10/wall-clock.wit b/examples/wit/deps/clocks-2023-11-10/wall-clock.wit deleted file mode 100644 index 8abb9a0..0000000 --- a/examples/wit/deps/clocks-2023-11-10/wall-clock.wit +++ /dev/null @@ -1,42 +0,0 @@ -package wasi:clocks@0.2.0-rc-2023-11-10; -/// 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/examples/wit/deps/clocks-2023-11-10/world.wit b/examples/wit/deps/clocks-2023-11-10/world.wit deleted file mode 100644 index 8fa080f..0000000 --- a/examples/wit/deps/clocks-2023-11-10/world.wit +++ /dev/null @@ -1,6 +0,0 @@ -package wasi:clocks@0.2.0-rc-2023-11-10; - -world imports { - import monotonic-clock; - import wall-clock; -} diff --git a/examples/wit/deps/filesystem-2023-10-18/preopens.wit b/examples/wit/deps/filesystem-2023-10-18/preopens.wit deleted file mode 100644 index 3f787ac..0000000 --- a/examples/wit/deps/filesystem-2023-10-18/preopens.wit +++ /dev/null @@ -1,6 +0,0 @@ -interface preopens { - use types.{descriptor}; - - /// Return the set of preopened directories, and their path. - get-directories: func() -> list>; -} diff --git a/examples/wit/deps/filesystem-2023-10-18/types.wit b/examples/wit/deps/filesystem-2023-10-18/types.wit deleted file mode 100644 index af36135..0000000 --- a/examples/wit/deps/filesystem-2023-10-18/types.wit +++ /dev/null @@ -1,810 +0,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-rc-2023-10-18.{input-stream, output-stream, error}; - use wasi:clocks/wall-clock@0.2.0-rc-2023-10-18.{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, - } - - /// Permissions mode used by `open-at`, `change-file-permissions-at`, and - /// similar. - flags modes { - /// True if the resource is considered readable by the containing - /// filesystem. - readable, - /// True if the resource is considered writable by the containing - /// filesystem. - writable, - /// True if the resource is considered executable by the containing - /// filesystem. This does not apply to directories. - executable, - } - - /// Access type used by `access-at`. - variant access-type { - /// Test for readability, writeability, or executability. - access(modes), - - /// Test whether the path exists. - exists, - } - - /// 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, - /// Permissions to use when creating a new file. - modes: modes - ) -> 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>; - - /// Check accessibility of a filesystem path. - /// - /// Check whether the given filesystem path names an object which is - /// readable, writable, or executable, or whether it exists. - /// - /// This does not a guarantee that subsequent accesses will succeed, as - /// filesystem permissions may be modified asynchronously by external - /// entities. - /// - /// Note: This is similar to `faccessat` with the `AT_EACCESS` flag in POSIX. - access-at: func( - /// Flags determining the method of how the path is resolved. - path-flags: path-flags, - /// The relative path to check. - path: string, - /// The type of check to perform. - %type: access-type - ) -> 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>; - - /// Change the permissions of a filesystem object that is not a directory. - /// - /// Note that the ultimate meanings of these permissions is - /// filesystem-specific. - /// - /// Note: This is similar to `fchmodat` in POSIX. - change-file-permissions-at: func( - /// Flags determining the method of how the path is resolved. - path-flags: path-flags, - /// The relative path to operate on. - path: string, - /// The new permissions for the filesystem object. - modes: modes, - ) -> result<_, error-code>; - - /// Change the permissions of a directory. - /// - /// Note that the ultimate meanings of these permissions is - /// filesystem-specific. - /// - /// Unlike in POSIX, the `executable` flag is not reinterpreted as a "search" - /// flag. `read` on a directory implies readability and searchability, and - /// `execute` is not valid for directories. - /// - /// Note: This is similar to `fchmodat` in POSIX. - change-directory-permissions-at: func( - /// Flags determining the method of how the path is resolved. - path-flags: path-flags, - /// The relative path to operate on. - path: string, - /// The new permissions for the directory. - modes: modes, - ) -> result<_, error-code>; - - /// Request a shared advisory lock for an open file. - /// - /// This requests a *shared* lock; more than one shared lock can be held for - /// a file at the same time. - /// - /// If the open file has an exclusive lock, this function downgrades the lock - /// to a shared lock. If it has a shared lock, this function has no effect. - /// - /// This requests an *advisory* lock, meaning that the file could be accessed - /// by other programs that don't hold the lock. - /// - /// It is unspecified how shared locks interact with locks acquired by - /// non-WASI programs. - /// - /// This function blocks until the lock can be acquired. - /// - /// Not all filesystems support locking; on filesystems which don't support - /// locking, this function returns `error-code::unsupported`. - /// - /// Note: This is similar to `flock(fd, LOCK_SH)` in Unix. - lock-shared: func() -> result<_, error-code>; - - /// Request an exclusive advisory lock for an open file. - /// - /// This requests an *exclusive* lock; no other locks may be held for the - /// file while an exclusive lock is held. - /// - /// If the open file has a shared lock and there are no exclusive locks held - /// for the file, this function upgrades the lock to an exclusive lock. If the - /// open file already has an exclusive lock, this function has no effect. - /// - /// This requests an *advisory* lock, meaning that the file could be accessed - /// by other programs that don't hold the lock. - /// - /// It is unspecified whether this function succeeds if the file descriptor - /// is not opened for writing. It is unspecified how exclusive locks interact - /// with locks acquired by non-WASI programs. - /// - /// This function blocks until the lock can be acquired. - /// - /// Not all filesystems support locking; on filesystems which don't support - /// locking, this function returns `error-code::unsupported`. - /// - /// Note: This is similar to `flock(fd, LOCK_EX)` in Unix. - lock-exclusive: func() -> result<_, error-code>; - - /// Request a shared advisory lock for an open file. - /// - /// This requests a *shared* lock; more than one shared lock can be held for - /// a file at the same time. - /// - /// If the open file has an exclusive lock, this function downgrades the lock - /// to a shared lock. If it has a shared lock, this function has no effect. - /// - /// This requests an *advisory* lock, meaning that the file could be accessed - /// by other programs that don't hold the lock. - /// - /// It is unspecified how shared locks interact with locks acquired by - /// non-WASI programs. - /// - /// This function returns `error-code::would-block` if the lock cannot be - /// acquired. - /// - /// Not all filesystems support locking; on filesystems which don't support - /// locking, this function returns `error-code::unsupported`. - /// - /// Note: This is similar to `flock(fd, LOCK_SH | LOCK_NB)` in Unix. - try-lock-shared: func() -> result<_, error-code>; - - /// Request an exclusive advisory lock for an open file. - /// - /// This requests an *exclusive* lock; no other locks may be held for the - /// file while an exclusive lock is held. - /// - /// If the open file has a shared lock and there are no exclusive locks held - /// for the file, this function upgrades the lock to an exclusive lock. If the - /// open file already has an exclusive lock, this function has no effect. - /// - /// This requests an *advisory* lock, meaning that the file could be accessed - /// by other programs that don't hold the lock. - /// - /// It is unspecified whether this function succeeds if the file descriptor - /// is not opened for writing. It is unspecified how exclusive locks interact - /// with locks acquired by non-WASI programs. - /// - /// This function returns `error-code::would-block` if the lock cannot be - /// acquired. - /// - /// Not all filesystems support locking; on filesystems which don't support - /// locking, this function returns `error-code::unsupported`. - /// - /// Note: This is similar to `flock(fd, LOCK_EX | LOCK_NB)` in Unix. - try-lock-exclusive: func() -> result<_, error-code>; - - /// Release a shared or exclusive lock on an open file. - /// - /// Note: This is similar to `flock(fd, LOCK_UN)` in Unix. - unlock: func() -> 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/examples/wit/deps/filesystem-2023-10-18/world.wit b/examples/wit/deps/filesystem-2023-10-18/world.wit deleted file mode 100644 index 3f953f8..0000000 --- a/examples/wit/deps/filesystem-2023-10-18/world.wit +++ /dev/null @@ -1,6 +0,0 @@ -package wasi:filesystem@0.2.0-rc-2023-10-18; - -world imports { - import types; - import preopens; -} diff --git a/examples/wit/deps/filesystem-2023-11-10/preopens.wit b/examples/wit/deps/filesystem-2023-11-10/preopens.wit deleted file mode 100644 index 95ec678..0000000 --- a/examples/wit/deps/filesystem-2023-11-10/preopens.wit +++ /dev/null @@ -1,8 +0,0 @@ -package wasi:filesystem@0.2.0-rc-2023-11-10; - -interface preopens { - use types.{descriptor}; - - /// Return the set of preopened directories, and their path. - get-directories: func() -> list>; -} diff --git a/examples/wit/deps/filesystem-2023-11-10/types.wit b/examples/wit/deps/filesystem-2023-11-10/types.wit deleted file mode 100644 index 059722a..0000000 --- a/examples/wit/deps/filesystem-2023-11-10/types.wit +++ /dev/null @@ -1,634 +0,0 @@ -package wasi:filesystem@0.2.0-rc-2023-11-10; -/// 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-rc-2023-11-10.{input-stream, output-stream, error}; - use wasi:clocks/wall-clock@0.2.0-rc-2023-11-10.{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/examples/wit/deps/filesystem-2023-11-10/world.wit b/examples/wit/deps/filesystem-2023-11-10/world.wit deleted file mode 100644 index 285e0ba..0000000 --- a/examples/wit/deps/filesystem-2023-11-10/world.wit +++ /dev/null @@ -1,6 +0,0 @@ -package wasi:filesystem@0.2.0-rc-2023-11-10; - -world imports { - import types; - import preopens; -} diff --git a/examples/wit/deps/http-2023-10-18/incoming-handler.wit b/examples/wit/deps/http-2023-10-18/incoming-handler.wit deleted file mode 100644 index 6968d63..0000000 --- a/examples/wit/deps/http-2023-10-18/incoming-handler.wit +++ /dev/null @@ -1,24 +0,0 @@ -// The `wasi:http/incoming-handler` interface is meant to be exported by -// components and called by the host in response to a new incoming HTTP -// response. -// -// NOTE: in Preview3, this interface will be merged with -// `wasi:http/outgoing-handler` into a single `wasi:http/handler` interface -// that takes a `request` parameter and returns a `response` result. -// -interface incoming-handler { - use types.{incoming-request, response-outparam}; - - // The `handle` function takes an outparam instead of returning its response - // so that the component may stream its response while streaming any other - // request or response bodies. The callee MUST write a response to the - // `response-outparam` and then finish the response before returning. The `handle` - // function is allowed to continue execution after finishing the response's - // output stream. While this post-response execution is taken off the - // critical path, since there is no return value, there is no way to report - // its success or failure. - handle: func( - request: incoming-request, - response-out: response-outparam - ); -} diff --git a/examples/wit/deps/http-2023-10-18/outgoing-handler.wit b/examples/wit/deps/http-2023-10-18/outgoing-handler.wit deleted file mode 100644 index 286e283..0000000 --- a/examples/wit/deps/http-2023-10-18/outgoing-handler.wit +++ /dev/null @@ -1,20 +0,0 @@ -// The `wasi:http/outgoing-handler` interface is meant to be imported by -// components and implemented by the host. -// -// NOTE: in Preview3, this interface will be merged with -// `wasi:http/outgoing-handler` into a single `wasi:http/handler` interface -// that takes a `request` parameter and returns a `response` result. -// -interface outgoing-handler { - use types.{outgoing-request, request-options, future-incoming-response, error}; - - // The parameter and result types of the `handle` function allow the caller - // to concurrently stream the bodies of the outgoing request and the incoming - // response. - // Consumes the outgoing-request. Gives an error if the outgoing-request - // is invalid or cannot be satisfied by this handler. - handle: func( - request: outgoing-request, - options: option - ) -> result; -} diff --git a/examples/wit/deps/http-2023-10-18/proxy.wit b/examples/wit/deps/http-2023-10-18/proxy.wit deleted file mode 100644 index dde0659..0000000 --- a/examples/wit/deps/http-2023-10-18/proxy.wit +++ /dev/null @@ -1,34 +0,0 @@ -package wasi:http@0.2.0-rc-2023-10-18; - -// 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. - import wasi:clocks/wall-clock@0.2.0-rc-2023-10-18; - import wasi:clocks/monotonic-clock@0.2.0-rc-2023-10-18; - import wasi:clocks/timezone@0.2.0-rc-2023-10-18; - import wasi:random/random@0.2.0-rc-2023-10-18; - - // 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-rc-2023-10-18; - import wasi:cli/stderr@0.2.0-rc-2023-10-18; - - // 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-rc-2023-10-18; - - // 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/examples/wit/deps/http-2023-10-18/types.wit b/examples/wit/deps/http-2023-10-18/types.wit deleted file mode 100644 index 2471f04..0000000 --- a/examples/wit/deps/http-2023-10-18/types.wit +++ /dev/null @@ -1,208 +0,0 @@ -/// The `wasi:http/types` interface is meant to be imported by components to -/// define the HTTP resource types and operations used by the component's -/// imported and exported interfaces. -interface types { - use wasi:io/streams@0.2.0-rc-2023-10-18.{input-stream, output-stream}; - use wasi:io/poll@0.2.0-rc-2023-10-18.{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) - } - - // TODO: perhaps better align with HTTP semantics? - /// This type enumerates the different kinds of errors that may occur when - /// initially returning a response. - variant error { - invalid-url(string), - timeout-error(string), - protocol-error(string), - unexpected-error(string) - } - - /// This following block defines the `fields` resource which corresponds to - /// HTTP standard Fields. - resource fields { - // Multiple values for a header are multiple entries in the list with the - // same key. - constructor(entries: list>>); - - // Values off wire are not necessarily well formed, so they are given by - // list instead of string. - get: func(name: string) -> list>; - - // Values off wire are not necessarily well formed, so they are given by - // list instead of string. - set: func(name: string, value: list>); - delete: func(name: string); - append: func(name: string, value: list); - - // Values off wire are not necessarily well formed, so they are given by - // list instead of string. - entries: func() -> list>>; - - // Deep copy of all contents in a fields. - clone: func() -> fields; - } - - type headers = fields; - type trailers = fields; - - /// The following block defines the `incoming-request` and `outgoing-request` - /// resource types that correspond to HTTP standard Requests. - /// - /// The `consume` and `write` methods may only be called once (and - /// return failure thereafter). - resource incoming-request { - method: func() -> method; - - path-with-query: func() -> option; - - scheme: func() -> option; - - authority: func() -> option; - - headers: func() -> /* child */ headers; - - /// Returns the input-stream child at most once. - /// - /// If called more than once, subsequent calls return an error. - consume: func() -> result; - } - - resource outgoing-request { - constructor( - method: method, - path-with-query: option, - scheme: option, - authority: option, - headers: borrow - ); - - /// Will return the outgoing-body child at most once. - /// - /// If called more than once, subsequent calls return an error. - write: func() -> result< /* child */ outgoing-body>; - } - - /// Additional optional parameters that can be set when making a request. - record request-options { - // The following timeouts are specific to the HTTP protocol and work - // independently of the overall timeouts passed to `io.poll.poll-list`. - - /// The timeout for the initial connect. - connect-timeout-ms: option, - - /// The timeout for receiving the first byte of the response body. - first-byte-timeout-ms: option, - - /// The timeout for receiving the next chunk of bytes in the response body - /// stream. - between-bytes-timeout-ms: option - } - - /// The following block defines a special resource type used by the - /// `wasi:http/incoming-handler` interface. When resource types are added, this - /// block can be replaced by a proper `resource response-outparam { ... }` - /// definition. Later, with Preview3, the need for an outparam goes away entirely - /// (the `wasi:http/handler` interface used for both incoming and outgoing can - /// simply return a `stream`). - resource response-outparam { - set: static func(param: response-outparam, response: result); - } - - // This type corresponds to the HTTP standard Status Code. - type status-code = u16; - - /// The following block defines the `incoming-response` and `outgoing-response` - /// resource types that correspond to HTTP standard Responses. - /// - /// The `consume` and `write` methods may only be called once (and return failure thereafter). - resource incoming-response { - status: func() -> status-code; - - headers: func() -> /* child */ headers; - - // May be called at most once. returns error if called additional times. - // TODO: make incoming-request-consume work the same way, giving a child - // incoming-body. - consume: func() -> result; - } - - resource incoming-body { - // returned input-stream is a child - the implementation may trap if - // incoming-body is dropped (or consumed by call to - // incoming-body-finish) before the input-stream is dropped. - // May be called at most once. returns error if called additional times. - %stream: func() -> result; - - // takes ownership of incoming-body. this will trap if the - // incoming-body-stream child is still alive! - finish: static func(this: incoming-body) -> - /* transitive child of the incoming-response of incoming-body */ future-trailers; - } - - resource future-trailers { - /// Pollable that resolves when the body has been fully read, and the trailers - /// are ready to be consumed. - subscribe: func() -> /* child */ pollable; - - /// Retrieve reference to trailers, if they are ready. - get: func() -> option>; - } - - resource outgoing-response { - constructor(status-code: status-code, headers: borrow); - - /// Will give the child outgoing-response at most once. subsequent calls will - /// return an error. - write: func() -> result; - } - - resource outgoing-body { - /// Will give the child output-stream at most once. subsequent calls will - /// return an 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. - finish: static func(this: outgoing-body, trailers: option); - } - - /// The following block defines a special resource type used by the - /// `wasi:http/outgoing-handler` interface to emulate - /// `future>` in advance of Preview3. Given a - /// `future-incoming-response`, the client can call the non-blocking `get` - /// method to get the result if it is available. If the result is not available, - /// the client can call `listen` to get a `pollable` that can be passed to - /// `wasi:io/poll.poll-list`. - resource future-incoming-response { - /// option indicates readiness. - /// outer result indicates you are allowed to get the - /// incoming-response-or-error at most once. subsequent calls after ready - /// will return an error here. - /// inner result indicates whether the incoming-response was available, or an - /// error occured. - get: func() -> option>>; - - subscribe: func() -> /* child */ pollable; - } -} diff --git a/examples/wit/deps/http-2023-11-10/handler.wit b/examples/wit/deps/http-2023-11-10/handler.wit deleted file mode 100644 index a34a064..0000000 --- a/examples/wit/deps/http-2023-11-10/handler.wit +++ /dev/null @@ -1,43 +0,0 @@ -/// 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/examples/wit/deps/http-2023-11-10/proxy.wit b/examples/wit/deps/http-2023-11-10/proxy.wit deleted file mode 100644 index 453f590..0000000 --- a/examples/wit/deps/http-2023-11-10/proxy.wit +++ /dev/null @@ -1,33 +0,0 @@ -package wasi:http@0.2.0-rc-2023-11-10; - -/// 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. - import wasi:clocks/wall-clock@0.2.0-rc-2023-11-10; - import wasi:clocks/monotonic-clock@0.2.0-rc-2023-11-10; - import wasi:random/random@0.2.0-rc-2023-11-10; - - /// 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-rc-2023-11-10; - import wasi:cli/stderr@0.2.0-rc-2023-11-10; - - /// 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-rc-2023-11-10; - - /// 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/examples/wit/deps/http-2023-11-10/types.wit b/examples/wit/deps/http-2023-11-10/types.wit deleted file mode 100644 index 1dd4214..0000000 --- a/examples/wit/deps/http-2023-11-10/types.wit +++ /dev/null @@ -1,559 +0,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. -interface types { - use wasi:clocks/monotonic-clock@0.2.0-rc-2023-11-10.{duration}; - use wasi:io/streams@0.2.0-rc-2023-11-10.{input-stream, output-stream}; - use wasi:io/error@0.2.0-rc-2023-11-10.{error as io-error}; - use wasi:io/poll@0.2.0-rc-2023-11-10.{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. - get: func(name: field-key) -> list; - - /// 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 an - /// optional timeout, with the unit in milliseconds, 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-ms: 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-ms: func(ms: option) -> result; - - /// The timeout for receiving the first byte of the Response body. - first-byte-timeout-ms: 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-ms: func(ms: option) -> result; - - /// The timeout for receiving subsequent chunks of bytes in the Response - /// body stream. - between-bytes-timeout-ms: 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-ms: func(ms: 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 `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/examples/wit/deps/io-2023-10-18/poll.wit b/examples/wit/deps/io-2023-10-18/poll.wit deleted file mode 100644 index 74835e6..0000000 --- a/examples/wit/deps/io-2023-10-18/poll.wit +++ /dev/null @@ -1,32 +0,0 @@ -/// A poll API intended to let users wait for I/O events on multiple handles -/// at once. -interface poll { - /// A "pollable" handle. - resource pollable; - - /// 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-list: func(in: list>) -> list; - - /// Poll for completion on a single pollable. - /// - /// This function is similar to `poll-list`, but operates on only a single - /// pollable. When it returns, the handle is ready for I/O. - poll-one: func(in: borrow); -} diff --git a/examples/wit/deps/io-2023-10-18/streams.wit b/examples/wit/deps/io-2023-10-18/streams.wit deleted file mode 100644 index c9600b7..0000000 --- a/examples/wit/deps/io-2023-10-18/streams.wit +++ /dev/null @@ -1,287 +0,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 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 - } - - /// Contextual error information about the last failure that happened on - /// a read, write, or flush from an `input-stream` or `output-stream`. - /// - /// This type is returned through the `stream-error` type whenever an - /// operation on a stream directly fails or an error is discovered - /// after-the-fact, for example when a write's failure shows up through a - /// later `flush` or `check-write`. - /// - /// Interfaces such as `wasi:filesystem/types` provide functionality to - /// further "downcast" this error into interface-specific error information. - resource error { - /// Returns a string that's suitable to assist humans in debugging this - /// error. - /// - /// The returned string will change across platforms and hosts which - /// means that parsing it, for example, would be a - /// platform-compatibility hazard. - to-debug-string: func() -> string; - } - - /// 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. - /// - /// This function returns a list of bytes containing the data that was - /// read, along with a `stream-status` which, indicates whether further - /// reads are expected to produce data. The returned list will contain up to - /// `len` bytes; it may return fewer than requested, but not more. An - /// empty list and `stream-status:open` indicates no more data is - /// available at this time, and that the pollable given by `subscribe` - /// will be ready when more data is available. - /// - /// Once a stream has reached the end, subsequent calls to `read` or - /// `skip` will always report `stream-status:ended` rather than producing more - /// data. - /// - /// When the caller gives a `len` of 0, it represents a request to read 0 - /// bytes. This read should always succeed and return an empty list and - /// the current `stream-status`. - /// - /// 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, identical to `read`. - blocking-read: func( - /// The maximum number of bytes to read - len: u64 - ) -> result, stream-error>; - - /// Skip bytes from a stream. - /// - /// This is similar to the `read` function, but avoids copying the - /// bytes into the instance. - /// - /// Once a stream has reached the end, subsequent calls to read or - /// `skip` will always report end-of-stream rather than producing more - /// data. - /// - /// This function returns the number of bytes skipped, along with a - /// `stream-status` indicating whether the end of the stream was - /// reached. The returned value will be at most `len`; it may be less. - 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. - /// - /// 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 - /// poll-one(pollable); - /// 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` - /// poll-one(pollable); - /// // 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 - /// poll-one(pollable); - /// 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` - /// poll-one(pollable); - /// // 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. - /// - /// This function returns the number of bytes transferred; it may be less - /// than `len`. - /// - /// Unlike other I/O functions, this function blocks until all the data - /// read from the input stream has been written to the output stream. - splice: func( - /// The stream to read from - src: input-stream, - /// 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 at least - /// one byte can be read. - blocking-splice: func( - /// The stream to read from - src: input-stream, - /// The number of bytes to splice - len: u64, - ) -> result; - - /// Forward the entire contents of an input stream to an output stream. - /// - /// This function repeatedly reads from the input stream and writes - /// the data to the output stream, until the end of the input stream - /// is reached, or an error is encountered. - /// - /// Unlike other I/O functions, this function blocks until the end - /// of the input stream is seen and all the data has been written to - /// the output stream. - /// - /// This function returns the number of bytes transferred, and the status of - /// the output stream. - forward: func( - /// The stream to read from - src: input-stream - ) -> result; - } -} diff --git a/examples/wit/deps/io-2023-10-18/world.wit b/examples/wit/deps/io-2023-10-18/world.wit deleted file mode 100644 index a0bcd31..0000000 --- a/examples/wit/deps/io-2023-10-18/world.wit +++ /dev/null @@ -1 +0,0 @@ -package wasi:io@0.2.0-rc-2023-10-18; diff --git a/examples/wit/deps/io-2023-11-10/error.wit b/examples/wit/deps/io-2023-11-10/error.wit deleted file mode 100644 index 31918ac..0000000 --- a/examples/wit/deps/io-2023-11-10/error.wit +++ /dev/null @@ -1,34 +0,0 @@ -package wasi:io@0.2.0-rc-2023-11-10; - - -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/examples/wit/deps/io-2023-11-10/poll.wit b/examples/wit/deps/io-2023-11-10/poll.wit deleted file mode 100644 index bddde3c..0000000 --- a/examples/wit/deps/io-2023-11-10/poll.wit +++ /dev/null @@ -1,41 +0,0 @@ -package wasi:io@0.2.0-rc-2023-11-10; - -/// A poll API intended to let users wait for I/O events on multiple handles -/// at once. -interface poll { - /// `pollable` epresents 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/examples/wit/deps/io-2023-11-10/streams.wit b/examples/wit/deps/io-2023-11-10/streams.wit deleted file mode 100644 index e7e1b68..0000000 --- a/examples/wit/deps/io-2023-11-10/streams.wit +++ /dev/null @@ -1,251 +0,0 @@ -package wasi:io@0.2.0-rc-2023-11-10; - -/// 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. - /// - /// 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. - /// - /// 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 - /// poll-one(pollable); - /// 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` - /// poll-one(pollable); - /// // 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 - /// poll-one(pollable); - /// 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` - /// poll-one(pollable); - /// // 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/examples/wit/deps/io-2023-11-10/world.wit b/examples/wit/deps/io-2023-11-10/world.wit deleted file mode 100644 index 8243da2..0000000 --- a/examples/wit/deps/io-2023-11-10/world.wit +++ /dev/null @@ -1,6 +0,0 @@ -package wasi:io@0.2.0-rc-2023-11-10; - -world imports { - import streams; - import poll; -} diff --git a/examples/wit/deps/random-2023-10-18/insecure-seed.wit b/examples/wit/deps/random-2023-10-18/insecure-seed.wit deleted file mode 100644 index 139aed1..0000000 --- a/examples/wit/deps/random-2023-10-18/insecure-seed.wit +++ /dev/null @@ -1,24 +0,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/examples/wit/deps/random-2023-10-18/insecure.wit b/examples/wit/deps/random-2023-10-18/insecure.wit deleted file mode 100644 index 2ffd223..0000000 --- a/examples/wit/deps/random-2023-10-18/insecure.wit +++ /dev/null @@ -1,21 +0,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/examples/wit/deps/random-2023-10-18/random.wit b/examples/wit/deps/random-2023-10-18/random.wit deleted file mode 100644 index 2c3c6a8..0000000 --- a/examples/wit/deps/random-2023-10-18/random.wit +++ /dev/null @@ -1,25 +0,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/examples/wit/deps/random-2023-10-18/world.wit b/examples/wit/deps/random-2023-10-18/world.wit deleted file mode 100644 index dcbff93..0000000 --- a/examples/wit/deps/random-2023-10-18/world.wit +++ /dev/null @@ -1,7 +0,0 @@ -package wasi:random@0.2.0-rc-2023-10-18; - -world imports { - import random; - import insecure; - import insecure-seed; -} diff --git a/examples/wit/deps/random-2023-11-10/insecure-seed.wit b/examples/wit/deps/random-2023-11-10/insecure-seed.wit deleted file mode 100644 index f76e87d..0000000 --- a/examples/wit/deps/random-2023-11-10/insecure-seed.wit +++ /dev/null @@ -1,25 +0,0 @@ -package wasi:random@0.2.0-rc-2023-11-10; -/// 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/examples/wit/deps/random-2023-11-10/insecure.wit b/examples/wit/deps/random-2023-11-10/insecure.wit deleted file mode 100644 index ec7b997..0000000 --- a/examples/wit/deps/random-2023-11-10/insecure.wit +++ /dev/null @@ -1,22 +0,0 @@ -package wasi:random@0.2.0-rc-2023-11-10; -/// 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/examples/wit/deps/random-2023-11-10/random.wit b/examples/wit/deps/random-2023-11-10/random.wit deleted file mode 100644 index 7a7dfa2..0000000 --- a/examples/wit/deps/random-2023-11-10/random.wit +++ /dev/null @@ -1,26 +0,0 @@ -package wasi:random@0.2.0-rc-2023-11-10; -/// 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/examples/wit/deps/random-2023-11-10/world.wit b/examples/wit/deps/random-2023-11-10/world.wit deleted file mode 100644 index 49e5743..0000000 --- a/examples/wit/deps/random-2023-11-10/world.wit +++ /dev/null @@ -1,7 +0,0 @@ -package wasi:random@0.2.0-rc-2023-11-10; - -world imports { - import random; - import insecure; - import insecure-seed; -} diff --git a/examples/wit/deps/sockets-2023-10-18/instance-network.wit b/examples/wit/deps/sockets-2023-10-18/instance-network.wit deleted file mode 100644 index 14e4479..0000000 --- a/examples/wit/deps/sockets-2023-10-18/instance-network.wit +++ /dev/null @@ -1,9 +0,0 @@ - -/// 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/examples/wit/deps/sockets-2023-10-18/ip-name-lookup.wit b/examples/wit/deps/sockets-2023-10-18/ip-name-lookup.wit deleted file mode 100644 index f2dab32..0000000 --- a/examples/wit/deps/sockets-2023-10-18/ip-name-lookup.wit +++ /dev/null @@ -1,61 +0,0 @@ - -interface ip-name-lookup { - use wasi:io/poll@0.2.0-rc-2023-10-18.{pollable}; - use network.{network, error-code, ip-address, ip-address-family}; - - - /// Resolve an internet host name to a list of IP addresses. - /// - /// See the wasi-socket proposal README.md for a comparison with getaddrinfo. - /// - /// # Parameters - /// - `name`: The name to look up. IP addresses are not allowed. Unicode domain names are automatically converted - /// to ASCII using IDNA encoding. - /// - `address-family`: If provided, limit the results to addresses of this specific address family. - /// - `include-unavailable`: When set to true, this function will also return addresses of which the runtime - /// thinks (or knows) can't be connected to at the moment. For example, this will return IPv6 addresses on - /// systems without an active IPv6 interface. Notes: - /// - Even when no public IPv6 interfaces are present or active, names like "localhost" can still resolve to an IPv6 address. - /// - Whatever is "available" or "unavailable" is volatile and can change everytime a network cable is unplugged. - /// - /// 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. - /// - /// At the moment, the stream never completes successfully with 0 items. Ie. the first call - /// to `resolve-next-address` never returns `ok(none)`. This may change in the future. - /// - /// # Typical errors - /// - `invalid-argument`: `name` is a syntactically invalid domain name. - /// - `invalid-argument`: `name` is an IP address. - /// - `not-supported`: The specified `address-family` is not supported. (EAI_FAMILY) - /// - /// # References: - /// - - /// - - /// - - /// - - resolve-addresses: func(network: borrow, name: string, address-family: option, include-unavailable: bool) -> 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/examples/wit/deps/sockets-2023-10-18/network.wit b/examples/wit/deps/sockets-2023-10-18/network.wit deleted file mode 100644 index fc51604..0000000 --- a/examples/wit/deps/sockets-2023-10-18/network.wit +++ /dev/null @@ -1,146 +0,0 @@ - -interface network { - /// An opaque resource that represents access to (a subset of) the network. - /// This enables context-based security for networking. - /// There is no need for this to map 1:1 to a physical network interface. - 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 { - // ### GENERAL ERRORS ### - - /// 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, - - - - // ### TCP & UDP SOCKET ERRORS ### - - /// 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, - - - // ### TCP SOCKET ERRORS ### - - /// The connection was forcefully rejected - connection-refused, - - /// The connection was reset. - connection-reset, - - /// A connection was aborted. - connection-aborted, - - // ### UDP SOCKET ERRORS ### - datagram-too-large, - - - // ### NAME LOOKUP ERRORS ### - - /// 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 { - port: u16, // sin_port - address: ipv4-address, // sin_addr - } - - record ipv6-socket-address { - port: u16, // sin6_port - flow-info: u32, // sin6_flowinfo - address: ipv6-address, // sin6_addr - scope-id: u32, // sin6_scope_id - } - - variant ip-socket-address { - ipv4(ipv4-socket-address), - ipv6(ipv6-socket-address), - } - -} diff --git a/examples/wit/deps/sockets-2023-10-18/tcp-create-socket.wit b/examples/wit/deps/sockets-2023-10-18/tcp-create-socket.wit deleted file mode 100644 index a9a3373..0000000 --- a/examples/wit/deps/sockets-2023-10-18/tcp-create-socket.wit +++ /dev/null @@ -1,26 +0,0 @@ - -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. - /// - /// 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`/`listen`/`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/examples/wit/deps/sockets-2023-10-18/tcp.wit b/examples/wit/deps/sockets-2023-10-18/tcp.wit deleted file mode 100644 index 448f629..0000000 --- a/examples/wit/deps/sockets-2023-10-18/tcp.wit +++ /dev/null @@ -1,268 +0,0 @@ - -interface tcp { - use wasi:io/streams@0.2.0-rc-2023-10-18.{input-stream, output-stream}; - use wasi:io/poll@0.2.0-rc-2023-10-18.{pollable}; - 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 handle. - 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. - /// - /// When a socket is not explicitly bound, the first invocation to a listen or connect operation will - /// implicitly bind the socket. - /// - /// Unlike in POSIX, this function is async. This enables interactive WASI hosts to inject permission prompts. - /// - /// # Typical `start` 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, but the socket has `ipv6-only` enabled. (EINVAL) - /// - `invalid-state`: The socket is already bound. (EINVAL) - /// - /// # Typical `finish` errors - /// - `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) - /// - /// # 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 - /// - /// POSIX mentions: - /// > If connect() fails, the state of the socket is unspecified. Conforming applications should - /// > close the file descriptor and create a new socket before attempting to reconnect. - /// - /// WASI prescribes the following behavior: - /// - If `connect` fails because an input/state validation error, the socket should remain usable. - /// - If a connection was actually attempted but failed, the socket should become unusable for further network communication. - /// Besides `drop`, any method after such a failure may return an error. - /// - /// # Typical `start` 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, but the socket has `ipv6-only` enabled. (EINVAL, EADDRNOTAVAIL on Illumos) - /// - `invalid-argument`: `remote-address` is a non-IPv4-mapped IPv6 address, but the socket was bound to a specific IPv4-mapped IPv6 address. (or vice versa) - /// - `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 Connection state. (EISCONN) - /// - `invalid-state`: The socket is already in the Listener state. (EOPNOTSUPP, EINVAL on Windows) - /// - /// # Typical `finish` errors - /// - `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) - /// - `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) - /// - /// # 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 Listener state. - /// - /// Unlike POSIX: - /// - this function is async. This enables interactive WASI hosts to inject permission prompts. - /// - the socket must already be explicitly bound. - /// - /// # Typical `start` errors - /// - `invalid-state`: The socket is not bound to any local address. (EDESTADDRREQ) - /// - `invalid-state`: The socket is already in the Connection state. (EISCONN, EINVAL on BSD) - /// - `invalid-state`: The socket is already in the Listener state. - /// - /// # Typical `finish` errors - /// - `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) - /// - /// # 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 Connection state. The following properties are inherited from the listener socket: - /// - `address-family` - /// - `ipv6-only` - /// - `keep-alive` - /// - `no-delay` - /// - `unicast-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 Listener 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 this is a IPv4 or IPv6 socket. - /// - /// Equivalent to the SO_DOMAIN socket option. - address-family: func() -> ip-address-family; - - /// Whether IPv4 compatibility (dual-stack) mode is disabled or not. - /// - /// Equivalent to the IPV6_V6ONLY socket option. - /// - /// # Typical errors - /// - `invalid-state`: (set) The socket is already bound. - /// - `not-supported`: (get/set) `this` socket is an IPv4 socket. - /// - `not-supported`: (set) Host does not support dual-stack sockets. (Implementations are not required to.) - ipv6-only: func() -> result; - set-ipv6-only: func(value: bool) -> result<_, error-code>; - - /// Hints the desired listen queue size. Implementations are free to ignore this. - /// - /// # Typical errors - /// - `not-supported`: (set) The platform does not support changing the backlog size after the initial listen. - /// - `invalid-state`: (set) The socket is already in the Connection state. - set-listen-backlog-size: func(value: u64) -> result<_, error-code>; - - /// Equivalent to the SO_KEEPALIVE socket option. - keep-alive: func() -> result; - set-keep-alive: func(value: bool) -> result<_, error-code>; - - /// Equivalent to the TCP_NODELAY socket option. - /// - /// The default value is `false`. - no-delay: func() -> result; - set-no-delay: func(value: bool) -> result<_, error-code>; - - /// Equivalent to the IP_TTL & IPV6_UNICAST_HOPS socket options. - /// - /// # Typical errors - /// - `invalid-argument`: (set) The TTL value must be 1 or higher. - /// - `invalid-state`: (set) The socket is already in the Connection state. - /// - `invalid-state`: (set) The socket is already in the Listener state. - 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. - /// - /// Note #1: an implementation may choose to cap or round the buffer size when setting the value. - /// In other words, after setting a value, reading the same setting back may return a different value. - /// - /// Note #2: there is not necessarily a direct relationship between the kernel buffer size and the bytes of - /// actual data to be sent/received by the application, because the kernel might also use the buffer space - /// for internal metadata structures. - /// - /// Equivalent to the SO_RCVBUF and SO_SNDBUF socket options. - /// - /// # Typical errors - /// - `invalid-state`: (set) The socket is already in the Connection state. - /// - `invalid-state`: (set) The socket is already in the Listener state. - 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; - - /// Initiate a graceful shutdown. - /// - /// - receive: the socket is not expecting to receive any more data from the peer. All subsequent read - /// operations on the `input-stream` associated with this socket will return an End Of Stream indication. - /// Any data still in the receive queue at time of calling `shutdown` will be discarded. - /// - send: the socket is not expecting to send any more data to the peer. All subsequent write - /// operations on the `output-stream` associated with this socket will return an error. - /// - both: same effect as receive & send combined. - /// - /// The shutdown function does not close (drop) the socket. - /// - /// # Typical errors - /// - `invalid-state`: The socket is not in the Connection state. (ENOTCONN) - /// - /// # References - /// - - /// - - /// - - /// - - shutdown: func(shutdown-type: shutdown-type) -> result<_, error-code>; - } -} diff --git a/examples/wit/deps/sockets-2023-10-18/udp-create-socket.wit b/examples/wit/deps/sockets-2023-10-18/udp-create-socket.wit deleted file mode 100644 index e026359..0000000 --- a/examples/wit/deps/sockets-2023-10-18/udp-create-socket.wit +++ /dev/null @@ -1,26 +0,0 @@ - -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. - /// - /// 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-udp-socket: func(address-family: ip-address-family) -> result; -} diff --git a/examples/wit/deps/sockets-2023-10-18/udp.wit b/examples/wit/deps/sockets-2023-10-18/udp.wit deleted file mode 100644 index 91a8c6c..0000000 --- a/examples/wit/deps/sockets-2023-10-18/udp.wit +++ /dev/null @@ -1,213 +0,0 @@ - -interface udp { - use wasi:io/poll@0.2.0-rc-2023-10-18.{pollable}; - use network.{network, error-code, ip-socket-address, ip-address-family}; - - - record datagram { - data: list, // Theoretical max size: ~64 KiB. In practice, typically less than 1500 bytes. - remote-address: ip-socket-address, - - /// Possible future additions: - /// local-address: ip-socket-address, // IP_PKTINFO / IP_RECVDSTADDR / IPV6_PKTINFO - /// local-interface: u32, // IP_PKTINFO / IP_RECVIF - /// ttl: u8, // IP_RECVTTL - /// dscp: u6, // IP_RECVTOS - /// ecn: u2, // IP_RECVTOS - } - - - - /// 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 TCP/UDP port is zero, the socket will be bound to a random free port. - /// - /// When a socket is not explicitly bound, the first invocation to connect will implicitly bind the socket. - /// - /// Unlike in POSIX, this function is async. This enables interactive WASI hosts to inject permission prompts. - /// - /// # Typical `start` errors - /// - `invalid-argument`: The `local-address` has the wrong address family. (EAFNOSUPPORT, EFAULT on Windows) - /// - `invalid-state`: The socket is already bound. (EINVAL) - /// - /// # Typical `finish` errors - /// - `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) - /// - /// # References - /// - - /// - - /// - - /// - - start-bind: func(network: borrow, local-address: ip-socket-address) -> result<_, error-code>; - finish-bind: func() -> result<_, error-code>; - - /// Set the destination address. - /// - /// The local-address is updated based on the best network path to `remote-address`. - /// - /// When a destination address is set: - /// - all receive operations will only return datagrams sent from the provided `remote-address`. - /// - the `send` function can only be used to send to this destination. - /// - /// Note that this function does not generate any network traffic and the peer is not aware of this "connection". - /// - /// Unlike in POSIX, this function is async. This enables interactive WASI hosts to inject permission prompts. - /// - /// # Typical `start` errors - /// - `invalid-argument`: The `remote-address` has the wrong address family. (EAFNOSUPPORT) - /// - `invalid-argument`: `remote-address` is a non-IPv4-mapped IPv6 address, but the socket was bound to a specific IPv4-mapped IPv6 address. (or vice versa) - /// - `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 already bound to a different network. The `network` passed to `connect` must be identical to the one passed to `bind`. - /// - /// # Typical `finish` errors - /// - `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) - /// - /// # References - /// - - /// - - /// - - /// - - start-connect: func(network: borrow, remote-address: ip-socket-address) -> result<_, error-code>; - finish-connect: func() -> result<_, error-code>; - - /// 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. - /// If `max-results` is 0, this function returns successfully with an empty list. - /// - /// # Typical errors - /// - `invalid-state`: The socket is not bound to any local address. (EINVAL) - /// - `remote-unreachable`: The remote address is not reachable. (ECONNREFUSED, ECONNRESET, ENETRESET on Windows, EHOSTUNREACH, EHOSTDOWN, ENETUNREACH, ENETDOWN) - /// - `would-block`: There is no pending data available to be read at the moment. (EWOULDBLOCK, EAGAIN) - /// - /// # References - /// - - /// - - /// - - /// - - /// - - /// - - /// - - /// - - receive: func(max-results: u64) -> result, error-code>; - - /// 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 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)`. - /// - /// The remote address option is required. To send a message to the "connected" peer, - /// call `remote-address` to get their address. - /// - /// # Typical errors - /// - `invalid-argument`: The `remote-address` has the wrong address family. (EAFNOSUPPORT) - /// - `invalid-argument`: `remote-address` is a non-IPv4-mapped IPv6 address, but the socket was bound to a specific IPv4-mapped IPv6 address. (or vice versa) - /// - `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 the `datagram.remote-address` does not match the address passed to `connect`. (EISCONN) - /// - `invalid-state`: The socket is not bound to any local address. Unlike POSIX, this function does not perform an implicit bind. - /// - `remote-unreachable`: The remote address is not reachable. (ECONNREFUSED, ECONNRESET, ENETRESET on Windows, EHOSTUNREACH, EHOSTDOWN, ENETUNREACH, ENETDOWN) - /// - `datagram-too-large`: The datagram is too large. (EMSGSIZE) - /// - `would-block`: The send buffer is currently full. (EWOULDBLOCK, EAGAIN) - /// - /// # References - /// - - /// - - /// - - /// - - /// - - /// - - /// - - /// - - send: func(datagrams: list) -> result; - - /// 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 set with `connect`. - /// - /// # Typical errors - /// - `invalid-state`: The socket is not connected to a 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; - - /// Whether IPv4 compatibility (dual-stack) mode is disabled or not. - /// - /// Equivalent to the IPV6_V6ONLY socket option. - /// - /// # Typical errors - /// - `not-supported`: (get/set) `this` socket is an IPv4 socket. - /// - `invalid-state`: (set) The socket is already bound. - /// - `not-supported`: (set) Host does not support dual-stack sockets. (Implementations are not required to.) - ipv6-only: func() -> result; - set-ipv6-only: func(value: bool) -> result<_, error-code>; - - /// Equivalent to the IP_TTL & IPV6_UNICAST_HOPS socket options. - 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. - /// - /// Note #1: an implementation may choose to cap or round the buffer size when setting the value. - /// In other words, after setting a value, reading the same setting back may return a different value. - /// - /// Note #2: there is not necessarily a direct relationship between the kernel buffer size and the bytes of - /// actual data to be sent/received by the application, because the kernel might also use the buffer space - /// for internal metadata structures. - /// - /// Equivalent to the SO_RCVBUF and SO_SNDBUF socket options. - 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; - } -} diff --git a/examples/wit/deps/sockets-2023-10-18/world.wit b/examples/wit/deps/sockets-2023-10-18/world.wit deleted file mode 100644 index d16530c..0000000 --- a/examples/wit/deps/sockets-2023-10-18/world.wit +++ /dev/null @@ -1,11 +0,0 @@ -package wasi:sockets@0.2.0-rc-2023-10-18; - -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/examples/wit/deps/sockets-2023-11-10/instance-network.wit b/examples/wit/deps/sockets-2023-11-10/instance-network.wit deleted file mode 100644 index e455d0f..0000000 --- a/examples/wit/deps/sockets-2023-11-10/instance-network.wit +++ /dev/null @@ -1,9 +0,0 @@ - -/// 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/examples/wit/deps/sockets-2023-11-10/ip-name-lookup.wit b/examples/wit/deps/sockets-2023-11-10/ip-name-lookup.wit deleted file mode 100644 index 931ccf7..0000000 --- a/examples/wit/deps/sockets-2023-11-10/ip-name-lookup.wit +++ /dev/null @@ -1,51 +0,0 @@ - -interface ip-name-lookup { - use wasi:io/poll@0.2.0-rc-2023-11-10.{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/examples/wit/deps/sockets-2023-11-10/network.wit b/examples/wit/deps/sockets-2023-11-10/network.wit deleted file mode 100644 index 6bb07cd..0000000 --- a/examples/wit/deps/sockets-2023-11-10/network.wit +++ /dev/null @@ -1,147 +0,0 @@ - -interface network { - /// An opaque resource that represents access to (a subset of) the network. - /// This enables context-based security for networking. - /// There is no need for this to map 1:1 to a physical network interface. - 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 { - // ### GENERAL ERRORS ### - - /// 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, - - - - // ### TCP & UDP SOCKET ERRORS ### - - /// 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, - - - // ### TCP SOCKET ERRORS ### - - /// The connection was forcefully rejected - connection-refused, - - /// The connection was reset. - connection-reset, - - /// A connection was aborted. - connection-aborted, - - - // ### UDP SOCKET ERRORS ### - datagram-too-large, - - - // ### NAME LOOKUP ERRORS ### - - /// 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 { - port: u16, // sin_port - address: ipv4-address, // sin_addr - } - - record ipv6-socket-address { - port: u16, // sin6_port - flow-info: u32, // sin6_flowinfo - address: ipv6-address, // sin6_addr - scope-id: u32, // sin6_scope_id - } - - variant ip-socket-address { - ipv4(ipv4-socket-address), - ipv6(ipv6-socket-address), - } - -} diff --git a/examples/wit/deps/sockets-2023-11-10/tcp-create-socket.wit b/examples/wit/deps/sockets-2023-11-10/tcp-create-socket.wit deleted file mode 100644 index 768a07c..0000000 --- a/examples/wit/deps/sockets-2023-11-10/tcp-create-socket.wit +++ /dev/null @@ -1,26 +0,0 @@ - -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. - /// - /// 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`/`listen`/`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/examples/wit/deps/sockets-2023-11-10/tcp.wit b/examples/wit/deps/sockets-2023-11-10/tcp.wit deleted file mode 100644 index b01b65e..0000000 --- a/examples/wit/deps/sockets-2023-11-10/tcp.wit +++ /dev/null @@ -1,321 +0,0 @@ - -interface tcp { - use wasi:io/streams@0.2.0-rc-2023-11-10.{input-stream, output-stream}; - use wasi:io/poll@0.2.0-rc-2023-11-10.{pollable}; - use wasi:clocks/monotonic-clock@0.2.0-rc-2023-11-10.{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 handle. - 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. - /// - /// When a socket is not explicitly bound, the first invocation to a listen or connect operation will - /// implicitly bind the socket. - /// - /// Unlike in POSIX, this function is async. This enables interactive WASI hosts to inject permission prompts. - /// - /// # Typical `start` 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, but the socket has `ipv6-only` enabled. (EINVAL) - /// - `invalid-state`: The socket is already bound. (EINVAL) - /// - /// # Typical `finish` errors - /// - `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) - /// - /// # 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 - /// - /// POSIX mentions: - /// > If connect() fails, the state of the socket is unspecified. Conforming applications should - /// > close the file descriptor and create a new socket before attempting to reconnect. - /// - /// WASI prescribes the following behavior: - /// - If `connect` fails because an input/state validation error, the socket should remain usable. - /// - If a connection was actually attempted but failed, the socket should become unusable for further network communication. - /// Besides `drop`, any method after such a failure may return an error. - /// - /// # Typical `start` 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, but the socket has `ipv6-only` enabled. (EINVAL, EADDRNOTAVAIL on Illumos) - /// - `invalid-argument`: `remote-address` is a non-IPv4-mapped IPv6 address, but the socket was bound to a specific IPv4-mapped IPv6 address. (or vice versa) - /// - `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 Connection state. (EISCONN) - /// - `invalid-state`: The socket is already in the Listener state. (EOPNOTSUPP, EINVAL on Windows) - /// - /// # Typical `finish` errors - /// - `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) - /// - /// # 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 Listener state. - /// - /// Unlike POSIX: - /// - this function is async. This enables interactive WASI hosts to inject permission prompts. - /// - the socket must already be explicitly bound. - /// - /// # Typical `start` errors - /// - `invalid-state`: The socket is not bound to any local address. (EDESTADDRREQ) - /// - `invalid-state`: The socket is already in the Connection state. (EISCONN, EINVAL on BSD) - /// - `invalid-state`: The socket is already in the Listener state. - /// - /// # Typical `finish` errors - /// - `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) - /// - /// # 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 Connection state. The following properties are inherited from the listener socket: - /// - `address-family` - /// - `ipv6-only` - /// - `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 Listener 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 listening for new connections. - /// - /// 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; - - /// Whether IPv4 compatibility (dual-stack) mode is disabled or not. - /// - /// Equivalent to the IPV6_V6ONLY socket option. - /// - /// # Typical errors - /// - `invalid-state`: (set) The socket is already bound. - /// - `not-supported`: (get/set) `this` socket is an IPv4 socket. - /// - `not-supported`: (set) Host does not support dual-stack sockets. (Implementations are not required to.) - ipv6-only: func() -> result; - set-ipv6-only: func(value: bool) -> result<_, error-code>; - - /// 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 already in the Connection 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. - /// - `invalid-state`: (set) The socket is already in the Connection state. - /// - `invalid-state`: (set) The socket is already in the Listener state. - 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. - /// - `invalid-state`: (set) The socket is already in the Connection state. - /// - `invalid-state`: (set) The socket is already in the Listener state. - 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; - - /// Initiate a graceful shutdown. - /// - /// - receive: the socket is not expecting to receive any more data from the peer. All subsequent read - /// operations on the `input-stream` associated with this socket will return an End Of Stream indication. - /// Any data still in the receive queue at time of calling `shutdown` will be discarded. - /// - send: the socket is not expecting to send any more data to the peer. All subsequent write - /// operations on the `output-stream` associated with this socket will return an error. - /// - both: same effect as receive & send combined. - /// - /// The shutdown function does not close (drop) the socket. - /// - /// # Typical errors - /// - `invalid-state`: The socket is not in the Connection state. (ENOTCONN) - /// - /// # References - /// - - /// - - /// - - /// - - shutdown: func(shutdown-type: shutdown-type) -> result<_, error-code>; - } -} diff --git a/examples/wit/deps/sockets-2023-11-10/udp-create-socket.wit b/examples/wit/deps/sockets-2023-11-10/udp-create-socket.wit deleted file mode 100644 index cc58234..0000000 --- a/examples/wit/deps/sockets-2023-11-10/udp-create-socket.wit +++ /dev/null @@ -1,26 +0,0 @@ - -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. - /// - /// 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/examples/wit/deps/sockets-2023-11-10/udp.wit b/examples/wit/deps/sockets-2023-11-10/udp.wit deleted file mode 100644 index c8dafad..0000000 --- a/examples/wit/deps/sockets-2023-11-10/udp.wit +++ /dev/null @@ -1,277 +0,0 @@ - -interface udp { - use wasi:io/poll@0.2.0-rc-2023-11-10.{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. - /// - /// Unlike in POSIX, this function is async. This enables interactive WASI hosts to inject permission prompts. - /// - /// # Typical `start` errors - /// - `invalid-argument`: The `local-address` has the wrong address family. (EAFNOSUPPORT, EFAULT on Windows) - /// - `invalid-state`: The socket is already bound. (EINVAL) - /// - /// # Typical `finish` errors - /// - `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) - /// - /// # 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`: `remote-address` is a non-IPv4-mapped IPv6 address, but the socket was bound to a specific IPv4-mapped IPv6 address. (or vice versa) - /// - `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; - - /// Whether IPv4 compatibility (dual-stack) mode is disabled or not. - /// - /// Equivalent to the IPV6_V6ONLY socket option. - /// - /// # Typical errors - /// - `not-supported`: (get/set) `this` socket is an IPv4 socket. - /// - `invalid-state`: (set) The socket is already bound. - /// - `not-supported`: (set) Host does not support dual-stack sockets. (Implementations are not required to.) - ipv6-only: func() -> result; - set-ipv6-only: func(value: bool) -> 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. - 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`: `remote-address` is a non-IPv4-mapped IPv6 address, but the socket was bound to a specific IPv4-mapped IPv6 address. (or vice versa) - /// - `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/examples/wit/deps/sockets-2023-11-10/world.wit b/examples/wit/deps/sockets-2023-11-10/world.wit deleted file mode 100644 index 49ad8d3..0000000 --- a/examples/wit/deps/sockets-2023-11-10/world.wit +++ /dev/null @@ -1,11 +0,0 @@ -package wasi:sockets@0.2.0-rc-2023-11-10; - -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/examples/wit/deps/spin@unversioned/config.wit b/examples/wit/deps/spin@unversioned/config.wit deleted file mode 100644 index ac465fb..0000000 --- a/examples/wit/deps/spin@unversioned/config.wit +++ /dev/null @@ -1,12 +0,0 @@ -interface config { - // Get a configuration value for the current component. - // The config key must match one defined in in the component manifest. - get-config: func(key: string) -> result; - - variant error { - provider(string), - invalid-key(string), - invalid-schema(string), - other(string), - } -} diff --git a/examples/wit/deps/spin@unversioned/http-types.wit b/examples/wit/deps/spin@unversioned/http-types.wit deleted file mode 100644 index c941cc9..0000000 --- a/examples/wit/deps/spin@unversioned/http-types.wit +++ /dev/null @@ -1,44 +0,0 @@ -interface http-types { - type http-status = u16; - - type body = list; - - type headers = list>; - - type params = list>; - - type uri = string; - - enum method { - get, - post, - put, - delete, - patch, - head, - options, - } - - record request { - method: method, - uri: uri, - headers: headers, - params: params, - body: option, - } - - record response { - status: http-status, - headers: option, - body: option, - } - - enum http-error { - success, - destination-not-allowed, - invalid-url, - request-error, - runtime-error, - too-many-requests, - } -} diff --git a/examples/wit/deps/spin@unversioned/http.wit b/examples/wit/deps/spin@unversioned/http.wit deleted file mode 100644 index 6ca943c..0000000 --- a/examples/wit/deps/spin@unversioned/http.wit +++ /dev/null @@ -1,5 +0,0 @@ -interface http { - use http-types.{request, response, http-error}; - - send-request: func(req: request) -> result; -} diff --git a/examples/wit/deps/spin@unversioned/inbound-http.wit b/examples/wit/deps/spin@unversioned/inbound-http.wit deleted file mode 100644 index 968c576..0000000 --- a/examples/wit/deps/spin@unversioned/inbound-http.wit +++ /dev/null @@ -1,5 +0,0 @@ -interface inbound-http { - use http-types.{request, response}; - - handle-request: func(req: request) -> response; -} diff --git a/examples/wit/deps/spin@unversioned/inbound-redis.wit b/examples/wit/deps/spin@unversioned/inbound-redis.wit deleted file mode 100644 index a991e5d..0000000 --- a/examples/wit/deps/spin@unversioned/inbound-redis.wit +++ /dev/null @@ -1,6 +0,0 @@ -interface inbound-redis { - use redis-types.{payload, error}; - - // The entrypoint for a Redis handler. - handle-message: func(message: payload) -> result<_, error>; -} diff --git a/examples/wit/deps/spin@unversioned/key-value.wit b/examples/wit/deps/spin@unversioned/key-value.wit deleted file mode 100644 index 314a758..0000000 --- a/examples/wit/deps/spin@unversioned/key-value.wit +++ /dev/null @@ -1,80 +0,0 @@ -interface key-value { - // A handle to an open key-value store - type store = u32; - - // The set of errors which may be raised by functions in this interface - variant error { - // Too many stores have been opened simultaneously. Closing one or more - // stores prior to retrying may address this. - store-table-full, - - // The host does not recognize the store name requested. Defining and - // configuring a store with that name in a runtime configuration file - // may address this. - no-such-store, - - // The requesting component does not have access to the specified store - // (which may or may not exist). - access-denied, - - // The store handle provided is not recognized, i.e. it was either never - // opened or has been closed. - invalid-store, - - // No key-value tuple exists for the specified key in the specified - // store. - no-such-key, - - // Some implementation-specific error has occurred (e.g. I/O) - io(string) - } - - // Open the store with the specified name. - // - // If `name` is "default", the default store is opened. Otherwise, - // `name` must refer to a store defined and configured in a runtime - // configuration file supplied with the application. - // - // `error::no-such-store` will be raised if the `name` is not recognized. - open: func(name: string) -> result; - - // Get the value associated with the specified `key` from the specified - // `store`. - // - // `error::invalid-store` will be raised if `store` is not a valid handle - // to an open store, and `error::no-such-key` will be raised if there is no - // tuple for `key` in `store`. - get: func(store: store, key: string) -> result, error>; - - // Set the `value` associated with the specified `key` in the specified - // `store`, overwriting any existing value. - // - // `error::invalid-store` will be raised if `store` is not a valid handle - // to an open store. - set: func(store: store, key: string, value: list) -> result<_, error>; - - // Delete the tuple with the specified `key` from the specified `store`. - // - // `error::invalid-store` will be raised if `store` is not a valid handle - // to an open store. No error is raised if a tuple did not previously - // exist for `key`. - delete: func(store: store, key: string) -> result<_, error>; - - // Return whether a tuple exists for the specified `key` in the specified - // `store`. - // - // `error::invalid-store` will be raised if `store` is not a valid handle - // to an open store. - exists: func(store: store, key: string) -> result; - - // Return a list of all the keys in the specified `store`. - // - // `error::invalid-store` will be raised if `store` is not a valid handle - // to an open store. - get-keys: func(store: store) -> result, error>; - - // Close the specified `store`. - // - // This has no effect if `store` is not a valid handle to an open store. - close: func(store: store); -} diff --git a/examples/wit/deps/spin@unversioned/llm.wit b/examples/wit/deps/spin@unversioned/llm.wit deleted file mode 100644 index ffed09c..0000000 --- a/examples/wit/deps/spin@unversioned/llm.wit +++ /dev/null @@ -1,70 +0,0 @@ -// A WASI interface dedicated to performing inferencing for Large Language Models. -interface llm { - /// A Large Language Model. - type inferencing-model = string; - - /// Inference request parameters - record inferencing-params { - /// The maximum tokens that should be inferred. - /// - /// Note: the backing implementation may return less tokens. - max-tokens: u32, - /// The amount the model should avoid repeating tokens. - repeat-penalty: float32, - /// The number of tokens the model should apply the repeat penalty to. - repeat-penalty-last-n-token-count: u32, - /// The randomness with which the next token is selected. - temperature: float32, - /// The number of possible next tokens the model will choose from. - top-k: u32, - /// The probability total of next tokens the model will choose from. - top-p: float32 - } - - /// The set of errors which may be raised by functions in this interface - variant error { - model-not-supported, - runtime-error(string), - invalid-input(string) - } - - /// An inferencing result - record inferencing-result { - /// The text generated by the model - // TODO: this should be a stream - text: string, - /// Usage information about the inferencing request - usage: inferencing-usage - } - - /// Usage information related to the inferencing result - record inferencing-usage { - /// Number of tokens in the prompt - prompt-token-count: u32, - /// Number of tokens generated by the inferencing operation - generated-token-count: u32 - } - - /// Perform inferencing using the provided model and prompt with the given optional params - infer: func(model: inferencing-model, prompt: string, params: option) -> result; - - /// The model used for generating embeddings - type embedding-model = string; - - /// Generate embeddings for the supplied list of text - generate-embeddings: func(model: embedding-model, text: list) -> result; - - /// Result of generating embeddings - record embeddings-result { - /// The embeddings generated by the request - embeddings: list>, - /// Usage related to the embeddings generation request - usage: embeddings-usage - } - - /// Usage related to an embeddings generation request - record embeddings-usage { - /// Number of tokens in the prompt - prompt-token-count: u32, - } -} diff --git a/examples/wit/deps/spin@unversioned/mysql.wit b/examples/wit/deps/spin@unversioned/mysql.wit deleted file mode 100644 index dd1b9c3..0000000 --- a/examples/wit/deps/spin@unversioned/mysql.wit +++ /dev/null @@ -1,19 +0,0 @@ -interface mysql { - use rdbms-types.{parameter-value, row-set}; - - // General purpose error. - variant mysql-error { - success, - connection-failed(string), - bad-parameter(string), - query-failed(string), - value-conversion-failed(string), - other-error(string) - } - - // query the database: select - query: func(address: string, statement: string, params: list) -> result; - - // execute command to the database: insert, update, delete - execute: func(address: string, statement: string, params: list) -> result<_, mysql-error>; -} diff --git a/examples/wit/deps/spin@unversioned/postgres.wit b/examples/wit/deps/spin@unversioned/postgres.wit deleted file mode 100644 index e82ef42..0000000 --- a/examples/wit/deps/spin@unversioned/postgres.wit +++ /dev/null @@ -1,19 +0,0 @@ -interface postgres { - use rdbms-types.{parameter-value, row-set}; - - // General purpose error. - variant pg-error { - success, - connection-failed(string), - bad-parameter(string), - query-failed(string), - value-conversion-failed(string), - other-error(string) - } - - // query the database: select - query: func(address: string, statement: string, params: list) -> result; - - // execute command to the database: insert, update, delete - execute: func(address: string, statement: string, params: list) -> result; -} diff --git a/examples/wit/deps/spin@unversioned/rdbms-types.wit b/examples/wit/deps/spin@unversioned/rdbms-types.wit deleted file mode 100644 index 7af0420..0000000 --- a/examples/wit/deps/spin@unversioned/rdbms-types.wit +++ /dev/null @@ -1,65 +0,0 @@ -interface rdbms-types { - enum db-data-type { - boolean, - int8, - int16, - int32, - int64, - uint8, - uint16, - uint32, - uint64, - floating32, - floating64, - str, - binary, - other, - } - - variant db-value { - boolean(bool), - int8(s8), - int16(s16), - int32(s32), - int64(s64), - uint8(u8), - uint16(u16), - uint32(u32), - uint64(u64), - floating32(float32), - floating64(float64), - str(string), - binary(list), - db-null, - unsupported, - } - - variant parameter-value { - boolean(bool), - int8(s8), - int16(s16), - int32(s32), - int64(s64), - uint8(u8), - uint16(u16), - uint32(u32), - uint64(u64), - floating32(float32), - floating64(float64), - str(string), - binary(list), - db-null, - } - - record column { - name: string, - data-type: db-data-type, - } - - type row = list; - - record row-set { - columns: list, - rows: list, - } -} diff --git a/examples/wit/deps/spin@unversioned/redis-types.wit b/examples/wit/deps/spin@unversioned/redis-types.wit deleted file mode 100644 index 6970f63..0000000 --- a/examples/wit/deps/spin@unversioned/redis-types.wit +++ /dev/null @@ -1,24 +0,0 @@ -interface redis-types { - // General purpose error. - enum error { - success, - error, - } - - /// The message payload. - type payload = list; - - /// A parameter type for the general-purpose `execute` function. - variant redis-parameter { - int64(s64), - binary(payload) - } - - /// A return type for the general-purpose `execute` function. - variant redis-result { - nil, - status(string), - int64(s64), - binary(payload) - } -} diff --git a/examples/wit/deps/spin@unversioned/redis.wit b/examples/wit/deps/spin@unversioned/redis.wit deleted file mode 100644 index 1b64906..0000000 --- a/examples/wit/deps/spin@unversioned/redis.wit +++ /dev/null @@ -1,31 +0,0 @@ -interface redis { - use redis-types.{payload, redis-parameter, redis-result, error}; - - // Publish a Redis message to the specificed channel and return an error, if any. - publish: func(address: string, channel: string, payload: payload) -> result<_, error>; - - // Get the value of a key. - get: func(address: string, key: string) -> result; - - // Set key to value. If key alreads holds a value, it is overwritten. - set: func(address: string, key: string, value: payload) -> result<_, error>; - - // Increments the number stored at key by one. If the key does not exist, it is set to 0 before performing the operation. - // An error is returned if the key contains a value of the wrong type or contains a string that can not be represented as integer. - incr: func(address: string, key: string) -> result; - - // Removes the specified keys. A key is ignored if it does not exist. - del: func(address: string, keys: list) -> result; - - // Add the specified `values` to the set named `key`, returning the number of newly-added values. - sadd: func(address: string, key: string, values: list) -> result; - - // Retrieve the contents of the set named `key`. - smembers: func(address: string, key: string) -> result, error>; - - // Remove the specified `values` from the set named `key`, returning the number of newly-removed values. - srem: func(address: string, key: string, values: list) -> result; - - // Execute an arbitrary Redis command and receive the result. - execute: func(address: string, command: string, arguments: list) -> result, error>; -} diff --git a/examples/wit/deps/spin@unversioned/sqlite.wit b/examples/wit/deps/spin@unversioned/sqlite.wit deleted file mode 100644 index 7e2908f..0000000 --- a/examples/wit/deps/spin@unversioned/sqlite.wit +++ /dev/null @@ -1,52 +0,0 @@ -interface sqlite { - // A handle to an open sqlite instance - type connection = u32; - - // The set of errors which may be raised by functions in this interface - variant error { - // The host does not recognize the database name requested. - no-such-database, - // The requesting component does not have access to the specified database (which may or may not exist). - access-denied, - // The provided connection is not valid - invalid-connection, - // The database has reached its capacity - database-full, - // Some implementation-specific error has occurred (e.g. I/O) - io(string) - } - - // Open a connection to a named database instance. - // - // If `database` is "default", the default instance is opened. - // - // `error::no-such-database` will be raised if the `name` is not recognized. - open: func(database: string) -> result; - - // Execute a statement returning back data if there is any - execute: func(conn: connection, statement: string, parameters: list) -> result; - - // Close the specified `connection`. - close: func(conn: connection); - - // A result of a query - record query-result { - // The names of the columns retrieved in the query - columns: list, - // the row results each containing the values for all the columns for a given row - rows: list, - } - - // A set of values for each of the columns in a query-result - record row-result { - values: list - } - - variant value { - integer(s64), - real(float64), - text(string), - blob(list), - null - } -} diff --git a/examples/wit/deps/spin@unversioned/world.wit b/examples/wit/deps/spin@unversioned/world.wit deleted file mode 100644 index 603a760..0000000 --- a/examples/wit/deps/spin@unversioned/world.wit +++ /dev/null @@ -1,29 +0,0 @@ -package fermyon:spin; - -world host { - include platform; - - export inbound-http; - export inbound-redis; -} - -world redis-trigger { - include platform; - export inbound-redis; -} - -world http-trigger { - include platform; - export inbound-http; -} - -world platform { - import config; - import http; - import postgres; - import mysql; - import sqlite; - import redis; - import key-value; - import llm; -} diff --git a/examples/wit/main.wit b/examples/wit/main.wit index eb9ac37..4dd42a8 100644 --- a/examples/wit/main.wit +++ b/examples/wit/main.wit @@ -1,32 +1 @@ -package wasmtime:wasi; - -// All of the same imports available in the wasi:cli/command world, but no -// export required: -world preview1-adapter-reactor { - import wasi:clocks/wall-clock@0.2.0; - import wasi:clocks/monotonic-clock@0.2.0; - import wasi:filesystem/types@0.2.0; - import wasi:filesystem/preopens@0.2.0; - import wasi:sockets/instance-network@0.2.0; - import wasi:sockets/ip-name-lookup@0.2.0; - import wasi:sockets/network@0.2.0; - import wasi:sockets/tcp-create-socket@0.2.0; - import wasi:sockets/tcp@0.2.0; - import wasi:sockets/udp-create-socket@0.2.0; - import wasi:sockets/udp@0.2.0; - import wasi:random/random@0.2.0; - import wasi:random/insecure@0.2.0; - import wasi:random/insecure-seed@0.2.0; - import wasi:io/poll@0.2.0; - import wasi:io/streams@0.2.0; - import wasi:cli/environment@0.2.0; - import wasi:cli/exit@0.2.0; - import wasi:cli/stdin@0.2.0; - import wasi:cli/stdout@0.2.0; - import wasi:cli/stderr@0.2.0; - import wasi:cli/terminal-input@0.2.0; - import wasi:cli/terminal-output@0.2.0; - import wasi:cli/terminal-stdin@0.2.0; - import wasi:cli/terminal-stdout@0.2.0; - import wasi:cli/terminal-stderr@0.2.0; -} +package wasmtime:wasi; \ No newline at end of file From 0520a10d619eeb52ddf05dbd4b1584b8c9b33d09 Mon Sep 17 00:00:00 2001 From: Ryan Levick Date: Tue, 3 Sep 2024 14:14:43 +0200 Subject: [PATCH 5/6] Get JS really working Signed-off-by: Ryan Levick --- examples/javascript/.gitignore | 4 +++- examples/javascript/build.mjs | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/examples/javascript/.gitignore b/examples/javascript/.gitignore index 40b878d..1543858 100644 --- a/examples/javascript/.gitignore +++ b/examples/javascript/.gitignore @@ -1 +1,3 @@ -node_modules/ \ No newline at end of file +node_modules/ +http.wasm +composed.wasm \ No newline at end of file diff --git a/examples/javascript/build.mjs b/examples/javascript/build.mjs index 0250c49..63a27b6 100644 --- a/examples/javascript/build.mjs +++ b/examples/javascript/build.mjs @@ -2,7 +2,7 @@ import { componentize } from "@bytecodealliance/componentize-js" import { readFile, writeFile } from "node:fs/promises" const { component } = await componentize( - await readFile("app.mjs"), + await readFile("app.mjs", "utf-8"), { witPath: "../wit", worldName: "proxy", From 28655808bbc6885e5ef2bfd09172a1f3b1033864 Mon Sep 17 00:00:00 2001 From: Ryan Levick Date: Mon, 9 Sep 2024 12:38:02 +0200 Subject: [PATCH 6/6] PR feedback Signed-off-by: Ryan Levick --- examples/python/README.md | 4 ++-- examples/rust/src/lib.rs | 6 ++---- src/bindings.rs | 18 ------------------ src/lib.rs | 5 +---- 4 files changed, 5 insertions(+), 28 deletions(-) delete mode 100644 src/bindings.rs diff --git a/examples/python/README.md b/examples/python/README.md index 79f3697..1f94a01 100644 --- a/examples/python/README.md +++ b/examples/python/README.md @@ -14,7 +14,7 @@ component for serving static files. - [wac](https://github.com/bytecodealliance/wac) - [Python](https://www.python.org/downloads/) 3.11 or later - [pip](https://pip.pypa.io/en/stable/installation/) -- [componentize-py](https://pypi.org/project/componentize-py/) +- [componentize-py](https://pypi.org/project/componentize-py/) 0.13.x - [curl](https://curl.se/download.html) or a web browser for testing Once you have Rust, Python, and pip installed, the following should give you everything else: @@ -23,7 +23,7 @@ Once you have Rust, Python, and pip installed, the following should give you eve rustup target add wasm32-wasi cargo install cargo-component cargo install wac-cli -pip install componentize-py +pip install componentize-py=0.13.5 ``` ## Building and Running diff --git a/examples/rust/src/lib.rs b/examples/rust/src/lib.rs index c8451be..3740959 100644 --- a/examples/rust/src/lib.rs +++ b/examples/rust/src/lib.rs @@ -21,10 +21,8 @@ mod bindings { async fn handle_request(request: IncomingRequest, response_out: ResponseOutparam) { match (request.method(), request.path_with_query().as_deref()) { (Method::Get, Some("/hello")) => { - let fields = Fields::new(); - fields - .append(&"content-type".to_owned(), &b"text/plain".to_vec()) - .unwrap(); + let fields = + Fields::from_list(&[("content-type".to_owned(), b"text/plain".to_vec())]).unwrap(); let response = OutgoingResponse::new(fields); let mut body = response.take_body(); diff --git a/src/bindings.rs b/src/bindings.rs deleted file mode 100644 index 0da7e33..0000000 --- a/src/bindings.rs +++ /dev/null @@ -1,18 +0,0 @@ -// Generated by `wit-bindgen` 0.25.0. DO NOT EDIT! -// Options used: - -#[cfg(target_arch = "wasm32")] -#[link_section = "component-type:wit-bindgen:0.25.0:spin-static-fs:encoded world"] -#[doc(hidden)] -pub static __WIT_BINDGEN_COMPONENT_TYPE: [u8; 182] = *b"\ -\0asm\x0d\0\x01\0\0\x19\x16wit-component-encoding\x04\0\x072\x01A\x02\x01A\0\x04\ -\x01'component:spin-static-fs/spin-static-fs\x04\0\x0b\x14\x01\0\x0espin-static-\ -fs\x03\0\0\0G\x09producers\x01\x0cprocessed-by\x02\x0dwit-component\x070.208.1\x10\ -wit-bindgen-rust\x060.25.0"; - -#[inline(never)] -#[doc(hidden)] -#[cfg(target_arch = "wasm32")] -pub fn __link_custom_section_describing_imports() { - wit_bindgen_rt::maybe_link_cabi_realloc(); -} diff --git a/src/lib.rs b/src/lib.rs index 065fbb8..eef44cc 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -235,10 +235,7 @@ async fn handle_request(req: IncomingRequest, res_out: ResponseOutparam) { .unwrap_or(b""); match FileServer::make_response(path, enc, if_none_match) { Ok((status, headers, reader)) => { - let fields = Fields::new(); - for (name, value) in headers { - let _ = fields.append(&name, &value); - } + let fields = Fields::from_list(&headers).unwrap(); let res = OutgoingResponse::new(fields); let _ = res.set_status_code(status.as_u16()); let mut body = res.take_body();