Skip to content

Commit

Permalink
Add CI for wasm targets using wasm-bindgen (rust-lang#20)
Browse files Browse the repository at this point in the history
  • Loading branch information
KodrAus committed Oct 3, 2020
1 parent 19c8529 commit 0fbf64b
Show file tree
Hide file tree
Showing 7 changed files with 186 additions and 0 deletions.
24 changes: 24 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,30 @@ matrix:
arch: amd64
env:
- TARGET=x86_64-apple-darwin

# WebAssembly (wasm-bindgen)

- name: "wasm32-unknown-unknown (node, firefox, chrome)"
os: linux
arch: amd64
addons:
firefox: latest
chrome : stable
install:
- curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh
script:
- wasm-pack test --node --firefox --chrome --headless crates/core_simd

- name: "wasm32-unknown-unknown+simd128 (chrome)"
os: linux
arch: amd64
addons:
chrome : stable
install:
- curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh
script:
- RUSTFLAGS="-C target-feature=+simd128"
- wasm-pack test --chrome --headless crates/core_simd

script:
- rustup target add $TARGET
Expand Down
6 changes: 6 additions & 0 deletions crates/core_simd/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,9 @@ repository = "https://github.com/rust-lang/stdsimd"
keywords = ["core", "simd", "intrinsics"]
categories = ["hardware-support", "no-std"]
license = "MIT OR Apache-2.0"

[target.'cfg(target_arch = "wasm32")'.dependencies.wasm-bindgen]
version = "0.2"

[dev-dependencies.wasm-bindgen-test]
version = "0.3"
32 changes: 32 additions & 0 deletions crates/core_simd/tests/ops_impl/float_macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ macro_rules! float_tests {
use super::*;
use helpers::lanewise::*;

#[cfg(target_arch = "wasm32")]
use wasm_bindgen_test::*;

#[cfg(target_arch = "wasm32")]
wasm_bindgen_test_configure!(run_in_browser);

// TODO impl this as an associated fn on vectors
fn from_slice(slice: &[$scalar]) -> core_simd::$vector {
let mut value = core_simd::$vector::default();
Expand All @@ -17,6 +23,7 @@ macro_rules! float_tests {
const B: [$scalar; 16] = [16., 17., 18., 19., 20., 21., 22., 23., 24., 25., 26., 27., 28., 29., 30., 31.];

#[test]
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)]
fn add() {
let a = from_slice(&A);
let b = from_slice(&B);
Expand All @@ -25,6 +32,7 @@ macro_rules! float_tests {
}

#[test]
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)]
fn add_assign() {
let mut a = from_slice(&A);
let b = from_slice(&B);
Expand All @@ -34,6 +42,7 @@ macro_rules! float_tests {
}

#[test]
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)]
fn add_scalar_rhs() {
let a = from_slice(&A);
let b = 5.;
Expand All @@ -42,6 +51,7 @@ macro_rules! float_tests {
}

#[test]
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)]
fn add_scalar_lhs() {
let a = 5.;
let b = from_slice(&B);
Expand All @@ -50,6 +60,7 @@ macro_rules! float_tests {
}

#[test]
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)]
fn add_assign_scalar() {
let mut a = from_slice(&A);
let b = 5.;
Expand All @@ -59,6 +70,7 @@ macro_rules! float_tests {
}

#[test]
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)]
fn sub() {
let a = from_slice(&A);
let b = from_slice(&B);
Expand All @@ -67,6 +79,7 @@ macro_rules! float_tests {
}

#[test]
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)]
fn sub_assign() {
let mut a = from_slice(&A);
let b = from_slice(&B);
Expand All @@ -76,6 +89,7 @@ macro_rules! float_tests {
}

#[test]
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)]
fn sub_scalar_rhs() {
let a = from_slice(&A);
let b = 5.;
Expand All @@ -84,6 +98,7 @@ macro_rules! float_tests {
}

#[test]
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)]
fn sub_scalar_lhs() {
let a = 5.;
let b = from_slice(&B);
Expand All @@ -92,6 +107,7 @@ macro_rules! float_tests {
}

#[test]
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)]
fn sub_assign_scalar() {
let mut a = from_slice(&A);
let b = 5.;
Expand All @@ -101,6 +117,7 @@ macro_rules! float_tests {
}

#[test]
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)]
fn mul() {
let a = from_slice(&A);
let b = from_slice(&B);
Expand All @@ -109,6 +126,7 @@ macro_rules! float_tests {
}

#[test]
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)]
fn mul_assign() {
let mut a = from_slice(&A);
let b = from_slice(&B);
Expand All @@ -118,6 +136,7 @@ macro_rules! float_tests {
}

#[test]
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)]
fn mul_scalar_rhs() {
let a = from_slice(&A);
let b = 5.;
Expand All @@ -126,6 +145,7 @@ macro_rules! float_tests {
}

#[test]
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)]
fn mul_scalar_lhs() {
let a = 5.;
let b = from_slice(&B);
Expand All @@ -134,6 +154,7 @@ macro_rules! float_tests {
}

#[test]
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)]
fn mul_assign_scalar() {
let mut a = from_slice(&A);
let b = 5.;
Expand All @@ -143,6 +164,7 @@ macro_rules! float_tests {
}

#[test]
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)]
fn div() {
let a = from_slice(&A);
let b = from_slice(&B);
Expand All @@ -151,6 +173,7 @@ macro_rules! float_tests {
}

#[test]
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)]
fn div_assign() {
let mut a = from_slice(&A);
let b = from_slice(&B);
Expand All @@ -160,6 +183,7 @@ macro_rules! float_tests {
}

#[test]
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)]
fn div_scalar_rhs() {
let a = from_slice(&A);
let b = 5.;
Expand All @@ -168,6 +192,7 @@ macro_rules! float_tests {
}

#[test]
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)]
fn div_scalar_lhs() {
let a = 5.;
let b = from_slice(&B);
Expand All @@ -176,6 +201,7 @@ macro_rules! float_tests {
}

#[test]
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)]
fn div_assign_scalar() {
let mut a = from_slice(&A);
let b = 5.;
Expand All @@ -185,6 +211,7 @@ macro_rules! float_tests {
}

#[test]
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)]
fn rem() {
let a = from_slice(&A);
let b = from_slice(&B);
Expand All @@ -193,6 +220,7 @@ macro_rules! float_tests {
}

#[test]
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)]
fn rem_assign() {
let mut a = from_slice(&A);
let b = from_slice(&B);
Expand All @@ -202,6 +230,7 @@ macro_rules! float_tests {
}

#[test]
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)]
fn rem_scalar_rhs() {
let a = from_slice(&A);
let b = 5.;
Expand All @@ -210,6 +239,7 @@ macro_rules! float_tests {
}

#[test]
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)]
fn rem_scalar_lhs() {
let a = 5.;
let b = from_slice(&B);
Expand All @@ -218,6 +248,7 @@ macro_rules! float_tests {
}

#[test]
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)]
fn rem_assign_scalar() {
let mut a = from_slice(&A);
let b = 5.;
Expand All @@ -227,6 +258,7 @@ macro_rules! float_tests {
}

#[test]
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)]
fn neg() {
let v = from_slice(&A);
let expected = apply_unary_lanewise(v, core::ops::Neg::neg);
Expand Down
Loading

0 comments on commit 0fbf64b

Please sign in to comment.