# Rebuilding the Wesnoth browser edition

This guide records the pinned native build and its corresponding-source inputs.
The open-font edition below supplies the fonts used by the browser release;
the earlier all-font candidate remains private. See `docs/wesnoth-browser.md`
for exact local evidence and the release record for deployment status.

## Reassemble the supplied archives

The private package is under `artifacts/expansion/wesnoth/source-distribution/`.
Each archive is divided into numbered parts of at most 20 MiB. Read
`source/manifest.json`, verify each part's SHA-256 and length, concatenate its
listed parts in that order, then verify the whole archive's SHA-256 and length.
Do not extract a failed or unverified archive. On the original checkout,
`python3 scripts/expansion/verify-wesnoth-sources.py` performs that transport audit
and also compares the packaged source and binary identities with the build.

Extract `leaf-wesnoth-integration.tar.gz` into a clean checkout directory. It
contains the readable integration scripts, runtime, tests, package manifests,
this guide and the actual CMake/Ninja configuration as diagnostic records.
The recorded absolute build paths are evidence, not portable configuration;
configure a new build with the supplied scripts rather than reusing build.ninja.

Create `artifacts/expansion/wesnoth/` there. Put the reassembled
`original-wesnoth-source.tar.gz` in that directory as `browser-source.tar.gz` and
`original-lua-source.tar.gz` as `lua-source.tar.gz`. Extract the original game
archive there, preserving its `wesnoth-9b4c32e3b0421d968375a01497e3d66659260fa7`
root directory. The supplied prepared overlay contains the exact changed files
and Lua sources for independent comparison; the preparation scripts recreate
that overlay from the pinned originals.

## Build and relink

Requirements are Docker, Python 3, Node.js/npm and sufficient local disk/memory.
The Dockerfile pins Emscripten 5.0.7 by image digest. It installs ordinary Linux
build tools. The native script pins vcpkg to
`52f93a645e9f4d4141c32f5bab12575278548367`; source downloads are recorded in the
121 selected package definitions and SPDX metadata supplied in
`exact-vcpkg-definitions-and-notices.tar.gz`.

```sh
npm ci
python3 scripts/expansion/prepare-wesnoth.py
python3 scripts/expansion/prepare-wesnoth.py --verify
bash scripts/expansion/build-wesnoth.sh
python3 scripts/expansion/wesnoth-build-record.py verify
```

This supported path requires network access to the pinned toolchain, vcpkg and
native dependency sources. A fully offline rebuild has not been demonstrated.
The supplied 118 original dependency archives and prepared dependency trees
preserve the corresponding inputs; they are not a preconfigured offline build
cache. The cache also retains earlier diagnostic versions and host tools, so
use the installed version/ABI records to distinguish the selected packages.
Five empty vcpkg packages use SDK/platform facilities. The libpng APNG feature
was not selected and its unused source declaration is recorded in the audit.

To change and relink the platform adapter, edit the readable files under
`scripts/expansion/`, rerun preparation while the build container is stopped,
and rebuild. Changes to native gameplay may instead be applied deliberately
to the original source before creating a new audited pin; the preparation audit
will reject undisclosed differences. Existing successful objects are reused
when their inputs are unchanged. The build writes `completed-build.json` only
after successful completion and an unchanged source identity. Staging refuses
a source or output that differs from that completed record.

## Stage and verify locally

```sh
python3 scripts/expansion/package-wesnoth-resources.py
python3 scripts/expansion/verify-wesnoth-resources.py
python3 scripts/expansion/stage-wesnoth-player.py
```

Serve `artifacts/expansion/wesnoth/resources/` with a local static HTTP server.
Game resources retain their original hashes. Written game saves remain local
and are excluded from this source package. Native gameplay E2E requires the
original engine-generated checkpoint described in `tests/e2e/wesnoth-native.spec.ts`;
that checkpoint is verification data, not a supplied replacement game state.
The existing passing desktop/Retina evidence is recorded in the browser guide.


## Open-font source edition

The optional `source-open-fonts/` candidate omits exactly nine unused GPL font
programs from the original game archive. It supplies the full unchanged Adobe
Source Serif 4.005 released-font archive and matching editable UFO/designspace /
build-source archive under OFL-1.1. Original body fonts and gameplay are retained.
Font aliases, omission list and exact input checksums are in
`scripts/expansion/wesnoth-open-fonts.json`; these are presentation changes and
require no native rebuild.

In this edition, reassemble `wesnoth-open-font-source.tar.gz` and place it in
the task directory as `browser-source.tar.gz`, then extract it under its preserved
upstream root. The preparation script recognizes only its pinned length/SHA-256
or those of the original archive. Keep the normal original Lua archive. Put the
two reassembled Source Serif archives under
`artifacts/expansion/wesnoth/font-replacement/` with their recorded filenames.
All normal native build steps above apply. To stage the declared font edition:

```sh
python3 scripts/expansion/package-wesnoth-resources.py --open-fonts --directory artifacts/expansion/wesnoth/open-fonts
python3 scripts/expansion/verify-wesnoth-resources.py --directory artifacts/expansion/wesnoth/open-fonts
python3 scripts/expansion/stage-wesnoth-player.py --directory artifacts/expansion/wesnoth/open-fonts --compressed-engine
python3 scripts/expansion/verify-wesnoth-engine.py artifacts/expansion/wesnoth/open-fonts
```

`filter-wesnoth-font-sources.py` recreates the filtered archive from the original
private archive and independently checks every retained entry. `--verify`
repeats that comparison without rewriting it. Source-package creation on the
maintainer workspace requires that original for the independent comparison;
rebuilding the engine and staging resources from the supplied filtered source
uses its strict recorded fingerprint. Public release checks remain unfinished.


The open-font candidate contains 128 source archives, including complete
preferred fflate 0.8.3 TypeScript. Preparation and the retained-source/Lua audit
were repeated in a fresh workspace restored from the candidate alone. No new
native compilation is claimed: the native code and completed Wasm are unchanged.
