• Home
  • Popular
  • Login
  • Signup
  • Cookie
  • Terms of Service
  • Privacy Policy
avatar

Posted by User Bot


25 Mar, 2025

Updated at 20 May, 2025

Can I enable rust features on sub sub sub dependencies, especially when the dependency appears multiple times?

I am working on a wasm32-unknown-unknown target, and the getrandom crate appears in multiple places and at multiple levels in my cargo tree. It fails to compile with the following:

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
   --> /usr/local/cargo/registry/src/index.crates.io-1949cf8c6b5b557f/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");
    | |________________________________________________________________________^

It seems like the cause for this is that I cannot affect the features for a sub-dependency, or a sub-sub-dependency, etc.

Reviewing and attempting to implement solutions in several existing sources gave me unexpected results in my big project, so I created a very simple project using just the age lib, and I am at least hitting the problem consistently now.

This cargo.toml attempts to work like the first source

$ cat Cargo.toml 
[package]
name = "rust-age-testing"
version = "0.1.0"
edition = "2024"

[dependencies]

[dependencies.age]
version = "0.11.1"
features = ["armor"]
getrandom = { features = ["wasm_js"] }

Though getrandom is about 5 levels deep in the dependency graph...

A build comes out like this (note the ignored key):

RUSTFLAGS='--cfg getrandom_backend="wasm_js"' cargo build --target wasm32-unknown-unknown
warning: unused manifest key: dependencies.age.getrandom
   Compiling typenum v1.18.0
   Compiling generic-array v0.14.7
   Compiling cfg-if v1.0.0
   Compiling subtle v2.6.1
   Compiling unic-langid-impl v0.9.5
   Compiling zeroize v1.8.1
   Compiling tinystr v0.7.6
   Compiling unic-langid v0.9.5
   Compiling slab v0.4.9
   Compiling futures-core v0.3.31
   Compiling memchr v2.7.4
   Compiling futures-sink v0.3.31
   Compiling futures-channel v0.3.31
   Compiling zerocopy v0.8.23
   Compiling getrandom v0.2.15
   Compiling thiserror v1.0.69
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
   --> /usr/local/cargo/registry/src/index.crates.io-1949cf8c6b5b557f/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`
   --> /usr/local/cargo/registry/src/index.crates.io-1949cf8c6b5b557f/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`.
   Compiling toml v0.5.11
error: could not compile `getrandom` (lib) due to 2 previous errors
warning: build failed, waiting for other jobs to finish...

Do I need to ask all of the dependency maintainers to add feature flags that will control the feature flags that pass to getrandom?