Skip to content
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

Run tests w/ fallback on wasm32-unknown-unknown #1114

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
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
12 changes: 8 additions & 4 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -61,8 +61,9 @@ jobs:
- run: cargo test --verbose --package rayon
- run: cargo test --verbose --package rayon-core

# wasm32-unknown-unknown builds, and even has the runtime fallback for
# unsupported threading, but we don't have an environment to execute in.
# wasm32-unknown-unknown has a runtime fallback for unsupported threading.
# Proper threading needs more glue and is tested in wasm-bindgen-rayon,
# but we can at least verify that all tests can run on Wasm with the fallback.
wasm:
name: WebAssembly (standalone)
runs-on: ubuntu-latest
@@ -71,7 +72,8 @@ jobs:
include:
- toolchain: stable
- toolchain: nightly
cargoflags: --features web_spin_lock
components: rust-src
cargoflags: -Z build-std=panic_abort,std --features web_spin_lock
rustflags: -C target-feature=+atomics,+bulk-memory,+mutable-globals
env:
RUSTFLAGS: ${{ matrix.rustflags }}
@@ -80,8 +82,10 @@ jobs:
- uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{ matrix.toolchain }}
components: ${{ matrix.components }}
targets: wasm32-unknown-unknown
- run: cargo build --verbose --target wasm32-unknown-unknown ${{ matrix.cargoflags }}
- uses: jetli/wasm-pack-action@v0.4.0
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm wary of adding 3rd-party github actions -- can we just use the official installer like I did for wasmtime below?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a reasonably popular action, but, sure, we can use official installer too, especially since wasm-pack provides prebuilt binaries and doesn't need recompilation from source.

- run: wasm-pack test --chrome --headless -- --verbose ${{ matrix.cargoflags }}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we also test rayon-core?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm probably.


# wasm32-wasi can test the fallback by running in wasmtime.
wasi:
5 changes: 5 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -37,3 +37,8 @@ web_spin_lock = ["dep:wasm_sync", "rayon-core/web_spin_lock"]
[dev-dependencies]
rand = "0.8"
rand_xorshift = "0.3"

# Test dependencies for wasm32-unknown-unknown with wasm-bindgen.
[target.'cfg(all(target_arch = "wasm32", target_os = "unknown"))'.dev-dependencies]
getrandom = { version = "0.2", features = ["js"] }
wasm-bindgen-test = "0.3"
39 changes: 39 additions & 0 deletions ci/compat-Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions tests/chars.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
use rayon::prelude::*;
use std::char;

#[cfg(all(target_arch = "wasm32", target_os = "unknown"))]
use wasm_bindgen_test::wasm_bindgen_test as test;

#[cfg(all(target_arch = "wasm32", target_os = "unknown"))]
wasm_bindgen_test::wasm_bindgen_test_configure!(run_in_browser);

