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

Comment on WASM targets where getrandom should never work #152

Closed
vks opened this issue Jul 1, 2020 · 5 comments
Closed

Comment on WASM targets where getrandom should never work #152

vks opened this issue Jul 1, 2020 · 5 comments

Comments

@vks
Copy link

vks commented Jul 1, 2020

@burdges in rust-random/rand#991:

There exist wasm targets where getrandom should never work, which may warrant a comment somewhere.

@burdges
Copy link

burdges commented Jul 1, 2020

I donno much about the range of wasm targets that exist, or what normally happens, but wasm was meant to be quite deterministic, and ours bans any form of real randomness or secrets. I'd assume that no_std wasm has basically nothing unless you'd some additional host interface that supplies it, but not really sure.

@josephlr
Copy link
Member

josephlr commented Sep 8, 2020

This will get clarified w/ the 0.2 release (see #135). But the basic idea is:

  • getrandom works perfectly fine on wasm32-unknown-emscripten and wasm32-wasi
  • getrandom does not automatically work on wasm32-unknown-unknown
    • Enabling the getrandom/js cargo feature will make this target work
    • Enabling this feature essentially says "I assume I'm running in an enviornment w/ JavaScript". This includes:
  • There are no other Rust wasm32 targets that I am aware of. If new ones are added, they would not automatically work, and a pull request to getrandom would be needed.

Comment either here or in the doc bug if the above seems unclear or incorrect.

@burdges
Copy link

burdges commented Sep 8, 2020

I believe the rust target is wasm32-unknown-unknown. If I read lib.rs correctly, wasm32-unknown-unknown without wasm32_bindgen or wasm32_stdweb compiles to dummy.rs, which always errors. This is correct behavior for "perfectly" deterministic wasm targets. I think this can be closed.

@josephlr
Copy link
Member

josephlr commented Sep 8, 2020

Sounds good.

If I read lib.rs correctly, wasm32-unknown-unknown without wasm32_bindgen or wasm32_stdweb compiles to dummy.rs, which always errors. This is correct behavior for "perfectly" deterministic wasm targets. I think this can be closed.

This is correct for v0.1. For v0.2 we are changing things so that getrandom will not compile on unsupported targets (i.e. wasm32-unknown-unknown without JavaScript). See lib.rs on the 0.2 branch.

@josephlr josephlr closed this as completed Sep 8, 2020
@burdges
Copy link

burdges commented Sep 8, 2020

I see, getrandom is already an optional dependency of rand_core and rand though, so this sounds good too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants