Closed
Description
Describe the Bug
The Hello World! example fails to run or even compile with Rust 1.82.0, presumably due to reference types. That example uses webpack with a configuration that will invoke @webassemblyjs/wasm-parser which doesn't support reference types. This other bug report has a backtrace that is similar to what happens now.
Steps to Reproduce (when using Rust 1.82.0)
cd examples/hello_world
- install the needed node packages (I used
yarn install
, I'm sure npm has something similar, possiblynpm install
) - Try to build (e.g.
npm run build
oryarn build
) - See backtrace
Everything you need is in this repository other than installing the npm modules.
Expected Behavior
[main]% rustup default 1.81.0
rustup default 1.81.0
info: using existing install for '1.81.0-x86_64-apple-darwin'
info: default toolchain set to '1.81.0-x86_64-apple-darwin'
1.81.0-x86_64-apple-darwin unchanged - rustc 1.81.0 (eeb90cda1 2024-09-04)
[main]% npm run build
npm run build
> build
> webpack
🧐 Checking for wasm-pack...
✅ wasm-pack is installed at /Users/ctm/.cargo/bin/wasm-pack.
ℹ️ Compiling your crate in development mode...
[INFO]: 🎯 Checking for the Wasm target...
[INFO]: 🌀 Compiling to Wasm...
Compiling hello_world v0.0.0 (/Users/ctm/git_others/wasm-bindgen/examples/hello_world)
Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.43s
[INFO]: Optional fields missing from Cargo.toml: 'description', 'repository', and 'license'. These are not necessary, but recommended
[INFO]: ✨ Done in 0.87s
[INFO]: 📦 Your wasm pkg is ready to publish at /Users/ctm/git_others/wasm-bindgen/examples/hello_world/pkg.
✅ Your crate has been correctly compiled
assets by status 54 KiB [cached] 1 asset
asset index.js 16.3 KiB [emitted] (name: main)
asset index.html 232 bytes [compared for emit]
runtime modules 4.87 KiB 7 modules
cacheable modules 3.61 KiB (javascript) 54 KiB (webassembly)
modules by path ./pkg/*.js 3.5 KiB
./pkg/index.js 141 bytes [built] [code generated]
./pkg/index_bg.js 3.36 KiB [built] [code generated]
./index.js 48 bytes [built] [code generated]
./pkg/index_bg.wasm 70 bytes (javascript) 54 KiB (webassembly) [built] [code generated]
webpack 5.95.0 compiled successfully in 1640 ms
Actual Behavior
[main]% rustup default stable
rustup default stable
info: using existing install for 'stable-x86_64-apple-darwin'
info: default toolchain set to 'stable-x86_64-apple-darwin'
stable-x86_64-apple-darwin unchanged - rustc 1.82.0 (f6e511eec 2024-10-15)
[main]% npm run build
npm run build
> build
> webpack
🧐 Checking for wasm-pack...
✅ wasm-pack is installed at /Users/ctm/.cargo/bin/wasm-pack.
ℹ️ Compiling your crate in development mode...
[INFO]: 🎯 Checking for the Wasm target...
[INFO]: 🌀 Compiling to Wasm...
Compiling hello_world v0.0.0 (/Users/ctm/git_others/wasm-bindgen/examples/hello_world)
Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.37s
[INFO]: Optional fields missing from Cargo.toml: 'description', 'repository', and 'license'. These are not necessary, but recommended
[INFO]: ✨ Done in 0.80s
[INFO]: 📦 Your wasm pkg is ready to publish at /Users/ctm/git_others/wasm-bindgen/examples/hello_world/pkg.
✅ Your crate has been correctly compiled
assets by status 1.58 KiB [cached] 1 asset
asset index.js 13.2 KiB [emitted] (name: main)
asset index.html 232 bytes [compared for emit]
runtime modules 1.77 KiB 4 modules
cacheable modules 3.91 KiB (javascript) 56.1 KiB (webassembly)
modules by path ./pkg/*.js 3.82 KiB
./pkg/index.js 167 bytes [built] [code generated]
./pkg/index_bg.js 3.66 KiB [built] [code generated]
./index.js 48 bytes [built] [code generated]
./pkg/index_bg.wasm 40 bytes (javascript) 56.1 KiB (webassembly) [built] [code generated] [1 error]
ERROR in ./pkg/index_bg.wasm
Module parse failed: Unknown element type in table: 0xNaN
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
Error: Unknown element type in table: 0xNaN
at parseTableType (/Users/ctm/git_others/wasm-bindgen/examples/hello_world/node_modules/@webassemblyjs/wasm-parser/lib/decoder.js:1018:13)
at parseTableSection (/Users/ctm/git_others/wasm-bindgen/examples/hello_world/node_modules/@webassemblyjs/wasm-parser/lib/decoder.js:1274:24)
at parseSection (/Users/ctm/git_others/wasm-bindgen/examples/hello_world/node_modules/@webassemblyjs/wasm-parser/lib/decoder.js:1406:24)
at Object.decode (/Users/ctm/git_others/wasm-bindgen/examples/hello_world/node_modules/@webassemblyjs/wasm-parser/lib/decoder.js:1740:25)
at decode (/Users/ctm/git_others/wasm-bindgen/examples/hello_world/node_modules/@webassemblyjs/wasm-parser/lib/index.js:253:21)
at WebAssemblyParser.parse (/Users/ctm/git_others/wasm-bindgen/examples/hello_world/node_modules/webpack/lib/wasm-async/AsyncWebAssemblyParser.js:61:19)
at /Users/ctm/git_others/wasm-bindgen/examples/hello_world/node_modules/webpack/lib/NormalModule.js:1303:19
at processResult (/Users/ctm/git_others/wasm-bindgen/examples/hello_world/node_modules/webpack/lib/NormalModule.js:937:11)
at /Users/ctm/git_others/wasm-bindgen/examples/hello_world/node_modules/webpack/lib/NormalModule.js:1030:5
at /Users/ctm/git_others/wasm-bindgen/examples/hello_world/node_modules/loader-runner/lib/LoaderRunner.js:407:3
@ ./pkg/index.js 1:0-40 4:15-19 5:0-21
@ ./index.js 1:0-30 3:0-5
webpack 5.95.0 compiled with 1 error in 1532 ms
Additional Context
I believe this can be fixed by disabling the reference-types
feature for wasm32-unknown-unknown
, however even after reading the Enabled WebAssembly Features
section of the rustc book (and trying various things), I have not been successful at disabling that feature.