Files
reims-vgpu/scripts/feature-matrix/feature-matrix.sh
T
Anees IqbalandClaude f5209c344a ✅ The option ROM every x86 boot builds was checked by nothing
Component: scripts/feature-matrix. No product code changes.

`crates/reims-vgpu-efi` is live — `vm/boot-x86.sh` rebuilds it before every x86
boot, and OVMF loads the result as the PCI expansion ROM — but it is a separate
workspace targeting `x86_64-unknown-uefi`, so no command in AGENTS.md and no
cell of the feature matrix ever compiled it. That is the same gap that let the
Metal arm accumulate 11 errors while every run read green: a shipping crate
nothing checks.

The matrix gains a fourth cell. It is not a backend arm and the script says so;
it is the artifact half of the x86 pathway.

Two mechanical facts made this more than one line:

- `--all-targets` cannot be used on this package. Its bin is `#![no_main]` with
  the `uefi` crate's panic handler, so building a libtest harness for it
  collides with `std`'s `#[panic_handler]` (E0152) — on the UEFI target and on
  the host alike. The cell checks lib + bin without it, and the count cell
  enumerates `--lib` only and prints "(bin is UEFI-only)" rather than a number
  that would look like a drop.
- `run_cell` and `count_cell` assumed one workspace and `-p reims-vgpu`. Both
  now take the directory, the package selector and the target scope as trailing
  optionals, defaulted to what the three backend arms already passed. The
  defaults use `${n-…}` rather than `${n:-…}` so a cell can pass an explicitly
  empty selector — with the colon form, "no `-p`" silently became
  "`-p reims-vgpu`" and the cell failed with "did not match any packages".

The cell was proved able to fail: a type error appended to
`crates/reims-vgpu-efi/src/lib.rs` produces `FAIL option-rom /
x86_64-unknown-uefi` with the rustc line and a non-zero exit, and the run goes
back to PASS when reverted. A host without the target installed gets SKIP with
the `rustup target add` line, matching how the Metal arm reports the same
condition.

It also reports 7 host-runnable lib tests (`paint`, the real Blt paths), which
were previously enumerated by nothing.

Verified: `bash -n`; a full `scripts/feature-matrix/feature-matrix.sh` run —
PASS on all four cells, warnings=0, lib=1381 unchanged for the Vulkan arm.
shellcheck is not installed on this host and was not run.

Not verified: no boot. The cell checks; it does not link a real ROM, and
`crates/reims-vgpu-efi/scripts/reims-vgpu-efi-rom/reims-vgpu-efi-rom.sh`
remains the only thing that produces the artifact.

Found while adding it, not fixed here: the package is not clippy-clean —
8 lints on the UEFI target, four of them `too_many_arguments` (11, 10, 10 and 8
parameters), plus three `enum_clike_unportable_variant` and one
`manual_is_multiple_of`. Adding a clippy arm now would land a standing red, so
that is its own change.

Co-Authored-By: Claude <noreply@anthropic.com>
2026-08-05 14:51:48 +03:00

291 lines
11 KiB
Bash
Executable File

