Skip to content

wasm32-wasip1/wasm32-wasip2 tests #2

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

Draft
wants to merge 35 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
997352a
most tests are now passing, code is messy, working on GitHub Actions
lastmjs Mar 6, 2025
c83e9bb
turn on building for wasm32-wasip1
lastmjs Mar 6, 2025
b9b8f58
not sure why, but had to fix this code coverage issue
lastmjs Mar 6, 2025
10d2ad2
do not try to upload to code coverage site
lastmjs Mar 6, 2025
dc994e3
attempt to turn off the full async feature for wasm32-wasip1 CI tests
lastmjs Mar 6, 2025
9ab4abc
fix the feature set for the wasm32-wasip1 tests
lastmjs Mar 6, 2025
4c39908
typo I guess
lastmjs Mar 6, 2025
2266d21
attempt to install wasmtime
lastmjs Mar 6, 2025
13acc7e
attempt to see if version is shown
lastmjs Mar 6, 2025
cfd77c5
attempt to see if version is shown
lastmjs Mar 6, 2025
ac2b0bc
attempt
lastmjs Mar 6, 2025
9f8a573
let's attemp to build wasm32-wasip2
lastmjs Mar 6, 2025
af759d7
push up wasi changes
lastmjs Mar 6, 2025
435c238
let us check the clang version
lastmjs Mar 7, 2025
264b8ad
adding wasmtime configuration for wasm32-wasip2
lastmjs Mar 7, 2025
2ecd13d
test
lastmjs Mar 7, 2025
b3dd450
test
lastmjs Mar 7, 2025
0aac390
test
lastmjs Mar 7, 2025
783529e
test
lastmjs Mar 7, 2025
7b2468f
attempt to use the wasmtime action
lastmjs Mar 7, 2025
ce05364
remove wasmtime verification step
lastmjs Mar 7, 2025
48240b9
add back module loader in the main Cargo.toml, fix up the yaml to put…
lastmjs Mar 7, 2025
2c86a2e
remove unnecessary documents
lastmjs Mar 7, 2025
5034881
use the already-existing parallel feature instead of multi-thread
lastmjs Mar 7, 2025
bba2616
fix typo in yaml
lastmjs Mar 7, 2025
a31d27e
fix the yaml
lastmjs Mar 7, 2025
afdd376
fix
lastmjs Mar 7, 2025
f0652f9
SystemTime on wasm32 cannot handle being before the Unix Epoch
lastmjs Mar 7, 2025
02d12d7
forgot to conditionally compile
lastmjs Mar 8, 2025
7cce958
put back old code
lastmjs Mar 8, 2025
58bdbf7
removing wasm32 from the into test for system time
lastmjs Mar 8, 2025
941d3b1
clean up the code
lastmjs Mar 8, 2025
aa24df1
get rid of the comment
lastmjs Mar 8, 2025
be3cf31
update the README
lastmjs Mar 8, 2025
96d47c3
Merge branch 'master' into wasm32-wasip1-wasip2-tests
lastmjs Mar 15, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ jobs:

sanitizer:
runs-on: ubuntu-latest
name: ubuntu / nightly / sanitizer
name: ubuntu / nightly / sanitizer
steps:
- uses: actions/checkout@v4
with:
Expand Down Expand Up @@ -246,14 +246,12 @@ jobs:
os: ubuntu-latest
rust: stable
target: wasm32-wasip1
features: full-async
no-build: true
features: full-async-wasi
- task: bindings
os: ubuntu-latest
rust: nightly
target: wasm32-wasip2
features: full-async
no-build: true
features: full-async-wasi

# Test features
- task: features
Expand Down Expand Up @@ -410,6 +408,9 @@ jobs:
echo 'rustflags = ["-C", "linker=loongarch64-linux-gnu-gcc-14"]' >> ~/.cargo/config.toml

echo "/musl/bin" >> $GITHUB_PATH
- name: Setup wasmtime for wasm32-wasip1 and wasm32-wasip2
if: matrix.target == 'wasm32-wasip1' || matrix.target == 'wasm32-wasip2'
uses: bytecodealliance/actions/wasmtime/setup@v1
- name: Setup msys2 toolchains
if: startsWith(matrix.os, 'windows') && endsWith(matrix.target, '-gnu')
uses: msys2/setup-msys2@v2
Expand Down Expand Up @@ -475,7 +476,7 @@ jobs:
timeout-minutes: 12
env:
RUST_BACKTRACE: full
run: cargo test ${{ matrix.optimization && '--release' || '' }} --all --target ${{ matrix.target }} --no-default-features --features ${{ matrix.features }}
run: ${{ matrix.target == 'wasm32-wasip1' && 'CARGO_TARGET_WASM32_WASIP1_RUNNER=wasmtime' || '' }} ${{ matrix.target == 'wasm32-wasip2' && 'CARGO_TARGET_WASM32_WASIP2_RUNNER=wasmtime' || '' }} cargo test ${{ matrix.optimization && '--release' || '' }} --all ${{ (matrix.target == 'wasm32-wasip1' || matrix.target == 'wasm32-wasip2') && '--exclude module-loader' || '' }} --target ${{ matrix.target }} --no-default-features --features ${{ matrix.features }}

update-bindings:
if: ${{ github.event_name != 'pull_request' && !startsWith(github.ref, 'refs/tags/') }}
Expand Down
17 changes: 7 additions & 10 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,19 +39,17 @@ rquickjs-macro = { workspace = true, optional = true }
default = []

# Almost all features excluding "parallel" and support for async runtimes
full = [
"chrono",
"loader",
"dyn-load",
"either",
"indexmap",
"macro",
"phf",
]
full = ["chrono", "loader", "dyn-load", "either", "indexmap", "macro", "phf"]

# A version of full designed for wasm32-wasip1 and wasm32-wasip2 (simply excludes dyn-load)
full-wasi = ["chrono", "loader", "either", "indexmap", "macro", "phf"]

# Almost all features excluding "parallel"
full-async = ["full", "futures"]

# A version of full-async designed for wasm32-wasip1 and wasm32-wasip2
full-async-wasi = ["full-wasi", "futures"]

# Chrono support.
chrono = ["rquickjs-core/chrono"]

Expand Down Expand Up @@ -82,7 +80,6 @@ dyn-load = ["rquickjs-core/dyn-load"]
rust-alloc = ["rquickjs-core/rust-alloc"]



# Enable helper macros
macro = ["rquickjs-macro"]

Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ See below for a list of supported platforms.
| x86_64-pc-windows-mvsc | ✅ | ✅ | ❌ experimental! |
| x86_64-apple-darwin | ✅ | ✅ | ✅ |
| aarch64-apple-darwin | ✅ | ❌ | ✅ |
| wasm32-wasi | ✅ | ❌ | ✅ |
| wasm32-wasip1 | ✅ | ✅ | ✅ |
| wasm32-wasip2 | ✅ | ✅ | ✅ |
| other | ❌ | ❌ | Unknown |

## License
Expand Down
13 changes: 8 additions & 5 deletions core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,13 @@ relative-path = { version = "1.9", optional = true }


[dev-dependencies]
futures-rs = { package = "futures", version = "0.3"}
tokio = { version = "1.0", default-features = false, features = ["rt", "rt-multi-thread", "time", "macros", "sync"] }
futures-rs = { package = "futures", version = "0.3" }
tokio = { version = "1.0", default-features = false, features = [
"rt",
"time",
"macros",
"sync",
] }
rquickjs.path = "../"
approx = "0.5"
trybuild = "1.0.23"
Expand All @@ -45,7 +50,7 @@ full-async = ["full", "futures"]
bindgen = ["rquickjs-sys/bindgen"]

# Enable support of parallel execution
parallel = []
parallel = ["tokio/rt-multi-thread"]

# Enable user-defined module loader support
loader = ["relative-path"]
Expand Down Expand Up @@ -92,5 +97,3 @@ properties = []
classes = []
array-buffer = []
allocator = []


18 changes: 10 additions & 8 deletions core/src/runtime/async.rs
Original file line number Diff line number Diff line change
Expand Up @@ -346,14 +346,16 @@ macro_rules! async_test_case {
($name:ident => ($rt:ident,$ctx:ident) { $($t:tt)* }) => {
#[test]
fn $name() {
let rt = if cfg!(feature = "parallel") {
tokio::runtime::Builder::new_multi_thread()
} else {
tokio::runtime::Builder::new_current_thread()
}
.enable_all()
.build()
.unwrap();
#[cfg(feature = "parallel")]
let mut new_thread = tokio::runtime::Builder::new_multi_thread();

#[cfg(not(feature = "parallel"))]
let mut new_thread = tokio::runtime::Builder::new_current_thread();

let rt = new_thread
.enable_all()
.build()
.unwrap();

#[cfg(feature = "parallel")]
{
Expand Down
28 changes: 23 additions & 5 deletions core/src/value/convert/from.rs
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,9 @@ chrono_from_js_impls! {

#[cfg(test)]
mod test {
#[cfg(target_arch = "wasm32")]
use super::Error;

#[test]
fn js_to_system_time() {
use crate::{Context, Runtime};
Expand All @@ -426,11 +429,26 @@ mod test {
res.duration_since(SystemTime::UNIX_EPOCH).unwrap()
);

let res: SystemTime = ctx.eval("new Date(-123456789)").unwrap();
assert_eq!(
Duration::from_millis(123456789),
SystemTime::UNIX_EPOCH.duration_since(res).unwrap()
);
#[cfg(not(target_arch = "wasm32"))]
{
let res: SystemTime = ctx.eval("new Date(-123456789)").unwrap();
assert_eq!(
Duration::from_millis(123456789),
SystemTime::UNIX_EPOCH.duration_since(res).unwrap()
);
}

// wasm32-wasip1 and wasm32-wasip2 do not support SystemTime before the Unix Epoch
#[cfg(target_arch = "wasm32")]
{
let res: Error = ctx
.eval::<SystemTime, &str>("new Date(-123456789)")
.unwrap_err();
assert_eq!(
"Error converting from js 'Date' into type 'SystemTime': Timestamp too small",
res.to_string()
);
}
});
}

Expand Down
33 changes: 20 additions & 13 deletions core/src/value/convert/into.rs
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,9 @@ mod test {
#[test]
fn system_time_to_js() {
use crate::{Context, IntoJs, Runtime};
use std::time::{Duration, SystemTime};
#[cfg(not(target_arch = "wasm32"))]
use std::time::Duration;
use std::time::SystemTime;

let runtime = Runtime::new().unwrap();
let ctx = Context::full(&runtime).unwrap();
Expand All @@ -563,18 +565,23 @@ mod test {
assert_eq!(millis, res as _);
});

let ts = SystemTime::UNIX_EPOCH - Duration::from_millis(123456);
let millis = SystemTime::UNIX_EPOCH
.duration_since(ts)
.unwrap()
.as_millis();

ctx.with(|ctx| {
let globs = ctx.globals();
globs.set("ts", ts.into_js(&ctx).unwrap()).unwrap();
let res: i64 = ctx.eval("ts.getTime()").unwrap();
assert_eq!(-(millis as i64), res as _);
});
// wasm32-wasip1 and wasm32-wasip2 do not support SystemTime before the Unix epoch.
// The subtraction from the Unix epoch would panic with: overflow when subtracting duration from instant
#[cfg(not(target_arch = "wasm32"))]
{
let ts = SystemTime::UNIX_EPOCH - Duration::from_millis(123456);
let millis = SystemTime::UNIX_EPOCH
.duration_since(ts)
.unwrap()
.as_millis();

ctx.with(|ctx| {
let globs = ctx.globals();
globs.set("ts", ts.into_js(&ctx).unwrap()).unwrap();
let res: i64 = ctx.eval("ts.getTime()").unwrap();
assert_eq!(-(millis as i64), res as _);
});
}
}

#[cfg(feature = "chrono")]
Expand Down
66 changes: 56 additions & 10 deletions tests/compile.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,58 @@
#[cfg(target_arch = "wasm32")]
#[path = "macros/pass_class.rs"]
pub mod pass_class;

#[cfg(target_arch = "wasm32")]
#[path = "macros/pass_method.rs"]
pub mod pass_method;

#[cfg(target_arch = "wasm32")]
#[path = "macros/pass_module.rs"]
pub mod pass_module;

#[cfg(target_arch = "wasm32")]
#[path = "macros/pass_trace.rs"]
pub mod pass_trace;

#[cfg(feature = "macro")]
#[test]
fn macros() {
let t = trybuild::TestCases::new();
t.pass("tests/macros/pass_*.rs");
#[cfg(feature = "compile-tests")]
t.compile_fail("tests/compile_fail/*.rs");
#[cfg(all(feature = "futures", feature = "compile-tests"))]
t.compile_fail("tests/async_compile_fail/*.rs");
#[cfg(all(feature = "futures", feature = "parallel", feature = "compile-tests"))]
t.compile_fail("tests/async_parallel_compile_fail/*.rs");
mod macro_tests {
#[cfg(target_arch = "wasm32")]
use crate::{pass_class, pass_method, pass_module, pass_trace};

#[cfg(not(target_arch = "wasm32"))]
#[test]
fn macros() {
let t = trybuild::TestCases::new();
t.pass("tests/macros/pass_*.rs");
#[cfg(feature = "compile-tests")]
t.compile_fail("tests/compile_fail/*.rs");
#[cfg(all(feature = "futures", feature = "compile-tests"))]
t.compile_fail("tests/async_compile_fail/*.rs");
#[cfg(all(feature = "futures", feature = "parallel", feature = "compile-tests"))]
t.compile_fail("tests/async_parallel_compile_fail/*.rs");
}

#[cfg(target_arch = "wasm32")]
#[test]
fn macros_pass_class() {
pass_class::main();
}

#[cfg(target_arch = "wasm32")]
#[test]
fn macros_pass_method() {
pass_method::main();
}

#[cfg(target_arch = "wasm32")]
#[test]
fn macros_pass_module() {
pass_module::main();
}

#[cfg(target_arch = "wasm32")]
#[test]
fn macros_pass_trace() {
pass_trace::main();
}
}
2 changes: 1 addition & 1 deletion tests/macros/pass_module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ mod test_mod {
}
}

fn main() {
pub fn main() {
assert_eq!(test_mod::ignore_function(), 4);
let rt = Runtime::new().unwrap();
let ctx = Context::full(&rt).unwrap();
Expand Down
2 changes: 1 addition & 1 deletion tests/macros/pass_trace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ impl<'js> JsClass<'js> for TraceEnum {
}
}

fn main() {
pub fn main() {
let rt = Runtime::new().unwrap();
let ctx = Context::full(&rt).unwrap();

Expand Down
Loading