Skip to content

JS calls brought in for every compile for WASM #431

Description

@ranile

When compiling for wasm, the only option is to bring in JS bindings for web APIs. However, wasm is used a for a lot more than just browsers or runtime with web APIs available, causing this library to be unusable in those cases.

One such example is https://forum.dfinity.org/t/module-imports-function-wbg-now-2e07eedfb4ac9dbe-from-wbindgen-placeholder-that-is-not-exported-by-the-runtime/22083, with me also running into the same issue.

Culprit code

jsonwebtoken/Cargo.toml

Lines 30 to 35 in 5cd1887

[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
ring = { version = "0.17.4", features = ["std"] }
[target.'cfg(target_arch = "wasm32")'.dependencies]
js-sys = "0.3"
ring = { version = "0.17.4", features = ["std", "wasm32_unknown_unknown_js"] }

Solution

Give option to opt out of JS calls on wasm targets. One way to do that is to move JS calls behind a feature flag, similar to the ring crate that is enabled here. Note that wasm32-unknown-unknown target is not enough to assume that JS API will be available, as is the case for the platform of the forum post linked above

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions