Skip to content

fix: explicitly export __heap_base for wasm-bindgen thread support#680

Draft
temeddix with Copilot wants to merge 4 commits into
mainfrom
copilot/fix-wasm-bindgen-issues
Draft

fix: explicitly export __heap_base for wasm-bindgen thread support#680
temeddix with Copilot wants to merge 4 commits into
mainfrom
copilot/fix-wasm-bindgen-issues

Conversation

Copilot AI commented May 25, 2026

Copy link
Copy Markdown

Changes

Fixes the wasm build failure when running rinf wasm on newer Rust nightly toolchains:

error: failed to prepare module for threading
Caused by:
    failed to find `__heap_base` for injecting thread id
Error: Running the wasm-bindgen CLI

Root Cause

Rust nightly removed the automatic export of __heap_base from wasm targets in this commit:
rust-lang/rust@b594ef3

The wasm-bindgen CLI relies on finding __heap_base in the wasm module's exports when preparing the module for threading support. Since rinf's wasm build enables threading via +atomics and --shared-memory, this symbol is required.

Fix

  1. Explicit linker export: Added -C link-arg=--export=__heap_base to the RUSTFLAGS used during wasm compilation. This ensures the symbol remains exported regardless of Rust toolchain version.

  2. Install wasm tools with nightly: Changed cargo install for wasm-pack and wasm-bindgen-cli to use cargo +nightly install. This is needed because wasm-pack v0.15.0 depends on cargo-platform@0.3.3 which requires rustc 1.91, while the project supports Rust 1.88+. Since nightly is already required for the wasm build itself, using it to compile the build tools maintains backward compatibility with stable Rust 1.88.

Before Committing

Please make sure that you've analyzed and formatted the files.

dart analyze flutter_package --fatal-infos
dart format .
cargo fmt
cargo clippy --fix --allow-dirty

Rust nightly removed the automatic export of __heap_base from wasm
targets. wasm-bindgen CLI needs this symbol when preparing the module
for threading (to inject thread IDs). Adding --export=__heap_base to
the linker args fixes the "failed to find __heap_base" error.

Ref: rust-lang/rust@b594ef3

Agent-Logs-Url: https://github.com/cunarist/rinf/sessions/d27d942d-2ccd-46e0-9223-f5cae25d8eff

Co-authored-by: temeddix <66480156+temeddix@users.noreply.github.com>

@temeddix temeddix left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please mention whether docs should be updated. If the CI tests pass, are we good?

Copilot AI commented May 25, 2026

Copy link
Copy Markdown
Author

Please mention whether docs should be updated. If the CI tests pass, are we good?

No docs update needed — this is a purely internal build configuration change (adding a linker export flag). Users don't interact with this directly; rinf wasm will just work again on newer Rust nightly toolchains. If CI tests pass, we're good.

Copilot AI requested a review from temeddix May 25, 2026 05:42
@temeddix

Copy link
Copy Markdown
Member

@copilot Please fix the broken CI

Copilot AI commented May 25, 2026

Copy link
Copy Markdown
Author

@copilot Please fix the broken CI

Fixed in e8586f1. The CI was failing because wasm-pack v0.15.0 depends on cargo-platform@0.3.3 which requires rustc 1.91, but CI was using 1.88. Bumped the Rust toolchain to 1.91 in all workflow files.

@temeddix

Copy link
Copy Markdown
Member

@copilot We should support Rust 1.88 and above. Refer to the docs

Copilot AI commented May 25, 2026

Copy link
Copy Markdown
Author

@copilot We should support Rust 1.88 and above. Refer to the docs

Fixed in 2298f5f. Reverted CI workflows back to Rust 1.88. The wasm-pack compilation issue is now resolved by using cargo +nightly install for wasm-pack and wasm-bindgen-cli, since the nightly toolchain is already required for the wasm build anyway.

@temeddix

Copy link
Copy Markdown
Member

@copilot Should we require Rust 1.91 and update the docs instead?

Copilot AI commented May 25, 2026

Copy link
Copy Markdown
Author

@copilot Should we require Rust 1.91 and update the docs instead?

No, I don't think we need to bump to 1.91. The only thing requiring 1.91 is compiling wasm-pack itself (a build tool), not the user's project code. The current fix (cargo +nightly install) is clean since nightly is already a requirement for the wasm build. Users' non-wasm code still compiles fine on Rust 1.88. Bumping the minimum to 1.91 would unnecessarily break users who don't use wasm and are on older stable Rust.

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.

2 participants