Skip to content

PhotoCraft: An open-source, photo editor written by scratch in pure Rust

ci(web): validate browser builds and wasm size on pull requests (#1689)

Nigel Ihza Firdausyd502c5de279d
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index f74eddbf0..3116e3e94 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -39,6 +39,7 @@ jobs:
runs-on: ubuntu-latest
outputs:
os: ${{ steps.pick.outputs.os }}
+ web: ${{ steps.pick.outputs.web }}
steps:
- uses: actions/checkout@v4
with:
@@ -54,8 +55,17 @@ jobs:
all='["ubuntu-latest","windows-latest"]'
if [ "$EVENT" != pull_request ] || [ "$FULL" = true ]; then
echo "os=$all" >> "$GITHUB_OUTPUT"
+ echo "web=true" >> "$GITHUB_OUTPUT"
exit 0
fi
+ # The browser build (a fat-LTO wasm build) runs only when something it compiles or
+ # packages changed: the web app and its packaging, crate sources and manifests (the web
+ # build compiles nearly every crate), the workspace manifests and this workflow.
+ if git diff --name-only "$BASE" HEAD | grep -Eq '^(apps/photocraft-web/|packaging/web/|packaging/env\.sh$|crates/[^/]+/(src/|Cargo\.toml$|build\.rs$)|Cargo\.(toml|lock)$|rust-toolchain(\.toml)?$|\.github/workflows/ci\.yml$)'; then
+ echo "web=true" >> "$GITHUB_OUTPUT"
+ else
+ echo "web=false" >> "$GITHUB_OUTPUT"
+ fi
if git diff --name-only "$BASE" HEAD | grep -Eq '^(apps/|crates/(ui-egui|text|gpu|tablet|heif)/|Cargo\.lock$|(.*/)?build\.rs$|\.github/workflows/ci\.yml$)'; then
echo "os=$all" >> "$GITHUB_OUTPUT"
else
@@ -191,6 +201,50 @@ jobs:
- name: Check wasm-safe crates
run: cargo xtask wasm
+ web:
+ name: web build and wasm size gate
+ # PRs run it only when web-relevant files change (see `platforms`); main always does.
+ needs: platforms
+ if: needs.platforms.outputs.web == 'true'
+ runs-on: ubuntu-latest
+ env:
+ # Match release.yml so PR results reflect what would actually ship.
+ TRUNK_VERSION: 0.21.14
+ steps:
+ - uses: actions/checkout@v4
+ - uses: dtolnay/rust-toolchain@stable
+ with:
+ targets: wasm32-unknown-unknown
+ - uses: Swatinem/rust-cache@v2
+ with:
+ key: ci-web
+ save-if: ${{ github.ref == 'refs/heads/main' }}
+ cache-on-failure: true
+ - name: Install trunk
+ run: |
+ curl -fsSL "https://github.com/trunk-rs/trunk/releases/download/v${TRUNK_VERSION}/trunk-x86_64-unknown-linux-gnu.tar.gz" \
+ | tar -xz -C "$HOME/.cargo/bin" trunk
+ trunk --version
+ # package.sh runs Trunk's release build, validates relative URLs, checks the 24 MiB
+ # wasm limit and exercises the same packaging step used by release.yml.
+ - name: Build and verify browser release
+ run: packaging/web/package.sh
+ - name: Report wasm size
+ if: success()
+ run: |
+ {
+ echo "### Browser WebAssembly size"
+ echo
+ echo "| File | Bytes | MiB | Limit |"
+ echo "| --- | ---: | ---: | ---: |"
+ for wasm in dist/web/*.wasm; do
+ [ -f "$wasm" ] || continue
+ bytes=$(wc -c < "$wasm" | tr -d ' ')
+ mib=$(awk -v n="$bytes" 'BEGIN { printf "%.2f", n / 1048576 }')
+ echo "| $(basename "$wasm") | $bytes | $mib | 24 MiB |"
+ done
+ } >> "$GITHUB_STEP_SUMMARY"
+
fuzz:
name: fuzz (${{ matrix.target.crate }}/${{ matrix.target.name }})
# Placeholder: manual trigger only until a nightly schedule is enabled.
diff --git a/docs/development.md b/docs/development.md
index dfaa41a2a..2afc52854 100644
--- a/docs/development.md
+++ b/docs/development.md
@@ -332,7 +332,7 @@ trunk build --release # writes ../../dist/web (index.html, .js glue
trunk serve --release # dev server on http://127.0.0.1:8765
```
-Any static file server works for `dist/web`, for example `python3 -m http.server 8765` run inside that directory. Trunk downloads the matching `wasm-bindgen` and `wasm-opt` itself. `trunk build --release` uses the `wasm-release` Cargo profile (`data-cargo-profile` in `index.html`: fat LTO, opt-level "s" except the pixel crates). The `.wasm` is about 18.8 MiB raw, 7.8 MiB gzipped and 5.6 MiB with Brotli; serve it with compression. Keep it under 24 MiB (`packaging/web/package.sh` enforces this; Cloudflare's per-file cap is 25 MiB). The web build never embeds craft-fonts (see Fonts above). To see where the bytes go, run `twiggy top -n 40` on `target/wasm32-unknown-unknown/wasm-release/photocraft-web.wasm` (before wasm-opt strips the names).
+Any static file server works for `dist/web`, for example `python3 -m http.server 8765` run inside that directory. Trunk downloads the matching `wasm-bindgen` and `wasm-opt` itself. `trunk build --release` uses the `wasm-release` Cargo profile (`data-cargo-profile` in `index.html`: fat LTO, opt-level "s" except the pixel crates). The `.wasm` is about 18.8 MiB raw, 7.8 MiB gzipped and 5.6 MiB with Brotli; serve it with compression. Keep it under 24 MiB (`packaging/web/package.sh` enforces this; Cloudflare's per-file cap is 25 MiB). Pull-request CI also builds the actual browser app with the same pinned Trunk version as the release job and runs `packaging/web/package.sh`, including the relative-URL and 24 MiB checks. The `web build and wasm size gate` check runs on main and on PRs that change something the web build compiles or packages (`apps/photocraft-web`, `packaging/web`, crate sources and manifests, `Cargo.toml`/`Cargo.lock`, the CI workflow), and reports the resulting wasm size in the Actions job summary. The web build never embeds craft-fonts (see Fonts above). To see where the bytes go, run `twiggy top -n 40` on `target/wasm32-unknown-unknown/wasm-release/photocraft-web.wasm` (before wasm-opt strips the names).
URL flags: `?webgl` forces the WebGL2 backend, and `?cpu` forces the CPU canvas path.