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

Fails to build on wasm32-unknown-unknown using getrandom #1110

Closed
sffc opened this issue Apr 3, 2021 · 5 comments
Closed

Fails to build on wasm32-unknown-unknown using getrandom #1110

sffc opened this issue Apr 3, 2021 · 5 comments

Comments

@sffc
Copy link

sffc commented Apr 3, 2021

When the std feature is enabled, the latest version of this crate fails to build on wasm32-unknown-unknown with the following error:

error: target is not supported, for more information see: https://docs.rs/getrandom/#unsupported-targets
   --> /path/to/.cargo/registry/src/github.com-1ecc6299db9ec823/getrandom-0.2.2/src/lib.rs:213:9
    |
213 | /         compile_error!("target is not supported, for more information see: \
214 | |                         https://docs.rs/getrandom/#unsupported-targets");
    | |_________________________________________________________________________^

error[E0433]: failed to resolve: use of undeclared crate or module `imp`
   --> /path/to/.cargo/registry/src/github.com-1ecc6299db9ec823/getrandom-0.2.2/src/lib.rs:235:5
    |
235 |     imp::getrandom_inner(dest)
    |     ^^^ use of undeclared crate or module `imp`

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0433`.
error: could not compile `getrandom`

To learn more, run the command again with --verbose.
warning: build failed, waiting for other jobs to finish...
error: build failed
[cargo-make] ERROR - Error while executing command, exit code: 101
[cargo-make] WARN - Build Failed.

The solution seems to be enabling the "js" feature of getrandom. However, the client of rand cannot do that right now, because rand does not have a "js" feature.

So, I think the solution is to add a "js" feature to rand that enables the "js" feature of getrandom.

@newpavlov
Copy link
Member

We intentionally have removed such feature-forwarding and we do not recommend addition of such features in library crates dependent on getrandom. As clearly stated in the getrandom docs, applications which target web-based WASM should enable the getrandom's js feature directly in their Cargo.toml.

@sffc
Copy link
Author

sffc commented Apr 4, 2021

Yes, but I don't depend directly on getrandom; it's two levels down from rand. Are you recommending that I add getrandom to my Cargo.toml as a way to enable the feature?

@newpavlov
Copy link
Member

newpavlov commented Apr 4, 2021

Yes, it's exactly what is written in the link.

If getrandom is not a direct dependency of your crate, you can still enable any of the above fallback behaviors by enabling the relevant feature in your root crate's Cargo.toml

@sffc
Copy link
Author

sffc commented Apr 5, 2021

Okay, I did the above and it worked! Thank you for your help!

@ashWhiteHat
Copy link

I added like following in my Cargo.toml.

getrandom = { version = "0.2", features = ["js"] }

If above doesn't work please try following.
Remove version 0.2.2 getrandom in my Cargo.lock and install again.

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