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

old wasm-bindgen being run instead of new #853

Closed
ctaggart opened this issue May 30, 2020 · 6 comments
Closed

old wasm-bindgen being run instead of new #853

ctaggart opened this issue May 30, 2020 · 6 comments

Comments

@ctaggart
Copy link

🐛 Bug description

The Cargo.lock file has two wasm-bindgen entries and the wrong one is being picked and used.

[[package]]
name = "wasm-bindgen"
version = "0.2.19"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6dbe59a66beb5f8f5cfb2b5fa7a672173b965fdf0e16cdff89baaa58e48e86ff"
dependencies = [
 "wasm-bindgen-macro 0.2.19",
]

[[package]]
name = "wasm-bindgen"
version = "0.2.63"
source = "git+https://github.com/rustwasm/wasm-bindgen#cc36bdc00d3a41c67ee0a2c0af04a7c4323637a5"
dependencies = [
 "cfg-if",
 "wasm-bindgen-macro 0.2.63",
]

The old 0.2.19 is a dependency from console_error_panic_hook, coming from wasm-bindgen-test.

🤔 Expected Behavior

It picks 0.2.63 instead of 0.2.19.

🌍 Your environment

Camerons-MacBook-Pro:monaco-hello-world cameron$ wasm-pack --version
wasm-pack 0.9.1
Camerons-MacBook-Pro:monaco-hello-world cameron$ rustc --version
rustc 1.45.0-nightly (451272115 2020-05-28)
@ctaggart
Copy link
Author

ctaggart commented May 30, 2020

👟 Steps to reproduce

git clone git@github.com:taggartsoftware/ts2rs.git
cd ts2rs
git checkout 0ceeae9e3486761d02d2e65b41aaa73a7fe9193c
cd monaco-hello-world
npm start

@ctaggart
Copy link
Author

Here is what the error looks like when version 0.2.19 is selected and used.

Camerons-MacBook-Pro:monaco-hello-world cameron$ npm start

> monaco-hello-world@ start /Users/cameron/rs/ts2rs/monaco-hello-world
> rimraf dist pkg && webpack-dev-server --open -d

🧐  Checking for wasm-pack...

✅  wasm-pack is installed. 

ℹ️  Compiling your crate in development mode...

ℹ 「wds」: Project is running at http://localhost:8080/
ℹ 「wds」: webpack output is served from /
ℹ 「wds」: Content not from webpack is served from /Users/cameron/rs/ts2rs/monaco-hello-world/dist
ℹ 「wdm」: wait until bundle finished: /
[INFO]: 🎯  Checking for the Wasm target...
[INFO]: 🌀  Compiling to Wasm...
    Finished dev [unoptimized + debuginfo] target(s) in 0.06s
[INFO]: ⬇️  Installing wasm-bindgen...
Unknown flag: '--out-name'

Usage:
    wasm-bindgen [options] <input>
    wasm-bindgen -h | --help
    wasm-bindgen -V | --version
Error: Running the wasm-bindgen CLI
Caused by: failed to execute `wasm-bindgen`: exited with exit code: 1
  full command: "/Users/cameron/Library/Caches/.wasm-pack/wasm-bindgen-57f6f6a265a0d2ec/wasm-bindgen" "/Users/cameron/rs/ts2rs/target/wasm32-unknown-unknown/debug/monaco_hello_world.wasm" "--out-dir" "/Users/cameron/rs/ts2rs/monaco-hello-world/pkg" "--typescript" "--browser" "--out-name" "index" "--debug"
ℹ 「wdm」: Hash: 06191cb5d8b21ceb7adf
Version: webpack 4.43.0
Time: 3009ms
Built at: 05/29/2020 7:11:12 PM
     Asset       Size  Chunks             Chunk Names
      0.js  520 bytes       0  [emitted]  
index.html  319 bytes          [emitted]  
  index.js    897 KiB   index  [emitted]  index
Entrypoint index = index.js

Camerons-MacBook-Pro:monaco-hello-world cameron$ "/Users/cameron/Library/Caches/.wasm-pack/wasm-bindgen-57f6f6a265a0d2ec/wasm-bindgen" --version
wasm-bindgen 0.2.19 (d9bc0a317)

Then if you run the command directly, you see the out-name is not supported in 0.2.19 from almost two years ago. The fix is that 0.2.63 should be selected.

ctaggart added a commit to taggartsoftware/ts2rs that referenced this issue Jun 1, 2020
* working example in JavaScript

* copy sample and add rust webpackage template
manually mapped wasm-bindgen calls for monaco.editor

* commit to reproduce rustwasm/wasm-pack#853

* rust example runs, js_namespace on function

* renamed to monaco-editor-hello-world

* configure Monaco environment in rust

* move index.js

* ignore pkg/ too

* move bindings to module
@DzmitryFil
Copy link

old bindgen is crashing on me also

@Pauan
Copy link
Contributor

Pauan commented Jun 4, 2020

This isn't a bug in Rust, wasm-bindgen, or wasm-pack, it is a mistake in your code.

When you specify wasm-bindgen = { git = "https://github.com/rustwasm/wasm-bindgen" } you are saying that Cargo should import a new wasm-bindgen package (which is unrelated to the wasm-bindgen package which is used by console_error_panic_hook).

So you will have two different packages which are both called wasm-bindgen (even though they are unrelated).

The reason why this happens is because Cargo treats crates.io packages and git packages as completely separate. This is similar to how Cargo treats version 1.0 as completely separate from version 2.0.

The way to fix this is to use [patch] to override the version of wasm-bindgen:

[patch.crates-io]
wasm-bindgen = { git = "https://github.com/rustwasm/wasm-bindgen" }

What this does is it tells Cargo that whenever it imports the wasm-bindgen crate, it should instead import the GitHub repo. This affects both your crate and also any dependencies that you're using.

You will probably need to add some patches for other crates as well:

[patch.crates-io]
wasm-bindgen = { git = "https://github.com/rustwasm/wasm-bindgen" }
wasm-bindgen-shared = { git = "https://github.com/rustwasm/wasm-bindgen" }
wasm-bindgen-backend = { git = "https://github.com/rustwasm/wasm-bindgen" }
wasm-bindgen-macro = { git = "https://github.com/rustwasm/wasm-bindgen" }
js-sys = { git = "https://github.com/rustwasm/wasm-bindgen" }
web-sys = { git = "https://github.com/rustwasm/wasm-bindgen" }

@Pauan Pauan closed this as completed Jun 4, 2020
@ctaggart
Copy link
Author

ctaggart commented Jun 4, 2020

Thank you @Pauan for the detailed explanation! ❤️

@ctaggart
Copy link
Author

ctaggart commented Jun 5, 2020

Confirming that it worked. In my case, I just had to override wasm-bindgen:

[patch.crates-io]
wasm-bindgen = { git = "https://github.com/rustwasm/wasm-bindgen" }

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

No branches or pull requests

3 participants