Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Panic when trying to run with dependencies #3640

Closed
nappa85 opened this issue Oct 3, 2023 · 4 comments
Closed

Panic when trying to run with dependencies #3640

nappa85 opened this issue Oct 3, 2023 · 4 comments
Labels

Comments

@nappa85
Copy link

nappa85 commented Oct 3, 2023

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?

@nappa85 nappa85 added the bug label Oct 3, 2023
@Liamolucko
Copy link
Collaborator

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.

I don't think that's the issue. target/release/deps is just an internal folder where cargo 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 mostly rlib files for dependencies though, not wasm 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 with wasm-bindgen, and was actually disabled in #3233 (not released yet). Is there any particular reason why you're using wasm32-wasi? Does this issue still happen when you use wasm32-unknown-unknown?

@nappa85
Copy link
Author

nappa85 commented 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...

@hamza1311
Copy link
Collaborator

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
Copy link
Author

nappa85 commented Oct 4, 2023 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants