diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 8d1d0587..0b5ad3c5 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -336,23 +336,57 @@ jobs: # Firefox doesn't support module service workers and therefor can't import scripts run: wasm-pack test --headless --chrome -- ${{ matrix.rust.args }} - wasi: - name: WASI + wasi_p1: + name: WASIp1 runs-on: ubuntu-24.04 steps: - uses: actions/checkout@v6 - uses: dtolnay/rust-toolchain@master with: toolchain: 1.85 - targets: wasm32-wasip1,wasm32-wasip2 + targets: wasm32-wasip1 - name: Install Wasmtime run: | - VERSION=v24.0.0 + VERSION=v40.0.0 URL=https://github.com/bytecodealliance/wasmtime/releases/download/${VERSION}/wasmtime-${VERSION}-x86_64-linux.tar.xz wget -O - $URL | tar -xJ --strip-components=1 -C ~/.cargo/bin wasmtime --version - uses: Swatinem/rust-cache@v2 - - name: WASI 0.1 Test - run: cargo test --target wasm32-wasip1 - - name: WASI 0.2 Test - run: cargo test --target wasm32-wasip2 + - run: cargo test --target wasm32-wasip1 + + wasi_p2: + name: WASIp2 + runs-on: ubuntu-24.04 + steps: + - uses: actions/checkout@v6 + - uses: dtolnay/rust-toolchain@master + with: + toolchain: 1.85 + targets: wasm32-wasip2 + - name: Install Wasmtime + run: | + VERSION=v40.0.0 + URL=https://github.com/bytecodealliance/wasmtime/releases/download/${VERSION}/wasmtime-${VERSION}-x86_64-linux.tar.xz + wget -O - $URL | tar -xJ --strip-components=1 -C ~/.cargo/bin + wasmtime --version + - uses: Swatinem/rust-cache@v2 + - run: cargo test --target wasm32-wasip2 + + # TODO: enable after pre-built std will be provided by Rust + # wasi_p3: + # name: WASIp3 + # runs-on: ubuntu-24.04 + # steps: + # - uses: actions/checkout@v6 + # - uses: dtolnay/rust-toolchain@master + # with: + # toolchain: 1.90 + # targets: wasm32-wasip3 + # - name: Install Wasmtime + # run: | + # VERSION=v40.0.0 + # URL=https://github.com/bytecodealliance/wasmtime/releases/download/${VERSION}/wasmtime-${VERSION}-x86_64-linux.tar.xz + # wget -O - $URL | tar -xJ --strip-components=1 -C ~/.cargo/bin + # wasmtime --version + # - uses: Swatinem/rust-cache@v2 + # - run: cargo test --target wasm32-wasip3 diff --git a/CHANGELOG.md b/CHANGELOG.md index 28162ef4..1aff310c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added - `RawOsError` type alias [#739] - `SysRng` behind new feature `sys_rng` [#751] +- WASIp3 support [#779] ### Changed - Use Edition 2024 and MSRV 1.85 [#749] @@ -16,6 +17,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 [#739]: https://github.com/rust-random/getrandom/pull/739 [#749]: https://github.com/rust-random/getrandom/pull/749 [#751]: https://github.com/rust-random/getrandom/pull/751 +[#779]: https://github.com/rust-random/getrandom/pull/779 ## [0.3.4] - 2025-10-14 diff --git a/Cargo.lock b/Cargo.lock index 86d2606b..a0ee3dc0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,6 +2,12 @@ # It is not intended for manual editing. version = 4 +[[package]] +name = "anyhow" +version = "1.0.100" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a23eb6b1614318a8071c9b2521f36b424b2c83db5eb3a0fead4a6c0809af6e61" + [[package]] name = "async-trait" version = "0.1.89" @@ -19,6 +25,12 @@ version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c08606f8c3cbf4ce6ec8e28fb0014a2c086708fe954eaa885384a6165172e7e8" +[[package]] +name = "bitflags" +version = "2.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "812e12b5285cc515a9c72a5c1d3b6d46a19dac5acfef5265968c166106e31dd3" + [[package]] name = "bumpalo" version = "3.19.1" @@ -47,12 +59,24 @@ version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801" +[[package]] +name = "equivalent" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "877a4ace8713b0bcf2a4e7eec82529c029f1d0619886d18145fea96c3ffe5c0f" + [[package]] name = "find-msvc-tools" version = "0.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "645cbb3a84e60b7531617d5ae4e57f7e27308f6445f5abf653209ea76dec8dff" +[[package]] +name = "foldhash" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d9c4f5dac5e15c24eb999c26181a6ca40b39fe946cbe4c263c7209467bc83af2" + [[package]] name = "getrandom" version = "0.4.0-rc.0" @@ -63,10 +87,50 @@ dependencies = [ "r-efi", "rand_core", "wasip2", + "wasip3", "wasm-bindgen", "wasm-bindgen-test", ] +[[package]] +name = "hashbrown" +version = "0.15.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9229cfe53dfd69f0609a49f65461bd93001ea1ef889cd5529dd176593f5338a1" +dependencies = [ + "foldhash", +] + +[[package]] +name = "hashbrown" +version = "0.16.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "841d1cc9bed7f9236f321df977030373f4a4163ae1a7dbfe1a51a2c1a51d9100" + +[[package]] +name = "heck" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" + +[[package]] +name = "id-arena" +version = "2.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "25a2bc672d1148e28034f176e01fffebb08b35768468cc954630da77a1449005" + +[[package]] +name = "indexmap" +version = "2.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7714e70437a7dc3ac8eb7e6f8df75fd8eb422675fc7678aff7364301092b1017" +dependencies = [ + "equivalent", + "hashbrown 0.16.1", + "serde", + "serde_core", +] + [[package]] name = "itoa" version = "1.0.17" @@ -83,6 +147,12 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "leb128fmt" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09edd9e8b54e49e587e4f6295a7d29c3ea94d469cb40ab8ca70b288248a81db2" + [[package]] name = "libc" version = "0.2.179" @@ -95,6 +165,12 @@ version = "0.2.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f9fbbcab51052fe104eb5e5d351cf728d30a5be1fe14d9be8a3b097481fb97de" +[[package]] +name = "log" +version = "0.4.29" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5e5032e24019045c762d3c0f28f5b6b8bbf38563a65908389bf7978758920897" + [[package]] name = "memchr" version = "2.7.6" @@ -142,20 +218,30 @@ version = "11.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d6790f58c7ff633d8771f42965289203411a5e5c68388703c06e14f24770b41e" +[[package]] +name = "prettyplease" +version = "0.2.37" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "479ca8adacdd7ce8f1fb39ce9ecccbfe93a3f1344b3d0d97f20bc0196208f62b" +dependencies = [ + "proc-macro2", + "syn", +] + [[package]] name = "proc-macro2" -version = "1.0.104" +version = "1.0.105" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9695f8df41bb4f3d222c95a67532365f569318332d03d5f3f67f37b20e6ebdf0" +checksum = "535d180e0ecab6268a3e718bb9fd44db66bbbc256257165fc699dadf70d16fe7" dependencies = [ "unicode-ident", ] [[package]] name = "quote" -version = "1.0.42" +version = "1.0.43" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a338cc41d27e6cc6dce6cefc13a0729dfbb81c262b1f519331575dd80ef3067f" +checksum = "dc74d9a594b72ae6656596548f56f667211f8a97b3d4c3d467150794690dc40a" dependencies = [ "proc-macro2", ] @@ -187,6 +273,12 @@ dependencies = [ "winapi-util", ] +[[package]] +name = "semver" +version = "1.0.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d767eb0aabc880b29956c35734170f26ed551a859dbd361d140cdbeca61ab1e2" + [[package]] name = "serde" version = "1.0.228" @@ -219,9 +311,9 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.148" +version = "1.0.149" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3084b546a1dd6289475996f182a22aba973866ea8e8b02c51d9f46b1336a22da" +checksum = "83fc039473c5595ace860d8c4fafa220ff474b3fc6bfdb4293327f1a37e94d86" dependencies = [ "itoa", "memchr", @@ -238,9 +330,9 @@ checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" [[package]] name = "syn" -version = "2.0.113" +version = "2.0.114" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "678faa00651c9eb72dd2020cbdf275d92eccb2400d568e419efdd64838145cb4" +checksum = "d4d107df263a3013ef9b1879b0df87d706ff80f65a86ea879bd9c31f9b307c2a" dependencies = [ "proc-macro2", "quote", @@ -253,6 +345,12 @@ version = "1.0.22" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9312f7c4f6ff9069b165498234ce8be658059c6728633667c526e27dc2cf1df5" +[[package]] +name = "unicode-xid" +version = "0.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ebc1c04c71510c7f702b52b7c350734c9ff1295c464a03335b00bb84fc54f853" + [[package]] name = "walkdir" version = "2.5.0" @@ -269,7 +367,16 @@ version = "1.0.1+wasi-0.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0562428422c63773dad2c345a1882263bbf4d65cf3f42e90921f787ef5ad58e7" dependencies = [ - "wit-bindgen", + "wit-bindgen 0.46.0", +] + +[[package]] +name = "wasip3" +version = "0.3.1+wasi-0.3.0-rc-2025-09-16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87ba4be47b1d11244670d11857eee0758a8f2c39aea64d80b78c1ce29b4642cd" +dependencies = [ + "wit-bindgen 0.48.1", ] [[package]] @@ -362,6 +469,40 @@ dependencies = [ "syn", ] +[[package]] +name = "wasm-encoder" +version = "0.241.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e01164c9dda68301e34fdae536c23ed6fe90ce6d97213ccc171eebbd3d02d6b8" +dependencies = [ + "leb128fmt", + "wasmparser", +] + +[[package]] +name = "wasm-metadata" +version = "0.241.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "876fe286f2fa416386deedebe8407e6f19e0b5aeaef3d03161e77a15fa80f167" +dependencies = [ + "anyhow", + "indexmap", + "wasm-encoder", + "wasmparser", +] + +[[package]] +name = "wasmparser" +version = "0.241.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "46d90019b1afd4b808c263e428de644f3003691f243387d30d673211ee0cb8e8" +dependencies = [ + "bitflags", + "hashbrown 0.15.5", + "indexmap", + "semver", +] + [[package]] name = "web-sys" version = "0.3.83" @@ -402,8 +543,96 @@ version = "0.46.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f17a85883d4e6d00e8a97c586de764dabcc06133f7f1d55dce5cdc070ad7fe59" +[[package]] +name = "wit-bindgen" +version = "0.48.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f8c2adb5f74ac9395bc3121c99a1254bf9310482c27b13f97167aedb5887138" +dependencies = [ + "wit-bindgen-rust-macro", +] + +[[package]] +name = "wit-bindgen-core" +version = "0.48.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b881a098cae03686d7a0587f8f306f8a58102ad8da8b5599100fbe0e7f5800b" +dependencies = [ + "anyhow", + "heck", + "wit-parser", +] + +[[package]] +name = "wit-bindgen-rust" +version = "0.48.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "69667efa439a453e1d50dac939c6cab6d2c3ac724a9d232b6631dad2472a5b70" +dependencies = [ + "anyhow", + "heck", + "indexmap", + "prettyplease", + "syn", + "wasm-metadata", + "wit-bindgen-core", + "wit-component", +] + +[[package]] +name = "wit-bindgen-rust-macro" +version = "0.48.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eae2e22cceb5d105d52326c07e3e67603a861cc7add70fc467f7cc7ec5265017" +dependencies = [ + "anyhow", + "prettyplease", + "proc-macro2", + "quote", + "syn", + "wit-bindgen-core", + "wit-bindgen-rust", +] + +[[package]] +name = "wit-component" +version = "0.241.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fd0c57df25e7ee612d946d3b7646c1ddb2310f8280aa2c17e543b66e0812241" +dependencies = [ + "anyhow", + "bitflags", + "indexmap", + "log", + "serde", + "serde_derive", + "serde_json", + "wasm-encoder", + "wasm-metadata", + "wasmparser", + "wit-parser", +] + +[[package]] +name = "wit-parser" +version = "0.241.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09ef1c6ad67f35c831abd4039c02894de97034100899614d1c44e2268ad01c91" +dependencies = [ + "anyhow", + "id-arena", + "indexmap", + "log", + "semver", + "serde", + "serde_derive", + "serde_json", + "unicode-xid", + "wasmparser", +] + [[package]] name = "zmij" -version = "1.0.10" +version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "30e0d8dffbae3d840f64bda38e28391faef673a7b5a6017840f2a106c8145868" +checksum = "2fc5a66a20078bf1251bde995aa2fdcc4b800c70b5d92dd2c62abc5c60f679f8" diff --git a/Cargo.toml b/Cargo.toml index baffad7f..4d773018 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -69,10 +69,14 @@ libc = { version = "0.2.154", default-features = false } [target.'cfg(target_os = "vxworks")'.dependencies] libc = { version = "0.2.154", default-features = false } -# wasi_p2 +# wasi_p2_3 [target.'cfg(all(target_arch = "wasm32", target_os = "wasi", target_env = "p2"))'.dependencies] wasip2 = { version = "1", default-features = false } +# wasi_p2_3 +[target.'cfg(all(target_arch = "wasm32", target_os = "wasi", target_env = "p3"))'.dependencies] +wasip3 = { version = "0.3", default-features = false } + # wasm_js [target.'cfg(all(target_arch = "wasm32", any(target_os = "unknown", target_os = "none")))'.dependencies] wasm-bindgen = { version = "0.2.98", default-features = false, optional = true } diff --git a/src/backends.rs b/src/backends.rs index e572b8b5..58e9a85b 100644 --- a/src/backends.rs +++ b/src/backends.rs @@ -151,14 +151,9 @@ cfg_if! { if #[cfg(target_env = "p1")] { mod wasi_p1; pub use wasi_p1::*; - } else if #[cfg(target_env = "p2")] { - mod wasi_p2; - pub use wasi_p2::*; } else { - compile_error!( - "Unknown version of WASI (only previews 1 and 2 are supported) \ - or Rust version older than 1.80 was used" - ); + mod wasi_p2_3; + pub use wasi_p2_3::*; } } } else if #[cfg(target_os = "hermit")] { diff --git a/src/backends/wasi_p2.rs b/src/backends/wasi_p2_3.rs similarity index 73% rename from src/backends/wasi_p2.rs rename to src/backends/wasi_p2_3.rs index d16fdff9..3b8ee968 100644 --- a/src/backends/wasi_p2.rs +++ b/src/backends/wasi_p2_3.rs @@ -1,7 +1,21 @@ -//! Implementation for WASI Preview 2. +//! Implementation for WASIp2 and WASIp3. use crate::Error; use core::{mem::MaybeUninit, ptr::copy_nonoverlapping}; -use wasip2::random::random::get_random_u64; + +#[cfg(target_env = "p2")] +use wasip2 as wasi; + +// Workaround to silence `unexpected_cfgs` warning +// on Rust version between 1.85 and 1.91 +#[cfg(not(target_env = "p2"))] +#[cfg(target_env = "p3")] +use wasip3 as wasi; + +#[cfg(not(target_env = "p2"))] +#[cfg(not(target_env = "p3"))] +compile_error!("Unknown version of WASI (only previews 1, 2 and 3 are supported)"); + +use wasi::random::random::get_random_u64; #[inline] pub fn inner_u32() -> Result {