Web version, stage 1: the interface as a library over a platform layer; apps/web
apps/desktop becomes a library (chesspenguin_app: the interface) and a thin
binary; apps/web starts the same interface in a page's canvas (eframe's
WebRunner). cfg(web) (build.rs) marks WebAssembly in a browser.
The platform layer (apps/desktop/src/platform): the program's folders, files,
background work, the files the user opens or saves, the clipboard and what
the platform offers (CAPS). On a computer it is the system as before; in a
browser the program's data lives in IndexedDB behind an in-memory file tree
loaded before the start, the files the user opens are read into it for the
session (only read), background jobs run on the page's thread after the
frame, the clipboard is read through the browser's API, sounds play through
audio elements, a game is saved as a download.
What a browser does not have is not built for it: updates, the online games
window and its probe, engine processes (analysis starts a Web Worker there;
the review and preparation jobs, Rodent and the judge are native), blocking
requests (engine, Maia and Rodent downloads report no download for the
platform, translation reports that it makes no requests). The desktop
program behaves as before; its build finds unused code (the web build
compiles parts it never shows).
apps/web: the entry point, the page /app/ (device check before anything large
is loaded: phones and tablets get the page about the apps in the site's nine
languages, keys app_* in website/site/i18n), build.sh (wasm-bindgen, profile
web), a static server and headless Firefox checks.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-30 15:09:17 +03:00
|
|
|
#!/bin/sh
|
|
|
|
|
# Builds the web version into a folder served as the site's /app/ (docs/dev/web.md):
|
|
|
|
|
#
|
|
|
|
|
# apps/web/build.sh [out-dir] (default: target/web/app)
|
|
|
|
|
# PROFILE=release apps/web/build.sh (the default profile is `web`: small, slower to build)
|
|
|
|
|
#
|
|
|
|
|
# Needs: the target wasm32-unknown-unknown (rustup target add wasm32-unknown-unknown),
|
|
|
|
|
# wasm-bindgen-cli of the version in Cargo.lock (cargo install wasm-bindgen-cli --version …;
|
|
|
|
|
# WASM_BINDGEN= points at another binary), python3. wasm-opt (binaryen) makes the program
|
|
|
|
|
# smaller when it is there.
|
|
|
|
|
set -eu
|
|
|
|
|
|
|
|
|
|
here=$(cd "$(dirname "$0")" && pwd)
|
|
|
|
|
root=$(cd "$here/../.." && pwd)
|
|
|
|
|
out=${1:-$root/target/web/app}
|
|
|
|
|
profile=${PROFILE:-web}
|
|
|
|
|
bindgen=${WASM_BINDGEN:-wasm-bindgen}
|
|
|
|
|
|
|
|
|
|
want=$(awk '/^name = "wasm-bindgen"$/ { getline; gsub(/version = |"/, ""); print; exit }' "$root/Cargo.lock")
|
|
|
|
|
have=$("$bindgen" --version | awk '{ print $2 }')
|
|
|
|
|
if [ "$want" != "$have" ]; then
|
|
|
|
|
echo "wasm-bindgen $have, but Cargo.lock has $want: cargo install wasm-bindgen-cli --version $want" >&2
|
|
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
cd "$root"
|
|
|
|
|
cargo build -p chesspenguin-web --target wasm32-unknown-unknown --profile "$profile"
|
|
|
|
|
wasm="$root/target/wasm32-unknown-unknown/$profile/chesspenguin_web.wasm"
|
|
|
|
|
|
|
|
|
|
rm -rf "$out"
|
|
|
|
|
mkdir -p "$out"
|
|
|
|
|
"$bindgen" --target web --no-typescript --out-dir "$out" --out-name chesspenguin_web "$wasm"
|
|
|
|
|
if command -v wasm-opt >/dev/null 2>&1; then
|
|
|
|
|
wasm-opt -Os --enable-bulk-memory --enable-nontrapping-float-to-int --enable-sign-ext \
|
|
|
|
|
--enable-mutable-globals --enable-reference-types \
|
|
|
|
|
"$out/chesspenguin_web_bg.wasm" -o "$out/chesspenguin_web_bg.wasm"
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
cp "$here/page/device.js" "$here/page/page.js" "$out/"
|
Web version, stage 2: Stockfish 19 in workers, live analysis, game review on N workers, My games, files, keys
game-review: what the job does for one target (the full search, the second
best without the move played, the shallow ones) becomes a machine without I/O
(job/work.rs), driven by the engine processes on a computer (job/engines.rs,
the same searches as before) and by Web Workers in a browser
(job/workers.rs: a dispatcher polled from the frames, never blocking). The
analysis cache goes through a CacheStore (a folder, or the program's files of
the platform).
The browser's engine: Stockfish.js 19.0.1 (npm stockfish, GPL-3.0), its
single-threaded build served beside /app/ (engine/, build.sh checks the
package's sha512), its 99 MB wasm downloaded only through the engine offer,
checked against its SHA-256 and kept in Cache Storage; workers get it as a
blob: address. Live analysis (lines, arrows, the bar) and the review run on it;
the review uses one worker per logical CPU, at most 8.
My games (the web version): a PGN in the browser's storage, always on the
shelf; Ctrl+S puts a game there (its own record, or a new one); deleting with
undo. chess-core's store gives the bytes of append/replace/remove/restore, so
the platform writes them into the browser's files; on a computer the files
are written as before. Settings: Browser data (used and free space, keeping
the data for good, Download all as PGN, deleting the engine).
Files: a file of the last visit offers Choose the file again; Keep a copy in
the browser (refused with the room it needs when the browser gives too
little); files over 1 GB are not opened, with a word on why. No reference tab
and no search by position in the web version. Keys: Alt+Left, plain 1-6,
Ctrl+C, N in the library (the browser keeps Ctrl+W/N/1-6/Shift+C).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-30 16:35:16 +03:00
|
|
|
|
|
|
|
|
# The engine: Stockfish.js 19.0.1 (npm `stockfish`, GPL-3.0), its single-threaded build,
|
|
|
|
|
# checked against the registry's integrity (THIRD_PARTY_NOTICES.md). STOCKFISH_TGZ= points
|
|
|
|
|
# at a copy of the package; otherwise it is downloaded once into target/web/.
|
|
|
|
|
sf_url=https://registry.npmjs.org/stockfish/-/stockfish-19.0.1.tgz
|
|
|
|
|
sf_sha512=bTwsO4e9HAwPBKls1+szcfibmaWRNzTF20rQE/XPdB3LOSoT6XTZDr1zYwriwSRRFT5MkvqrglPmJrKEVXGnyQ==
|
|
|
|
|
tgz=${STOCKFISH_TGZ:-$root/target/web/stockfish-19.0.1.tgz}
|
|
|
|
|
if [ ! -f "$tgz" ]; then
|
|
|
|
|
mkdir -p "$(dirname "$tgz")"
|
|
|
|
|
curl -fsSL --retry 3 -o "$tgz.part" "$sf_url"
|
|
|
|
|
mv "$tgz.part" "$tgz"
|
|
|
|
|
fi
|
|
|
|
|
have_sha=$(openssl dgst -sha512 -binary "$tgz" | base64 -w0)
|
|
|
|
|
if [ "$have_sha" != "$sf_sha512" ]; then
|
|
|
|
|
echo "$tgz is not stockfish@19.0.1 (sha512 $have_sha)" >&2
|
|
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
mkdir -p "$out/engine"
|
|
|
|
|
tar -xzf "$tgz" -C "$out/engine" --strip-components=2 \
|
|
|
|
|
package/bin/stockfish-19-single.js package/bin/stockfish-19-single.wasm
|
|
|
|
|
tar -xzf "$tgz" -C "$out/engine" --strip-components=1 package/Copying.txt
|
Web version, stage 1: the interface as a library over a platform layer; apps/web
apps/desktop becomes a library (chesspenguin_app: the interface) and a thin
binary; apps/web starts the same interface in a page's canvas (eframe's
WebRunner). cfg(web) (build.rs) marks WebAssembly in a browser.
The platform layer (apps/desktop/src/platform): the program's folders, files,
background work, the files the user opens or saves, the clipboard and what
the platform offers (CAPS). On a computer it is the system as before; in a
browser the program's data lives in IndexedDB behind an in-memory file tree
loaded before the start, the files the user opens are read into it for the
session (only read), background jobs run on the page's thread after the
frame, the clipboard is read through the browser's API, sounds play through
audio elements, a game is saved as a download.
What a browser does not have is not built for it: updates, the online games
window and its probe, engine processes (analysis starts a Web Worker there;
the review and preparation jobs, Rodent and the judge are native), blocking
requests (engine, Maia and Rodent downloads report no download for the
platform, translation reports that it makes no requests). The desktop
program behaves as before; its build finds unused code (the web build
compiles parts it never shows).
apps/web: the entry point, the page /app/ (device check before anything large
is loaded: phones and tablets get the page about the apps in the site's nine
languages, keys app_* in website/site/i18n), build.sh (wasm-bindgen, profile
web), a static server and headless Firefox checks.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-30 15:09:17 +03:00
|
|
|
for size in 32 64 180; do
|
|
|
|
|
cp "$root/website/static/img/icon-$size.png" "$out/"
|
|
|
|
|
done
|
|
|
|
|
# The page's texts in the site's languages: the app_* keys and the shared ones it uses.
|
|
|
|
|
python3 -I - "$here/page/index.html" "$root/website/site/i18n" "$out/index.html" <<'PY'
|
|
|
|
|
import json, pathlib, sys
|
|
|
|
|
template, i18n, target = sys.argv[1], pathlib.Path(sys.argv[2]), sys.argv[3]
|
|
|
|
|
shared = ["btn_android", "and_light_title", "and_full_title", "and_requires", "next_android",
|
|
|
|
|
"copy_link", "link_copied", "email", "language"]
|
|
|
|
|
texts = {}
|
|
|
|
|
for f in sorted(i18n.glob("*.json")):
|
|
|
|
|
d = json.loads(f.read_text(encoding="utf-8"))
|
|
|
|
|
texts[f.stem] = {k: v for k, v in d.items() if k.startswith("app_") or k in shared}
|
|
|
|
|
page = pathlib.Path(template).read_text(encoding="utf-8")
|
|
|
|
|
blob = json.dumps(texts, ensure_ascii=False, separators=(",", ":")).replace("</", "<\\/")
|
|
|
|
|
pathlib.Path(target).write_text(page.replace("{{TEXTS}}", blob), encoding="utf-8")
|
|
|
|
|
PY
|
|
|
|
|
echo "built $out"
|
|
|
|
|
du -sh "$out"/chesspenguin_web_bg.wasm
|