Skip to content

Fix wasm_js error formatting with backend overrides - #874

Closed
raiyan-ironsoftware wants to merge 1 commit into
rust-random:masterfrom
raiyan-ironsoftware:fix/wasm-js-backend-override
Closed

raiyan-ironsoftware wants to merge 1 commit into
rust-random:masterfrom
raiyan-ironsoftware:fix/wasm-js-backend-override

Conversation

@raiyan-ironsoftware

Copy link
Copy Markdown

Enabling wasm_js while selecting an explicit non-JavaScript backend fails to compile on wasm32-unknown-unknown:

RUSTFLAGS='--cfg getrandom_backend="unsupported"' \
  cargo check --target wasm32-unknown-unknown --features wasm_js
error[E0599]: no associated function or constant named `WEB_CRYPTO`
found for struct `error::Error` in the current scope

The same error occurs with the custom backend. A transitive dependency can enable wasm_js, so this configuration is useful for non-JavaScript Wasm applications that explicitly override the default backend.

internal_desc checks the feature and target, but Error::WEB_CRYPTO is defined only when the wasm_js backend is selected. Exclude the supported non-JavaScript overrides (unsupported, custom, and extern_impl) from that match arm. This changes no entropy source or runtime error behavior.

The existing override build job now covers unsupported and custom, both with and without wasm_js. These feature-enabled builds fail on the base revision and pass with this change.

Validated locally:

  • Reproduced E0599 on the unmodified base with unsupported and custom.
  • Wasm builds for unsupported and custom, with and without wasm_js, with warnings denied.
  • Wasm checks for unsupported, custom, and extern_impl, with wasm_js and wasm_js,std.
  • Default JavaScript-backend Wasm check with wasm_js.
  • Native cargo test --locked --all-features: 11 integration tests and 9 doctests passed; 1 existing doctest ignored.
  • cargo fmt --all -- --check and git diff --check.

Do not reference WEB_CRYPTO when unsupported, custom, or extern_impl overrides the WebAssembly backend. That constant exists only in the wasm_js backend, even when Cargo feature unification leaves wasm_js enabled.

Extend the Wasm override build job to compile unsupported and custom backends both with and without wasm_js.
@raiyan-ironsoftware
raiyan-ironsoftware deleted the fix/wasm-js-backend-override branch November 4, 2026 03:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant