File tree 5 files changed +71
-0
lines changed
5 files changed +71
-0
lines changed Original file line number Diff line number Diff line change @@ -142,6 +142,8 @@ matrix:
142
142
- ./utils/ci/install_cargo_web.sh
143
143
- cargo web prepare-emscripten
144
144
- cargo web -V
145
+ - cargo list | grep install-update || cargo install -f cargo-update
146
+ - cargo install-update -i cargo-update wasm-bindgen-cli wasm-pack
145
147
addons :
146
148
chrome : stable
147
149
script :
@@ -154,6 +156,10 @@ matrix:
154
156
# - cargo build --target wasm32-unknown-unknown # without any features
155
157
- cargo build --target wasm32-unknown-unknown --features=wasm-bindgen
156
158
- cargo web test --target wasm32-unknown-unknown --features=stdweb
159
+ - cargo build --manifest-path tests/wasm_bindgen/Cargo.toml --target wasm32-unknown-unknown
160
+ - wasm-bindgen --nodejs target/wasm32-unknown-unknown/debug/rand_wasm_bindgen_test.wasm --out-dir tests/wasm_bindgen/js
161
+ - node tests/wasm_bindgen/js/index.js
162
+ - wasm-pack test --node tests/wasm_bindgen
157
163
158
164
- rust : nightly
159
165
env : DESCRIPTION="cross-platform builder (doesn't run tests)"
Original file line number Diff line number Diff line change @@ -42,6 +42,7 @@ members = [
42
42
" rand_pcg" ,
43
43
" rand_xorshift" ,
44
44
" rand_xoshiro" ,
45
+ " tests/wasm_bindgen" ,
45
46
]
46
47
47
48
[dependencies ]
Original file line number Diff line number Diff line change
1
+ [package ]
2
+ name = " rand_wasm_bindgen_test"
3
+ description = " Minimal crate to test that rand can be build for web assembly target"
4
+ version = " 0.1.0"
5
+ authors = [" The Rand Project Developers" ]
6
+ publish = false
7
+ license = " MIT/Apache-2.0"
8
+
9
+ [lib ]
10
+ crate-type = [" cdylib" ]
11
+
12
+ [dependencies ]
13
+ rand = { path = " ../.." , features = [" wasm-bindgen" ] }
14
+ wasm-bindgen = " 0.2"
15
+ wasm-bindgen-test = " 0.2"
Original file line number Diff line number Diff line change
1
+ 'use strict' ;
2
+
3
+ const rand_wasm_bindgen_test = require ( './rand_wasm_bindgen_test' ) ;
4
+
5
+ console . log ( rand_wasm_bindgen_test . generate_from_entropy ( ) ) ;
6
+ console . log ( rand_wasm_bindgen_test . generate_from_os_rand ( ) ) ;
7
+ console . log ( rand_wasm_bindgen_test . generate_from_seed ( ) ) ;
Original file line number Diff line number Diff line change
1
+ extern crate rand;
2
+ extern crate wasm_bindgen;
3
+ extern crate wasm_bindgen_test;
4
+
5
+ use rand:: rngs:: { OsRng , StdRng } ;
6
+ use rand:: FromEntropy ;
7
+ use rand:: { Rng , SeedableRng } ;
8
+ use wasm_bindgen:: prelude:: * ;
9
+
10
+ #[ wasm_bindgen]
11
+ pub fn generate_from_seed ( seed : u32 ) -> i32 {
12
+ StdRng :: seed_from_u64 ( seed as u64 ) . gen ( )
13
+ }
14
+
15
+ #[ wasm_bindgen]
16
+ pub fn generate_from_os_rand ( ) -> i32 {
17
+ OsRng :: new ( ) . unwrap ( ) . gen ( )
18
+ }
19
+
20
+ #[ wasm_bindgen]
21
+ pub fn generate_from_entropy ( ) -> i32 {
22
+ StdRng :: from_entropy ( ) . gen ( )
23
+ }
24
+
25
+ pub mod tests {
26
+ use wasm_bindgen_test:: * ;
27
+
28
+ #[ wasm_bindgen_test]
29
+ fn generate_from_seed ( ) {
30
+ let _ = super :: generate_from_seed ( 42 ) ;
31
+ }
32
+
33
+ #[ wasm_bindgen_test]
34
+ fn generate_from_os_rand ( ) {
35
+ let _ = super :: generate_from_os_rand ( ) ;
36
+ }
37
+
38
+ #[ wasm_bindgen_test]
39
+ fn generate_from_entropy ( ) {
40
+ let _ = super :: generate_from_entropy ( ) ;
41
+ }
42
+ }
You can’t perform that action at this time.
0 commit comments