diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 423ff59..e6da62e 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -37,6 +37,9 @@ jobs: - name: Install wasm32-wasi target run: rustup target add wasm32-wasi + - name: Install wasm-tools + run: cargo install wasm-tools + - name: Build adapter run: ./build-adapter.sh diff --git a/.gitignore b/.gitignore index d14bda9..277d36f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ /target /tests/generated +/lib/package.wasm \ No newline at end of file diff --git a/Cargo.lock b/Cargo.lock index 371dded..b4bcb1e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -8,7 +8,7 @@ version = "0.21.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8a30b2e23b9e17a9f90641c7ab1549cd9b44f296d3ccbf309d2863cfe398a0cb" dependencies = [ - "gimli 0.28.0", + "gimli 0.28.1", ] [[package]] @@ -19,13 +19,14 @@ checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" [[package]] name = "ahash" -version = "0.8.3" +version = "0.8.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2c99f64d1e06488f620f932677e24bc6e2897582980441ae90a671415bd7ec2f" +checksum = "42cd52102d3df161c77a887b608d7a4897d7cc112886a9537b738a887a03aaff" dependencies = [ "cfg-if", "once_cell", "version_check", + "zerocopy", ] [[package]] @@ -34,11 +35,20 @@ version = "0.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e9d4ee0d472d1cd2e28c97dfa124b3d8d992e10eb0a035f33f5d12e3a177ba3b" +[[package]] +name = "android_system_properties" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "819e7219dbd41043ac279b19830f2efc897156490d7fd6ea916720117ee66311" +dependencies = [ + "libc", +] + [[package]] name = "anstream" -version = "0.5.0" +version = "0.6.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b1f58811cfac344940f1a400b6e6231ce35171f614f26439e80f8c1465c5cc0c" +checksum = "6e2e1ebcb11de5c03c67de28a7df593d32191b44939c482e97702baaaa6ab6a5" dependencies = [ "anstyle", "anstyle-parse", @@ -50,43 +60,43 @@ dependencies = [ [[package]] name = "anstyle" -version = "1.0.3" +version = "1.0.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b84bf0a05bbb2a83e5eb6fa36bb6e87baa08193c35ff52bbf6b38d8af2890e46" +checksum = "8901269c6307e8d93993578286ac0edf7f195079ffff5ebdeea6a59ffb7e36bc" [[package]] name = "anstyle-parse" -version = "0.2.1" +version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "938874ff5980b03a87c5524b3ae5b59cf99b1d6bc836848df7bc5ada9643c333" +checksum = "c75ac65da39e5fe5ab759307499ddad880d724eed2f6ce5b5e8a26f4f387928c" dependencies = [ "utf8parse", ] [[package]] name = "anstyle-query" -version = "1.0.0" +version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5ca11d4be1bab0c8bc8734a9aa7bf4ee8316d462a08c6ac5052f888fef5b494b" +checksum = "e28923312444cdd728e4738b3f9c9cac739500909bb3d3c94b43551b16517648" dependencies = [ - "windows-sys 0.48.0", + "windows-sys 0.52.0", ] [[package]] name = "anstyle-wincon" -version = "2.1.0" +version = "3.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "58f54d10c6dfa51283a066ceab3ec1ab78d13fae00aa49243a45e4571fb79dfd" +checksum = "1cd54b81ec8d6180e24654d0b371ad22fc3dd083b6ff8ba325b72e00c87660a7" dependencies = [ "anstyle", - "windows-sys 0.48.0", + "windows-sys 0.52.0", ] [[package]] name = "anyhow" -version = "1.0.75" +version = "1.0.79" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4668cab20f66d8d020e1fbc0ebe47217433c1b6c8f2040faf858554e394ace6" +checksum = "080e9890a082662b09c1ad45f567faeeb47f22b5fb23895fbe1e651e718e25ca" [[package]] name = "arbitrary" @@ -96,13 +106,13 @@ checksum = "7d5a26814d8dcb93b0e5a0ff3c6d80a8843bafb21b39e8e18a6f05471870e110" [[package]] name = "async-trait" -version = "0.1.73" +version = "0.1.77" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bc00ceb34980c03614e35a3a4e218276a0a824e911d07651cd0d858a51e8c0f0" +checksum = "c980ee35e870bd1a4d2c8294d4c04d0499e67bca1e4b5cefcc693c2fa00caea9" dependencies = [ "proc-macro2", "quote", - "syn 2.0.37", + "syn 2.0.48", ] [[package]] @@ -128,9 +138,9 @@ dependencies = [ [[package]] name = "base64" -version = "0.21.4" +version = "0.21.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9ba43ea6f343b788c8764558649e08df62f86c6ef251fdaeb1ffd010a9ae50a2" +checksum = "9d297deb1925b89f2ccc13d7635fa0714f12c87adce1c75356b39ca9b7178567" [[package]] name = "bincode" @@ -179,9 +189,9 @@ checksum = "7f30e7476521f6f8af1a1c4c0b8cc94f0bee37d91763d0ca2665f299b6cd8aec" [[package]] name = "byteorder" -version = "1.4.3" +version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610" +checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" [[package]] name = "bytes" @@ -191,25 +201,25 @@ checksum = "a2bd12c1caf447e69cd4528f47f94d203fd2582878ecb9e9465484c4148a8223" [[package]] name = "cap-fs-ext" -version = "2.0.0" +version = "2.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b779b2d0a001c125b4584ad586268fb4b92d957bff8d26d7fe0dd78283faa814" +checksum = "88e341d15ac1029aadce600be764a1a1edafe40e03cde23285bc1d261b3a4866" dependencies = [ - "cap-primitives 2.0.0", - "cap-std 2.0.0", - "io-lifetimes 2.0.2", - "windows-sys 0.48.0", + "cap-primitives 2.0.1", + "cap-std 2.0.1", + "io-lifetimes 2.0.3", + "windows-sys 0.52.0", ] [[package]] name = "cap-net-ext" -version = "2.0.0" +version = "2.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6ffc30dee200c20b4dcb80572226f42658e1d9c4b668656d7cc59c33d50e396e" +checksum = "434168fe6533055f0f4204039abe3ff6d7db338ef46872a5fa39e9d5ad5ab7a9" dependencies = [ - "cap-primitives 2.0.0", - "cap-std 2.0.0", - "rustix 0.38.30", + "cap-primitives 2.0.1", + "cap-std 2.0.1", + "rustix 0.38.31", "smallvec", ] @@ -225,33 +235,33 @@ dependencies = [ "io-lifetimes 1.0.11", "ipnet", "maybe-owned", - "rustix 0.37.23", + "rustix 0.37.27", "windows-sys 0.48.0", "winx 0.35.1", ] [[package]] name = "cap-primitives" -version = "2.0.0" +version = "2.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2bf30c373a3bee22c292b1b6a7a26736a38376840f1af3d2d806455edf8c3899" +checksum = "fe16767ed8eee6d3f1f00d6a7576b81c226ab917eb54b96e5f77a5216ef67abb" dependencies = [ "ambient-authority", - "fs-set-times 0.20.0", - "io-extras 0.18.0", - "io-lifetimes 2.0.2", + "fs-set-times 0.20.1", + "io-extras 0.18.1", + "io-lifetimes 2.0.3", "ipnet", "maybe-owned", - "rustix 0.38.30", - "windows-sys 0.48.0", - "winx 0.36.2", + "rustix 0.38.31", + "windows-sys 0.52.0", + "winx 0.36.3", ] [[package]] name = "cap-rand" -version = "2.0.0" +version = "2.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "577de6cff7c2a47d6b13efe5dd28bf116bd7f8f7db164ea95b7cc2640711f522" +checksum = "20e5695565f0cd7106bc3c7170323597540e772bb73e0be2cd2c662a0f8fa4ca" dependencies = [ "ambient-authority", "rand", @@ -266,31 +276,33 @@ dependencies = [ "cap-primitives 1.0.15", "io-extras 0.17.4", "io-lifetimes 1.0.11", - "rustix 0.37.23", + "rustix 0.37.27", ] [[package]] name = "cap-std" -version = "2.0.0" +version = "2.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "84bade423fa6403efeebeafe568fdb230e8c590a275fba2ba978dd112efcf6e9" +checksum = "593db20e4c51f62d3284bae7ee718849c3214f93a3b94ea1899ad85ba119d330" dependencies = [ - "cap-primitives 2.0.0", - "io-extras 0.18.0", - "io-lifetimes 2.0.2", - "rustix 0.38.30", + "cap-primitives 2.0.1", + "io-extras 0.18.1", + "io-lifetimes 2.0.3", + "rustix 0.38.31", ] [[package]] name = "cap-time-ext" -version = "2.0.0" +version = "2.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f8f52b3c8f4abfe3252fd0a071f3004aaa3b18936ec97bdbd8763ce03aff6247" +checksum = "03261630f291f425430a36f38c847828265bc928f517cdd2004c56f4b02f002b" dependencies = [ - "cap-primitives 2.0.0", + "ambient-authority", + "cap-primitives 2.0.1", + "iana-time-zone", "once_cell", - "rustix 0.38.30", - "winx 0.36.2", + "rustix 0.38.31", + "winx 0.36.3", ] [[package]] @@ -311,9 +323,9 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "clap" -version = "4.4.4" +version = "4.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b1d7b8d5ec32af0fadc644bf1fd509a688c2103b185644bb1e29d164e0703136" +checksum = "80c21025abd42669a92efc996ef13cfb2c5c627858421ea58d5c3b331a6c134f" dependencies = [ "clap_builder", "clap_derive", @@ -321,9 +333,9 @@ dependencies = [ [[package]] name = "clap_builder" -version = "4.4.4" +version = "4.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5179bb514e4d7c2051749d8fcefa2ed6d06a9f4e6d69faf3805f5d80b8cf8d56" +checksum = "458bf1f341769dfcf849846f65dffdf9146daa56bcd2a47cb4e1de9915567c99" dependencies = [ "anstream", "anstyle", @@ -333,21 +345,21 @@ dependencies = [ [[package]] name = "clap_derive" -version = "4.4.2" +version = "4.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0862016ff20d69b84ef8247369fabf5c008a7417002411897d40ee1f4532b873" +checksum = "307bc0538d5f0f83b8248db3087aa92fe504e4691294d0c96c0eabc33f47ba47" dependencies = [ "heck 0.4.1", "proc-macro2", "quote", - "syn 2.0.37", + "syn 2.0.48", ] [[package]] name = "clap_lex" -version = "0.5.1" +version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cd7cc57abe963c6d3b9d8be5b06ba7c8957a930305ca90304f24ef040aa6f961" +checksum = "98cc8fbded0c607b7ba9dd60cd98df59af97e84d24e49c8557331cfc26d301ce" [[package]] name = "codespan-reporting" @@ -365,6 +377,12 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "acbf1af155f9b9ef647e42cdc158db4b64a1b61f743629225fde6f3e0be2a7c7" +[[package]] +name = "core-foundation-sys" +version = "0.8.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "06ea2b9bc92be3c2baa9334a323ebca2d6f074ff852cd1d7b11064035cd3868f" + [[package]] name = "cpp_demangle" version = "0.3.5" @@ -376,27 +394,27 @@ dependencies = [ [[package]] name = "cpufeatures" -version = "0.2.9" +version = "0.2.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a17b76ff3a4162b0b27f354a0c87015ddad39d35f9c0c36607a3bdd175dde1f1" +checksum = "53fe5e26ff1b7aef8bca9c6080520cfb8d9333c7568e1829cef191a9723e5504" dependencies = [ "libc", ] [[package]] name = "cranelift-bforest" -version = "0.103.0" +version = "0.104.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7c22542c0b95bd3302f7ed6839869c561f2324bac2fd5e7e99f5cfa65fdc8b92" +checksum = "7e7c0d51205b863591dd1e7aaa0fb69c2ea7bed48ffa63d6c4a848b07a35a732" dependencies = [ "cranelift-entity", ] [[package]] name = "cranelift-codegen" -version = "0.103.0" +version = "0.104.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6b3db903ef2e9c8a4de2ea6db5db052c7857282952f9df604aa55d169e6000d8" +checksum = "9ffb467cbc25543e4c20d2ad669bf8275598047b03c89652ad5fe2a0f47fc0e1" dependencies = [ "bumpalo", "cranelift-bforest", @@ -405,8 +423,8 @@ dependencies = [ "cranelift-control", "cranelift-entity", "cranelift-isle", - "gimli 0.28.0", - "hashbrown 0.14.0", + "gimli 0.28.1", + "hashbrown 0.14.3", "log", "regalloc2", "smallvec", @@ -415,33 +433,33 @@ dependencies = [ [[package]] name = "cranelift-codegen-meta" -version = "0.103.0" +version = "0.104.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6590feb5a1d6438f974bf6a5ac4dddf69fca14e1f07f3265d880f69e61a94463" +checksum = "bc7e74aed5c2b91e38d090653506afbd2cd3be1ff70593e2aa6bb82b3c6b77ff" dependencies = [ "cranelift-codegen-shared", ] [[package]] name = "cranelift-codegen-shared" -version = "0.103.0" +version = "0.104.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7239038c56fafe77fddc8788fc8533dd6c474dc5bdc5637216404f41ba807330" +checksum = "9ff2dd24cce0775566da85770cb48aa58fef901cf2bff30275b42e7dbe62cbd5" [[package]] name = "cranelift-control" -version = "0.103.0" +version = "0.104.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f7dc9c595341404d381d27a3d950160856b35b402275f0c3990cd1ad683c8053" +checksum = "e8bcf4d5c73bbca309edf3af2839b5218e5c74cfbf22b0ac492af8a1d11120d9" dependencies = [ "arbitrary", ] [[package]] name = "cranelift-entity" -version = "0.103.0" +version = "0.104.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "44e3ee532fc4776c69bcedf7e62f9632cbb3f35776fa9a525cdade3195baa3f7" +checksum = "286754159b1a685475d6a0b4710832f950d6f4846a817002e2c23ff001321a65" dependencies = [ "serde", "serde_derive", @@ -449,9 +467,9 @@ dependencies = [ [[package]] name = "cranelift-frontend" -version = "0.103.0" +version = "0.104.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a612c94d09e653662ec37681dc2d6fd2b9856e6df7147be0afc9aabb0abf19df" +checksum = "67150a1fef9857caba710f8c0c8223d640f02c0e5d1ebbfc75ed62912599cb6b" dependencies = [ "cranelift-codegen", "log", @@ -461,15 +479,15 @@ dependencies = [ [[package]] name = "cranelift-isle" -version = "0.103.0" +version = "0.104.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "85db9830abeb1170b7d29b536ffd55af1d4d26ac8a77570b5d1aca003bf225cc" +checksum = "eb7ceea70d3e0d7f69df7657f99de902e32016731c5a8d2788c1df0215f00952" [[package]] name = "cranelift-native" -version = "0.103.0" +version = "0.104.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "301ef0edafeaeda5771a5d2db64ac53e1818ae3111220a185677025fe91db4a1" +checksum = "707e5d9384ce4fa3c40af1abf4c3ec49857745cced5187593385f4a2c0b95445" dependencies = [ "cranelift-codegen", "libc", @@ -478,9 +496,9 @@ dependencies = [ [[package]] name = "cranelift-wasm" -version = "0.103.0" +version = "0.104.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "380f0abe8264e4570ac615fc31cef32a3b90a77f7eb97b08331f9dd357b1f500" +checksum = "d4d957e3ff2a14c2f974a66c22bfcedcd2bd0272af8dce4236869c3942f5a471" dependencies = [ "cranelift-codegen", "cranelift-entity", @@ -488,51 +506,43 @@ dependencies = [ "itertools", "log", "smallvec", - "wasmparser 0.118.1", + "wasmparser 0.118.2", "wasmtime-types", ] [[package]] name = "crc32fast" -version = "1.3.2" +version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b540bd8bc810d3885c6ea91e2018302f68baba2129ab3e88f32389ee9370880d" +checksum = "b3855a8a784b474f333699ef2bbca9db2c4a1f6d9088a90a2d25b1eb53111eaa" dependencies = [ "cfg-if", ] [[package]] name = "crossbeam-deque" -version = "0.8.3" +version = "0.8.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ce6fd6f855243022dcecf8702fef0c297d4338e226845fe067f6341ad9fa0cef" +checksum = "613f8cc01fe9cf1a3eb3d7f488fd2fa8388403e97039e2f73692932e291a770d" dependencies = [ - "cfg-if", "crossbeam-epoch", "crossbeam-utils", ] [[package]] name = "crossbeam-epoch" -version = "0.9.15" +version = "0.9.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae211234986c545741a7dc064309f67ee1e5ad243d0e48335adc0484d960bcc7" +checksum = "5b82ac4a3c2ca9c3460964f020e1402edd5753411d7737aa39c3714ad1b5420e" dependencies = [ - "autocfg", - "cfg-if", "crossbeam-utils", - "memoffset", - "scopeguard", ] [[package]] name = "crossbeam-utils" -version = "0.8.16" +version = "0.8.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5a22b2d63d4d1dc0b7f1b6b2747dd0088008a9be28b6ddf0b1e7d335e3037294" -dependencies = [ - "cfg-if", -] +checksum = "248e3bacc7dc6baa3b21e405ee045c3047101a49145e7e9eca583ab4c2ca5345" [[package]] name = "crypto-common" @@ -546,9 +556,9 @@ dependencies = [ [[package]] name = "cxx" -version = "1.0.107" +version = "1.0.116" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bbe98ba1789d56fb3db3bee5e032774d4f421b685de7ba703643584ba24effbe" +checksum = "8aff472b83efd22bfc0176aa8ba34617dd5c17364670eb201a5f06d339b8abf7" dependencies = [ "cc", "cxxbridge-flags", @@ -558,9 +568,9 @@ dependencies = [ [[package]] name = "cxx-build" -version = "1.0.107" +version = "1.0.116" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c4ce20f6b8433da4841b1dadfb9468709868022d829d5ca1f2ffbda928455ea3" +checksum = "bcf6e7a52c19013a9a0ec421c7d9c2d1125faf333551227e0a017288d71b47c3" dependencies = [ "cc", "codespan-reporting", @@ -568,24 +578,24 @@ dependencies = [ "proc-macro2", "quote", "scratch", - "syn 2.0.37", + "syn 2.0.48", ] [[package]] name = "cxxbridge-flags" -version = "1.0.107" +version = "1.0.116" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "20888d9e1d2298e2ff473cee30efe7d5036e437857ab68bbfea84c74dba91da2" +checksum = "589e83d02fc1d4fb78f5ad56ca08835341e23499d086d2821315869426d618dc" [[package]] name = "cxxbridge-macro" -version = "1.0.107" +version = "1.0.116" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2fa16a70dd58129e4dfffdff535fb1bce66673f7bbeec4a5a1765a504e1ccd84" +checksum = "e2cb1fd8ffae4230c7cfbbaf3698dbeaf750fa8c5dadf7ed897df581b9b572a5" dependencies = [ "proc-macro2", "quote", - "syn 2.0.37", + "syn 2.0.48", ] [[package]] @@ -659,9 +669,9 @@ dependencies = [ [[package]] name = "either" -version = "1.9.0" +version = "1.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a26ae43d7bcc3b814de94796a5e736d4029efb0ee900c12e2d54c993ad1a1e07" +checksum = "11157ac094ffbdde99aa67b23417ebdd801842852b500e395a45a9c0aac03e4a" [[package]] name = "encoding_rs" @@ -702,19 +712,19 @@ checksum = "2acce4a10f12dc2fb14a218589d4f1f62ef011b2d0cc4b3cb1bba8e94da14649" [[package]] name = "fastrand" -version = "2.0.0" +version = "2.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6999dc1837253364c2ebb0704ba97994bd874e8f195d665c50b7548f6ea92764" +checksum = "25cbce373ec4653f1a01a31e8a5e5ec0c622dc27ff9c4e6606eefef5cbbed4a5" [[package]] name = "fd-lock" -version = "4.0.0" +version = "4.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b0377f1edc77dbd1118507bc7a66e4ab64d2b90c66f90726dc801e73a8c68f9" +checksum = "7e5768da2206272c81ef0b5e951a41862938a6070da63bcea197899942d3b947" dependencies = [ "cfg-if", - "rustix 0.38.30", - "windows-sys 0.48.0", + "rustix 0.38.31", + "windows-sys 0.52.0", ] [[package]] @@ -733,9 +743,9 @@ checksum = "0ce7134b9999ecaf8bcd65542e436736ef32ddca1b3e06094cb6ec5755203b80" [[package]] name = "form_urlencoded" -version = "1.2.0" +version = "1.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a62bc1cf6f830c2ec14a513a9fb124d0a213a629668a4186f329db21fe045652" +checksum = "e13624c2627564efccf4934284bdd98cbaa14e79b0b5a141218e507b3a823456" dependencies = [ "percent-encoding", ] @@ -747,26 +757,26 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6d167b646a876ba8fda6b50ac645cfd96242553cbaf0ca4fccaa39afcbf0801f" dependencies = [ "io-lifetimes 1.0.11", - "rustix 0.38.30", + "rustix 0.38.31", "windows-sys 0.48.0", ] [[package]] name = "fs-set-times" -version = "0.20.0" +version = "0.20.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dd738b84894214045e8414eaded76359b4a5773f0a0a56b16575110739cdcf39" +checksum = "033b337d725b97690d86893f9de22b67b80dcc4e9ad815f348254c38119db8fb" dependencies = [ - "io-lifetimes 2.0.2", - "rustix 0.38.30", - "windows-sys 0.48.0", + "io-lifetimes 2.0.3", + "rustix 0.38.31", + "windows-sys 0.52.0", ] [[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", @@ -778,9 +788,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", @@ -788,33 +798,33 @@ 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-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-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-core", "futures-sink", @@ -865,9 +875,9 @@ dependencies = [ [[package]] name = "getrandom" -version = "0.2.10" +version = "0.2.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "be4136b2a15dd319360be1c07d9933517ccf0be8f16bf62a3bee4f0d618df427" +checksum = "190092ea657667030ac6a35e305e62fc4dd69fd98ac98631e5d3a2b1575a12b5" dependencies = [ "cfg-if", "libc", @@ -887,12 +897,12 @@ dependencies = [ [[package]] name = "gimli" -version = "0.28.0" +version = "0.28.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6fb8d784f27acf97159b40fc4db5ecd8aa23b9ad5ef69cdd136d3bc80665f0c0" +checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253" dependencies = [ "fallible-iterator 0.3.0", - "indexmap 2.0.0", + "indexmap 2.2.3", "stable_deref_trait", ] @@ -913,9 +923,9 @@ dependencies = [ [[package]] name = "hashbrown" -version = "0.14.0" +version = "0.14.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2c6201b9ff9fd90a5a3bac2e56a830d0caa509576f0e503818ee82c181b3437a" +checksum = "290f1a1d9242c78d09ce40a5e87e7554ee637af1351968159f4952f028f75604" dependencies = [ "ahash", ] @@ -940,9 +950,32 @@ dependencies = [ [[package]] name = "hermit-abi" -version = "0.3.3" +version = "0.3.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bd5256b483761cd23699d0da46cc6fd2ee3be420bbe6d020ae4a091e70b7e9fd" + +[[package]] +name = "iana-time-zone" +version = "0.1.60" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d77f7ec81a6d05a3abb01ab6eb7590f6083d08449fe5a1c8b1e620283546ccb7" +checksum = "e7ffbb5a1b541ea2561f8c41c087286cc091e21e556a4f09a8f6cbf17b69b141" +dependencies = [ + "android_system_properties", + "core-foundation-sys", + "iana-time-zone-haiku", + "js-sys", + "wasm-bindgen", + "windows-core", +] + +[[package]] +name = "iana-time-zone-haiku" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f31827a206f56af32e590ba56d5d2d085f558508192593743f16b2306495269f" +dependencies = [ + "cc", +] [[package]] name = "id-arena" @@ -952,9 +985,9 @@ checksum = "25a2bc672d1148e28034f176e01fffebb08b35768468cc954630da77a1449005" [[package]] name = "idna" -version = "0.4.0" +version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7d20d6b07bfbc108882d88ed8e37d39636dcc260e15e30c45e6ba089610b917c" +checksum = "634d9b1461af396cad843f47fdba5597a4f9e6ddd4bfb6ff5d85028c25cb12f6" dependencies = [ "unicode-bidi", "unicode-normalization", @@ -986,12 +1019,12 @@ dependencies = [ [[package]] name = "indexmap" -version = "2.0.0" +version = "2.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d5477fe2230a79769d8dc68e0eabf5437907c0457a5614a9e8dddb67f65eb65d" +checksum = "233cf39063f058ea2caae4091bf4a3ef70a653afbc026f5c4a4135d114e3c177" dependencies = [ "equivalent", - "hashbrown 0.14.0", + "hashbrown 0.14.3", "serde", ] @@ -1007,12 +1040,12 @@ dependencies = [ [[package]] name = "io-extras" -version = "0.18.0" +version = "0.18.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9d3c230ee517ee76b1cc593b52939ff68deda3fae9e41eca426c6b4993df51c4" +checksum = "c301e73fb90e8a29e600a9f402d095765f74310d582916a952f618836a1bd1ed" dependencies = [ - "io-lifetimes 2.0.2", - "windows-sys 0.48.0", + "io-lifetimes 2.0.3", + "windows-sys 0.52.0", ] [[package]] @@ -1028,15 +1061,15 @@ dependencies = [ [[package]] name = "io-lifetimes" -version = "2.0.2" +version = "2.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bffb4def18c48926ccac55c1223e02865ce1a821751a95920448662696e7472c" +checksum = "5a611371471e98973dbcab4e0ec66c31a10bc356eeb4d54a0e05eac8158fe38c" [[package]] name = "ipnet" -version = "2.8.0" +version = "2.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "28b29a3cd74f0f4598934efe3aeba42bae0eb4680554128851ebbecb02af14e6" +checksum = "8f518f335dce6725a761382244631d86cf0ccb2863413590b31338feb467f9c3" [[package]] name = "itertools" @@ -1049,9 +1082,9 @@ dependencies = [ [[package]] name = "itoa" -version = "1.0.9" +version = "1.0.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "af150ab688ff2122fcef229be89cb50dd66af9e01a4ff320cc137eecc9bacc38" +checksum = "b1a46d1a171d865aa5f83f92695765caa047a9b4cbae2cbf37dbd613a793fd4c" [[package]] name = "ittapi" @@ -1075,13 +1108,22 @@ dependencies = [ [[package]] name = "jobserver" -version = "0.1.26" +version = "0.1.28" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "936cfd212a0155903bcbc060e316fb6cc7cbf2e1907329391ebadc1fe0ce77c2" +checksum = "ab46a6e9526ddef3ae7f787c06f0f2600639ba80ea3eade3d8e670a2230f51d6" dependencies = [ "libc", ] +[[package]] +name = "js-sys" +version = "0.3.68" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "406cda4b368d531c842222cf9d2600a9a4acce8d29423695379c6868a143a9ee" +dependencies = [ + "wasm-bindgen", +] + [[package]] name = "leb128" version = "0.2.5" @@ -1090,9 +1132,20 @@ checksum = "884e2677b40cc8c339eaefcb701c32ef1fd2493d71118dc0ca4b6a736c93bd67" [[package]] name = "libc" -version = "0.2.152" +version = "0.2.153" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "13e3bf6590cbc649f4d1a3eefc9d5d6eb746f5200ffb04e5e142700b8faa56e7" +checksum = "9c198f91728a82281a64e1f4f9eeb25d82cb32a5de251c6bd1b5154d63a8e7bd" + +[[package]] +name = "libredox" +version = "0.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85c833ca1e66078851dba29046874e38f08b2c883700aa29a03ddd3b23814ee8" +dependencies = [ + "bitflags 2.4.2", + "libc", + "redox_syscall", +] [[package]] name = "link-cplusplus" @@ -1138,9 +1191,9 @@ checksum = "4facc753ae494aeb6e3c22f839b158aebd4f9270f55cd3c79906c45476c47ab4" [[package]] name = "memchr" -version = "2.6.3" +version = "2.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f232d6ef707e1956a43342693d2a31e72989554d58299d7a88738cc95b0d35c" +checksum = "523dc4f511e55ab87b694dc30d0f820d60906ef06413f93d4d7a1385599cc149" [[package]] name = "memfd" @@ -1148,7 +1201,7 @@ version = "0.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b2cffa4ad52c6f791f4f8b15f0c05f9824b2ced1160e88cc393d64fff9a8ac64" dependencies = [ - "rustix 0.38.30", + "rustix 0.38.31", ] [[package]] @@ -1162,18 +1215,18 @@ dependencies = [ [[package]] name = "miniz_oxide" -version = "0.7.1" +version = "0.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e7810e0be55b428ada41041c41f32c9f1a42817901b4ccf45fa3d4b6561e74c7" +checksum = "9d811f3e15f28568be3407c8e7fdb6514c1cda3cb30683f15b6a1a1dc4ea14a7" dependencies = [ "adler", ] [[package]] name = "mio" -version = "0.8.8" +version = "0.8.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "927a765cd3fc26206e66b296465fa9d3e5ab003e651c1b3c060e7956d96b19d2" +checksum = "8f3d0b296e374a4e6f3c7b0a1f5a51d748a0d34c85e7dc48fc3fa9a87657fe09" dependencies = [ "libc", "wasi", @@ -1192,21 +1245,21 @@ dependencies = [ [[package]] name = "object" -version = "0.32.1" +version = "0.32.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9cf5f9dd3933bd50a9e1f149ec995f39ae2c496d31fd772c1fd45ebc27e902b0" +checksum = "a6a622008b6e321afc04970976f62ee297fdbaa6f95318ca343e3eebb9648441" dependencies = [ "crc32fast", - "hashbrown 0.14.0", - "indexmap 2.0.0", + "hashbrown 0.14.3", + "indexmap 2.2.3", "memchr", ] [[package]] name = "once_cell" -version = "1.18.0" +version = "1.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dd8b5dd2ae5ed71462c540258bedcb51965123ad7e7ccf4b9a8cafaa4a63576d" +checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" [[package]] name = "paste" @@ -1216,9 +1269,9 @@ checksum = "de3145af08024dea9fa9914f381a17b8fc6034dfb00f3a84013f7ff43f29ed4c" [[package]] name = "percent-encoding" -version = "2.3.0" +version = "2.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9b2a4787296e9989611394c33f193f676704af1686e70b8f8033ab5ba9a35a94" +checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e" [[package]] name = "petgraph" @@ -1227,7 +1280,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e1d3afd2628e69da2be385eb6f2fd57c8ac7977ceeff6dc166ff1657b0e386a9" dependencies = [ "fixedbitset", - "indexmap 2.0.0", + "indexmap 2.2.3", ] [[package]] @@ -1244,9 +1297,9 @@ checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" [[package]] name = "pkg-config" -version = "0.3.27" +version = "0.3.29" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "26072860ba924cbfa98ea39c8c19b4dd6a4a25423dbdf219c1eca91aa0cf6964" +checksum = "2900ede94e305130c13ddd391e0ab7cbaeb783945ae07a279c268cb05109c6cb" [[package]] name = "ppv-lite86" @@ -1256,9 +1309,9 @@ checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" [[package]] name = "proc-macro2" -version = "1.0.67" +version = "1.0.78" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3d433d9f1a3e8c1263d9456598b16fec66f4acc9a74dacffd35c7bb09b3a1328" +checksum = "e2422ad645d89c99f8f3e6b88a9fdeca7fabeac836b1002371c4367c8f984aae" dependencies = [ "unicode-ident", ] @@ -1274,9 +1327,9 @@ dependencies = [ [[package]] name = "quote" -version = "1.0.33" +version = "1.0.35" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5267fca4496028628a95160fc423a33e8b2e6af8a5302579e322e4b520293cae" +checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef" dependencies = [ "proc-macro2", ] @@ -1322,9 +1375,9 @@ dependencies = [ [[package]] name = "rayon" -version = "1.8.0" +version = "1.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c27db03db7734835b3f53954b534c91069375ce6ccaa2e065441e07d9b6cdb1" +checksum = "fa7237101a77a10773db45d62004a272517633fbcc3df19d96455ede1122e051" dependencies = [ "either", "rayon-core", @@ -1332,9 +1385,9 @@ dependencies = [ [[package]] name = "rayon-core" -version = "1.12.0" +version = "1.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5ce3fb6ad83f861aac485e76e1985cd109d9a3713802152be56c3b1f0e0658ed" +checksum = "1465873a3dfdaa8ae7cb14b4383657caab0b3e8a0aa9ae8e04b044854c8dfce2" dependencies = [ "crossbeam-deque", "crossbeam-utils", @@ -1342,30 +1395,21 @@ dependencies = [ [[package]] name = "redox_syscall" -version = "0.2.16" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fb5a58c1855b4b6819d59012155603f0b22ad30cad752600aadfcb695265519a" -dependencies = [ - "bitflags 1.3.2", -] - -[[package]] -name = "redox_syscall" -version = "0.3.5" +version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "567664f262709473930a4bf9e51bf2ebf3348f2e748ccc50dea20646858f8f29" +checksum = "4722d768eff46b75989dd134e5c353f0d6296e5aaa3132e776cbdb56be7731aa" dependencies = [ "bitflags 1.3.2", ] [[package]] name = "redox_users" -version = "0.4.3" +version = "0.4.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b033d837a7cf162d7993aded9304e30a83213c648b6e389db233191f891e5c2b" +checksum = "a18479200779601e498ada4e8c1e1f50e3ee19deb0259c25825a98b5603b2cb4" dependencies = [ "getrandom", - "redox_syscall 0.2.16", + "libredox", "thiserror", ] @@ -1396,9 +1440,9 @@ checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" [[package]] name = "rustix" -version = "0.37.23" +version = "0.37.27" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4d69718bf81c6127a49dc64e44a742e8bb9213c0ff8869a22c308f84c1d4ab06" +checksum = "fea8ca367a3a01fe35e6943c400addf443c0f57670e6ec51196f71a4b8762dd2" dependencies = [ "bitflags 1.3.2", "errno", @@ -1412,9 +1456,9 @@ dependencies = [ [[package]] name = "rustix" -version = "0.38.30" +version = "0.38.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "322394588aaf33c24007e8bb3238ee3e4c5c09c084ab32bc73890b99ff326bca" +checksum = "6ea3e1a662af26cd7a3ba09c0297a31af215563ecf42817c98df621387f4e949" dependencies = [ "bitflags 2.4.2", "errno", @@ -1433,15 +1477,9 @@ checksum = "7ffc183a10b4478d04cbbbfc96d0873219d962dd5accaff2ffbd4ceb7df837f4" [[package]] name = "ryu" -version = "1.0.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1ad4cc8da4ef723ed60bced201181d83791ad433213d8c24efffda1eec85d741" - -[[package]] -name = "scopeguard" -version = "1.2.0" +version = "1.0.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" +checksum = "f98d2aa92eebf49b69786be48e4477826b256916e84a57ff2a4f21923b48eb4c" [[package]] name = "scratch" @@ -1451,35 +1489,35 @@ checksum = "a3cf7c11c38cb994f3d40e8a8cde3bbd1f72a435e4c49e85d6553d8312306152" [[package]] name = "semver" -version = "1.0.18" +version = "1.0.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b0293b4b29daaf487284529cc2f5675b8e57c61f70167ba415a463651fd6a918" +checksum = "b97ed7a9823b74f99c7742f5336af7be5ecd3eeafcb1507d1fa93347b1d589b0" [[package]] name = "serde" -version = "1.0.188" +version = "1.0.196" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf9e0fcba69a370eed61bcf2b728575f726b50b55cba78064753d708ddc7549e" +checksum = "870026e60fa08c69f064aa766c10f10b1d62db9ccd4d0abb206472bee0ce3b32" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.188" +version = "1.0.196" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4eca7ac642d82aa35b60049a6eccb4be6be75e599bd2e9adb5f875a737654af2" +checksum = "33c85360c95e7d137454dc81d9a4ed2b8efd8fbe19cee57357b32b9771fccb67" dependencies = [ "proc-macro2", "quote", - "syn 2.0.37", + "syn 2.0.48", ] [[package]] name = "serde_json" -version = "1.0.107" +version = "1.0.113" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6b420ce6e3d8bd882e9b243c6eed35dbc9a6110c9769e74b584e0d68d1f20c65" +checksum = "69801b70b1c3dac963ecb03a364ba0ceda9cf60c71cfe475e99864759c8b8a79" dependencies = [ "itoa", "ryu", @@ -1488,20 +1526,20 @@ dependencies = [ [[package]] name = "serde_spanned" -version = "0.6.3" +version = "0.6.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "96426c9936fd7a0124915f9185ea1d20aa9445cc9821142f0a73bc9207a2e186" +checksum = "eb3622f419d1296904700073ea6cc23ad690adbd66f13ea683df73298736f0c1" dependencies = [ "serde", ] [[package]] name = "serde_yaml" -version = "0.9.25" +version = "0.9.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1a49e178e4452f45cb61d0cd8cebc1b0fafd3e41929e996cef79aa3aca91f574" +checksum = "adf8a49373e98a4c5f0ceb5d05aa7c648d75f63774981ed95b7c7443bbd50c6e" dependencies = [ - "indexmap 2.0.0", + "indexmap 2.2.3", "itoa", "ryu", "serde", @@ -1510,9 +1548,9 @@ dependencies = [ [[package]] name = "sha2" -version = "0.10.7" +version = "0.10.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "479fb9d862239e610720565ca91403019f2f00410f1864c5aa7479b950a76ed8" +checksum = "793db75ad2bcafc3ffa7c68b215fee268f537982cd901d132f89c6343f3a3dc8" dependencies = [ "cfg-if", "cpufeatures", @@ -1546,15 +1584,15 @@ checksum = "826167069c09b99d56f31e9ae5c99049e932a98c9dc2dac47645b08dbbf76ba7" [[package]] name = "smallvec" -version = "1.11.1" +version = "1.13.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "942b4a808e05215192e39f4ab80813e599068285906cc91aa64f923db842bd5a" +checksum = "e6ecd384b10a64542d77071bd64bd7b231f4ed5940fba55e98c3de13824cf3d7" [[package]] name = "socket2" -version = "0.5.4" +version = "0.5.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4031e820eb552adee9295814c0ced9e5cf38ddf1e8b7d566d6de8e2538ea989e" +checksum = "7b5fac59a5cb5dd637972e5fca70daf0523c9067fcdc4842f053dae04a18f8e9" dependencies = [ "libc", "windows-sys 0.48.0", @@ -1562,9 +1600,9 @@ dependencies = [ [[package]] name = "spdx" -version = "0.10.2" +version = "0.10.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b19b32ed6d899ab23174302ff105c1577e45a06b08d4fe0a9dd13ce804bbbf71" +checksum = "62bde1398b09b9f93fc2fc9b9da86e362693e999d3a54a8ac47a99a5a73f638b" dependencies = [ "smallvec", ] @@ -1591,9 +1629,9 @@ dependencies = [ [[package]] name = "strsim" -version = "0.10.0" +version = "0.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" +checksum = "5ee073c9e4cd00e28217186dbe12796d692868f432bf2e97ee73bed0c56dfa01" [[package]] name = "strum" @@ -1627,9 +1665,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.37" +version = "2.0.48" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7303ef2c05cd654186cb250d29049a24840ca25d2747c25c0381c8d9e2f582e8" +checksum = "0f3531638e407dfc0814761abb7c00a5b54992b849452a0646b7f65c9f770f3f" dependencies = [ "proc-macro2", "quote", @@ -1638,18 +1676,18 @@ dependencies = [ [[package]] name = "system-interface" -version = "0.26.0" +version = "0.26.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "27ce32341b2c0b70c144bbf35627fdc1ef18c76ced5e5e7b3ee8b5ba6b2ab6a0" +checksum = "0682e006dd35771e392a6623ac180999a9a854b1d4a6c12fb2e804941c2b1f58" dependencies = [ "bitflags 2.4.2", "cap-fs-ext", - "cap-std 2.0.0", + "cap-std 2.0.1", "fd-lock", - "io-lifetimes 2.0.2", - "rustix 0.38.30", - "windows-sys 0.48.0", - "winx 0.36.2", + "io-lifetimes 2.0.3", + "rustix 0.38.31", + "windows-sys 0.52.0", + "winx 0.36.3", ] [[package]] @@ -1660,44 +1698,43 @@ checksum = "69758bda2e78f098e4ccb393021a0963bb3442eac05f135c30f61b7370bbafae" [[package]] name = "tempfile" -version = "3.8.0" +version = "3.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cb94d2f3cc536af71caac6b6fcebf65860b347e7ce0cc9ebe8f70d3e521054ef" +checksum = "a365e8cd18e44762ef95d87f284f4b5cd04107fec2ff3052bd6a3e6069669e67" dependencies = [ "cfg-if", "fastrand", - "redox_syscall 0.3.5", - "rustix 0.38.30", - "windows-sys 0.48.0", + "rustix 0.38.31", + "windows-sys 0.52.0", ] [[package]] name = "termcolor" -version = "1.3.0" +version = "1.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6093bad37da69aab9d123a8091e4be0aa4a03e4d601ec641c327398315f62b64" +checksum = "06794f8f6c5c898b3275aebefa6b8a1cb24cd2c6c79397ab15774837a0bc5755" dependencies = [ "winapi-util", ] [[package]] name = "thiserror" -version = "1.0.48" +version = "1.0.57" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9d6d7a740b8a666a7e828dd00da9c0dc290dff53154ea77ac109281de90589b7" +checksum = "1e45bcbe8ed29775f228095caf2cd67af7a4ccf756ebff23a306bf3e8b47b24b" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.48" +version = "1.0.57" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49922ecae66cc8a249b77e68d1d0623c1b2c514f0060c27cdc68bd62a1219d35" +checksum = "a953cb265bef375dae3de6663da4d3804eee9682ea80d8e2542529b73c531c81" dependencies = [ "proc-macro2", "quote", - "syn 2.0.37", + "syn 2.0.48", ] [[package]] @@ -1717,9 +1754,9 @@ checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" [[package]] name = "tokio" -version = "1.32.0" +version = "1.36.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "17ed6077ed6cd6c74735e21f37eb16dc3935f96878b1fe961074089cc80893f9" +checksum = "61285f6515fa018fb2d1e46eb21223fff441ee8db5d0f1435e8ab4f5cdb80931" dependencies = [ "backtrace", "bytes", @@ -1734,13 +1771,13 @@ dependencies = [ [[package]] name = "tokio-macros" -version = "2.1.0" +version = "2.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "630bdcf245f78637c13ec01ffae6187cca34625e8c63150d424b59e55af2675e" +checksum = "5b8a1e28f2deaa14e508979454cb3a223b10b938b45af148bc0986de36f1923b" dependencies = [ "proc-macro2", "quote", - "syn 2.0.37", + "syn 2.0.48", ] [[package]] @@ -1754,9 +1791,9 @@ dependencies = [ [[package]] name = "toml" -version = "0.7.8" +version = "0.8.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dd79e69d3b627db300ff956027cc6c3798cef26d22526befdfcd12feeb6d2257" +checksum = "9a9aad4a3066010876e8dcf5a8a06e70a558751117a145c6ce2b82c2e2054290" dependencies = [ "serde", "serde_spanned", @@ -1766,20 +1803,20 @@ dependencies = [ [[package]] name = "toml_datetime" -version = "0.6.3" +version = "0.6.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7cda73e2f1397b1262d6dfdcef8aafae14d1de7748d66822d3bfeeb6d03e5e4b" +checksum = "3550f4e9685620ac18a50ed434eb3aec30db8ba93b0287467bca5826ea25baf1" dependencies = [ "serde", ] [[package]] name = "toml_edit" -version = "0.19.15" +version = "0.22.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1b5bb770da30e5cbfde35a2d7b9b8a2c4b8ef89548a7a6aeab5c9a576e3e7421" +checksum = "99e68c159e8f5ba8a28c4eb7b0c0c190d77bb479047ca713270048145a9ad28a" dependencies = [ - "indexmap 2.0.0", + "indexmap 2.2.3", "serde", "serde_spanned", "toml_datetime", @@ -1788,11 +1825,10 @@ dependencies = [ [[package]] name = "tracing" -version = "0.1.37" +version = "0.1.40" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ce8c33a8d48bd45d624a6e523445fd21ec13d3653cd51f681abf67418f54eb8" +checksum = "c3523ab5a71916ccf420eebdf5521fcef02141234bbc0b8a49f2fdc4544364ef" dependencies = [ - "cfg-if", "log", "pin-project-lite", "tracing-attributes", @@ -1801,20 +1837,20 @@ dependencies = [ [[package]] name = "tracing-attributes" -version = "0.1.26" +version = "0.1.27" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5f4f31f56159e98206da9efd823404b79b6ef3143b4a7ab76e67b1751b25a4ab" +checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.37", + "syn 2.0.48", ] [[package]] name = "tracing-core" -version = "0.1.31" +version = "0.1.32" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0955b8137a1df6f1a2e9a37d8a6656291ff0297c1a97c24e0d8425fe2312f79a" +checksum = "c06d3da6113f116aaee68e4d601191614c9053067f9ab7f6edbcb161237daa54" dependencies = [ "once_cell", ] @@ -1827,9 +1863,9 @@ checksum = "42ff0bf0c66b8238c6f3b578df37d0b7848e55df8577b3f74f92a69acceeb825" [[package]] name = "unicode-bidi" -version = "0.3.13" +version = "0.3.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "92888ba5573ff080736b3648696b70cafad7d250551175acbaa4e0385b3e1460" +checksum = "08f95100a766bf4f8f28f90d77e0a5461bbdb219042e7679bebe79004fed8d75" [[package]] name = "unicode-ident" @@ -1848,9 +1884,9 @@ dependencies = [ [[package]] name = "unicode-segmentation" -version = "1.10.1" +version = "1.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1dd624098567895118886609431a7c3b8f516e41d30e0643f03d94592a147e36" +checksum = "d4c87d22b6e3f4a18d4d40ef354e97c90fcb14dd91d7dc0aa9d8a1172ebf7202" [[package]] name = "unicode-width" @@ -1866,15 +1902,15 @@ checksum = "f962df74c8c05a667b5ee8bcf162993134c104e96440b663c8daa176dc772d8c" [[package]] name = "unsafe-libyaml" -version = "0.2.9" +version = "0.2.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f28467d3e1d3c6586d8f25fa243f544f5800fec42d97032474e17222c2b75cfa" +checksum = "ab4c90930b95a82d00dc9e9ac071b4991924390d46cbd0dfe566148667605e4b" [[package]] name = "url" -version = "2.4.1" +version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "143b538f18257fac9cad154828a57c6bf5157e1aa604d4816b5995bf6de87ae5" +checksum = "31e6302e3bb753d46e83516cae55ae196fc0c309407cf11ab35cc51a4c2a4633" dependencies = [ "form_urlencoded", "idna", @@ -1889,9 +1925,9 @@ checksum = "711b9620af191e0cdc7468a8d14e709c3dcdb115b36f838e601583af800a370a" [[package]] name = "uuid" -version = "1.4.1" +version = "1.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "79daa5ed5740825c40b389c5e50312b9c86df53fccd33f281df655642b43869d" +checksum = "f00cc9702ca12d3c81455259621e676d0f7251cec66a21e98fe2e9a37db93b2a" [[package]] name = "version_check" @@ -1943,45 +1979,45 @@ checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" [[package]] name = "wasi-cap-std-sync" -version = "16.0.0" +version = "17.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "154528979a211aa28d969846e883df75705809ed9bcc70aba61460683ea7355b" +checksum = "025e842ba390587e523785ff58bd54fbbf1781b8d3072bc9aba4dc0b809f69da" dependencies = [ "anyhow", "async-trait", "cap-fs-ext", "cap-rand", - "cap-std 2.0.0", + "cap-std 2.0.1", "cap-time-ext", - "fs-set-times 0.20.0", - "io-extras 0.18.0", - "io-lifetimes 2.0.2", + "fs-set-times 0.20.1", + "io-extras 0.18.1", + "io-lifetimes 2.0.3", "once_cell", - "rustix 0.38.30", + "rustix 0.38.31", "system-interface", "tracing", "wasi-common", - "windows-sys 0.48.0", + "windows-sys 0.52.0", ] [[package]] name = "wasi-common" -version = "16.0.0" +version = "17.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3d888b611fee7d273dd057dc009d2dd3132736f36710ffd65657ac83628d1e3b" +checksum = "da4d4023cc65b3615590d38db0afb79234de09b3bb89cb0d8f83bdee9f5c28a8" dependencies = [ "anyhow", "bitflags 2.4.2", "cap-rand", - "cap-std 2.0.0", - "io-extras 0.18.0", + "cap-std 2.0.1", + "io-extras 0.18.1", "log", - "rustix 0.38.30", + "rustix 0.38.31", "thiserror", "tracing", "wasmtime", "wiggle", - "windows-sys 0.48.0", + "windows-sys 0.52.0", ] [[package]] @@ -1994,35 +2030,89 @@ dependencies = [ "heck 0.4.1", "serde", "tokio", - "toml 0.7.8", + "toml 0.8.10", "walrus", "wasm-compose", "wasm-metadata", "wasm-opt", - "wasmparser 0.119.0", + "wasmparser 0.121.2", "wasmtime", "wasmtime-wasi", - "wit-component 0.19.1", + "wit-component", ] +[[package]] +name = "wasm-bindgen" +version = "0.2.91" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c1e124130aee3fb58c5bdd6b639a0509486b0338acaaae0c84a5124b0f588b7f" +dependencies = [ + "cfg-if", + "wasm-bindgen-macro", +] + +[[package]] +name = "wasm-bindgen-backend" +version = "0.2.91" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c9e7e1900c352b609c8488ad12639a311045f40a35491fb69ba8c12f758af70b" +dependencies = [ + "bumpalo", + "log", + "once_cell", + "proc-macro2", + "quote", + "syn 2.0.48", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.2.91" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b30af9e2d358182b5c7449424f017eba305ed32a7010509ede96cdc4696c46ed" +dependencies = [ + "quote", + "wasm-bindgen-macro-support", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.91" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "642f325be6301eb8107a83d12a8ac6c1e1c54345a7ef1a9261962dfefda09e66" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.48", + "wasm-bindgen-backend", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-shared" +version = "0.2.91" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4f186bd2dcf04330886ce82d6f33dd75a7bfcf69ecf5763b89fcde53b6ac9838" + [[package]] name = "wasm-compose" -version = "0.5.0" +version = "0.5.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9941776e288d53b544a50d295554497c499516095634d92d63f0aa099685372a" +checksum = "fd324927af875ebedb1b820c00e3c585992d33c2c787c5021fe6d8982527359b" dependencies = [ "anyhow", "heck 0.4.1", "im-rc", - "indexmap 2.0.0", + "indexmap 2.2.3", "log", "petgraph", "serde", "serde_derive", "serde_yaml", "smallvec", - "wasm-encoder 0.39.0", - "wasmparser 0.119.0", + "wasm-encoder 0.41.2", + "wasmparser 0.121.2", "wat", ] @@ -2046,35 +2136,35 @@ dependencies = [ [[package]] name = "wasm-encoder" -version = "0.39.0" +version = "0.41.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "111495d6204760238512f57a9af162f45086504da332af210f2f75dd80b34f1d" +checksum = "972f97a5d8318f908dded23594188a90bcd09365986b1163e66d70170e5287ae" dependencies = [ "leb128", - "wasmparser 0.119.0", + "wasmparser 0.121.2", ] [[package]] name = "wasm-metadata" -version = "0.10.15" +version = "0.10.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "818931c85b1d197909699d36c509fa89550ccfa0d66932ba3c1726faddb4d0c7" +checksum = "18ebaa7bd0f9e7a5e5dd29b9a998acf21c4abed74265524dd7e85934597bfb10" dependencies = [ "anyhow", - "indexmap 2.0.0", + "indexmap 2.2.3", "serde", "serde_derive", "serde_json", "spdx", - "wasm-encoder 0.39.0", - "wasmparser 0.119.0", + "wasm-encoder 0.41.2", + "wasmparser 0.121.2", ] [[package]] name = "wasm-opt" -version = "0.114.1" +version = "0.114.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4d005a95f934878a1fb446a816d51c3601a0120ff929005ba3bab3c749cfd1c7" +checksum = "effbef3bd1dde18acb401f73e740a6f3d4a1bc651e9773bddc512fe4d8d68f67" dependencies = [ "anyhow", "libc", @@ -2088,9 +2178,9 @@ dependencies = [ [[package]] name = "wasm-opt-cxx-sys" -version = "0.114.1" +version = "0.114.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6d04e240598162810fad3b2e96fa0dec6dba1eb65a03f3bd99a9248ab8b56caa" +checksum = "c09e24eb283919ace2ed5733bda4842a59ce4c8de110ef5c6d98859513d17047" dependencies = [ "anyhow", "cxx", @@ -2100,9 +2190,9 @@ dependencies = [ [[package]] name = "wasm-opt-sys" -version = "0.114.1" +version = "0.114.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2efd2aaca519d64098c4faefc8b7433a97ed511caf4c9e516384eb6aef1ff4f9" +checksum = "36f2f817bed2e8d65eb779fa37317e74de15585751f903c9118342d1970703a4" dependencies = [ "anyhow", "cc", @@ -2118,40 +2208,40 @@ checksum = "449167e2832691a1bff24cde28d2804e90e09586a448c8e76984792c44334a6b" [[package]] name = "wasmparser" -version = "0.118.1" +version = "0.118.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "95ee9723b928e735d53000dec9eae7b07a60e490c85ab54abb66659fc61bfcd9" +checksum = "77f1154f1ab868e2a01d9834a805faca7bf8b50d041b4ca714d005d0dab1c50c" dependencies = [ - "indexmap 2.0.0", + "indexmap 2.2.3", "semver", ] [[package]] name = "wasmparser" -version = "0.119.0" +version = "0.121.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8c35daf77afb4f9b14016625144a391085ec2ca99ca9cc53ed291bb53ab5278d" +checksum = "9dbe55c8f9d0dbd25d9447a5a889ff90c0cc3feaa7395310d3d826b2c703eaab" dependencies = [ "bitflags 2.4.2", - "indexmap 2.0.0", + "indexmap 2.2.3", "semver", ] [[package]] name = "wasmprinter" -version = "0.2.76" +version = "0.2.80" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cac2a7745372074e5573e365e17100f5a26058740576313784ef03fb900ea8d2" +checksum = "60e73986a6b7fdfedb7c5bf9e7eb71135486507c8fbc4c0c42cffcb6532988b7" dependencies = [ "anyhow", - "wasmparser 0.119.0", + "wasmparser 0.121.2", ] [[package]] name = "wasmtime" -version = "16.0.0" +version = "17.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a8e539fded2495422ea3c4dfa7beeddba45904eece182cf315294009e1a323bf" +checksum = "8acb6aa966be38f613954c3debe7ba6c7a02ffd0537432be438da0b038955cdf" dependencies = [ "anyhow", "async-trait", @@ -2160,7 +2250,7 @@ dependencies = [ "cfg-if", "encoding_rs", "fxprof-processed-profile", - "indexmap 2.0.0", + "indexmap 2.2.3", "libc", "log", "object", @@ -2172,7 +2262,7 @@ dependencies = [ "serde_json", "target-lexicon", "wasm-encoder 0.38.1", - "wasmparser 0.118.1", + "wasmparser 0.118.2", "wasmtime-cache", "wasmtime-component-macro", "wasmtime-component-util", @@ -2183,64 +2273,64 @@ dependencies = [ "wasmtime-runtime", "wasmtime-winch", "wat", - "windows-sys 0.48.0", + "windows-sys 0.52.0", ] [[package]] name = "wasmtime-asm-macros" -version = "16.0.0" +version = "17.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "660ba9143e15a2acd921820df221b73aee256bd3ca2d208d73d8adc9587ccbb9" +checksum = "c1495ef4d46aec14f967b672e946e391dd8a14a443cda3d5e0779ff67fb6e28d" dependencies = [ "cfg-if", ] [[package]] name = "wasmtime-cache" -version = "16.0.0" +version = "17.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a3ce373743892002f9391c6741ef0cb0335b55ec899d874f311222b7e36f4594" +checksum = "e2de1b065bdbaca3df9e7e9f70eb129e326a99d971b16d666acd798d98d47635" dependencies = [ "anyhow", "base64", "bincode", "directories-next", "log", - "rustix 0.38.30", + "rustix 0.38.31", "serde", "serde_derive", "sha2", "toml 0.5.11", - "windows-sys 0.48.0", + "windows-sys 0.52.0", "zstd", ] [[package]] name = "wasmtime-component-macro" -version = "16.0.0" +version = "17.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "12ef32643324e564e1c359e9044daa06cbf90d7e2d6c99a738d17a12959f01a5" +checksum = "2f19bcff82f81ba0273c0b68f3909977b0dd54489bc86c630d8aad43dca92f3f" dependencies = [ "anyhow", "proc-macro2", "quote", - "syn 2.0.37", + "syn 2.0.48", "wasmtime-component-util", "wasmtime-wit-bindgen", - "wit-parser", + "wit-parser 0.13.2", ] [[package]] name = "wasmtime-component-util" -version = "16.0.0" +version = "17.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8c87d06c18d21a4818f354c00a85f4ebc62b2270961cd022968452b0e4dbed9d" +checksum = "8af072b7ad5ac5583e1f9e4737ebf88923de564fb5d4ace0ca9b4b720bdf95a1" [[package]] name = "wasmtime-cranelift" -version = "16.0.0" +version = "17.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2d648c8b4064a7911093b02237cd5569f71ca171d3a0a486bf80600b19e1cba2" +checksum = "df08a8bd9a68732577bee05ac685e4c247238b5e79ad9c062e2dfb4d04dca132" dependencies = [ "anyhow", "cfg-if", @@ -2250,12 +2340,12 @@ dependencies = [ "cranelift-frontend", "cranelift-native", "cranelift-wasm", - "gimli 0.28.0", + "gimli 0.28.1", "log", "object", "target-lexicon", "thiserror", - "wasmparser 0.118.1", + "wasmparser 0.118.2", "wasmtime-cranelift-shared", "wasmtime-environ", "wasmtime-versioned-export-macros", @@ -2263,15 +2353,15 @@ dependencies = [ [[package]] name = "wasmtime-cranelift-shared" -version = "16.0.0" +version = "17.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "290a89027688782da8ff60b12bb95695494b1874e0d0ba2ba387d23dace6d70c" +checksum = "404201c9e669083f189f01337b3ed0aa0eb081157fb4e170bbfe193df9497771" dependencies = [ "anyhow", "cranelift-codegen", "cranelift-control", "cranelift-native", - "gimli 0.28.0", + "gimli 0.28.1", "object", "target-lexicon", "wasmtime-environ", @@ -2279,14 +2369,14 @@ dependencies = [ [[package]] name = "wasmtime-environ" -version = "16.0.0" +version = "17.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "61eb64fb3e0da883e2df4a13a81d6282e072336e6cb6295021d0f7ab2e352754" +checksum = "7e696b4911c9a69c3c2892ec05eb41bb15436d1a46d8830a755c40f5df47546a" dependencies = [ "anyhow", "cranelift-entity", - "gimli 0.28.0", - "indexmap 2.0.0", + "gimli 0.28.1", + "indexmap 2.2.3", "log", "object", "serde", @@ -2294,7 +2384,7 @@ dependencies = [ "target-lexicon", "thiserror", "wasm-encoder 0.38.1", - "wasmparser 0.118.1", + "wasmparser 0.118.2", "wasmprinter", "wasmtime-component-util", "wasmtime-types", @@ -2302,36 +2392,36 @@ dependencies = [ [[package]] name = "wasmtime-fiber" -version = "16.0.0" +version = "17.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "40ecf1d3a838b0956b71ad3f8cb80069a228339775bf02dd35d86a5a68bbe443" +checksum = "4a39681c1f6f54d1bf7efe5dc829f8d7fc0e2ca12c346fd7a3efbf726e9681d2" dependencies = [ "anyhow", "cc", "cfg-if", - "rustix 0.38.30", + "rustix 0.38.31", "wasmtime-asm-macros", "wasmtime-versioned-export-macros", - "windows-sys 0.48.0", + "windows-sys 0.52.0", ] [[package]] name = "wasmtime-jit" -version = "16.0.0" +version = "17.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f485336add49267d8859e8f8084d2d4b9a4b1564496b6f30ba5b168d50c10ceb" +checksum = "2c56519882d936c680bd191d58ac04cff071a470eca2dcc664adcd60f986a731" dependencies = [ "addr2line", "anyhow", "bincode", "cfg-if", "cpp_demangle", - "gimli 0.28.0", + "gimli 0.28.1", "ittapi", "log", "object", "rustc-demangle", - "rustix 0.38.30", + "rustix 0.38.31", "serde", "serde_derive", "target-lexicon", @@ -2339,43 +2429,43 @@ dependencies = [ "wasmtime-jit-debug", "wasmtime-jit-icache-coherence", "wasmtime-runtime", - "windows-sys 0.48.0", + "windows-sys 0.52.0", ] [[package]] name = "wasmtime-jit-debug" -version = "16.0.0" +version = "17.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "65e119affec40edb2fab9044f188759a00c2df9c3017278d047012a2de1efb4f" +checksum = "babc65e64ab0dd4e1ce65624db64e24ed0fbdebb16148729173fa0da9f70e53c" dependencies = [ "object", "once_cell", - "rustix 0.38.30", + "rustix 0.38.31", "wasmtime-versioned-export-macros", ] [[package]] name = "wasmtime-jit-icache-coherence" -version = "16.0.0" +version = "17.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6b6d197fcc34ad32ed440e1f9552fd57d1f377d9699d31dee1b5b457322c1f8a" +checksum = "d7ec5b11c12d9acb09612e7ce04c4c8aea3e8dc79b2591ffdead986a5ce8ec49" dependencies = [ "cfg-if", "libc", - "windows-sys 0.48.0", + "windows-sys 0.52.0", ] [[package]] name = "wasmtime-runtime" -version = "16.0.0" +version = "17.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "794b2bb19b99ef8322ff0dd9fe1ba7e19c41036dfb260b3f99ecce128c42ff92" +checksum = "28e1c31bbdf67cb86f149bcead5193749f23f77c93c5244ec9ac8d192f90966c" dependencies = [ "anyhow", "cc", "cfg-if", "encoding_rs", - "indexmap 2.0.0", + "indexmap 2.2.3", "libc", "log", "mach", @@ -2383,7 +2473,7 @@ dependencies = [ "memoffset", "paste", "psm", - "rustix 0.38.30", + "rustix 0.38.31", "sptr", "wasm-encoder 0.38.1", "wasmtime-asm-macros", @@ -2392,38 +2482,38 @@ dependencies = [ "wasmtime-jit-debug", "wasmtime-versioned-export-macros", "wasmtime-wmemcheck", - "windows-sys 0.48.0", + "windows-sys 0.52.0", ] [[package]] name = "wasmtime-types" -version = "16.0.0" +version = "17.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d995db8bb56f2cd8d2dc0ed5ffab94ffb435283b0fe6747f80f7aab40b2d06a1" +checksum = "52e799cff634d30fd042db96b417d515e54f903b95f8c1e0ec60e8f604479485" dependencies = [ "cranelift-entity", "serde", "serde_derive", "thiserror", - "wasmparser 0.118.1", + "wasmparser 0.118.2", ] [[package]] name = "wasmtime-versioned-export-macros" -version = "16.0.0" +version = "17.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f55c5565959287c21dd0f4277ae3518dd2ae62679f655ee2dbc4396e19d210db" +checksum = "e10fe166d4e4c95d5d80c5b47e1e12256af2099ac525ddb9a19b1aeb8896e5e1" dependencies = [ "proc-macro2", "quote", - "syn 2.0.37", + "syn 2.0.48", ] [[package]] name = "wasmtime-wasi" -version = "16.0.0" +version = "17.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ccd8370078149d49a3a47e93741553fd79b700421464b6a27ca32718192ab130" +checksum = "494f99111a165dcddc69aaa5fa23604f49dcfab479a869edd84581abd6ac569b" dependencies = [ "anyhow", "async-trait", @@ -2432,16 +2522,16 @@ dependencies = [ "cap-fs-ext", "cap-net-ext", "cap-rand", - "cap-std 2.0.0", + "cap-std 2.0.1", "cap-time-ext", - "fs-set-times 0.20.0", + "fs-set-times 0.20.1", "futures", - "io-extras 0.18.0", - "io-lifetimes 2.0.2", + "io-extras 0.18.1", + "io-lifetimes 2.0.3", "libc", "log", "once_cell", - "rustix 0.38.30", + "rustix 0.38.31", "system-interface", "thiserror", "tokio", @@ -2451,21 +2541,21 @@ dependencies = [ "wasi-common", "wasmtime", "wiggle", - "windows-sys 0.48.0", + "windows-sys 0.52.0", ] [[package]] name = "wasmtime-winch" -version = "16.0.0" +version = "17.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2c6f945ff9bad96e0a69973d74f193c19f627c8adbf250e7cb73ae7564b6cc8a" +checksum = "d3f5d76d399cb4423e6f178bc154a0e1c314711e28dabaa6e757e56628a083ec" dependencies = [ "anyhow", "cranelift-codegen", - "gimli 0.28.0", + "gimli 0.28.1", "object", "target-lexicon", - "wasmparser 0.118.1", + "wasmparser 0.118.2", "wasmtime-cranelift-shared", "wasmtime-environ", "winch-codegen", @@ -2473,21 +2563,21 @@ dependencies = [ [[package]] name = "wasmtime-wit-bindgen" -version = "16.0.0" +version = "17.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f328b2d4a690270324756e886ed5be3a4da4c00be0eea48253f4595ad068062b" +checksum = "6bb3bc92c031cf4961135bffe055a69c1bd67c253dca20631478189bb05ec27b" dependencies = [ "anyhow", "heck 0.4.1", - "indexmap 2.0.0", - "wit-parser", + "indexmap 2.2.3", + "wit-parser 0.13.2", ] [[package]] name = "wasmtime-wmemcheck" -version = "16.0.0" +version = "17.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "67761d8f8c0b3c13a5d34356274b10a40baba67fe9cfabbfc379a8b414e45de2" +checksum = "5da08ab734954e16f57be38423b90c25a0b13420e51cbd0a2e37b86a468a988c" [[package]] name = "wast" @@ -2500,30 +2590,31 @@ dependencies = [ [[package]] name = "wast" -version = "70.0.0" +version = "71.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2ee4bc54bbe1c6924160b9f75e374a1d07532e7580eb632c0ee6cdd109bb217e" +checksum = "647c3ac4354da32688537e8fc4d2fe6c578df51896298cb64727d98088a1fd26" dependencies = [ + "bumpalo", "leb128", "memchr", "unicode-width", - "wasm-encoder 0.39.0", + "wasm-encoder 0.41.2", ] [[package]] name = "wat" -version = "1.0.83" +version = "1.0.88" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9f0dce8cdc288c717cf01e461a1e451a7b8445d53451123536ba576e423a101a" +checksum = "b69c36f634411568a2c6d24828b674961e37ea03340fe1d605c337ed8162d901" dependencies = [ - "wast 70.0.0", + "wast 71.0.1", ] [[package]] name = "wiggle" -version = "16.0.0" +version = "17.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0afb26cd3269289bb314a361ff0a6685e5ce793b62181a9fe3f81ace15051697" +checksum = "cd5b200b5dd3d5d7cc4093166f4f916d2d2839296cf1b1757b9726635f6425c3" dependencies = [ "anyhow", "async-trait", @@ -2536,28 +2627,28 @@ dependencies = [ [[package]] name = "wiggle-generate" -version = "16.0.0" +version = "17.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cef2868fed7584d2b552fa317104858ded80021d23b073b2d682d3c932a027bd" +checksum = "a4dc34a2bc1091599de005e9b854cd1a9ea35b16ca51cac2797274c1a2666e06" dependencies = [ "anyhow", "heck 0.4.1", "proc-macro2", "quote", "shellexpand", - "syn 2.0.37", + "syn 2.0.48", "witx", ] [[package]] name = "wiggle-macro" -version = "16.0.0" +version = "17.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "31ae1ec11a17ea481539ee9a5719a278c9790d974060fbf71db4b2c05378780b" +checksum = "37ba3b37f402a7513b9ed7973a6e907074987b3afdcede98d3d79939b3e76f1b" dependencies = [ "proc-macro2", "quote", - "syn 2.0.37", + "syn 2.0.48", "wiggle-generate", ] @@ -2594,20 +2685,29 @@ checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" [[package]] name = "winch-codegen" -version = "0.14.0" +version = "0.15.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "58e58c236a6abdd9ab454552b4f29e16cfa837a86897c1503313b2e62e7609ec" +checksum = "8d921185084e134e897e0e202e129a422306d0f1391954ecf4928d36defa897d" dependencies = [ "anyhow", "cranelift-codegen", - "gimli 0.28.0", + "gimli 0.28.1", "regalloc2", "smallvec", "target-lexicon", - "wasmparser 0.118.1", + "wasmparser 0.118.2", "wasmtime-environ", ] +[[package]] +name = "windows-core" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "33ab640c8d7e35bf8ba19b884ba838ceb4fba93a4e8c65a9059d08afcfc683d9" +dependencies = [ + "windows-targets 0.52.0", +] + [[package]] name = "windows-sys" version = "0.48.0" @@ -2742,9 +2842,9 @@ checksum = "dff9641d1cd4be8d1a070daf9e3773c5f67e78b4d9d42263020c057706765c04" [[package]] name = "winnow" -version = "0.5.15" +version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7c2e3184b9c4e92ad5167ca73039d0c42476302ab603e2fec4487511f38ccefc" +checksum = "6b1dbce9e90e5404c5a52ed82b1d13fc8cfbdad85033b6f57546ffd1265f8451" dependencies = [ "memchr", ] @@ -2762,19 +2862,19 @@ dependencies = [ [[package]] name = "winx" -version = "0.36.2" +version = "0.36.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "357bb8e2932df531f83b052264b050b81ba0df90ee5a59b2d1d3949f344f81e5" +checksum = "f9643b83820c0cd246ecabe5fa454dd04ba4fa67996369466d0747472d337346" dependencies = [ "bitflags 2.4.2", - "windows-sys 0.48.0", + "windows-sys 0.52.0", ] [[package]] name = "wit-bindgen" -version = "0.16.0" +version = "0.17.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b76f1d099678b4f69402a421e888bbe71bf20320c2f3f3565d0e7484dbe5bc20" +checksum = "d78a762c4fbc1bc0dedf4aaa280ac5ea87e0d3a7ec83487b7b25999a55ec4b73" dependencies = [ "bitflags 2.4.2", "wit-bindgen-rust-macro", @@ -2782,96 +2882,95 @@ dependencies = [ [[package]] name = "wit-bindgen-core" -version = "0.16.0" +version = "0.17.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "75d55e1a488af2981fb0edac80d8d20a51ac36897a1bdef4abde33c29c1b6d0d" +checksum = "43cc97e83ffaabab15791f6fe7d7f8c4e1dc670243e460765c2830463d53bcdf" dependencies = [ "anyhow", - "wit-component 0.18.2", - "wit-parser", + "wit-component", + "wit-parser 0.14.0", ] [[package]] name = "wit-bindgen-rust" -version = "0.16.0" +version = "0.17.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a01ff9cae7bf5736750d94d91eb8a49f5e3a04aff1d1a3218287d9b2964510f8" +checksum = "a67b2ee0578e3e8be67f1d863b86e5d649bb16d56c85752eef5228967db103e2" dependencies = [ "anyhow", "heck 0.4.1", "wasm-metadata", "wit-bindgen-core", - "wit-component 0.18.2", + "wit-component", ] [[package]] name = "wit-bindgen-rust-macro" -version = "0.16.0" +version = "0.17.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "804a98e2538393d47aa7da65a7348116d6ff403b426665152b70a168c0146d49" +checksum = "345a07e6740bc71c7da6e95e9547d89c54895b8a93fad9d192b67c1ec8358e32" dependencies = [ "anyhow", "proc-macro2", "quote", - "syn 2.0.37", + "syn 2.0.48", "wit-bindgen-core", "wit-bindgen-rust", - "wit-component 0.18.2", + "wit-component", ] [[package]] name = "wit-component" -version = "0.18.2" +version = "0.21.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b8a35a2a9992898c9d27f1664001860595a4bc99d32dd3599d547412e17d7e2" +checksum = "be60cd1b2ff7919305301d0c27528d4867bd793afe890ba3837743da9655d91b" dependencies = [ "anyhow", "bitflags 2.4.2", - "indexmap 2.0.0", + "indexmap 2.2.3", "log", "serde", "serde_derive", "serde_json", - "wasm-encoder 0.38.1", + "wasm-encoder 0.41.2", "wasm-metadata", - "wasmparser 0.118.1", - "wit-parser", + "wasmparser 0.121.2", + "wit-parser 0.14.0", ] [[package]] -name = "wit-component" -version = "0.19.1" +name = "wit-parser" +version = "0.13.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "429e3c06fba3a7566aab724ae3ffff3152ede5399d44789e7dd11f5421292859" +checksum = "316b36a9f0005f5aa4b03c39bc3728d045df136f8c13a73b7db4510dec725e08" dependencies = [ "anyhow", - "bitflags 2.4.2", - "indexmap 2.0.0", + "id-arena", + "indexmap 2.2.3", "log", + "semver", "serde", "serde_derive", "serde_json", - "wasm-encoder 0.39.0", - "wasm-metadata", - "wasmparser 0.119.0", - "wit-parser", + "unicode-xid", ] [[package]] name = "wit-parser" -version = "0.13.1" +version = "0.14.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "df4913a2219096373fd6512adead1fb77ecdaa59d7fc517972a7d30b12f625be" +checksum = "1ee4ad7310367bf272507c0c8e0c74a80b4ed586b833f7c7ca0b7588f686f11a" dependencies = [ "anyhow", "id-arena", - "indexmap 2.0.0", + "indexmap 2.2.3", "log", "semver", "serde", "serde_derive", "serde_json", "unicode-xid", + "wasmparser 0.121.2", ] [[package]] @@ -2886,6 +2985,26 @@ dependencies = [ "wast 35.0.2", ] +[[package]] +name = "zerocopy" +version = "0.7.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "74d4d3961e53fa4c9a25a8637fc2bfaf2595b3d3ae34875568a5cf64787716be" +dependencies = [ + "zerocopy-derive", +] + +[[package]] +name = "zerocopy-derive" +version = "0.7.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ce1b18ccd8e73a9321186f97e46f9f04b778851177567b1975109d26a08d2a6" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.48", +] + [[package]] name = "zstd" version = "0.11.2+zstd.1.5.2" @@ -2907,11 +3026,10 @@ dependencies = [ [[package]] name = "zstd-sys" -version = "2.0.8+zstd.1.5.5" +version = "2.0.9+zstd.1.5.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5556e6ee25d32df2586c098bbfa278803692a20d0ab9565e049480d52707ec8c" +checksum = "9e16efa8a874a0481a574084d34cc26fdb3b99627480f785888deb6386506656" dependencies = [ "cc", - "libc", "pkg-config", ] diff --git a/Cargo.toml b/Cargo.toml index 78eae1e..001428b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -32,12 +32,12 @@ rustflags = ["-Zoom=panic"] anyhow = "1" clap = { version = "4", features = ["derive"] } serde = { version = "1", features = ["derive"] } -toml = "0.7" +toml = "0.8" walrus = "0.20.3" -wasm-compose = "0.5.0" -wasm-metadata = "0.10.15" -wasm-opt = "0.114.1" -wit-component = "0.19.1" +wasm-compose = "0.5.5" +wasm-metadata = "0.10.20" +wasm-opt = "0.114.2" +wit-component = "0.21.0" [build-dependencies] anyhow = "1" @@ -47,10 +47,10 @@ anyhow = "1" cap-std = "1.0.12" heck = { version = "0.4" } tokio = { version = "1.30.0", features = ["macros"] } -wasmtime = { version = "16.0.0", features = ["component-model"] } -wasmtime-wasi = "16.0.0" -wasmparser = "0.119.0" +wasmtime = { version = "17.0.1", features = ["component-model"] } +wasmtime-wasi = "17.0.1" +wasmparser = "0.121.2" [workspace.dependencies] anyhow = "1" -wit-bindgen = "0.16.0" +wit-bindgen = "0.17.1" diff --git a/build-adapter.sh b/build-adapter.sh index 362ae42..5ee0c63 100755 --- a/build-adapter.sh +++ b/build-adapter.sh @@ -1,2 +1,11 @@ -cargo +nightly build -p virtual-adapter --target wasm32-wasi --release -Z build-std=std,panic_abort -Z build-std-features=panic_immediate_abort && cp target/wasm32-wasi/release/virtual_adapter.wasm lib/ -cargo +nightly build -p virtual-adapter --target wasm32-wasi --release --features debug -Z build-std=std,panic_abort -Z build-std-features=panic_immediate_abort && cp target/wasm32-wasi/release/virtual_adapter.wasm lib/virtual_adapter.debug.wasm +# Useful for debugging: +# export CARGO_PROFILE_RELEASE_DEBUG=2 +# export WIT_BINDGEN_DEBUG=1 + +wasm-tools component wit --wasm wit -o lib/package.wasm + +cargo build -p virtual-adapter --target wasm32-unknown-unknown --release -Z build-std=std,panic_abort -Z build-std-features=panic_immediate_abort && + cp target/wasm32-unknown-unknown/release/virtual_adapter.wasm lib/virtual_adapter.wasm + +cargo build -p virtual-adapter --target wasm32-unknown-unknown --release --features debug -Z build-std=std,panic_abort -Z build-std-features=panic_immediate_abort && + cp target/wasm32-unknown-unknown/release/virtual_adapter.wasm lib/virtual_adapter.debug.wasm diff --git a/lib/virtual_adapter.debug.wasm b/lib/virtual_adapter.debug.wasm index 5daea84..1e78cf5 100755 Binary files a/lib/virtual_adapter.debug.wasm and b/lib/virtual_adapter.debug.wasm differ diff --git a/lib/virtual_adapter.wasm b/lib/virtual_adapter.wasm index 61cc257..6573579 100755 Binary files a/lib/virtual_adapter.wasm and b/lib/virtual_adapter.wasm differ diff --git a/lib/wasi_snapshot_preview1.reactor.wasm b/lib/wasi_snapshot_preview1.reactor.wasm index 0610703..82455c8 100644 Binary files a/lib/wasi_snapshot_preview1.reactor.wasm and b/lib/wasi_snapshot_preview1.reactor.wasm differ diff --git a/src/lib.rs b/src/lib.rs index 87da4e0..2ecc0db 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -5,13 +5,11 @@ use virt_deny::{ deny_clocks_virt, deny_exit_virt, deny_http_virt, deny_random_virt, deny_sockets_virt, }; use virt_env::{create_env_virt, strip_env_virt}; -use virt_io::{ - create_io_virt, strip_clocks_virt, strip_fs_virt, strip_http_virt, strip_io_virt, - strip_sockets_virt, strip_stdio_virt, VirtStdio, -}; +use virt_io::{create_io_virt, VirtStdio}; +use walrus_ops::strip_virt; use wasm_metadata::Producers; -use wasm_opt::{Feature, OptimizationOptions}; -use wit_component::{metadata, ComponentEncoder, StringEncoding}; +use wasm_opt::{Feature, OptimizationOptions, ShrinkLevel}; +use wit_component::{metadata, ComponentEncoder, DecodedWasm, StringEncoding}; mod data; mod stub_preview1; @@ -26,6 +24,7 @@ pub use virt_io::{FsEntry, StdioCfg, VirtFs, VirtualFiles}; const VIRT_ADAPTER: &[u8] = include_bytes!("../lib/virtual_adapter.wasm"); const VIRT_ADAPTER_DEBUG: &[u8] = include_bytes!("../lib/virtual_adapter.debug.wasm"); +const VIRT_WIT_METADATA: &[u8] = include_bytes!("../lib/package.wasm"); /// Virtualization options /// @@ -131,7 +130,10 @@ impl WasiVirt { } pub fn finish(&mut self) -> Result { - let config = walrus::ModuleConfig::new(); + let mut config = walrus::ModuleConfig::new(); + if self.debug { + config.generate_dwarf(true); + } let mut module = if self.debug { config.parse(VIRT_ADAPTER_DEBUG) } else { @@ -164,70 +166,45 @@ impl WasiVirt { .remove_raw("component-type:virtual-adapter") .context("Unable to find component section")?; - let (_, mut bindgen) = if self.debug { - metadata::decode(VIRT_ADAPTER_DEBUG) - } else { - metadata::decode(VIRT_ADAPTER) - }?; - let (_, pkg_id) = bindgen - .resolve - .package_names - .iter() - .find(|(name, _)| name.namespace == "local") - .unwrap(); - - let base_world = bindgen - .resolve - .select_world(*pkg_id, Some("virtual-base"))?; - - let env_world = bindgen.resolve.select_world(*pkg_id, Some("virtual-env"))?; - - let io_world = bindgen.resolve.select_world(*pkg_id, Some("virtual-io"))?; - let io_clocks_world = bindgen - .resolve - .select_world(*pkg_id, Some("virtual-io-clocks"))?; - let io_http_world = bindgen - .resolve - .select_world(*pkg_id, Some("virtual-io-http"))?; - let io_sockets_world = bindgen - .resolve - .select_world(*pkg_id, Some("virtual-io-sockets"))?; - - let exit_world = bindgen - .resolve - .select_world(*pkg_id, Some("virtual-exit"))?; - let fs_world = bindgen.resolve.select_world(*pkg_id, Some("virtual-fs"))?; - let random_world = bindgen - .resolve - .select_world(*pkg_id, Some("virtual-random"))?; - let stdio_world = bindgen - .resolve - .select_world(*pkg_id, Some("virtual-stdio"))?; - let clocks_world = bindgen - .resolve - .select_world(*pkg_id, Some("virtual-clocks"))?; - let http_world = bindgen - .resolve - .select_world(*pkg_id, Some("virtual-http"))?; - let sockets_world = bindgen - .resolve - .select_world(*pkg_id, Some("virtual-sockets"))?; + let (mut resolve, pkg_id) = match wit_component::decode(VIRT_WIT_METADATA)? { + DecodedWasm::WitPackage(resolve, pkg_id) => (resolve, pkg_id), + DecodedWasm::Component(..) => { + anyhow::bail!("expected a WIT package, found a component") + } + }; + + let base_world = resolve.select_world(pkg_id, Some("virtual-base"))?; + + let env_world = resolve.select_world(pkg_id, Some("virtual-env"))?; + + let io_world = resolve.select_world(pkg_id, Some("virtual-io"))?; + let io_clocks_world = resolve.select_world(pkg_id, Some("virtual-io-clocks"))?; + let io_http_world = resolve.select_world(pkg_id, Some("virtual-io-http"))?; + let io_sockets_world = resolve.select_world(pkg_id, Some("virtual-io-sockets"))?; + + let exit_world = resolve.select_world(pkg_id, Some("virtual-exit"))?; + let fs_world = resolve.select_world(pkg_id, Some("virtual-fs"))?; + let random_world = resolve.select_world(pkg_id, Some("virtual-random"))?; + let stdio_world = resolve.select_world(pkg_id, Some("virtual-stdio"))?; + let clocks_world = resolve.select_world(pkg_id, Some("virtual-clocks"))?; + let http_world = resolve.select_world(pkg_id, Some("virtual-http"))?; + let sockets_world = resolve.select_world(pkg_id, Some("virtual-sockets"))?; // env, exit & random subsystems are fully independent if self.env.is_some() { - bindgen.resolve.merge_worlds(env_world, base_world)?; + resolve.merge_worlds(env_world, base_world)?; } else { strip_env_virt(&mut module)?; } if let Some(exit) = self.exit { if !exit { - bindgen.resolve.merge_worlds(exit_world, base_world)?; + resolve.merge_worlds(exit_world, base_world)?; deny_exit_virt(&mut module)?; } } if let Some(random) = self.random { if !random { - bindgen.resolve.merge_worlds(random_world, base_world)?; + resolve.merge_worlds(random_world, base_world)?; deny_random_virt(&mut module)?; } } @@ -235,69 +212,64 @@ impl WasiVirt { // io subsystems have io dependence due to streams + poll // therefore we need to strip just their io dependence portion if has_io { - bindgen.resolve.merge_worlds(io_world, base_world)?; + resolve.merge_worlds(io_world, base_world)?; } else { - strip_io_virt(&mut module)?; + strip_virt(&mut module, &["wasi:io/"])?; } if let Some(clocks) = self.clocks { if !clocks { // deny is effectively virtualization // in future with fine-grained virtualization options, they // also would extend here (ie !clocks is deceiving) - bindgen.resolve.merge_worlds(clocks_world, base_world)?; + resolve.merge_worlds(clocks_world, base_world)?; deny_clocks_virt(&mut module)?; } else { // passthrough can be simplified to just rewrapping io interfaces - bindgen.resolve.merge_worlds(io_clocks_world, base_world)?; + resolve.merge_worlds(io_clocks_world, base_world)?; } } else { - strip_clocks_virt(&mut module)?; + strip_virt(&mut module, &["wasi:clocks/"])?; } // sockets and http are identical to clocks above if let Some(sockets) = self.sockets { if !sockets { - bindgen.resolve.merge_worlds(sockets_world, base_world)?; + resolve.merge_worlds(sockets_world, base_world)?; deny_sockets_virt(&mut module)?; } else { - bindgen.resolve.merge_worlds(io_sockets_world, base_world)?; + resolve.merge_worlds(io_sockets_world, base_world)?; } } else { - strip_sockets_virt(&mut module)?; + strip_virt(&mut module, &["wasi:sockets/"])?; } if let Some(http) = self.http { if !http { - bindgen.resolve.merge_worlds(http_world, base_world)?; + resolve.merge_worlds(http_world, base_world)?; deny_http_virt(&mut module)?; } else { - bindgen.resolve.merge_worlds(io_http_world, base_world)?; + resolve.merge_worlds(io_http_world, base_world)?; } } else { - strip_http_virt(&mut module)?; + strip_virt(&mut module, &["wasi:http/"])?; } // stdio and fs are fully implemented in io world // (all their interfaces use streams) if self.stdio.is_some() { - bindgen.resolve.merge_worlds(stdio_world, base_world)?; + resolve.merge_worlds(stdio_world, base_world)?; } else { - strip_stdio_virt(&mut module)?; + strip_virt(&mut module, &["wasi:cli/std", "wasi:cli/terminal"])?; } if self.fs.is_some() || self.stdio.is_some() { - bindgen.resolve.merge_worlds(fs_world, base_world)?; + resolve.merge_worlds(fs_world, base_world)?; } else { - strip_fs_virt(&mut module)?; + strip_virt(&mut module, &["wasi:filesystem/"])?; } let mut producers = Producers::default(); producers.add("processed-by", "wasi-virt", env!("CARGO_PKG_VERSION")); - component_section.data = metadata::encode( - &bindgen.resolve, - base_world, - StringEncoding::UTF8, - Some(&producers), - None, - )?; + component_section.data = + metadata::encode(&resolve, base_world, StringEncoding::UTF8, Some(&producers))?; module.customs.add(component_section); @@ -312,8 +284,9 @@ impl WasiVirt { let tmp_output = dir.join(format!("virt.core.output.{}.wasm", timestamp())); fs::write(&tmp_input, bytes) .with_context(|| "Unable to write temporary file for wasm-opt call on adapter")?; - OptimizationOptions::new_optimize_for_size_aggressively() - .enable_feature(Feature::ReferenceTypes) + OptimizationOptions::new_opt_level_2() + .shrink_level(ShrinkLevel::Level1) + .enable_feature(Feature::All) .run(&tmp_input, &tmp_output) .with_context(|| "Unable to apply wasm-opt optimization to virt. This can be disabled with wasm_opt: false.") .or_else(|e| { diff --git a/src/virt_deny/clocks.rs b/src/virt_deny/clocks.rs index 494ca8d..8e7224a 100644 --- a/src/virt_deny/clocks.rs +++ b/src/virt_deny/clocks.rs @@ -3,7 +3,7 @@ use std::sync::OnceLock; use anyhow::Result; use walrus::{FuncParams, FuncResults, Module, ValType}; -use crate::virt_io::stub_clocks_virt; +use crate::walrus_ops::stub_virt; use super::replace_or_insert_stub_for_exports; @@ -15,32 +15,32 @@ fn get_wasi_clock_fns() -> &'static Vec<(&'static str, FuncParams, FuncResults)> WASI_CLOCK_FNS.get_or_init(|| { Vec::from([ ( - "wasi:clocks/monotonic-clock@0.2.0-rc-2023-11-10#now", + "wasi:clocks/monotonic-clock@0.2.0#now", vec![], vec![ValType::I64], ), ( - "wasi:clocks/monotonic-clock@0.2.0-rc-2023-11-10#resolution", + "wasi:clocks/monotonic-clock@0.2.0#resolution", vec![], vec![ValType::I64], ), ( - "wasi:clocks/monotonic-clock@0.2.0-rc-2023-11-10#subscribe-instant", + "wasi:clocks/monotonic-clock@0.2.0#subscribe-instant", vec![ValType::I64], vec![ValType::I32], ), ( - "wasi:clocks/monotonic-clock@0.2.0-rc-2023-11-10#subscribe-duration", + "wasi:clocks/monotonic-clock@0.2.0#subscribe-duration", vec![ValType::I64], vec![ValType::I32], ), ( - "wasi:clocks/wall-clock@0.2.0-rc-2023-11-10#now", + "wasi:clocks/wall-clock@0.2.0#now", vec![], vec![ValType::I32], ), ( - "wasi:clocks/wall-clock@0.2.0-rc-2023-11-10#resolution", + "wasi:clocks/wall-clock@0.2.0#resolution", vec![], vec![ValType::I32], ), @@ -50,6 +50,6 @@ fn get_wasi_clock_fns() -> &'static Vec<(&'static str, FuncParams, FuncResults)> /// Replace exports related to clocks in WASI to deny access pub(crate) fn deny_clocks_virt(module: &mut Module) -> Result<()> { - stub_clocks_virt(module)?; + stub_virt(module, &["wasi:clocks/"], false)?; replace_or_insert_stub_for_exports(module, get_wasi_clock_fns()) } diff --git a/src/virt_deny/exit.rs b/src/virt_deny/exit.rs index a79c6f5..a135c5e 100644 --- a/src/virt_deny/exit.rs +++ b/src/virt_deny/exit.rs @@ -10,13 +10,8 @@ static WASI_EXIT_FNS: OnceLock> = OnceLock: /// Retrieve or initialize the static list of functions related to exiting in WASI fn get_wasi_exit_fns() -> &'static Vec<(&'static str, FuncParams, FuncResults)> { - WASI_EXIT_FNS.get_or_init(|| { - Vec::from([( - "wasi:cli/exit@0.2.0-rc-2023-12-05#exit", - vec![ValType::I32], - vec![], - )]) - }) + WASI_EXIT_FNS + .get_or_init(|| Vec::from([("wasi:cli/exit@0.2.0#exit", vec![ValType::I32], vec![])])) } /// Replace exports related to exiting in WASI to deny access diff --git a/src/virt_deny/http.rs b/src/virt_deny/http.rs index 7ca8bb4..f9340ff 100644 --- a/src/virt_deny/http.rs +++ b/src/virt_deny/http.rs @@ -3,7 +3,7 @@ use std::sync::OnceLock; use anyhow::Result; use walrus::{FuncParams, FuncResults, Module, ValType}; -use crate::virt_io::stub_http_virt; +use crate::walrus_ops::stub_virt; use super::replace_or_insert_stub_for_exports; @@ -15,12 +15,12 @@ fn get_wasi_http_fns() -> &'static Vec<(&'static str, FuncParams, FuncResults)> WASI_HTTP_FNS.get_or_init(|| { Vec::from([ ( - "wasi:http/incoming-handler@0.2.0-rc-2023-10-18#handle", + "wasi:http/incoming-handler@0.2.0#handle", vec![ValType::I32, ValType::I32], vec![], ), ( - "wasi:http/outgoing-handler@0.2.0-rc-2023-10-18#handle", + "wasi:http/outgoing-handler@0.2.0#handle", vec![ ValType::I32, ValType::I32, @@ -34,22 +34,32 @@ fn get_wasi_http_fns() -> &'static Vec<(&'static str, FuncParams, FuncResults)> vec![ValType::I32], ), ( - "wasi:http/types@0.2.0-rc-2023-10-18#[dtor]fields", + "wasi:http/types@0.2.0#[dtor]fields", vec![ValType::I32], vec![], ), ( - "wasi:http/types@0.2.0-rc-2023-10-18#[constructor]fields", + "wasi:http/types@0.2.0#[constructor]fields", vec![ValType::I32, ValType::I32], vec![ValType::I32], ), ( - "wasi:http/types@0.2.0-rc-2023-10-18#[method]fields.get", + "wasi:http/types@0.2.0#[constructor]fields.from-list", + vec![ValType::I32, ValType::I32], + vec![ValType::I32], + ), + ( + "wasi:http/types@0.2.0#[method]fields.get", vec![ValType::I32, ValType::I32, ValType::I32], vec![ValType::I32], ), ( - "wasi:http/types@0.2.0-rc-2023-10-18#[method]fields.set", + "wasi:http/types@0.2.0#[method]fields.has", + vec![ValType::I32, ValType::I32, ValType::I32], + vec![ValType::I32], + ), + ( + "wasi:http/types@0.2.0#[method]fields.set", vec![ ValType::I32, ValType::I32, @@ -60,12 +70,12 @@ fn get_wasi_http_fns() -> &'static Vec<(&'static str, FuncParams, FuncResults)> vec![], ), ( - "wasi:http/types@0.2.0-rc-2023-10-18#[method]fields.delete", + "wasi:http/types@0.2.0#[method]fields.delete", vec![ValType::I32, ValType::I32, ValType::I32], vec![], ), ( - "wasi:http/types@0.2.0-rc-2023-10-18#[method]fields.append", + "wasi:http/types@0.2.0#[method]fields.append", vec![ ValType::I32, ValType::I32, @@ -76,117 +86,162 @@ fn get_wasi_http_fns() -> &'static Vec<(&'static str, FuncParams, FuncResults)> vec![], ), ( - "wasi:http/types@0.2.0-rc-2023-10-18#[method]fields.entries", + "wasi:http/types@0.2.0#[method]fields.entries", vec![ValType::I32], vec![ValType::I32], ), ( - "wasi:http/types@0.2.0-rc-2023-10-18#[method]fields.clone", + "wasi:http/types@0.2.0#[method]fields.clone", vec![ValType::I32], vec![ValType::I32], ), ( - "wasi:http/types@0.2.0-rc-2023-10-18#[dtor]incoming-body", + "wasi:http/types@0.2.0#[dtor]incoming-request", vec![ValType::I32], vec![], ), ( - "wasi:http/types@0.2.0-rc-2023-10-18#[method]incoming-body.stream", + "wasi:http/types@0.2.0#[method]incoming-request.method", vec![ValType::I32], vec![ValType::I32], ), ( - "wasi:http/types@0.2.0-rc-2023-10-18#[static]incoming-body.finish", + "wasi:http/types@0.2.0#[method]incoming-request.path-with-query", vec![ValType::I32], vec![ValType::I32], ), ( - "wasi:http/types@0.2.0-rc-2023-10-18#[dtor]outgoing-body", + "wasi:http/types@0.2.0#[method]incoming-request.scheme", + vec![ValType::I32], vec![ValType::I32], - vec![], ), ( - "wasi:http/types@0.2.0-rc-2023-10-18#[method]outgoing-body.write", + "wasi:http/types@0.2.0#[method]incoming-request.authority", vec![ValType::I32], vec![ValType::I32], ), ( - "wasi:http/types@0.2.0-rc-2023-10-18#[static]outgoing-body.finish", - vec![ValType::I32, ValType::I32, ValType::I32], - vec![], + "wasi:http/types@0.2.0#[method]incoming-request.headers", + vec![ValType::I32], + vec![ValType::I32], ), ( - "wasi:http/types@0.2.0-rc-2023-10-18#[dtor]incoming-request", + "wasi:http/types@0.2.0#[method]incoming-request.consume", + vec![ValType::I32], vec![ValType::I32], - vec![], ), ( - "wasi:http/types@0.2.0-rc-2023-10-18#[dtor]outgoing-request", + "wasi:http/types@0.2.0#[dtor]outgoing-request", vec![ValType::I32], vec![], ), ( - "wasi:http/types@0.2.0-rc-2023-10-18#[method]incoming-request.method", + "wasi:http/types@0.2.0#[constructor]outgoing-request", + vec![ + ValType::I32, + ValType::I32, + ValType::I32, + ValType::I32, + ValType::I32, + ValType::I32, + ValType::I32, + ValType::I32, + ValType::I32, + ValType::I32, + ValType::I32, + ValType::I32, + ValType::I32, + ValType::I32, + ], + vec![ValType::I32], + ), + ( + "wasi:http/types@0.2.0#[method]outgoing-request.body", vec![ValType::I32], vec![ValType::I32], ), ( - "wasi:http/types@0.2.0-rc-2023-10-18#[method]incoming-request.path-with-query", + "wasi:http/types@0.2.0#[method]outgoing-request.method", vec![ValType::I32], vec![ValType::I32], ), ( - "wasi:http/types@0.2.0-rc-2023-10-18#[method]incoming-request.scheme", + "wasi:http/types@0.2.0#[method]outgoing-request.set-method", vec![ValType::I32], vec![ValType::I32], ), ( - "wasi:http/types@0.2.0-rc-2023-10-18#[method]incoming-request.authority", + "wasi:http/types@0.2.0#[method]outgoing-request.path-with-query", vec![ValType::I32], vec![ValType::I32], ), ( - "wasi:http/types@0.2.0-rc-2023-10-18#[method]incoming-request.headers", + "wasi:http/types@0.2.0#[method]outgoing-request.set-path-with-query", vec![ValType::I32], vec![ValType::I32], ), ( - "wasi:http/types@0.2.0-rc-2023-10-18#[method]incoming-request.consume", + "wasi:http/types@0.2.0#[method]outgoing-request.scheme", vec![ValType::I32], vec![ValType::I32], ), ( - "wasi:http/types@0.2.0-rc-2023-10-18#[constructor]outgoing-request", - vec![ - ValType::I32, - ValType::I32, - ValType::I32, - ValType::I32, - ValType::I32, - ValType::I32, - ValType::I32, - ValType::I32, - ValType::I32, - ValType::I32, - ValType::I32, - ValType::I32, - ValType::I32, - ValType::I32, - ], + "wasi:http/types@0.2.0#[method]outgoing-request.set-scheme", + vec![ValType::I32], + vec![ValType::I32], + ), + ( + "wasi:http/types@0.2.0#[method]outgoing-request.authority", + vec![ValType::I32], + vec![ValType::I32], + ), + ( + "wasi:http/types@0.2.0#[method]outgoing-request.set-authority", + vec![ValType::I32], + vec![ValType::I32], + ), + ( + "wasi:http/types@0.2.0#[method]outgoing-request.headers", + vec![ValType::I32], + vec![ValType::I32], + ), + ( + "wasi:http/types@0.2.0#[dtor]incoming-body", + vec![ValType::I32], + vec![], + ), + ( + "wasi:http/types@0.2.0#[method]incoming-body.stream", + vec![ValType::I32], + vec![ValType::I32], + ), + ( + "wasi:http/types@0.2.0#[static]incoming-body.finish", + vec![ValType::I32], vec![ValType::I32], ), ( - "wasi:http/types@0.2.0-rc-2023-10-18#[method]outgoing-request.write", + "wasi:http/types@0.2.0#[dtor]outgoing-body", + vec![ValType::I32], + vec![], + ), + ( + "wasi:http/types@0.2.0#[method]outgoing-body.write", vec![ValType::I32], vec![ValType::I32], ), ( - "wasi:http/types@0.2.0-rc-2023-10-18#[dtor]response-outparam", + "wasi:http/types@0.2.0#[static]outgoing-body.finish", + vec![ValType::I32, ValType::I32, ValType::I32], + vec![], + ), + ( + "wasi:http/types@0.2.0#[dtor]response-outparam", vec![ValType::I32], vec![], ), ( - "wasi:http/types@0.2.0-rc-2023-10-18#[static]response-outparam.set", + "wasi:http/types@0.2.0#[static]response-outparam.set", vec![ ValType::I32, ValType::I32, @@ -197,72 +252,87 @@ fn get_wasi_http_fns() -> &'static Vec<(&'static str, FuncParams, FuncResults)> vec![ValType::I32], ), ( - "wasi:http/types@0.2.0-rc-2023-10-18#[dtor]incoming-response", + "wasi:http/types@0.2.0#[dtor]incoming-response", vec![ValType::I32], vec![], ), ( - "wasi:http/types@0.2.0-rc-2023-10-18#[dtor]outgoing-response", + "wasi:http/types@0.2.0#[method]incoming-response.status", + vec![ValType::I32], vec![ValType::I32], - vec![], ), ( - "wasi:http/types@0.2.0-rc-2023-10-18#[method]incoming-response.status", + "wasi:http/types@0.2.0#[method]incoming-response.headers", vec![ValType::I32], vec![ValType::I32], ), ( - "wasi:http/types@0.2.0-rc-2023-10-18#[method]incoming-response.headers", + "wasi:http/types@0.2.0#[method]incoming-response.consume", vec![ValType::I32], vec![ValType::I32], ), ( - "wasi:http/types@0.2.0-rc-2023-10-18#[method]incoming-response.consume", - vec![ValType::I32], + "wasi:http/types@0.2.0#[dtor]outgoing-response", vec![ValType::I32], + vec![], ), ( - "wasi:http/types@0.2.0-rc-2023-10-18#[constructor]outgoing-response", + "wasi:http/types@0.2.0#[constructor]outgoing-response", vec![ValType::I32, ValType::I32], vec![ValType::I32], ), ( - "wasi:http/types@0.2.0-rc-2023-10-18#[method]outgoing-response.write", + "wasi:http/types@0.2.0#[method]outgoing-response.body", + vec![ValType::I32], + vec![ValType::I32], + ), + ( + "wasi:http/types@0.2.0#[method]outgoing-response.status-code", + vec![ValType::I32], + vec![ValType::I32], + ), + ( + "wasi:http/types@0.2.0#[method]outgoing-response.set-status-code", + vec![ValType::I32], + vec![ValType::I32], + ), + ( + "wasi:http/types@0.2.0#[method]outgoing-response.headers", vec![ValType::I32], vec![ValType::I32], ), ( - "wasi:http/types@0.2.0-rc-2023-10-18#[dtor]future-incoming-response", + "wasi:http/types@0.2.0#[dtor]future-incoming-response", vec![ValType::I32], vec![], ), ( - "wasi:http/types@0.2.0-rc-2023-10-18#[method]future-incoming-response.get", + "wasi:http/types@0.2.0#[method]future-incoming-response.get", vec![ValType::I32], vec![ValType::I32], ), ( - "wasi:http/types@0.2.0-rc-2023-10-18#[method]future-incoming-response.subscribe", + "wasi:http/types@0.2.0#[method]future-incoming-response.subscribe", vec![ValType::I32], vec![ValType::I32], ), ( - "wasi:http/types@0.2.0-rc-2023-10-18#[dtor]future-trailers", + "wasi:http/types@0.2.0#[dtor]future-trailers", vec![ValType::I32], vec![], ), ( - "wasi:http/types@0.2.0-rc-2023-10-18#[method]future-trailers.subscribe", + "wasi:http/types@0.2.0#[method]future-trailers.subscribe", vec![ValType::I32], vec![ValType::I32], ), ( - "wasi:http/types@0.2.0-rc-2023-10-18#[method]future-trailers.get", + "wasi:http/types@0.2.0#[method]future-trailers.get", vec![ValType::I32], vec![ValType::I32], ), ( - "wasi:http/outgoing-handler@0.2.0-rc-2023-10-18#handle", + "wasi:http/outgoing-handler@0.2.0#handle", vec![ValType::I32; 8], vec![ValType::I32], ), @@ -272,6 +342,6 @@ fn get_wasi_http_fns() -> &'static Vec<(&'static str, FuncParams, FuncResults)> /// Replace exports related to HTTP in WASI to deny access pub(crate) fn deny_http_virt(module: &mut Module) -> Result<()> { - stub_http_virt(module)?; + stub_virt(module, &["wasi:http/"], false)?; replace_or_insert_stub_for_exports(module, get_wasi_http_fns()) } diff --git a/src/virt_deny/random.rs b/src/virt_deny/random.rs index c4bdcf8..c73ea4b 100644 --- a/src/virt_deny/random.rs +++ b/src/virt_deny/random.rs @@ -13,37 +13,37 @@ fn get_wasi_random_fns() -> &'static Vec<(&'static str, FuncParams, FuncResults) WASI_RANDOM_FNS.get_or_init(|| { Vec::from([ ( - "wasi:random/random@0.2.0-rc-2023-11-10#get-random-bytes", + "wasi:random/random@0.2.0#get-random-bytes", vec![ValType::I64], vec![ValType::I32], ), ( - "cabi_post_wasi:random/random@0.2.0-rc-2023-11-10#get-random-bytes", + "cabi_post_wasi:random/random@0.2.0#get-random-bytes", vec![ValType::I32], vec![], ), ( - "wasi:random/random@0.2.0-rc-2023-11-10#get-random-u64", + "wasi:random/random@0.2.0#get-random-u64", vec![], vec![ValType::I64], ), ( - "wasi:random/insecure@0.2.0-rc-2023-11-10#get-insecure-random-bytes", + "wasi:random/insecure@0.2.0#get-insecure-random-bytes", vec![ValType::I64], vec![ValType::I32], ), ( - "cabi_post_wasi:random/insecure@0.2.0-rc-2023-11-10#get-insecure-random-bytes", + "cabi_post_wasi:random/insecure@0.2.0#get-insecure-random-bytes", vec![ValType::I32], vec![], ), ( - "wasi:random/insecure@0.2.0-rc-2023-11-10#get-insecure-random-u64", + "wasi:random/insecure@0.2.0#get-insecure-random-u64", vec![], vec![ValType::I64], ), ( - "wasi:random/insecure-seed@0.2.0-rc-2023-11-10#insecure-seed", + "wasi:random/insecure-seed@0.2.0#insecure-seed", vec![], vec![ValType::I32], ), diff --git a/src/virt_deny/sockets.rs b/src/virt_deny/sockets.rs index 87053ea..a18bd3e 100644 --- a/src/virt_deny/sockets.rs +++ b/src/virt_deny/sockets.rs @@ -3,7 +3,7 @@ use std::sync::OnceLock; use anyhow::Result; use walrus::{FuncParams, FuncResults, Module, ValType}; -use crate::virt_io::stub_sockets_virt; +use crate::walrus_ops::stub_virt; use super::replace_or_insert_stub_for_exports; @@ -15,49 +15,42 @@ pub fn get_wasi_sockets_fns() -> &'static Vec<(&'static str, FuncParams, FuncRes WASI_SOCKETS_FNS.get_or_init(|| { Vec::from([ ( - "wasi:sockets/network@0.2.0-rc-2023-10-18#drop-network", + "wasi:sockets/network@0.2.0#drop-network", vec![ValType::I32], vec![], ), ( - "wasi:sockets/instance-network@0.2.0-rc-2023-10-18#instance-network", + "wasi:sockets/instance-network@0.2.0#instance-network", vec![], vec![ValType::I32], ), ( - "wasi:sockets/ip-name-lookup@0.2.0-rc-2023-10-18#resolve-addresses", - vec![ - ValType::I32, - ValType::I32, - ValType::I32, - ValType::I32, - ValType::I32, - ValType::I32, - ], + "wasi:sockets/ip-name-lookup@0.2.0#resolve-addresses", + vec![ValType::I32, ValType::I32, ValType::I32], vec![ValType::I32], ), ( - "wasi:sockets/ip-name-lookup@0.2.0-rc-2023-10-18#resolve-next-address", + "wasi:sockets/ip-name-lookup@0.2.0#resolve-next-address", vec![ValType::I32], vec![ValType::I32], ), ( - "wasi:sockets/ip-name-lookup@0.2.0-rc-2023-10-18#drop-resolve-address-stream", + "wasi:sockets/ip-name-lookup@0.2.0#drop-resolve-address-stream", vec![ValType::I32], vec![], ), ( - "wasi:sockets/ip-name-lookup@0.2.0-rc-2023-10-18#subscribe", + "wasi:sockets/ip-name-lookup@0.2.0#subscribe", vec![ValType::I32], vec![ValType::I32], ), ( - "wasi:sockets/tcp-create-socket@0.2.0-rc-2023-10-18#create-tcp-socket", + "wasi:sockets/tcp-create-socket@0.2.0#create-tcp-socket", vec![ValType::I32], vec![ValType::I32], ), ( - "wasi:sockets/tcp@0.2.0-rc-2023-10-18#start-bind", + "wasi:sockets/tcp@0.2.0#start-bind", vec![ ValType::I32, ValType::I32, @@ -77,12 +70,12 @@ pub fn get_wasi_sockets_fns() -> &'static Vec<(&'static str, FuncParams, FuncRes vec![ValType::I32], ), ( - "wasi:sockets/tcp@0.2.0-rc-2023-10-18#finish-bind", + "wasi:sockets/tcp@0.2.0#finish-bind", vec![ValType::I32], vec![ValType::I32], ), ( - "wasi:sockets/tcp@0.2.0-rc-2023-10-18#start-connect", + "wasi:sockets/tcp@0.2.0#start-connect", vec![ ValType::I32, ValType::I32, @@ -102,127 +95,142 @@ pub fn get_wasi_sockets_fns() -> &'static Vec<(&'static str, FuncParams, FuncRes vec![ValType::I32], ), ( - "wasi:sockets/tcp@0.2.0-rc-2023-10-18#finish-connect", + "wasi:sockets/tcp@0.2.0#finish-connect", vec![ValType::I32], vec![ValType::I32], ), ( - "wasi:sockets/tcp@0.2.0-rc-2023-10-18#start-listen", + "wasi:sockets/tcp@0.2.0#start-listen", vec![ValType::I32], vec![ValType::I32], ), ( - "wasi:sockets/tcp@0.2.0-rc-2023-10-18#finish-listen", + "wasi:sockets/tcp@0.2.0#finish-listen", vec![ValType::I32], vec![ValType::I32], ), ( - "wasi:sockets/tcp@0.2.0-rc-2023-10-18#accept", + "wasi:sockets/tcp@0.2.0#accept", vec![ValType::I32], vec![ValType::I32], ), ( - "wasi:sockets/tcp@0.2.0-rc-2023-10-18#local-address", + "wasi:sockets/tcp@0.2.0#local-address", vec![ValType::I32], vec![ValType::I32], ), ( - "wasi:sockets/tcp@0.2.0-rc-2023-10-18#remote-address", + "wasi:sockets/tcp@0.2.0#remote-address", vec![ValType::I32], vec![ValType::I32], ), ( - "wasi:sockets/tcp@0.2.0-rc-2023-10-18#address-family", + "wasi:sockets/tcp@0.2.0#[method]tcp-socket.is-listening", vec![ValType::I32], vec![ValType::I32], ), ( - "wasi:sockets/tcp@0.2.0-rc-2023-10-18#ipv6-only", + "wasi:sockets/tcp@0.2.0#address-family", vec![ValType::I32], vec![ValType::I32], ), ( - "wasi:sockets/tcp@0.2.0-rc-2023-10-18#set-ipv6-only", - vec![ValType::I32, ValType::I32], + "wasi:sockets/tcp@0.2.0#set-listen-backlog-size", + vec![ValType::I32, ValType::I64], vec![ValType::I32], ), ( - "wasi:sockets/tcp@0.2.0-rc-2023-10-18#set-listen-backlog-size", - vec![ValType::I32, ValType::I64], + "wasi:sockets/tcp@0.2.0#keep-alive-enabled", + vec![ValType::I32], vec![ValType::I32], ), ( - "wasi:sockets/tcp@0.2.0-rc-2023-10-18#keep-alive", + "wasi:sockets/tcp@0.2.0#set-keep-alive-enabled", + vec![ValType::I32, ValType::I32], vec![ValType::I32], + ), + ( + "wasi:sockets/tcp@0.2.0#keep-alive-idle-time", + vec![ValType::I32], // fixme vec![ValType::I32], ), ( - "wasi:sockets/tcp@0.2.0-rc-2023-10-18#set-keep-alive", - vec![ValType::I32, ValType::I32], + "wasi:sockets/tcp@0.2.0#set-keep-alive-idle-time", + vec![ValType::I32, ValType::I32], // fixme vec![ValType::I32], ), ( - "wasi:sockets/tcp@0.2.0-rc-2023-10-18#no-delay", + "wasi:sockets/tcp@0.2.0#keep-alive-interval", + vec![ValType::I32], // fixme vec![ValType::I32], + ), + ( + "wasi:sockets/tcp@0.2.0#set-keep-alive-interval", + vec![ValType::I32, ValType::I32], // fixme vec![ValType::I32], ), ( - "wasi:sockets/tcp@0.2.0-rc-2023-10-18#set-no-delay", - vec![ValType::I32, ValType::I32], + "wasi:sockets/tcp@0.2.0#keep-alive-count", + vec![ValType::I32], // fixme + vec![ValType::I32], + ), + ( + "wasi:sockets/tcp@0.2.0#set-keep-alive-count", + vec![ValType::I32, ValType::I32], // fixme vec![ValType::I32], ), ( - "wasi:sockets/tcp@0.2.0-rc-2023-10-18#unicast-hop-limit", + "wasi:sockets/tcp@0.2.0#hop-limit", vec![ValType::I32], vec![ValType::I32], ), ( - "wasi:sockets/tcp@0.2.0-rc-2023-10-18#set-unicast-hop-limit", + "wasi:sockets/tcp@0.2.0#set-hop-limit", vec![ValType::I32, ValType::I32], vec![ValType::I32], ), ( - "wasi:sockets/tcp@0.2.0-rc-2023-10-18#receive-buffer-size", + "wasi:sockets/tcp@0.2.0#receive-buffer-size", vec![ValType::I32], vec![ValType::I32], ), ( - "wasi:sockets/tcp@0.2.0-rc-2023-10-18#set-receive-buffer-size", + "wasi:sockets/tcp@0.2.0#set-receive-buffer-size", vec![ValType::I32, ValType::I64], vec![ValType::I32], ), ( - "wasi:sockets/tcp@0.2.0-rc-2023-10-18#send-buffer-size", + "wasi:sockets/tcp@0.2.0#send-buffer-size", vec![ValType::I32], vec![ValType::I32], ), ( - "wasi:sockets/tcp@0.2.0-rc-2023-10-18#set-send-buffer-size", + "wasi:sockets/tcp@0.2.0#set-send-buffer-size", vec![ValType::I32, ValType::I64], vec![ValType::I32], ), ( - "wasi:sockets/tcp@0.2.0-rc-2023-10-18#subscribe", + "wasi:sockets/tcp@0.2.0#subscribe", vec![ValType::I32], vec![ValType::I32], ), ( - "wasi:sockets/tcp@0.2.0-rc-2023-10-18#shutdown", + "wasi:sockets/tcp@0.2.0#shutdown", vec![ValType::I32, ValType::I32], vec![ValType::I32], ), ( - "wasi:sockets/tcp@0.2.0-rc-2023-10-18#drop-tcp-socket", + "wasi:sockets/tcp@0.2.0#drop-tcp-socket", vec![ValType::I32], vec![], ), ( - "wasi:sockets/udp-create-socket@0.2.0-rc-2023-10-18#create-udp-socket", + "wasi:sockets/udp-create-socket@0.2.0#create-udp-socket", vec![ValType::I32], vec![ValType::I32], ), ( - "wasi:sockets/udp@0.2.0-rc-2023-10-18#start-bind", + "wasi:sockets/udp@0.2.0#start-bind", vec![ ValType::I32, ValType::I32, @@ -242,107 +250,118 @@ pub fn get_wasi_sockets_fns() -> &'static Vec<(&'static str, FuncParams, FuncRes vec![ValType::I32], ), ( - "wasi:sockets/udp@0.2.0-rc-2023-10-18#finish-bind", + "wasi:sockets/udp@0.2.0#finish-bind", vec![ValType::I32], vec![ValType::I32], ), ( - "wasi:sockets/udp@0.2.0-rc-2023-10-18#start-connect", - vec![ - ValType::I32, - ValType::I32, - ValType::I32, - ValType::I32, - ValType::I32, - ValType::I32, - ValType::I32, - ValType::I32, - ValType::I32, - ValType::I32, - ValType::I32, - ValType::I32, - ValType::I32, - ValType::I32, - ], + "wasi:sockets/udp@0.2.0#local-address", + vec![ValType::I32], vec![ValType::I32], ), ( - "wasi:sockets/udp@0.2.0-rc-2023-10-18#finish-connect", + "wasi:sockets/udp@0.2.0#remote-address", vec![ValType::I32], vec![ValType::I32], ), ( - "wasi:sockets/udp@0.2.0-rc-2023-10-18#receive", - vec![ValType::I32, ValType::I64], + "wasi:sockets/udp@0.2.0#address-family", + vec![ValType::I32], vec![ValType::I32], ), ( - "wasi:sockets/udp@0.2.0-rc-2023-10-18#send", - vec![ValType::I32, ValType::I32, ValType::I32], + "wasi:sockets/udp@0.2.0#unicast-hop-limit", + vec![ValType::I32], vec![ValType::I32], ), ( - "wasi:sockets/udp@0.2.0-rc-2023-10-18#local-address", - vec![ValType::I32], + "wasi:sockets/udp@0.2.0#set-unicast-hop-limit", + vec![ValType::I32, ValType::I32], vec![ValType::I32], ), ( - "wasi:sockets/udp@0.2.0-rc-2023-10-18#remote-address", + "wasi:sockets/udp@0.2.0#receive-buffer-size", vec![ValType::I32], vec![ValType::I32], ), ( - "wasi:sockets/udp@0.2.0-rc-2023-10-18#address-family", - vec![ValType::I32], + "wasi:sockets/udp@0.2.0#set-receive-buffer-size", + vec![ValType::I32, ValType::I64], vec![ValType::I32], ), ( - "wasi:sockets/udp@0.2.0-rc-2023-10-18#ipv6-only", + "wasi:sockets/udp@0.2.0#send-buffer-size", vec![ValType::I32], vec![ValType::I32], ), ( - "wasi:sockets/udp@0.2.0-rc-2023-10-18#set-ipv6-only", - vec![ValType::I32, ValType::I32], + "wasi:sockets/udp@0.2.0#set-send-buffer-size", + vec![ValType::I32, ValType::I64], vec![ValType::I32], ), ( - "wasi:sockets/udp@0.2.0-rc-2023-10-18#unicast-hop-limit", + "wasi:sockets/udp@0.2.0#subscribe", vec![ValType::I32], vec![ValType::I32], ), ( - "wasi:sockets/udp@0.2.0-rc-2023-10-18#set-unicast-hop-limit", - vec![ValType::I32, ValType::I32], + "wasi:sockets/udp@0.2.0#drop-udp-socket", vec![ValType::I32], + vec![], ), ( - "wasi:sockets/udp@0.2.0-rc-2023-10-18#receive-buffer-size", - vec![ValType::I32], - vec![ValType::I32], + "wasi:sockets/udp@0.2.0#[method]udp-socket.stream", + vec![ + ValType::I32, + ValType::I32, + ValType::I32, + ValType::I32, + ValType::I32, + ValType::I32, + ValType::I32, + ValType::I32, + ValType::I32, + ValType::I32, + ValType::I32, + ValType::I32, + ValType::I32, + ValType::I32, + ValType::I32, + ], + vec![], ), ( - "wasi:sockets/udp@0.2.0-rc-2023-10-18#set-receive-buffer-size", - vec![ValType::I32, ValType::I64], - vec![ValType::I32], + "wasi:sockets/udp@0.2.0#[method]incoming-datagram-stream.receive", + vec![ValType::I32, ValType::I64, ValType::I32], + vec![], ), ( - "wasi:sockets/udp@0.2.0-rc-2023-10-18#send-buffer-size", + "wasi:sockets/udp@0.2.0#[method]incoming-datagram-stream.subscribe", vec![ValType::I32], vec![ValType::I32], ), ( - "wasi:sockets/udp@0.2.0-rc-2023-10-18#set-send-buffer-size", - vec![ValType::I32, ValType::I64], + "wasi:sockets/udp@0.2.0#[resource-drop]incoming-datagram-stream", vec![ValType::I32], + vec![], + ), + ( + "wasi:sockets/udp@0.2.0#[method]outgoing-datagram-stream.check-send", + vec![ValType::I32, ValType::I32], + vec![], + ), + ( + "wasi:sockets/udp@0.2.0#[method]outgoing-datagram-stream.send", + vec![ValType::I32, ValType::I32, ValType::I32, ValType::I32], + vec![], ), ( - "wasi:sockets/udp@0.2.0-rc-2023-10-18#subscribe", + "wasi:sockets/udp@0.2.0#[method]outgoing-datagram-stream.subscribe", vec![ValType::I32], vec![ValType::I32], ), ( - "wasi:sockets/udp@0.2.0-rc-2023-10-18#drop-udp-socket", + "wasi:sockets/udp@0.2.0#[resource-drop]outgoing-datagram-stream", vec![ValType::I32], vec![], ), @@ -352,6 +371,6 @@ pub fn get_wasi_sockets_fns() -> &'static Vec<(&'static str, FuncParams, FuncRes /// Replace exports related to sockets in WASI to deny access pub(crate) fn deny_sockets_virt(module: &mut Module) -> Result<()> { - stub_sockets_virt(module)?; + stub_virt(module, &["wasi:sockets/"], false)?; replace_or_insert_stub_for_exports(module, get_wasi_sockets_fns()) } diff --git a/src/virt_env.rs b/src/virt_env.rs index 491b784..11bb545 100644 --- a/src/virt_env.rs +++ b/src/virt_env.rs @@ -222,7 +222,7 @@ pub(crate) fn stub_env_virt(module: &mut Module) -> Result<()> { module.replace_imported_func( module .imports - .get_func("wasi:cli/environment@0.2.0-rc-2023-12-05", fn_name)?, + .get_func("wasi:cli/environment@0.2.0", fn_name)?, |(body, _)| { body.unreachable(); }, @@ -233,19 +233,19 @@ pub(crate) fn stub_env_virt(module: &mut Module) -> Result<()> { } /// Strip exported functions that implement the WASI CLI environment functionality -/// -/// This function *does not* throw an error if an export does not exist. pub(crate) fn strip_env_virt(module: &mut Module) -> Result<()> { stub_env_virt(module)?; for fn_name in WASI_ENV_FNS { - if let Ok(fid) = module.exports.get_func(format!( - "wasi:cli/environment@0.2.0-rc-2023-12-05#{fn_name}" - )) { - module.replace_exported_func(fid, |(body, _)| { - body.unreachable(); - })?; + let Ok(fid) = module + .exports + .get_func(format!("wasi:cli/environment@0.2.0#{fn_name}")) + else { + bail!("Expected CLI function {fn_name}") }; + module.replace_exported_func(fid, |(body, _)| { + body.unreachable(); + })?; } Ok(()) diff --git a/src/virt_io/mod.rs b/src/virt_io.rs similarity index 93% rename from src/virt_io/mod.rs rename to src/virt_io.rs index c9f3409..53026e8 100644 --- a/src/virt_io/mod.rs +++ b/src/virt_io.rs @@ -7,41 +7,11 @@ use walrus::{ir::Value, ExportItem, GlobalKind, InitExpr, Module}; use crate::{ data::{Data, WasmEncode}, - walrus_ops::{get_active_data_segment, get_stack_global}, + walrus_ops::{get_active_data_segment, get_stack_global, strip_virt, stub_virt}, }; -mod clocks; -mod filesystem; -mod http; -mod io; -mod sockets; -mod stdio; - -pub(crate) use clocks::{strip_clocks_virt, stub_clocks_virt}; -pub(crate) use filesystem::{strip_fs_virt, stub_fs_virt}; -pub(crate) use http::{strip_http_virt, stub_http_virt}; -pub(crate) use io::{strip_io_virt, stub_io_virt}; -pub(crate) use sockets::{strip_sockets_virt, stub_sockets_virt}; -pub(crate) use stdio::{strip_stdio_virt, stub_stdio_virt}; - pub type VirtualFiles = BTreeMap; -/// How to deal with a stubbed/stripped export -/// -/// This enum is used mostly for nearly-static data, which exists -/// to make it easy to iterate over stubbing modules & functions that must -/// be manipulated. -enum StubRequirement { - /// The import/export that is stubbed/stripped must be present *and* must be replaced - Required, - /// The import/export that is stubbed/stripped is allowed to be missing - Optional, - /// Whether the import/export must be present and replaced - /// depends on external factors (use-case specific), in this case - /// whether the filesystem is used or not - DependsOnFsUsage, -} - #[derive(ValueEnum, Clone, Debug, Default, Deserialize)] #[serde(rename_all = "kebab-case")] pub enum StdioCfg { @@ -387,10 +357,10 @@ pub(crate) fn create_io_virt<'a>( StdioCfg::Deny => {} } } else { - strip_stdio_virt(module)?; + strip_virt(module, &["wasi:cli/std", "wasi:cli/terminal"])?; } if disable_stdio { - stub_stdio_virt(module)?; + stub_virt(module, &["wasi:cli/std", "wasi:cli/terminal"], false)?; } // First we iterate the options and fill in all HostDir and HostFile entries @@ -547,9 +517,9 @@ pub(crate) fn create_io_virt<'a>( // replacing it with a stub panic if !fs_passthrough { if disable_stdio { - stub_io_virt(module)?; + stub_virt(module, &["wasi:io/"], false)?; } - stub_fs_virt(module, true)?; + stub_virt(module, &["wasi:filesystem/"], false)?; } else { flags |= FLAGS_HOST_PASSTHROUGH; } diff --git a/src/virt_io/clocks.rs b/src/virt_io/clocks.rs deleted file mode 100644 index 3a6b0d6..0000000 --- a/src/virt_io/clocks.rs +++ /dev/null @@ -1,75 +0,0 @@ -use anyhow::{bail, Context, Result}; -use walrus::Module; - -use super::StubRequirement; - -/// Imports exposed by WASI for clocks functionality which are allowed to be -const WASI_CLOCKS_IMPORTS: [(&str, &str, &StubRequirement); 4] = [ - ( - "wasi:clocks/monotonic-clock@0.2.0-rc-2023-11-10", - "now", - &StubRequirement::Required, - ), - ( - "wasi:clocks/monotonic-clock@0.2.0-rc-2023-11-10", - "resolution", - &StubRequirement::Required, - ), - ( - "wasi:clocks/monotonic-clock@0.2.0-rc-2023-11-10", - "subscribe-instant", - &StubRequirement::Required, - ), - ( - "wasi:clocks/monotonic-clock@0.2.0-rc-2023-11-10", - "subscribe-duration", - &StubRequirement::Required, - ), -]; - -/// Replace imported WASI functions that implement clocks access with no-ops -pub(crate) fn stub_clocks_virt(module: &mut Module) -> Result<()> { - for (module_name, func_name, stub_requirement) in WASI_CLOCKS_IMPORTS { - match stub_requirement { - StubRequirement::Required => { - let fid = module - .imports - .get_func(module_name, func_name) - .with_context(|| { - format!( - "failed to find required clocks import [{func_name}] in module [{module_name}]" - ) - })?; - module - .replace_imported_func(fid, |(body, _)| { - body.unreachable(); - }) - .with_context(|| { - "failed to stub clocks functionality [{}] in module [{export_name}]" - })?; - } - _ => bail!("unexpected stub requirement in imports for WASI clocks"), - } - } - Ok(()) -} - -/// Exported functions related to WASI clocks -const WASI_CLOCK_EXPORTS: [&str; 4] = [ - "wasi:clocks/monotonic-clock@0.2.0-rc-2023-11-10#now", - "wasi:clocks/monotonic-clock@0.2.0-rc-2023-11-10#resolution", - "wasi:clocks/monotonic-clock@0.2.0-rc-2023-11-10#subscribe-instant", - "wasi:clocks/monotonic-clock@0.2.0-rc-2023-11-10#subscribe-duration", -]; - -/// Strip exported WASI functions that implement clock access -pub(crate) fn strip_clocks_virt(module: &mut Module) -> Result<()> { - stub_clocks_virt(module)?; - for export_name in WASI_CLOCK_EXPORTS { - module - .exports - .remove(export_name) - .with_context(|| format!("failed to strip WASI clocks function [{export_name}]"))?; - } - Ok(()) -} diff --git a/src/virt_io/filesystem.rs b/src/virt_io/filesystem.rs deleted file mode 100644 index 379edc3..0000000 --- a/src/virt_io/filesystem.rs +++ /dev/null @@ -1,255 +0,0 @@ -use anyhow::{Context, Result}; -use walrus::Module; - -use super::StubRequirement; - -/// Imports exposed by WASI for Filesystem functionality -/// -/// Some are allowed to be missing, some are required depending on -/// whether the FS is used or not (`fs_used` in `stub_fs_virt`) -const WASI_FS_IMPORTS: &[(&str, &str, &StubRequirement)] = &[ - ( - "wasi:filesystem/types@0.2.0-rc-2023-11-10", - "[method]descriptor.advise", - &StubRequirement::Optional, - ), - ( - "wasi:filesystem/types@0.2.0-rc-2023-11-10", - "[method]descriptor.append-via-stream", - &StubRequirement::Optional, - ), - ( - "wasi:filesystem/types@0.2.0-rc-2023-11-10", - "[method]descriptor.create-directory-at", - &StubRequirement::Optional, - ), - ( - "wasi:filesystem/types@0.2.0-rc-2023-11-10", - "[method]descriptor.get-flags", - &StubRequirement::Optional, - ), - ( - "wasi:filesystem/types@0.2.0-rc-2023-11-10", - "[method]descriptor.link-at", - &StubRequirement::Optional, - ), - ( - "wasi:filesystem/types@0.2.0-rc-2023-11-10", - "[method]descriptor.metadata-hash", - &StubRequirement::Optional, - ), - ( - "wasi:filesystem/types@0.2.0-rc-2023-11-10", - "[method]descriptor.metadata-hash-at", - &StubRequirement::Optional, - ), - ( - "wasi:filesystem/types@0.2.0-rc-2023-11-10", - "[method]descriptor.read-directory", - &StubRequirement::Optional, - ), - ( - "wasi:filesystem/types@0.2.0-rc-2023-11-10", - "[method]descriptor.readlink-at", - &StubRequirement::Optional, - ), - ( - "wasi:filesystem/types@0.2.0-rc-2023-11-10", - "[method]descriptor.remove-directory-at", - &StubRequirement::Optional, - ), - ( - "wasi:filesystem/types@0.2.0-rc-2023-11-10", - "[method]descriptor.rename-at", - &StubRequirement::Optional, - ), - ( - "wasi:filesystem/types@0.2.0-rc-2023-11-10", - "[method]descriptor.set-size", - &StubRequirement::Optional, - ), - ( - "wasi:filesystem/types@0.2.0-rc-2023-11-10", - "[method]descriptor.set-times", - &StubRequirement::Optional, - ), - ( - "wasi:filesystem/types@0.2.0-rc-2023-11-10", - "[method]descriptor.set-times-at", - &StubRequirement::Optional, - ), - ( - "wasi:filesystem/types@0.2.0-rc-2023-11-10", - "[method]descriptor.symlink-at", - &StubRequirement::Optional, - ), - ( - "wasi:filesystem/types@0.2.0-rc-2023-11-10", - "[method]descriptor.sync", - &StubRequirement::Optional, - ), - ( - "wasi:filesystem/types@0.2.0-rc-2023-11-10", - "[method]descriptor.sync-data", - &StubRequirement::Optional, - ), - ( - "wasi:filesystem/types@0.2.0-rc-2023-11-10", - "[method]descriptor.unlink-file-at", - &StubRequirement::Optional, - ), - ( - "wasi:filesystem/types@0.2.0-rc-2023-11-10", - "[method]descriptor.write", - &StubRequirement::Optional, - ), - ( - "wasi:filesystem/types@0.2.0-rc-2023-11-10", - "[method]descriptor.write-via-stream", - &StubRequirement::Optional, - ), - ( - "wasi:filesystem/preopens@0.2.0-rc-2023-11-10", - "get-directories", - &StubRequirement::DependsOnFsUsage, - ), - ( - "wasi:filesystem/types@0.2.0-rc-2023-11-10", - "[resource-drop]descriptor", - &StubRequirement::DependsOnFsUsage, - ), - ( - "wasi:filesystem/types@0.2.0-rc-2023-11-10", - "[resource-drop]directory-entry-stream", - &StubRequirement::DependsOnFsUsage, - ), - ( - "wasi:filesystem/types@0.2.0-rc-2023-11-10", - "[method]descriptor.get-type", - &StubRequirement::DependsOnFsUsage, - ), - ( - "wasi:filesystem/types@0.2.0-rc-2023-11-10", - "[method]descriptor.is-same-object", - &StubRequirement::DependsOnFsUsage, - ), - ( - "wasi:filesystem/types@0.2.0-rc-2023-11-10", - "[method]descriptor.open-at", - &StubRequirement::DependsOnFsUsage, - ), - ( - "wasi:filesystem/types@0.2.0-rc-2023-11-10", - "[method]descriptor.read", - &StubRequirement::Optional, - ), - ( - "wasi:filesystem/types@0.2.0-rc-2023-11-10", - "[method]directory-entry-stream.read-directory-entry", - &StubRequirement::DependsOnFsUsage, - ), - ( - "wasi:filesystem/types@0.2.0-rc-2023-11-10", - "[method]descriptor.read-via-stream", - &StubRequirement::DependsOnFsUsage, - ), - ( - "wasi:filesystem/types@0.2.0-rc-2023-11-10", - "[method]descriptor.stat", - &StubRequirement::DependsOnFsUsage, - ), - ( - "wasi:filesystem/types@0.2.0-rc-2023-11-10", - "[method]descriptor.stat-at", - &StubRequirement::DependsOnFsUsage, - ), -]; - -/// Replace imported WASI functions that implement filesystem access with no-ops -// Stubs must be _comprehensive_ in order to act as full deny over entire subsystem -// when stubbing functions that are not part of the virtual adapter exports, we therefore -// have to create this functions fresh. -// Ideally, we should generate these stubs automatically from WASI definitions. -pub(crate) fn stub_fs_virt(module: &mut Module, uses_fs: bool) -> Result<()> { - // Replace the filesystem functions that are allowed to be missing - for (module_name, func_name, stub_requirement) in WASI_FS_IMPORTS { - match (stub_requirement, uses_fs) { - // If the stub is always required, or depends on FS usage and uses_fs is set - // then we *must* find the function and replace it - (StubRequirement::Required, _) | (StubRequirement::DependsOnFsUsage, true) => { - let fid = module.imports.get_func(module_name, func_name) - .with_context(|| format!("failed to find required filesystem import [{func_name}] in module [{module_name}]"))?; - - module - .replace_imported_func(fid, |(body, _)| { - body.unreachable(); - }) - .with_context(|| { - "failed to stub filesystem functionality [{}] in module [{export_name}]" - })?; - } - // If the stub is optional, or required w/ FS usage and fs is not used, we can replace - // the functions optimistically, and not fail if they are missing - (StubRequirement::Optional, _) | (StubRequirement::DependsOnFsUsage, false) => { - if let Ok(fid) = module.imports.get_func(module_name, func_name) { - module - .replace_imported_func(fid, |(body, _)| { - body.unreachable(); - }) - .with_context(|| { - "failed to stub filesystem functionality [{}] in module [{export_name}]" - })?; - } - } - }; - } - Ok(()) -} - -const WASI_FILESYSTEM_EXPORTS: &[&str] = &[ - "wasi:filesystem/preopens@0.2.0-rc-2023-11-10#get-directories", - "wasi:filesystem/types@0.2.0-rc-2023-11-10#[method]descriptor.read-via-stream", - "wasi:filesystem/types@0.2.0-rc-2023-11-10#[method]descriptor.write-via-stream", - "wasi:filesystem/types@0.2.0-rc-2023-11-10#[method]descriptor.append-via-stream", - "wasi:filesystem/types@0.2.0-rc-2023-11-10#[method]descriptor.advise", - "wasi:filesystem/types@0.2.0-rc-2023-11-10#[method]descriptor.sync-data", - "wasi:filesystem/types@0.2.0-rc-2023-11-10#[method]descriptor.get-flags", - "wasi:filesystem/types@0.2.0-rc-2023-11-10#[method]descriptor.get-type", - "wasi:filesystem/types@0.2.0-rc-2023-11-10#[method]descriptor.set-size", - "wasi:filesystem/types@0.2.0-rc-2023-11-10#[method]descriptor.set-times", - "wasi:filesystem/types@0.2.0-rc-2023-11-10#[method]descriptor.read", - "wasi:filesystem/types@0.2.0-rc-2023-11-10#[method]descriptor.write", - "wasi:filesystem/types@0.2.0-rc-2023-11-10#[method]descriptor.read-directory", - "wasi:filesystem/types@0.2.0-rc-2023-11-10#[method]descriptor.sync", - "wasi:filesystem/types@0.2.0-rc-2023-11-10#[method]descriptor.create-directory-at", - "wasi:filesystem/types@0.2.0-rc-2023-11-10#[method]descriptor.stat", - "wasi:filesystem/types@0.2.0-rc-2023-11-10#[method]descriptor.stat-at", - "wasi:filesystem/types@0.2.0-rc-2023-11-10#[method]descriptor.set-times-at", - "wasi:filesystem/types@0.2.0-rc-2023-11-10#[method]descriptor.link-at", - "wasi:filesystem/types@0.2.0-rc-2023-11-10#[method]descriptor.open-at", - "wasi:filesystem/types@0.2.0-rc-2023-11-10#[method]descriptor.readlink-at", - "wasi:filesystem/types@0.2.0-rc-2023-11-10#[method]descriptor.remove-directory-at", - "wasi:filesystem/types@0.2.0-rc-2023-11-10#[method]descriptor.rename-at", - "wasi:filesystem/types@0.2.0-rc-2023-11-10#[method]descriptor.symlink-at", - "wasi:filesystem/types@0.2.0-rc-2023-11-10#[method]descriptor.unlink-file-at", - "wasi:filesystem/types@0.2.0-rc-2023-11-10#[method]descriptor.metadata-hash", - "wasi:filesystem/types@0.2.0-rc-2023-11-10#[method]descriptor.metadata-hash-at", - "wasi:filesystem/types@0.2.0-rc-2023-11-10#[method]descriptor.is-same-object", - "wasi:filesystem/types@0.2.0-rc-2023-11-10#[dtor]descriptor", - "wasi:filesystem/types@0.2.0-rc-2023-11-10#[method]directory-entry-stream.read-directory-entry", - "wasi:filesystem/types@0.2.0-rc-2023-11-10#[dtor]directory-entry-stream", -]; - -/// Strip exported WASI functions that implement filesystem access -pub(crate) fn strip_fs_virt(module: &mut Module) -> Result<()> { - stub_fs_virt(module, false)?; - - for &export_name in WASI_FILESYSTEM_EXPORTS { - module - .exports - .remove(export_name) - .with_context(|| format!("failed to strip WASI FS function [{export_name}]"))?; - } - - Ok(()) -} diff --git a/src/virt_io/http.rs b/src/virt_io/http.rs deleted file mode 100644 index cf63823..0000000 --- a/src/virt_io/http.rs +++ /dev/null @@ -1,229 +0,0 @@ -use anyhow::{bail, Context, Result}; -use walrus::Module; - -use super::StubRequirement; - -/// Exported functions related to WASI http -const WASI_HTTP_EXPORTS: &[&str] = &[ - "wasi:http/types@0.2.0-rc-2023-10-18#[dtor]fields", - "wasi:http/types@0.2.0-rc-2023-10-18#[constructor]fields", - "wasi:http/types@0.2.0-rc-2023-10-18#[method]fields.get", - "wasi:http/types@0.2.0-rc-2023-10-18#[method]fields.set", - "wasi:http/types@0.2.0-rc-2023-10-18#[method]fields.delete", - "wasi:http/types@0.2.0-rc-2023-10-18#[method]fields.append", - "wasi:http/types@0.2.0-rc-2023-10-18#[method]fields.entries", - "wasi:http/types@0.2.0-rc-2023-10-18#[method]fields.clone", - "wasi:http/types@0.2.0-rc-2023-10-18#[method]incoming-body.stream", - "wasi:http/types@0.2.0-rc-2023-10-18#[static]incoming-body.finish", - "wasi:http/types@0.2.0-rc-2023-10-18#[static]outgoing-body.finish", - "wasi:http/types@0.2.0-rc-2023-10-18#[dtor]incoming-request", - "wasi:http/types@0.2.0-rc-2023-10-18#[dtor]incoming-body", - "wasi:http/types@0.2.0-rc-2023-10-18#[dtor]outgoing-request", - "wasi:http/types@0.2.0-rc-2023-10-18#[dtor]outgoing-body", - "wasi:http/types@0.2.0-rc-2023-10-18#[method]incoming-request.method", - "wasi:http/types@0.2.0-rc-2023-10-18#[method]incoming-request.path-with-query", - "wasi:http/types@0.2.0-rc-2023-10-18#[method]incoming-request.scheme", - "wasi:http/types@0.2.0-rc-2023-10-18#[method]incoming-request.authority", - "wasi:http/types@0.2.0-rc-2023-10-18#[method]incoming-request.headers", - "wasi:http/types@0.2.0-rc-2023-10-18#[method]incoming-request.consume", - "wasi:http/types@0.2.0-rc-2023-10-18#[constructor]outgoing-request", - "wasi:http/types@0.2.0-rc-2023-10-18#[method]outgoing-request.write", - "wasi:http/types@0.2.0-rc-2023-10-18#[dtor]response-outparam", - "wasi:http/types@0.2.0-rc-2023-10-18#[static]response-outparam.set", - "wasi:http/types@0.2.0-rc-2023-10-18#[dtor]incoming-response", - "wasi:http/types@0.2.0-rc-2023-10-18#[dtor]outgoing-response", - "wasi:http/types@0.2.0-rc-2023-10-18#[method]incoming-response.status", - "wasi:http/types@0.2.0-rc-2023-10-18#[method]incoming-response.headers", - "wasi:http/types@0.2.0-rc-2023-10-18#[method]incoming-response.consume", - "wasi:http/types@0.2.0-rc-2023-10-18#[constructor]outgoing-response", - "wasi:http/types@0.2.0-rc-2023-10-18#[method]outgoing-response.write", - "wasi:http/types@0.2.0-rc-2023-10-18#[method]outgoing-body.write", - "wasi:http/types@0.2.0-rc-2023-10-18#[dtor]future-trailers", - "wasi:http/types@0.2.0-rc-2023-10-18#[method]future-trailers.get", - "wasi:http/types@0.2.0-rc-2023-10-18#[method]future-trailers.subscribe", - "wasi:http/types@0.2.0-rc-2023-10-18#[dtor]future-incoming-response", - "wasi:http/types@0.2.0-rc-2023-10-18#[method]future-incoming-response.get", - "wasi:http/types@0.2.0-rc-2023-10-18#[method]future-incoming-response.subscribe", - "wasi:http/outgoing-handler@0.2.0-rc-2023-10-18#handle", -]; - -/// Strip exported WASI functions that implement HTTP access -pub(crate) fn strip_http_virt(module: &mut Module) -> Result<()> { - stub_http_virt(module)?; - for &export_name in WASI_HTTP_EXPORTS { - module - .exports - .remove(export_name) - .with_context(|| format!("failed to strip WASI HTTP function [{export_name}]"))?; - } - Ok(()) -} - -/// Imports exposed by WASI for HTTP functionality -const WASI_HTTP_IMPORTS: [(&str, &str, &StubRequirement); 32] = [ - ("wasi:http/types", "drop-fields", &StubRequirement::Optional), - ("wasi:http/types", "new-fields", &StubRequirement::Optional), - ("wasi:http/types", "fields-get", &StubRequirement::Optional), - ("wasi:http/types", "fields-set", &StubRequirement::Optional), - ( - "wasi:http/types", - "fields-delete", - &StubRequirement::Optional, - ), - ( - "wasi:http/types", - "fields-append", - &StubRequirement::Optional, - ), - ( - "wasi:http/types", - "fields-entries", - &StubRequirement::Optional, - ), - ( - "wasi:http/types", - "fields-clone", - &StubRequirement::Optional, - ), - ( - "wasi:http/types", - "finish-incoming-stream", - &StubRequirement::Optional, - ), - ( - "wasi:http/types", - "finish-outgoing-stream", - &StubRequirement::Optional, - ), - ( - "wasi:http/types", - "drop-incoming-request", - &StubRequirement::Optional, - ), - ( - "wasi:http/types", - "drop-outgoing-request", - &StubRequirement::Optional, - ), - ( - "wasi:http/types", - "incoming-request-method", - &StubRequirement::Optional, - ), - ( - "wasi:http/types", - "incoming-request-path-with-query", - &StubRequirement::Optional, - ), - ( - "wasi:http/types", - "incoming-request-scheme", - &StubRequirement::Optional, - ), - ( - "wasi:http/types", - "incoming-request-authority", - &StubRequirement::Optional, - ), - ( - "wasi:http/types", - "incoming-request-headers", - &StubRequirement::Optional, - ), - ( - "wasi:http/types", - "incoming-request-consume", - &StubRequirement::Optional, - ), - ( - "wasi:http/types", - "new-outgoing-request", - &StubRequirement::Optional, - ), - ( - "wasi:http/types", - "outgoing-request-write", - &StubRequirement::Optional, - ), - ( - "wasi:http/types", - "drop-response-outparam", - &StubRequirement::Optional, - ), - ( - "wasi:http/types", - "set-response-outparam", - &StubRequirement::Optional, - ), - ( - "wasi:http/types", - "drop-incoming-response", - &StubRequirement::Optional, - ), - ( - "wasi:http/types", - "drop-outgoing-response", - &StubRequirement::Optional, - ), - ( - "wasi:http/types", - "incoming-response-status", - &StubRequirement::Optional, - ), - ( - "wasi:http/types", - "incoming-response-headers", - &StubRequirement::Optional, - ), - ( - "wasi:http/types", - "incoming-response-consume", - &StubRequirement::Optional, - ), - ( - "wasi:http/types", - "new-outgoing-response", - &StubRequirement::Optional, - ), - ( - "wasi:http/types", - "outgoing-response-write", - &StubRequirement::Optional, - ), - ( - "wasi:http/types", - "drop-future-incoming-response", - &StubRequirement::Optional, - ), - ( - "wasi:http/types", - "future-incoming-response-get", - &StubRequirement::Optional, - ), - ( - "wasi:http/types", - "listen-to-future-incoming-response", - &StubRequirement::Optional, - ), -]; - -/// Replace imported WASI functions that implement HTTP access with no-ops -pub(crate) fn stub_http_virt(module: &mut Module) -> Result<()> { - for (module_name, func_name, stub_requirement) in WASI_HTTP_IMPORTS { - match stub_requirement { - StubRequirement::Optional => { - if let Ok(fid) = module.imports.get_func(module_name, func_name) { - module - .replace_imported_func(fid, |(body, _)| { - body.unreachable(); - }) - .with_context(|| { - "failed to stub WASI HTTP functionality [{}] in module [{export_name}]" - })?; - } - } - _ => bail!("unexpected stub requirement in imports for WASI HTTP"), - } - } - Ok(()) -} diff --git a/src/virt_io/io.rs b/src/virt_io/io.rs deleted file mode 100644 index 44ccf9f..0000000 --- a/src/virt_io/io.rs +++ /dev/null @@ -1,195 +0,0 @@ -use anyhow::{bail, Context, Result}; -use walrus::Module; - -use super::StubRequirement; - -/// Imports exposed by WASI for IO functionality -/// -/// Some imports are required, and others are optional. -const WASI_IO_IMPORTS: &[(&str, &str, &StubRequirement)] = &[ - ( - "wasi:io/streams@0.2.0-rc-2023-11-10", - "[method]output-stream.blocking-flush", - &StubRequirement::Optional, - ), - ( - "wasi:io/streams@0.2.0-rc-2023-11-10", - "[method]input-stream.blocking-read", - &StubRequirement::Required, - ), - ( - "wasi:io/streams@0.2.0-rc-2023-11-10", - "[method]input-stream.blocking-skip", - &StubRequirement::Required, - ), - ( - "wasi:io/streams@0.2.0-rc-2023-11-10", - "[method]output-stream.blocking-splice", - &StubRequirement::Required, - ), - ( - "wasi:io/streams@0.2.0-rc-2023-11-10", - "[method]output-stream.blocking-write-and-flush", - &StubRequirement::Optional, - ), - ( - "wasi:io/streams@0.2.0-rc-2023-11-10", - "[method]output-stream.check-write", - &StubRequirement::Optional, - ), - ( - "wasi:io/streams@0.2.0-rc-2023-11-10", - "[resource-drop]input-stream", - &StubRequirement::Required, - ), - ( - "wasi:io/streams@0.2.0-rc-2023-11-10", - "[resource-drop]output-stream", - &StubRequirement::Required, - ), - ( - "wasi:io/streams@0.2.0-rc-2023-11-10", - "[method]output-stream.flush", - &StubRequirement::Optional, - ), - ( - "wasi:io/streams@0.2.0-rc-2023-11-10", - "[method]input-stream.read", - &StubRequirement::Optional, - ), - ( - "wasi:io/streams@0.2.0-rc-2023-11-10", - "[method]input-stream.skip", - &StubRequirement::Required, - ), - ( - "wasi:io/streams@0.2.0-rc-2023-11-10", - "[method]output-stream.splice", - &StubRequirement::Required, - ), - ( - "wasi:io/streams@0.2.0-rc-2023-11-10", - "[method]input-stream.subscribe", - &StubRequirement::Required, - ), - ( - "wasi:io/streams@0.2.0-rc-2023-11-10", - "[method]output-stream.subscribe", - &StubRequirement::Required, - ), - ( - "wasi:io/streams@0.2.0-rc-2023-11-10", - "[method]output-stream.write", - &StubRequirement::Required, - ), - ( - "wasi:io/streams@0.2.0-rc-2023-11-10", - "[method]output-stream.write-zeroes", - &StubRequirement::Required, - ), - ( - "wasi:io/streams@0.2.0-rc-2023-11-10", - "[method]output-stream.blocking-write-zeroes-and-flush", - &StubRequirement::Required, - ), - ( - "wasi:io/error@0.2.0-rc-2023-11-10", - "[resource-drop]error", - &StubRequirement::Required, - ), - ( - "wasi:io/poll@0.2.0-rc-2023-11-10", - "[method]pollable.ready", - &StubRequirement::Required, - ), - ( - "wasi:io/poll@0.2.0-rc-2023-11-10", - "[method]pollable.block", - &StubRequirement::Required, - ), - ( - "wasi:io/poll@0.2.0-rc-2023-11-10", - "[resource-drop]pollable", - &StubRequirement::Required, - ), - ( - "wasi:io/poll@0.2.0-rc-2023-11-10", - "poll", - &StubRequirement::Required, - ), -]; - -/// Replace imported WASI functions that implement general I/O access with no-ops -pub(crate) fn stub_io_virt(module: &mut Module) -> Result<()> { - // Replace the I/O functions that are allowed to be missing - for (module_name, func_name, stub_requirement) in WASI_IO_IMPORTS { - match stub_requirement { - // If the stub is always required we *must* find the function and replace it - StubRequirement::Required => { - let fid = module.imports.get_func(module_name, func_name) - .with_context(|| format!("failed to find required io import [{func_name}] in module [{module_name}]"))?; - - module - .replace_imported_func(fid, |(body, _)| { - body.unreachable(); - }) - .with_context(|| { - "failed to stub filesystem functionality [{}] in module [{export_name}]" - })?; - } - // If the stub is optional, we can replace the functions optimistically, and not fail if they are missing - StubRequirement::Optional => { - if let Ok(fid) = module.imports.get_func(module_name, func_name) { - module - .replace_imported_func(fid, |(body, _)| { - body.unreachable(); - }) - .with_context(|| { - "failed to stub filesystem functionality [{}] in module [{export_name}]" - })?; - } - } - _ => bail!("unexpected stub requirement in imports for WASI I/O"), - }; - } - - Ok(()) -} - -/// Exported functions related to IO -const WASI_IO_EXPORTS: &[&str] = &[ - "wasi:io/streams@0.2.0-rc-2023-11-10#[method]output-stream.blocking-flush", - "wasi:io/streams@0.2.0-rc-2023-11-10#[method]input-stream.blocking-read", - "wasi:io/streams@0.2.0-rc-2023-11-10#[method]input-stream.blocking-skip", - "wasi:io/streams@0.2.0-rc-2023-11-10#[method]output-stream.blocking-splice", - "wasi:io/streams@0.2.0-rc-2023-11-10#[method]output-stream.blocking-write-and-flush", - "wasi:io/streams@0.2.0-rc-2023-11-10#[method]output-stream.check-write", - "wasi:io/streams@0.2.0-rc-2023-11-10#[dtor]input-stream", - "wasi:io/streams@0.2.0-rc-2023-11-10#[dtor]output-stream", - "wasi:io/error@0.2.0-rc-2023-11-10#[dtor]error", - "wasi:io/error@0.2.0-rc-2023-11-10#[method]error.to-debug-string", - "wasi:io/streams@0.2.0-rc-2023-11-10#[method]output-stream.flush", - "wasi:io/streams@0.2.0-rc-2023-11-10#[method]input-stream.read", - "wasi:io/streams@0.2.0-rc-2023-11-10#[method]input-stream.skip", - "wasi:io/streams@0.2.0-rc-2023-11-10#[method]output-stream.splice", - "wasi:io/streams@0.2.0-rc-2023-11-10#[method]input-stream.subscribe", - "wasi:io/streams@0.2.0-rc-2023-11-10#[method]output-stream.subscribe", - "wasi:io/streams@0.2.0-rc-2023-11-10#[method]output-stream.write", - "wasi:io/streams@0.2.0-rc-2023-11-10#[method]output-stream.write-zeroes", - "wasi:io/streams@0.2.0-rc-2023-11-10#[method]output-stream.blocking-write-zeroes-and-flush", - "wasi:io/poll@0.2.0-rc-2023-11-10#[method]pollable.ready", - "wasi:io/poll@0.2.0-rc-2023-11-10#[method]pollable.block", - "wasi:io/poll@0.2.0-rc-2023-11-10#[dtor]pollable", - "wasi:io/poll@0.2.0-rc-2023-11-10#poll", -]; - -/// Strip exported WASI functions that implement IO (streams, polling) access -pub(crate) fn strip_io_virt(module: &mut Module) -> Result<()> { - stub_io_virt(module)?; - for &export_name in WASI_IO_EXPORTS { - module.exports.remove(export_name).with_context(|| { - format!("failed to strip general I/O export function [{export_name}]") - })?; - } - Ok(()) -} diff --git a/src/virt_io/sockets.rs b/src/virt_io/sockets.rs deleted file mode 100644 index 55c5372..0000000 --- a/src/virt_io/sockets.rs +++ /dev/null @@ -1,345 +0,0 @@ -use anyhow::{bail, Context, Result}; -use walrus::Module; - -use super::StubRequirement; - -/// Imports exposed by WASI for sockets functionality which are allowed to be missing -const WASI_SOCKETS_IMPORTS: [(&str, &str, &StubRequirement); 49] = [ - ( - "wasi:sockets/ip-name-lookup@0.2.0-rc-2023-10-18", - "resolve-addresses", - &StubRequirement::Required, - ), - ( - "wasi:sockets/ip-name-lookup@0.2.0-rc-2023-10-18", - "[method]resolve-address-stream.resolve-next-address", - &StubRequirement::Required, - ), - ( - "wasi:sockets/ip-name-lookup@0.2.0-rc-2023-10-18", - "[resource-drop]resolve-address-stream", - &StubRequirement::Required, - ), - ( - "wasi:sockets/ip-name-lookup@0.2.0-rc-2023-10-18", - "[method]resolve-address-stream.subscribe", - &StubRequirement::Required, - ), - ( - "wasi:sockets/tcp@0.2.0-rc-2023-10-18", - "[method]tcp-socket.start-bind", - &StubRequirement::Required, - ), - ( - "wasi:sockets/tcp@0.2.0-rc-2023-10-18", - "[method]tcp-socket.finish-bind", - &StubRequirement::Required, - ), - ( - "wasi:sockets/tcp@0.2.0-rc-2023-10-18", - "[method]tcp-socket.start-connect", - &StubRequirement::Required, - ), - ( - "wasi:sockets/tcp@0.2.0-rc-2023-10-18", - "[method]tcp-socket.finish-connect", - &StubRequirement::Required, - ), - ( - "wasi:sockets/tcp@0.2.0-rc-2023-10-18", - "[method]tcp-socket.start-listen", - &StubRequirement::Required, - ), - ( - "wasi:sockets/tcp@0.2.0-rc-2023-10-18", - "[method]tcp-socket.finish-listen", - &StubRequirement::Required, - ), - ( - "wasi:sockets/tcp@0.2.0-rc-2023-10-18", - "[method]tcp-socket.accept", - &StubRequirement::Required, - ), - ( - "wasi:sockets/tcp@0.2.0-rc-2023-10-18", - "[method]tcp-socket.local-address", - &StubRequirement::Required, - ), - ( - "wasi:sockets/tcp@0.2.0-rc-2023-10-18", - "[method]tcp-socket.remote-address", - &StubRequirement::Required, - ), - ( - "wasi:sockets/tcp@0.2.0-rc-2023-10-18", - "[method]tcp-socket.address-family", - &StubRequirement::Required, - ), - ( - "wasi:sockets/tcp@0.2.0-rc-2023-10-18", - "[method]tcp-socket.ipv6-only", - &StubRequirement::Required, - ), - ( - "wasi:sockets/tcp@0.2.0-rc-2023-10-18", - "[method]tcp-socket.set-ipv6-only", - &StubRequirement::Required, - ), - ( - "wasi:sockets/tcp@0.2.0-rc-2023-10-18", - "[method]tcp-socket.set-listen-backlog-size", - &StubRequirement::Required, - ), - ( - "wasi:sockets/tcp@0.2.0-rc-2023-10-18", - "[method]tcp-socket.keep-alive", - &StubRequirement::Required, - ), - ( - "wasi:sockets/tcp@0.2.0-rc-2023-10-18", - "[method]tcp-socket.set-keep-alive", - &StubRequirement::Required, - ), - ( - "wasi:sockets/tcp@0.2.0-rc-2023-10-18", - "[method]tcp-socket.no-delay", - &StubRequirement::Required, - ), - ( - "wasi:sockets/tcp@0.2.0-rc-2023-10-18", - "[method]tcp-socket.set-no-delay", - &StubRequirement::Required, - ), - ( - "wasi:sockets/tcp@0.2.0-rc-2023-10-18", - "[method]tcp-socket.unicast-hop-limit", - &StubRequirement::Required, - ), - ( - "wasi:sockets/tcp@0.2.0-rc-2023-10-18", - "[method]tcp-socket.set-unicast-hop-limit", - &StubRequirement::Required, - ), - ( - "wasi:sockets/tcp@0.2.0-rc-2023-10-18", - "[method]tcp-socket.receive-buffer-size", - &StubRequirement::Required, - ), - ( - "wasi:sockets/tcp@0.2.0-rc-2023-10-18", - "[method]tcp-socket.set-receive-buffer-size", - &StubRequirement::Required, - ), - ( - "wasi:sockets/tcp@0.2.0-rc-2023-10-18", - "[method]tcp-socket.send-buffer-size", - &StubRequirement::Required, - ), - ( - "wasi:sockets/tcp@0.2.0-rc-2023-10-18", - "[method]tcp-socket.set-send-buffer-size", - &StubRequirement::Required, - ), - ( - "wasi:sockets/tcp@0.2.0-rc-2023-10-18", - "[method]tcp-socket.subscribe", - &StubRequirement::Required, - ), - ( - "wasi:sockets/tcp@0.2.0-rc-2023-10-18", - "[method]tcp-socket.shutdown", - &StubRequirement::Required, - ), - ( - "wasi:sockets/tcp@0.2.0-rc-2023-10-18", - "[resource-drop]tcp-socket", - &StubRequirement::Required, - ), - ( - "wasi:sockets/udp@0.2.0-rc-2023-10-18", - "[method]udp-socket.start-bind", - &StubRequirement::Required, - ), - ( - "wasi:sockets/udp@0.2.0-rc-2023-10-18", - "[method]udp-socket.finish-bind", - &StubRequirement::Required, - ), - ( - "wasi:sockets/udp@0.2.0-rc-2023-10-18", - "[method]udp-socket.start-connect", - &StubRequirement::Required, - ), - ( - "wasi:sockets/udp@0.2.0-rc-2023-10-18", - "[method]udp-socket.finish-connect", - &StubRequirement::Required, - ), - ( - "wasi:sockets/udp@0.2.0-rc-2023-10-18", - "[method]udp-socket.receive", - &StubRequirement::Required, - ), - ( - "wasi:sockets/udp@0.2.0-rc-2023-10-18", - "[method]udp-socket.send", - &StubRequirement::Required, - ), - ( - "wasi:sockets/udp@0.2.0-rc-2023-10-18", - "[method]udp-socket.local-address", - &StubRequirement::Required, - ), - ( - "wasi:sockets/udp@0.2.0-rc-2023-10-18", - "[method]udp-socket.remote-address", - &StubRequirement::Required, - ), - ( - "wasi:sockets/udp@0.2.0-rc-2023-10-18", - "[method]udp-socket.address-family", - &StubRequirement::Required, - ), - ( - "wasi:sockets/udp@0.2.0-rc-2023-10-18", - "[method]udp-socket.ipv6-only", - &StubRequirement::Required, - ), - ( - "wasi:sockets/udp@0.2.0-rc-2023-10-18", - "[method]udp-socket.set-ipv6-only", - &StubRequirement::Required, - ), - ( - "wasi:sockets/udp@0.2.0-rc-2023-10-18", - "[method]udp-socket.unicast-hop-limit", - &StubRequirement::Required, - ), - ( - "wasi:sockets/udp@0.2.0-rc-2023-10-18", - "[method]udp-socket.set-unicast-hop-limit", - &StubRequirement::Required, - ), - ( - "wasi:sockets/udp@0.2.0-rc-2023-10-18", - "[method]udp-socket.receive-buffer-size", - &StubRequirement::Required, - ), - ( - "wasi:sockets/udp@0.2.0-rc-2023-10-18", - "[method]udp-socket.set-receive-buffer-size", - &StubRequirement::Required, - ), - ( - "wasi:sockets/udp@0.2.0-rc-2023-10-18", - "[method]udp-socket.send-buffer-size", - &StubRequirement::Required, - ), - ( - "wasi:sockets/udp@0.2.0-rc-2023-10-18", - "[method]udp-socket.set-send-buffer-size", - &StubRequirement::Required, - ), - ( - "wasi:sockets/udp@0.2.0-rc-2023-10-18", - "[method]udp-socket.subscribe", - &StubRequirement::Required, - ), - ( - "wasi:sockets/udp@0.2.0-rc-2023-10-18", - "[resource-drop]udp-socket", - &StubRequirement::Required, - ), -]; - -/// Replace imported WASI functions that implement socket access with no-ops -pub(crate) fn stub_sockets_virt(module: &mut Module) -> Result<()> { - for (module_name, func_name, stub_requirement) in WASI_SOCKETS_IMPORTS { - match stub_requirement { - StubRequirement::Required => { - let fid = module - .imports - .get_func(module_name, func_name) - .with_context(|| { - format!( - "failed to find required sockets import [{func_name}] in module [{module_name}]" - ) - })?; - module - .replace_imported_func(fid, |(body, _)| { - body.unreachable(); - }) - .with_context(|| { - "failed to stub sockets functionality [{}] in module [{export_name}]" - })?; - } - _ => bail!("unexpected stub requirement in imports for WASI sockets"), - } - } - - Ok(()) -} - -/// Exported functions related to sockets -const WASI_SOCKETS_EXPORTS: [&str; 49] = [ - "wasi:sockets/ip-name-lookup@0.2.0-rc-2023-10-18#resolve-addresses", - "wasi:sockets/ip-name-lookup@0.2.0-rc-2023-10-18#[method]resolve-address-stream.resolve-next-address", - "wasi:sockets/ip-name-lookup@0.2.0-rc-2023-10-18#[dtor]resolve-address-stream", - "wasi:sockets/ip-name-lookup@0.2.0-rc-2023-10-18#[method]resolve-address-stream.subscribe", - "wasi:sockets/tcp@0.2.0-rc-2023-10-18#[method]tcp-socket.start-bind", - "wasi:sockets/tcp@0.2.0-rc-2023-10-18#[method]tcp-socket.finish-bind", - "wasi:sockets/tcp@0.2.0-rc-2023-10-18#[method]tcp-socket.start-connect", - "wasi:sockets/tcp@0.2.0-rc-2023-10-18#[method]tcp-socket.finish-connect", - "wasi:sockets/tcp@0.2.0-rc-2023-10-18#[method]tcp-socket.start-listen", - "wasi:sockets/tcp@0.2.0-rc-2023-10-18#[method]tcp-socket.finish-listen", - "wasi:sockets/tcp@0.2.0-rc-2023-10-18#[method]tcp-socket.accept", - "wasi:sockets/tcp@0.2.0-rc-2023-10-18#[method]tcp-socket.local-address", - "wasi:sockets/tcp@0.2.0-rc-2023-10-18#[method]tcp-socket.remote-address", - "wasi:sockets/tcp@0.2.0-rc-2023-10-18#[method]tcp-socket.address-family", - "wasi:sockets/tcp@0.2.0-rc-2023-10-18#[method]tcp-socket.ipv6-only", - "wasi:sockets/tcp@0.2.0-rc-2023-10-18#[method]tcp-socket.set-ipv6-only", - "wasi:sockets/tcp@0.2.0-rc-2023-10-18#[method]tcp-socket.set-listen-backlog-size", - "wasi:sockets/tcp@0.2.0-rc-2023-10-18#[method]tcp-socket.keep-alive", - "wasi:sockets/tcp@0.2.0-rc-2023-10-18#[method]tcp-socket.set-keep-alive", - "wasi:sockets/tcp@0.2.0-rc-2023-10-18#[method]tcp-socket.no-delay", - "wasi:sockets/tcp@0.2.0-rc-2023-10-18#[method]tcp-socket.set-no-delay", - "wasi:sockets/tcp@0.2.0-rc-2023-10-18#[method]tcp-socket.unicast-hop-limit", - "wasi:sockets/tcp@0.2.0-rc-2023-10-18#[method]tcp-socket.set-unicast-hop-limit", - "wasi:sockets/tcp@0.2.0-rc-2023-10-18#[method]tcp-socket.receive-buffer-size", - "wasi:sockets/tcp@0.2.0-rc-2023-10-18#[method]tcp-socket.set-receive-buffer-size", - "wasi:sockets/tcp@0.2.0-rc-2023-10-18#[method]tcp-socket.send-buffer-size", - "wasi:sockets/tcp@0.2.0-rc-2023-10-18#[method]tcp-socket.set-send-buffer-size", - "wasi:sockets/tcp@0.2.0-rc-2023-10-18#[method]tcp-socket.subscribe", - "wasi:sockets/tcp@0.2.0-rc-2023-10-18#[method]tcp-socket.shutdown", - "wasi:sockets/tcp@0.2.0-rc-2023-10-18#[dtor]tcp-socket", - "wasi:sockets/udp@0.2.0-rc-2023-10-18#[method]udp-socket.start-bind", - "wasi:sockets/udp@0.2.0-rc-2023-10-18#[method]udp-socket.finish-bind", - "wasi:sockets/udp@0.2.0-rc-2023-10-18#[method]udp-socket.start-connect", - "wasi:sockets/udp@0.2.0-rc-2023-10-18#[method]udp-socket.finish-connect", - "wasi:sockets/udp@0.2.0-rc-2023-10-18#[method]udp-socket.receive", - "wasi:sockets/udp@0.2.0-rc-2023-10-18#[method]udp-socket.send", - "wasi:sockets/udp@0.2.0-rc-2023-10-18#[method]udp-socket.local-address", - "wasi:sockets/udp@0.2.0-rc-2023-10-18#[method]udp-socket.remote-address", - "wasi:sockets/udp@0.2.0-rc-2023-10-18#[method]udp-socket.address-family", - "wasi:sockets/udp@0.2.0-rc-2023-10-18#[method]udp-socket.ipv6-only", - "wasi:sockets/udp@0.2.0-rc-2023-10-18#[method]udp-socket.set-ipv6-only", - "wasi:sockets/udp@0.2.0-rc-2023-10-18#[method]udp-socket.unicast-hop-limit", - "wasi:sockets/udp@0.2.0-rc-2023-10-18#[method]udp-socket.set-unicast-hop-limit", - "wasi:sockets/udp@0.2.0-rc-2023-10-18#[method]udp-socket.receive-buffer-size", - "wasi:sockets/udp@0.2.0-rc-2023-10-18#[method]udp-socket.set-receive-buffer-size", - "wasi:sockets/udp@0.2.0-rc-2023-10-18#[method]udp-socket.send-buffer-size", - "wasi:sockets/udp@0.2.0-rc-2023-10-18#[method]udp-socket.set-send-buffer-size", - "wasi:sockets/udp@0.2.0-rc-2023-10-18#[method]udp-socket.subscribe", - "wasi:sockets/udp@0.2.0-rc-2023-10-18#[dtor]udp-socket", -]; - -/// Strip exported WASI functions that implement sockets access -pub(crate) fn strip_sockets_virt(module: &mut Module) -> Result<()> { - stub_sockets_virt(module)?; - for export_name in WASI_SOCKETS_EXPORTS { - module.exports.remove(export_name).with_context(|| { - format!("failed to strip WASI sockets export function [{export_name}]") - })?; - } - Ok(()) -} diff --git a/src/virt_io/stdio.rs b/src/virt_io/stdio.rs deleted file mode 100644 index 4a9bfc7..0000000 --- a/src/virt_io/stdio.rs +++ /dev/null @@ -1,95 +0,0 @@ -use anyhow::{bail, Context, Result}; -use walrus::Module; - -use super::StubRequirement; - -/// Imports exposed by WASI for STDIO functionality which are allowed to be missing -const WASI_STDIO_IMPORTS: &[(&str, &str, &StubRequirement)] = &[ - ( - "wasi:cli/stdin@0.2.0-rc-2023-12-05", - "get-stdin", - &StubRequirement::Optional, - ), - ( - "wasi:cli/stdout@0.2.0-rc-2023-12-05", - "get-stdout", - &StubRequirement::Optional, - ), - ( - "wasi:cli/stderr@0.2.0-rc-2023-12-05", - "get-stderr", - &StubRequirement::Optional, - ), - ( - "wasi:cli/terminal-stdin@0.2.0-rc-2023-12-05", - "get-terminal-stdin", - &StubRequirement::Optional, - ), - ( - "wasi:cli/terminal-stdout@0.2.0-rc-2023-12-05", - "get-terminal-stdout", - &StubRequirement::Optional, - ), - ( - "wasi:cli/terminal-stderr@0.2.0-rc-2023-12-05", - "get-terminal-stderr", - &StubRequirement::Optional, - ), - ( - "wasi:cli/terminal-input@0.2.0-rc-2023-12-05", - "drop-terminal-input", - &StubRequirement::Optional, - ), - ( - "wasi:cli/terminal-output@0.2.0-rc-2023-12-05", - "drop-terminal-output", - &StubRequirement::Optional, - ), -]; - -/// Replace imported WASI functions that implement STDIO access with no-ops -pub(crate) fn stub_stdio_virt(module: &mut Module) -> Result<()> { - for (module_name, func_name, stub_requirement) in WASI_STDIO_IMPORTS { - match stub_requirement { - StubRequirement::Optional => { - if let Ok(fid) = module.imports.get_func(module_name, func_name) { - module - .replace_imported_func(fid, |(body, _)| { - body.unreachable(); - }) - .with_context(|| { - format!( - "failed to stub STDIO functionality [{func_name}] in module [{module_name}]" - ) - })?; - } - } - _ => bail!("unexpected stub requirement in imports for WASI STD I/O"), - } - } - Ok(()) -} - -/// Exported functions related to STDIO -const WASI_STDIO_EXPORTS: [&str; 8] = [ - "wasi:cli/stdin@0.2.0-rc-2023-12-05#get-stdin", - "wasi:cli/stdout@0.2.0-rc-2023-12-05#get-stdout", - "wasi:cli/stderr@0.2.0-rc-2023-12-05#get-stderr", - "wasi:cli/terminal-stdin@0.2.0-rc-2023-12-05#get-terminal-stdin", - "wasi:cli/terminal-stdout@0.2.0-rc-2023-12-05#get-terminal-stdout", - "wasi:cli/terminal-stderr@0.2.0-rc-2023-12-05#get-terminal-stderr", - "wasi:cli/terminal-input@0.2.0-rc-2023-12-05#[dtor]terminal-input", - "wasi:cli/terminal-output@0.2.0-rc-2023-12-05#[dtor]terminal-output", -]; - -/// Strip exported WASI functions that implement standard I/O (stdin, stdout, etc) access -pub(crate) fn strip_stdio_virt(module: &mut Module) -> Result<()> { - stub_stdio_virt(module)?; - for export_name in WASI_STDIO_EXPORTS { - module - .exports - .remove(export_name) - .with_context(|| format!("failed to strip std I/O function [{export_name}]"))?; - } - Ok(()) -} diff --git a/src/walrus_ops.rs b/src/walrus_ops.rs index c9386d6..7ff3a17 100644 --- a/src/walrus_ops.rs +++ b/src/walrus_ops.rs @@ -86,3 +86,64 @@ pub(crate) fn bump_stack_global(module: &mut Module, offset: i32) -> Result *stack_value = new_stack_value; Ok(new_stack_value as u32) } + +pub(crate) fn strip_virt(module: &mut Module, subsystems: &[&str]) -> Result<()> { + stub_virt(module, subsystems, true)?; + let mut subsystem_exports = Vec::new(); + for export in module.exports.iter() { + let export_name = if export.name.starts_with("cabi_post_") { + &export.name[10..] + } else { + &export.name + }; + if subsystems + .iter() + .any(|subsystem| export_name.starts_with(subsystem)) + { + subsystem_exports.push(export.name.to_string()); + } + } + for export_name in subsystem_exports { + module + .exports + .remove(&export_name) + .with_context(|| format!("failed to strip function [{export_name}]"))?; + } + Ok(()) +} + +/// Replace imported WASI functions that implement subsystem access with no-ops +pub(crate) fn stub_virt( + module: &mut Module, + subsystems: &[&str], + with_exports: bool, +) -> Result<()> { + let mut subsystem_imports = Vec::new(); + for import in module.imports.iter() { + let module_name = if with_exports && import.module.starts_with("[export]") { + &import.module[8..] + } else { + &import.module + }; + if subsystems + .iter() + .any(|subsystem| module_name.starts_with(subsystem)) + { + subsystem_imports.push((import.module.to_string(), import.name.to_string())); + } + } + for (module_name, func_name) in &subsystem_imports { + if let Ok(fid) = module.imports.get_func(module_name, func_name) { + module + .replace_imported_func(fid, |(body, _)| { + body.unreachable(); + }) + .with_context(|| { + format!( + "failed to stub WASI functionality [{func_name}] in module [{module_name}]" + ) + })?; + } + } + Ok(()) +} diff --git a/tests/cases/encapsulate.toml b/tests/cases/encapsulate.toml index fbfd176..f09d554 100644 --- a/tests/cases/encapsulate.toml +++ b/tests/cases/encapsulate.toml @@ -6,7 +6,7 @@ host-fs-path = "/LICENSE" exit = false fs.host-preopens = false stdio.stdin = "ignore" -stdio.stdout = "ignore" +stdio.stdout = "allow" stdio.stderr = "ignore" clocks = true http = false diff --git a/tests/cases/fs-nested-dir-read.toml b/tests/cases/fs-nested-dir-read.toml index a52ce39..faca022 100644 --- a/tests/cases/fs-nested-dir-read.toml +++ b/tests/cases/fs-nested-dir-read.toml @@ -11,7 +11,7 @@ stderr = "allow" virtualize = "./wit/deps" [expect] -file-read = '''package wasi:clocks@0.2.0-rc-2023-11-10; +file-read = '''package wasi:clocks@0.2.0; /// WASI Monotonic Clock is a clock API intended to let users measure elapsed /// time. /// @@ -23,7 +23,7 @@ file-read = '''package wasi:clocks@0.2.0-rc-2023-11-10; /// /// It is intended for measuring elapsed time. interface monotonic-clock { - use wasi:io/poll@0.2.0-rc-2023-11-10.{pollable}; + use wasi:io/poll@0.2.0.{pollable}; /// An instant in time, in nanoseconds. An instant is relative to an /// unspecified initial value, and can only be compared to instances from diff --git a/tests/virt.rs b/tests/virt.rs index 5823ce7..61bbb51 100644 --- a/tests/virt.rs +++ b/tests/virt.rs @@ -8,12 +8,13 @@ use std::{fs, path::PathBuf}; use wasi_virt::WasiVirt; use wasm_compose::composer::ComponentComposer; use wasmparser::{Chunk, Parser, Payload}; +use wasmtime::component::ResourceTable; use wasmtime::{ component::{Component, Linker}, Config, Engine, Store, WasmBacktraceDetails, }; use wasmtime_wasi::preview2::command::add_to_linker; -use wasmtime_wasi::preview2::{DirPerms, FilePerms, Table, WasiCtx, WasiCtxBuilder, WasiView}; +use wasmtime_wasi::preview2::{DirPerms, FilePerms, WasiCtx, WasiCtxBuilder, WasiView}; use wasmtime_wasi::Dir; use wit_component::ComponentEncoder; @@ -76,7 +77,7 @@ async fn virt_test() -> Result<()> { let test_case_name = test_case_file_name.strip_suffix(".toml").unwrap(); // Filtering... - // if test_case_name != "stdio" { + // if !test_case_name.starts_with("fs") { // continue; // } @@ -108,11 +109,12 @@ async fn virt_test() -> Result<()> { } // encode the component - let component_core = fs::read(&format!( + let component_core_path = &format!( "target/wasm32-wasi/{}/{}.wasm", if DEBUG { "debug" } else { "release" }, component_name.to_snake_case() - ))?; + ); + let component_core = fs::read(component_core_path)?; let mut encoder = ComponentEncoder::default() .validate(true) .module(&component_core)?; @@ -138,9 +140,12 @@ async fn virt_test() -> Result<()> { } } - let virt_component = virt_opts - .finish() - .with_context(|| format!("Error creating virtual adapter for {:?}", test_case_path))?; + let virt_component = virt_opts.finish().with_context(|| { + format!( + "Error creating virtual adapter {:?} for {:?}", + test_case_path, component_core_path + ) + })?; fs::write(&virt_component_path, &virt_component.adapter)?; @@ -189,7 +194,7 @@ async fn virt_test() -> Result<()> { builder.env(k, v); } } - let table = Table::new(); + let table = ResourceTable::new(); let wasi = builder.build(); let mut config = Config::new(); @@ -204,14 +209,14 @@ async fn virt_test() -> Result<()> { let component = Component::from_binary(&engine, &component_bytes).unwrap(); struct CommandCtx { - table: Table, + table: ResourceTable, wasi: WasiCtx, } impl WasiView for CommandCtx { - fn table(&self) -> &Table { + fn table(&self) -> &ResourceTable { &self.table } - fn table_mut(&mut self) -> &mut Table { + fn table_mut(&mut self) -> &mut ResourceTable { &mut self.table } fn ctx(&self) -> &WasiCtx { diff --git a/virtual-adapter/src/io.rs b/virtual-adapter/src/io.rs index 540b3cd..327b425 100644 --- a/virtual-adapter/src/io.rs +++ b/virtual-adapter/src/io.rs @@ -15,11 +15,13 @@ use crate::exports::wasi::filesystem::types::{ }; use crate::exports::wasi::http::outgoing_handler::Guest as OutgoingHandler; use crate::exports::wasi::http::types::{ - Error as HttpError, Fields, FutureIncomingResponse, FutureTrailers, GuestFields, - GuestFutureIncomingResponse, GuestFutureTrailers, GuestIncomingBody, GuestIncomingRequest, - GuestIncomingResponse, GuestOutgoingBody, GuestOutgoingRequest, GuestOutgoingResponse, - GuestResponseOutparam, IncomingBody, IncomingRequest, IncomingResponse, Method, OutgoingBody, - OutgoingRequest, OutgoingResponse, RequestOptions, ResponseOutparam, Scheme, StatusCode, + DnsErrorPayload, ErrorCode as HttpErrorCode, FieldSizePayload, Fields, FutureIncomingResponse, + FutureTrailers, Guest as GuestHttpTypes, GuestFields, GuestFutureIncomingResponse, + GuestFutureTrailers, GuestIncomingBody, GuestIncomingRequest, GuestIncomingResponse, + GuestOutgoingBody, GuestOutgoingRequest, GuestOutgoingResponse, GuestRequestOptions, + GuestResponseOutparam, HeaderError, Headers, IncomingBody, IncomingRequest, IncomingResponse, + Method, OutgoingBody, OutgoingRequest, OutgoingResponse, RequestOptions, ResponseOutparam, + Scheme, StatusCode, TlsAlertReceivedPayload, }; use crate::exports::wasi::io::error::GuestError as GuestStreamsError; use crate::exports::wasi::io::poll::{Guest as Poll, GuestPollable, Pollable}; @@ -28,17 +30,22 @@ use crate::exports::wasi::io::streams::{ StreamError, }; use crate::exports::wasi::sockets::ip_name_lookup::{ - Guest as IpNameLookup, GuestResolveAddressStream, IpAddress, IpAddressFamily, Network, - ResolveAddressStream, + Guest as IpNameLookup, GuestResolveAddressStream, IpAddress, Network, ResolveAddressStream, }; use crate::exports::wasi::sockets::tcp::{ - ErrorCode as NetworkErrorCode, GuestTcpSocket, IpSocketAddress, ShutdownType, TcpSocket, + Duration, ErrorCode as NetworkErrorCode, GuestTcpSocket, IpAddressFamily, IpSocketAddress, + ShutdownType, TcpSocket, +}; +use crate::exports::wasi::sockets::udp::{ + GuestIncomingDatagramStream, GuestOutgoingDatagramStream, GuestUdpSocket, IncomingDatagram, + OutgoingDatagram, UdpSocket, }; -use crate::exports::wasi::sockets::udp::{Datagram, GuestUdpSocket, UdpSocket}; -use crate::wasi::cli::stderr; use crate::wasi::cli::stdin; use crate::wasi::cli::stdout; +use crate::wasi::cli::terminal_input; +use crate::wasi::cli::terminal_output; +use crate::wasi::cli::{stderr, terminal_stderr, terminal_stdin, terminal_stdout}; use crate::wasi::filesystem::preopens; use crate::wasi::filesystem::types as filesystem_types; use crate::wasi::io::streams; @@ -105,7 +112,7 @@ fn log(msg: &str) { #[derive(Debug)] pub enum IoError { - Code(ErrorCode), + FsCode(ErrorCode), Host(streams::Error), } @@ -299,7 +306,7 @@ impl StaticIndexEntry { } if offset.get() as usize > unsafe { self.data.active.1 } { return Err(StreamError::LastOperationFailed(Resource::new( - StreamsError::Code(ErrorCode::InvalidSeek), + StreamsError::FsCode(ErrorCode::InvalidSeek), ))); } let read_ptr = unsafe { self.data.active.0.add(offset.get() as usize) }; @@ -317,7 +324,7 @@ impl StaticIndexEntry { } if offset.get() as usize > unsafe { self.data.passive.1 } { return Err(StreamError::LastOperationFailed(Resource::new( - StreamsError::Code(ErrorCode::InvalidSeek), + StreamsError::FsCode(ErrorCode::InvalidSeek), ))); } let read_len = cmp::min( @@ -337,7 +344,7 @@ impl StaticIndexEntry { } StaticIndexType::RuntimeDir | StaticIndexType::Dir => { Err(StreamError::LastOperationFailed(Resource::new( - StreamsError::Code(ErrorCode::IsDirectory), + StreamsError::FsCode(ErrorCode::IsDirectory), ))) } StaticIndexType::RuntimeFile => { @@ -406,8 +413,10 @@ pub enum FilesystemDirectoryEntryStream { Host(filesystem_types::DirectoryEntryStream), } -pub struct CliTerminalInput; -pub struct CliTerminalOutput; +pub struct CliTerminalInput(terminal_input::TerminalInput); +pub struct CliTerminalOutput(terminal_output::TerminalOutput); + +pub struct HttpTypes; pub struct HttpFields(http_types::Fields); pub struct HttpFutureIncomingResponse(http_types::FutureIncomingResponse); @@ -419,9 +428,13 @@ pub struct HttpOutgoingBody(http_types::OutgoingBody); pub struct HttpOutgoingRequest(http_types::OutgoingRequest); pub struct HttpOutgoingResponse(http_types::OutgoingResponse); pub struct HttpResponseOutparam(http_types::ResponseOutparam); + +pub struct HttpRequestOptions(http_types::RequestOptions); pub struct SocketsResolveAddressStream(ip_name_lookup::ResolveAddressStream); pub struct SocketsTcpSocket(tcp::TcpSocket); pub struct SocketsUdpSocket(udp::UdpSocket); +pub struct SocketsIncomingDatagramStream(udp::IncomingDatagramStream); +pub struct SocketsOutgoingDatagramStream(udp::OutgoingDatagramStream); pub struct IoState { initialized: bool, @@ -436,6 +449,12 @@ impl IoState { return; } + if DEBUG { + std::panic::set_hook(Box::new(|invoke| { + debug!("{:?}", invoke); + })); + } + if Io::host_passthrough() || Io::host_preopens() { let host_preopen_directories = unsafe { &mut STATE.host_preopen_directories }; for (fd, name) in preopens::get_directories() { @@ -546,21 +565,24 @@ impl Stderr for VirtAdapter { impl TerminalStdin for VirtAdapter { fn get_terminal_stdin() -> Option> { debug!("CALL wasi:cli/terminal-stdin#get-terminal-stdin"); - Some(Resource::new(TerminalInput)) + terminal_stdin::get_terminal_stdin() + .map(|terminal_input| Resource::new(CliTerminalInput(terminal_input))) } } impl TerminalStdout for VirtAdapter { fn get_terminal_stdout() -> Option> { debug!("CALL wasi:cli/terminal-stdout#get-terminal-stdout"); - Some(Resource::new(TerminalOutput)) + terminal_stdout::get_terminal_stdout() + .map(|terminal_output| Resource::new(CliTerminalOutput(terminal_output))) } } impl TerminalStderr for VirtAdapter { fn get_terminal_stderr() -> Option> { debug!("CALL wasi:cli/terminal-stderr#get-terminal-stderr"); - Some(Resource::new(TerminalOutput)) + terminal_stderr::get_terminal_stderr() + .map(|terminal_output| Resource::new(CliTerminalOutput(terminal_output))) } } @@ -587,7 +609,8 @@ impl MonotonicClock for VirtAdapter { impl FilesystemTypes for VirtAdapter { fn filesystem_error_code(err: &StreamsError) -> Option { - if let StreamsError::Code(code) = err { + debug!("CALL wasi:filesystem/types#filesystem-error-code"); + if let StreamsError::FsCode(code) = err { Some(*code) } else { None @@ -597,6 +620,7 @@ impl FilesystemTypes for VirtAdapter { impl Preopens for VirtAdapter { fn get_directories() -> Vec<(Resource, String)> { + debug!("CALL wasi:filesystem/preopens#get-directories"); IoState::initialize(); unsafe { &STATE.preopen_directories } .iter() @@ -608,17 +632,48 @@ impl Preopens for VirtAdapter { impl OutgoingHandler for VirtAdapter { fn handle( request: Resource, - options: Option, - ) -> Result, HttpError> { + options: Option>, + ) -> Result, HttpErrorCode> { outgoing_handler::handle( Resource::into_inner(request).0, - options.map(request_options_map), + options.map(|o| Resource::into_inner(o).0), ) .map(|response| Resource::new(HttpFutureIncomingResponse(response))) .map_err(http_err_map_rev) } } +impl GuestRequestOptions for RequestOptions { + fn new() -> Self { + debug!("CALL wasi:http/types#request-options.new"); + Self(http_types::RequestOptions::new()) + } + fn connect_timeout(&self) -> Option { + debug!("CALL wasi:http/types#request-options.connect-timeout"); + self.0.connect_timeout() + } + fn set_connect_timeout(&self, duration: Option) -> Result<(), ()> { + debug!("CALL wasi:http/types#request-options.set-connect-timeout"); + self.0.set_connect_timeout(duration) + } + fn first_byte_timeout(&self) -> Option { + debug!("CALL wasi:http/types#request-options.first-byte-timeout"); + self.0.first_byte_timeout() + } + fn set_first_byte_timeout(&self, duration: Option) -> Result<(), ()> { + debug!("CALL wasi:http/types#request-options.set-first-byte-timeout"); + self.0.set_first_byte_timeout(duration) + } + fn between_bytes_timeout(&self) -> Option { + debug!("CALL wasi:http/types#request-options.between-bytes-timeout"); + self.0.between_bytes_timeout() + } + fn set_between_bytes_timeout(&self, duration: Option) -> Result<(), ()> { + debug!("CALL wasi:http/types#request-options.set-between-bytes-timeout"); + self.0.set_between_bytes_timeout(duration) + } +} + impl GuestPollable for IoPollable { fn ready(&self) -> bool { debug!("CALL wasi:io/poll#pollable.ready PID={self:?}",); @@ -684,12 +739,10 @@ impl IpNameLookup for VirtAdapter { fn resolve_addresses( network: &Network, name: String, - address_family: Option, - include_unavailable: bool, ) -> Result, NetworkErrorCode> { debug!("CALL wasi:sockets/ip-name-lookup#resolve-addresses"); Ok(Resource::new(SocketsResolveAddressStream( - ip_name_lookup::resolve_addresses(network, &name, address_family, include_unavailable)?, + ip_name_lookup::resolve_addresses(network, &name)?, ))) } } @@ -1020,7 +1073,7 @@ impl GuestInputStream for InputStream { Self::Null => Ok(0), Self::Err => Err(StreamError::Closed), Self::StaticFile { .. } => Err(StreamError::LastOperationFailed(Resource::new( - StreamsError::Code(ErrorCode::Io), + StreamsError::FsCode(ErrorCode::Io), ))), Self::Host(descriptor) => descriptor.skip(offset).map_err(stream_err_map), } @@ -1031,7 +1084,7 @@ impl GuestInputStream for InputStream { Self::Null => Ok(0), Self::Err => Err(StreamError::Closed), Self::StaticFile { .. } => Err(StreamError::LastOperationFailed(Resource::new( - StreamsError::Code(ErrorCode::Io), + StreamsError::FsCode(ErrorCode::Io), ))), Self::Host(descriptor) => descriptor.blocking_skip(offset).map_err(stream_err_map), } @@ -1165,6 +1218,7 @@ impl GuestOutputStream for OutputStream { impl GuestStreamsError for StreamsError { fn to_debug_string(&self) -> String { + debug!("CALL wasi:io/error#to-debug-string"); format!("{self:?}") } } @@ -1182,30 +1236,40 @@ impl GuestDirectoryEntryStream for DirectoryEntryStream { } } +impl GuestHttpTypes for HttpTypes { + fn http_error_code(err: &IoError) -> Option { + debug!("CALL wasi:http/types#http-error-code"); + match err { + IoError::FsCode(_) => None, + IoError::Host(h) => http_types::http_error_code(h).map(|e| http_err_map_rev(e)), + } + } +} + impl GuestFields for Fields { - fn new(entries: Vec<(String, Vec)>) -> Self { + fn new() -> Self { debug!("CALL wasi:http/types#fields.constructor"); - Self(http_types::Fields::new(&entries)) + Self(http_types::Fields::new()) } fn get(&self, name: String) -> Vec> { - debug!("CALL wasi:http/types#fields.get"); + debug!("CALL wasi:http/types#fields.get NAME={name}"); self.0.get(&name) } - fn set(&self, name: String, values: Vec>) { - debug!("CALL wasi:http/types#fields.set"); - self.0.set(&name, &values) + fn set(&self, name: String, values: Vec>) -> Result<(), HeaderError> { + debug!("CALL wasi:http/types#fields.set NAME={name}"); + self.0.set(&name, &values).map_err(header_err_map_rev) } - fn delete(&self, name: String) { - debug!("CALL wasi:http/types#fields.delete"); - self.0.delete(&name) + fn delete(&self, name: String) -> Result<(), HeaderError> { + debug!("CALL wasi:http/types#fields.delete NAME={name}"); + self.0.delete(&name).map_err(header_err_map_rev) } - fn append(&self, name: String, value: Vec) { - debug!("CALL wasi:http/types#fields.append"); - self.0.append(&name, &value) + fn append(&self, name: String, value: Vec) -> Result<(), HeaderError> { + debug!("CALL wasi:http/types#fields.append NAME={name}"); + self.0.append(&name, &value).map_err(header_err_map_rev) } fn entries(&self) -> Vec<(String, Vec)> { @@ -1214,8 +1278,21 @@ impl GuestFields for Fields { } fn clone(&self) -> Resource { + debug!("CALL wasi:http/types#fields.clone"); Resource::new(Self(self.0.clone())) } + + fn from_list(list: Vec<(String, Vec)>) -> Result, HeaderError> { + debug!("CALL wasi:http/types#fields.from-list"); + http_types::Fields::from_list(&list) + .map(|fields| Resource::new(Self(fields))) + .map_err(header_err_map_rev) + } + + fn has(&self, name: String) -> bool { + debug!("CALL wasi:http/types#fields.has NAME={name}"); + self.0.has(&name) + } } impl GuestIncomingRequest for IncomingRequest { @@ -1246,31 +1323,57 @@ impl GuestIncomingRequest for IncomingRequest { } impl GuestOutgoingRequest for OutgoingRequest { - fn new( - method: Method, - path_with_query: Option, - scheme: Option, - authority: Option, - headers: &Fields, - ) -> Self { + fn new(headers: Resource) -> Self { debug!("CALL wasi:http/types#outgoing-request.new"); Self(http_types::OutgoingRequest::new( - &method_map(method), - path_with_query.as_deref(), - scheme.map(|s| scheme_map(s)).as_ref(), - authority.as_deref(), - &headers.0, + Resource::into_inner(headers).0, )) } - fn write(&self) -> Result, ()> { + fn body(&self) -> Result, ()> { debug!("CALL wasi:http/types#outgoing-request.write"); - Ok(Resource::new(HttpOutgoingBody(self.0.write()?))) + Ok(Resource::new(HttpOutgoingBody(self.0.body()?))) + } + + fn method(&self) -> Method { + method_map_rev(self.0.method()) + } + + fn set_method(&self, method: Method) -> Result<(), ()> { + self.0.set_method(&method_map(method)) + } + + fn path_with_query(&self) -> Option { + self.0.path_with_query() + } + + fn set_path_with_query(&self, path_with_query: Option) -> Result<(), ()> { + self.0.set_path_with_query(path_with_query.as_deref()) + } + + fn scheme(&self) -> Option { + self.0.scheme().map(scheme_map_rev) + } + + fn set_scheme(&self, scheme: Option) -> Result<(), ()> { + self.0.set_scheme(scheme.map(scheme_map).as_ref()) + } + + fn authority(&self) -> Option { + self.0.authority() + } + + fn set_authority(&self, authority: Option) -> Result<(), ()> { + self.0.set_authority(authority.as_deref()) + } + + fn headers(&self) -> Resource { + Resource::new(HttpFields(self.0.headers())) } } impl GuestResponseOutparam for ResponseOutparam { - fn set(param: Resource, response: Result, HttpError>) { + fn set(param: Resource, response: Result, HttpErrorCode>) { debug!("CALL wasi:http/types#response-outparam.set"); let param = Resource::into_inner(param).0; match response { @@ -1315,24 +1418,44 @@ impl GuestFutureTrailers for FutureTrailers { Resource::new(Pollable::Host(self.0.subscribe())) } - fn get(&self) -> Option, HttpError>> { + fn get(&self) -> Option>, HttpErrorCode>, ()>> { debug!("CALL wasi:http/types#future-trailers.get"); self.0.get().map(|r| { - r.map(|fields| Resource::new(HttpFields(fields))) - .map_err(|e| http_err_map_rev(e)) + r.map(|fields| { + fields + .map(|fields| fields.map(|fields| Resource::new(HttpFields(fields)))) + .map_err(http_err_map_rev) + }) }) } } impl GuestOutgoingResponse for OutgoingResponse { - fn new(status_code: StatusCode, headers: &Fields) -> Self { + fn new(headers: Resource) -> Self { debug!("CALL wasi:http/types#outgoing-response.constructor"); - Self(http_types::OutgoingResponse::new(status_code, &headers.0)) + Self(http_types::OutgoingResponse::new( + Resource::into_inner(headers).0, + )) + } + + fn status_code(&self) -> StatusCode { + debug!("CALL wasi:http/types#outgoing-response.status-code"); + self.0.status_code() + } + + fn set_status_code(&self, status_code: StatusCode) -> Result<(), ()> { + debug!("CALL wasi:http/types#outgoing-response.set-status-code"); + self.0.set_status_code(status_code) } - fn write(&self) -> Result, ()> { + fn headers(&self) -> Resource { + debug!("CALL wasi:http/types#outgoing-response.headers"); + Resource::new(HttpFields(self.0.headers())) + } + + fn body(&self) -> Result, ()> { debug!("CALL wasi:http/types#outgoing-response.body"); - Ok(Resource::new(HttpOutgoingBody(self.0.write()?))) + Ok(Resource::new(HttpOutgoingBody(self.0.body()?))) } } @@ -1349,12 +1472,16 @@ impl GuestOutgoingBody for OutgoingBody { Ok(Resource::new(OutputStream::Host(self.0.write()?))) } - fn finish(body: Resource, trailers: Option>) { + fn finish( + body: Resource, + trailers: Option>, + ) -> Result<(), HttpErrorCode> { debug!("CALL wasi:http/types#outgoing-body.finish"); http_types::OutgoingBody::finish( Resource::into_inner(body).0, trailers.map(|fields| Resource::into_inner(fields).0), ) + .map_err(http_err_map_rev) } } @@ -1364,7 +1491,7 @@ impl GuestFutureIncomingResponse for FutureIncomingResponse { Resource::new(Pollable::Host(self.0.subscribe())) } - fn get(&self) -> Option, HttpError>, ()>> { + fn get(&self) -> Option, HttpErrorCode>, ()>> { debug!("CALL wasi:http/types#future-incoming-response.get"); self.0.get().map(|r| { r.map(|r| { @@ -1453,45 +1580,57 @@ impl GuestTcpSocket for TcpSocket { debug!("CALL wasi:sockets/tcp#tcp-socket.remote-address"); self.0.remote_address() } + fn is_listening(&self) -> bool { + debug!("CALL wasi:sockets/tcp#tcp-socket.is-listening"); + self.0.is_listening() + } fn address_family(&self) -> IpAddressFamily { debug!("CALL wasi:sockets/tcp#tcp-socket.address-family"); self.0.address_family() } - fn ipv6_only(&self) -> Result { - debug!("CALL wasi:sockets/tcp#tcp-socket.ipv6-only"); - self.0.ipv6_only() - } - fn set_ipv6_only(&self, value: bool) -> Result<(), NetworkErrorCode> { - debug!("CALL wasi:sockets/tcp#tcp-socket.set-ipv6-only"); - self.0.set_ipv6_only(value) - } fn set_listen_backlog_size(&self, value: u64) -> Result<(), NetworkErrorCode> { debug!("CALL wasi:sockets/tcp#tcp-socket.set-listen-backlog-size"); self.0.set_listen_backlog_size(value) } - fn keep_alive(&self) -> Result { - debug!("CALL wasi:sockets/tcp#tcp-socket.keep-alive"); - self.0.keep_alive() + fn keep_alive_enabled(&self) -> Result { + debug!("CALL wasi:sockets/tcp#tcp-socket.keep-alive-enabled"); + self.0.keep_alive_enabled() } - fn set_keep_alive(&self, value: bool) -> Result<(), NetworkErrorCode> { - debug!("CALL wasi:sockets/tcp#tcp-socket.set-keep-alive"); - self.0.set_keep_alive(value) + fn set_keep_alive_enabled(&self, value: bool) -> Result<(), NetworkErrorCode> { + debug!("CALL wasi:sockets/tcp#tcp-socket.set-keep-alive-enabled"); + self.0.set_keep_alive_enabled(value) } - fn no_delay(&self) -> Result { - debug!("CALL wasi:sockets/tcp#tcp-socket.no-delay"); - self.0.no_delay() + fn keep_alive_idle_time(&self) -> Result { + debug!("CALL wasi:sockets/tcp#tcp-socket.keep-alive-idle-time"); + self.0.keep_alive_idle_time() } - fn set_no_delay(&self, value: bool) -> Result<(), NetworkErrorCode> { - debug!("CALL wasi:sockets/tcp#tcp-socket.set-no-delay"); - self.0.set_no_delay(value) + fn set_keep_alive_idle_time(&self, value: Duration) -> Result<(), NetworkErrorCode> { + debug!("CALL wasi:sockets/tcp#tcp-socket.set-keep-alive-idle-time"); + self.0.set_keep_alive_idle_time(value) } - fn unicast_hop_limit(&self) -> Result { - debug!("CALL wasi:sockets/tcp#tcp-socket.unicast-hop-limit"); - self.0.unicast_hop_limit() + fn keep_alive_interval(&self) -> Result { + debug!("CALL wasi:sockets/tcp#tcp-socket.keep-alive-interval-time"); + self.0.keep_alive_interval() } - fn set_unicast_hop_limit(&self, value: u8) -> Result<(), NetworkErrorCode> { - debug!("CALL wasi:sockets/tcp#tcp-socket.set-unicast-hop-limit"); - self.0.set_unicast_hop_limit(value) + fn set_keep_alive_interval(&self, value: Duration) -> Result<(), NetworkErrorCode> { + debug!("CALL wasi:sockets/tcp#tcp-socket.set-keep-alive-interval-time"); + self.0.set_keep_alive_interval(value) + } + fn keep_alive_count(&self) -> Result { + debug!("CALL wasi:sockets/tcp#tcp-socket.keep-alive-count-time"); + self.0.keep_alive_count() + } + fn set_keep_alive_count(&self, value: u32) -> Result<(), NetworkErrorCode> { + debug!("CALL wasi:sockets/tcp#tcp-socket.set-keep-alive-count-time"); + self.0.set_keep_alive_count(value) + } + fn hop_limit(&self) -> Result { + debug!("CALL wasi:sockets/tcp#tcp-socket.hop-limit"); + self.0.hop_limit() + } + fn set_hop_limit(&self, value: u8) -> Result<(), NetworkErrorCode> { + debug!("CALL wasi:sockets/tcp#tcp-socket.set-hop-limit"); + self.0.set_hop_limit(value) } fn receive_buffer_size(&self) -> Result { debug!("CALL wasi:sockets/tcp#tcp-socket.receive-buffer-size"); @@ -1536,44 +1675,6 @@ impl GuestUdpSocket for UdpSocket { debug!("CALL wasi:sockets/udp#udp-socket.finish-bind"); self.0.finish_bind() } - fn start_connect( - &self, - network: &Network, - remote_address: IpSocketAddress, - ) -> Result<(), NetworkErrorCode> { - debug!("CALL wasi:sockets/udp#udp-socket.start-connect"); - self.0.start_connect(network, remote_address) - } - fn finish_connect(&self) -> Result<(), NetworkErrorCode> { - debug!("CALL wasi:sockets/udp#udp-socket.finish-connect"); - self.0.finish_connect() - } - fn receive(&self, max_results: u64) -> Result, NetworkErrorCode> { - debug!("CALL wasi:sockets/udp#udp-socket.receive"); - match self.0.receive(max_results) { - Ok(mut datagrams) => Ok(datagrams - .drain(..) - .map(|d| Datagram { - data: d.data, - remote_address: d.remote_address, - }) - .collect::>()), - Err(err) => Err(err), - } - } - fn send(&self, mut datagrams: Vec) -> Result { - debug!("CALL wasi:sockets/udp#udp-socket.send"); - self.0.send( - datagrams - .drain(..) - .map(|d| udp::Datagram { - data: d.data, - remote_address: d.remote_address, - }) - .collect::>() - .as_slice(), - ) - } fn local_address(&self) -> Result { debug!("CALL wasi:sockets/udp#udp-socket.local-address"); self.0.local_address() @@ -1586,14 +1687,6 @@ impl GuestUdpSocket for UdpSocket { debug!("CALL wasi:sockets/udp#udp-socket.address-family"); self.0.address_family() } - fn ipv6_only(&self) -> Result { - debug!("CALL wasi:sockets/udp#udp-socket.ipv6-only"); - self.0.ipv6_only() - } - fn set_ipv6_only(&self, value: bool) -> Result<(), NetworkErrorCode> { - debug!("CALL wasi:sockets/udp#udp-socket.set-ipv6-only"); - self.0.set_ipv6_only(value) - } fn unicast_hop_limit(&self) -> Result { debug!("CALL wasi:sockets/udp#udp-socket.unicast-hop-limit"); self.0.unicast_hop_limit() @@ -1622,6 +1715,70 @@ impl GuestUdpSocket for UdpSocket { debug!("CALL wasi:sockets/udp#udp-socket.subscribe"); Resource::new(Pollable::Host(self.0.subscribe())) } + fn stream( + &self, + remote_addr: Option, + ) -> Result< + ( + Resource, + Resource, + ), + NetworkErrorCode, + > { + debug!("CALL wasi:sockets/udp#udp-socket.stream"); + let (in_, out) = self.0.stream(remote_addr)?; + Ok(( + Resource::new(SocketsIncomingDatagramStream(in_)), + Resource::new(SocketsOutgoingDatagramStream(out)), + )) + } +} + +impl GuestIncomingDatagramStream for SocketsIncomingDatagramStream { + fn receive(&self, max_results: u64) -> Result, NetworkErrorCode> { + debug!("CALL wasi:sockets/udp#incoming-datagram-stream.receive"); + match self.0.receive(max_results) { + Ok(mut datagrams) => Ok(datagrams + .drain(..) + .map(|d| IncomingDatagram { + data: d.data, + remote_address: d.remote_address, + }) + .collect::>()), + Err(err) => Err(err), + } + } + + fn subscribe(&self) -> Resource { + debug!("CALL wasi:sockets/udp#incoming-datagram-stream.subscribe"); + Resource::new(Pollable::Host(self.0.subscribe())) + } +} + +impl GuestOutgoingDatagramStream for SocketsOutgoingDatagramStream { + fn check_send(&self) -> Result { + debug!("CALL wasi:sockets/udp#outgoing-datagram-stream.check-send"); + self.0.check_send() + } + + fn send(&self, mut datagrams: Vec) -> Result { + debug!("CALL wasi:sockets/udp#outgoing-datagram-stream.send"); + self.0.send( + datagrams + .drain(..) + .map(|d| udp::OutgoingDatagram { + data: d.data, + remote_address: d.remote_address, + }) + .collect::>() + .as_slice(), + ) + } + + fn subscribe(&self) -> Resource { + debug!("CALL wasi:sockets/udp#outgoing-datagram-stream.subscribe"); + Resource::new(Pollable::Host(self.0.subscribe())) + } } fn descriptor_ty_map(d: filesystem_types::DescriptorType) -> DescriptorType { @@ -1722,6 +1879,14 @@ fn scheme_map_rev(scheme: http_types::Scheme) -> Scheme { } } +fn header_err_map_rev(err: http_types::HeaderError) -> HeaderError { + match err { + http_types::HeaderError::InvalidSyntax => HeaderError::InvalidSyntax, + http_types::HeaderError::Forbidden => HeaderError::Forbidden, + http_types::HeaderError::Immutable => HeaderError::Immutable, + } +} + fn method_map_rev(method: http_types::Method) -> Method { match method { http_types::Method::Get => Method::Get, @@ -1752,29 +1917,189 @@ fn method_map(method: Method) -> http_types::Method { } } -fn http_err_map(err: HttpError) -> http_types::Error { +fn http_err_map(err: HttpErrorCode) -> http_types::ErrorCode { match err { - HttpError::InvalidUrl(s) => http_types::Error::InvalidUrl(s), - HttpError::TimeoutError(s) => http_types::Error::TimeoutError(s), - HttpError::ProtocolError(s) => http_types::Error::ProtocolError(s), - HttpError::UnexpectedError(s) => http_types::Error::UnexpectedError(s), + HttpErrorCode::DnsTimeout => http_types::ErrorCode::DnsTimeout, + HttpErrorCode::DnsError(DnsErrorPayload { rcode, info_code }) => { + http_types::ErrorCode::DnsError(http_types::DnsErrorPayload { rcode, info_code }) + } + HttpErrorCode::DestinationNotFound => http_types::ErrorCode::DestinationNotFound, + HttpErrorCode::DestinationUnavailable => http_types::ErrorCode::DestinationUnavailable, + HttpErrorCode::DestinationIpProhibited => http_types::ErrorCode::DestinationIpProhibited, + HttpErrorCode::DestinationIpUnroutable => http_types::ErrorCode::DestinationIpUnroutable, + HttpErrorCode::ConnectionRefused => http_types::ErrorCode::ConnectionRefused, + HttpErrorCode::ConnectionTerminated => http_types::ErrorCode::ConnectionTerminated, + HttpErrorCode::ConnectionTimeout => http_types::ErrorCode::ConnectionTimeout, + HttpErrorCode::ConnectionReadTimeout => http_types::ErrorCode::ConnectionReadTimeout, + HttpErrorCode::ConnectionWriteTimeout => http_types::ErrorCode::ConnectionWriteTimeout, + HttpErrorCode::ConnectionLimitReached => http_types::ErrorCode::ConnectionLimitReached, + HttpErrorCode::TlsProtocolError => http_types::ErrorCode::TlsProtocolError, + HttpErrorCode::TlsCertificateError => http_types::ErrorCode::TlsCertificateError, + HttpErrorCode::TlsAlertReceived(TlsAlertReceivedPayload { + alert_id, + alert_message, + }) => http_types::ErrorCode::TlsAlertReceived(http_types::TlsAlertReceivedPayload { + alert_id, + alert_message, + }), + HttpErrorCode::HttpRequestDenied => http_types::ErrorCode::HttpRequestDenied, + HttpErrorCode::HttpRequestLengthRequired => { + http_types::ErrorCode::HttpRequestLengthRequired + } + HttpErrorCode::HttpRequestBodySize(s) => http_types::ErrorCode::HttpRequestBodySize(s), + HttpErrorCode::HttpRequestMethodInvalid => http_types::ErrorCode::HttpRequestMethodInvalid, + HttpErrorCode::HttpRequestUriInvalid => http_types::ErrorCode::HttpRequestUriInvalid, + HttpErrorCode::HttpRequestUriTooLong => http_types::ErrorCode::HttpRequestUriTooLong, + HttpErrorCode::HttpRequestHeaderSectionSize(s) => { + http_types::ErrorCode::HttpRequestHeaderSectionSize(s) + } + HttpErrorCode::HttpRequestHeaderSize(Some(FieldSizePayload { + field_name, + field_size, + })) => http_types::ErrorCode::HttpRequestHeaderSize(Some(http_types::FieldSizePayload { + field_name, + field_size, + })), + HttpErrorCode::HttpRequestHeaderSize(None) => { + http_types::ErrorCode::HttpRequestHeaderSize(None) + } + HttpErrorCode::HttpRequestTrailerSectionSize(s) => { + http_types::ErrorCode::HttpRequestTrailerSectionSize(s) + } + HttpErrorCode::HttpRequestTrailerSize(FieldSizePayload { + field_name, + field_size, + }) => http_types::ErrorCode::HttpRequestTrailerSize(http_types::FieldSizePayload { + field_name, + field_size, + }), + HttpErrorCode::HttpResponseIncomplete => http_types::ErrorCode::HttpResponseIncomplete, + HttpErrorCode::HttpResponseHeaderSectionSize(s) => { + http_types::ErrorCode::HttpResponseHeaderSectionSize(s) + } + HttpErrorCode::HttpResponseHeaderSize(FieldSizePayload { + field_name, + field_size, + }) => http_types::ErrorCode::HttpResponseHeaderSize(http_types::FieldSizePayload { + field_name, + field_size, + }), + HttpErrorCode::HttpResponseBodySize(s) => http_types::ErrorCode::HttpResponseBodySize(s), + HttpErrorCode::HttpResponseTrailerSectionSize(s) => { + http_types::ErrorCode::HttpResponseTrailerSectionSize(s) + } + HttpErrorCode::HttpResponseTrailerSize(FieldSizePayload { + field_name, + field_size, + }) => http_types::ErrorCode::HttpResponseTrailerSize(http_types::FieldSizePayload { + field_name, + field_size, + }), + HttpErrorCode::HttpResponseTransferCoding(e) => { + http_types::ErrorCode::HttpResponseTransferCoding(e) + } + HttpErrorCode::HttpResponseContentCoding(e) => { + http_types::ErrorCode::HttpResponseContentCoding(e) + } + HttpErrorCode::HttpResponseTimeout => http_types::ErrorCode::HttpResponseTimeout, + HttpErrorCode::HttpUpgradeFailed => http_types::ErrorCode::HttpUpgradeFailed, + HttpErrorCode::HttpProtocolError => http_types::ErrorCode::HttpProtocolError, + HttpErrorCode::LoopDetected => http_types::ErrorCode::LoopDetected, + HttpErrorCode::ConfigurationError => http_types::ErrorCode::ConfigurationError, + HttpErrorCode::InternalError(e) => http_types::ErrorCode::InternalError(e), } } -fn http_err_map_rev(err: http_types::Error) -> HttpError { +fn http_err_map_rev(err: http_types::ErrorCode) -> HttpErrorCode { match err { - http_types::Error::InvalidUrl(s) => HttpError::InvalidUrl(s), - http_types::Error::TimeoutError(s) => HttpError::TimeoutError(s), - http_types::Error::ProtocolError(s) => HttpError::ProtocolError(s), - http_types::Error::UnexpectedError(s) => HttpError::UnexpectedError(s), - } -} - -fn request_options_map(options: RequestOptions) -> http_types::RequestOptions { - http_types::RequestOptions { - connect_timeout_ms: options.connect_timeout_ms, - first_byte_timeout_ms: options.first_byte_timeout_ms, - between_bytes_timeout_ms: options.between_bytes_timeout_ms, + http_types::ErrorCode::DnsTimeout => HttpErrorCode::DnsTimeout, + http_types::ErrorCode::DnsError(http_types::DnsErrorPayload { rcode, info_code }) => { + HttpErrorCode::DnsError(DnsErrorPayload { rcode, info_code }) + } + http_types::ErrorCode::DestinationNotFound => HttpErrorCode::DestinationNotFound, + http_types::ErrorCode::DestinationUnavailable => HttpErrorCode::DestinationUnavailable, + http_types::ErrorCode::DestinationIpProhibited => HttpErrorCode::DestinationIpProhibited, + http_types::ErrorCode::DestinationIpUnroutable => HttpErrorCode::DestinationIpUnroutable, + http_types::ErrorCode::ConnectionRefused => HttpErrorCode::ConnectionRefused, + http_types::ErrorCode::ConnectionTerminated => HttpErrorCode::ConnectionTerminated, + http_types::ErrorCode::ConnectionTimeout => HttpErrorCode::ConnectionTimeout, + http_types::ErrorCode::ConnectionReadTimeout => HttpErrorCode::ConnectionReadTimeout, + http_types::ErrorCode::ConnectionWriteTimeout => HttpErrorCode::ConnectionWriteTimeout, + http_types::ErrorCode::ConnectionLimitReached => HttpErrorCode::ConnectionLimitReached, + http_types::ErrorCode::TlsProtocolError => HttpErrorCode::TlsProtocolError, + http_types::ErrorCode::TlsCertificateError => HttpErrorCode::TlsCertificateError, + http_types::ErrorCode::TlsAlertReceived(http_types::TlsAlertReceivedPayload { + alert_id, + alert_message, + }) => HttpErrorCode::TlsAlertReceived(TlsAlertReceivedPayload { + alert_id, + alert_message, + }), + http_types::ErrorCode::HttpRequestDenied => HttpErrorCode::HttpRequestDenied, + http_types::ErrorCode::HttpRequestLengthRequired => { + HttpErrorCode::HttpRequestLengthRequired + } + http_types::ErrorCode::HttpRequestBodySize(s) => HttpErrorCode::HttpRequestBodySize(s), + http_types::ErrorCode::HttpRequestMethodInvalid => HttpErrorCode::HttpRequestMethodInvalid, + http_types::ErrorCode::HttpRequestUriInvalid => HttpErrorCode::HttpRequestUriInvalid, + http_types::ErrorCode::HttpRequestUriTooLong => HttpErrorCode::HttpRequestUriTooLong, + http_types::ErrorCode::HttpRequestHeaderSectionSize(s) => { + HttpErrorCode::HttpRequestHeaderSectionSize(s) + } + http_types::ErrorCode::HttpRequestHeaderSize(Some(http_types::FieldSizePayload { + field_name, + field_size, + })) => HttpErrorCode::HttpRequestHeaderSize(Some(FieldSizePayload { + field_name, + field_size, + })), + http_types::ErrorCode::HttpRequestHeaderSize(None) => { + HttpErrorCode::HttpRequestHeaderSize(None) + } + http_types::ErrorCode::HttpRequestTrailerSectionSize(s) => { + HttpErrorCode::HttpRequestTrailerSectionSize(s) + } + http_types::ErrorCode::HttpRequestTrailerSize(http_types::FieldSizePayload { + field_name, + field_size, + }) => HttpErrorCode::HttpRequestTrailerSize(FieldSizePayload { + field_name, + field_size, + }), + http_types::ErrorCode::HttpResponseIncomplete => HttpErrorCode::HttpResponseIncomplete, + http_types::ErrorCode::HttpResponseHeaderSectionSize(s) => { + HttpErrorCode::HttpResponseHeaderSectionSize(s) + } + http_types::ErrorCode::HttpResponseHeaderSize(http_types::FieldSizePayload { + field_name, + field_size, + }) => HttpErrorCode::HttpResponseHeaderSize(FieldSizePayload { + field_name, + field_size, + }), + http_types::ErrorCode::HttpResponseBodySize(s) => HttpErrorCode::HttpResponseBodySize(s), + http_types::ErrorCode::HttpResponseTrailerSectionSize(s) => { + HttpErrorCode::HttpResponseTrailerSectionSize(s) + } + http_types::ErrorCode::HttpResponseTrailerSize(http_types::FieldSizePayload { + field_name, + field_size, + }) => HttpErrorCode::HttpResponseTrailerSize(FieldSizePayload { + field_name, + field_size, + }), + http_types::ErrorCode::HttpResponseTransferCoding(e) => { + HttpErrorCode::HttpResponseTransferCoding(e) + } + http_types::ErrorCode::HttpResponseContentCoding(e) => { + HttpErrorCode::HttpResponseContentCoding(e) + } + http_types::ErrorCode::HttpResponseTimeout => HttpErrorCode::HttpResponseTimeout, + http_types::ErrorCode::HttpUpgradeFailed => HttpErrorCode::HttpUpgradeFailed, + http_types::ErrorCode::HttpProtocolError => HttpErrorCode::HttpProtocolError, + http_types::ErrorCode::LoopDetected => HttpErrorCode::LoopDetected, + http_types::ErrorCode::ConfigurationError => HttpErrorCode::ConfigurationError, + http_types::ErrorCode::InternalError(e) => HttpErrorCode::InternalError(e), } } diff --git a/virtual-adapter/src/lib.rs b/virtual-adapter/src/lib.rs index 7f57d3d..3b69025 100644 --- a/virtual-adapter/src/lib.rs +++ b/virtual-adapter/src/lib.rs @@ -10,25 +10,22 @@ wit_bindgen::generate!({ path: "../wit", world: "virtual-adapter", exports: { - "wasi:io/poll": VirtAdapter, - "wasi:io/poll/pollable": io::IoPollable, - "wasi:io/error/error": io::IoError, - "wasi:io/streams/input-stream": io::IoInputStream, - "wasi:io/streams/output-stream": io::IoOutputStream, - "wasi:filesystem/preopens": VirtAdapter, - "wasi:filesystem/types": VirtAdapter, - "wasi:filesystem/types/descriptor": io::FilesystemDescriptor, - "wasi:filesystem/types/directory-entry-stream": io::FilesystemDirectoryEntryStream, "wasi:cli/environment": VirtAdapter, + "wasi:cli/stderr": VirtAdapter, "wasi:cli/stdin": VirtAdapter, "wasi:cli/stdout": VirtAdapter, - "wasi:cli/stderr": VirtAdapter, "wasi:cli/terminal-input/terminal-input": io::CliTerminalInput, "wasi:cli/terminal-output/terminal-output": io::CliTerminalOutput, + "wasi:cli/terminal-stderr": VirtAdapter, "wasi:cli/terminal-stdin": VirtAdapter, "wasi:cli/terminal-stdout": VirtAdapter, - "wasi:cli/terminal-stderr": VirtAdapter, "wasi:clocks/monotonic-clock": VirtAdapter, + "wasi:filesystem/preopens": VirtAdapter, + "wasi:filesystem/types": VirtAdapter, + "wasi:filesystem/types/descriptor": io::FilesystemDescriptor, + "wasi:filesystem/types/directory-entry-stream": io::FilesystemDirectoryEntryStream, + "wasi:http/outgoing-handler": VirtAdapter, + "wasi:http/types": io::HttpTypes, "wasi:http/types/fields": io::HttpFields, "wasi:http/types/future-incoming-response": io::HttpFutureIncomingResponse, "wasi:http/types/future-trailers": io::HttpFutureTrailers, @@ -38,11 +35,18 @@ wit_bindgen::generate!({ "wasi:http/types/outgoing-body": io::HttpOutgoingBody, "wasi:http/types/outgoing-request": io::HttpOutgoingRequest, "wasi:http/types/outgoing-response": io::HttpOutgoingResponse, + "wasi:http/types/request-options": io::HttpRequestOptions, "wasi:http/types/response-outparam": io::HttpResponseOutparam, - "wasi:http/outgoing-handler": VirtAdapter, + "wasi:io/error/error": io::IoError, + "wasi:io/poll": VirtAdapter, + "wasi:io/poll/pollable": io::IoPollable, + "wasi:io/streams/input-stream": io::IoInputStream, + "wasi:io/streams/output-stream": io::IoOutputStream, "wasi:sockets/ip-name-lookup": VirtAdapter, "wasi:sockets/ip-name-lookup/resolve-address-stream": io::SocketsResolveAddressStream, "wasi:sockets/tcp/tcp-socket": io::SocketsTcpSocket, + "wasi:sockets/udp/incoming-datagram-stream": io::SocketsIncomingDatagramStream, + "wasi:sockets/udp/outgoing-datagram-stream": io::SocketsOutgoingDatagramStream, "wasi:sockets/udp/udp-socket": io::SocketsUdpSocket, } }); diff --git a/wit/deps/cli/command.wit b/wit/deps/cli/command.wit index cc82ae5..d8005bd 100644 --- a/wit/deps/cli/command.wit +++ b/wit/deps/cli/command.wit @@ -1,4 +1,4 @@ -package wasi:cli@0.2.0-rc-2023-12-05; +package wasi:cli@0.2.0; world command { include imports; diff --git a/wit/deps/cli/imports.wit b/wit/deps/cli/imports.wit index 36b1c59..083b84a 100644 --- a/wit/deps/cli/imports.wit +++ b/wit/deps/cli/imports.wit @@ -1,11 +1,11 @@ -package wasi:cli@0.2.0-rc-2023-12-05; +package wasi:cli@0.2.0; world imports { - include wasi:clocks/imports@0.2.0-rc-2023-11-10; - include wasi:filesystem/imports@0.2.0-rc-2023-11-10; - include wasi:sockets/imports@0.2.0-rc-2023-10-18; - include wasi:random/imports@0.2.0-rc-2023-11-10; - include wasi:io/imports@0.2.0-rc-2023-11-10; + 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; diff --git a/wit/deps/cli/stdio.wit b/wit/deps/cli/stdio.wit index 1b653b6..31ef35b 100644 --- a/wit/deps/cli/stdio.wit +++ b/wit/deps/cli/stdio.wit @@ -1,17 +1,17 @@ interface stdin { - use wasi:io/streams@0.2.0-rc-2023-11-10.{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-11-10.{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-11-10.{output-stream}; + use wasi:io/streams@0.2.0.{output-stream}; get-stderr: func() -> output-stream; } diff --git a/wit/deps/cli/terminal.wit b/wit/deps/cli/terminal.wit index 4749576..38c724e 100644 --- a/wit/deps/cli/terminal.wit +++ b/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/wit/deps/clocks/monotonic-clock.wit b/wit/deps/clocks/monotonic-clock.wit index 09ef32c..4e4dc3a 100644 --- a/wit/deps/clocks/monotonic-clock.wit +++ b/wit/deps/clocks/monotonic-clock.wit @@ -1,4 +1,4 @@ -package wasi:clocks@0.2.0-rc-2023-11-10; +package wasi:clocks@0.2.0; /// WASI Monotonic Clock is a clock API intended to let users measure elapsed /// time. /// @@ -10,7 +10,7 @@ package wasi:clocks@0.2.0-rc-2023-11-10; /// /// It is intended for measuring elapsed time. interface monotonic-clock { - use wasi:io/poll@0.2.0-rc-2023-11-10.{pollable}; + use wasi:io/poll@0.2.0.{pollable}; /// An instant in time, in nanoseconds. An instant is relative to an /// unspecified initial value, and can only be compared to instances from diff --git a/wit/deps/clocks/wall-clock.wit b/wit/deps/clocks/wall-clock.wit index 8abb9a0..440ca0f 100644 --- a/wit/deps/clocks/wall-clock.wit +++ b/wit/deps/clocks/wall-clock.wit @@ -1,4 +1,4 @@ -package wasi:clocks@0.2.0-rc-2023-11-10; +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/wit/deps/clocks/world.wit b/wit/deps/clocks/world.wit index 8fa080f..c022457 100644 --- a/wit/deps/clocks/world.wit +++ b/wit/deps/clocks/world.wit @@ -1,4 +1,4 @@ -package wasi:clocks@0.2.0-rc-2023-11-10; +package wasi:clocks@0.2.0; world imports { import monotonic-clock; diff --git a/wit/deps/filesystem/preopens.wit b/wit/deps/filesystem/preopens.wit index 95ec678..da801f6 100644 --- a/wit/deps/filesystem/preopens.wit +++ b/wit/deps/filesystem/preopens.wit @@ -1,4 +1,4 @@ -package wasi:filesystem@0.2.0-rc-2023-11-10; +package wasi:filesystem@0.2.0; interface preopens { use types.{descriptor}; diff --git a/wit/deps/filesystem/types.wit b/wit/deps/filesystem/types.wit index 059722a..11108fc 100644 --- a/wit/deps/filesystem/types.wit +++ b/wit/deps/filesystem/types.wit @@ -1,4 +1,4 @@ -package wasi:filesystem@0.2.0-rc-2023-11-10; +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. @@ -24,8 +24,8 @@ package wasi:filesystem@0.2.0-rc-2023-11-10; /// /// [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}; + 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; diff --git a/wit/deps/filesystem/world.wit b/wit/deps/filesystem/world.wit index 285e0ba..663f579 100644 --- a/wit/deps/filesystem/world.wit +++ b/wit/deps/filesystem/world.wit @@ -1,4 +1,4 @@ -package wasi:filesystem@0.2.0-rc-2023-11-10; +package wasi:filesystem@0.2.0; world imports { import types; diff --git a/wit/deps/http/handler.wit b/wit/deps/http/handler.wit new file mode 100644 index 0000000..a34a064 --- /dev/null +++ b/wit/deps/http/handler.wit @@ -0,0 +1,43 @@ +/// This interface defines a handler of incoming HTTP Requests. It should +/// be exported by components which can respond to HTTP Requests. +interface incoming-handler { + use types.{incoming-request, response-outparam}; + + /// This function is invoked with an incoming HTTP Request, and a resource + /// `response-outparam` which provides the capability to reply with an HTTP + /// Response. The response is sent by calling the `response-outparam.set` + /// method, which allows execution to continue after the response has been + /// sent. This enables both streaming to the response body, and performing other + /// work. + /// + /// The implementor of this function must write a response to the + /// `response-outparam` before returning, or else the caller will respond + /// with an error on its behalf. + handle: func( + request: incoming-request, + response-out: response-outparam + ); +} + +/// This interface defines a handler of outgoing HTTP Requests. It should be +/// imported by components which wish to make HTTP Requests. +interface outgoing-handler { + use types.{ + outgoing-request, request-options, future-incoming-response, error-code + }; + + /// This function is invoked with an outgoing HTTP Request, and it returns + /// a resource `future-incoming-response` which represents an HTTP Response + /// which may arrive in the future. + /// + /// The `options` argument accepts optional parameters for the HTTP + /// protocol's transport layer. + /// + /// This function may return an error if the `outgoing-request` is invalid + /// or not allowed to be made. Otherwise, protocol errors are reported + /// through the `future-incoming-response`. + handle: func( + request: outgoing-request, + options: option + ) -> result; +} diff --git a/wit/deps/http/incoming-handler.wit b/wit/deps/http/incoming-handler.wit deleted file mode 100644 index 6968d63..0000000 --- a/wit/deps/http/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/wit/deps/http/outgoing-handler.wit b/wit/deps/http/outgoing-handler.wit deleted file mode 100644 index 286e283..0000000 --- a/wit/deps/http/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/wit/deps/http/proxy.wit b/wit/deps/http/proxy.wit index 20d4a43..687c24d 100644 --- a/wit/deps/http/proxy.wit +++ b/wit/deps/http/proxy.wit @@ -1,33 +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-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; + /// 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-12-05; - import wasi:cli/stderr@0.2.0-rc-2023-12-05; + /// 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-12-05; + /// 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/wit/deps/http/types.wit b/wit/deps/http/types.wit index 5f604a6..755ac6a 100644 --- a/wit/deps/http/types.wit +++ b/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-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.{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/wit/deps/io/error.wit b/wit/deps/io/error.wit index 31918ac..22e5b64 100644 --- a/wit/deps/io/error.wit +++ b/wit/deps/io/error.wit @@ -1,4 +1,4 @@ -package wasi:io@0.2.0-rc-2023-11-10; +package wasi:io@0.2.0; interface error { diff --git a/wit/deps/io/poll.wit b/wit/deps/io/poll.wit index bddde3c..ddc67f8 100644 --- a/wit/deps/io/poll.wit +++ b/wit/deps/io/poll.wit @@ -1,9 +1,9 @@ -package wasi:io@0.2.0-rc-2023-11-10; +package wasi:io@0.2.0; /// A poll API intended to let users wait for I/O events on multiple handles /// at once. interface poll { - /// `pollable` epresents a single I/O event which may be ready, or not. + /// `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. diff --git a/wit/deps/io/streams.wit b/wit/deps/io/streams.wit index e7e1b68..6d2f871 100644 --- a/wit/deps/io/streams.wit +++ b/wit/deps/io/streams.wit @@ -1,4 +1,4 @@ -package wasi:io@0.2.0-rc-2023-11-10; +package wasi:io@0.2.0; /// WASI I/O is an I/O abstraction API which is currently focused on providing /// stream types. @@ -32,6 +32,11 @@ interface streams { resource input-stream { /// Perform a non-blocking read from the stream. /// + /// When the source of a `read` is binary data, the bytes from the source + /// are returned verbatim. When the source of a `read` is known to the + /// implementation to be text, bytes containing the UTF-8 encoding of the + /// text are returned. + /// /// This function returns a list of bytes containing the read data, /// when successful. The returned list will contain up to `len` bytes; /// it may return fewer than requested, but not more. The list is @@ -111,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. /// @@ -131,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); @@ -140,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 /// ``` @@ -178,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. @@ -199,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 @@ -207,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 /// ``` diff --git a/wit/deps/io/world.wit b/wit/deps/io/world.wit index 8243da2..5f0b43f 100644 --- a/wit/deps/io/world.wit +++ b/wit/deps/io/world.wit @@ -1,4 +1,4 @@ -package wasi:io@0.2.0-rc-2023-11-10; +package wasi:io@0.2.0; world imports { import streams; diff --git a/wit/deps/random/insecure-seed.wit b/wit/deps/random/insecure-seed.wit index f76e87d..47210ac 100644 --- a/wit/deps/random/insecure-seed.wit +++ b/wit/deps/random/insecure-seed.wit @@ -1,4 +1,4 @@ -package wasi:random@0.2.0-rc-2023-11-10; +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/wit/deps/random/insecure.wit b/wit/deps/random/insecure.wit index ec7b997..c58f4ee 100644 --- a/wit/deps/random/insecure.wit +++ b/wit/deps/random/insecure.wit @@ -1,4 +1,4 @@ -package wasi:random@0.2.0-rc-2023-11-10; +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/wit/deps/random/random.wit b/wit/deps/random/random.wit index 7a7dfa2..0c017f0 100644 --- a/wit/deps/random/random.wit +++ b/wit/deps/random/random.wit @@ -1,4 +1,4 @@ -package wasi:random@0.2.0-rc-2023-11-10; +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/wit/deps/random/world.wit b/wit/deps/random/world.wit index 49e5743..3da3491 100644 --- a/wit/deps/random/world.wit +++ b/wit/deps/random/world.wit @@ -1,4 +1,4 @@ -package wasi:random@0.2.0-rc-2023-11-10; +package wasi:random@0.2.0; world imports { import random; diff --git a/wit/deps/sockets/instance-network.wit b/wit/deps/sockets/instance-network.wit index 14e4479..e455d0f 100644 --- a/wit/deps/sockets/instance-network.wit +++ b/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/wit/deps/sockets/ip-name-lookup.wit b/wit/deps/sockets/ip-name-lookup.wit index 5e8bd27..8e639ec 100644 --- a/wit/deps/sockets/ip-name-lookup.wit +++ b/wit/deps/sockets/ip-name-lookup.wit @@ -1,61 +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, 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/wit/deps/sockets/network.wit b/wit/deps/sockets/network.wit index fc51604..9cadf06 100644 --- a/wit/deps/sockets/network.wit +++ b/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/wit/deps/sockets/tcp-create-socket.wit b/wit/deps/sockets/tcp-create-socket.wit index a9a3373..c7ddf1f 100644 --- a/wit/deps/sockets/tcp-create-socket.wit +++ b/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/wit/deps/sockets/tcp.wit b/wit/deps/sockets/tcp.wit index 76caf88..5902b9e 100644 --- a/wit/deps/sockets/tcp.wit +++ b/wit/deps/sockets/tcp.wit @@ -1,268 +1,353 @@ 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 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/wit/deps/sockets/udp-create-socket.wit b/wit/deps/sockets/udp-create-socket.wit index e026359..0482d1f 100644 --- a/wit/deps/sockets/udp-create-socket.wit +++ b/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/wit/deps/sockets/udp.wit b/wit/deps/sockets/udp.wit index 4c1a9f2..d987a0a 100644 --- a/wit/deps/sockets/udp.wit +++ b/wit/deps/sockets/udp.wit @@ -1,213 +1,266 @@ 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}; - - - 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/wit/deps/sockets/world.wit b/wit/deps/sockets/world.wit index d16530c..f8bb92a 100644 --- a/wit/deps/sockets/world.wit +++ b/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/wit/virt.wit b/wit/virt.wit index 64cbca0..7ed1cfb 100644 --- a/wit/virt.wit +++ b/wit/virt.wit @@ -3,190 +3,190 @@ package local:virt; // in future this should be defined as a union world of the various // virtual subsystems, when union syntax lands world virtual-adapter { - import wasi:cli/environment@0.2.0-rc-2023-12-05; - import wasi:filesystem/preopens@0.2.0-rc-2023-11-10; - import wasi:filesystem/types@0.2.0-rc-2023-11-10; - import wasi:io/error@0.2.0-rc-2023-11-10; - export wasi:io/error@0.2.0-rc-2023-11-10; - import wasi:io/streams@0.2.0-rc-2023-11-10; - export wasi:io/streams@0.2.0-rc-2023-11-10; - import wasi:io/poll@0.2.0-rc-2023-11-10; - export wasi:io/poll@0.2.0-rc-2023-11-10; - export wasi:cli/environment@0.2.0-rc-2023-12-05; - export wasi:filesystem/types@0.2.0-rc-2023-11-10; - export wasi:filesystem/preopens@0.2.0-rc-2023-11-10; - import wasi:cli/stdin@0.2.0-rc-2023-12-05; - import wasi:cli/stdout@0.2.0-rc-2023-12-05; - import wasi:cli/stderr@0.2.0-rc-2023-12-05; - import wasi:cli/terminal-input@0.2.0-rc-2023-12-05; - import wasi:cli/terminal-output@0.2.0-rc-2023-12-05; - import wasi:cli/terminal-stdin@0.2.0-rc-2023-12-05; - import wasi:cli/terminal-stdout@0.2.0-rc-2023-12-05; - import wasi:cli/terminal-stderr@0.2.0-rc-2023-12-05; - export wasi:cli/stdin@0.2.0-rc-2023-12-05; - export wasi:cli/stdout@0.2.0-rc-2023-12-05; - export wasi:cli/stderr@0.2.0-rc-2023-12-05; - export wasi:cli/terminal-input@0.2.0-rc-2023-12-05; - export wasi:cli/terminal-output@0.2.0-rc-2023-12-05; - export wasi:cli/terminal-stdin@0.2.0-rc-2023-12-05; - export wasi:cli/terminal-stdout@0.2.0-rc-2023-12-05; - export wasi:cli/terminal-stderr@0.2.0-rc-2023-12-05; - import wasi:clocks/monotonic-clock@0.2.0-rc-2023-11-10; - export wasi:clocks/monotonic-clock@0.2.0-rc-2023-11-10; - import wasi:http/types@0.2.0-rc-2023-10-18; - export wasi:http/types@0.2.0-rc-2023-10-18; - import wasi:http/outgoing-handler@0.2.0-rc-2023-10-18; - export wasi:http/outgoing-handler@0.2.0-rc-2023-10-18; - import wasi:sockets/ip-name-lookup@0.2.0-rc-2023-10-18; - export wasi:sockets/ip-name-lookup@0.2.0-rc-2023-10-18; - import wasi:sockets/tcp@0.2.0-rc-2023-10-18; - export wasi:sockets/tcp@0.2.0-rc-2023-10-18; - import wasi:sockets/udp@0.2.0-rc-2023-10-18; - export wasi:sockets/udp@0.2.0-rc-2023-10-18; + import wasi:cli/environment@0.2.0; + import wasi:filesystem/preopens@0.2.0; + import wasi:filesystem/types@0.2.0; + import wasi:io/error@0.2.0; + export wasi:io/error@0.2.0; + import wasi:io/streams@0.2.0; + export wasi:io/streams@0.2.0; + import wasi:io/poll@0.2.0; + export wasi:io/poll@0.2.0; + export wasi:cli/environment@0.2.0; + export wasi:filesystem/types@0.2.0; + export wasi:filesystem/preopens@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; + export wasi:cli/stdin@0.2.0; + export wasi:cli/stdout@0.2.0; + export wasi:cli/stderr@0.2.0; + export wasi:cli/terminal-input@0.2.0; + export wasi:cli/terminal-output@0.2.0; + export wasi:cli/terminal-stdin@0.2.0; + export wasi:cli/terminal-stdout@0.2.0; + export wasi:cli/terminal-stderr@0.2.0; + import wasi:clocks/monotonic-clock@0.2.0; + export wasi:clocks/monotonic-clock@0.2.0; + import wasi:http/types@0.2.0; + export wasi:http/types@0.2.0; + import wasi:http/outgoing-handler@0.2.0; + export wasi:http/outgoing-handler@0.2.0; + import wasi:sockets/ip-name-lookup@0.2.0; + export wasi:sockets/ip-name-lookup@0.2.0; + import wasi:sockets/tcp@0.2.0; + export wasi:sockets/tcp@0.2.0; + import wasi:sockets/udp@0.2.0; + export wasi:sockets/udp@0.2.0; } world virtual-base { } world virtual-io { - import wasi:io/error@0.2.0-rc-2023-11-10; - export wasi:io/error@0.2.0-rc-2023-11-10; - import wasi:io/streams@0.2.0-rc-2023-11-10; - export wasi:io/streams@0.2.0-rc-2023-11-10; - import wasi:io/poll@0.2.0-rc-2023-11-10; - export wasi:io/poll@0.2.0-rc-2023-11-10; + import wasi:io/error@0.2.0; + export wasi:io/error@0.2.0; + import wasi:io/streams@0.2.0; + export wasi:io/streams@0.2.0; + import wasi:io/poll@0.2.0; + export wasi:io/poll@0.2.0; } // io components of subsystems // where there is an intersection of // streams + poll world virtual-io-sockets { - import wasi:sockets/ip-name-lookup@0.2.0-rc-2023-10-18; - export wasi:sockets/ip-name-lookup@0.2.0-rc-2023-10-18; - import wasi:sockets/tcp@0.2.0-rc-2023-10-18; - export wasi:sockets/tcp@0.2.0-rc-2023-10-18; - import wasi:sockets/udp@0.2.0-rc-2023-10-18; - export wasi:sockets/udp@0.2.0-rc-2023-10-18; + import wasi:sockets/ip-name-lookup@0.2.0; + export wasi:sockets/ip-name-lookup@0.2.0; + import wasi:sockets/tcp@0.2.0; + export wasi:sockets/tcp@0.2.0; + import wasi:sockets/udp@0.2.0; + export wasi:sockets/udp@0.2.0; } world virtual-io-clocks { - import wasi:clocks/monotonic-clock@0.2.0-rc-2023-11-10; - export wasi:clocks/monotonic-clock@0.2.0-rc-2023-11-10; + import wasi:clocks/monotonic-clock@0.2.0; + export wasi:clocks/monotonic-clock@0.2.0; } world virtual-io-http { - import wasi:http/types@0.2.0-rc-2023-10-18; - export wasi:http/types@0.2.0-rc-2023-10-18; - import wasi:http/outgoing-handler@0.2.0-rc-2023-10-18; - export wasi:http/outgoing-handler@0.2.0-rc-2023-10-18; + import wasi:http/types@0.2.0; + export wasi:http/types@0.2.0; + import wasi:http/outgoing-handler@0.2.0; + export wasi:http/outgoing-handler@0.2.0; } world virtual-fs { - import wasi:filesystem/preopens@0.2.0-rc-2023-11-10; - import wasi:filesystem/types@0.2.0-rc-2023-11-10; - export wasi:filesystem/types@0.2.0-rc-2023-11-10; - export wasi:filesystem/preopens@0.2.0-rc-2023-11-10; + import wasi:filesystem/preopens@0.2.0; + import wasi:filesystem/types@0.2.0; + export wasi:filesystem/types@0.2.0; + export wasi:filesystem/preopens@0.2.0; } world virtual-stdio { - import wasi:cli/stdin@0.2.0-rc-2023-12-05; - import wasi:cli/stdout@0.2.0-rc-2023-12-05; - import wasi:cli/stderr@0.2.0-rc-2023-12-05; - import wasi:cli/terminal-input@0.2.0-rc-2023-12-05; - import wasi:cli/terminal-output@0.2.0-rc-2023-12-05; - import wasi:cli/terminal-stdin@0.2.0-rc-2023-12-05; - import wasi:cli/terminal-stdout@0.2.0-rc-2023-12-05; - import wasi:cli/terminal-stderr@0.2.0-rc-2023-12-05; - export wasi:cli/stdin@0.2.0-rc-2023-12-05; - export wasi:cli/stdout@0.2.0-rc-2023-12-05; - export wasi:cli/stderr@0.2.0-rc-2023-12-05; - export wasi:cli/terminal-input@0.2.0-rc-2023-12-05; - export wasi:cli/terminal-output@0.2.0-rc-2023-12-05; - export wasi:cli/terminal-stdin@0.2.0-rc-2023-12-05; - export wasi:cli/terminal-stdout@0.2.0-rc-2023-12-05; - export wasi:cli/terminal-stderr@0.2.0-rc-2023-12-05; + 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; + export wasi:cli/stdin@0.2.0; + export wasi:cli/stdout@0.2.0; + export wasi:cli/stderr@0.2.0; + export wasi:cli/terminal-input@0.2.0; + export wasi:cli/terminal-output@0.2.0; + export wasi:cli/terminal-stdin@0.2.0; + export wasi:cli/terminal-stdout@0.2.0; + export wasi:cli/terminal-stderr@0.2.0; } // remaining subsystems world virtual-env { - import wasi:cli/environment@0.2.0-rc-2023-12-05; - export wasi:cli/environment@0.2.0-rc-2023-12-05; + import wasi:cli/environment@0.2.0; + export wasi:cli/environment@0.2.0; } world virtual-clocks { - import wasi:clocks/monotonic-clock@0.2.0-rc-2023-11-10; - export wasi:clocks/monotonic-clock@0.2.0-rc-2023-11-10; - import wasi:clocks/wall-clock@0.2.0-rc-2023-11-10; - export wasi:clocks/wall-clock@0.2.0-rc-2023-11-10; + import wasi:clocks/monotonic-clock@0.2.0; + export wasi:clocks/monotonic-clock@0.2.0; + import wasi:clocks/wall-clock@0.2.0; + export wasi:clocks/wall-clock@0.2.0; } world virtual-random { - import wasi:random/insecure-seed@0.2.0-rc-2023-11-10; - import wasi:random/insecure@0.2.0-rc-2023-11-10; - import wasi:random/random@0.2.0-rc-2023-11-10; - export wasi:random/insecure-seed@0.2.0-rc-2023-11-10; - export wasi:random/insecure@0.2.0-rc-2023-11-10; - export wasi:random/random@0.2.0-rc-2023-11-10; + import wasi:random/insecure-seed@0.2.0; + import wasi:random/insecure@0.2.0; + import wasi:random/random@0.2.0; + export wasi:random/insecure-seed@0.2.0; + export wasi:random/insecure@0.2.0; + export wasi:random/random@0.2.0; } world virtual-sockets { - import wasi:sockets/ip-name-lookup@0.2.0-rc-2023-10-18; - export wasi:sockets/ip-name-lookup@0.2.0-rc-2023-10-18; - import wasi:sockets/tcp@0.2.0-rc-2023-10-18; - export wasi:sockets/tcp@0.2.0-rc-2023-10-18; - import wasi:sockets/udp@0.2.0-rc-2023-10-18; - export wasi:sockets/udp@0.2.0-rc-2023-10-18; - import wasi:sockets/instance-network@0.2.0-rc-2023-10-18; - import wasi:sockets/tcp-create-socket@0.2.0-rc-2023-10-18; - import wasi:sockets/udp-create-socket@0.2.0-rc-2023-10-18; - export wasi:sockets/instance-network@0.2.0-rc-2023-10-18; - export wasi:sockets/tcp-create-socket@0.2.0-rc-2023-10-18; - export wasi:sockets/udp-create-socket@0.2.0-rc-2023-10-18; - import wasi:sockets/network@0.2.0-rc-2023-10-18; - export wasi:sockets/network@0.2.0-rc-2023-10-18; + import wasi:sockets/ip-name-lookup@0.2.0; + export wasi:sockets/ip-name-lookup@0.2.0; + import wasi:sockets/tcp@0.2.0; + export wasi:sockets/tcp@0.2.0; + import wasi:sockets/udp@0.2.0; + export wasi:sockets/udp@0.2.0; + import wasi:sockets/instance-network@0.2.0; + import wasi:sockets/tcp-create-socket@0.2.0; + import wasi:sockets/udp-create-socket@0.2.0; + export wasi:sockets/instance-network@0.2.0; + export wasi:sockets/tcp-create-socket@0.2.0; + export wasi:sockets/udp-create-socket@0.2.0; + import wasi:sockets/network@0.2.0; + export wasi:sockets/network@0.2.0; } world virtual-http { - import wasi:http/types@0.2.0-rc-2023-10-18; - export wasi:http/types@0.2.0-rc-2023-10-18; - import wasi:http/incoming-handler@0.2.0-rc-2023-10-18; - import wasi:http/outgoing-handler@0.2.0-rc-2023-10-18; - export wasi:http/incoming-handler@0.2.0-rc-2023-10-18; - export wasi:http/outgoing-handler@0.2.0-rc-2023-10-18; + import wasi:http/types@0.2.0; + export wasi:http/types@0.2.0; + import wasi:http/incoming-handler@0.2.0; + import wasi:http/outgoing-handler@0.2.0; + export wasi:http/incoming-handler@0.2.0; + export wasi:http/outgoing-handler@0.2.0; } world virtual-exit { - import wasi:cli/exit@0.2.0-rc-2023-12-05; - export wasi:cli/exit@0.2.0-rc-2023-12-05; + import wasi:cli/exit@0.2.0; + export wasi:cli/exit@0.2.0; } world virt-test { - 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: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-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 wasi:cli/environment@0.2.0-rc-2023-12-05; - import wasi:filesystem/preopens@0.2.0-rc-2023-11-10; - import wasi:cli/exit@0.2.0-rc-2023-12-05; - import wasi:cli/stdin@0.2.0-rc-2023-12-05; - import wasi:cli/stdout@0.2.0-rc-2023-12-05; - import wasi:cli/stderr@0.2.0-rc-2023-12-05; - import wasi:cli/terminal-input@0.2.0-rc-2023-12-05; - import wasi:cli/terminal-output@0.2.0-rc-2023-12-05; - import wasi:cli/terminal-stdin@0.2.0-rc-2023-12-05; - import wasi:cli/terminal-stdout@0.2.0-rc-2023-12-05; - import wasi:cli/terminal-stderr@0.2.0-rc-2023-12-05; + 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: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:filesystem/preopens@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; export test-get-env: func() -> list>; export test-file-read: func(path: string) -> string;