-
Notifications
You must be signed in to change notification settings - Fork 207
Where to enable "js" for wasm-bindgen #267
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
Comments
You want to enable the "js" feature on the getrandom crate itself. Even if your crate doesn't directly depend on it, you'll want to add a line like |
@vdods is correct. We explain this in our docs for the |
I think we close this issue considering #280 is merged. |
Leaving this here for the next dummy who thought he applied both changes in the docs and goes searching for more magical incantations, but actually did these two changes wrong :)
# Cargo.toml
# A dependency _somewhere_ that does not play nicely with wasm.
# https://docs.rs/getrandom/latest/getrandom/#webassembly-support
# It needs the feature here, but also RUSTFLAGS='--cfg getrandom_backend="wasm_js"'
getrandom = { version = "0.3", features = ["wasm_js"] } # .cargo/config.toml
# cargo install wasm-server-runner
# then this config makes cargo run use the server-runner if --target wasm32-unknown-unknown is specified
# https://bevy-cheatbook.github.io/platforms/wasm.html
[target.wasm32-unknown-unknown]
runner = "wasm-server-runner"
# The dependency getrandom needs this flag set, but only when the target is wasm32-unknown-unknown.
# https://docs.rs/getrandom/latest/getrandom/#opt-in-backends
rustflags = ['--cfg', 'getrandom_backend="linux_getrandom"',]
These changes changed got me past the previous error to a different one. When I ran the command (without explicitly adding the rustflags) RUSTFLAGS='--cfg getrandom_backend="wasm_js"' cargo run --target wasm32-unknown-unknown I ran into
Well, the reason was simply that I somehow happened to specify |
Hi, I am trying to compile my program into WebAssembly using wasm-bindgen, but I got the following errors:
May I ask where I can enable the "js" feature, as shown in https://docs.rs/getrandom/latest/getrandom/#webassembly-support? Or are there any other solutions?
Thank you!
The text was updated successfully, but these errors were encountered: