wasm-bindgen icon indicating copy to clipboard operation
wasm-bindgen copied to clipboard

`wasm-bindgen` fails to run due to assert

Open hukasu opened this issue 1 month ago • 12 comments

I just joined a team on a wasm project and wasm-pack is used to prepare the web deploy, but both with 0.2.100 and 0.2.105 on my Linux machine it fails with this error

thread 'main' panicked at /build/wasm-bindgen-cli-0.2.100-vendor/wasm-bindgen-threads-xform-0.2.100/src/lib.rs:74:5:
assertion failed: mem.import.is_some()
stack backtrace:
   0:     0x5600e5da1680 - <std::sys::backtrace::BacktraceLock::print::DisplayBacktrace as core::fmt::Display>::fmt::h9edbd6e38a8b0805
   1:     0x5600e5dbcf63 - core::fmt::write::h7b1248e5e0c79c78
   2:     0x5600e5d73d43 - std::io::Write::write_fmt::h5e301665499081bf
   3:     0x5600e5da1523 - std::sys::backtrace::BacktraceLock::print::h4a386d2ef944f43e
   4:     0x5600e5d9d3dc - std::panicking::default_hook::{{closure}}::h61b7aa0fc15f236b
   5:     0x5600e5d9d2e9 - std::panicking::default_hook::h2d21379b0b23a14f
   6:     0x5600e5d9d90f - std::panicking::rust_panic_with_hook::h100726ba9570b85a
   7:     0x5600e5da1b66 - std::panicking::begin_panic_handler::{{closure}}::h141712493bfacf0c
   8:     0x5600e5da1899 - std::sys::backtrace::__rust_end_short_backtrace::h891003731531c924
   9:     0x5600e5d9d47d - rust_begin_unwind
  10:     0x5600e5a286a0 - core::panicking::panic_fmt::h1df68d570cb2382b
  11:     0x5600e5a2872c - core::panicking::panic::he6cc393dce485baf
  12:     0x5600e5bca7d2 - wasm_bindgen_threads_xform::run::h44cca9a3d2f78f5b
  13:     0x5600e5b16ecf - wasm_bindgen_cli_support::Bindgen::generate_output::ha692af2767a53886
  14:     0x5600e5a3dbb0 - wasm_bindgen_cli_support::Bindgen::generate::hbfb0a81d50fa1bf1
  15:     0x5600e5a2c1f4 - wasm_bindgen::main::hc608f260fd81fe71
  16:     0x5600e5a37693 - std::sys::backtrace::__rust_begin_short_backtrace::h6d944d5c08dd9485
  17:     0x5600e5a3dca9 - std::rt::lang_start::{{closure}}::h79150d63ab3b4395
  18:     0x5600e5d7d065 - std::rt::lang_start_internal::he3cad277a2bdfe30
  19:     0x5600e5a367f5 - main
  20:     0x7f3223a2a47e - __libc_start_call_main
  21:     0x7f3223a2a539 - __libc_start_main_alias_1
  22:     0x5600e5a28ca5 - _start
  23:                0x0 - <unknown>
Error: Running the wasm-bindgen CLI
Caused by: Running the wasm-bindgen CLI
Caused by: failed to execute `wasm-bindgen`: exited with exit status: 101
  full command: "/nix/store/iy0jb006n1x5dajpypz0ypqb5hk6lhrg-wasm-bindgen-cli-0.2.100/bin/wasm-bindgen" "/mnt/data/Code/decentraland/target/wasm32-unknown-unknown/release/webgpu_build.wasm" "--out-dir" "/mnt/data/Code/decentraland/deploy/web/pkg" "--typescript" "--target" "web"

The other members do not run into this issue, but none of them are on Linux

hukasu avatar Nov 24 '25 23:11 hukasu

Could you provide a reproducible example?

Spxg avatar Nov 25 '25 01:11 Spxg

it is this project https://github.com/decentraland/bevy-explorer

hukasu avatar Nov 25 '25 01:11 hukasu

@hukasu can you share the wasm binary in the Rust target folder that was produced by wasm pack here?

guybedford avatar Nov 25 '25 01:11 guybedford

drive link because it is a heavy boi https://drive.google.com/file/d/1zD2-mMAoH7d0boeVrcpKid7dKXbPBYmI/view?usp=drive_link

hukasu avatar Nov 25 '25 01:11 hukasu

I've requested access.

guybedford avatar Nov 25 '25 01:11 guybedford

Done

hukasu avatar Nov 25 '25 01:11 hukasu

It looks like the binary exports its memory instead of importing it which is needed for shared memory. So the problem is in the cargo call from wasm pack giving the wrong binary.

guybedford avatar Nov 25 '25 02:11 guybedford

any idea of what might cause this? rustflags? something on Cargo.toml? .cargo/config.toml?

hukasu avatar Nov 25 '25 12:11 hukasu

it was rustc version it seems, dropped from 2025-11-09 to 2025-06-03 and wasm-pack finished without issue

hukasu avatar Nov 25 '25 12:11 hukasu

Seem like https://github.com/wasm-bindgen/wasm-bindgen/pull/4717

Spxg avatar Nov 25 '25 15:11 Spxg

is it a question of updating the -C rustflags? or is there something else to it?

hukasu avatar Nov 25 '25 16:11 hukasu

I'm not sure if that's the issue. Are you using atomics target-features? If so, try these flags:

-Ctarget-feature=+atomics -Clink-args=--shared-memory -Clink-args=--max-memory=1073741824 -Clink-args=--import-memory -Clink-args=--export=__wasm_init_tls -Clink-args=--export=__tls_size -Clink-args=--export=__tls_align -Clink-args=--export=__tls_base

Spxg avatar Nov 25 '25 16:11 Spxg