mirror of
https://github.com/imjasonh/nescript
synced 2026-07-08 17:06:04 +00:00
The compiler is deterministic: rebuilding any example produces a byte-identical ROM, verified across all 22 examples and all four mappers (NROM, MMC1, UxROM, MMC3). That means the .nes files are reproducible artefacts and can live next to their sources without drift. Benefits: - Users can clone the repo and open any example in an emulator without installing a Rust toolchain or running the compiler. - The emulator harness can trust examples/*.nes directly, so its CI job no longer needs a compiler build or a "compile all examples" loop — it just boots jsnes against the committed ROMs and diffs each against its golden. - ROM diffs in PRs are now meaningful: "this compiler change flipped 17 bytes in hello_sprite.nes" is visible review signal, not hidden behind the emulator golden. Guard rails so the ROMs don't drift from their sources: - .gitignore no longer excludes *.nes. - The `examples` CI job rebuilds every .ne into /tmp and fails loudly (with a GitHub error annotation pointing at the exact cargo command to rerun) if any committed ROM differs. - scripts/pre-commit does the same check locally. - CLAUDE.md now states that editing a .ne file requires rebuilding its .nes in the same commit, so future agents won't miss the invariant. Total footprint: 22 ROMs, 624 KB (avg 28 KB each — most are NROM 24 KB; two banked examples are larger). https://claude.ai/code/session_01BcCcHi6FUmTh8jC7UgkA3A
147 lines
4.7 KiB
YAML
147 lines
4.7 KiB
YAML
name: CI
|
|
|
|
on:
|
|
push:
|
|
branches: [main]
|
|
pull_request:
|
|
branches: [main]
|
|
|
|
env:
|
|
CARGO_TERM_COLOR: always
|
|
RUSTFLAGS: "-D warnings"
|
|
|
|
jobs:
|
|
check:
|
|
name: Check
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
- uses: dtolnay/rust-toolchain@stable
|
|
- uses: Swatinem/rust-cache@v2
|
|
- run: cargo check --all-targets
|
|
|
|
fmt:
|
|
name: Format
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
- uses: dtolnay/rust-toolchain@stable
|
|
with:
|
|
components: rustfmt
|
|
- run: cargo fmt --all -- --check
|
|
|
|
clippy:
|
|
name: Clippy
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
- uses: dtolnay/rust-toolchain@stable
|
|
with:
|
|
components: clippy
|
|
- uses: Swatinem/rust-cache@v2
|
|
- run: cargo clippy --all-targets -- -D warnings
|
|
|
|
test:
|
|
name: Test
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
- uses: dtolnay/rust-toolchain@stable
|
|
- uses: Swatinem/rust-cache@v2
|
|
- run: cargo test --all-targets
|
|
|
|
examples:
|
|
name: Build Examples
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
- uses: dtolnay/rust-toolchain@stable
|
|
- uses: Swatinem/rust-cache@v2
|
|
- run: cargo build --release
|
|
- name: Verify committed ROMs match their .ne sources
|
|
# Every example has a committed .nes file under examples/. The
|
|
# compiler is deterministic (verified: same input → byte-identical
|
|
# output), so rebuilding each example into a tmp directory and
|
|
# diffing against the committed ROM catches "someone edited a .ne
|
|
# file but forgot to regenerate the ROM" at PR time.
|
|
run: |
|
|
mkdir -p /tmp/reprotest
|
|
fail=0
|
|
for f in examples/*.ne; do
|
|
name=$(basename "$f" .ne)
|
|
./target/release/nescript build "$f" --output "/tmp/reprotest/$name.nes"
|
|
if ! cmp -s "examples/$name.nes" "/tmp/reprotest/$name.nes"; then
|
|
echo "::error file=examples/$name.ne::committed examples/$name.nes is stale; rerun \`cargo run --release -- build examples/$name.ne\` and commit the new ROM"
|
|
fail=1
|
|
fi
|
|
done
|
|
if [ $fail -ne 0 ]; then
|
|
exit 1
|
|
fi
|
|
- name: Verify ROMs are valid iNES
|
|
run: |
|
|
for f in examples/*.nes; do
|
|
echo "==> Checking $f"
|
|
# iNES magic: first 4 bytes must be "NES\x1a"
|
|
header=$(od -A n -t x1 -N 4 "$f" | tr -d ' ')
|
|
if [ "$header" != "4e45531a" ]; then
|
|
echo "FAIL: $f is not a valid iNES ROM (header: $header)"
|
|
exit 1
|
|
fi
|
|
size=$(stat -c%s "$f")
|
|
echo " OK: $size bytes"
|
|
done
|
|
|
|
emulator:
|
|
name: Emulator Smoke Test
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
- uses: actions/setup-node@v4
|
|
with:
|
|
node-version: '22'
|
|
- name: Install Chrome runtime deps for puppeteer
|
|
# puppeteer ships its own Chrome for Testing binary via the
|
|
# package's postinstall hook, but the runner image is missing
|
|
# a handful of shared libs that Chrome needs to launch.
|
|
run: |
|
|
sudo apt-get update
|
|
sudo apt-get install -y --no-install-recommends \
|
|
libnss3 \
|
|
libatk-bridge2.0-0 \
|
|
libatk1.0-0 \
|
|
libatspi2.0-0 \
|
|
libcups2t64 \
|
|
libdbus-1-3 \
|
|
libdrm2 \
|
|
libgbm1 \
|
|
libpango-1.0-0 \
|
|
libxcomposite1 \
|
|
libxdamage1 \
|
|
libxfixes3 \
|
|
libxkbcommon0 \
|
|
libxrandr2 \
|
|
libasound2t64
|
|
# No compiler build needed — the `.nes` files are committed
|
|
# alongside their `.ne` sources, and the `examples` CI job
|
|
# fails on any stale ROM, so the emulator job can trust them.
|
|
- name: Install emulator harness dependencies
|
|
working-directory: tests/emulator
|
|
run: npm ci
|
|
- name: Diff each ROM's framebuffer against its committed golden
|
|
working-directory: tests/emulator
|
|
run: node run_examples.mjs
|
|
- name: Upload actual + diff PNGs on failure
|
|
if: failure()
|
|
uses: actions/upload-artifact@v4
|
|
with:
|
|
name: emulator-diff
|
|
# `actual/` holds the run's output and red-highlighted diff
|
|
# PNGs for any ROM that didn't match its golden. `report.json`
|
|
# has the per-example pass/fail/diff counts. `goldens/` is
|
|
# included too so reviewers can compare the three side by side
|
|
# without cloning the repo.
|
|
path: |
|
|
tests/emulator/actual/
|
|
tests/emulator/goldens/
|
|
tests/emulator/report.json
|