Skip to content

wasm-bindgen’s std feature is non-additive, breaking some build configurations #4303

@kpreid

Description

@kpreid

Steps to Reproduce

cargo init --lib
cargo add [email protected]
cargo add [email protected] --no-default-features
cargo check --target=wasm32-unknown-unknown

Expected Behavior

The project should build

Actual Behavior

error[E0432]: unresolved import `wasm_bindgen::__rt::LazyCell`
    --> /Users/kpreid/.cargo/registry/src/index.crates.io-6f17d22bba15001f/js-sys-0.3.73/src/lib.rs:6041:13
     |
6041 |         use wasm_bindgen::__rt::LazyCell;
     |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ no `LazyCell` in `__rt`
     |
note: found an item that was configured out
    --> /Users/kpreid/.cargo/registry/src/index.crates.io-6f17d22bba15001f/wasm-bindgen-0.2.96/src/lib.rs:1598:16
     |
1598 |     pub struct LazyCell<T, F = fn() -> T>(::once_cell::unsync::Lazy<T, F>);
     |                ^^^^^^^^
note: the item is gated here
    --> /Users/kpreid/.cargo/registry/src/index.crates.io-6f17d22bba15001f/wasm-bindgen-0.2.96/src/lib.rs:1597:5
     |
1597 |     #[cfg(not(feature = "std"))]
     |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Additional Context

This problem is occurring because wasm-bindgen is exporting the item LazyCell only if the feature wasm-bindgen/std feature is not enabled, but wasm-bindgen-futures uses LazyCell if wasm-bindgen-futures/std feature is not enabled. But it is not true that wasm-bindgen/std implies wasm-bindgen-futures/std, so this can fail to compile if wasm-bindgen/std is enabled and wasm-bindgen-futures/std is not.

Like all Cargo packages, wasm-bindgen must ensure that its std feature is additive — only adds items, without removing any — or if necessary, use some other technique like exporting a macro by which wasm-bindgen-futures can make its code conditional on whether wasm-bindgen/std is enabled rather than whether wasm-bindgen-futures/std is enabled.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions