Add wasm64-unknown-unknown target support#819
Open
audreyt wants to merge 4 commits intorust-random:masterfrom
Open
Add wasm64-unknown-unknown target support#819audreyt wants to merge 4 commits intorust-random:masterfrom
audreyt wants to merge 4 commits intorust-random:masterfrom
Conversation
Extend wasm_js backend cfg guards to include wasm64 alongside wasm32, enabling the getrandom crate to compile for wasm64-unknown-unknown targets (WebAssembly memory64 proposal). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
wasm-bindgen and js-sys optional deps were gated on wasm32 only, causing build failures for wasm64-unknown-unknown targets. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Extend the
wasm_jsbackend to supportwasm64-unknown-unknowntargets alongside existingwasm32support, enablinggetrandomto compile under the WebAssembly memory64 proposal.Changes
All three changes are mechanical: widen
target_arch = "wasm32"cfg guards toany(target_arch = "wasm32", target_arch = "wasm64").Cargo.toml— Gatewasm-bindgen,js-sys, andwasm-bindgen-testoptional deps on both wasm32 and wasm64 OS-less targetssrc/backends.rs— Include wasm64 in thecfg_if!branch that selects thewasm_jsbackendsrc/backends/wasm_js.rs— Update thecompile_error!guard so it doesn't reject wasm64 targetsMotivation
The WebAssembly memory64 proposal has reached standardization phase, and Rust nightly ships a
wasm64-unknown-unknowntarget. However,wasm-bindgenhas been the major blocker for actually using it — the CLI generates JS glue that assumes 32-bit pointers throughout (>>> 0,getUint32, 4-byte strides), and the runtime library hardcodesu32for all pointer/length ABI types. With a corresponding upstream PR (wasm-bindgen#5004), the remaining gap is downstream crates likegetrandomwhose cfg guards are hardcoded towasm32. Since thewasm_jsbackend usescrypto.getRandomValues()viawasm-bindgen— which is architecture-independent — no behavioral changes are needed; the only fix is widening the cfg predicates.Testing
cargo check --target wasm64-unknown-unknown --features wasm_jssucceedsSummary
Extend the
wasm_jsbackend to supportwasm64-unknown-unknowntargets alongside existingwasm32support, enablinggetrandomto compile under the WebAssembly memory64 proposal.Changes
All three changes are mechanical: widen
target_arch = "wasm32"cfg guards toany(target_arch = "wasm32", target_arch = "wasm64").Cargo.toml— Gatewasm-bindgen,js-sys, andwasm-bindgen-testoptional deps on both wasm32 and wasm64 OS-less targetssrc/backends.rs— Include wasm64 in thecfg_if!branch that selects thewasm_jsbackendsrc/backends/wasm_js.rs— Update thecompile_error!guard so it doesn't reject wasm64 targetsMotivation
The WebAssembly memory64 proposal has reached standardization phase, and Rust nightly ships a
wasm64-unknown-unknowntarget. However,wasm-bindgenhas been the major blocker for actually using it — the CLI generates JS glue that assumes 32-bit pointers throughout (>>> 0,getUint32, 4-byte strides), and the runtime library hardcodesu32for all pointer/length ABI types. With those issues now resolved upstream (wasm-bindgen#5004), the remaining gap is downstream crates likegetrandomwhose cfg guards are hardcoded towasm32. Since thewasm_jsbackend usescrypto.getRandomValues()viawasm-bindgen— which is architecture-independent — no behavioral changes are needed; the only fix is widening the cfg predicates.Testing
cargo +nightly check --target wasm64-unknown-unknown --features wasm_js -Zbuild-std=core,allocsucceeds (wasm64 is a tier 3 target requiring-Zbuild-std)wasm64-unknown-unknown— a 1.7B parameter LLM inference engine that requires >4 GB memory. The generated JS glue correctly handles model loading, tensor operations, and inference across the 64-bit boundary.