File tree 7 files changed +40
-30
lines changed
7 files changed +40
-30
lines changed Original file line number Diff line number Diff line change @@ -16,8 +16,7 @@ appveyor = { repository = "rust-random/getrandom" }
16
16
17
17
[workspace ]
18
18
members = [
19
- " custom/stdweb" ,
20
- " custom/wasm-bindgen" ,
19
+ " custom/js" ,
21
20
]
22
21
23
22
[dependencies ]
Original file line number Diff line number Diff line change 1
1
[package ]
2
- name = " wasm-bindgen- getrandom"
2
+ name = " getrandom-js "
3
3
version = " 0.1.0"
4
4
edition = " 2018"
5
5
authors = [" The Rand Project Developers" ]
6
6
license = " MIT OR Apache-2.0"
7
- description = " Custom shim for using getrandom with wasm-bindgen "
8
- documentation = " https://docs.rs/wasm-bindgen- getrandom"
7
+ description = " Custom shim for using getrandom with JavaScript "
8
+ documentation = " https://docs.rs/getrandom-js "
9
9
repository = " https://github.com/rust-random/getrandom"
10
10
categories = [" wasm" ]
11
11
12
12
[dependencies ]
13
13
getrandom = { path = " ../.." , version = " 0.2" , features = [" custom" ] }
14
- wasm-bindgen = " 0.2.46 "
14
+ cfg-if = " 0.1.2 "
15
15
16
- [dev-dependencies ]
17
- wasm-bindgen-test = " 0.2.46"
16
+ [target .'cfg(cargo_web)' .dependencies ]
17
+ stdweb = " 0.4.18"
18
+
19
+ [target .'cfg(not(cargo_web))' .dependencies ]
20
+ wasm-bindgen = " 0.2.62"
21
+
22
+ [target .'cfg(not(cargo_web))' .dev-dependencies ]
23
+ wasm-bindgen-test = " 0.3.12"
18
24
19
25
[package .metadata .docs .rs ]
20
26
default-target = " wasm32-unknown-unknown"
Original file line number Diff line number Diff line change
1
+ // Necessary to work around complex macros in stdweb
2
+ #![ cfg_attr( cargo_web, recursion_limit = "128" ) ]
3
+
4
+ #[ cfg( not( all( target_arch = "wasm32" , target_os = "unknown" ) ) ) ]
5
+ compile_error ! ( "This crate is only for the `wasm32-unknown-unknown` target" ) ;
6
+
7
+ #[ cfg_attr( cargo_web, path = "stdweb.rs" ) ]
8
+ #[ cfg_attr( not( cargo_web) , path = "wasm-bindgen.rs" ) ]
9
+ mod imp;
10
+
11
+ getrandom:: register_custom_getrandom!( imp:: getrandom_inner) ;
Original file line number Diff line number Diff line change 5
5
// <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your
6
6
// option. This file may not be copied, modified, or distributed
7
7
// except according to those terms.
8
-
9
- #![ recursion_limit = "128" ]
10
- #[ cfg( not( all( target_arch = "wasm32" , target_os = "unknown" ) ) ) ]
11
- compile_error ! ( "This crate is only for the `wasm32-unknown-unknown` target" ) ;
12
-
13
8
use std:: thread_local;
14
9
15
10
use stdweb:: js;
16
11
17
- use getrandom:: { register_custom_getrandom , Error } ;
12
+ use getrandom:: Error ;
18
13
19
14
#[ derive( Clone , Copy , PartialEq ) ]
20
15
enum RngSource {
@@ -26,9 +21,7 @@ thread_local!(
26
21
static RNG_SOURCE : Result <RngSource , Error > = getrandom_init( ) ;
27
22
) ;
28
23
29
- register_custom_getrandom ! ( getrandom_inner) ;
30
-
31
- fn getrandom_inner ( dest : & mut [ u8 ] ) -> Result < ( ) , Error > {
24
+ pub ( crate ) fn getrandom_inner ( dest : & mut [ u8 ] ) -> Result < ( ) , Error > {
32
25
RNG_SOURCE . with ( |& source| getrandom_fill ( source?, dest) )
33
26
}
34
27
Original file line number Diff line number Diff line change 5
5
// <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your
6
6
// option. This file may not be copied, modified, or distributed
7
7
// except according to those terms.
8
-
9
- #[ cfg( not( all( target_arch = "wasm32" , target_os = "unknown" ) ) ) ]
10
- compile_error ! ( "This crate is only for the `wasm32-unknown-unknown` target" ) ;
11
-
12
8
use std:: thread_local;
13
9
14
10
use wasm_bindgen:: prelude:: * ;
15
11
16
- use getrandom:: { register_custom_getrandom , Error } ;
12
+ use getrandom:: Error ;
17
13
18
14
enum RngSource {
19
15
Node ( NodeCrypto ) ,
@@ -26,9 +22,7 @@ thread_local!(
26
22
static RNG_SOURCE : Result <RngSource , Error > = getrandom_init( ) ;
27
23
) ;
28
24
29
- register_custom_getrandom ! ( getrandom_inner) ;
30
-
31
- fn getrandom_inner ( dest : & mut [ u8 ] ) -> Result < ( ) , Error > {
25
+ pub ( crate ) fn getrandom_inner ( dest : & mut [ u8 ] ) -> Result < ( ) , Error > {
32
26
RNG_SOURCE . with ( |result| {
33
27
let source = result. as_ref ( ) . map_err ( |& e| e) ?;
34
28
Original file line number Diff line number Diff line change 1
1
// Explicitly use the Custom RNG crate to link it in.
2
- use wasm_bindgen_getrandom as _;
3
-
4
2
use getrandom:: getrandom;
3
+ use getrandom_js as _;
4
+
5
+ // We don't use wasm_bindgen when building with cargo web
6
+ #[ cfg( cargo_web) ]
7
+ use test;
8
+ #[ cfg( not( cargo_web) ) ]
5
9
use wasm_bindgen_test:: wasm_bindgen_test as test;
10
+
6
11
#[ path = "../../../src/test_common.rs" ]
7
12
mod test_common;
Original file line number Diff line number Diff line change
1
+ // Don't use the wasm_bindgen browser framework with cargo web
2
+ #![ cfg( not( cargo_web) ) ]
1
3
// Explicitly use the Custom RNG crate to link it in.
2
- use wasm_bindgen_getrandom as _;
4
+ use getrandom:: getrandom;
5
+ use getrandom_js as _;
3
6
4
7
wasm_bindgen_test:: wasm_bindgen_test_configure!( run_in_browser) ;
5
-
6
- use getrandom:: getrandom;
7
8
use wasm_bindgen_test:: wasm_bindgen_test as test;
9
+
8
10
#[ path = "../../../src/test_common.rs" ]
9
11
mod test_common;
You can’t perform that action at this time.
0 commit comments