Skip to content

Commit 0fbf64b

Browse files
authored
Add CI for wasm targets using wasm-bindgen (rust-lang#20)
1 parent 19c8529 commit 0fbf64b

File tree

7 files changed

+186
-0
lines changed

7 files changed

+186
-0
lines changed

.travis.yml

+24
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,30 @@ matrix:
230230
arch: amd64
231231
env:
232232
- TARGET=x86_64-apple-darwin
233+
234+
# WebAssembly (wasm-bindgen)
235+
236+
- name: "wasm32-unknown-unknown (node, firefox, chrome)"
237+
os: linux
238+
arch: amd64
239+
addons:
240+
firefox: latest
241+
chrome : stable
242+
install:
243+
- curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh
244+
script:
245+
- wasm-pack test --node --firefox --chrome --headless crates/core_simd
246+
247+
- name: "wasm32-unknown-unknown+simd128 (chrome)"
248+
os: linux
249+
arch: amd64
250+
addons:
251+
chrome : stable
252+
install:
253+
- curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh
254+
script:
255+
- RUSTFLAGS="-C target-feature=+simd128"
256+
- wasm-pack test --chrome --headless crates/core_simd
233257

234258
script:
235259
- rustup target add $TARGET

crates/core_simd/Cargo.toml

+6
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,9 @@ repository = "https://github.com/rust-lang/stdsimd"
88
keywords = ["core", "simd", "intrinsics"]
99
categories = ["hardware-support", "no-std"]
1010
license = "MIT OR Apache-2.0"
11+
12+
[target.'cfg(target_arch = "wasm32")'.dependencies.wasm-bindgen]
13+
version = "0.2"
14+
15+
[dev-dependencies.wasm-bindgen-test]
16+
version = "0.3"

crates/core_simd/tests/ops_impl/float_macros.rs

+32
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ macro_rules! float_tests {
55
use super::*;
66
use helpers::lanewise::*;
77

8+
#[cfg(target_arch = "wasm32")]
9+
use wasm_bindgen_test::*;
10+
11+
#[cfg(target_arch = "wasm32")]
12+
wasm_bindgen_test_configure!(run_in_browser);
13+
814
// TODO impl this as an associated fn on vectors
915
fn from_slice(slice: &[$scalar]) -> core_simd::$vector {
1016
let mut value = core_simd::$vector::default();
@@ -17,6 +23,7 @@ macro_rules! float_tests {
1723
const B: [$scalar; 16] = [16., 17., 18., 19., 20., 21., 22., 23., 24., 25., 26., 27., 28., 29., 30., 31.];
1824

1925
#[test]
26+
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)]
2027
fn add() {
2128
let a = from_slice(&A);
2229
let b = from_slice(&B);
@@ -25,6 +32,7 @@ macro_rules! float_tests {
2532
}
2633

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

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

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

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

6172
#[test]
73+
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)]
6274
fn sub() {
6375
let a = from_slice(&A);
6476
let b = from_slice(&B);
@@ -67,6 +79,7 @@ macro_rules! float_tests {
6779
}
6880

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

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

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

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

103119
#[test]
120+
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)]
104121
fn mul() {
105122
let a = from_slice(&A);
106123
let b = from_slice(&B);
@@ -109,6 +126,7 @@ macro_rules! float_tests {
109126
}
110127

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

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

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

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

145166
#[test]
167+
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)]
146168
fn div() {
147169
let a = from_slice(&A);
148170
let b = from_slice(&B);
@@ -151,6 +173,7 @@ macro_rules! float_tests {
151173
}
152174

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

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

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

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

187213
#[test]
214+
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)]
188215
fn rem() {
189216
let a = from_slice(&A);
190217
let b = from_slice(&B);
@@ -193,6 +220,7 @@ macro_rules! float_tests {
193220
}
194221

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

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

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

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

229260
#[test]
261+
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)]
230262
fn neg() {
231263
let v = from_slice(&A);
232264
let expected = apply_unary_lanewise(v, core::ops::Neg::neg);

0 commit comments

Comments
 (0)