LightCraft: An open-source non-destructive photo editor written by scratch in pure Rust
Gap 9: cargo xtask ci on every PR (Linux x64); ci --quick; one local ci at a time
Matthew James Sivak5690afe51a42
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.ymlnew file mode 100644index 000000000..f5783ac54--- /dev/null+++ b/.github/workflows/ci.yml@@ -0,0 +1,69 @@+# The quality gate (`cargo xtask ci`: fmt, clippy, heif, tests, parity, layers, assets, wasm) on+# every pull request and every push to main, so the full run happens here rather than on the+# machine of everyone with a branch open. Locally, `cargo xtask ci --quick` checks what a branch's+# changes can break in a few minutes; this job is the merge gate.+#+# Linux only: macOS / Windows test jobs are #1148. Standard GitHub-hosted runner (free for public+# repositories), never a larger one.+name: CI++on:+ push:+ branches: [main]+ pull_request:+ workflow_dispatch:++concurrency:+ group: ci-${{ github.ref }}+ cancel-in-progress: true++permissions:+ contents: read++env:+ CARGO_TERM_COLOR: always+ # a fresh build every run: incremental state is only overhead, and it bloats the cache+ CARGO_INCREMENTAL: 0+ RUST_BACKTRACE: 1+ # one job per runner: the machine-wide CI lock (xtask/src/ci_lock.rs) has nothing to wait for+ LIGHTCRAFT_CI_LOCK: "off"++jobs:+ xtask-ci:+ name: cargo xtask ci (Linux x86_64)+ runs-on: ubuntu-latest+ timeout-minutes: 90+ env:+ CRAFT_FONTS_DIR: ${{ github.workspace }}/craft-fonts+ CRAFT_FONTS_REQUIRED: "1"+ steps:+ - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1+ with:+ persist-credentials: false+ # the font build input, so the Japanese and Chinese font tests run (they skip without it)+ - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1+ with:+ repository: storytold/craft-fonts+ ref: 3d9ab3a132ed0eff457e424226a435a901da30d3 # as freebsd.yml; bump deliberately+ path: craft-fonts+ persist-credentials: false+ - name: Install system libraries+ run: |+ sudo apt-get update+ sudo apt-get install -y --no-install-recommends \+ libxkbcommon-dev libwayland-dev libx11-dev libxrandr-dev libxi-dev libgl1-mesa-dev+ - uses: dtolnay/rust-toolchain@686976e191b89faba57d3206551f0f330d8cb249 # stable+ with:+ components: rustfmt, clippy+ targets: wasm32-unknown-unknown+ # dependencies only (rust-cache drops the workspace's own artifacts), saved from main and+ # restored by pull requests+ - uses: Swatinem/rust-cache@6323deb102c322ba6fcbdcafc7e3dddab59af2b6 # v2.9.2+ with:+ key: ci+ save-if: ${{ github.ref == 'refs/heads/main' }}+ - name: cargo xtask ci+ run: cargo xtask ci+ - name: Job summary+ if: ${{ !cancelled() }}+ run: cat target/ci/summary.md >> "$GITHUB_STEP_SUMMARY" || truediff --git a/CLAUDE.md b/CLAUDE.mdindex 00a2314aa..f432baf96 100644--- a/CLAUDE.md+++ b/CLAUDE.md@@ -67,7 +67,10 @@ of it. Full standard: `../craftrules/standards/never-crash.md`label, cancel)` for its whole run. It adopts the cancel flag the job already checks (`Cancel::Flag`), or uses`Cancel::No` when the job can't stop. No progress window, panel or progress toast of its own; its tests assert the row.- **Resolution independence:** settings use normalized image coordinates and relative radii; previews and exports must match.-- **Quality gates** before every commit: `cargo xtask ci` (fmt, clippy -D warnings, tests, layers, assets, wasm).+- **Quality gates** before every commit: `cargo xtask ci --quick` (fmt, clippy -D warnings, the changed packages'+ tests, layers, assets, and heif / parity / wasm when touched). GitHub runs the full `cargo xtask ci` on every PR+ (`.github/workflows/ci.yml`); run the full one locally before merging branches (below) or when `--quick` can't see+ the risk. One `ci` runs at a time per machine; others wait their turn (`xtask/src/ci_lock.rs`).- **Commits:** one task id per commit (`M2.3: local Laplacian highlights/shadows`). Only green states. End messages with the attribution line required by the environment.## Assets: icons, images, fonts (ABSOLUTE RULE — never violate)diff --git a/README.md b/README.mdindex 38ff85898..98eda5710 100644--- a/README.md+++ b/README.md@@ -396,8 +396,17 @@ cargo run --release -p lightcraft -- --control 7980 # with the automation chcargo xtask web --serve # the same app in the browser: http://127.0.0.1:8080/cargo run --release -p lightcraft-cli -- render photo.jpg -o out.jpg --set light.exposure=0.5cargo xtask ci # fmt, clippy, HEIF, tests, parity, layers, assets, WASM+cargo xtask ci --quick # only what your branch's changes can break (minutes)```+`cargo xtask ci --quick` compares with the merge base of `origin/main` (`--base REF` for another)+and runs fmt, clippy, the tests of the changed packages, layers and assets, plus HEIF, parity and+the wasm check when the changes touch them; a change to `Cargo.toml`, `Cargo.lock` or the lint+config tests everything. GitHub runs the full `cargo xtask ci` on every pull request+(`.github/workflows/ci.yml`). Only one `ci` runs at a time per machine: a second one, from another+worktree say, waits for the first and names it, since several at once take longer in total than in+turn. `LIGHTCRAFT_CI_SLOTS=2` allows two; `LIGHTCRAFT_CI_LOCK=off` skips the lock.+CI defaults to line-table debug information and one build job per 1.5 GB of RAMavailable when it starts (at most one per CPU; 4 if memory can't be read), so an8 GB machine with 6 GB free builds with 4, and a busy machine with little freediff --git a/docs/gaps.md b/docs/gaps.mdindex 1b4a385fa..92668ee64 100644--- a/docs/gaps.md+++ b/docs/gaps.md@@ -1,6 +1,6 @@# Gaps: where LightCraft falls short of Lightroom-> **Last reviewed:** 2026-10-11 · **Last updated:** 2026-10-15 · **Change:** minor (gap 15: Print Page Options — page numbers, page info, crop marks)+> **Last reviewed:** 2026-10-11 · **Last updated:** 2026-10-19 · **Change:** minor (gap 9 shrinks: `cargo xtask ci` runs on every PR on Linux x64)Every known shortfall, one entry each, ranked by user impact (how many Lightroom users hit it, andhow hard it blocks them), then by effort. **Agents pick work from the top** (the first entry nobody is@@ -23,7 +23,7 @@ Hours are Opus 5.5 agent wall-clock hours (see [target-app-parity.md](target-app| 6 B | **Compressed ORF** (every Olympus / OM body since ~2008) | measured: 66 of 78 Olympus / OM models preview-only; `orf.rs` refuses; OM bucket 3% of photographers, 3% of them fully work | +2.6 points; best gain per hour of any raw gap (~0.2) | 8–15 | [raw-parity](raw-parity.md#compressed-orf-a-clean-room-starting-point) (the two Olympus patents that describe the method) || 7 | **Nikon High Efficiency NEF** (HE / HE★ on Z 8, Z 9, Z 6III, Z f, Z50II, Z5II when set to HE) | named and preview only (#193); needs a pure-Rust JPEG XS decoder | +1.1 points (only shots taken in HE; lossless works on the same bodies); low gain per hour (~0.04), so not a beta blocker | 20–40 | [raw-parity](raw-parity.md) || 8 B | **No lens profile database** (LR-EDIT-OPTICS-PROFILE): only DNG opcodes, RW2 in-file distortion, Sony ILCE-7RM4A and ILCE-7RM6 distortion (`docs/sony-ilce7rm6-lens-corrections.md`) and Nikon Z 6II / Z 8 / Z f distortion (`docs/nikon-lens-corrections.md`) | Adobe ships 3,635 lens profiles; we never use them | distortion / vignetting correction is a default step for many | 40–80 + calibration shots | [raw-parity](raw-parity.md#lens-profiles) |-| 9 B | **Tests don't run in CI on macOS, Windows or Linux x64**: only FreeBSD runs `cargo test`; the others build packages | `.github/workflows/` (freebsd, packaging-lint, release, windows-arm64); the linux-riscv64 release job added in 0.6.0 (#844) runs only `lightcraft-cli --version` under QEMU | regressions reach users on the main platforms; `cargo xtask ci` runs only locally | 6–12 | [target-app-parity](target-app-parity.md#by-dimension) |+| 9 B | **Tests don't run in CI on macOS or Windows**: Linux x64 runs `cargo xtask ci` on every PR and push to main (`.github/workflows/ci.yml`) and FreeBSD runs `cargo test`; the others build packages | `.github/workflows/` (ci, freebsd, packaging-lint, release, windows-arm64); the linux-riscv64 release job added in 0.6.0 (#844) runs only `lightcraft-cli --version` under QEMU; macOS / Windows jobs: #1148 | regressions in `cfg(target_os)` code reach macOS and Windows users | 6–12 | [target-app-parity](target-app-parity.md#by-dimension) || 10 B | **Per-model verification thin, plus cheap per-body decode fixes**: 545 of 1,446 Adobe models verified (38%), ~85% of photographers on a verified body; Nikon 5 bodies verified, Canon 34, Leica 14 (the Q3 by a recorded check of 38 private DNGs). Cheap fixes: Z 6II packed 14-bit NEF (#769, PR #671), Sony A100 / F828 regression (#702), DSLR-A200…A390 / A850 12-bit ARW (#535) | measured: [raw/coverage.tsv](raw/coverage.tsv) | per-body bugs (levels, crops, WB) surface only from users | 25–45 | [raw-parity](raw-parity.md#by-maker-measured) || 11 | **Enhance: Raw Details, Super Resolution; AI denoise without shippable weights or X-Trans** | ENH rows 0%; denoise Bayer only, RawNIND weights GPL and opt-in | Fujifilm users get no AI denoise; nobody gets it out of the box | 30–60 + model decision | [raw-parity](raw-parity.md#demosaic-levels-crops-and-lens-metadata) || 12 | **Content-aware / generative remove, detect distractions, reflections removal** | REM rows 75%; patch synthesis missing | cleanup work goes back to Photoshop | 25–45 (+ generative model) | [target-app-parity](target-app-parity.md#ai) |@@ -77,6 +77,7 @@ Beta-blocking gaps (B) total **~230–430 h**; with the stability and platform w| Date | Change | Summary ||---|---|---|+| 2026-10-19 | minor | Gap 9 shrinks: `.github/workflows/ci.yml` runs `cargo xtask ci` on Linux x64 for every PR and push to main; macOS and Windows remain || 2026-10-18 | patch | Gap 1: six X-Trans CMOS 4 Fujifilm bodies (X-T30 …) take the X-T3's spectral matrices instead of the neutral matrix || 2026-10-15 | minor | Gap 15 shrinks: the Page panel's Page Options (Page Numbers, Page Info, Crop Marks) print on Single Image and Contact Sheet pages; identity plate, watermark, photo info, Cut Guides, direct printing and JPEG output remain || 2026-10-14 | minor | Gap 26: at 100k photos stack and album lookups are indexed, so an "In a Stack" or "Album" smart album counts in ~14 ms (was 0.6–2.7 s); open time unchanged |diff --git a/docs/target-app-parity.md b/docs/target-app-parity.mdindex 557f37a6a..8281639a7 100644--- a/docs/target-app-parity.md+++ b/docs/target-app-parity.md@@ -1,6 +1,6 @@# Target-app parity: LightCraft vs Adobe Lightroom-> **Last reviewed:** 2026-10-10 · **Last updated:** 2026-10-15 · **Change:** minor (RAW: 83% of Adobe's models decode, 38% verified after the camera-coverage sweep #1327) · **Target:** Adobe Lightroom Classic 15.5 (August 2026) and Lightroom 9.6 (desktop)+> **Last reviewed:** 2026-10-10 · **Last updated:** 2026-10-19 · **Change:** patch (stability: `cargo xtask ci` runs on every PR on Linux x64) · **Target:** Adobe Lightroom Classic 15.5 (August 2026) and Lightroom 9.6 (desktop)The authoritative assessment of how close LightCraft is to Lightroom. The row-by-row checklist is[parity-checklist.md](parity-checklist.md); the ranked work list is [gaps.md](gaps.md); deep areas@@ -158,7 +158,7 @@ essentials replaces its guessed 45% raw look with 84% × 0.75 (+1 point).| Discount | Mainstream | Essentials | Evidence ||---|---:|---:|---|| Interaction fidelity / UI clarity | ×0.95 | ×0.95 | brush live preview gaps and feathering (#517, #518); crop artefacts and limits (#731, #742, #770, #771); Compare white-balance selector (#743–#745); low-res slider previews (#330); dialogs taller than the window (#781); mouse-wheel scroll (#714) |-| Stability on real machines | ×0.92 | ×0.92 | launch and quit crashes or silent startup failures (#250 macOS 12 Intel, #315 Windows Intel GPU, #431 Intel Mac, #260, #462, #783 Linux / Nouveau, #790 Windows installer); tests run in CI on FreeBSD only (gap 9) |+| Stability on real machines | ×0.92 | ×0.92 | launch and quit crashes or silent startup failures (#250 macOS 12 Intel, #315 Windows Intel GPU, #431 Intel Mac, #260, #462, #783 Linux / Nouveau, #790 Windows installer); tests run in CI on Linux x64 and FreeBSD only (gap 9) || File exchange with Lightroom users (mainstream) / opening files people send (essentials) | ×0.92 | ×0.95 | Adobe XMP sidecars change colours (#290), XMP CameraProfile and Upright ignored (#204, #205), catalog import fails (#599), same Light values render differently (#523, #209), no write-back to `.lrcat`; for casual users: CR3 beyond verified bodies, compressed ORF, HE NEF open as previews (#473, #485, #556), HEIC trouble (#693) || **Product** | **×0.804** | **×0.830** | |@@ -300,6 +300,7 @@ P2 items 12–25 h; look tuning, performance, packaging, hardening 25–45 h.| Date | Change | Summary ||---|---|---|+| 2026-10-19 | patch | Stability note: tests run in CI on Linux x64 (every PR) as well as FreeBSD; macOS and Windows remain (gap 9) || 2026-10-14 | minor | Localization ~52% → ~55% (mean of the 12 key languages): de, es, fr, ja and uk catalogs filled || 2026-10-12 | minor | UI/UX remaining 34–58 h → 32–54 h (canvas tools by keyboard); headline numbers unchanged || 2026-10-14 | minor | Merge and HDR: merge 100% → 88% (LR-MERGE-HDR ✅ → 🟡 after testing on real 67 MP brackets; gap 29); area percentages unchanged |diff --git a/xtask/src/ci_lock.rs b/xtask/src/ci_lock.rsnew file mode 100644index 000000000..321b0f391--- /dev/null+++ b/xtask/src/ci_lock.rs@@ -0,0 +1,145 @@+//! One `cargo xtask ci` at a time per machine.+//!+//! Every CI run builds the workspace several times with one job per CPU. Several worktrees running+//! it at once (parallel agents) slow each other down far more than waiting in turn would, and make+//! the machine unusable meanwhile. So `ci` first takes one of `LIGHTCRAFT_CI_SLOTS` (default 1)+//! lock files in a per-user cache directory, shared by every checkout and worktree, and holds it+//! until it exits. The OS drops the lock when the process ends, crashed or not.+//!+//! - `LIGHTCRAFT_CI_SLOTS=N`: N runs at once (1–64).+//! - `LIGHTCRAFT_CI_LOCK=off`: no lock (e.g. a CI runner that only ever runs one job).+//! - `LIGHTCRAFT_CI_LOCK=<dir>`: keep the lock files there instead.++use std::fs::{File, OpenOptions, TryLockError};+use std::io::Write;+use std::path::{Path, PathBuf};+use std::time::{Duration, Instant};++const POLL: Duration = Duration::from_secs(2);++/// A held CI slot; dropping it releases the slot.+pub struct Held {+ _file: File,+ owner: PathBuf,+}++impl Drop for Held {+ fn drop(&mut self) {+ let _ = std::fs::remove_file(&self.owner);+ }+}++/// Where the lock files live, or `None` when the lock is switched off.+fn lock_dir() -> Option<PathBuf> {+ match std::env::var_os("LIGHTCRAFT_CI_LOCK") {+ Some(v) if matches!(v.to_str(), Some("off" | "0" | "false" | "no")) => return None,+ Some(v) if !v.is_empty() => return Some(PathBuf::from(v)),+ _ => {}+ }+ let cache = std::env::var_os("XDG_CACHE_HOME")+ .map(PathBuf::from)+ .or_else(|| std::env::var_os("LOCALAPPDATA").map(PathBuf::from))+ .or_else(|| std::env::var_os("HOME").map(|h| PathBuf::from(h).join(".cache")))+ .unwrap_or_else(std::env::temp_dir);+ Some(cache.join("lightcraft"))+}++fn slots() -> usize {+ std::env::var("LIGHTCRAFT_CI_SLOTS").ok().and_then(|s| s.trim().parse().ok()).unwrap_or(1).clamp(1, 64)+}++fn slot_path(dir: &Path, slot: usize) -> PathBuf {+ if slot == 0 { dir.join("ci.lock") } else { dir.join(format!("ci-{}.lock", slot + 1)) }+}++fn owner_path(lock: &Path) -> PathBuf {+ lock.with_extension("lock.owner")+}++/// Take the first free slot of `slots` in `dir`, or `None` when all are held.+pub fn try_acquire(dir: &Path, slots: usize, owner: &str) -> Result<Option<Held>, String> {+ std::fs::create_dir_all(dir).map_err(|e| format!("ci lock: {}: {e}", dir.display()))?;+ for slot in 0..slots.max(1) {+ let path = slot_path(dir, slot);+ let file =+ OpenOptions::new().create(true).truncate(false).write(true).open(&path).map_err(|e| format!("ci lock: {}: {e}", path.display()))?;+ match file.try_lock() {+ Ok(()) => {+ // a sidecar file, not the lock file: Windows locks are mandatory, so others couldn't read it+ let owner_file = owner_path(&path);+ let _ = std::fs::File::create(&owner_file).and_then(|mut f| f.write_all(owner.as_bytes()));+ return Ok(Some(Held { _file: file, owner: owner_file }));+ }+ Err(TryLockError::WouldBlock) => continue,+ Err(TryLockError::Error(e)) => return Err(format!("ci lock: {}: {e}", path.display())),+ }+ }+ Ok(None)+}++/// Who holds each slot, as they wrote it.+fn holders(dir: &Path, slots: usize) -> Vec<String> {+ (0..slots.max(1))+ .filter_map(|slot| std::fs::read_to_string(owner_path(&slot_path(dir, slot))).ok())+ .map(|s| s.trim().to_owned())+ .filter(|s| !s.is_empty())+ .collect()+}++/// Wait for a CI slot (see the module docs). `None` when the lock is off.+pub fn acquire(root: &Path, command: &str) -> Result<Option<Held>, String> {+ let Some(dir) = lock_dir() else {+ return Ok(None);+ };+ let slots = slots();+ let owner = format!("pid {} in {}: {command}", std::process::id(), root.display());+ if let Some(held) = try_acquire(&dir, slots, &owner)? {+ return Ok(Some(held));+ }+ let waiting = Instant::now();+ eprintln!("=== ci: waiting for another CI run to finish ({slots} at a time; LIGHTCRAFT_CI_SLOTS changes it) ===");+ for h in holders(&dir, slots) {+ eprintln!(" running: {h}");+ }+ loop {+ std::thread::sleep(POLL);+ if let Some(held) = try_acquire(&dir, slots, &owner)? {+ eprintln!("=== ci: waited {:.0} s for a CI slot ===", waiting.elapsed().as_secs_f64());+ return Ok(Some(held));+ }+ }+}++#[cfg(test)]+mod tests {+ use super::*;++ fn scratch(name: &str) -> PathBuf {+ let dir = std::env::temp_dir().join(format!("xtask-ci-lock-{name}-{}", std::process::id()));+ let _ = std::fs::remove_dir_all(&dir);+ dir+ }++ #[test]+ fn one_slot_is_exclusive_until_dropped() {+ let dir = scratch("one");+ let first = try_acquire(&dir, 1, "first").unwrap().expect("free slot");+ assert!(try_acquire(&dir, 1, "second").unwrap().is_none());+ assert_eq!(holders(&dir, 1), ["first"]);+ drop(first);+ assert!(holders(&dir, 1).is_empty());+ assert!(try_acquire(&dir, 1, "third").unwrap().is_some());+ let _ = std::fs::remove_dir_all(&dir);+ }++ #[test]+ fn more_slots_admit_more_runs() {+ let dir = scratch("two");+ let a = try_acquire(&dir, 2, "a").unwrap();+ let b = try_acquire(&dir, 2, "b").unwrap();+ assert!(a.is_some() && b.is_some());+ assert!(try_acquire(&dir, 2, "c").unwrap().is_none());+ assert_eq!(holders(&dir, 2), ["a", "b"]);+ let _ = std::fs::remove_dir_all(&dir);+ }+}diff --git a/xtask/src/ci_quick.rs b/xtask/src/ci_quick.rsnew file mode 100644index 000000000..a9e98703b--- /dev/null+++ b/xtask/src/ci_quick.rs@@ -0,0 +1,204 @@+//! `cargo xtask ci --quick`: the checks a branch's own changes can break, for a pre-push check.+//!+//! The full `ci` builds the workspace four ways (clippy, heif, tests, wasm) plus the CLI for the+//! parity check, ~23 minutes cold. `--quick` looks at what changed since the merge base with+//! `origin/main` (or `--base REF`), committed or not, and runs:+//!+//! - fmt, layers, assets: always (seconds);+//! - clippy on the whole workspace (check builds only; catches callers broken by an API change);+//! - the tests of the changed packages only (not their dependents);+//! - heif when `lightcraft-codecs` / `lightcraft-heif` changed;+//! - parity when the tracker docs, a command/control crate, or a file's path changed (renames and+//! deletions: the tracker cites paths);+//! - the wasm check of the changed packages that must build for wasm32.+//!+//! A change to a workspace-wide file (root `Cargo.toml`, `Cargo.lock`, lint or toolchain config)+//! tests everything. The full `ci` (GitHub's CI on every PR) stays the merge gate.++use std::collections::BTreeSet;+use std::path::Path;+use std::process::Command;++/// Root-level files whose change can affect every package.+const WORKSPACE_WIDE: &[&str] =+ &["Cargo.toml", "Cargo.lock", "clippy.toml", "rustfmt.toml", ".rustfmt.toml", "rust-toolchain", "rust-toolchain.toml"];+const WORKSPACE_WIDE_DIRS: &[&str] = &[".cargo/"];+/// Packages whose ids or paths the parity tracker cites (commands, develop controls, UI menus).+const PARITY_PACKAGES: &[&str] = &["lightcraft-engine", "lightcraft-develop", "lightcraft-ui-egui", "lightcraft-cli"];+const PARITY_DOCS: &[&str] = &["docs/parity-checklist.md", "docs/gaps.md"];+const HEIF_PACKAGES: &[&str] = &["lightcraft-codecs", "lightcraft-heif"];++/// A changed path, relative to the workspace root; `gone` when deleted or renamed away.+#[derive(Clone, Debug, PartialEq, Eq)]+pub struct Changed {+ pub path: String,+ pub gone: bool,+}++#[derive(Clone, Debug, Default, PartialEq, Eq)]+pub struct Plan {+ /// Workspace packages with a changed file.+ pub packages: BTreeSet<String>,+ /// A workspace-wide file changed: test everything.+ pub workspace_wide: bool,+ pub heif: bool,+ pub parity: bool,+ /// What the changes were measured against, for the log and the report.+ pub base: String,+ pub files: usize,+}++impl Plan {+ /// Whether anything compiled changed (otherwise clippy and the tests are skipped).+ pub fn rust(&self) -> bool {+ self.workspace_wide || !self.packages.is_empty()+ }+}++/// Decide what to run. `packages` are (name, directory relative to the root, `/`-separated).+pub fn plan(changed: &[Changed], packages: &[(String, String)], base: String) -> Plan {+ let mut p = Plan { base, files: changed.len(), ..Plan::default() };+ for c in changed {+ let path = c.path.as_str();+ if WORKSPACE_WIDE.contains(&path) || WORKSPACE_WIDE_DIRS.iter().any(|d| path.starts_with(d)) {+ p.workspace_wide = true;+ }+ if PARITY_DOCS.contains(&path) || c.gone {+ p.parity = true;+ }+ // the innermost package directory containing the file+ let owner = packages+ .iter()+ .filter(|(_, dir)| !dir.is_empty() && path.strip_prefix(dir.as_str()).is_some_and(|rest| rest.starts_with('/')))+ .max_by_key(|(_, dir)| dir.len());+ if let Some((name, _)) = owner {+ p.packages.insert(name.clone());+ }+ }+ p.heif = p.workspace_wide || HEIF_PACKAGES.iter().any(|h| p.packages.contains(*h));+ p.parity |= p.workspace_wide || PARITY_PACKAGES.iter().any(|h| p.packages.contains(*h));+ p+}++fn git(root: &Path, args: &[&str]) -> Result<String, String> {+ let out = Command::new("git").args(args).current_dir(root).output().map_err(|e| format!("git {}: {e}", args.join(" ")))?;+ if !out.status.success() {+ return Err(format!("git {}: {}", args.join(" "), String::from_utf8_lossy(&out.stderr).trim()));+ }+ Ok(String::from_utf8_lossy(&out.stdout).into_owned())+}++/// Parse `git diff --name-status` output.+fn parse_name_status(out: &str) -> Vec<Changed> {+ let mut v = Vec::new();+ for line in out.lines() {+ let mut cols = line.split('\t');+ let (Some(status), Some(first)) = (cols.next(), cols.next()) else { continue };+ match (status.chars().next(), cols.next()) {+ // renamed / copied: old path, new path+ (Some(k @ ('R' | 'C')), Some(second)) => {+ v.push(Changed { path: first.to_owned(), gone: k == 'R' });+ v.push(Changed { path: second.to_owned(), gone: false });+ }+ (Some('D'), _) => v.push(Changed { path: first.to_owned(), gone: true }),+ _ => v.push(Changed { path: first.to_owned(), gone: false }),+ }+ }+ v+}++/// The files changed since the merge base with `base` (default `origin/main`, else `main`):+/// committed, staged, unstaged and untracked. Returns the base description and the files.+pub fn changed_files(root: &Path, base: Option<&str>) -> Result<(String, Vec<Changed>), String> {+ let base = match base {+ Some(b) => b.to_owned(),+ None => ["origin/main", "main"]+ .into_iter()+ .find(|b| git(root, &["rev-parse", "--verify", "--quiet", &format!("{b}^{{commit}}")]).is_ok())+ .ok_or("no origin/main or main to compare with; pass --base REF")?+ .to_owned(),+ };+ let merge_base = git(root, &["merge-base", "HEAD", &base])?.trim().to_owned();+ let mut files = parse_name_status(&git(root, &["diff", "--name-status", "-M", &merge_base])?);+ for path in git(root, &["ls-files", "--others", "--exclude-standard"])?.lines() {+ files.push(Changed { path: path.to_owned(), gone: false });+ }+ let short: String = merge_base.chars().take(10).collect();+ Ok((format!("{base} (merge base {short})"), files))+}++/// (name, root-relative directory) of each workspace package, from `cargo metadata`.+pub fn packages(root: &Path, metadata: &serde_json::Value) -> Vec<(String, String)> {+ let roots: Vec<std::path::PathBuf> = [Some(root.to_path_buf()), root.canonicalize().ok()].into_iter().flatten().collect();+ metadata["packages"]+ .as_array()+ .into_iter()+ .flatten()+ .filter_map(|p| {+ let name = p["name"].as_str()?;+ let dir = Path::new(p["manifest_path"].as_str()?).parent()?;+ let rel = roots.iter().find_map(|r| dir.strip_prefix(r).ok())?;+ let rel = rel.components().map(|c| c.as_os_str().to_string_lossy()).collect::<Vec<_>>().join("/");+ Some((name.to_owned(), rel))+ })+ .collect()+}++#[cfg(test)]+mod tests {+ use super::*;++ fn ch(path: &str) -> Changed {+ Changed { path: path.into(), gone: false }+ }++ fn pkgs() -> Vec<(String, String)> {+ [+ ("lightcraft-raw", "crates/raw"),+ ("lightcraft-codecs", "crates/codecs"),+ ("lightcraft-engine", "crates/engine"),+ ("lightcraft-cli", "apps/lightcraft-cli"),+ ("xtask", "xtask"),+ ("lightcraft-raw-nested", "crates/raw/nested"),+ ]+ .into_iter()+ .map(|(a, b)| (a.to_owned(), b.to_owned()))+ .collect()+ }++ #[test]+ fn changed_files_pick_their_innermost_package() {+ let p = plan(&[ch("crates/raw/src/lib.rs"), ch("crates/raw/nested/src/x.rs"), ch("crates/rawx/y.rs")], &pkgs(), "b".into());+ assert_eq!(p.packages.iter().map(String::as_str).collect::<Vec<_>>(), ["lightcraft-raw", "lightcraft-raw-nested"]);+ assert!(p.rust() && !p.workspace_wide && !p.heif && !p.parity);+ }++ #[test]+ fn docs_only_skip_the_builds_but_tracker_docs_run_parity() {+ let p = plan(&[ch("README.md"), ch("docs/raw-parity.md")], &pkgs(), "b".into());+ assert!(!p.rust() && !p.parity);+ let p = plan(&[ch("docs/gaps.md")], &pkgs(), "b".into());+ assert!(!p.rust() && p.parity);+ }++ #[test]+ fn workspace_files_heif_and_parity_triggers() {+ let p = plan(&[ch("Cargo.lock")], &pkgs(), "b".into());+ assert!(p.workspace_wide && p.rust() && p.heif && p.parity);+ let p = plan(&[ch("crates/codecs/src/heif.rs")], &pkgs(), "b".into());+ assert!(p.heif && !p.parity);+ let p = plan(&[ch("crates/engine/src/commands.rs")], &pkgs(), "b".into());+ assert!(p.parity && !p.heif);+ let p = plan(&[Changed { path: "crates/raw/src/old.rs".into(), gone: true }], &pkgs(), "b".into());+ assert!(p.parity, "a removed path may be cited by the tracker");+ }++ #[test]+ fn name_status_parses_renames_and_deletions() {+ let v = parse_name_status("M\ta.rs\nR087\told.rs\tnew.rs\nD\tgone.rs\nA\tadded.rs\n\n");+ assert_eq!(+ v,+ [ch("a.rs"), Changed { path: "old.rs".into(), gone: true }, ch("new.rs"), Changed { path: "gone.rs".into(), gone: true }, ch("added.rs"),]+ );+ }+}diff --git a/xtask/src/main.rs b/xtask/src/main.rsindex 8a7d597b5..0a5e64532 100644--- a/xtask/src/main.rs+++ b/xtask/src/main.rs@@ -5,6 +5,8 @@mod assets;mod bench;+mod ci_lock;+mod ci_quick;mod ci_report;mod ico;mod layers;@@ -34,11 +36,15 @@ commands:web [--serve [port]] [--dev]build the browser app (apps/lightcraft-web) into <target>/web-site/;--serve serves it on http://127.0.0.1:<port> (default 8080)- ci [--hardware] [--summary-md]+ ci [--hardware] [--summary-md] [--quick [--base REF]]fmt --check, clippy -D warnings, heif, test, GPU probe, parity refs, layers, assets, wasm(stops at first failure); writes target/ci/report.json (machine, GPU adapters, data,steps, skipped tests) and target/ci/summary.md; --hardware also runs the GPU tests on- every backend with a hardware adapter; --summary-md prints the Markdown summary+ every backend with a hardware adapter; --summary-md prints the Markdown summary.+ --quick: only what the changes since the merge base with origin/main (or REF) can+ break: clippy, the changed packages' tests, and heif / parity / wasm when they apply.+ One ci runs at a time per machine; others wait (LIGHTCRAFT_CI_SLOTS=N for N at once,+ LIGHTCRAFT_CI_LOCK=off to skip the lock)corpus [--download]show where test corpora live; --download fetches PngSuite and CC0 raw samples (raw.pixls.us) into corpus/ and checks their sha256stats [--exact] count tests and lines per crate (--exact: ask the test harness via `-- --list`)@@ -249,7 +255,16 @@ fn wasm_set() -> Result<Vec<String>, String> {}fn cmd_wasm() -> Result<(), String> {- let set = wasm_set()?;+ cmd_wasm_for(None)+}++/// The wasm check of the wasm-safe crates, or only those of them in `only` (`ci --quick`).+fn cmd_wasm_for(only: Option<&std::collections::BTreeSet<String>>) -> Result<(), String> {+ let set: Vec<String> = wasm_set()?.into_iter().filter(|p| only.is_none_or(|o| o.contains(p))).collect();+ if set.is_empty() {+ println!("wasm32-unknown-unknown check: no changed crate builds for wasm32");+ return Ok(());+ }let mut results = Vec::new();for pkg in &set {let mut c = cargo();@@ -268,10 +283,36 @@ fn cmd_wasm() -> Result<(), String> {fn cmd_ci(args: &[&str]) -> Result<(), String> {let hardware = args.contains(&"--hardware");let print_md = args.contains(&"--summary-md");- if let Some(other) = args.iter().find(|a| !matches!(**a, "--hardware" | "--summary-md")) {+ let quick = args.contains(&"--quick");+ let base_at = args.iter().position(|a| *a == "--base");+ let base = base_at.map(|i| args.get(i + 1).copied().ok_or("ci: --base needs a ref")).transpose()?;+ let unknown = args+ .iter()+ .enumerate()+ .find(|(i, a)| !matches!(**a, "--hardware" | "--summary-md" | "--quick" | "--base") && base_at.is_none_or(|b| *i != b + 1));+ if let Some((_, other)) = unknown {return Err(format!("ci: unknown option `{other}`\n\n{USAGE}"));}+ if base.is_some() && !quick {+ return Err("ci: --base only applies to --quick".into());+ }let root = root();+ let command = std::iter::once("cargo xtask ci").chain(args.iter().copied()).collect::<Vec<_>>().join(" ");+ // held until ci returns: one run at a time per machine (ci_lock.rs)+ let _slot = ci_lock::acquire(&root, &command)?;+ let plan = if quick {+ let (base, files) = ci_quick::changed_files(&root, base)?;+ let plan = ci_quick::plan(&files, &ci_quick::packages(&root, &metadata()?), base);+ let packages: Vec<&str> = plan.packages.iter().map(String::as_str).collect();+ eprintln!("=== ci --quick: {} changed file(s) since {} ===", plan.files, plan.base);+ eprintln!(" packages: {}", if packages.is_empty() { "none".to_owned() } else { packages.join(", ") });+ if plan.workspace_wide {+ eprintln!(" a workspace-wide file changed: testing every package");+ }+ Some(plan)+ } else {+ None+ };let report_dir = ci_report::prepare(&root)?;let started = std::time::Instant::now();let started_unix = std::time::SystemTime::now().duration_since(std::time::UNIX_EPOCH).map(|d| d.as_secs()).unwrap_or(0);@@ -296,6 +337,21 @@ fn cmd_ci(args: &[&str]) -> Result<(), String> {};type Step<'a> = (&'static str, Box<dyn Fn() -> Result<(), String> + 'a>);+ // `--quick`: which steps apply (all of them in a full run) and the packages to test+ let wants = |step: &str| match &plan {+ None => true,+ Some(p) => match step {+ "clippy" | "test" | "wasm" => p.rust(),+ "heif" => p.heif,+ "parity" => p.parity,+ _ => true,+ },+ };+ let mut test_args = vec!["test".to_owned()];+ match &plan {+ Some(p) if !p.workspace_wide => test_args.extend(p.packages.iter().flat_map(|n| ["-p".to_owned(), n.clone()])),+ _ => test_args.push("--workspace".to_owned()),+ }let mut steps: Vec<Step> = vec![("fmt",@@ -325,8 +381,15 @@ fn cmd_ci(args: &[&str]) -> Result<(), String> {test(&["test", "-p", "lightcraft-engine", "--lib", "--features", "lightcraft-codecs/heif", "heic"], "heif")}),),- ("test", Box::new(|| test(&["test", "--workspace"], "test"))),+ (+ "test",+ Box::new(|| {+ let a: Vec<&str> = test_args.iter().map(String::as_str).collect();+ test(&a, "test")+ }),+ ),];+ steps.retain(|(name, _)| wants(name));if hardware {steps.push(("gpu-backends",@@ -360,10 +423,17 @@ fn cmd_ci(args: &[&str]) -> Result<(), String> {}),));}- steps.push(("parity", Box::new(|| parity::run(&root, false))));+ if wants("parity") {+ steps.push(("parity", Box::new(|| parity::run(&root, false))));+ }steps.push(("layers", Box::new(cmd_layers)));steps.push(("assets", Box::new(|| assets::run(&root))));- steps.push(("wasm", Box::new(cmd_wasm)));+ if wants("wasm") {+ match plan.as_ref().filter(|p| !p.workspace_wide) {+ Some(p) => steps.push(("wasm", Box::new(|| cmd_wasm_for(Some(&p.packages))))),+ None => steps.push(("wasm", Box::new(cmd_wasm))),+ }+ }let mut results = Vec::new();let mut failure = None;@@ -373,7 +443,7 @@ fn cmd_ci(args: &[&str]) -> Result<(), String> {let r = f();let status = if r.is_ok() { "ok" } else { "fail" };results.push(serde_json::json!({"name": name, "status": status, "seconds": t.elapsed().as_secs_f64()}));- if *name == "test" {+ if *name == "test" && plan.is_none() {// right after the workspace tests, before parity and wasm build other feature setsprobe();}@@ -383,7 +453,8 @@ fn cmd_ci(args: &[&str]) -> Result<(), String> {}}if gpu.borrow().is_null() {- *gpu.borrow_mut() = serde_json::json!({"error": "not probed: the test step did not run"});+ let why = if plan.is_some() { "not probed: --quick" } else { "not probed: the test step did not run" };+ *gpu.borrow_mut() = serde_json::json!({"error": why});}let done: Vec<&str> = steps.iter().take(results.len()).map(|(n, _)| *n).collect();match &failure {@@ -407,7 +478,8 @@ fn cmd_ci(args: &[&str]) -> Result<(), String> {let ram_mb = available_ram_mb();let report = serde_json::json!({"schema": ci_report::SCHEMA,- "command": std::iter::once("cargo xtask ci").chain(args.iter().copied()).collect::<Vec<_>>().join(" "),+ "command": command,+ "quick": plan.as_ref().map(|p| serde_json::json!({"base": p.base, "files": p.files, "packages": p.packages, "workspace_wide": p.workspace_wide})),"result": if failure.is_some() { "fail" } else { "pass" },"failed_step": failure.as_ref().map(|(n, _)| *n),"started_unix": started_unix,