trunk icon indicating copy to clipboard operation
trunk copied to clipboard

0.21 fails to build workspace project from crate root: "could not find the root package"

Open antifuchs opened this issue 1 year ago • 3 comments

Trunk 0.20 managed to build my workspace project's wasm project from the workspace root, using the following command line: trunk build ./src/foo-ui/index.html. Now, on trunk 0.21.4, that results in the following error:

:;    ~/.cargo/bin/trunk build ./src/foo-ui/index.html
2024-11-08T17:02:50.706597Z  INFO 🚀 Starting trunk 0.21.4
2024-11-08T17:02:51.198526Z ERROR could not find the root package of the target crate

I notice that trunk isn't searching for a Trunk.toml (and Cargo.tom) relative to the index.html file provided - only the current directory. Is there a way to make it search there again? The build process I'm using doesn't make it easy to invoke trunk from a subdirectory.

antifuchs avatar Nov 08 '24 17:11 antifuchs

I experimented with some options a bit and it looks like --config solves half of what I need:

:;    ~/.cargo/bin/trunk build --config=src/foo-ui/Trunk.toml ./src/foo-ui/index.html
2024-11-08T17:49:07.855806Z  INFO 🚀 Starting trunk 0.21.4
2024-11-08T17:49:07.861348Z ERROR error getting the canonical path to the build target HTML file "/Users/asf/Hacks/foo/src/foo-ui/./src/foo-ui/index.html"
2024-11-08T17:49:07.861529Z  INFO   1: No such file or directory (os error 2)

but:

:;    ~/.cargo/bin/trunk build --config=src/foo-ui/Trunk.toml ./src/foo-ui/index.html
2024-11-08T17:49:07.855806Z  INFO 🚀 Starting trunk 0.21.4
2024-11-08T17:51:17.755288Z  INFO 📦 starting build
2024-11-08T17:51:17.761751Z  INFO spawned hook yarn command_arguments=["install"]
2024-11-08T17:51:17.761762Z  INFO spawning hook stage=PreBuild command=yarn
yarn install v1.22.22
[1/4] 🔍  Resolving packages...
success Already up-to-date.
✨  Done in 0.03s.
2024-11-08T17:51:17.902947Z  INFO finished hook yarn
   Compiling proc-macro2 v1.0.82
   Compiling wasm-bindgen-shared v0.2.93
[...success!]

So it sounds like trunk is looking for the HTML file relative to the config option's directory, rather than relative to the directory where trunk was invoked... if the index file is a relative pathname, because passing an absolute pathname works:

:;    ~/.cargo/bin/trunk build --config=src/foo-ui/Trunk.toml `pwd`/src/foo-ui/index.html
2024-11-08T17:49:07.855806Z  INFO 🚀 Starting trunk 0.21.4
2024-11-08T17:51:17.755288Z  INFO 📦 starting build
2024-11-08T17:56:35.660576Z  INFO spawned hook yarn command_arguments=["install"]
2024-11-08T17:56:35.660597Z  INFO spawning hook stage=PreBuild command=yarn
2024-11-08T17:56:35.661358Z ERROR ❌ error
error from build pipeline

Caused by:
    0: error spawning hook call for yarn
    1: No such file or directory (os error 2)
[...failure, but because the yarn command runs in the workspace root instead of the src/foo-ui now?!]

That's really confusing /:

antifuchs avatar Nov 08 '24 17:11 antifuchs

Having the same problem

chianti-ga avatar Nov 10 '24 20:11 chianti-ga

So yes, the -c (--config) option should point to the configuration (or context) of the trunk build. All other paths should be relative to this. This might be a change from 0.20, but also aligns with that cargo does.

ctron avatar Nov 11 '24 07:11 ctron