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

Build fault when --target wasm32-unknown-unknown --release #769

Open
ipconfiger opened this issue Dec 20, 2024 · 2 comments
Open

Build fault when --target wasm32-unknown-unknown --release #769

ipconfiger opened this issue Dec 20, 2024 · 2 comments

Comments

@ipconfiger
Copy link

in Cargo.toml

[lib]
crate-type = ["cdylib"]

[dependencies]
secp256k1 = {version = "0.30.0", features = ["std", "rand", "serde", "hashes"]}

but when i run cargo build --target wasm32-unknown-unknown --release

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/alex/.cargo/registry/src/rsproxy.cn-8f6827c7555bfaf8/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");
    | |________________________________________________________________________^

error[E0433]: failed to resolve: use of undeclared crate or module `imp`
   --> /Users/alex/.cargo/registry/src/rsproxy.cn-8f6827c7555bfaf8/getrandom-0.2.15/src/lib.rs:398:9
    |
398 |         imp::getrandom_inner(dest)?;
    |         ^^^ use of undeclared crate or module `imp`

For more information about this error, try `rustc --explain E0433`.
error: could not compile `getrandom` (lib) due to 2 previous errors
warning: build failed, waiting for other jobs to finish...
The following warnings were emitted during compilation:
@apoelstra
Copy link
Member

You need to add an explicit dependency to getrandom in your crate with the js feature turned on.

Historically cargo has not given us any way to do this from rust-bitcoin. Though maybe now that we have weak dependencies it might be possible? Not sure about the interaction between weak dependencies and architecture-specific options.

@ipconfiger
Copy link
Author

but how?

[target.wasm32-unknown-unknown.dev-dependencies]
wasm-bindgen-test = "0.3"
getrandom = { version = "0.2", features = ["js"] }

OR

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

But it doesn't works

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