Getrandom version conflict error - building a WASM
โ Rust ๐ 2025-07-28 ๐ค surdeus ๐๏ธ 12Hello rusty fellow,
im trying to build libsignalล protocol crate .WASM for R&D and project analysis but im failing again and again because of the getrandom version conflict.
What i tried
i build using following command
aqua@aqua-server:~/Desktop/libsignal-0.76.7/rust/protocol$ wasm-pack build --target web --out-dir ../pkg_wasm
and get following error
aqua@aqua-server:~/Desktop/libsignal-0.76.7/rust/protocol$ wasm-pack build --target web --out-dir ../pkg_wasm
[INFO]: ๐ฏ Checking for the Wasm target...
[INFO]: ๐ Compiling to Wasm...
Compiling proc-macro2 v1.0.94
Compiling unicode-ident v1.0.18
Compiling cfg-if v1.0.0
Compiling log v0.4.27
Compiling wasm-bindgen-shared v0.2.100
Compiling bumpalo v3.17.0
Compiling quote v1.0.40
Compiling syn v2.0.100
Compiling typenum v1.18.0
Compiling version_check v0.9.5
Compiling generic-array v0.14.7
Compiling wasm-bindgen v0.2.100
Compiling once_cell v1.21.3
Compiling getrandom v0.3.3
Compiling subtle v2.6.1
error: The wasm32-unknown-unknown targets are not supported by default; you may need to enable the "wasm_js" configuration flag. Note that enabling the `wasm_js` feature flag alone is insufficient. For more information see: https://docs.rs/getrandom/0.3.3/#webassembly-support
--> /home/aqua/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/getrandom-0.3.3/src/backends.rs:168:9
|
168 | / compile_error!(concat!(
169 | | "The wasm32-unknown-unknown targets are not supported by default; \
170 | | you may need to enable the \"wasm_js\" configuration flag. Note \
171 | | that enabling the `wasm_js` feature flag alone is insufficient. \
172 | | For more information see: \
173 | | https://docs.rs/getrandom/", env!("CARGO_PKG_VERSION"), "/#webassembly-support"
174 | | ));
| |__________^
error[E0425]: cannot find function `fill_inner` in module `backends`
--> /home/aqua/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/getrandom-0.3.3/src/lib.rs:99:19
|
99 | backends::fill_inner(dest)?;
| ^^^^^^^^^^ not found in `backends`
error[E0425]: cannot find function `inner_u32` in module `backends`
--> /home/aqua/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/getrandom-0.3.3/src/lib.rs:128:15
|
128 | backends::inner_u32()
| ^^^^^^^^^ not found in `backends`
|
help: consider importing this function
|
33 + use crate::util::inner_u32;
|
help: if you import `inner_u32`, refer to it directly
|
128 - backends::inner_u32()
128 + inner_u32()
|
error[E0425]: cannot find function `inner_u64` in module `backends`
--> /home/aqua/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/getrandom-0.3.3/src/lib.rs:142:15
|
142 | backends::inner_u64()
| ^^^^^^^^^ not found in `backends`
|
help: consider importing this function
|
33 + use crate::util::inner_u64;
|
help: if you import `inner_u64`, refer to it directly
|
142 - backends::inner_u64()
142 + inner_u64()
|
For more information about this error, try `rustc --explain E0425`.
error: could not compile `getrandom` (lib) due to 4 previous errors
warning: build failed, waiting for other jobs to finish...
Error: Compiling your crate to WebAssembly failed
Caused by: Compiling your crate to WebAssembly failed
Caused by: failed to execute `cargo build`: exited with exit status: 101
full command: cd "/home/aqua/Desktop/libsignal-0.76.7/rust/protocol" && "cargo" "build" "--lib" "--release" "--target" "wasm32-unknown-unknown"
After roaming on the internet i tried this by patching a /rust/protocol crate Cargo.toml
[patch.crates-io]
getrandom = {version = "0.2", features = ["js"]}
and get very same error. so i update the getrandom version from 0.2 to 0.3
[patch.crates-io]
getrandom = {version = "0.3", features = ["wasm_js"]}
i also tried by not patching just declaring as dependency.
[dependencies]
getrandom = {version = "0.2", features = ["js"]}
and get very same error. so i update the getrandom version from 0.2 to 0.3
[dependencies]
getrandom = {version = "0.3", features = ["wasm_js"]}
i also tried patching root folder Cargo.toml file and get following error.
[patch.crates-io]
getrandom = {version = "0.2", features = ["js"]}
# tried both of this version
# getrandom = {version = "0.3", features = ["wasm_js"]}
And get following error.
aqua@aqua-server:~/Desktop/libsignal-0.76.7/rust/protocol$ wasm-pack build --target web --out-dir ../pkg_wasm
Error: `cargo metadata` exited with an error: warning: patch for `getrandom` uses the features mechanism. default-features and features will not take effect because the patch dependency does not support this mechanism
error: failed to resolve patches for `https://github.com/rust-lang/crates.io-index`
Caused by:
patch for `getrandom` in `https://github.com/rust-lang/crates.io-index` points to the same source, but patches must point to different sources
Caused by: `cargo metadata` exited with an error: warning: patch for `getrandom` uses the features mechanism. default-features and features will not take effect because the patch dependency does not support this mechanism
error: failed to resolve patches for `https://github.com/rust-lang/crates.io-index`
Caused by:
patch for `getrandom` in `https://github.com/rust-lang/crates.io-index` points to the same source, but patches must point to different sources
Instead patching i tried to declare as dependency on root Cargo.toml, and that leads very same error.
i also tried as describe in getrandom documentation, there were no config.toml so i created a new one and paste this on .cargo/config.toml
[target.wasm32-unknown-unknown]
rustflags = ['--cfg', 'getrandom_backend="wasm_js"']
and try to build using following rustflags
RUSTFLAGS='--cfg getrandom_backend="linux_getrandom"' cargo build --release --target wasm32-unknown-unknown
Here if i build native lib it would be success but if i try to generate wasm file i get very same error i stuck with.
aqua@aqua-server:~/Desktop/libsignal-0.76.7/rust/protocol$ RUSTFLAGS="--cfg getrandom_wasm_js" cargo build --release --target wasm32-unknown-unknown
warning: patch for the non root package will be ignored, specify patch at the workspace root:
package: /home/aqua/Desktop/libsignal-0.76.7/rust/protocol/Cargo.toml
workspace: /home/aqua/Desktop/libsignal-0.76.7/Cargo.toml
Compiling proc-macro2 v1.0.94
Compiling unicode-ident v1.0.18
Compiling cfg-if v1.0.0
Compiling log v0.4.27
Compiling wasm-bindgen-shared v0.2.100
Compiling bumpalo v3.17.0
Compiling quote v1.0.40
Compiling syn v2.0.100
Compiling version_check v0.9.5
Compiling typenum v1.18.0
Compiling generic-array v0.14.7
Compiling wasm-bindgen v0.2.100
Compiling once_cell v1.21.3
Compiling getrandom v0.3.3
Compiling subtle v2.6.1
error: The wasm32-unknown-unknown targets are not supported by default; you may need to enable the "wasm_js" configuration flag. Note that enabling the `wasm_js` feature flag alone is insufficient. For more information see: https://docs.rs/getrandom/0.3.3/#webassembly-support
--> /home/aqua/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/getrandom-0.3.3/src/backends.rs:168:9
|
168 | / compile_error!(concat!(
169 | | "The wasm32-unknown-unknown targets are not supported by default; \
170 | | you may need to enable the \"wasm_js\" configuration flag. Note \
171 | | that enabling the `wasm_js` feature flag alone is insufficient. \
172 | | For more information see: \
173 | | https://docs.rs/getrandom/", env!("CARGO_PKG_VERSION"), "/#webassembly-support"
174 | | ));
| |__________^
error[E0425]: cannot find function `fill_inner` in module `backends`
--> /home/aqua/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/getrandom-0.3.3/src/lib.rs:99:19
|
99 | backends::fill_inner(dest)?;
| ^^^^^^^^^^ not found in `backends`
error[E0425]: cannot find function `inner_u32` in module `backends`
--> /home/aqua/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/getrandom-0.3.3/src/lib.rs:128:15
|
128 | backends::inner_u32()
| ^^^^^^^^^ not found in `backends`
|
help: consider importing this function
|
33 + use crate::util::inner_u32;
|
help: if you import `inner_u32`, refer to it directly
|
128 - backends::inner_u32()
128 + inner_u32()
|
error[E0425]: cannot find function `inner_u64` in module `backends`
--> /home/aqua/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/getrandom-0.3.3/src/lib.rs:142:15
|
142 | backends::inner_u64()
| ^^^^^^^^^ not found in `backends`
|
help: consider importing this function
|
33 + use crate::util::inner_u64;
|
help: if you import `inner_u64`, refer to it directly
|
142 - backends::inner_u64()
142 + inner_u64()
|
For more information about this error, try `rustc --explain E0425`.
error: could not compile `getrandom` (lib) due to 4 previous errors
warning: build failed, waiting for other jobs to finish...
so i tired to identify which package causing an error using cargo tree
$ cargo tree | grep getrandom
aqua@aqua-server:~/Desktop/libsignal-0.76.7/rust/protocol$ cargo tree | grep getrandom
warning: patch for the non root package will be ignored, specify patch at the workspace root:
package: /home/aqua/Desktop/libsignal-0.76.7/rust/protocol/Cargo.toml
workspace: /home/aqua/Desktop/libsignal-0.76.7/Cargo.toml
โ โ โ โ โโโ getrandom v0.2.16
โโโ getrandom v0.2.16 (*)
โ โ โโโ getrandom v0.3.3
โ โโโ getrandom v0.3.3 (*)
and i explore more on it using cargo features and get the several crate that use getrandom without enabling js features that include rand_core, aes-gcm-siv that causing an error.
I also tried clearing cache by following command.
rm -rf ~/.cargo/registry ~/.cargo/git
let me knw i can share more insight/logs on it, any help would be appreciate.
1 post - 1 participant
๐ท๏ธ Rust_feed