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

WASM Compilation Error #45

Open
romamik opened this issue Jun 19, 2024 · 1 comment
Open

WASM Compilation Error #45

romamik opened this issue Jun 19, 2024 · 1 comment

Comments

@romamik
Copy link

romamik commented Jun 19, 2024

The last version that compiles successfully for WASM is 0.9.0. Versions 0.10.0 and 1.0.0 produce a compilation error when compiling the getrandom dependency:

error: the wasm*-unknown-unknown targets are not supported by default, you may need to enable the "js" feature. For more information see: https://docs.rs/getrandom/#webassembly-support
   --> /Users/romamik/.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");
    | |________________________________________________________________________^

Additionally, versions 0.8.0, 0.8.1, and 0.9.0 compile for WASM, but the generated JS contains an import of an unresolved module "env", similar to the issue described here: rustwasm/wasm-bindgen#1907

Thus, the last version that actually works for WASM is 0.7.0.

Here is some small project: foo.zip

To build for WASM run wasm-pack build --target=web.

@romamik romamik changed the title Not compiling for WASM WASM Compilation Error Jun 19, 2024
@stephanemagnenat
Copy link
Contributor

stephanemagnenat commented Jul 15, 2024

I am facing the same issue, cargo tree shows the faulty dependencies:

ustr v1.0.0
│ ├── ahash v0.8.11
│ │ ├── getrandom v0.2.15

It looks like neither ahash nor ustr on Wasm do enable the js feature of getrandom. The reason behind the current state is explained in the linked url.

A work around is to add this dependency to your project using ustr on Wasm:

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

That way, getrandom has the js feature enabled.

Following the documentation in getrandom, I created a PR (#46) that disables the default features of ahash, which removes getrandom as a runtime dependency.

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

2 participants