wasm-pack icon indicating copy to clipboard operation
wasm-pack copied to clipboard

--target-dir causes build errors when used in workspace

Open chanks opened this issue 2 years ago • 1 comments

🐛 Bug description

I have a workspace which contains both WASM and non-WASM binaries. I find that using the default target directory in the workspace root for both types of binary seems to thrash the target cache and cause unnecessary recompilations, so I'd like to compile the WASM binaries to a different directory. One WASM binary is in {workspace_root}/crates/binary/user_interface_wasm.

For reference, my default wasm-pack invocation is: wasm-pack build crates/binary/user_interface_wasm --dev -t web --no-typescript This works, but thrashes the cache:

[INFO]: License key is set in Cargo.toml but no LICENSE file(s) were found; Please add the LICENSE file(s) to your project directory
[INFO]: ⬇️  Installing wasm-bindgen...
[INFO]: ✨   Done in 1m 23s
[INFO]: 📦   Your wasm pkg is ready to publish at crates/binary/user_interface_wasm/pkg.

When I pass a --target-dir: wasm-pack build crates/binary/user_interface_wasm --dev -t web --no-typescript --target-dir target-web It builds the WASM app in crates/binary/user_interface_wasm/target-web rather than {workspace_root}/target-web. I guess that's fine, but it also errors, seemingly because it's looking for the built binary in the wrong place:

[INFO]: License key is set in Cargo.toml but no LICENSE file(s) were found; Please add the LICENSE file(s) to your project directory
[INFO]: ⬇️  Installing wasm-bindgen...
error: failed reading 'target-web/wasm32-unknown-unknown/debug/user_interface_wasm.wasm'

Caused by:
    No such file or directory (os error 2)
Error: Running the wasm-bindgen CLI
Caused by: Running the wasm-bindgen CLI
Caused by: failed to execute `wasm-bindgen`: exited with exit status: 1
  full command: "/home/chris/.cache/.wasm-pack/wasm-bindgen-5f26acfc988649a3/wasm-bindgen" "target-web/wasm32-unknown-unknown/debug/user_interface_wasm.wasm" "--out-dir" "crates/binary/user_interface_wasm/pkg" "--no-typescript" "--target" "web" "--debug"

Passing a target-dir that puts the build directory at the workspace root is a bit nicer place for it: wasm-pack build crates/binary/user_interface_wasm --dev -t web --no-typescript --target-dir ../../../target-web But also fails with a similar error:

[INFO]: License key is set in Cargo.toml but no LICENSE file(s) were found; Please add the LICENSE file(s) to your project directory
[INFO]: ⬇️  Installing wasm-bindgen...
error: failed reading '../../../target-web/wasm32-unknown-unknown/debug/user_interface_wasm.wasm'

Caused by:
    No such file or directory (os error 2)
Error: Running the wasm-bindgen CLI
Caused by: Running the wasm-bindgen CLI
Caused by: failed to execute `wasm-bindgen`: exited with exit status: 1
  full command: "/home/chris/.cache/.wasm-pack/wasm-bindgen-5f26acfc988649a3/wasm-bindgen" "../../../target-web/wasm32-unknown-unknown/debug/user_interface_wasm.wasm" "--out-dir" "crates/binary/user_interface_wasm/pkg" "--no-typescript" "--target" "web" "--debug"

🤔 Expected Behavior

The WASM app should still be built and copied to user_interface_wasm/pkg with either of the last two commands above.

👟 Steps to reproduce

See above.

🌍 Your environment

Include the relevant details of your environment. wasm-pack version: wasm-pack 0.11.0 rustc version: rustc 1.70.0-nightly (44f518058 2023-03-20)

Thanks!

chanks avatar Mar 22 '23 17:03 chanks

Is there any easy workaround for this?

kaimast avatar Mar 16 '24 21:03 kaimast

Fixed in #1331.

drager avatar Jul 01 '24 19:07 drager