#[test]
fn half_open_correctness() {
let low = char::from_u32(0xD800 - 0x7).unwrap();
6 changes: 6 additions & 0 deletions tests/clones.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
use rayon::prelude::*;

#[cfg(all(target_arch = "wasm32", target_os = "unknown"))]
use wasm_bindgen_test::wasm_bindgen_test as test;

#[cfg(all(target_arch = "wasm32", target_os = "unknown"))]
wasm_bindgen_test::wasm_bindgen_test_configure!(run_in_browser);

fn check<I>(iter: I)
where
I: ParallelIterator + Clone,
6 changes: 6 additions & 0 deletions tests/collect.rs
Original file line number Diff line number Diff line change
@@ -5,6 +5,12 @@ use std::sync::atomic::AtomicUsize;
use std::sync::atomic::Ordering;
use std::sync::Mutex;

#[cfg(all(target_arch = "wasm32", target_os = "unknown"))]
use wasm_bindgen_test::wasm_bindgen_test as test;

#[cfg(all(target_arch = "wasm32", target_os = "unknown"))]
wasm_bindgen_test::wasm_bindgen_test_configure!(run_in_browser);

#[test]
#[cfg_attr(not(panic = "unwind"), ignore)]
fn collect_drop_on_unwind() {
6 changes: 6 additions & 0 deletions tests/cross-pool.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
use rayon::prelude::*;
use rayon::ThreadPoolBuilder;

#[cfg(all(target_arch = "wasm32", target_os = "unknown"))]
use wasm_bindgen_test::wasm_bindgen_test as test;

#[cfg(all(target_arch = "wasm32", target_os = "unknown"))]
wasm_bindgen_test::wasm_bindgen_test_configure!(run_in_browser);

#[test]
#[cfg_attr(any(target_os = "emscripten", target_family = "wasm"), ignore)]
fn cross_pool_busy() {
6 changes: 6 additions & 0 deletions tests/debug.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
use rayon::prelude::*;
use std::fmt::Debug;

#[cfg(all(target_arch = "wasm32", target_os = "unknown"))]
use wasm_bindgen_test::wasm_bindgen_test as test;

#[cfg(all(target_arch = "wasm32", target_os = "unknown"))]
wasm_bindgen_test::wasm_bindgen_test_configure!(run_in_browser);

fn check<I>(iter: I)
where
I: ParallelIterator + Debug,
6 changes: 6 additions & 0 deletions tests/drain_vec.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
use rayon::prelude::*;

#[cfg(all(target_arch = "wasm32", target_os = "unknown"))]
use wasm_bindgen_test::wasm_bindgen_test as test;

#[cfg(all(target_arch = "wasm32", target_os = "unknown"))]
wasm_bindgen_test::wasm_bindgen_test_configure!(run_in_browser);

#[test]
fn drain_vec_yielded() {
let mut vec_org = vec![0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
6 changes: 6 additions & 0 deletions tests/intersperse.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
use rayon::prelude::*;

#[cfg(all(target_arch = "wasm32", target_os = "unknown"))]
use wasm_bindgen_test::wasm_bindgen_test as test;

#[cfg(all(target_arch = "wasm32", target_os = "unknown"))]
wasm_bindgen_test::wasm_bindgen_test_configure!(run_in_browser);

#[test]
fn check_intersperse() {
let v: Vec<_> = (0..1000).into_par_iter().intersperse(-1).collect();
6 changes: 6 additions & 0 deletions tests/issue671-unzip.rs
Original file line number Diff line number Diff line change
@@ -2,6 +2,12 @@

use rayon::prelude::*;

#[cfg(all(target_arch = "wasm32", target_os = "unknown"))]
use wasm_bindgen_test::wasm_bindgen_test as test;

#[cfg(all(target_arch = "wasm32", target_os = "unknown"))]
wasm_bindgen_test::wasm_bindgen_test_configure!(run_in_browser);

#[test]
fn type_length_limit() {
let input = vec![1, 2, 3, 4, 5];
6 changes: 6 additions & 0 deletions tests/issue671.rs
Original file line number Diff line number Diff line change
@@ -2,6 +2,12 @@

use rayon::prelude::*;

#[cfg(all(target_arch = "wasm32", target_os = "unknown"))]
use wasm_bindgen_test::wasm_bindgen_test as test;

#[cfg(all(target_arch = "wasm32", target_os = "unknown"))]
wasm_bindgen_test::wasm_bindgen_test_configure!(run_in_browser);

#[test]
fn type_length_limit() {
let _ = Vec::<Result<(), ()>>::new()
6 changes: 6 additions & 0 deletions tests/iter_panic.rs
Original file line number Diff line number Diff line change
@@ -4,6 +4,12 @@ use std::ops::Range;
use std::panic::{self, UnwindSafe};
use std::sync::atomic::{AtomicUsize, Ordering};

#[cfg(all(target_arch = "wasm32", target_os = "unknown"))]
use wasm_bindgen_test::wasm_bindgen_test as test;

#[cfg(all(target_arch = "wasm32", target_os = "unknown"))]
wasm_bindgen_test::wasm_bindgen_test_configure!(run_in_browser);

const ITER: Range<i32> = 0..0x1_0000;
const PANIC: i32 = 0xC000;

6 changes: 6 additions & 0 deletions tests/named-threads.rs
Original file line number Diff line number Diff line change
@@ -3,6 +3,12 @@ use std::collections::HashSet;
use rayon::prelude::*;
use rayon::*;

#[cfg(all(target_arch = "wasm32", target_os = "unknown"))]
use wasm_bindgen_test::wasm_bindgen_test as test;

#[cfg(all(target_arch = "wasm32", target_os = "unknown"))]
wasm_bindgen_test::wasm_bindgen_test_configure!(run_in_browser);

#[test]
#[cfg_attr(any(target_os = "emscripten", target_family = "wasm"), ignore)]
fn named_threads() {
6 changes: 6 additions & 0 deletions tests/octillion.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
use rayon::prelude::*;

#[cfg(all(target_arch = "wasm32", target_os = "unknown"))]
use wasm_bindgen_test::wasm_bindgen_test as test;

#[cfg(all(target_arch = "wasm32", target_os = "unknown"))]
wasm_bindgen_test::wasm_bindgen_test_configure!(run_in_browser);

const OCTILLION: u128 = 1_000_000_000_000_000_000_000_000_000;

/// Produce a parallel iterator for 0u128..10²⁷
6 changes: 6 additions & 0 deletions tests/par_bridge_recursion.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
use rayon::prelude::*;
use std::iter::once_with;

#[cfg(all(target_arch = "wasm32", target_os = "unknown"))]
use wasm_bindgen_test::wasm_bindgen_test as test;

#[cfg(all(target_arch = "wasm32", target_os = "unknown"))]
wasm_bindgen_test::wasm_bindgen_test_configure!(run_in_browser);

const N: usize = 100_000;

#[test]
6 changes: 6 additions & 0 deletions tests/producer_split_at.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
use rayon::iter::plumbing::*;
use rayon::prelude::*;

#[cfg(all(target_arch = "wasm32", target_os = "unknown"))]
use wasm_bindgen_test::wasm_bindgen_test as test;

#[cfg(all(target_arch = "wasm32", target_os = "unknown"))]
wasm_bindgen_test::wasm_bindgen_test_configure!(run_in_browser);

/// Stress-test indexes for `Producer::split_at`.
fn check<F, I>(expected: &[I::Item], mut f: F)
where
6 changes: 6 additions & 0 deletions tests/sort-panic-safe.rs
Original file line number Diff line number Diff line change
@@ -8,6 +8,12 @@ use std::sync::atomic::AtomicUsize;
use std::sync::atomic::Ordering::Relaxed;
use std::thread;

#[cfg(all(target_arch = "wasm32", target_os = "unknown"))]
use wasm_bindgen_test::wasm_bindgen_test as test;

#[cfg(all(target_arch = "wasm32", target_os = "unknown"))]
wasm_bindgen_test::wasm_bindgen_test_configure!(run_in_browser);

const ZERO: AtomicUsize = AtomicUsize::new(0);
const LEN: usize = 20_000;

6 changes: 6 additions & 0 deletions tests/str.rs
Original file line number Diff line number Diff line change
@@ -3,6 +3,12 @@ use rand::{Rng, SeedableRng};
use rand_xorshift::XorShiftRng;
use rayon::prelude::*;

#[cfg(all(target_arch = "wasm32", target_os = "unknown"))]
use wasm_bindgen_test::wasm_bindgen_test as test;

#[cfg(all(target_arch = "wasm32", target_os = "unknown"))]
wasm_bindgen_test::wasm_bindgen_test_configure!(run_in_browser);

fn seeded_rng() -> XorShiftRng {
let mut seed = <XorShiftRng as SeedableRng>::Seed::default();
(0..).zip(seed.as_mut()).for_each(|(i, x)| *x = i);