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

Make it work on WASM #194

Open
RCasatta opened this issue Jan 22, 2024 · 3 comments · May be fixed by #195
Open

Make it work on WASM #194

RCasatta opened this issue Jan 22, 2024 · 3 comments · May be fixed by #195

Comments

@RCasatta
Copy link
Collaborator

I think the only issue is deal with rand

cargo check --target wasm32-unknown-unknown

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
   --> /home/casatta/.cargo/registry/src/index.crates.io-6f17d22bba15001f/getrandom-0.2.12/src/lib.rs:291:9
    |
291 | /         compile_error!("the wasm*-unknown-unknown targets are not supported by \
292 | |                         default, you may need to enable the \"js\" feature. \
293 | |                         For more information see: \
294 | |                         https://docs.rs/getrandom/#webassembly-support");
    | |________________________________________________________________________^

error[E0433]: failed to resolve: use of undeclared crate or module `imp`
   --> /home/casatta/.cargo/registry/src/index.crates.io-6f17d22bba15001f/getrandom-0.2.12/src/lib.rs:347:9
    |
347 |         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...


@apoelstra
Copy link
Member

In rust-secp we have the following code in our Cargo.toml

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

I guess we need to copy that here. (Though I'm surprised that us having a rust-secp dependency here is insufficient.)

@RCasatta
Copy link
Collaborator Author

The rust-secp code seems it's there also in rust-secp-zkp https://github.com/BlockstreamResearch/rust-secp256k1-zkp/blob/master/Cargo.toml (it puzzles me it's a DEV-dependencies but anyway).

Not sure if some deps is taking it without the js feature?

$ cargo tree -i getrandom
getrandom v0.2.12
├── elements v0.24.0 (/home/casatta/git/rust-elements)
└── rand_core v0.6.4
    ├── rand v0.8.5
    │   ├── secp256k1 v0.28.1
    │   │   ├── bitcoin v0.31.1
    │   │   │   └── elements v0.24.0 (/home/casatta/git/rust-elements)
    │   │   └── secp256k1-zkp v0.10.1
    │   │       └── elements v0.24.0 (/home/casatta/git/rust-elements)
    │   └── secp256k1-zkp v0.10.1 (*)
    │   [dev-dependencies]
    │   └── elements v0.24.0 (/home/casatta/git/rust-elements)
    └── rand_chacha v0.3.1
        └── rand v0.8.5 (*)
        [dev-dependencies]
        └── elements v0.24.0 (/home/casatta/git/rust-elements)

If I add

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

to rust-elements the build succeeds but I am not sure it's the right way to do it

@apoelstra
Copy link
Member

Ohh, I see. It's a dev-dependency because this avoids making it a dependency downstream. We don't want to force wasm users to have rand on. What we want to say is, if the user has rand on, and they are on WASM, then they should have the rand/js feature on ... but Cargo has no way to say this.

So what you're doing is the right thing, AFAICT.

@RCasatta RCasatta linked a pull request Jan 23, 2024 that will close this issue
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

Successfully merging a pull request may close this issue.

2 participants