-
Notifications
You must be signed in to change notification settings - Fork 844
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
thread_rng can't get random number in a WASI module #460
Comments
I've completely removed all random number generation from my own code, but it looks like somewhere in the dependency tree there's still some other code using |
Did you consider using https://github.com/rust-random/rand to get random number with WebAssembly? |
@Hywan yeah, like I said I removed my own random code. Problem is the use of the rand crate is littered throughout my dependency tree. |
Try to run |
I've done both. I can actually compile the wasm to the |
Thanks for the report! I'll investigate and write a test covering this case |
The error message is originating past the rand crate. See rust-random/rand#769 for more information.
That was early April, so hopefully WASI support will be coming soon! |
Encountering the same issue. |
You can use the |
Hey guys! I don't know whether this issue is still relevant, but just wanted to let you know that the prelease version
|
Error has changed. and
|
This is fixed in the new version of Closing the issue |
Runtime panic (trap) when getting random number
Rust code in the compiled WASI module:
let mut rng = thread_rng();
My system:
Steps to reproduce
thread_rng()
to produce a RNGExpected behavior
According to the WASI spec, there's a __wasi_rnd_get() function that I figured would be invoked underneath the
rand
crate's compiled WASI code.Actual behavior
This error message reads like someone's compile-time error message that doesn't take into account the shunting being done by the WASI code and its relevant imports.
If we can't use random numbers, things are going to be difficult compiling to WASI.
Additional context
I'm perfectly fine with cheap workarounds. I don't need cryptographic random, I'm just using this to shuffle a list of servers to connect with, so if there are some lines of Rust I can replace my code with that will pick a random number between 0 and n or let me invoke
shuffle
on a vec and not cause a wasmer-time trap, that'd be awesome.p.s. I don't know if the problem is in the runtime wasmer's providing or in the code that Rust is generating via the
wasm32-wasi
target. Apologies if this is not your issue at all.The text was updated successfully, but these errors were encountered: