rustwasm / wasm-bindgen

Facilitating high-level interactions between Wasm modules and JavaScript
https://rustwasm.github.io/docs/wasm-bindgen/
Apache License 2.0
7.84k stars 1.08k forks source link

wasm-bindgen >= 0.2.94 generates undesired `table.fill` instructions when used with rust 1.82.0 #4250

Closed eric-seppanen closed 2 weeks ago

eric-seppanen commented 2 weeks ago

Describe the Bug

When using rust 1.82.0 and wasm-bindgen 0.2.94 or 0.2.95, builds fail because the wasm-bindgen output includes table.fill instructions that are poorly supported by downstream tools (namely, Trunk).

Steps to Reproduce

Reproducible two ways: With Trunk 0.21.2 and rust 1.82.0:

  1. Using the partially-minimized repo https://github.com/eric-seppanen/wasm_test_2024
  2. trunk build --release

Or, using rust 1.82.0, wasm-bindgen 0.2.95, and wasm-opt v116:

  1. Using the partially-minimized repo https://github.com/eric-seppanen/wasm_test_2024
  2. cargo build --target=wasm32-unknown-unknown --release --bin wasm_test_2024
  3. wasm-bindgen --target=web --out-dir=target/wasm-bindgen/release --out-name=wasm_test_2024 target/wasm32-unknown-unknown/release/wasm_test_2024.wasm --no-typescript
  4. wasm-opt -Oz target/wasm-bindgen/release/wasm_test_2024_bg.wasm --output wasm-opt.out

The failure can't be reproduced with rust 1.81.0.

Expected Behavior

No table.fill instructions.

Trunk's bundled wasm-opt can't handle them (and doesn't yet support the CLI changes needed to enable bulk-memory in wasm-opt >= v117).

Actual Behavior

wasm-opt (version 116, as bundled by Trunk) fails with:

[parse exception: invalid code after misc prefix: 17 (at 0:20646)]

I am informed that this means that wasm-bindgen emitted table.fill instructions.

Additional Context

I expect this is a duplicate issue, because the wasm-bindgen main branch seems to work, presumably because #4237 solved this? (the changlelog entry says Only emit table.fill instructions if the bulk-memory proposal is enabled.)

I wanted to write this up anyway because I didn't see my failure symptom described in any current issues, and wanted to ensure that I was correctly understanding the problem and its solution (can we get the fix in a new release?)

(Related issue in Trunk repo)

insipx commented 2 weeks ago

Ran into this issue, and fixed by using an up-to-date wasm-opt. You can use the one on npmjs or install the one from the binaryen repo. wasm-opt on nixpkgs also works

wasm-opt from crates.io is not updated as often, so sometimes lacks more recent features

eric-seppanen commented 2 weeks ago

While this is true, it's not practical with Trunk. Newer versions (117+) of wasm-opt require the CLI flag --enable-bulk-memory to be able to operate on these files, and Trunk currently does not have the ability to set the wasm-opt parameters that are used. (edit: Trunk 0.21.3 added this ability.)

Since this issue (unexpectedly enabling bulk-memory instructions) has already been fixed on master, all that is needed for wasm-bindgen to cut a new release.

daxpedda commented 2 weeks ago

Indeed, this has been addressed by #4237 and I plan to make a new release soon.