diff --git a/.github/regenerate-wasi-bindings.sh b/.github/regenerate-wasi-bindings.sh new file mode 100644 index 00000000..49229ba8 --- /dev/null +++ b/.github/regenerate-wasi-bindings.sh @@ -0,0 +1,51 @@ +# Helper script executed from CI to execute `wit-bindgen` and regenerate the +# bindings for the WASIp2 and WASIp3 targets. + +set -ex + +# Disable some features required for compat with really old toolchains/WASI +# versions that aren't required here. +args="--disable-custom-section-link-helpers" +args="$args --disable-run-ctors-once-workaround" + +# Make the generated code a bit easier to read +args="$args --format" + +# Use `feature = "std"` if needed, mostly intended for future compat if ever +# since this isn't needed currently. +args="$args --std-feature" + +# Fail to compile if a runtime-path is actually needed, and it shouldn't be +# given the current generated bindings. +args="$args --runtime-path nonexisten" + +# The custom section generated by wit-bindgen needs a globally unique version in +# the entire crate graph, so "salt" it with the `rand` crate's version which +# should be sufficient enough for now. +rand_version=$(cat Cargo.toml | grep '^version' | sed 's/version = "\(.*\)"/\1/') +args="$args --type-section-suffix rust-rand-${rand_version}" + +# Skip generated bindings for functions that this crate doesn't use. +args="$args --skip=get-random-bytes" +args="$args --skip=get-insecure-random-bytes" +args="$args --skip=get-insecure-random-u64" +args="$args --skip=get-insecure-seed" + +# WASIp2 bindings +wasip2=0.2.10 +curl -LO https://github.com/WebAssembly/WASI/releases/download/v$wasip2/wasi-wit-$wasip2.tar.gz +tar xf wasi-wit-$wasip2.tar.gz +wit-bindgen rust $args ./wasi-wit-$wasip2/random \ + --world imports \ + --out-dir src/backends/wasi_p2_3/p2 + +# WASIp3 bindings +# +# Note that the folder structure is a bit different for WASIp2 for now, but it's +# expected to converge on the same structure as WASIp2 above eventually. +wasip3=0.3.0-rc-2026-01-06 +curl -LO https://github.com/WebAssembly/WASI/archive/refs/tags/v$wasip3.tar.gz +tar xf v$wasip3.tar.gz +wit-bindgen rust $args ./WASI-$wasip3/proposals/random/wit-0.3.0-draft \ + --world imports \ + --out-dir src/backends/wasi_p2_3/p3 diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 828ba711..b1a90774 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -391,14 +391,9 @@ jobs: wget -O - $URL | tar -xJ --strip-components=1 -C ~/.cargo/bin wasmtime --version - uses: Swatinem/rust-cache@v2 - # TODO(MSRV-1.87): Remove this step. - - name: Generate MSRV-compatible Cargo.lock - env: - CARGO_RESOLVER_INCOMPATIBLE_RUST_VERSIONS: "fallback" - run: cargo update -p wasip2 - run: cargo test --target wasm32-wasip2 - # TODO: enable after pre-built std will be provided by Rust + # TODO: enable after pre-built std will be provided by Rust # wasi_p3: # name: WASIp3 # runs-on: ubuntu-24.04 @@ -416,3 +411,19 @@ jobs: # wasmtime --version # - uses: Swatinem/rust-cache@v2 # - run: cargo test --target wasm32-wasip3 + + wasi_bindings: + name: WASI bindings up-to-date + runs-on: ubuntu-24.04 + steps: + - uses: actions/checkout@v6 + - name: Install wit-bindgen + run: | + VERSION=0.53.1 + URL=https://github.com/bytecodealliance/wit-bindgen/releases/download/v${VERSION}/wit-bindgen-${VERSION}-x86_64-linux.tar.gz + wget -O - $URL | tar -xz --strip-components=1 -C ~/.cargo/bin + wit-bindgen --version + - name: Generate bindings + run: sh .github/regenerate-wasi-bindings.sh + - name: Ensure generated files up-to-date + run: git diff --exit-code diff --git a/.typos.toml b/.typos.toml index 89bf65df..151b1def 100644 --- a/.typos.toml +++ b/.typos.toml @@ -1,6 +1,7 @@ [files] extend-exclude = [ - ".git/" + ".git/", + "src/backends/wasi_p2_3", ] [default.extend-words] diff --git a/Cargo.lock b/Cargo.lock index 7c489472..fbab3d1a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,12 +2,6 @@ # It is not intended for manual editing. version = 4 -[[package]] -name = "anyhow" -version = "1.0.102" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f202df86484c868dbad7eaa557ef785d5c66295e41b460ef922eca0723b842c" - [[package]] name = "async-trait" version = "0.1.89" @@ -25,12 +19,6 @@ version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c08606f8c3cbf4ce6ec8e28fb0014a2c086708fe954eaa885384a6165172e7e8" -[[package]] -name = "bitflags" -version = "2.11.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "843867be96c8daad0d758b57df9392b6d8d271134fce549de6ce169ff98a92af" - [[package]] name = "bumpalo" version = "3.20.2" @@ -59,24 +47,12 @@ 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.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5baebc0774151f905a1a2cc41989300b1e6fbb29aff0ceffa1064fdd3088d582" -[[package]] -name = "foldhash" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d9c4f5dac5e15c24eb999c26181a6ca40b39fe946cbe4c263c7209467bc83af2" - [[package]] name = "futures-core" version = "0.3.32" @@ -110,51 +86,10 @@ dependencies = [ "libc", "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.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3d3067d79b975e8844ca9eb072e16b31c3c1c36928edf9c6789548c524d0d954" - -[[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" @@ -171,12 +106,6 @@ 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.182" @@ -189,12 +118,6 @@ version = "0.2.16" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b6d2cec3eae94f9f509c767b45932f1ada8350c4bdb85af2fcab4a3c14807981" -[[package]] -name = "log" -version = "0.4.29" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5e5032e24019045c762d3c0f28f5b6b8bbf38563a65908389bf7978758920897" - [[package]] name = "memchr" version = "2.8.0" @@ -248,16 +171,6 @@ version = "0.2.17" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a89322df9ebe1c1578d689c92318e070967d1042b512afbe49518723f4e6d5cd" -[[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.106" @@ -303,12 +216,6 @@ 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" @@ -381,12 +288,6 @@ version = "1.0.24" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e6e4313cd5fcd3dad5cafa179702e2b244f760991f45397d14d4ebf38247da75" -[[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" @@ -397,24 +298,6 @@ dependencies = [ "winapi-util", ] -[[package]] -name = "wasip2" -version = "1.0.2+wasi-0.2.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9517f9239f02c069db75e65f174b3da828fe5f5b945c4dd26bd25d89c03ebcf5" -dependencies = [ - "wit-bindgen", -] - -[[package]] -name = "wasip3" -version = "0.4.0+wasi-0.3.0-rc-2026-01-06" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5428f8bf88ea5ddc08faddef2ac4a67e390b88186c703ce6dbd955e1c145aca5" -dependencies = [ - "wit-bindgen", -] - [[package]] name = "wasm-bindgen" version = "0.2.114" @@ -513,40 +396,6 @@ version = "0.2.114" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cfe29135b180b72b04c74aa97b2b4a2ef275161eff9a6c7955ea9eaedc7e1d4e" -[[package]] -name = "wasm-encoder" -version = "0.244.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "990065f2fe63003fe337b932cfb5e3b80e0b4d0f5ff650e6985b1048f62c8319" -dependencies = [ - "leb128fmt", - "wasmparser", -] - -[[package]] -name = "wasm-metadata" -version = "0.244.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bb0e353e6a2fbdc176932bbaab493762eb1255a7900fe0fea1a2f96c296cc909" -dependencies = [ - "anyhow", - "indexmap", - "wasm-encoder", - "wasmparser", -] - -[[package]] -name = "wasmparser" -version = "0.244.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "47b807c72e1bac69382b3a6fb3dbe8ea4c0ed87ff5629b8685ae6b9a611028fe" -dependencies = [ - "bitflags", - "hashbrown 0.15.5", - "indexmap", - "semver", -] - [[package]] name = "web-sys" version = "0.3.91" @@ -581,94 +430,6 @@ dependencies = [ "windows-link", ] -[[package]] -name = "wit-bindgen" -version = "0.51.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d7249219f66ced02969388cf2bb044a09756a083d0fab1e566056b04d9fbcaa5" -dependencies = [ - "wit-bindgen-rust-macro", -] - -[[package]] -name = "wit-bindgen-core" -version = "0.51.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ea61de684c3ea68cb082b7a88508a8b27fcc8b797d738bfc99a82facf1d752dc" -dependencies = [ - "anyhow", - "heck", - "wit-parser", -] - -[[package]] -name = "wit-bindgen-rust" -version = "0.51.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b7c566e0f4b284dd6561c786d9cb0142da491f46a9fbed79ea69cdad5db17f21" -dependencies = [ - "anyhow", - "heck", - "indexmap", - "prettyplease", - "syn", - "wasm-metadata", - "wit-bindgen-core", - "wit-component", -] - -[[package]] -name = "wit-bindgen-rust-macro" -version = "0.51.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0c0f9bfd77e6a48eccf51359e3ae77140a7f50b1e2ebfe62422d8afdaffab17a" -dependencies = [ - "anyhow", - "prettyplease", - "proc-macro2", - "quote", - "syn", - "wit-bindgen-core", - "wit-bindgen-rust", -] - -[[package]] -name = "wit-component" -version = "0.244.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9d66ea20e9553b30172b5e831994e35fbde2d165325bec84fc43dbf6f4eb9cb2" -dependencies = [ - "anyhow", - "bitflags", - "indexmap", - "log", - "serde", - "serde_derive", - "serde_json", - "wasm-encoder", - "wasm-metadata", - "wasmparser", - "wit-parser", -] - -[[package]] -name = "wit-parser" -version = "0.244.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ecc8ac4bc1dc3381b7f59c34f00b67e18f910c2c0f50015669dde7def656a736" -dependencies = [ - "anyhow", - "id-arena", - "indexmap", - "log", - "semver", - "serde", - "serde_derive", - "serde_json", - "unicode-xid", - "wasmparser", -] - [[package]] name = "zmij" version = "1.0.21" diff --git a/Cargo.toml b/Cargo.toml index 8580a64e..f1029ad3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -76,15 +76,6 @@ libc = { version = "0.2.154", default-features = false } [target.'cfg(target_os = "vxworks")'.dependencies] libc = { version = "0.2.154", default-features = false } -# 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] -# TODO: remove 0.3 after MSRV bumped to 1.87+. -wasip3 = ">=0.3, <=0.4" - # 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/wasi_p2_3.rs b/src/backends/wasi_p2_3.rs index 3b8ee968..2227b37b 100644 --- a/src/backends/wasi_p2_3.rs +++ b/src/backends/wasi_p2_3.rs @@ -3,32 +3,61 @@ use crate::Error; use core::{mem::MaybeUninit, ptr::copy_nonoverlapping}; #[cfg(target_env = "p2")] -use wasip2 as wasi; +#[allow(clippy::cast_sign_loss, clippy::cast_ptr_alignment)] +mod p2 { + include!("./wasi_p2_3/p2/imports.rs"); + #[inline(never)] + pub fn _link_custom_section_describing_imports() {} +} +#[cfg(target_env = "p2")] +use p2::*; // 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; +#[allow(clippy::all)] +#[allow(clippy::cast_sign_loss, clippy::cast_ptr_alignment)] +mod p3 { + include!("./wasi_p2_3/p3/imports.rs"); + #[inline(never)] + pub fn _link_custom_section_describing_imports() {} +} +#[cfg(not(target_env = "p2"))] +#[cfg(target_env = "p3")] +use p3::*; #[cfg(not(target_env = "p2"))] #[cfg(not(target_env = "p3"))] compile_error!("Unknown version of WASI (only previews 1, 2 and 3 are supported)"); +// This is a bit subtle, in addition to the `include!` above, but the general +// idea is that `wit-bindgen` generates a custom section of type information +// needed by `wasm-component-ld`. That needs to make its way to the linker and +// that's particularly tricky to do unfortunately. To force the linker to at +// least witness the object file with the custom section in it a `#[used]` +// static here refers to a function in the `p2`/`p3` modules which is adjacent +// to the custom section. This is then coupled with a lack of `#[inline]` below +// such that whenever this file itself is used it'll force the linker to look at +// this `#[used]` static, then look at the type section, and include that. +// +// Note that the linker will strip this static as well as the referred-to +// function as it's actually dead, but the linker will still preserve the type +// information since it's in a custom section, which is what we want. +#[used] +static _FORCE_SECTION_REF: fn() = _link_custom_section_describing_imports; + use wasi::random::random::get_random_u64; -#[inline] pub fn inner_u32() -> Result { let val = get_random_u64(); Ok(crate::util::truncate(val)) } -#[inline] pub fn inner_u64() -> Result { Ok(get_random_u64()) } -#[inline] pub fn fill_inner(dest: &mut [MaybeUninit]) -> Result<(), Error> { let (prefix, chunks, suffix) = unsafe { dest.align_to_mut::>() }; diff --git a/src/backends/wasi_p2_3/.gitattributes b/src/backends/wasi_p2_3/.gitattributes new file mode 100644 index 00000000..115f2710 --- /dev/null +++ b/src/backends/wasi_p2_3/.gitattributes @@ -0,0 +1,3 @@ +# All files in this directory are auto-generated by wit-bindgen, so flag as such +# with github. +* linguist-generated diff --git a/src/backends/wasi_p2_3/p2/imports.rs b/src/backends/wasi_p2_3/p2/imports.rs new file mode 100644 index 00000000..86fac3d6 --- /dev/null +++ b/src/backends/wasi_p2_3/p2/imports.rs @@ -0,0 +1,115 @@ +// Generated by `wit-bindgen` 0.53.1. DO NOT EDIT! +// Options used: +// * std_feature +// * skip: ["get-random-bytes", "get-insecure-random-bytes", "get-insecure-random-u64", "get-insecure-seed"] +// * runtime_path: "nonexisten" +// * type_section_suffix: "rust-rand-0.4.2" +// * disable-run-ctors-once-workaround +// * disable_custom_section_link_helpers +#[rustfmt::skip] +#[allow(dead_code, clippy::all)] +pub mod wasi { + pub mod random { + /// WASI Random is a random data API. + /// + /// It is intended to be portable at least between Unix-family platforms and + /// Windows. + #[allow(dead_code, async_fn_in_trait, unused_imports, clippy::all)] + pub mod random { + #[allow(unused_unsafe, clippy::all)] + /// Return a cryptographically-secure random or pseudo-random `u64` value. + /// + /// This function returns the same type of data as `get-random-bytes`, + /// represented as a `u64`. + #[allow(async_fn_in_trait)] + pub fn get_random_u64() -> u64 { + unsafe { + #[cfg(target_arch = "wasm32")] + #[link(wasm_import_module = "wasi:random/random@0.2.10")] + unsafe extern "C" { + #[link_name = "get-random-u64"] + fn wit_import0() -> i64; + } + #[cfg(not(target_arch = "wasm32"))] + unsafe extern "C" fn wit_import0() -> i64 { + unreachable!() + } + let ret = wit_import0(); + ret as u64 + } + } + } + /// The insecure interface for insecure pseudo-random numbers. + /// + /// It is intended to be portable at least between Unix-family platforms and + /// Windows. + #[allow(dead_code, async_fn_in_trait, unused_imports, clippy::all)] + pub mod insecure {} + /// The insecure-seed interface for seeding hash-map DoS resistance. + /// + /// It is intended to be portable at least between Unix-family platforms and + /// Windows. + #[allow(dead_code, async_fn_in_trait, unused_imports, clippy::all)] + pub mod insecure_seed { + #[allow(unused_unsafe, clippy::all)] + /// Return a 128-bit value that may contain a pseudo-random value. + /// + /// The returned value is not required to be computed from a CSPRNG, and may + /// even be entirely deterministic. Host implementations are encouraged to + /// provide pseudo-random values to any program exposed to + /// attacker-controlled content, to enable DoS protection built into many + /// languages' hash-map implementations. + /// + /// This function is intended to only be called once, by a source language + /// to initialize Denial Of Service (DoS) protection in its hash-map + /// implementation. + /// + /// # Expected future evolution + /// + /// This will likely be changed to a value import, to prevent it from being + /// called multiple times and potentially used for purposes other than DoS + /// protection. + #[allow(async_fn_in_trait)] + pub fn insecure_seed() -> (u64, u64) { + unsafe { + #[repr(align(8))] + struct RetArea([::core::mem::MaybeUninit; 16]); + let mut ret_area = RetArea([::core::mem::MaybeUninit::uninit(); 16]); + let ptr0 = ret_area.0.as_mut_ptr().cast::(); + #[cfg(target_arch = "wasm32")] + #[link(wasm_import_module = "wasi:random/insecure-seed@0.2.10")] + unsafe extern "C" { + #[link_name = "insecure-seed"] + fn wit_import1(_: *mut u8); + } + #[cfg(not(target_arch = "wasm32"))] + unsafe extern "C" fn wit_import1(_: *mut u8) { + unreachable!() + } + wit_import1(ptr0); + let l2 = *ptr0.add(0).cast::(); + let l3 = *ptr0.add(8).cast::(); + let result4 = (l2 as u64, l3 as u64); + result4 + } + } + } + } +} +#[rustfmt::skip] +#[cfg(target_arch = "wasm32")] +#[unsafe( + link_section = "component-type:wit-bindgen:0.53.1:wasi:random@0.2.10:imports:encoded worldrust-rand-0.4.2" +)] +#[doc(hidden)] +#[allow(clippy::octal_escapes)] +pub static __WIT_BINDGEN_COMPONENT_TYPE: [u8; 433] = *b"\ +\0asm\x0d\0\x01\0\0\x19\x16wit-component-encoding\x04\0\x07\xb3\x02\x01A\x02\x01\ +A\x06\x01B\x05\x01p}\x01@\x01\x03lenw\0\0\x04\0\x10get-random-bytes\x01\x01\x01@\ +\0\0w\x04\0\x0eget-random-u64\x01\x02\x03\0\x19wasi:random/random@0.2.10\x05\0\x01\ +B\x05\x01p}\x01@\x01\x03lenw\0\0\x04\0\x19get-insecure-random-bytes\x01\x01\x01@\ +\0\0w\x04\0\x17get-insecure-random-u64\x01\x02\x03\0\x1bwasi:random/insecure@0.2\ +.10\x05\x01\x01B\x03\x01o\x02ww\x01@\0\0\0\x04\0\x0dinsecure-seed\x01\x01\x03\0\x20\ +wasi:random/insecure-seed@0.2.10\x05\x02\x04\0\x1awasi:random/imports@0.2.10\x04\ +\0\x0b\x0d\x01\0\x07imports\x03\0\0\0G\x09producers\x01\x0cprocessed-by\x02\x0dw\ +it-component\x070.245.1\x10wit-bindgen-rust\x060.53.1"; diff --git a/src/backends/wasi_p2_3/p3/imports.rs b/src/backends/wasi_p2_3/p3/imports.rs new file mode 100644 index 00000000..46889b58 --- /dev/null +++ b/src/backends/wasi_p2_3/p3/imports.rs @@ -0,0 +1,75 @@ +// Generated by `wit-bindgen` 0.53.1. DO NOT EDIT! +// Options used: +// * std_feature +// * skip: ["get-random-bytes", "get-insecure-random-bytes", "get-insecure-random-u64", "get-insecure-seed"] +// * runtime_path: "nonexisten" +// * type_section_suffix: "rust-rand-0.4.2" +// * disable-run-ctors-once-workaround +// * disable_custom_section_link_helpers +#[rustfmt::skip] +#[allow(dead_code, clippy::all)] +pub mod wasi { + pub mod random { + /// WASI Random is a random data API. + /// + /// It is intended to be portable at least between Unix-family platforms and + /// Windows. + #[allow(dead_code, async_fn_in_trait, unused_imports, clippy::all)] + pub mod random { + #[allow(unused_unsafe, clippy::all)] + /// Return a cryptographically-secure random or pseudo-random `u64` value. + /// + /// This function returns the same type of data as `get-random-bytes`, + /// represented as a `u64`. + #[allow(async_fn_in_trait)] + pub fn get_random_u64() -> u64 { + unsafe { + #[cfg(target_arch = "wasm32")] + #[link( + wasm_import_module = "wasi:random/random@0.3.0-rc-2026-01-06" + )] + unsafe extern "C" { + #[link_name = "get-random-u64"] + fn wit_import0() -> i64; + } + #[cfg(not(target_arch = "wasm32"))] + unsafe extern "C" fn wit_import0() -> i64 { + unreachable!() + } + let ret = wit_import0(); + ret as u64 + } + } + } + /// The insecure interface for insecure pseudo-random numbers. + /// + /// It is intended to be portable at least between Unix-family platforms and + /// Windows. + #[allow(dead_code, async_fn_in_trait, unused_imports, clippy::all)] + pub mod insecure {} + /// The insecure-seed interface for seeding hash-map DoS resistance. + /// + /// It is intended to be portable at least between Unix-family platforms and + /// Windows. + #[allow(dead_code, async_fn_in_trait, unused_imports, clippy::all)] + pub mod insecure_seed {} + } +} +#[rustfmt::skip] +#[cfg(target_arch = "wasm32")] +#[unsafe( + link_section = "component-type:wit-bindgen:0.53.1:wasi:random@0.3.0-rc-2026-01-06:imports:encoded worldrust-rand-0.4.2" +)] +#[doc(hidden)] +#[allow(clippy::octal_escapes)] +pub static __WIT_BINDGEN_COMPONENT_TYPE: [u8; 489] = *b"\ +\0asm\x0d\0\x01\0\0\x19\x16wit-component-encoding\x04\0\x07\xeb\x02\x01A\x02\x01\ +A\x06\x01B\x05\x01p}\x01@\x01\x03lenw\0\0\x04\0\x10get-random-bytes\x01\x01\x01@\ +\0\0w\x04\0\x0eget-random-u64\x01\x02\x03\0&wasi:random/random@0.3.0-rc-2026-01-\ +06\x05\0\x01B\x05\x01p}\x01@\x01\x03lenw\0\0\x04\0\x19get-insecure-random-bytes\x01\ +\x01\x01@\0\0w\x04\0\x17get-insecure-random-u64\x01\x02\x03\0(wasi:random/insecu\ +re@0.3.0-rc-2026-01-06\x05\x01\x01B\x03\x01o\x02ww\x01@\0\0\0\x04\0\x11get-insec\ +ure-seed\x01\x01\x03\0-wasi:random/insecure-seed@0.3.0-rc-2026-01-06\x05\x02\x04\ +\0'wasi:random/imports@0.3.0-rc-2026-01-06\x04\0\x0b\x0d\x01\0\x07imports\x03\0\0\ +\0G\x09producers\x01\x0cprocessed-by\x02\x0dwit-component\x070.245.1\x10wit-bind\ +gen-rust\x060.53.1";