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

WebAssembly support #511

Closed
orhun opened this issue Jan 11, 2025 · 2 comments
Closed

WebAssembly support #511

orhun opened this issue Jan 11, 2025 · 2 comments
Assignees
Labels

Comments

@orhun
Copy link

orhun commented Jan 11, 2025

bson is failing to build for wasm*-unknown-unknown target due to the hard dependency on rand crate defined here:

rand = "0.8"

I'm getting this error while trying to serve a WebAssembly application via trunk:

error: the wasm*-unknown-unknown targets are not supported by default, you may need to enable the "js" feature. For more information see: https://d
ocs.rs/getrandom/#webassembly-support
   --> /home/orhun/.cargo/registry/src/index.crates.io-6f17d22bba15001f/getrandom-0.2.15/src/lib.rs:342:9
    |
342 | /         compile_error!("the wasm*-unknown-unknown targets are not supported by \
343 | |                         default, you may need to enable the \"js\" feature. \
344 | |                         For more information see: \
345 | |                         https://docs.rs/getrandom/#webassembly-support");
    | |________________________________________________________________________^

Thanks for your work and I'm hoping to get this fixed!

@isabelatkinson
Copy link
Contributor

Hey @orhun, thanks for opening this issue! The page linked in the compiler error you received suggests adding the following to your Cargo.toml:

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

It also mentions:

This can be done even if getrandom is not a direct dependency. Cargo allows crates to enable features for indirect dependencies.

Does adding this additional dependency resolve the issue for you?

@orhun
Copy link
Author

orhun commented Jan 18, 2025

This can be done even if getrandom is not a direct dependency. Cargo allows crates to enable features for indirect dependencies.

Oh wow, I obviously missed that! Thanks for the pointer, looks good now :)

@orhun orhun closed this as completed Jan 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants