wasm32-unknown-emscripten: unresolved __wbindgen_placeholder__ import prevents WebAssembly.instantiate()
Description
When compiling a Rust project for the wasm32-unknown-emscripten target
(using emsdk 6.0.9 with emcc + Ninja), the resulting .wasm module contains
unresolved __wbindgen_* and __wbg_* imports that prevent
WebAssembly.instantiate() from succeeding, even when all feature flags
for web backends (webgpu / webgl) are disabled.
This makes it impossible to use wgpu as a dependency in any project that
targets Emscripten (e.g. SDL3-based engines that compile via
cargo build --target wasm32-unknown-emscripten).
Environment
- wgpu: 30.0.0
- rustc: 1.85+ (edition 2024)
- target:
wasm32-unknown-emscripten - emsdk: 6.0.9 (emcc 6.0.9, Ninja, node 24.19.0)
- SDL3: 3.4.12 (static, built from source via sdl3-sys)
Steps to reproduce
- Create a minimal lib with
wgpu = "30.0.0"in[dependencies] - Run:
cargo check --target wasm32-unknown-emscripten - The check passes at compile time (with ERROR_ON_UNDEFINED_SYMBOLS=0 tolerating unresolved symbols at link time)
- Deploy the
.js+.wasmto a browser with an HTML shell - Browser fails at instantiation:
LinkError: WebAssembly.instantiate(): Import #19 "__wbindgen_placeholder__": module is not an object or function
Root cause analysis
wgpu 30.0.0's Cargo.toml declares wasm-bindgen, web-sys, and js-sys
as unconditional dependencies for cfg(target_arch = "wasm32") (which includes
emscripten). The compiled code references wasm-bindgen runtime symbols
(__wbindgen_placeholder__, __wbg_*) that require wasm-bindgen CLI
post-processing — which is only available for wasm32-unknown-unknown
(not emscripten).
On the emscripten target, these symbols cannot be resolved because:
wasm-bindgenCLI does not support emscripten-built wasm output- Emscripten's JS glue does not provide the wasm-bindgen runtime
Impact
Any project that uses both SDL3 (via emscripten) and wgpu cannot target Web — the emscripten build is blocked at instantiation by the unresolved wasm-bindgen imports.
Source: gfx-rs/wgpu