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

Cache hits even if wasm-bindgen binary is missing #508

Closed
danwilhelm opened this issue Jan 17, 2019 · 3 comments
Closed

Cache hits even if wasm-bindgen binary is missing #508

danwilhelm opened this issue Jan 17, 2019 · 3 comments
Assignees
Labels
bug Something isn't working changelog - fix PR attached there's a PR open for this issue

Comments

@danwilhelm
Copy link
Member

danwilhelm commented Jan 17, 2019

🐛 Bug description

This bug affects some v0.6.0 users who will upgrade to v0.6.1, including #497 and #503.

The wasm-bindgen cache falsely reports a hit when the cache directory exists, but the binary does not.

This causes wasm-pack to fail on all subsequent builds requiring a cargo install (at least until the next wasm-bindgen version is released!).

🤔 Expected Behavior

When the wasm-bindgen binary is missing, a new cache should be created that overwrites the old one.

👟 Steps to reproduce

Occurs when all four are present:

  1. wasm-bindgen is not in $PATH.
  2. A prebuilt binary is not available (e.g. no Internet, no Windows build).
  3. wasm-bindgen has been installed previously to the cache.
  4. The wasm-bindgen binary in the cache has been removed.

MAC reproduction (Linux is similar)

In any WASM project:

  1. cargo uninstall wasm-bindgen (removes wasm-bindgen from $PATH)
  2. cargo build (creates the lockfile)
  3. rm -rf ~/Library/Caches/.wasm_pack (removes existing cache)
  4. mkdir -p ~/Library/Caches/.wasm_pack/wasm-bindgen-cargo-install-0.2.32 (creates a fake cargo install without a binary)
  5. Disconnect from the Internet (makes the pre-built binary unavailable)
  6. wasm-pack build <-- Use master

Should fail with:

Error: /Users/<username>/Library/Caches/.wasm_pack/wasm-bindgen-cargo-install-0.2.32/wasm-bindgen binary does not exist


WINDOWS reproduction (easier!)

In any WASM project:

  1. cargo uninstall wasm-bindgen (removes wasm-bindgen from $PATH)
  2. rm -rf ~\AppData\Local\.wasm_pack (removes existing cache)
  3. wasm-pack build <-- Use v0.6.0 (should fail at end)
  4. wasm-pack build <-- Use master

Note: This is shorter because the current version of wasm-bindgen does not have pre-built Windows binaries. So, it always defaults to cargo install. In wasm-pack v0.6.0, the correct cache directory is created, yet the binaries are not copied from /bin.

Should fail with:

Error: C:\Users\<username>\Local\.wasm_pack\wasm-bindgen-cargo-install-0.2.32\wasm-bindgen.exe binary does not exist

🌍 Your environment

Include the relevant details of your environment.
wasm-pack version: master branch
rustc version: rustc 1.33.0-nightly (8e2063d02 2019-01-07)

danwilhelm added a commit to danwilhelm/wasm-pack that referenced this issue Jan 17, 2019
Issue rustwasm#508

1. Tests the cache for the `wasm-bindgen` binary. Previously, only
tested for the directory.

2. Removes the `wasm-bindgen` cache directory if it already exists,
prior to renaming the temporary cache directory.
@danwilhelm
Copy link
Member Author

Fixed in #509

@ashleygwilliams ashleygwilliams added bug Something isn't working PR attached there's a PR open for this issue labels Jan 17, 2019
@ashleygwilliams ashleygwilliams added this to the 0.6.1 milestone Jan 17, 2019
@ashleygwilliams ashleygwilliams self-assigned this Jan 18, 2019
@ashleygwilliams ashleygwilliams removed this from the 0.7.0 milestone Mar 15, 2019
@cmdcolin
Copy link

just for some posterity I was running into this somehow and I was getting weird errors trying to use the hello-world example in wasm-bindgen starter guide e.g. I would download the hello-world example, run npm run serve, then open the browser to http://localhost:8080 and there would be nothing except this in the dev console

TypeError: m.greet is not a function

in the npm run serve output it would say

~/Downloads/wasm-bindgen/examples/hello_world on main
% npm run serve

> serve
> webpack serve

🧐  Checking for wasm-pack...

✅  wasm-pack is installed at /run/user/1001/fnm_multishells/2028640_1659075796381/bin/wasm-pack.

ℹ️  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 /home/cdiesh/Downloads/wasm-bindgen/examples/hello_world
[INFO]: Checking for the Wasm target...
[INFO]: Compiling to Wasm...
    Finished dev [unoptimized + debuginfo] target(s) in 0.05s
[INFO]: Installing wasm-bindgen...
Error: /home/cdiesh/.cache/.wasm-pack/wasm-bindgen-5edfed224f62a9f4/wasm-bindgen binary does not exist
ℹ 「wdm」: asset index.js 339 KiB [emitted] (name: main)
asset pkg_index_js.index.js 833 bytes [emitted]
asset index.html 232 bytes [emitted]
runtime modules 7.81 KiB 11 modules
modules by path ./node_modules/ 298 KiB
  modules by path ./node_modules/webpack-dev-server/ 21.2 KiB 12 modules
  modules by path ./node_modules/html-entities/lib/*.js 61 KiB 5 modules
  modules by path ./node_modules/webpack/hot/ 1.58 KiB 3 modules
  modules by path ./node_modules/url/ 37.4 KiB
    ./node_modules/url/url.js 22.8 KiB [built] [code generated]
    + 2 modules
  modules by path ./node_modules/querystring/*.js 4.51 KiB
    ./node_modules/querystring/index.js 127 bytes [built] [code generated]
    + 2 modules
  + 4 modules
./index.js 266 bytes [built] [code generated]
./pkg/index.js 1 bytes [built] [code generated]
webpack 5.74.0 compiled successfully in 702 ms
ℹ 「wdm」: Compiled successfully.

I had to look closely to see that it was not a success (everything was green) but a failure because of

Error: /home/cdiesh/.cache/.wasm-pack/wasm-bindgen-5edfed224f62a9f4/wasm-bindgen binary does not exist

The fix

I manually ran rm -rf ~/.cache/.wasm-pack and then re-ran the hello-world example npm run serve and it gave the correct compilation

~/wasm-bindgen/examples/hello_world on main took 6m13s
130 % npm run serve

> serve
> webpack serve

🧐  Checking for wasm-pack...

✅  wasm-pack is installed at /run/user/1001/fnm_multishells/2028640_1659075796381/bin/wasm-pack.

ℹ️  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 /home/cdiesh/Downloads/wasm-bindgen/examples/hello_world
[INFO]: Checking for the Wasm target...
[INFO]: Compiling to Wasm...
    Finished dev [unoptimized + debuginfo] target(s) in 0.06s
[INFO]: Installing wasm-bindgen...
[INFO]: Optional fields missing from Cargo.toml: 'description', 'repository', and 'license'. These are not necessary, but recommended
[INFO]: :-) Done in 0.17s
[INFO]: :-) Your wasm pkg is ready to publish at /home/cdiesh/Downloads/wasm-bindgen/examples/hello_world/pkg.
✅  Your crate has been correctly compiled

ℹ 「wdm」: assets by path *.js 973 KiB
  asset vendors-node_modules_text-encoding_index_js.index.js 623 KiB [emitted] (id hint: vendors)
  asset index.js 341 KiB [emitted] (name: main)
  asset pkg_index_js.index.js 8.39 KiB [emitted]
asset 92392d6570df2d5d3d48.module.wasm 66.1 KiB [emitted] [immutable]
asset index.html 232 bytes [emitted]
runtime modules 9.58 KiB 13 modules
modules by path ./node_modules/ 915 KiB
  modules by path ./node_modules/webpack-dev-server/ 21.2 KiB 12 modules
  modules by path ./node_modules/html-entities/lib/*.js 61 KiB 5 modules
  modules by path ./node_modules/webpack/hot/ 1.58 KiB 3 modules
  modules by path ./node_modules/url/ 37.4 KiB 3 modules
  modules by path ./node_modules/querystring/*.js 4.51 KiB 3 modules
  modules by path ./node_modules/text-encoding/ 617 KiB 3 modules
  + 4 modules
modules by path ./pkg/ 3.28 KiB (javascript) 66.1 KiB (webassembly)
  ./pkg/index.js 71 bytes [built] [code generated]
  ./pkg/index_bg.js 3.15 KiB [built] [code generated]
  ./pkg/index_bg.wasm 70 bytes (javascript) 66.1 KiB (webassembly) [built] [code generated]
./index.js 266 bytes [built] [code generated]
webpack 5.74.0 compiled successfully in 1111 ms
ℹ 「wdm」: Compiled successfully.
ℹ 「wdm」: Compiling...
ℹ 「wdm」: assets by status 1.01 MiB [cached] 4 assets
asset index.html 232 bytes [emitted]
cached modules 916 KiB (javascript) 9.58 KiB (runtime) [cached] 47 modules
modules by layer 3.28 KiB (javascript) 66.1 KiB (webassembly)
  ./pkg/index.js 71 bytes [built]
  ./pkg/index_bg.js 3.15 KiB [built]
  ./pkg/index_bg.wasm 70 bytes (javascript) 66.1 KiB (webassembly) [built]
webpack 5.74.0 compiled successfully in 111 ms
ℹ 「wdm」: Compiled successfully.


possibly I had an older wasm-pack or something that caused this (I had one from february this year) but I just thought I'd add these notes in case it helps someone

@cmdcolin
Copy link

random other note: it was odd that it was not giving a 404 from the .wasm file or some different error in the browser, it was unclear that it was actually not able to compile the wasm at all

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working changelog - fix PR attached there's a PR open for this issue
Projects
None yet
Development

No branches or pull requests

3 participants