Closed
Description
wasm-bindgen
panics on my application with this message:
wasm-bindgen --target web --out-dir . target/wasm32-wasi/release/my_project.wasm
thread 'main' panicked at 'assertion failed: `(left == right)`
left: `3`,
right: `1`', ~/.cargo/registry/src/index.crates.io-6f17d22bba15001f/wasm-bindgen-cli-support-0.2.87/src/js/binding.rs:172:9
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
From what I've been able to understand, this is due the fact my application generates more than one wasm
file in target/wasm32-wasi/release/deps/
, where the second one is called wasm_streams-4a21c93a06539d08.wasm
.
If I remove the proc-macro and manually export my methods as extern "C"
(thus removing all the describing code), wasm-bindgen
starts working and exports what I think are methods from the other wasm
file.
What's the solution in this situation?
Activity
Liamolucko commentedon Oct 3, 2023
I don't think that's the issue.
target/release/deps
is just an internal folder wherecargo
keeps the results of building your Rust dependencies, and it's not actually referenced by the final wasm file: the last step of compiling is to merge all those dependencies into a single wasm file. (Usually it's mostlyrlib
files for dependencies though, notwasm
files, so I'm not too sure what's going on there.)It might be because you're using
wasm32-wasi
, which often doesn't work properly withwasm-bindgen
, and was actually disabled in #3233 (not released yet). Is there any particular reason why you're usingwasm32-wasi
? Does this issue still happen when you usewasm32-unknown-unknown
?nappa85 commentedon Oct 4, 2023
In facts it was a test I didn't do, building with
wasm32-wasi
an example crate gives the same problems.I'm building with
wasm32-wasi
because I don't have full control over the deps, and many of the crates in my deps tree works on wasi but not on wasm (e.g. https://crates.io/crates/im)I see that with #3233 everything will stop working, I'll have to find another approach...
ranile commentedon Oct 4, 2023
You don't need to use wasm-bindgen if you want to use WASI. If a dependency can't be compiled to wasm32-unknown-unknown, it can't be run in browser anyway.
I suggest you look into WASI runtimes such as wasmtime for running your app as WASM
nappa85 commentedon Oct 4, 2023