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

Failed to build for wasm32-unknown-unknown with no_std #394

Closed
gshep opened this issue Feb 13, 2024 · 1 comment
Closed

Failed to build for wasm32-unknown-unknown with no_std #394

gshep opened this issue Feb 13, 2024 · 1 comment

Comments

@gshep
Copy link

gshep commented Feb 13, 2024

Hi,

I was playing with plonky2 for wasm32-unknown-unknown target without default features and found out that getrandom erroneously pulls std in.

Here is an example reproducing the issue.

Cargo.toml

[package]
name = "getrandom-test"
version = "0.1.0"
edition = "2021"

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

[dependencies]
sp-io = { version = "30.0.0", default-features = false }
getrandom = { version = "0.2", default-features = false, features = ["js"] }

[features]
default = ["std"]
std = ["sp-io/std", "getrandom/std"]

src/lib.rs

#![cfg_attr(not(feature = "std"), no_std)]

pub const ERROR: getrandom::Error = getrandom::Error::UNSUPPORTED;

extern crate sp_io;

cargo b --target=wasm32-unknown-unknown --no-default-features

...

   Compiling getrandom-test v0.1.0 (/home/user/devel/gear-tech/getrandom-test)
error[E0152]: duplicate lang item in crate `std` (which `getrandom` depends on): `panic_impl`.
  |
  = note: the lang item is first defined in crate `sp_io` (which `getrandom_test` depends on)
  = note: first definition in `sp_io` loaded from /home/user/devel/gear-tech/getrandom-test/target/wasm32-unknown-unknown/debug/deps/libsp_io-27b44a1938535aab.rlib
  = note: second definition in `std` loaded from /home/user/.rustup/toolchains/nightly-2023-04-25-x86_64-unknown-linux-gnu/lib/rustlib/wasm32-unknown-unknown/lib/libstd-bdf48c82ab858a37.rlib

For more information about this error, try `rustc --explain E0152`.
error: could not compile `getrandom-test` (lib) due to 1 previous error
@newpavlov
Copy link
Member

If you work with sp-io, then you should not use the js feature, since it clearly not a "Web" target. Instead, you should define a custom backend, which probably should use user-space CSPRNG seeded by random_seed.

@gshep gshep closed this as completed Feb 13, 2024
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