metronome/rust/run.sh
Me Here be524ce1ea Rust port Stage 1: track-format codec crate (passes the golden vectors)
A third implementation of the track DSL alongside engine.js and app.py, validated
against the same tests/fixtures/track-format.json:

- rust/track-format/: pure parse()/serialize() codec (std + alloc for now; no_std is
  a later refinement). Ports the app.py/engine.js semantics exactly — grouping,
  subdivisions, swing, ghost, polymeter, euclid, GM note-number aliases, unknown->beep,
  default groove (group-start accents), tempo clamp, empty->beep, and the playback-flow
  tokens (rep/end/relative-goto). Carries vol/cd too, so it's the most spec-complete
  of the three.
- tests/conformance.rs: the Rust adapter — reads the shared fixtures, asserts each
  case's normalized form (number-tolerant deep-equal) + serialize idempotency.
- rust/Containerfile + run.sh: Rust toolchain in a container (mirrors hardware/eda/),
  with the thumbv8m.main-none-eabihf target for the eventual RP2350 firmware. Never
  on the host.

Verified: ./rust/run.sh -> cargo test -> conformance + idempotent both pass.
docs/rust-port.md Stage 1 marked done.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-05-31 18:36:59 -05:00

25 lines
1 KiB
Bash
Executable file

#!/usr/bin/env bash
# Build (first time) and run the PM Rust container with the repo mounted.
#
# ./run.sh # cargo test (runs the golden-vector conformance suite)
# ./run.sh cargo build
# ./run.sh bash # interactive shell in rust/track-format/
#
# Override the runtime with RUNTIME=docker ./run.sh ...
set -euo pipefail
IMG="pm-rust:1"
RUST_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" # rust/
REPO_DIR="$(cd "$RUST_DIR/.." && pwd)" # repo root
RUNTIME="${RUNTIME:-podman}"
if ! "$RUNTIME" image inspect "$IMG" >/dev/null 2>&1; then
echo ">> building $IMG (first run, a few minutes)…" >&2
"$RUNTIME" build -t "$IMG" "$RUST_DIR"
fi
# Mount the whole repo so the crate's tests can read tests/fixtures/ ; land in the crate dir.
flags=(--rm -v "$REPO_DIR":/work:Z -w /work/rust/track-format)
[[ -t 0 ]] && flags+=(-it)
if [[ $# -eq 0 ]]; then set -- cargo test; fi # default command (multi-word, so set positional args)
exec "$RUNTIME" run "${flags[@]}" "$IMG" "$@"