build: a clone compiles before the frontend is built

rust-embed refused to derive without `web/dist`, so on a fresh clone
`cargo check`, `cargo test` and rust-analyzer failed with a derive error that
did not say what was missing. With `allow_missing` the embed is empty until
the frontend is built, and the handler gives the answer it already had for
that case, "frontend not built". The release build is unchanged once
`web/dist` is there, which `make build`, the Dockerfile and CI all see to.
This commit is contained in:
nvrl committed 2026-10-21 12:35:59 +02:00
1 parent 0e0d21506e
commit a59ba4af1b
4 files changed
+14 -9

No files matched your search

+1 -1
View File
@@ -18,7 +18,7 @@ jobs:
steps:
- uses: actions/checkout@v4
- uses: oven-sh/setup-bun@v2
# The binary embeds web/dist, so nothing compiles before the frontend is built.
# Built first so the binary under test embeds the app it ships with.
- name: frontend
working-directory: web
run: |
+2 -2
View File
@@ -91,8 +91,8 @@ make dev-web # vite dev server on :4243, proxying /api to :4242
```
In debug builds the binary reads `web/dist` from disk, so `cargo run` alone also
works once the frontend has been built at least once — and not before: the
binary embeds `web/dist`, so a fresh clone builds the frontend first.
works once the frontend has been built at least once. Before that it compiles,
tests and runs the API, and answers every page with "frontend not built".
`make check` runs what CI runs: format, clippy, the tests, svelte-check, and a
check that the generated wiki pages are current. The wiki is written in
+7 -5
View File
@@ -7,9 +7,11 @@ make dev-api # cargo run, serving the API on :4242
make dev-web # vite on :4243, proxying /api to :4242
```
Open <http://127.0.0.1:4243>. The Rust build embeds `web/dist`, so build the
frontend once (`cd web && bun install && bun run build`) before the first
`cargo build`; a debug build reads `web/dist` from disk after that.
Open <http://127.0.0.1:4243>. The release binary embeds `web/dist`, and a
debug build reads it from disk, so build the frontend once
(`cd web && bun install && bun run build`) for `cargo run` alone to serve the
app. Without it the Rust side still compiles and tests, and the pages answer
"frontend not built".
Point `WORKSPACE_DATA_DIR` at a throwaway directory while trying things, so the
real data stays out of it.
@@ -57,8 +59,8 @@ block at the bottom.
`.github/workflows/ci.yml` runs on every push and pull request:
- **rust**: builds the frontend (the binary embeds it), then format, clippy
and the tests;
- **rust**: builds the frontend, so the tests see the app the binary ships,
then format, clippy and the tests;
- **web**: svelte-check;
- **docs**: checks that the generated wiki pages are up to date and that every
link between the pages resolves.
+4 -1
View File
@@ -5,9 +5,12 @@ use axum::{
use rust_embed::Embed;
/// The built Svelte app. In debug builds rust-embed reads from disk, so a
/// `vite build --watch` next to `cargo run` is enough for iteration.
/// `vite build --watch` next to `cargo run` is enough for iteration. A clone
/// that has not built the frontend yet still compiles, tests and checks; it
/// serves the "frontend not built" answer below until it has.
#[derive(Embed)]
#[folder = "$CARGO_MANIFEST_DIR/web/dist"]
#[allow_missing = true]
struct Assets;
pub async fn handler(uri: Uri) -> Response {