-
Notifications
You must be signed in to change notification settings - Fork 211
Add support for wasm32-wasip1
and wasm32-wasip2
, remove support for wasm32-wasi
#499
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
10f59f6
927f14a
12809c4
c00eb60
4c62ab5
c1c63c0
9b56e5c
2f3c164
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -273,22 +273,41 @@ jobs: | |
# does not yet support memory64. | ||
run: cargo test --no-run -Z build-std=std,panic_abort --target=wasm64-unknown-unknown --features=js | ||
|
||
wasi-tests: | ||
name: WASI Test | ||
wasip1-tests: | ||
name: WASI Preview 1 Test | ||
runs-on: ubuntu-22.04 | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: dtolnay/rust-toolchain@stable | ||
- uses: dtolnay/rust-toolchain@nightly | ||
with: | ||
targets: wasm32-wasi | ||
targets: wasm32-wasip1 | ||
- name: Install precompiled wasmtime | ||
run: | | ||
VERSION=v24.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 --no-default-features --target wasm32-wasip1 | ||
|
||
wasip2-tests: | ||
name: WASI Preview 2 Test | ||
runs-on: ubuntu-22.04 | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: dtolnay/rust-toolchain@nightly | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The WASI 0.2 target should already be available on the beta channel, and will be available on stable come Rust 1.82. |
||
with: | ||
targets: wasm32-wasip2 | ||
components: rust-src | ||
- name: Install precompiled wasmtime | ||
run: | | ||
VERSION=v2.0.0 | ||
VERSION=v24.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-wasi | ||
# Without enabled optimizations tests cause stack overflow in Wasmtime | ||
- run: cargo test --release -Zbuild-std=std,panic_abort --target wasm32-wasip2 | ||
|
||
build-tier2: | ||
name: Tier 2 Build | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,48 @@ | ||
//! Implementation for WASI | ||
//! Implementation for WASI (preview 1 and 2) | ||
//! | ||
//! `target_env = "p1"` was introduced only in Rust 1.80, so on earlier compiler versions this | ||
//! code will result in a compilation error. | ||
use crate::Error; | ||
use core::mem::MaybeUninit; | ||
use wasi::random_get; | ||
|
||
#[cfg(not(any(target_env = "p1", target_env = "p2")))] | ||
compile_error!( | ||
"Unknown version of WASI (only previews 1 and 2 are supported) \ | ||
or Rust version older than 1.80 was used" | ||
); | ||
|
||
#[cfg(target_env = "p1")] | ||
pub fn getrandom_inner(dest: &mut [MaybeUninit<u8>]) -> Result<(), Error> { | ||
unsafe { random_get(dest.as_mut_ptr().cast::<u8>(), dest.len()) } | ||
unsafe { wasi::random_get(dest.as_mut_ptr().cast::<u8>(), dest.len()) } | ||
.map_err(|e| Error::from_os_error(e.raw().into())) | ||
} | ||
|
||
#[cfg(target_env = "p2")] | ||
pub fn getrandom_inner(dest: &mut [MaybeUninit<u8>]) -> Result<(), Error> { | ||
use core::ptr::copy_nonoverlapping; | ||
use wasi::random::random::get_random_u64; | ||
|
||
let (prefix, chunks, suffix) = unsafe { dest.align_to_mut::<MaybeUninit<u64>>() }; | ||
|
||
if !prefix.is_empty() { | ||
let val = get_random_u64(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
let src = (&val as *const u64).cast(); | ||
unsafe { | ||
copy_nonoverlapping(src, prefix.as_mut_ptr(), prefix.len()); | ||
} | ||
} | ||
|
||
for dst in chunks { | ||
dst.write(get_random_u64()); | ||
} | ||
|
||
if !suffix.is_empty() { | ||
let val = get_random_u64(); | ||
let src = (&val as *const u64).cast(); | ||
unsafe { | ||
copy_nonoverlapping(src, suffix.as_mut_ptr(), suffix.len()); | ||
} | ||
} | ||
|
||
Ok(()) | ||
} |
Uh oh!
There was an error while loading. Please reload this page.