#!/usr/bin/env bash
# Compile every supported reims-vgpu arm, tests included, plus the option ROM.
#
# The project supports three arms, one per host GPU API actually available:
# Metal on Apple, Vulkan through MoltenVK on Apple, and Vulkan on a native
# Linux ICD. QEMU's meson picks one per build and day-to-day work compiles one,
# so a rename or a cfg change could break another arm silently for days. This
# script is the gate.
#
# It checks `--all-targets`, not the bare default, so arm-specific test code
# compiles too. Compiling is not enough on its own: a test that compiles on an
# arm but is cfg'd out still tests nothing, so the script also reports how many
# tests each arm actually runs.
set -euo pipefail
REPO="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"
WORKSPACE_DIR="${REPO}"
CROSS_TARGET="${CROSS_TARGET:-x86_64-unknown-linux-gnu}"
CARGO_CMD="check"
COUNT_TESTS=1
usage() {
cat <<'EOF'
usage: scripts/feature-matrix/feature-matrix.sh [--build] [--no-counts]
Runs `cargo check --all-targets` (or `cargo build` with --build) over every
supported reims-vgpu arm and reports one PASS/FAIL line per arm. Exits non-zero
if any arm fails to compile.
It then reports, per natively-runnable arm, how many tests that arm actually
enumerates — a test that compiles but is cfg'd out still tests nothing, so a
cfg change that silently empties an arm shows up as a dropped count rather than
a green run. Counting links the test binaries, which is slower than checking;
pass --no-counts to skip it. The cross-compiled arm cannot be counted because
its binaries do not run on this host.
The three supported arms, one per host GPU API actually available:
Metal --features backend-metal Apple only
Vulkan / MoltenVK --no-default-features
--features backend-vulkan,host-window Apple
Vulkan / native same feature set Linux
A fourth cell checks crates/reims-vgpu-efi, the PCI option ROM every x86 boot
builds. It is a separate workspace targeting x86_64-unknown-uefi, so it is not
a backend arm — but it ships, and nothing else in the repository checks it.
The feature sets are exactly what vendor/qemu/hw/display/meson.build passes for
REIMS_VGPU_BACKEND=metal and REIMS_VGPU_BACKEND=vulkan. An Apple host builds
all three natively (the Linux one by cross check). A Linux host builds the
native Vulkan arm and cross-checks the other two.
The Metal arm cross-checks from any host. src/lib.rs rejects backend-metal on
`not(target_os = "macos")` — that is a condition on the *target*, not on the
host, so `--target *-apple-darwin` satisfies it and the real cfgs are
exercised. `cargo check` needs no Apple SDK. This script used to skip the arm
off Apple on the theory that Metal could not be cross-checked at all, and the
arm rotted to 11 errors unnoticed; every one of them was in first-party code
that this cell catches.
Checking is all that is claimed: it type-checks the arm, it does not link
against a real SDK and cannot run it.
Warnings do not fail an arm; the count is printed so drift stays visible.
env:
CROSS_TARGET Linux target to cross-check (default x86_64-unknown-linux-gnu)
METAL_TARGET Apple target to cross-check the Metal arm against off Apple
(default: aarch64-apple-darwin if installed, else
x86_64-apple-darwin)
EOF
}
while [ "$#" -gt 0 ]; do
case "$1" in
--build)
CARGO_CMD="build"
shift
;;
--no-counts)
COUNT_TESTS=0
shift
;;
-h | --help)
usage
exit 0
;;
*)
echo "feature-matrix: unknown argument '$1'" >&2
usage >&2
exit 64
;;
esac
done
if ! command -v cargo >/dev/null 2>&1; then
if [ -x "$HOME/.cargo/bin/cargo" ]; then
export PATH="$HOME/.cargo/bin:$PATH"
else
echo "feature-matrix: ERROR: cargo not found" >&2
exit 1
fi
fi
HOST_TRIPLE="$(rustc -vV | awk '/^host: /{print $2}')"
if ! rustc --print target-list | grep -qx "$CROSS_TARGET"; then
echo "feature-matrix: ERROR: unknown target '$CROSS_TARGET'" >&2
exit 1
fi
if [ "$CROSS_TARGET" != "$HOST_TRIPLE" ] &&
! rustup target list --installed 2>/dev/null | grep -qx "$CROSS_TARGET"; then
echo "feature-matrix: ERROR: target '$CROSS_TARGET' not installed" >&2
echo "feature-matrix: run: rustup target add $CROSS_TARGET" >&2
exit 1
fi
# Feature sets, verbatim from vendor/qemu/hw/display/meson.build.
FEATURES_METAL="--features backend-metal"
FEATURES_VULKAN="--no-default-features --features backend-vulkan,host-window"
FAILED=0
RESULTS=()
# label, target triple (empty for host), feature args, then three optionals for
# a package that is not `reims-vgpu` in the workspace: its directory, its
# `-p`/`--manifest-path` selector, and its target scope.
run_cell() {
local label="$1" target="$2" features="$3"
local dir="${4:-$WORKSPACE_DIR}" pkg="${5--p reims-vgpu}" scope="${6---all-targets}"
local target_args=()
[ -n "$target" ] && target_args=(--target "$target")
local log
log="$(mktemp)"
local status="PASS"
# --all-targets is load-bearing: without it this compiles the product only,
# and every arm's test code goes unchecked. The option ROM is the one cell
# that cannot use it — its bin is `#![no_main]` with its own panic handler,
# so libtest's harness collides with `std`'s on any target that has one.
# shellcheck disable=SC2086 # $features, $pkg and $scope are argument lists.
if ! (cd "$dir" && cargo "$CARGO_CMD" $scope $pkg \
${target_args[@]+"${target_args[@]}"} \
$features --message-format short) >"$log" 2>&1; then
status="FAIL"
FAILED=1
fi
# cargo replays nothing for an up-to-date unit, so a cached cell reports no
# warnings at all. Say "cached" rather than "0" — a silent 0 reads as clean.
local warns
if grep -q '^ *Checking reims-vgpu\|^ *Compiling reims-vgpu' "$log"; then
warns="$(grep -c ': warning' "$log" || true)"
else
warns="cached"
fi
RESULTS+=("$(printf '%-4s %-46s warnings=%s' "$status" "$label" "$warns")")
if [ "$status" = "FAIL" ]; then
echo "--- $label ---" >&2
grep -E ': error|^error' "$log" >&2 || cat "$log" >&2
fi
rm -f "$log"
}
# Enumerate an arm's tests without running them. `--list` makes the libtest
# harness print one `path::name: test` line per test and exit, so the count is
# what that arm would actually execute — cfg'd-out tests are simply absent.
# Only natively-runnable arms can be counted; a cross-compiled binary does not
# run on this host.
COUNTS=()
# label, feature args, then the same three optionals `run_cell` takes. A cell
# whose `all_targets` enumeration cannot link — the option ROM's — passes
# `--lib` as its scope and reports why rather than a misleading count.
count_cell() {
local label="$1" features="$2"
local dir="${3:-$WORKSPACE_DIR}" pkg="${4--p reims-vgpu}" scope="${5---all-targets}"
[ "$COUNT_TESTS" -eq 1 ] || return 0
local out lib total
out="$(mktemp)"
# shellcheck disable=SC2086 # $features and $pkg are argument lists.
if ! (cd "$dir" && cargo test $pkg $features --lib -- --list) \
>"$out" 2>/dev/null; then
COUNTS+=("$(printf '%-46s %s' "$label" "(could not enumerate)")")
rm -f "$out"
return 0
fi
lib="$(grep -c ': test$' "$out" || true)"
if [ "$scope" = "--lib" ]; then
COUNTS+=("$(printf '%-46s lib=%-5s all_targets=%s' "$label" "$lib" \
"(bin is UEFI-only)")")
rm -f "$out"
return 0
fi
# shellcheck disable=SC2086
(cd "$dir" && cargo test $pkg $features -- --list) \
>"$out" 2>/dev/null || true
total="$(grep -c ': test$' "$out" || true)"
COUNTS+=("$(printf '%-46s lib=%-5s all_targets=%s' "$label" "$lib" "$total")")
rm -f "$out"
}
echo "[feature-matrix] host=$HOST_TRIPLE cross=$CROSS_TARGET cargo=$CARGO_CMD"
# Arm 1 — Metal. Native on Apple, cross-checked everywhere else: lib.rs gates
# backend-metal on target_os, so an Apple *target* is all the arm needs. Only
# the run half is Apple-only, which is why the off-Apple cell never counts
# tests.
case "$HOST_TRIPLE" in
*-apple-*)
run_cell "metal / $HOST_TRIPLE" "" "$FEATURES_METAL"
count_cell "metal / $HOST_TRIPLE" "$FEATURES_METAL"
;;
*)
# arm64 macOS is the pathway this arm actually ships on, so prefer it and
# fall back to the x86 Apple target; both carry target_os = "macos" and so
# exercise the same cfgs.
if [ -z "${METAL_TARGET:-}" ]; then
for cand in aarch64-apple-darwin x86_64-apple-darwin; do
if rustup target list --installed 2>/dev/null | grep -qx "$cand"; then
METAL_TARGET="$cand"
break
fi
done
fi
if [ -n "${METAL_TARGET:-}" ]; then
run_cell "metal / $METAL_TARGET" "$METAL_TARGET" "$FEATURES_METAL"
if [ "$COUNT_TESTS" -eq 1 ]; then
COUNTS+=("$(printf '%-46s %s' "metal / $METAL_TARGET" \
"(cross-compiled — cannot run here)")")
fi
else
# Not a pass. Say which command restores the cell, because the last time
# this arm went unchecked it accumulated 11 errors.
RESULTS+=("$(printf '%-4s %-46s %s' "SKIP" "metal / $HOST_TRIPLE" \
"(rustup target add aarch64-apple-darwin)")")
fi
;;
esac
# Arms 2 and 3 — Vulkan through MoltenVK on Apple, native ICD on Linux. Same
# feature set; the host is what differs.
run_cell "vulkan,host-window / $HOST_TRIPLE" "" "$FEATURES_VULKAN"
count_cell "vulkan,host-window / $HOST_TRIPLE" "$FEATURES_VULKAN"
if [ "$CROSS_TARGET" != "$HOST_TRIPLE" ]; then
run_cell "vulkan,host-window / $CROSS_TARGET" "$CROSS_TARGET" "$FEATURES_VULKAN"
if [ "$COUNT_TESTS" -eq 1 ]; then
COUNTS+=("$(printf '%-46s %s' "vulkan,host-window / $CROSS_TARGET" \
"(cross-compiled — cannot run here)")")
fi
fi
# Arm 4 — the PCI option ROM. Not a backend arm and not a workspace member: it
# is its own workspace targeting x86_64-unknown-uefi, and `vm/boot-x86.sh`
# rebuilds it before every x86 boot. It was invisible to this script and to
# every command in AGENTS.md, which is the same gap that let the Metal arm rot
# to 11 errors: a live crate nothing checks.
#
# `--all-targets` cannot be used here. The bin is `#![no_main]` with the `uefi`
# crate's panic handler, so building its test harness collides with `std`'s —
# on the UEFI target and on the host alike. The lib is where the logic is
# (`paint`, the real Blt paths), and it does run on the host.
EFI_DIR="$REPO/crates/reims-vgpu-efi"
EFI_TARGET="x86_64-unknown-uefi"
if rustup target list --installed 2>/dev/null | grep -qx "$EFI_TARGET"; then
run_cell "option-rom / $EFI_TARGET" "$EFI_TARGET" "" "$EFI_DIR" "" ""
else
RESULTS+=("$(printf '%-4s %-46s %s' "SKIP" "option-rom / $EFI_TARGET" \
"(rustup target add $EFI_TARGET)")")
fi
count_cell "option-rom / host lib" "" "$EFI_DIR" "" "--lib"
echo
for line in "${RESULTS[@]}"; do
echo "[feature-matrix] $line"
done
if [ "${#COUNTS[@]}" -gt 0 ]; then
echo
echo "[feature-matrix] tests enumerated per arm:"
for line in "${COUNTS[@]}"; do
echo "[feature-matrix] $line"
done
echo "[feature-matrix] A dropped count means a cfg change emptied an arm;"
echo "[feature-matrix] compiling is not the same as testing."
fi
if [ "$FAILED" -ne 0 ]; then
echo "[feature-matrix] FAILED: at least one supported arm does not compile" >&2
exit 1
fi
echo "[feature-matrix] all supported arms compile"