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

How to use per-project wasm-bindgen-cli version? #2702

Closed
demurgos opened this issue Oct 18, 2021 · 5 comments
Closed

How to use per-project wasm-bindgen-cli version? #2702

demurgos opened this issue Oct 18, 2021 · 5 comments
Labels

Comments

@demurgos
Copy link

demurgos commented Oct 18, 2021

Summary

I have two projects on my computer depending on WasmBindgen, but requiring different versions. How can I specify and pin the right wasm-bindgen-cli version on a per-project basis so it always matches the corresponding wasm-bindgen lib version?

Additional Details

My first Cargo.toml contains:

[target.'cfg(target_arch = "wasm32")'.dependencies]
wasm-bindgen = "=0.2.67"

My second Cargo.toml was freshly updated and contains:

[target.'cfg(target_arch = "wasm32")'.dependencies]
wasm-bindgen = "=0.2.78"

On my system I have a single global wasm-bindgen installation:

$ wasm-bindgen --version
wasm-bindgen 0.2.67

I can't compile the recently updated project:

thread 'main' panicked at 'remaining data [19]', /home/demurgos/.cargo/registry/src/github.aaakk.us.kg-1ecc6299db9ec823/wasm-bindgen-cli-support-0.2.67/src/descriptor.rs:109:9
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

So I updated my globally installed wasm-bindgen CLI as documented:

cargo install -f wasm-bindgen-cli

But now I can't build my older project:

thread 'main' panicked at 'index out of bounds: the len is 0 but the index is 0', /home/demurgos/.cargo/registry/src/github.aaakk.us.kg-1ecc6299db9ec823/wasm-bindgen-cli-support-0.2.78/src/descriptor.rs:205:15
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

I believe that those are some relevant Cargo issues, but I feel that there is no good solution at the moment. How do you handle this problem for your own projects?

@chinedufn
Copy link
Contributor

chinedufn commented Oct 18, 2021

That

thread 'main' panicked at 'index out of bounds: the len is 0 but the index is 0', /home/demurgos/.cargo/registry/src/github.aaakk.us.kg-1ecc6299db9ec823/wasm-bindgen-cli-support-0.2.78/src/descriptor.rs:205:15

error is unfortunate. Versions 2.78+ have a better error message than that. You're seeing that because the old project is <2.78. Sorry!


The most popular way that people handle this right now is by using wasm-pack or by updating old projects whenever wasm-bindgen's internal schema changes (infrequent).

Some potential options for you:

  1. Download the release binaries that you need and use them accordingly

  2. OR use or write something like wasm-pack. It checks your Cargo.toml to figure out the necessary CLI version and then downloads it.

@demurgos
Copy link
Author

Thank you for your reply, I will look into these solutions.

@alexcrichton
Copy link
Contributor

I don't have much to add over what @chinedufn already said (thanks!), so I'm going to close.

@zopsicle
Copy link

zopsicle commented Sep 8, 2022

You can depend on wasm-bindgen-cli-support using regular Cargo dependencies and then write your own binary, like this:

use wasm_bindgen_cli_support::Bindgen;

fn main()
{
    Bindgen::new()
        .input_path("my-wasm-file.wasm")
        .generate("my-out-dir")
        .unwrap();
}

@demurgos
Copy link
Author

demurgos commented Dec 3, 2023

@chloekek Thank you very much, using wasm-bindgen-cli-support in a local bin wrapper works great and lets me version it properly. :)

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

4 participants