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

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

Closed
chanks opened this issue Mar 22, 2023 · 2 comments
Closed

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

chanks opened this issue Mar 22, 2023 · 2 comments

Comments

@chanks
Copy link

chanks commented Mar 22, 2023

🐛 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!

dfaust added a commit to dfaust/wasm-pack that referenced this issue Sep 22, 2023
dfaust added a commit to dfaust/wasm-pack that referenced this issue Sep 22, 2023
@kaimast
Copy link

kaimast commented Mar 16, 2024

Is there any easy workaround for this?

@drager
Copy link
Member

drager commented Jul 1, 2024

Fixed in #1331.

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