diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 7ee67d4e..d5659cd2 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -63,6 +63,8 @@ jobs: key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} - name: Install Wasm32-wasi target run: rustup target add wasm32-wasi + - name: Install wasm-tools + run: cargo install --locked wasm-tools@1.0.44 - name: Build Rust examples working-directory: ./examples run: make all diff --git a/Cargo.lock b/Cargo.lock index c8662a29..d3994b8c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -88,7 +88,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e01ed3140b2f8d422c68afa1ed2e85d996ea619c988ac834d255db32138655cb" dependencies = [ "quote", - "syn 2.0.33", + "syn 2.0.37", ] [[package]] @@ -201,7 +201,7 @@ dependencies = [ "actix-router", "proc-macro2", "quote", - "syn 2.0.33", + "syn 2.0.37", ] [[package]] @@ -233,9 +233,9 @@ dependencies = [ [[package]] name = "aho-corasick" -version = "1.0.5" +version = "1.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0c378d78423fdad8089616f827526ee33c19f2fddbd5de1629152c9593ba4783" +checksum = "ea5d730647d4fadd988536d06fecce94b7b4f2a7efdae548f1cf4b63205518ab" dependencies = [ "memchr", ] @@ -263,9 +263,9 @@ checksum = "e9d4ee0d472d1cd2e28c97dfa124b3d8d992e10eb0a035f33f5d12e3a177ba3b" [[package]] name = "anstream" -version = "0.5.0" +version = "0.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b1f58811cfac344940f1a400b6e6231ce35171f614f26439e80f8c1465c5cc0c" +checksum = "2ab91ebe16eb252986481c5b62f6098f3b698a45e34b5b98200cf20dd2484a44" dependencies = [ "anstyle", "anstyle-parse", @@ -277,15 +277,15 @@ dependencies = [ [[package]] name = "anstyle" -version = "1.0.3" +version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b84bf0a05bbb2a83e5eb6fa36bb6e87baa08193c35ff52bbf6b38d8af2890e46" +checksum = "7079075b41f533b8c61d2a4d073c4676e1f8b249ff94a393b0595db304e0dd87" [[package]] name = "anstyle-parse" -version = "0.2.1" +version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "938874ff5980b03a87c5524b3ae5b59cf99b1d6bc836848df7bc5ada9643c333" +checksum = "317b9a89c1868f5ea6ff1d9539a69f45dffc21ce321ac1fd1160dfa48c8e2140" dependencies = [ "utf8parse", ] @@ -301,9 +301,9 @@ dependencies = [ [[package]] name = "anstyle-wincon" -version = "2.1.0" +version = "3.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "58f54d10c6dfa51283a066ceab3ec1ab78d13fae00aa49243a45e4571fb79dfd" +checksum = "f0699d10d2f4d628a98ee7b57b289abbc98ff3bad977cb3152709d4bf2330628" dependencies = [ "anstyle", "windows-sys", @@ -347,7 +347,7 @@ checksum = "bc00ceb34980c03614e35a3a4e218276a0a824e911d07651cd0d858a51e8c0f0" dependencies = [ "proc-macro2", "quote", - "syn 2.0.33", + "syn 2.0.37", ] [[package]] @@ -434,16 +434,15 @@ checksum = "b4682ae6287fcf752ecaabbfcc7b6f9b72aa33933dc23a554d853aea8eea8635" [[package]] name = "blake3" -version = "1.4.1" +version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "199c42ab6972d92c9f8995f086273d25c42fc0f7b2a1fcefba465c1352d25ba5" +checksum = "0231f06152bf547e9c2b5194f247cd97aacf6dcd8b15d8e5ec0663f64580da87" dependencies = [ "arrayref", "arrayvec", "cc", "cfg-if", "constant_time_eq", - "digest", ] [[package]] @@ -520,7 +519,7 @@ checksum = "b779b2d0a001c125b4584ad586268fb4b92d957bff8d26d7fe0dd78283faa814" dependencies = [ "cap-primitives", "cap-std", - "io-lifetimes 2.0.2", + "io-lifetimes", "windows-sys", ] @@ -532,7 +531,7 @@ checksum = "6ffc30dee200c20b4dcb80572226f42658e1d9c4b668656d7cc59c33d50e396e" dependencies = [ "cap-primitives", "cap-std", - "rustix 0.38.13", + "rustix", "smallvec", ] @@ -545,10 +544,10 @@ dependencies = [ "ambient-authority", "fs-set-times", "io-extras", - "io-lifetimes 2.0.2", + "io-lifetimes", "ipnet", "maybe-owned", - "rustix 0.38.13", + "rustix", "windows-sys", "winx", ] @@ -571,8 +570,8 @@ checksum = "84bade423fa6403efeebeafe568fdb230e8c590a275fba2ba978dd112efcf6e9" dependencies = [ "cap-primitives", "io-extras", - "io-lifetimes 2.0.2", - "rustix 0.38.13", + "io-lifetimes", + "rustix", ] [[package]] @@ -583,7 +582,7 @@ checksum = "f8f52b3c8f4abfe3252fd0a071f3004aaa3b18936ec97bdbd8763ce03aff6247" dependencies = [ "cap-primitives", "once_cell", - "rustix 0.38.13", + "rustix", "winx", ] @@ -640,9 +639,9 @@ dependencies = [ [[package]] name = "clap" -version = "4.4.3" +version = "4.4.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "84ed82781cea27b43c9b106a979fe450a13a31aab0500595fb3fc06616de08e6" +checksum = "d04704f56c2cde07f43e8e2c154b43f216dc5c92fc98ada720177362f953b956" dependencies = [ "clap_builder", "clap_derive", @@ -650,9 +649,9 @@ dependencies = [ [[package]] name = "clap_builder" -version = "4.4.2" +version = "4.4.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2bb9faaa7c2ef94b2743a21f5a29e6f0010dff4caa69ac8e9d6cf8b6fa74da08" +checksum = "0e231faeaca65ebd1ea3c737966bf858971cd38c3849107aa3ea7de90a804e45" dependencies = [ "anstream", "anstyle", @@ -669,7 +668,7 @@ dependencies = [ "heck 0.4.1", "proc-macro2", "quote", - "syn 2.0.33", + "syn 2.0.37", ] [[package]] @@ -793,7 +792,7 @@ dependencies = [ "cranelift-entity", "cranelift-isle", "gimli", - "hashbrown 0.14.0", + "hashbrown 0.14.1", "log", "regalloc2", "smallvec", @@ -875,7 +874,7 @@ dependencies = [ "itertools", "log", "smallvec", - "wasmparser", + "wasmparser 0.112.0", "wasmtime-types", ] @@ -888,16 +887,6 @@ dependencies = [ "cfg-if", ] -[[package]] -name = "crossbeam-channel" -version = "0.5.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a33c2bf77f2df06183c3aa30d1e96c0695a313d4f9c453cc3762a6db39f99200" -dependencies = [ - "cfg-if", - "crossbeam-utils", -] - [[package]] name = "crossbeam-deque" version = "0.8.3" @@ -998,7 +987,6 @@ checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" dependencies = [ "block-buffer", "crypto-common", - "subtle", ] [[package]] @@ -1147,9 +1135,9 @@ 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" @@ -1158,7 +1146,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0b0377f1edc77dbd1118507bc7a66e4ab64d2b90c66f90726dc801e73a8c68f9" dependencies = [ "cfg-if", - "rustix 0.38.13", + "rustix", "windows-sys", ] @@ -1208,8 +1196,8 @@ version = "0.20.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dd738b84894214045e8414eaded76359b4a5773f0a0a56b16575110739cdcf39" dependencies = [ - "io-lifetimes 2.0.2", - "rustix 0.38.13", + "io-lifetimes", + "rustix", "windows-sys", ] @@ -1327,7 +1315,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6fb8d784f27acf97159b40fc4db5ecd8aa23b9ad5ef69cdd136d3bc80665f0c0" dependencies = [ "fallible-iterator", - "indexmap 2.0.0", + "indexmap 2.0.2", "stable_deref_trait", ] @@ -1388,9 +1376,9 @@ dependencies = [ [[package]] name = "hashbrown" -version = "0.14.0" +version = "0.14.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2c6201b9ff9fd90a5a3bac2e56a830d0caa509576f0e503818ee82c181b3437a" +checksum = "7dfda62a12f55daeae5015f81b0baea145391cb4520f86c248fc615d72640d12" dependencies = [ "ahash", ] @@ -1421,9 +1409,9 @@ dependencies = [ [[package]] name = "hermit-abi" -version = "0.3.2" +version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "443144c8cdadd93ebf52ddb4056d257f5b52c04d3c804e657d19eb73fc33668b" +checksum = "d77f7ec81a6d05a3abb01ab6eb7590f6083d08449fe5a1c8b1e620283546ccb7" [[package]] name = "hex" @@ -1566,12 +1554,12 @@ dependencies = [ [[package]] name = "indexmap" -version = "2.0.0" +version = "2.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d5477fe2230a79769d8dc68e0eabf5437907c0457a5614a9e8dddb67f65eb65d" +checksum = "8adf3ddd720272c6ea8bf59463c04e0f93d0bbf7c5439b691bca2987e0270897" dependencies = [ "equivalent", - "hashbrown 0.14.0", + "hashbrown 0.14.1", "serde", ] @@ -1581,18 +1569,7 @@ version = "0.18.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9d3c230ee517ee76b1cc593b52939ff68deda3fae9e41eca426c6b4993df51c4" dependencies = [ - "io-lifetimes 2.0.2", - "windows-sys", -] - -[[package]] -name = "io-lifetimes" -version = "1.0.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eae7b9aee968036d54dce06cebaefd919e4472e753296daccd6d344e3e2df0c2" -dependencies = [ - "hermit-abi 0.3.2", - "libc", + "io-lifetimes", "windows-sys", ] @@ -1614,8 +1591,8 @@ version = "0.4.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cb0889898416213fab133e1d33a0e5858a48177452750691bde3666d0fdbaf8b" dependencies = [ - "hermit-abi 0.3.2", - "rustix 0.38.13", + "hermit-abi 0.3.3", + "rustix", "windows-sys", ] @@ -1770,12 +1747,6 @@ dependencies = [ "vcpkg", ] -[[package]] -name = "linux-raw-sys" -version = "0.3.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ef53942eb7bf7ff43a617b3e2c1c4a5ecf5944a7c1bc12d7ee39bbb15e5c1519" - [[package]] name = "linux-raw-sys" version = "0.4.7" @@ -1784,13 +1755,12 @@ checksum = "1a9bad9f94746442c783ca431b22403b519cd7fbeed0533fdd6328b2f2212128" [[package]] name = "local-channel" -version = "0.1.3" +version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f303ec0e94c6c54447f84f3b0ef7af769858a9c4ef56ef2a986d3dcd4c3fc9c" +checksum = "e0a493488de5f18c8ffcba89eebb8532ffc562dc400490eb65b84893fae0b178" dependencies = [ "futures-core", "futures-sink", - "futures-util", "local-waker", ] @@ -1839,11 +1809,11 @@ checksum = "8f232d6ef707e1956a43342693d2a31e72989554d58299d7a88738cc95b0d35c" [[package]] name = "memfd" -version = "0.6.3" +version = "0.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ffc89ccdc6e10d6907450f753537ebc5c5d3460d2e4e62ea74bd571db62c0f9e" +checksum = "b2cffa4ad52c6f791f4f8b15f0c05f9824b2ced1160e88cc393d64fff9a8ac64" dependencies = [ - "rustix 0.37.23", + "rustix", ] [[package]] @@ -1945,7 +1915,7 @@ version = "1.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" dependencies = [ - "hermit-abi 0.3.2", + "hermit-abi 0.3.3", "libc", ] @@ -1956,8 +1926,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9cf5f9dd3933bd50a9e1f149ec995f39ae2c496d31fd772c1fd45ebc27e902b0" dependencies = [ "crc32fast", - "hashbrown 0.14.0", - "indexmap 2.0.0", + "hashbrown 0.14.1", + "indexmap 2.0.2", "memchr", ] @@ -1990,7 +1960,7 @@ checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" dependencies = [ "proc-macro2", "quote", - "syn 2.0.33", + "syn 2.0.37", ] [[package]] @@ -2001,9 +1971,9 @@ checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" [[package]] name = "openssl-src" -version = "300.1.3+3.1.2" +version = "300.1.5+3.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cd2c101a165fff9935e34def4669595ab1c7847943c42be86e21503e482be107" +checksum = "559068e4c12950d7dcaa1857a61725c0d38d4fc03ff8e070ab31a75d6e316491" dependencies = [ "cc", ] @@ -2298,9 +2268,9 @@ dependencies = [ [[package]] name = "rayon" -version = "1.7.0" +version = "1.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1d2df5196e37bcc87abebc0053e20787d73847bb33134a69841207dd0a47f03b" +checksum = "9c27db03db7734835b3f53954b534c91069375ce6ccaa2e065441e07d9b6cdb1" dependencies = [ "either", "rayon-core", @@ -2308,14 +2278,12 @@ dependencies = [ [[package]] name = "rayon-core" -version = "1.11.0" +version = "1.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4b8f95bd6966f5c87776639160a66bd8ab9895d9d4ab01ddba9fc60661aebe8d" +checksum = "5ce3fb6ad83f861aac485e76e1985cd109d9a3713802152be56c3b1f0e0658ed" dependencies = [ - "crossbeam-channel", "crossbeam-deque", "crossbeam-utils", - "num_cpus", ] [[package]] @@ -2446,7 +2414,7 @@ dependencies = [ "proc-macro2", "quote", "rust-embed-utils", - "syn 2.0.33", + "syn 2.0.37", "walkdir", ] @@ -2483,29 +2451,15 @@ dependencies = [ [[package]] name = "rustix" -version = "0.37.23" +version = "0.38.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4d69718bf81c6127a49dc64e44a742e8bb9213c0ff8869a22c308f84c1d4ab06" -dependencies = [ - "bitflags 1.3.2", - "errno", - "io-lifetimes 1.0.11", - "libc", - "linux-raw-sys 0.3.8", - "windows-sys", -] - -[[package]] -name = "rustix" -version = "0.38.13" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d7db8590df6dfcd144d22afd1b83b36c21a18d7cbc1dc4bb5295a8712e9eb662" +checksum = "747c788e9ce8e92b12cd485c49ddf90723550b654b32508f979b71a7b1ecda4f" dependencies = [ "bitflags 2.4.0", "errno", "itoa", "libc", - "linux-raw-sys 0.4.7", + "linux-raw-sys", "once_cell", "windows-sys", ] @@ -2571,9 +2525,9 @@ dependencies = [ [[package]] name = "semver" -version = "1.0.18" +version = "1.0.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b0293b4b29daaf487284529cc2f5675b8e57c61f70167ba415a463651fd6a918" +checksum = "ad977052201c6de01a8ef2aa3378c4bd23217a056337d1d6da40468d267a4fb0" [[package]] name = "serde" @@ -2601,7 +2555,7 @@ checksum = "4eca7ac642d82aa35b60049a6eccb4be6be75e599bd2e9adb5f875a737654af2" dependencies = [ "proc-macro2", "quote", - "syn 2.0.33", + "syn 2.0.37", ] [[package]] @@ -2638,9 +2592,9 @@ dependencies = [ [[package]] name = "sha1" -version = "0.10.5" +version = "0.10.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f04293dc80c3993519f2d7f6f511707ee7094fe0c6d3406feb330cdb3540eba3" +checksum = "e3bf829a2d51ab4a5ddf1352d8470c140cadc8301b2ae1789db023f01cedd6ba" dependencies = [ "cfg-if", "cpufeatures", @@ -2649,9 +2603,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", @@ -2712,9 +2666,9 @@ checksum = "826167069c09b99d56f31e9ae5c99049e932a98c9dc2dac47645b08dbbf76ba7" [[package]] name = "smallvec" -version = "1.11.0" +version = "1.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "62bb4feee49fdd9f707ef802e22365a35de4b7b299de4763d44bfea899442ff9" +checksum = "942b4a808e05215192e39f4ab80813e599068285906cc91aa64f923db842bd5a" [[package]] name = "socket2" @@ -2754,12 +2708,6 @@ version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" -[[package]] -name = "subtle" -version = "2.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "81cdd64d312baedb58e21336b31bc043b77e01cc99033ce76ef539f78e965ebc" - [[package]] name = "syn" version = "1.0.109" @@ -2773,9 +2721,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.33" +version = "2.0.37" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9caece70c63bfba29ec2fed841a09851b14a235c60010fa4de58089b6c025668" +checksum = "7303ef2c05cd654186cb250d29049a24840ca25d2747c25c0381c8d9e2f582e8" dependencies = [ "proc-macro2", "quote", @@ -2792,8 +2740,8 @@ dependencies = [ "cap-fs-ext", "cap-std", "fd-lock", - "io-lifetimes 2.0.2", - "rustix 0.38.13", + "io-lifetimes", + "rustix", "windows-sys", "winx", ] @@ -2813,7 +2761,7 @@ dependencies = [ "cfg-if", "fastrand", "redox_syscall 0.3.5", - "rustix 0.38.13", + "rustix", "windows-sys", ] @@ -2830,9 +2778,9 @@ dependencies = [ [[package]] name = "termcolor" -version = "1.2.0" +version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "be55cf8942feac5c765c2c993422806843c9a9a45d4d5c407ad6dd2ea95eb9b6" +checksum = "6093bad37da69aab9d123a8091e4be0aa4a03e4d601ec641c327398315f62b64" dependencies = [ "winapi-util", ] @@ -2845,29 +2793,29 @@ checksum = "222a222a5bfe1bba4a77b45ec488a741b3cb8872e5e499451fd7d0129c9c7c3d" [[package]] name = "thiserror" -version = "1.0.48" +version = "1.0.49" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9d6d7a740b8a666a7e828dd00da9c0dc290dff53154ea77ac109281de90589b7" +checksum = "1177e8c6d7ede7afde3585fd2513e611227efd6481bd78d2e82ba1ce16557ed4" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.48" +version = "1.0.49" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49922ecae66cc8a249b77e68d1d0623c1b2c514f0060c27cdc68bd62a1219d35" +checksum = "10712f02019e9288794769fba95cd6847df9874d49d871d062172f9dd41bc4cc" dependencies = [ "proc-macro2", "quote", - "syn 2.0.33", + "syn 2.0.37", ] [[package]] name = "time" -version = "0.3.28" +version = "0.3.29" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "17f6bb557fd245c28e6411aa56b6403c689ad95061f50e4be16c274e70a17e48" +checksum = "426f806f4089c493dcac0d24c29c01e2c38baf8e30f1b716ee37e83d200b18fe" dependencies = [ "deranged", "itoa", @@ -2878,15 +2826,15 @@ dependencies = [ [[package]] name = "time-core" -version = "0.1.1" +version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7300fbefb4dadc1af235a9cef3737cea692a9d97e1b9cbcd4ebdae6f8868e6fb" +checksum = "ef927ca75afb808a4d64dd374f00a2adf8d0fcff8e7b184af886c3c87ec4a3f3" [[package]] name = "time-macros" -version = "0.2.14" +version = "0.2.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1a942f44339478ef67935ab2bbaec2fb0322496cf3cbe84b261e06ac3814c572" +checksum = "4ad70d68dba9e1f8aceda7aa6711965dfec1cac869f311a51bd08b3a2ccbce20" dependencies = [ "time-core", ] @@ -2936,9 +2884,9 @@ dependencies = [ [[package]] name = "tokio-util" -version = "0.7.8" +version = "0.7.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "806fe8c2c87eccc8b3267cbae29ed3ab2d0bd37fca70ab622e46aaa9375ddb7d" +checksum = "1d68074620f57a0b21594d9735eb2e98ab38b17f80d3fcb189fca266771ca60d" dependencies = [ "bytes", "futures-core", @@ -2984,7 +2932,7 @@ version = "0.19.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1b5bb770da30e5cbfde35a2d7b9b8a2c4b8ef89548a7a6aeab5c9a576e3e7421" dependencies = [ - "indexmap 2.0.0", + "indexmap 2.0.2", "serde", "serde_spanned", "toml_datetime", @@ -3018,7 +2966,7 @@ checksum = "5f4f31f56159e98206da9efd823404b79b6ef3143b4a7ab76e67b1751b25a4ab" dependencies = [ "proc-macro2", "quote", - "syn 2.0.33", + "syn 2.0.37", ] [[package]] @@ -3080,9 +3028,9 @@ checksum = "1dd624098567895118886609431a7c3b8f516e41d30e0643f03d94592a147e36" [[package]] name = "unicode-width" -version = "0.1.10" +version = "0.1.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c0edd1e5b14653f783770bce4a4dabb4a5108a5370a5f5d8cfe8710c361f6c8b" +checksum = "e51733f11c9c4f72aa0c160008246859e340b00807569a0da0e7a1079b27ba85" [[package]] name = "unicode-xid" @@ -3113,7 +3061,7 @@ version = "3.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d82b1bc5417102a73e8464c686eef947bdfb99fcdfc0a4f228e81afa9526470a" dependencies = [ - "indexmap 2.0.0", + "indexmap 2.0.2", "serde", "serde_json", "utoipa-gen", @@ -3129,7 +3077,7 @@ dependencies = [ "proc-macro2", "quote", "regex", - "syn 2.0.33", + "syn 2.0.37", ] [[package]] @@ -3189,10 +3137,10 @@ dependencies = [ "cap-time-ext", "fs-set-times", "io-extras", - "io-lifetimes 2.0.2", + "io-lifetimes", "is-terminal", "once_cell", - "rustix 0.38.13", + "rustix", "system-interface", "tracing", "wasi-common", @@ -3211,7 +3159,7 @@ dependencies = [ "cap-std", "io-extras", "log", - "rustix 0.38.13", + "rustix", "thiserror", "tracing", "wasmtime", @@ -3240,7 +3188,7 @@ dependencies = [ "once_cell", "proc-macro2", "quote", - "syn 2.0.33", + "syn 2.0.37", "wasm-bindgen-shared", ] @@ -3274,7 +3222,7 @@ checksum = "54681b18a46765f095758388f2d0cf16eb8d4169b639ab575a8f5693af210c7b" dependencies = [ "proc-macro2", "quote", - "syn 2.0.33", + "syn 2.0.37", "wasm-bindgen-backend", "wasm-bindgen-shared", ] @@ -3294,6 +3242,15 @@ dependencies = [ "leb128", ] +[[package]] +name = "wasm-encoder" +version = "0.33.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34180c89672b3e4825c3a8db4b61a674f1447afd5fe2445b2d22c3d8b6ea086c" +dependencies = [ + "leb128", +] + [[package]] name = "wasm-workers-quick-js-engine" version = "0.1.0" @@ -3322,7 +3279,7 @@ version = "1.5.0" dependencies = [ "actix-web", "anyhow", - "clap 4.4.3", + "clap 4.4.6", "env_logger 0.10.0", "prettytable-rs", "reqwest", @@ -3338,18 +3295,28 @@ version = "0.112.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e986b010f47fcce49cf8ea5d5f9e5d2737832f12b53ae8ae785bbe895d0877bf" dependencies = [ - "indexmap 2.0.0", + "indexmap 2.0.2", + "semver", +] + +[[package]] +name = "wasmparser" +version = "0.113.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fd0d44fab0bd78404e352f3399324eef76516a4580b52bc9031c60f064e98f3" +dependencies = [ + "indexmap 2.0.2", "semver", ] [[package]] name = "wasmprinter" -version = "0.2.64" +version = "0.2.67" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "34ddf5892036cd4b780d505eff1194a0cbc10ed896097656fdcea3744b5e7c2f" +checksum = "f6615a5587149e753bf4b93f90fa3c3f41c88597a7a2da72879afcabeda9648f" dependencies = [ "anyhow", - "wasmparser", + "wasmparser 0.113.2", ] [[package]] @@ -3365,7 +3332,7 @@ dependencies = [ "cfg-if", "encoding_rs", "fxprof-processed-profile", - "indexmap 2.0.0", + "indexmap 2.0.2", "libc", "log", "object", @@ -3377,8 +3344,8 @@ dependencies = [ "serde_derive", "serde_json", "target-lexicon", - "wasm-encoder", - "wasmparser", + "wasm-encoder 0.32.0", + "wasmparser 0.112.0", "wasmtime-cache", "wasmtime-component-macro", "wasmtime-component-util", @@ -3412,7 +3379,7 @@ dependencies = [ "bincode", "directories-next", "log", - "rustix 0.38.13", + "rustix", "serde", "serde_derive", "sha2", @@ -3430,10 +3397,10 @@ dependencies = [ "anyhow", "proc-macro2", "quote", - "syn 2.0.33", + "syn 2.0.37", "wasmtime-component-util", "wasmtime-wit-bindgen", - "wit-parser 0.11.1", + "wit-parser 0.11.3", ] [[package]] @@ -3461,7 +3428,7 @@ dependencies = [ "object", "target-lexicon", "thiserror", - "wasmparser", + "wasmparser 0.112.0", "wasmtime-cranelift-shared", "wasmtime-environ", "wasmtime-versioned-export-macros", @@ -3492,15 +3459,15 @@ dependencies = [ "anyhow", "cranelift-entity", "gimli", - "indexmap 2.0.0", + "indexmap 2.0.2", "log", "object", "serde", "serde_derive", "target-lexicon", "thiserror", - "wasm-encoder", - "wasmparser", + "wasm-encoder 0.32.0", + "wasmparser 0.112.0", "wasmprinter", "wasmtime-component-util", "wasmtime-types", @@ -3514,7 +3481,7 @@ checksum = "2ef118b557df6193cd82cfb45ab57cd12388fedfe2bb76f090b2d77c96c1b56e" dependencies = [ "cc", "cfg-if", - "rustix 0.38.13", + "rustix", "wasmtime-asm-macros", "wasmtime-versioned-export-macros", "windows-sys", @@ -3536,7 +3503,7 @@ dependencies = [ "log", "object", "rustc-demangle", - "rustix 0.38.13", + "rustix", "serde", "serde_derive", "target-lexicon", @@ -3555,7 +3522,7 @@ checksum = "9b13924aedf6799ad66edb25500a20e3226629978b30a958c55285352bad130a" dependencies = [ "object", "once_cell", - "rustix 0.38.13", + "rustix", "wasmtime-versioned-export-macros", ] @@ -3580,7 +3547,7 @@ dependencies = [ "cc", "cfg-if", "encoding_rs", - "indexmap 2.0.0", + "indexmap 2.0.2", "libc", "log", "mach", @@ -3588,9 +3555,9 @@ dependencies = [ "memoffset", "paste", "rand", - "rustix 0.38.13", + "rustix", "sptr", - "wasm-encoder", + "wasm-encoder 0.32.0", "wasmtime-asm-macros", "wasmtime-environ", "wasmtime-fiber", @@ -3610,7 +3577,7 @@ dependencies = [ "serde", "serde_derive", "thiserror", - "wasmparser", + "wasmparser 0.112.0", ] [[package]] @@ -3621,7 +3588,7 @@ checksum = "fe877472cbdd6d96b4ecdc112af764e3b9d58c2e4175a87828f892ab94c60643" dependencies = [ "proc-macro2", "quote", - "syn 2.0.33", + "syn 2.0.37", ] [[package]] @@ -3642,11 +3609,11 @@ dependencies = [ "fs-set-times", "futures", "io-extras", - "io-lifetimes 2.0.2", + "io-lifetimes", "is-terminal", "libc", "once_cell", - "rustix 0.38.13", + "rustix", "system-interface", "thiserror", "tokio", @@ -3684,7 +3651,7 @@ dependencies = [ "gimli", "object", "target-lexicon", - "wasmparser", + "wasmparser 0.112.0", "wasmtime-cranelift-shared", "wasmtime-environ", "winch-codegen", @@ -3698,8 +3665,8 @@ checksum = "62003d48822f89cc393e93643366ddbee1766779c0874353b8ba2ede4679fbf9" dependencies = [ "anyhow", "heck 0.4.1", - "indexmap 2.0.0", - "wit-parser 0.11.1", + "indexmap 2.0.2", + "wit-parser 0.11.3", ] [[package]] @@ -3719,23 +3686,23 @@ dependencies = [ [[package]] name = "wast" -version = "64.0.0" +version = "65.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a259b226fd6910225aa7baeba82f9d9933b6d00f2ce1b49b80fa4214328237cc" +checksum = "a55a88724cf8c2c0ebbf32c8e8f4ac0d6aa7ba6d73a1cfd94b254aa8f894317e" dependencies = [ "leb128", "memchr", "unicode-width", - "wasm-encoder", + "wasm-encoder 0.33.2", ] [[package]] name = "wat" -version = "1.0.71" +version = "1.0.74" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "53253d920ab413fca1c7dc2161d601c79b4fdf631d0ba51dd4343bf9b556c3f6" +checksum = "d83e1a8d86d008adc7bafa5cf4332d448699a08fcf2a715a71fbb75e2c5ca188" dependencies = [ - "wast 64.0.0", + "wast 65.0.2", ] [[package]] @@ -3772,7 +3739,7 @@ dependencies = [ "either", "home", "once_cell", - "rustix 0.38.13", + "rustix", ] [[package]] @@ -3801,7 +3768,7 @@ dependencies = [ "proc-macro2", "quote", "shellexpand", - "syn 2.0.33", + "syn 2.0.37", "witx", ] @@ -3813,7 +3780,7 @@ checksum = "7d72d838b7c9302b2ca7c44f36d6af5ce1988239a16deba951d99c4630d17caf" dependencies = [ "proc-macro2", "quote", - "syn 2.0.33", + "syn 2.0.37", "wiggle-generate", ] @@ -3835,9 +3802,9 @@ checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" [[package]] name = "winapi-util" -version = "0.1.5" +version = "0.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178" +checksum = "f29e6f9198ba0d26b4c9f07dbe6f9ed633e1f3d5b8b414090084349e46a52596" dependencies = [ "winapi", ] @@ -3860,7 +3827,7 @@ dependencies = [ "regalloc2", "smallvec", "target-lexicon", - "wasmparser", + "wasmparser 0.112.0", "wasmtime-environ", ] @@ -4085,13 +4052,13 @@ dependencies = [ [[package]] name = "wit-parser" -version = "0.11.1" +version = "0.11.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1dcd022610436a1873e60bfdd9b407763f2404adf7d1cb57912c7ae4059e57a5" +checksum = "a39edca9abb16309def3843af73b58d47d243fe33a9ceee572446bcc57556b9a" dependencies = [ "anyhow", "id-arena", - "indexmap 2.0.0", + "indexmap 2.0.2", "log", "pulldown-cmark 0.9.3", "semver", @@ -4249,6 +4216,7 @@ dependencies = [ "tokio", "toml 0.7.8", "wasi-common", + "wasmparser 0.113.2", "wasmtime", "wasmtime-wasi", "wasmtime-wasi-nn", diff --git a/Cargo.toml b/Cargo.toml index 8eafd175..b8a8f52d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -64,11 +64,11 @@ members = [ ] # Exclude examples exclude = [ - "examples/pdf-create", "examples/rust-basic", "examples/rust-fetch", "examples/rust-kv", "examples/rust-params", + "examples/rust-pdf-create", "examples/rust-wasi-nn", "examples/rust-wasi-nn-preload", ] @@ -81,6 +81,7 @@ serde = { version = "1.0", features = ["derive"] } serde_json = "1.0.85" tokio = "1.28" toml = "0.7.0" +wasmparser = "0.113.2" wws-config = { path = "./crates/config" } wws-runtimes = { path = "./crates/runtimes" } wws-data-kv = { path = "./crates/data-kv" } diff --git a/crates/api-manage/src/handlers/v0/workers.rs b/crates/api-manage/src/handlers/v0/workers.rs index ed247ca1..5cdaca7c 100644 --- a/crates/api-manage/src/handlers/v0/workers.rs +++ b/crates/api-manage/src/handlers/v0/workers.rs @@ -44,7 +44,7 @@ pub async fn handle_api_worker(routes: Data, path: Path) -> Http .map(|r| workers.get(&r.worker).expect("unexpected missing worker")); if let Some(worker) = worker { - HttpResponse::Ok().json(WorkerConfig::from(worker)) + HttpResponse::Ok().json(WorkerConfig::from(worker.as_ref())) } else { HttpResponse::NotFound().json("{}") } diff --git a/crates/router/src/route.rs b/crates/router/src/route.rs index 55724621..f4230b70 100644 --- a/crates/router/src/route.rs +++ b/crates/router/src/route.rs @@ -16,7 +16,7 @@ use std::{ collections::HashMap, ffi::OsStr, path::{Component, Path, PathBuf}, - sync::RwLock, + sync::{Arc, RwLock}, }; use wws_config::Config as ProjectConfig; use wws_worker::Worker; @@ -60,16 +60,16 @@ pub struct Route { /// other crates. #[derive(Default)] pub struct WorkerSet { - workers: HashMap, + workers: HashMap>, } impl WorkerSet { - pub fn get(&self, worker_id: &str) -> Option<&Worker> { + pub fn get(&self, worker_id: &str) -> Option<&Arc> { self.workers.get(worker_id) } pub fn register(&mut self, worker_id: String, worker: Worker) { - self.workers.insert(worker_id, worker); + self.workers.insert(worker_id, Arc::new(worker)); } } diff --git a/crates/runtimes/src/lib.rs b/crates/runtimes/src/lib.rs index 687bb4c1..967ea156 100644 --- a/crates/runtimes/src/lib.rs +++ b/crates/runtimes/src/lib.rs @@ -6,6 +6,7 @@ use errors::Result; mod modules; mod runtime; +pub use runtime::CtxBuilder; use modules::{external::ExternalRuntime, javascript::JavaScriptRuntime, native::NativeRuntime}; use std::path::Path; diff --git a/crates/runtimes/src/modules/external.rs b/crates/runtimes/src/modules/external.rs index a41f85ef..19bdbf2c 100644 --- a/crates/runtimes/src/modules/external.rs +++ b/crates/runtimes/src/modules/external.rs @@ -3,12 +3,12 @@ use crate::errors::{self, Result}; -use crate::runtime::Runtime; +use crate::runtime::{CtxBuilder, Runtime}; use std::{ fs, path::{Path, PathBuf}, }; -use wasmtime_wasi::{ambient_authority, Dir, WasiCtxBuilder}; +use wasmtime_wasi::{ambient_authority, preview2, Dir}; use wws_project::metadata::Runtime as RuntimeMetadata; use wws_store::Store; @@ -90,14 +90,28 @@ impl Runtime for ExternalRuntime { /// Mount the source code in the WASI context so it can be /// processed by the engine - fn prepare_wasi_ctx(&self, builder: &mut WasiCtxBuilder) -> Result<()> { - builder - .preopened_dir( - Dir::open_ambient_dir(&self.store.folder, ambient_authority())?, - "/src", - )? - .args(&self.metadata.args) - .map_err(|_| errors::RuntimeError::WasiContextError)?; + fn prepare_wasi_ctx(&self, builder: &mut CtxBuilder) -> Result<()> { + match builder { + CtxBuilder::Preview1(ref mut builder) => { + builder + .preopened_dir( + Dir::open_ambient_dir(&self.store.folder, ambient_authority())?, + "/src", + )? + .args(&self.metadata.args) + .map_err(|_| errors::RuntimeError::WasiContextError)?; + } + CtxBuilder::Preview2(ref mut builder) => { + builder + .preopened_dir( + Dir::open_ambient_dir(&self.store.folder, ambient_authority())?, + preview2::DirPerms::all(), + preview2::FilePerms::all(), + "/src", + ) + .args(&self.metadata.args); + } + } Ok(()) } diff --git a/crates/runtimes/src/modules/javascript.rs b/crates/runtimes/src/modules/javascript.rs index 9c45895d..adec59ca 100644 --- a/crates/runtimes/src/modules/javascript.rs +++ b/crates/runtimes/src/modules/javascript.rs @@ -2,10 +2,10 @@ // SPDX-License-Identifier: Apache-2.0 use crate::errors::Result; -use crate::runtime::Runtime; +use crate::runtime::{CtxBuilder, Runtime}; use std::path::{Path, PathBuf}; -use wasmtime_wasi::{ambient_authority, Dir, WasiCtxBuilder}; +use wasmtime_wasi::{ambient_authority, preview2, Dir}; use wws_store::Store; static JS_ENGINE_WASM: &[u8] = @@ -46,11 +46,23 @@ impl Runtime for JavaScriptRuntime { /// Mount the source code in the WASI context so it can be /// processed by the engine - fn prepare_wasi_ctx(&self, builder: &mut WasiCtxBuilder) -> Result<()> { - builder.preopened_dir( - Dir::open_ambient_dir(&self.store.folder, ambient_authority())?, - "/src", - )?; + fn prepare_wasi_ctx(&self, builder: &mut CtxBuilder) -> Result<()> { + match builder { + CtxBuilder::Preview1(ref mut builder) => { + builder.preopened_dir( + Dir::open_ambient_dir(&self.store.folder, ambient_authority())?, + "/src", + )?; + } + CtxBuilder::Preview2(ref mut builder) => { + builder.preopened_dir( + Dir::open_ambient_dir(&self.store.folder, ambient_authority())?, + preview2::DirPerms::all(), + preview2::FilePerms::all(), + "/src", + ); + } + } Ok(()) } diff --git a/crates/runtimes/src/runtime.rs b/crates/runtimes/src/runtime.rs index f621f1a2..2988a3c3 100644 --- a/crates/runtimes/src/runtime.rs +++ b/crates/runtimes/src/runtime.rs @@ -3,7 +3,12 @@ use crate::errors::Result; -use wasmtime_wasi::WasiCtxBuilder; +use wasmtime_wasi::{preview2, WasiCtxBuilder}; + +pub enum CtxBuilder { + Preview1(WasiCtxBuilder), + Preview2(preview2::WasiCtxBuilder), +} /// Define the behavior a Runtime must have. This includes methods /// to initialize the environment for the given runtime as well as @@ -21,7 +26,7 @@ pub trait Runtime { /// WASI context builder. This allow runtimes to mount /// specific lib folders, source code and adding /// environment variables. - fn prepare_wasi_ctx(&self, _builder: &mut WasiCtxBuilder) -> Result<()> { + fn prepare_wasi_ctx(&self, _builder: &mut CtxBuilder) -> Result<()> { Ok(()) } diff --git a/crates/server/src/handlers/worker.rs b/crates/server/src/handlers/worker.rs index daadd1de..b54481a7 100644 --- a/crates/server/src/handlers/worker.rs +++ b/crates/server/src/handlers/worker.rs @@ -38,11 +38,10 @@ pub async fn handle_worker(req: HttpRequest, body: Bytes) -> HttpResponse { let data_connectors = req .app_data::>>() .expect("error fetching data connectors"); - let result: HttpResponse; // First, we need to identify the best suited route let selected_route = app_data.routes.retrieve_best_route(req.path()); - if let Some(route) = selected_route { + let worker = if let Some(route) = selected_route { // First, check if there's an existing static file. Static assets have more priority // than dynamic routes. However, I cannot set the static assets as the first service // as it's captures everything. @@ -56,74 +55,83 @@ pub async fn handle_worker(req: HttpRequest, body: Bytes) -> HttpResponse { .read() .expect("error locking worker lock for reading"); - let worker = workers - .get(&route.worker) - .expect("unexpected missing worker"); + Some( + workers + .get(&route.worker) + .expect("unexpected missing worker") + .clone(), + ) + } else { + None + }; - // Let's continue - let body_str = String::from_utf8(body.to_vec()).unwrap_or_else(|_| String::from("")); + if worker.is_none() { + return handle_not_found(&req).await; + }; + let worker = worker.unwrap(); - // Init from configuration - let vars = &worker.config.vars; - let kv_namespace = worker.config.data_kv_namespace(); + let body_str = String::from_utf8(body.to_vec()).unwrap_or_else(|_| String::from("")); - let store = match &kv_namespace { - Some(namespace) => { - let connector = data_connectors - .read() - .expect("error locking data connectors lock for reading"); - let kv_store = connector.kv.find_store(namespace); + // Init from configuration + let vars = &worker.config.vars; + let kv_namespace = worker.config.data_kv_namespace(); - kv_store.map(|store| store.clone()) - } - None => None, - }; - - let (handler_result, handler_success) = match worker.run(&req, &body_str, store, vars) { - Ok(output) => (output, true), - Err(_) => (WasmOutput::failed(), false), - }; - - let mut builder = HttpResponse::build( - StatusCode::from_u16(handler_result.status).unwrap_or(StatusCode::OK), - ); - // Default content type - builder.insert_header(("Content-Type", "text/html")); - - // Check if cors config has any origins to register - if let Some(origins) = app_data.cors_origins.as_ref() { - // Check if worker has overridden the header, if not - if !handler_result.headers.contains_key(CORS_HEADER) { - // insert those origins in 'Access-Control-Allow-Origin' header - let header_value = origins.join(","); - builder.insert_header((CORS_HEADER, header_value)); - } - } + let store = match &kv_namespace { + Some(namespace) => { + let connector = data_connectors + .read() + .expect("error locking data connectors lock for reading"); + let kv_store = connector.kv.find_store(namespace); - for (key, val) in handler_result.headers.iter() { - // Note that QuickJS is replacing the "-" character - // with "_" on property keys. Here, we rollback it - builder.insert_header((key.replace('_', "-").as_str(), val.as_str())); + kv_store.map(|store| store.clone()) } - - // Write to the state if required - if handler_success && kv_namespace.is_some() { - data_connectors - .write() - .expect("error locking data connectors lock for writing") - .kv - .replace_store(&kv_namespace.unwrap(), &handler_result.kv) + None => None, + }; + + let (handler_result, handler_success) = match worker.run(&req, &body_str, store, vars).await { + Ok(output) => (output, true), + Err(err) => ( + WasmOutput::failed( + err, + worker.config.name.clone(), + selected_route.map(|route| route.path.clone()), + ), + false, + ), + }; + + let mut builder = + HttpResponse::build(StatusCode::from_u16(handler_result.status).unwrap_or(StatusCode::OK)); + // Default content type + builder.insert_header(("Content-Type", "text/html")); + + // Check if cors config has any origins to register + if let Some(origins) = app_data.cors_origins.as_ref() { + // Check if worker has overridden the header, if not + if !handler_result.headers.contains_key(CORS_HEADER) { + // insert those origins in 'Access-Control-Allow-Origin' header + let header_value = origins.join(","); + builder.insert_header((CORS_HEADER, header_value)); } + } - result = match handler_result.body() { - Ok(res) => builder.body(res), - Err(_) => { - HttpResponse::ServiceUnavailable().body("There was an error running the worker") - } - } - } else { - result = handle_not_found(&req).await; + for (key, val) in handler_result.headers.iter() { + // Note that QuickJS is replacing the "-" character + // with "_" on property keys. Here, we rollback it + builder.insert_header((key.replace('_', "-").as_str(), val.as_str())); } - result + // Write to the state if required + if handler_success && kv_namespace.is_some() { + data_connectors + .write() + .expect("error locking data connectors lock for writing") + .kv + .replace_store(&kv_namespace.unwrap(), &handler_result.kv) + } + + match handler_result.body() { + Ok(res) => builder.body(res), + Err(_) => HttpResponse::ServiceUnavailable().body("There was an error running the worker"), + } } diff --git a/crates/server/src/lib.rs b/crates/server/src/lib.rs index a09fd16f..39b8a9cb 100644 --- a/crates/server/src/lib.rs +++ b/crates/server/src/lib.rs @@ -129,27 +129,30 @@ pub async fn serve(serve_options: ServeOptions) -> Result { static_prefix = String::from("/"); } - app = app.service( - Files::new(&static_prefix, app_data.root_path.join("public")) - .index_file("index.html") - // This handler check if there's an HTML file in the public folder that - // can reply to the given request. For example, if someone request /about, - // this handler will look for a /public/about.html file. - .default_handler(fn_service(|req: ServiceRequest| async { - let (req, _) = req.into_parts(); - - match handle_assets(&req).await { - Ok(existing_file) => { - let res = existing_file.into_response(&req); - Ok(ServiceResponse::new(req, res)) + let public_dir = app_data.root_path.join("public"); + if public_dir.exists() { + app = app.service( + Files::new(&static_prefix, public_dir) + .index_file("index.html") + // This handler check if there's an HTML file in the public folder that + // can reply to the given request. For example, if someone request /about, + // this handler will look for a /public/about.html file. + .default_handler(fn_service(|req: ServiceRequest| async { + let (req, _) = req.into_parts(); + + match handle_assets(&req).await { + Ok(existing_file) => { + let res = existing_file.into_response(&req); + Ok(ServiceResponse::new(req, res)) + } + Err(_) => { + let res = handle_not_found(&req).await; + Ok(ServiceResponse::new(req, res)) + } } - Err(_) => { - let res = handle_not_found(&req).await; - Ok(ServiceResponse::new(req, res)) - } - } - })), - ); + })), + ); + } app }) diff --git a/crates/worker/Cargo.toml b/crates/worker/Cargo.toml index 6bade552..23aec7b4 100644 --- a/crates/worker/Cargo.toml +++ b/crates/worker/Cargo.toml @@ -16,6 +16,7 @@ serde = { workspace = true } serde_json = { workspace = true } tokio = { workspace = true } toml = { workspace = true } +wasmparser = { workspace = true } wasmtime = { workspace = true } wasmtime-wasi = { workspace = true } wasmtime-wasi-nn = { workspace = true } diff --git a/crates/worker/src/errors.rs b/crates/worker/src/errors.rs index 8c386790..7a8a89d2 100644 --- a/crates/worker/src/errors.rs +++ b/crates/worker/src/errors.rs @@ -7,13 +7,21 @@ pub type Result = std::result::Result; #[derive(Debug)] pub enum WorkerError { - BadWasmModule, + BadWasmCoreModule { + error: String, + }, + BadWasmComponent { + error: String, + }, + BadWasmCoreModuleOrComponent, CannotLoadConfig, CannotParseConfig { path: PathBuf, error: toml::de::Error, }, - ConfigureRuntimeError, + ConfigureRuntimeError { + error: String, + }, DeserializeConfigError, FailedToInitialize, RuntimeError(wws_runtimes::errors::RuntimeError), @@ -35,14 +43,22 @@ impl From for WorkerError { impl std::fmt::Display for WorkerError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { match self { - WorkerError::BadWasmModule => write!(f, "Bad Wasm module"), + WorkerError::BadWasmCoreModule { error } => { + write!(f, "Bad Wasm core module: {}", error) + } + WorkerError::BadWasmComponent { error } => write!(f, "Bad Wasm component: {}", error), + WorkerError::BadWasmCoreModuleOrComponent => { + write!(f, "Bad Wasm core module or component") + } WorkerError::CannotLoadConfig => write!(f, "Could not load configuration"), WorkerError::CannotParseConfig { path, error } => write!( f, "Could not parse configuration at {:?}: {:?}", path, error ), - WorkerError::ConfigureRuntimeError => write!(f, "Error configuring runtime"), + WorkerError::ConfigureRuntimeError { error } => { + write!(f, "Error configuring runtime: {error}") + } WorkerError::DeserializeConfigError => write!(f, "Error deserializing configuration"), WorkerError::FailedToInitialize => write!(f, "Failed to initialize"), WorkerError::RuntimeError(error) => { diff --git a/crates/worker/src/io.rs b/crates/worker/src/io.rs index 8a297414..d63bc74d 100644 --- a/crates/worker/src/io.rs +++ b/crates/worker/src/io.rs @@ -1,7 +1,7 @@ // Copyright 2022 VMware, Inc. // SPDX-License-Identifier: Apache-2.0 -use crate::errors::{self, Result}; +use crate::errors::{self, Result, WorkerError}; use actix_web::{ http::{header::HeaderMap, StatusCode}, @@ -112,13 +112,17 @@ impl WasmOutput { } /// Build a default WasmOutput for a failed run. It will - /// return a generic error message and the proper 503 + /// return a generic error message and the proper 500 /// status code - pub fn failed() -> Self { + pub fn failed(err: WorkerError, worker_name: Option, route: Option) -> Self { + eprintln!( + "Error running worker {:?} at route {:?}: {err}", + worker_name, route + ); Self::new( "

There was an error running this function

", HashMap::from([("content-type".to_string(), "text/html".to_string())]), - StatusCode::SERVICE_UNAVAILABLE.as_u16(), + StatusCode::INTERNAL_SERVER_ERROR.as_u16(), HashMap::new(), ) } diff --git a/crates/worker/src/lib.rs b/crates/worker/src/lib.rs index 3ff88cf6..7a4f880d 100644 --- a/crates/worker/src/lib.rs +++ b/crates/worker/src/lib.rs @@ -19,12 +19,19 @@ use std::path::PathBuf; use std::sync::Arc; use std::{collections::HashMap, path::Path}; use stdio::Stdio; -use wasi_common::WasiCtx; -use wasmtime::{Engine, Linker, Module, Store}; -use wasmtime_wasi::{ambient_authority, Dir, WasiCtxBuilder}; +use wasmtime::{ + component::{self, Component}, + Config as WasmtimeConfig, Engine, Linker, Module, Store, +}; +use wasmtime_wasi::{ambient_authority, preview2, Dir, WasiCtxBuilder}; use wasmtime_wasi_nn::{InMemoryRegistry, Registry, WasiNnCtx}; use wws_config::Config as ProjectConfig; -use wws_runtimes::{init_runtime, Runtime}; +use wws_runtimes::{init_runtime, CtxBuilder, Runtime}; + +pub enum ModuleOrComponent { + Module(Module), + Component(Component), +} /// A worker contains the engine and the associated runtime. /// This struct will process requests by preparing the environment @@ -34,20 +41,63 @@ pub struct Worker { pub id: String, /// Wasmtime engine to run this worker engine: Engine, - /// Wasm Module - module: Module, /// Worker runtime runtime: Box, + /// Wasm Module or component + module_or_component: ModuleOrComponent, /// Current config pub config: Config, /// The worker filepath path: PathBuf, } -struct WorkerState { - pub wasi: WasiCtx, +#[derive(Default)] +struct Host { + pub wasi_preview1_ctx: Option, + pub wasi_preview2_ctx: Option>, + + // Resource table for preview2 if the `preview2_ctx` is in use, otherwise + // "just" an empty table. + wasi_preview2_table: Arc, + + // State necessary for the preview1 implementation of WASI backed by the + // preview2 host implementation. Only used with the `--preview2` flag right + // now when running core modules. + wasi_preview2_adapter: Arc, + pub wasi_nn: Option>, - pub http: HttpBindings, + pub http: Option, +} + +impl preview2::WasiView for Host { + fn table(&self) -> &preview2::Table { + &self.wasi_preview2_table + } + + fn table_mut(&mut self) -> &mut preview2::Table { + Arc::get_mut(&mut self.wasi_preview2_table) + .expect("preview2 is not compatible with threads") + } + + fn ctx(&self) -> &preview2::WasiCtx { + self.wasi_preview2_ctx.as_ref().unwrap() + } + + fn ctx_mut(&mut self) -> &mut preview2::WasiCtx { + let ctx = self.wasi_preview2_ctx.as_mut().unwrap(); + Arc::get_mut(ctx).expect("preview2 is not compatible with threads") + } +} + +impl preview2::preview1::WasiPreview1View for Host { + fn adapter(&self) -> &preview2::preview1::WasiPreview1Adapter { + &self.wasi_preview2_adapter + } + + fn adapter_mut(&mut self) -> &mut preview2::preview1::WasiPreview1Adapter { + Arc::get_mut(&mut self.wasi_preview2_adapter) + .expect("preview2 is not compatible with threads") + } } impl Worker { @@ -70,11 +120,36 @@ impl Worker { } } - let engine = Engine::default(); + let engine = Engine::new( + WasmtimeConfig::default() + .async_support(true) + .wasm_component_model(true), + ) + .map_err(|err| errors::WorkerError::ConfigureRuntimeError { + error: format!("error creating engine ({err})"), + })?; let runtime = init_runtime(project_root, path, project_config)?; let bytes = runtime.module_bytes()?; - let module = - Module::from_binary(&engine, &bytes).map_err(|_| errors::WorkerError::BadWasmModule)?; + + let module_or_component = if wasmparser::Parser::is_core_wasm(&bytes) { + Ok(ModuleOrComponent::Module( + Module::from_binary(&engine, &bytes).map_err(|err| { + errors::WorkerError::BadWasmCoreModule { + error: format!("{:?}", err), + } + })?, + )) + } else if wasmparser::Parser::is_component(&bytes) { + Ok(ModuleOrComponent::Component( + Component::from_binary(&engine, &bytes).map_err(|err| { + errors::WorkerError::BadWasmComponent { + error: format!("{:?}", err), + } + })?, + )) + } else { + Err(errors::WorkerError::BadWasmCoreModuleOrComponent) + }?; // Prepare the environment if required runtime.prepare()?; @@ -82,14 +157,86 @@ impl Worker { Ok(Self { id, engine, - module, runtime, + module_or_component, config, path: path.to_path_buf(), }) } - pub fn run( + pub fn prepare_wasi_context( + &self, + environment_variables: &[(String, String)], + wasi_builder: &mut CtxBuilder, + ) -> Result<()> { + match wasi_builder { + CtxBuilder::Preview1(wasi_builder) => { + // Set up environment variables + wasi_builder.envs(environment_variables).map_err(|error| { + errors::WorkerError::ConfigureRuntimeError { + error: format!("error configuring runtime: {error}"), + } + })?; + + // Setup pre-opens + if let Some(folders) = self.config.folders.as_ref() { + for folder in folders { + if let Some(base) = &self.path.parent() { + let dir = + Dir::open_ambient_dir(base.join(&folder.from), ambient_authority()) + .map_err(|error| { + errors::WorkerError::ConfigureRuntimeError { + error: format!( + "error setting up pre-opened folders: {error}" + ), + } + })?; + wasi_builder + .preopened_dir(dir, &folder.to) + .map_err(|error| errors::WorkerError::ConfigureRuntimeError { + error: format!("error setting up pre-opened folders: {error}"), + })?; + } else { + return Err(errors::WorkerError::FailedToInitialize); + } + } + } + } + CtxBuilder::Preview2(wasi_builder) => { + // Set up environment variables + wasi_builder.envs(environment_variables); + + // Setup pre-opens + if let Some(folders) = self.config.folders.as_ref() { + for folder in folders { + if let Some(base) = &self.path.parent() { + let dir = + Dir::open_ambient_dir(base.join(&folder.from), ambient_authority()) + .map_err(|error| { + errors::WorkerError::ConfigureRuntimeError { + error: format!( + "error setting up pre-opened folders: {error}" + ), + } + })?; + wasi_builder.preopened_dir( + dir, + preview2::DirPerms::all(), + preview2::FilePerms::all(), + &folder.to, + ); + } else { + return Err(errors::WorkerError::FailedToInitialize); + } + } + } + } + } + + Ok(()) + } + + pub async fn run( &self, request: &HttpRequest, body: &str, @@ -99,122 +246,185 @@ impl Worker { let input = serde_json::to_string(&WasmInput::new(request, body, kv)).unwrap(); let mut linker = Linker::new(&self.engine); + let mut component_linker = component::Linker::new(&self.engine); - http_add_to_linker(&mut linker, |s: &mut WorkerState| &mut s.http) - .map_err(|_| errors::WorkerError::ConfigureRuntimeError)?; - wasmtime_wasi::add_to_linker(&mut linker, |s: &mut WorkerState| &mut s.wasi) - .map_err(|_| errors::WorkerError::ConfigureRuntimeError)?; + if let ModuleOrComponent::Module(_) = &self.module_or_component { + wasmtime_wasi::add_to_linker(&mut linker, |host: &mut Host| { + host.wasi_preview1_ctx.as_mut().unwrap() + }) + .map_err(|error| errors::WorkerError::ConfigureRuntimeError { + error: format!("error adding WASI preview1 to linker ({error})"), + })?; + + http_add_to_linker(&mut linker, |host: &mut Host| host.http.as_mut().unwrap()) + .map_err(|error| errors::WorkerError::ConfigureRuntimeError { + error: format!("error adding HTTP bindings to linker ({error})"), + })?; + } else { + preview2::command::add_to_linker(&mut component_linker).map_err(|error| { + errors::WorkerError::ConfigureRuntimeError { + error: format!("error adding WASI preview2 to linker ({error})"), + } + })?; + } - // I have to use `String` as it's required by WasiCtxBuilder - let tuple_vars: Vec<(String, String)> = + let environment_variables: Vec<(String, String)> = vars.iter().map(|(k, v)| (k.clone(), v.clone())).collect(); - // Create the initial WASI context - let mut wasi_builder = WasiCtxBuilder::new(); - wasi_builder - .envs(&tuple_vars) - .map_err(|_| errors::WorkerError::ConfigureRuntimeError)?; + let mut wasi_builder = if let ModuleOrComponent::Module(_) = &self.module_or_component { + CtxBuilder::Preview1(WasiCtxBuilder::new()) + } else { + CtxBuilder::Preview2(preview2::WasiCtxBuilder::new()) + }; + self.prepare_wasi_context(&environment_variables, &mut wasi_builder)?; - // Configure the stdio let stdio = Stdio::new(&input); - stdio.configure_wasi_ctx(&mut wasi_builder); - - // Mount folders from the configuration - if let Some(folders) = self.config.folders.as_ref() { - for folder in folders { - if let Some(base) = &self.path.parent() { - let dir = Dir::open_ambient_dir(base.join(&folder.from), ambient_authority()) - .map_err(|_| errors::WorkerError::ConfigureRuntimeError)?; - wasi_builder - .preopened_dir(dir, &folder.to) - .map_err(|_| errors::WorkerError::ConfigureRuntimeError)?; - } else { - return Err(errors::WorkerError::FailedToInitialize); + let mut wasi_builder = stdio.configure_wasi_ctx(wasi_builder); + + self.runtime.prepare_wasi_ctx(&mut wasi_builder)?; + + let host = match wasi_builder { + CtxBuilder::Preview1(mut wasi_builder) => Host { + wasi_preview1_ctx: Some(wasi_builder.build()), + wasi_nn: None, + http: Some(HttpBindings { + http_config: self.config.features.http_requests.clone(), + }), + ..Host::default() + }, + CtxBuilder::Preview2(mut wasi_builder) => { + let mut table = preview2::Table::default(); + Host { + wasi_preview2_ctx: Some(Arc::new(wasi_builder.build(&mut table).map_err( + |error| errors::WorkerError::ConfigureRuntimeError { + error: format!("error configuring WASI preview 2: {error}"), + }, + )?)), + wasi_preview2_table: Arc::new(table), + wasi_preview2_adapter: Arc::new( + preview2::preview1::WasiPreview1Adapter::default(), + ), + wasi_nn: None, + http: Some(HttpBindings { + http_config: self.config.features.http_requests.clone(), + }), + ..Host::default() } } - } + }; - // WASI-NN - let allowed_backends = &self.config.features.wasi_nn.allowed_backends; - let preload_models = &self.config.features.wasi_nn.preload_models; - - let wasi_nn = if !preload_models.is_empty() { - // Preload the models on the host. - let graphs = preload_models - .iter() - .map(|m| m.build_graph_data(&self.path)) - .collect::>(); - let (backends, registry) = wasmtime_wasi_nn::preload(&graphs).map_err(|_| { - errors::WorkerError::RuntimeError( - wws_runtimes::errors::RuntimeError::WasiContextError, - ) - })?; + // Setup wasi-nn + { + let allowed_backends = &self.config.features.wasi_nn.allowed_backends; + let preload_models = &self.config.features.wasi_nn.preload_models; + let wasi_nn = if !preload_models.is_empty() { + // Preload the models on the host. + let graphs = preload_models + .iter() + .map(|m| m.build_graph_data(&self.path)) + .collect::>(); + let (backends, registry) = wasmtime_wasi_nn::preload(&graphs).map_err(|_| { + errors::WorkerError::RuntimeError( + wws_runtimes::errors::RuntimeError::WasiContextError, + ) + })?; - Some(Arc::new(WasiNnCtx::new(backends, registry))) - } else if !allowed_backends.is_empty() { - let registry = Registry::from(InMemoryRegistry::new()); - let mut backends = Vec::new(); + Some(Arc::new(WasiNnCtx::new(backends, registry))) + } else if !allowed_backends.is_empty() { + let registry = Registry::from(InMemoryRegistry::new()); + let mut backends = Vec::new(); - // Load the given backends: - for b in allowed_backends.iter() { - if let Some(backend) = b.to_backend() { - backends.push(backend); + // Load the given backends: + for b in allowed_backends.iter() { + if let Some(backend) = b.to_backend() { + backends.push(backend); + } } - } - Some(Arc::new(WasiNnCtx::new(backends, registry))) - } else { - None - }; + Some(Arc::new(WasiNnCtx::new(backends, registry))) + } else { + None + }; - // Load the Wasi NN linker - if wasi_nn.is_some() { - wasmtime_wasi_nn::witx::add_to_linker(&mut linker, |s: &mut WorkerState| { - Arc::get_mut(s.wasi_nn.as_mut().unwrap()) - .expect("wasi-nn is not implemented with multi-threading support") - }) - .map_err(|_| { - errors::WorkerError::RuntimeError( - wws_runtimes::errors::RuntimeError::WasiContextError, - ) - })?; + // Load the Wasi NN linker + if wasi_nn.is_some() { + wasmtime_wasi_nn::witx::add_to_linker(&mut linker, |host: &mut Host| { + Arc::get_mut(host.wasi_nn.as_mut().unwrap()) + .expect("wasi-nn is not implemented with multi-threading support") + }) + .map_err(|_| { + errors::WorkerError::RuntimeError( + wws_runtimes::errors::RuntimeError::WasiContextError, + ) + })?; + } } - // Pass to the runtime to add any WASI specific requirement - self.runtime.prepare_wasi_ctx(&mut wasi_builder)?; + let contents = { + let mut store = Store::new(&self.engine, host); + match &self.module_or_component { + ModuleOrComponent::Module(module) => { + linker + .module_async(&mut store, "", module) + .await + .map_err(|error| errors::WorkerError::ConfigureRuntimeError { + error: format!("error retrieving module from linker: {error}"), + })?; - let wasi = wasi_builder.build(); - let state = WorkerState { - wasi, - wasi_nn, - http: HttpBindings { - http_config: self.config.features.http_requests.clone(), - }, + linker + .get_default(&mut store, "") + .map_err(|error| errors::WorkerError::ConfigureRuntimeError { + error: format!("error getting default export from module: {error}"), + })? + .typed::<(), ()>(&store) + .map_err(|error| errors::WorkerError::ConfigureRuntimeError { + error: format!( + "error getting default typed export from module: {error}" + ), + })? + .call_async(&mut store, ()) + .await + .map_err(|error| errors::WorkerError::ConfigureRuntimeError { + error: format!("error calling module default export: {error}"), + })?; + + drop(store); + + stdio + .stdout + .try_into_inner() + .unwrap_or_default() + .into_inner() + } + ModuleOrComponent::Component(component) => { + let (command, _instance) = preview2::command::Command::instantiate_async( + &mut store, + component, + &component_linker, + ) + .await + .unwrap(); + let _ = command + .wasi_cli_run() + .call_run(&mut store) + .await + .map_err(|error| errors::WorkerError::ConfigureRuntimeError { + error: format!("error calling component cli::run: {error}"), + })?; + + drop(store); + + stdio.stdout_preview2.contents().to_vec() + } + } }; - let mut store = Store::new(&self.engine, state); - - linker - .module(&mut store, "", &self.module) - .map_err(|_| errors::WorkerError::ConfigureRuntimeError)?; - linker - .get_default(&mut store, "") - .map_err(|_| errors::WorkerError::ConfigureRuntimeError)? - .typed::<(), ()>(&store) - .map_err(|_| errors::WorkerError::ConfigureRuntimeError)? - .call(&mut store, ()) - .map_err(|_| errors::WorkerError::ConfigureRuntimeError)?; - - drop(store); - - let contents: Vec = stdio - .stdout - .try_into_inner() - .unwrap_or_default() - .into_inner(); // Build the output - let output: WasmOutput = serde_json::from_slice(&contents) - .map_err(|_| errors::WorkerError::ConfigureRuntimeError)?; + let output: WasmOutput = serde_json::from_slice(&contents).map_err(|error| { + errors::WorkerError::ConfigureRuntimeError { + error: format!("error building worker output: {error}"), + } + })?; Ok(output) } diff --git a/crates/worker/src/stdio.rs b/crates/worker/src/stdio.rs index 5bd35c50..550f3c48 100644 --- a/crates/worker/src/stdio.rs +++ b/crates/worker/src/stdio.rs @@ -1,6 +1,14 @@ use std::io::Cursor; use wasi_common::pipe::{ReadPipe, WritePipe}; -use wasmtime_wasi::WasiCtxBuilder; +use wasmtime_wasi::preview2; +use wws_runtimes::CtxBuilder; + +// WASI's Preview2 MemoryOutputPipe, used to retrieve the result from +// the worker, requires a `capacity` setting +// (https://docs.rs/wasmtime-wasi/13.0.0/wasmtime_wasi/preview2/pipe/struct.MemoryOutputPipe.html#method.new). We +// might look into a solution that is less restrictive than this. This +// effectively caps the output size a worker can produce. +const MAX_OUTPUT_BYTES: usize = 10240; /// A library to configure the stdio of the WASI context. /// Note that currently, wws relies on stdin and stdout @@ -9,28 +17,42 @@ use wasmtime_wasi::WasiCtxBuilder; /// The stdin/stdout approach will change in the future with /// a more performant and appropiate approach. pub struct Stdio { - /// Defines the stdin ReadPipe to send the data to the module - pub stdin: ReadPipe>, - /// Defines the stdout to extract the data from the module + /// Defines the stdin ReadPipe to send data to the module + pub stdin: Vec, + /// Defines the stdout to extract data from the module pub stdout: WritePipe>>, + /// Defines the stdout to extract data from the module + pub stdout_preview2: preview2::pipe::MemoryOutputPipe, } impl Stdio { /// Initialize the stdio. The stdin will contain the input data. pub fn new(input: &str) -> Self { Self { - stdin: ReadPipe::from(input), + stdin: Vec::from(input), stdout: WritePipe::new_in_memory(), + stdout_preview2: preview2::pipe::MemoryOutputPipe::new(MAX_OUTPUT_BYTES), } } - pub fn configure_wasi_ctx<'a>( - &self, - builder: &'a mut WasiCtxBuilder, - ) -> &'a mut WasiCtxBuilder { + pub fn configure_wasi_ctx(&self, mut builder: CtxBuilder) -> CtxBuilder { + match builder { + CtxBuilder::Preview1(ref mut wasi_builder) => { + wasi_builder + .stdin(Box::new(ReadPipe::from(self.stdin.clone()).clone())) + .stdout(Box::new(self.stdout.clone())) + .inherit_stderr(); + } + CtxBuilder::Preview2(ref mut wasi_builder) => { + wasi_builder + .stdin( + preview2::pipe::MemoryInputPipe::new(self.stdin.clone().into()), + preview2::IsATTY::No, + ) + .stdout(self.stdout_preview2.clone(), preview2::IsATTY::No) + .inherit_stderr(); + } + } builder - .stdin(Box::new(self.stdin.clone())) - .stdout(Box::new(self.stdout.clone())) - .inherit_stderr() } } diff --git a/examples/Makefile b/examples/Makefile index 264d31a1..97b1c235 100644 --- a/examples/Makefile +++ b/examples/Makefile @@ -1,38 +1,31 @@ -.PHONY: all rust-* pdf-create +SUBDIRS = rust-basic rust-fetch rust-kv rust-wasi-nn rust-wasi-nn-preload rust-pdf-create +COMPONENTS = components/rust-basic components/rust-kv -rust-basic: - cd rust-basic && \ - cargo build --target wasm32-wasi --release && \ - cp target/wasm32-wasi/release/rust-basic.wasm ./basic.wasm +all: $(SUBDIRS) rust-params $(COMPONENTS) components/rust-params -rust-fetch: - cd rust-fetch && \ - cargo build --target wasm32-wasi --release && \ - cp target/wasm32-wasi/release/rust-fetch.wasm ./index.wasm +.PHONY: $(SUBDIRS) rust-params $(COMPONENTS) components/rust-params -rust-kv: - cd rust-kv && \ - cargo build --target wasm32-wasi --release && \ - mv target/wasm32-wasi/release/rust-kv.wasm ./kv.wasm +$(SUBDIRS): + cd $@ && \ + cargo build --target wasm32-wasi --release && \ + cp target/wasm32-wasi/release/$@.wasm ./$@.wasm rust-params: - cd rust-params && \ - cargo build --target wasm32-wasi --release && \ - mv target/wasm32-wasi/release/rust-params.wasm "./[id].wasm" - -rust-wasi-nn: - cd rust-wasi-nn && \ - cargo build --target wasm32-wasi --release && \ - mv target/wasm32-wasi/release/rust-wasi-nn.wasm "./inference.wasm" - -rust-wasi-nn-preload: - cd rust-wasi-nn-preload && \ - cargo build --target wasm32-wasi --release && \ - mv target/wasm32-wasi/release/rust-wasi-nn-preload.wasm "./inference.wasm" - -rust-pdf-create: - cd rust-pdf-create && \ - cargo build --target wasm32-wasi --release && \ - mv target/wasm32-wasi/release/rust-pdf-create.wasm ./index.wasm - -all: rust-basic rust-fetch rust-kv rust-params rust-wasi-nn + cd $@ && \ + cargo build --target wasm32-wasi --release && \ + cp target/wasm32-wasi/release/$@.wasm "./[id].wasm" + +$(COMPONENTS): + mkdir -p $@ + make $(@:components/%=%) + cp $(@:components/%=%)/*.toml $@/ + wasm-tools component new $(@:components/%=%)/$(@:components/%=%).wasm \ + --adapt wasi_snapshot_preview1=components/wasi-component-adapter/wasi_snapshot_preview1-command.wasm \ + -o $@/$(@:components/%=%).wasm + +components/rust-params: + mkdir -p $@ + make rust-params + wasm-tools component new rust-params/[id].wasm \ + --adapt wasi_snapshot_preview1=components/wasi-component-adapter/wasi_snapshot_preview1-command.wasm \ + -o $@/[id].wasm diff --git a/examples/components/.gitignore b/examples/components/.gitignore new file mode 100644 index 00000000..19a4bd73 --- /dev/null +++ b/examples/components/.gitignore @@ -0,0 +1 @@ +/rust-* \ No newline at end of file diff --git a/examples/components/README.md b/examples/components/README.md new file mode 100644 index 00000000..61802caa --- /dev/null +++ b/examples/components/README.md @@ -0,0 +1,6 @@ +# Component model examples + +This directory contains core module examples found in the parent +directory, adapted with the +[`wasi-component-adapter`](./wasi-component-adapter/README.md) so that they are +converted to WebAssembly components. diff --git a/examples/components/wasi-component-adapter/README.md b/examples/components/wasi-component-adapter/README.md new file mode 100644 index 00000000..babd17e4 --- /dev/null +++ b/examples/components/wasi-component-adapter/README.md @@ -0,0 +1,58 @@ +# WASI component adapter + +The Bytecode Alliance provides a WASI component adapter that allows a +WASI WebAssembly module to be compiled to a WebAssembly component. + +You can reproduce this WASI component adapter by running: + +```shell-session +$ git clone git@github.com:bytecodealliance/wasmtime.git +$ cd wasmtime +$ cargo build -p wasi-preview1-component-adapter \ + --target wasm32-unknown-unknown --release +``` + +You can find the WASI component adapter at +`target/wasm32-unknown-unknown/release/wasi_snapshot_preview1.wasm`. + +This adapter is valid for a WASI reactor. If you want to build an +adapter for a WASI command, you can run: + +```shell-session +$ git clone git@github.com:bytecodealliance/wasmtime.git +$ cd wasmtime +$ cargo build -p wasi-preview1-component-adapter \ + --features command \ + --no-default-features \ + --target wasm32-unknown-unknown --release +``` + +## Converting a WebAssembly module to a WebAssembly component + +In order to convert a WebAssemby module to a WebAssembly component, +you can achieve this goal by using `wasm-tools`, along with the WASI +component adapter you have just built. + +You can link to the reactor WASI adapter like so: + +```shell-session +$ wasm-tools component new my-wasm-module.wasm \ + --adapt wasi_snapshot_preview1=wasi_snapshot_preview1-reactor.wasm \ + -o my-wasm-component.wasm +``` + +Or you can link to the command WASI adapter like the following: + +```shell-session +$ wasm-tools component new my-wasm-module.wasm \ + --adapt wasi_snapshot_preview1=wasi_snapshot_preview1-command.wasm \ + -o my-wasm-component.wasm +``` + +In both cases, you can check that the component is valid, and output +the WIT definition associated with it, like: + +```shell-session +$ wasm-tools validate my-wasm-component.wasm --features component-model +$ wasm-tools component wit component.wasm +``` diff --git a/examples/components/wasi-component-adapter/wasi_snapshot_preview1-command.wasm b/examples/components/wasi-component-adapter/wasi_snapshot_preview1-command.wasm new file mode 100644 index 00000000..88cf9fa4 Binary files /dev/null and b/examples/components/wasi-component-adapter/wasi_snapshot_preview1-command.wasm differ diff --git a/examples/components/wasi-component-adapter/wasi_snapshot_preview1-reactor.wasm b/examples/components/wasi-component-adapter/wasi_snapshot_preview1-reactor.wasm new file mode 100644 index 00000000..009345a2 Binary files /dev/null and b/examples/components/wasi-component-adapter/wasi_snapshot_preview1-reactor.wasm differ diff --git a/examples/rust-basic/Cargo.lock b/examples/rust-basic/Cargo.lock index 1a80e1b5..e41fc491 100644 --- a/examples/rust-basic/Cargo.lock +++ b/examples/rust-basic/Cargo.lock @@ -231,7 +231,7 @@ checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" [[package]] name = "wasm-workers-rs" -version = "1.3.0" +version = "1.5.0" dependencies = [ "anyhow", "base64", @@ -305,7 +305,7 @@ dependencies = [ [[package]] name = "worker" -version = "1.3.0" +version = "1.5.0" dependencies = [ "anyhow", "http", diff --git a/examples/rust-basic/basic.toml b/examples/rust-basic/rust-basic.toml similarity index 100% rename from examples/rust-basic/basic.toml rename to examples/rust-basic/rust-basic.toml diff --git a/examples/rust-fetch/Cargo.lock b/examples/rust-fetch/Cargo.lock index b20f14e2..6b21b17e 100644 --- a/examples/rust-fetch/Cargo.lock +++ b/examples/rust-fetch/Cargo.lock @@ -244,7 +244,7 @@ checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" [[package]] name = "wasm-workers-rs" -version = "1.3.0" +version = "1.5.0" dependencies = [ "anyhow", "base64", @@ -318,7 +318,7 @@ dependencies = [ [[package]] name = "worker" -version = "1.3.0" +version = "1.5.0" dependencies = [ "anyhow", "http", diff --git a/examples/rust-kv/Cargo.lock b/examples/rust-kv/Cargo.lock index a6e4f46b..aa326512 100644 --- a/examples/rust-kv/Cargo.lock +++ b/examples/rust-kv/Cargo.lock @@ -8,12 +8,29 @@ version = "1.0.65" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "98161a4e3e2184da77bb14f02184cdd111e83bbbcc9979dfee3c44b9a85f5602" +[[package]] +name = "async-trait" +version = "0.1.66" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b84f9ebcc6c1f5b8cb160f6990096a5c127f423fcb6e1ccc46c370cbdfb75dfc" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "base64" version = "0.21.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a4a4ddaa51a5bc52a6948f74c06d20aaaddb71924eab79b8c97a8c556e942d6a" +[[package]] +name = "bitflags" +version = "1.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" + [[package]] name = "bytes" version = "1.2.1" @@ -26,6 +43,15 @@ version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" +[[package]] +name = "heck" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6d621efb26863f0e9924c6ac577e8275e5e6b77455db64ffa6c65c904e9e132c" +dependencies = [ + "unicode-segmentation", +] + [[package]] name = "http" version = "0.2.8" @@ -37,12 +63,24 @@ dependencies = [ "itoa", ] +[[package]] +name = "id-arena" +version = "2.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "25a2bc672d1148e28034f176e01fffebb08b35768468cc954630da77a1449005" + [[package]] name = "itoa" version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6c8af84674fe1f223a982c933a0ee1086ac4d4052aa0fb8060c12c6ad838e754" +[[package]] +name = "memchr" +version = "2.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f665ee40bc4a3c5590afb1e9677db74a508659dfd71e126420da8274909a0167" + [[package]] name = "proc-macro2" version = "1.0.43" @@ -52,6 +90,17 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "pulldown-cmark" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ffade02495f22453cd593159ea2f59827aae7f53fa8323f756799b670881dcf8" +dependencies = [ + "bitflags", + "memchr", + "unicase", +] + [[package]] name = "quote" version = "1.0.21" @@ -117,12 +166,63 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "tinyvec" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87cc5ceb3875bb20c2890005a4e226a4651264a5c75edb2421b52861a0a0cb50" +dependencies = [ + "tinyvec_macros", +] + +[[package]] +name = "tinyvec_macros" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" + +[[package]] +name = "unicase" +version = "2.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f7d2d4dafb69621809a81864c9c1b864479e1235c0dd4e199924b9742439ed89" +dependencies = [ + "version_check", +] + [[package]] name = "unicode-ident" version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dcc811dc4066ac62f84f11307873c4850cb653bfa9b1719cee2bd2204a4bc5dd" +[[package]] +name = "unicode-normalization" +version = "0.1.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c5713f0fc4b5db668a2ac63cdb7bb4469d8c9fed047b1d0292cc7b0ce2ba921" +dependencies = [ + "tinyvec", +] + +[[package]] +name = "unicode-segmentation" +version = "1.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1dd624098567895118886609431a7c3b8f516e41d30e0643f03d94592a147e36" + +[[package]] +name = "unicode-xid" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f962df74c8c05a667b5ee8bcf162993134c104e96440b663c8daa176dc772d8c" + +[[package]] +name = "version_check" +version = "0.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" + [[package]] name = "wasi" version = "0.11.0+wasi-snapshot-preview1" @@ -131,19 +231,81 @@ checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" [[package]] name = "wasm-workers-rs" -version = "1.0.1" +version = "1.5.0" dependencies = [ "anyhow", "base64", "http", "serde", "serde_json", + "wit-bindgen-rust", "worker", ] +[[package]] +name = "wit-bindgen-gen-core" +version = "0.2.0" +source = "git+https://github.com/bytecodealliance/wit-bindgen?rev=cb871cfa1ee460b51eb1d144b175b9aab9c50aba#cb871cfa1ee460b51eb1d144b175b9aab9c50aba" +dependencies = [ + "anyhow", + "wit-parser", +] + +[[package]] +name = "wit-bindgen-gen-rust" +version = "0.2.0" +source = "git+https://github.com/bytecodealliance/wit-bindgen?rev=cb871cfa1ee460b51eb1d144b175b9aab9c50aba#cb871cfa1ee460b51eb1d144b175b9aab9c50aba" +dependencies = [ + "heck", + "wit-bindgen-gen-core", +] + +[[package]] +name = "wit-bindgen-gen-rust-wasm" +version = "0.2.0" +source = "git+https://github.com/bytecodealliance/wit-bindgen?rev=cb871cfa1ee460b51eb1d144b175b9aab9c50aba#cb871cfa1ee460b51eb1d144b175b9aab9c50aba" +dependencies = [ + "heck", + "wit-bindgen-gen-core", + "wit-bindgen-gen-rust", +] + +[[package]] +name = "wit-bindgen-rust" +version = "0.2.0" +source = "git+https://github.com/bytecodealliance/wit-bindgen?rev=cb871cfa1ee460b51eb1d144b175b9aab9c50aba#cb871cfa1ee460b51eb1d144b175b9aab9c50aba" +dependencies = [ + "async-trait", + "bitflags", + "wit-bindgen-rust-impl", +] + +[[package]] +name = "wit-bindgen-rust-impl" +version = "0.2.0" +source = "git+https://github.com/bytecodealliance/wit-bindgen?rev=cb871cfa1ee460b51eb1d144b175b9aab9c50aba#cb871cfa1ee460b51eb1d144b175b9aab9c50aba" +dependencies = [ + "proc-macro2", + "syn", + "wit-bindgen-gen-core", + "wit-bindgen-gen-rust-wasm", +] + +[[package]] +name = "wit-parser" +version = "0.2.0" +source = "git+https://github.com/bytecodealliance/wit-bindgen?rev=cb871cfa1ee460b51eb1d144b175b9aab9c50aba#cb871cfa1ee460b51eb1d144b175b9aab9c50aba" +dependencies = [ + "anyhow", + "id-arena", + "pulldown-cmark", + "unicode-normalization", + "unicode-xid", +] + [[package]] name = "worker" -version = "1.0.1" +version = "1.5.0" dependencies = [ "anyhow", "http", diff --git a/examples/rust-kv/kv.toml b/examples/rust-kv/rust-kv.toml similarity index 100% rename from examples/rust-kv/kv.toml rename to examples/rust-kv/rust-kv.toml diff --git a/examples/rust-params/Cargo.lock b/examples/rust-params/Cargo.lock index e8891263..e8d6e0ae 100644 --- a/examples/rust-params/Cargo.lock +++ b/examples/rust-params/Cargo.lock @@ -8,12 +8,29 @@ version = "1.0.65" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "98161a4e3e2184da77bb14f02184cdd111e83bbbcc9979dfee3c44b9a85f5602" +[[package]] +name = "async-trait" +version = "0.1.66" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b84f9ebcc6c1f5b8cb160f6990096a5c127f423fcb6e1ccc46c370cbdfb75dfc" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "base64" version = "0.21.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a4a4ddaa51a5bc52a6948f74c06d20aaaddb71924eab79b8c97a8c556e942d6a" +[[package]] +name = "bitflags" +version = "1.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" + [[package]] name = "bytes" version = "1.2.1" @@ -26,6 +43,15 @@ version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" +[[package]] +name = "heck" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6d621efb26863f0e9924c6ac577e8275e5e6b77455db64ffa6c65c904e9e132c" +dependencies = [ + "unicode-segmentation", +] + [[package]] name = "http" version = "0.2.8" @@ -37,12 +63,24 @@ dependencies = [ "itoa", ] +[[package]] +name = "id-arena" +version = "2.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "25a2bc672d1148e28034f176e01fffebb08b35768468cc954630da77a1449005" + [[package]] name = "itoa" version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6c8af84674fe1f223a982c933a0ee1086ac4d4052aa0fb8060c12c6ad838e754" +[[package]] +name = "memchr" +version = "2.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f665ee40bc4a3c5590afb1e9677db74a508659dfd71e126420da8274909a0167" + [[package]] name = "proc-macro2" version = "1.0.43" @@ -52,6 +90,17 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "pulldown-cmark" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ffade02495f22453cd593159ea2f59827aae7f53fa8323f756799b670881dcf8" +dependencies = [ + "bitflags", + "memchr", + "unicase", +] + [[package]] name = "quote" version = "1.0.21" @@ -117,12 +166,63 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "tinyvec" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87cc5ceb3875bb20c2890005a4e226a4651264a5c75edb2421b52861a0a0cb50" +dependencies = [ + "tinyvec_macros", +] + +[[package]] +name = "tinyvec_macros" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" + +[[package]] +name = "unicase" +version = "2.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f7d2d4dafb69621809a81864c9c1b864479e1235c0dd4e199924b9742439ed89" +dependencies = [ + "version_check", +] + [[package]] name = "unicode-ident" version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dcc811dc4066ac62f84f11307873c4850cb653bfa9b1719cee2bd2204a4bc5dd" +[[package]] +name = "unicode-normalization" +version = "0.1.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c5713f0fc4b5db668a2ac63cdb7bb4469d8c9fed047b1d0292cc7b0ce2ba921" +dependencies = [ + "tinyvec", +] + +[[package]] +name = "unicode-segmentation" +version = "1.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1dd624098567895118886609431a7c3b8f516e41d30e0643f03d94592a147e36" + +[[package]] +name = "unicode-xid" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f962df74c8c05a667b5ee8bcf162993134c104e96440b663c8daa176dc772d8c" + +[[package]] +name = "version_check" +version = "0.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" + [[package]] name = "wasi" version = "0.11.0+wasi-snapshot-preview1" @@ -131,19 +231,81 @@ checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" [[package]] name = "wasm-workers-rs" -version = "1.0.1" +version = "1.5.0" dependencies = [ "anyhow", "base64", "http", "serde", "serde_json", + "wit-bindgen-rust", "worker", ] +[[package]] +name = "wit-bindgen-gen-core" +version = "0.2.0" +source = "git+https://github.com/bytecodealliance/wit-bindgen?rev=cb871cfa1ee460b51eb1d144b175b9aab9c50aba#cb871cfa1ee460b51eb1d144b175b9aab9c50aba" +dependencies = [ + "anyhow", + "wit-parser", +] + +[[package]] +name = "wit-bindgen-gen-rust" +version = "0.2.0" +source = "git+https://github.com/bytecodealliance/wit-bindgen?rev=cb871cfa1ee460b51eb1d144b175b9aab9c50aba#cb871cfa1ee460b51eb1d144b175b9aab9c50aba" +dependencies = [ + "heck", + "wit-bindgen-gen-core", +] + +[[package]] +name = "wit-bindgen-gen-rust-wasm" +version = "0.2.0" +source = "git+https://github.com/bytecodealliance/wit-bindgen?rev=cb871cfa1ee460b51eb1d144b175b9aab9c50aba#cb871cfa1ee460b51eb1d144b175b9aab9c50aba" +dependencies = [ + "heck", + "wit-bindgen-gen-core", + "wit-bindgen-gen-rust", +] + +[[package]] +name = "wit-bindgen-rust" +version = "0.2.0" +source = "git+https://github.com/bytecodealliance/wit-bindgen?rev=cb871cfa1ee460b51eb1d144b175b9aab9c50aba#cb871cfa1ee460b51eb1d144b175b9aab9c50aba" +dependencies = [ + "async-trait", + "bitflags", + "wit-bindgen-rust-impl", +] + +[[package]] +name = "wit-bindgen-rust-impl" +version = "0.2.0" +source = "git+https://github.com/bytecodealliance/wit-bindgen?rev=cb871cfa1ee460b51eb1d144b175b9aab9c50aba#cb871cfa1ee460b51eb1d144b175b9aab9c50aba" +dependencies = [ + "proc-macro2", + "syn", + "wit-bindgen-gen-core", + "wit-bindgen-gen-rust-wasm", +] + +[[package]] +name = "wit-parser" +version = "0.2.0" +source = "git+https://github.com/bytecodealliance/wit-bindgen?rev=cb871cfa1ee460b51eb1d144b175b9aab9c50aba#cb871cfa1ee460b51eb1d144b175b9aab9c50aba" +dependencies = [ + "anyhow", + "id-arena", + "pulldown-cmark", + "unicode-normalization", + "unicode-xid", +] + [[package]] name = "worker" -version = "1.0.1" +version = "1.5.0" dependencies = [ "anyhow", "http", diff --git a/examples/rust-pdf-create/Cargo.lock b/examples/rust-pdf-create/Cargo.lock index 0b3bb3a3..861470d8 100644 --- a/examples/rust-pdf-create/Cargo.lock +++ b/examples/rust-pdf-create/Cargo.lock @@ -14,6 +14,17 @@ version = "1.0.65" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "98161a4e3e2184da77bb14f02184cdd111e83bbbcc9979dfee3c44b9a85f5602" +[[package]] +name = "async-trait" +version = "0.1.66" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b84f9ebcc6c1f5b8cb160f6990096a5c127f423fcb6e1ccc46c370cbdfb75dfc" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "base-x" version = "0.2.11" @@ -26,6 +37,12 @@ version = "0.21.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a4a4ddaa51a5bc52a6948f74c06d20aaaddb71924eab79b8c97a8c556e942d6a" +[[package]] +name = "bitflags" +version = "1.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" + [[package]] name = "bumpalo" version = "3.11.1" @@ -151,6 +168,15 @@ version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" +[[package]] +name = "heck" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6d621efb26863f0e9924c6ac577e8275e5e6b77455db64ffa6c65c904e9e132c" +dependencies = [ + "unicode-segmentation", +] + [[package]] name = "http" version = "0.2.8" @@ -162,6 +188,12 @@ dependencies = [ "itoa 1.0.3", ] +[[package]] +name = "id-arena" +version = "2.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "25a2bc672d1148e28034f176e01fffebb08b35768468cc954630da77a1449005" + [[package]] name = "itoa" version = "0.4.8" @@ -228,6 +260,12 @@ dependencies = [ "weezl", ] +[[package]] +name = "memchr" +version = "2.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f665ee40bc4a3c5590afb1e9677db74a508659dfd71e126420da8274909a0167" + [[package]] name = "miniz_oxide" version = "0.5.4" @@ -252,15 +290,6 @@ dependencies = [ "ttf-parser", ] -[[package]] -name = "pdf-create" -version = "0.1.0" -dependencies = [ - "anyhow", - "printpdf", - "wasm-workers-rs", -] - [[package]] name = "pom" version = "3.2.0" @@ -294,6 +323,17 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "pulldown-cmark" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ffade02495f22453cd593159ea2f59827aae7f53fa8323f756799b670881dcf8" +dependencies = [ + "bitflags", + "memchr", + "unicase", +] + [[package]] name = "quote" version = "1.0.21" @@ -303,6 +343,15 @@ dependencies = [ "proc-macro2", ] +[[package]] +name = "rust-pdf-create" +version = "0.1.0" +dependencies = [ + "anyhow", + "printpdf", + "wasm-workers-rs", +] + [[package]] name = "rustc_version" version = "0.2.3" @@ -486,18 +535,63 @@ dependencies = [ "syn", ] +[[package]] +name = "tinyvec" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87cc5ceb3875bb20c2890005a4e226a4651264a5c75edb2421b52861a0a0cb50" +dependencies = [ + "tinyvec_macros", +] + +[[package]] +name = "tinyvec_macros" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" + [[package]] name = "ttf-parser" version = "0.12.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7ae2f58a822f08abdaf668897e96a5656fe72f5a9ce66422423e8849384872e6" +[[package]] +name = "unicase" +version = "2.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f7d2d4dafb69621809a81864c9c1b864479e1235c0dd4e199924b9742439ed89" +dependencies = [ + "version_check", +] + [[package]] name = "unicode-ident" version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dcc811dc4066ac62f84f11307873c4850cb653bfa9b1719cee2bd2204a4bc5dd" +[[package]] +name = "unicode-normalization" +version = "0.1.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c5713f0fc4b5db668a2ac63cdb7bb4469d8c9fed047b1d0292cc7b0ce2ba921" +dependencies = [ + "tinyvec", +] + +[[package]] +name = "unicode-segmentation" +version = "1.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1dd624098567895118886609431a7c3b8f516e41d30e0643f03d94592a147e36" + +[[package]] +name = "unicode-xid" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f962df74c8c05a667b5ee8bcf162993134c104e96440b663c8daa176dc772d8c" + [[package]] name = "version_check" version = "0.9.4" @@ -566,13 +660,14 @@ checksum = "1c38c045535d93ec4f0b4defec448e4291638ee608530863b1e2ba115d4fff7f" [[package]] name = "wasm-workers-rs" -version = "1.0.1" +version = "1.5.0" dependencies = [ "anyhow", "base64", "http", "serde", "serde_json", + "wit-bindgen-rust", "worker", ] @@ -604,9 +699,70 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" +[[package]] +name = "wit-bindgen-gen-core" +version = "0.2.0" +source = "git+https://github.com/bytecodealliance/wit-bindgen?rev=cb871cfa1ee460b51eb1d144b175b9aab9c50aba#cb871cfa1ee460b51eb1d144b175b9aab9c50aba" +dependencies = [ + "anyhow", + "wit-parser", +] + +[[package]] +name = "wit-bindgen-gen-rust" +version = "0.2.0" +source = "git+https://github.com/bytecodealliance/wit-bindgen?rev=cb871cfa1ee460b51eb1d144b175b9aab9c50aba#cb871cfa1ee460b51eb1d144b175b9aab9c50aba" +dependencies = [ + "heck", + "wit-bindgen-gen-core", +] + +[[package]] +name = "wit-bindgen-gen-rust-wasm" +version = "0.2.0" +source = "git+https://github.com/bytecodealliance/wit-bindgen?rev=cb871cfa1ee460b51eb1d144b175b9aab9c50aba#cb871cfa1ee460b51eb1d144b175b9aab9c50aba" +dependencies = [ + "heck", + "wit-bindgen-gen-core", + "wit-bindgen-gen-rust", +] + +[[package]] +name = "wit-bindgen-rust" +version = "0.2.0" +source = "git+https://github.com/bytecodealliance/wit-bindgen?rev=cb871cfa1ee460b51eb1d144b175b9aab9c50aba#cb871cfa1ee460b51eb1d144b175b9aab9c50aba" +dependencies = [ + "async-trait", + "bitflags", + "wit-bindgen-rust-impl", +] + +[[package]] +name = "wit-bindgen-rust-impl" +version = "0.2.0" +source = "git+https://github.com/bytecodealliance/wit-bindgen?rev=cb871cfa1ee460b51eb1d144b175b9aab9c50aba#cb871cfa1ee460b51eb1d144b175b9aab9c50aba" +dependencies = [ + "proc-macro2", + "syn", + "wit-bindgen-gen-core", + "wit-bindgen-gen-rust-wasm", +] + +[[package]] +name = "wit-parser" +version = "0.2.0" +source = "git+https://github.com/bytecodealliance/wit-bindgen?rev=cb871cfa1ee460b51eb1d144b175b9aab9c50aba#cb871cfa1ee460b51eb1d144b175b9aab9c50aba" +dependencies = [ + "anyhow", + "id-arena", + "pulldown-cmark", + "unicode-normalization", + "unicode-xid", +] + [[package]] name = "worker" -version = "1.0.1" +version = "1.5.0" dependencies = [ "anyhow", "http", diff --git a/examples/rust-wasi-nn/Cargo.lock b/examples/rust-wasi-nn/Cargo.lock index e8d416d5..80e36906 100644 --- a/examples/rust-wasi-nn/Cargo.lock +++ b/examples/rust-wasi-nn/Cargo.lock @@ -452,7 +452,7 @@ dependencies = [ [[package]] name = "wasm-workers-rs" -version = "1.4.0" +version = "1.5.0" dependencies = [ "anyhow", "base64", @@ -532,7 +532,7 @@ dependencies = [ [[package]] name = "worker" -version = "1.4.0" +version = "1.5.0" dependencies = [ "anyhow", "http", diff --git a/tests/e2e.rs b/tests/e2e.rs index 55ca1ffd..25d3c099 100644 --- a/tests/e2e.rs +++ b/tests/e2e.rs @@ -128,15 +128,30 @@ mod test { let tests = [ ( "rust-basic", - "http://localhost:8080/basic", + "http://localhost:8080/rust-basic", "This page was generated by a Wasm module built from Rust", ), - ("rust-kv", "http://localhost:8080/kv", "Counter: 0"), + ( + &format!("components{}rust-basic", std::path::MAIN_SEPARATOR_STR), + "http://localhost:8080/rust-basic", + "This page was generated by a Wasm module built from Rust", + ), + ("rust-kv", "http://localhost:8080/rust-kv", "Counter: 0"), + ( + &format!("components{}rust-kv", std::path::MAIN_SEPARATOR_STR), + "http://localhost:8080/rust-kv", + "Counter: 0", + ), ( "rust-params", "http://localhost:8080/thisisatest", "thisisatest", ), + ( + &format!("components{}rust-params", std::path::MAIN_SEPARATOR_STR), + "http://localhost:8080/thisisatest", + "thisisatest", + ), ( "js-basic", "http://localhost:8080",