https://linen.dev logo
cargo workspace example
# help
f
I have a cargo workspace structure with frontend/ and backend/ folders. The frontend is a yew SPA and the backend is an axum server. The backend will serve the frontend using
shuttle-static-folder
. In the 0.14 release, there's a note that the static folder must be placed in the workspace root. So, if I build the frontend project and output to dist/ what do I specify in the
shuttle_static_folder::StaticFolder
annotation? I was using "dist" and it worked for
cargo shuttle run
when it was at backend/dist/ "../dist" doesn't seem to work.
When I deploy, it also appears to try and build the frontend/ project, but it shouldn't. How do we control which project in a workspace is the one that gets deployed?
a
Hiya, what's your frontend written in?
Normally I just keep my shuttle-only stuff in my backend folder to avoid conflicts but you can just write
(folder = "dist")
in the static folder macro and it should let you use your compiled frontend
g
> The frontend is a yew SPA
f
Yeah, the issue appears to be that it's a single git repo / cargo workspace with two rust crates
a
oh whoops sorry, lack of reading
but yeah, i put all shuttle-related stuff in the backend repo only and then just compile frontend assets whenever i want to test or deploy the backend if it uses a frontend
f
That's what I was trying to do, but the deploy process is trying to build my frontend (even though I don't want it to).
g
Does your frontend crate "use" any shuttle feature? IIRC the workspace setup should only look for certain crates, will check now
@flat-piano-13282 Does a local
cargo build
in the root build both crates for you? In that case, you might want to set
backend
as the default workspace member. That should cause only that one to get built. Worth trying at least.
f
Here's the workspace Cargo.toml (I assed the default-members and it still tried to build frontend)
Copy code
toml
[workspace]
members = ["backend", "frontend"]
default-members = ["backend"]
My frontend dependencies (from it's Cargo.toml) are:
Copy code
toml
[dependencies]
yew = { version = "0.20.0", features = ["csr"] }
wasm-bindgen = "0.2"
js-sys = "0.3.61"
web-sys = "0.3.61"
serde = { version = "1.0.159", features = ["derive"] }
wasm-bindgen-futures = "0.4"
serde-wasm-bindgen = "0.4"
gloo-console = "0.2.3"
gloo-net = { version = "0.2.6", features = ["json"] }
gloo-storage = "0.2.2"
serde_json = "1.0.95"
yew-router = "0.17.0"
reqwest = { version = "0.11.16", features = ["json"] }
anyhow = "1.0.70"
lazy_static = "1.4.0"
yewtube = "0.1.1"
Which I don't think has anything shuttle related.
I was able to get the deploy to work by removing frontend from the workspace Cargo.toml altogether and copying
dist/
to the workspace root for use by the static folder annotation. That's a bit awkward, however, since
dist/
needs to be copied into
backend/
too for it it to run locally
g
we might need help from @kind-area-3810 / @stocky-kangaroo-53672 on this one 🙏
a
I think you should be able to alias cargo commands for this?
k
Hey, did you try excluding the frontend dir?
Also the static-folder argument only allows you to change the name of the folder
The returned pathbuf will be the path (which will be different in deployment relative to the executable)
f
@strong-fireman-52515dgrd - I did, but I also had to remove it from
members
, not sure if that's expected. Can you describe how the path will be different in deployment? My confusion is around it needing to be in different places during
cargo shuttle run
(in the same directory as the
Cargo.toml
for the backend crate) vs
cargo shuttle deploy
(in the workspace root, the parent directory of the backend crate)
k
Ah, so it doesn't work with the static folder in the workspace root for both run and deploy? That seems like a bug, we may have missed that in our testing
The executable will be in a separate folder from your source code, so the reliable way to get the path to it is to use the path you get from
#[shuttle_static_folder] path: Pathbuf
f
Yeah, deploys also fail on the static directory step if I try to run
cargo shuttle deploy
from the backend crate directory.
cargo shuttle run
works from there
Oh wait, nevermind, static deploy is just completely broken for me it seems
Copy code
{response="LoadResponse { success: false, message: \"Custom error: failed to provision shuttle_static_folder :: StaticFolder\", resources: [] }"} shuttle_deployer::deployment::run: loading response
It works if I change the static dir the default for some reason