Search code examples
rustrust-cargo

how could I propagate feature to end-user crate


I have nested crates.

  1. lib Crate A
  2. lib Crate B using Crate A
  3. binary Crate C using Crate B

with following Cargo.toml

# CrateA/Cargo.toml
[features]
webgpu = [
    "web-sys", 
    'web-sys/Document',
    'web-sys/Element',
    'web-sys/GpuAdapter', 
    ...
]
# CrateB/Cargo.toml
[features]
webgpu = ["CrateA/webgpu"]

[dependencies]
CrateA = {path = "../CrateA", default-features = false}
# CrateC/Cargo.toml
[dependencies]
CrateB = {path = "../CrateB" , features = ["webgpu"], default-features = false}

and when I tried to build CrateC, it failed with following error.

error[E0432]: unresolved import `web_sys::GpuAdapter`
  |
8 | use web_sys::GpuAdapter;
  |     ^^^^^^^^^^^^^^^^^^^ no `GpuAdapter` in the root

web_sys::GpuAdapter is defined in web-sys only when web-sys/GpuAdapter feature is used.

I had assumed the above Cargo.toml settings are fine with those scenario but it was not.

What can I do for do this properly?


Solution

  • self solved.

    I just for forgot --cfg=web_sys_unstable_apis for build flags.