CosmWasm / cw-plus

Production Quality contracts under open source licenses

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

“use of undeclared crate or module `imp`” on getrandom-0.2.8 when building for wasm32-unknown-unknown

franksanchez112595 opened this issue · comments

I cloned cw20-base and tried to cargo build-bpf but failed.

This is Cargo.toml

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

[features]
backtraces = ["cosmwasm-std/backtraces"]
# use library feature to disable all instantiate/execute/query exports
library = []

[dependencies]
cosmwasm-schema = "1.2.3"
cosmwasm-std = "1.2.3"
cw-storage-plus = "1.0.1"
cw-utils = "1.0.1"
cw2 = "1.0.1"
cw20 = "1.0.1"
schemars = "0.8.12"
semver = "1.0.17"
serde = { version = "1.0.159", default-features = false, features = ["derive"] }
thiserror = "1.0.40"

[dev-dependencies]
cw-multi-test = "0.16.1"

I got error like this

error: target is not supported, for more information see: https://docs.rs/getrandom/#unsupported-targets
   --> src/lib.rs:268:9
    |
268 | /         compile_error!("target is not supported, for more information see: \
269 | |                         https://docs.rs/getrandom/#unsupported-targets");
    | |________________________________________________________________________^

error[E0433]: failed to resolve: use of undeclared crate or module `imp`
   --> src/lib.rs:290:5
    |
290 |     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` due to 2 previous errors
warning: build failed, waiting for other jobs to finish...

Unsupport targets doesn't work, too.
I added the getrandom dependency mannually getrandom = { version = "0.2", features = ["js"] } in Cargo.toml file but its version doesn't change into 0.2.8 in Cargo.lock and the error still happened.

Is there anyone who can help me urgently?
I pulled tons of hairs to solve it for some days.

I don't know anything about cargo build-bpf and we don't support that. The wasm build command that is working is: cargo build --release --lib --target wasm32-unknown-unknown. The --lib part ensures not examples, tests etc. are compiled to Wasm. Maybe that helps.