mirror of
https://github.com/storytold/figcraft.git
synced 2026-10-28 12:26:52 -06:00
The 0.12.0 release's Web job failed at 25,319,327 bytes against the 24 MiB (25,165,824-byte) gate. opt-level z, fat LTO and wasm-opt -Oz are already in place and extra wasm-opt passes save only ~20 KB, so the gate moves to 25,690,112 bytes, still under Cloudflare's 25 MiB per-file cap. The wasm grew ~2 MB in three days (egui 0.37, new features); bringing it back down is follow-up work. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
59 lines
2.6 KiB
Bash
Executable File
59 lines
2.6 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# Build the browser version and zip it: $DIST/figcraft-web-<version>.zip
|
|
#
|
|
# Usage: packaging/web/package.sh [--skip-build]
|
|
#
|
|
# Needs: trunk (brew install trunk / cargo install trunk --locked) and the wasm32-unknown-unknown
|
|
# target. The zip holds a self-contained static site in figcraft-web-<version>/ that works
|
|
# from any URL path and inside an <iframe>. Hosting notes: packaging/web/README.md.
|
|
set -euo pipefail
|
|
# shellcheck source=../env.sh
|
|
. "$(dirname "${BASH_SOURCE[0]}")/../env.sh"
|
|
HERE="$ROOT/packaging/web"
|
|
|
|
if [[ "${1:-}" != "--skip-build" ]]; then
|
|
command -v trunk >/dev/null || { echo "error: trunk not found (cargo install trunk --locked)" >&2; exit 1; }
|
|
(cd "$ROOT/apps/figcraft-web" && trunk build --release)
|
|
fi
|
|
|
|
SITE="$ROOT/dist/web"
|
|
[[ -f "$SITE/index.html" ]] || { echo "error: $SITE/index.html missing; run without --skip-build" >&2; exit 1; }
|
|
# Paths must be relative so the site works under any prefix (public_url = "./" in Trunk.toml).
|
|
if grep -Eq '(src|href)="/[^/]' "$SITE/index.html"; then
|
|
echo "error: $SITE/index.html has root-absolute URLs; it would break when served from a sub-path" >&2
|
|
exit 1
|
|
fi
|
|
|
|
# Size gate: Cloudflare Pages/Workers reject any single file over 25 MiB, and other
|
|
# hosts and CDNs have similar caps. Fail well before that so a regression shows up here, not at
|
|
# upload time. Override with FIGCRAFT_WASM_MAX_BYTES only to investigate.
|
|
# 25 MiB - 512 KiB: raised from 24 MiB for 0.12.1, when egui 0.37 and new features took the wasm to
|
|
# 25.3 MB with opt-level z and wasm-opt -Oz already applied. Cutting the wasm back down is open work.
|
|
MAX_WASM_BYTES="${FIGCRAFT_WASM_MAX_BYTES:-25690112}" # 25 MiB - 512 KiB
|
|
WASM_COUNT=0
|
|
for wasm in "$SITE"/*.wasm; do
|
|
[[ -f "$wasm" ]] || continue
|
|
WASM_COUNT=$((WASM_COUNT + 1))
|
|
size=$(wc -c <"$wasm" | tr -d ' ')
|
|
echo "$(basename "$wasm"): $size bytes ($((size / 1048576)) MiB; limit $MAX_WASM_BYTES)"
|
|
if [[ "$size" -gt "$MAX_WASM_BYTES" ]]; then
|
|
echo "error: $(basename "$wasm") is $size bytes, over the $MAX_WASM_BYTES-byte limit (Cloudflare's per-file cap is 25 MiB)" >&2
|
|
exit 1
|
|
fi
|
|
done
|
|
[[ "$WASM_COUNT" -gt 0 ]] || { echo "error: no .wasm in $SITE" >&2; exit 1; }
|
|
|
|
NAME="figcraft-web-$VERSION"
|
|
WORK="$CARGO_TARGET_DIR/web-package"
|
|
rm -rf "$WORK"
|
|
mkdir -p "$WORK/$NAME"
|
|
cp -R "$SITE/." "$WORK/$NAME/"
|
|
# Sample server configs (MIME type, caching, compression); harmless where unused.
|
|
cp "$HERE/_headers" "$HERE/.htaccess" "$WORK/$NAME/"
|
|
cp "$HERE/README.md" "$WORK/$NAME/HOSTING.md"
|
|
copy_docs "$WORK/$NAME"
|
|
rm -f "$DIST/$NAME.zip"
|
|
(cd "$WORK" && zip -qr9 "$DIST/$NAME.zip" "$NAME")
|
|
echo "wrote $DIST/$NAME.zip"
|
|
ls -lh "$DIST/$NAME.zip"
|