diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0ec32581..91f1009f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -26,6 +26,11 @@ jobs: components: rustfmt, clippy targets: wasm32-unknown-unknown - uses: Swatinem/rust-cache@v2 + with: + # The test build carries the golden feature; bump this when the + # features it builds with change, or the old cache is restored whole + # and never saved again. + key: workspace-goldens-clippy - name: Mesa lavapipe for the golden images run: sudo apt-get update && sudo apt-get install -y mesa-vulkan-drivers - run: cargo xtask ci diff --git a/xtask/src/snapshots.rs b/xtask/src/snapshots.rs index 9ea61a5a..e0d1a38e 100644 --- a/xtask/src/snapshots.rs +++ b/xtask/src/snapshots.rs @@ -30,16 +30,20 @@ pub struct Plan { pub filter: Option, } -/// The golden check with no filter, as a `cargo xtask ci` step. -pub fn check_goldens() -> Result<()> { - run(&Plan { - mode: Mode::Check, - filter: None, - }) +/// The workspace's whole test run with the goldens in it, as `cargo xtask ci` +/// runs it. `-p eggshell-ui --features snapshots` resolves the shared +/// dependencies' features differently from `--workspace` and rebuilds sixty-odd +/// crates, so the goldens ride in the one workspace build instead. +pub fn test_with_goldens() -> Result<()> { + guarded(&golden_dir(), workspace_step) +} + +fn golden_dir() -> PathBuf { + process::workspace_root().join(GOLDEN_DIR) } pub fn run(plan: &Plan) -> Result<()> { - let golden_dir = process::workspace_root().join(GOLDEN_DIR); + let golden_dir = golden_dir(); match plan.mode { Mode::Clean => { let removed = clean(&golden_dir)?; @@ -52,10 +56,15 @@ pub fn run(plan: &Plan) -> Result<()> { } fn check(plan: &Plan, golden_dir: &Path) -> Result<()> { + guarded(golden_dir, |icd| renderer_step(plan, icd)) +} + +/// Runs the step `renderer` makes and fails on any stray image it leaves. +fn guarded(golden_dir: &Path, renderer: impl FnOnce(&Path) -> Step) -> Result<()> { let icd = lavapipe_icd()?; // Strays from an earlier failed run would otherwise read as mismatches now. clean(golden_dir)?; - let result = renderer_step(plan, &icd).run(); + let result = renderer(&icd).run(); let strays = strays(golden_dir)?; for stray in &strays { println!("mismatch: {}", stray.display()); @@ -106,8 +115,7 @@ fn renderer_step(plan: &Plan, icd: &Path) -> Step { "--nocapture", ], ) - .with_env("VK_ICD_FILENAMES", icd.display().to_string()) - .with_env("VK_DRIVER_FILES", icd.display().to_string()); + .on_lavapipe(icd); if plan.mode == Mode::Update { step = step.with_env("UPDATE_SNAPSHOTS", "1"); } @@ -115,6 +123,22 @@ fn renderer_step(plan: &Plan, icd: &Path) -> Step { step } +/// Every test of the workspace, the goldens among them, with the software +/// renderer selected for the child only. +fn workspace_step(icd: &Path) -> Step { + Step::cargo( + "test", + &[ + "test", + "--workspace", + "--all-targets", + "--features", + "eggshell-ui/snapshots", + ], + ) + .on_lavapipe(icd) +} + /// The libtest filter selecting the `snapshots` module of the `it` binary, /// narrowed to the golden whose name starts with `name`. fn snapshot_filter(name: Option<&str>) -> String { @@ -261,6 +285,15 @@ mod tests { ); } + #[test] + fn the_workspace_run_carries_the_goldens_and_selects_lavapipe() { + assert_eq!( + workspace_step(Path::new("/icd/lvp.json")).to_string(), + "VK_ICD_FILENAMES=\"/icd/lvp.json\" VK_DRIVER_FILES=\"/icd/lvp.json\" \ + cargo test --workspace --all-targets --features eggshell-ui/snapshots" + ); + } + #[test] fn update_sets_the_variable_for_the_child_and_filter_follows_the_separator() { let step = renderer_step( diff --git a/xtask/src/steps.rs b/xtask/src/steps.rs index bbb09d0f..454d1f88 100644 --- a/xtask/src/steps.rs +++ b/xtask/src/steps.rs @@ -1,5 +1,5 @@ use std::fmt; -use std::path::PathBuf; +use std::path::{Path, PathBuf}; use anyhow::{Context, Result, bail}; @@ -53,6 +53,13 @@ impl Step { } } + /// Points Vulkan at the lavapipe driver whose manifest is `icd`. + pub fn on_lavapipe(self, icd: &Path) -> Self { + let icd = icd.display().to_string(); + self.with_env("VK_ICD_FILENAMES", icd.clone()) + .with_env("VK_DRIVER_FILES", icd) + } + pub fn with_env(mut self, key: &'static str, value: impl Into) -> Self { self.env.push((key, value.into())); self @@ -137,8 +144,8 @@ pub fn wasm() -> Step { pub const WASM_TARGET: &str = "wasm32-unknown-unknown"; -/// What CI runs, in order. The golden check needs Mesa lavapipe, locally and -/// on the runner alike. +/// What CI runs, in order. The test step carries the golden check, which needs +/// Mesa lavapipe, locally and on the runner alike. pub fn ci_steps() -> Vec { vec![ fmt(FmtMode::Check), @@ -149,17 +156,18 @@ pub fn ci_steps() -> Vec { "clippy", "--workspace", "--all-targets", + "--features", + "eggshell-ui/snapshots", "--", "-D", "warnings", ], ), - Step::cargo("test", &["test", "--workspace", "--all-targets"]), + Step::internal("test", snapshots::test_with_goldens), Step::cargo("doctest", &["test", "--workspace", "--doc"]), Step::cargo("rustdoc", &["doc", "--workspace", "--no-deps"]) .with_env("RUSTDOCFLAGS", "-D warnings"), wasm(), - Step::internal("snapshots", snapshots::check_goldens), ] } @@ -219,12 +227,11 @@ mod tests { [ "cargo fmt --all --check", "built-in clock check", - "cargo clippy --workspace --all-targets -- -D warnings", - "cargo test --workspace --all-targets", + "cargo clippy --workspace --all-targets --features eggshell-ui/snapshots -- -D warnings", + "built-in test check", "cargo test --workspace --doc", "RUSTDOCFLAGS=\"-D warnings\" cargo doc --workspace --no-deps", "cargo check --target wasm32-unknown-unknown --workspace --exclude xtask --lib --examples", - "built-in snapshots check", ] ); }