Skip to content

Panic when trying to run with dependencies #3640

Closed
@nappa85

Description

@nappa85

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

Liamolucko commented on Oct 3, 2023

@Liamolucko
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

nappa85 commented on Oct 4, 2023

@nappa85
Author

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

ranile commented on Oct 4, 2023

@ranile
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

nappa85 commented on Oct 4, 2023

@nappa85
Author
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @nappa85@Liamolucko@ranile

        Issue actions

          Panic when trying to run with dependencies · Issue #3640 · rustwasm/wasm-bindgen