Open ctm opened 3 days ago
I second this, cannot get this working on latest versions
Rust: 1.82 Webpack: 5.95.0 wasm-bindgen: 0.2.95
Trying to add a wasm
rule in my Webpack config just leads to different errors:
module: {
rules: [
{
test: /\.wasm$/,
type: "asset/resource"
}
]
},
ERROR in ../pkg/index.js 5:0-21
Can't import the named export '__wbindgen_start' (imported as 'wasm') from default-exporting module (only default export is available)
@ ./index.js 1:0-43 4:17-29
@ ./bootstrap.js 4:0-20
Upon further reading and experimenting, I suspect that for now it will simply impossible to use 1.82.0 with anything that uses wasm-pack
, because disabling reference-types
requires unstable features and 1.82.0 itself is stable. If so, this demo won't be able to use a stable 1.82 or later rust release until they either make it so that reference-types is not enabled by default or provide a stable way (that works through the wasm-pack
stack) to disable that default.
Similarly, Rust 1.82 and Node 18 don't play well together when running wasm-bindgen-test
, as node will crash with a bit of a nasty stacktrace.
So there's multiple things at play here. LLVM activated the reference-types
feature by default, which got pulled into Rust 1.82. The reference-types
feature generally affects almost nothing in how LLVM generates code, except it now supports some extended table index encoding.
The problem is that wasm-bindgen
looks at the features section of the module and assumes that you want FULL reference-types
support. It does so here:
Usually you are meant to use the wasm-bindgen
CLI flag --reference-types
to achieve the same effect. But this automatic detection above activates it anyway now.
This by itself isn't really a problem, but webpack
, or rather its webassemblyjs
dependency is mostly unmaintained and does not currently support the reference-types
proposal.
@daxpedda I propose that wasm-bindgen
for the time being should be patched to not automatically turn on the externref
support if it detects it from the features section. I can do that PR if you think this is the right course of action.
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
yarn install
, I'm sure npm has something similar, possiblynpm install
)npm run build
oryarn build
)Everything you need is in this repository other than installing the npm modules.
Expected Behavior
Actual Behavior
Additional Context
I believe this can be fixed by disabling the
reference-types
feature forwasm32-unknown-unknown
, however even after reading theEnabled WebAssembly Features
section of the rustc book (and trying various things), I have not been successful at disabling that feature.