diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 010aba1af8..f521beef69 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -44,7 +44,7 @@ Local and hosted checks select only what the diff touches, so a break can reach Repository tooling tests run whole files in `just gh test`, listed explicitly in `.github/justfile`; the merge gate runs them only when a path they read changes (the `tooling` module in `sh/dispatch.sh`), and `just gate` runs them always. Slow fixtures live in separate `*.slow.test.py` files; `just gh test-integration` runs those files and selector timing nightly. -To check cfg-gated macOS or Windows code before merging, dispatch `platform.yml` on the branch; never dispatch the full Nightly. +The merge gate lints cfg-gated macOS and Windows Rust from Linux (`just rs cross-lint-changed`); to run its tests on those hosts before merging, dispatch `platform.yml` on the branch, never the full Nightly. `quest review` records each PR's risk tier, which [RISK.md](RISK.md) sets from its diff, in the body's `## Review` section. diff --git a/flake.nix b/flake.nix index bd602001bb..75856c304a 100644 --- a/flake.nix +++ b/flake.nix @@ -76,7 +76,8 @@ # string pool 4-byte aligned, which macOS 27's dyld refuses to load, so # release-profile proc macros and cdylibs are a coin flip there. The # crates still declare their own lower floors (Cargo.toml rust-version). - rust-toolchain = pkgs.rust-bin.stable."1.98.1".minimal.override { + rust-stable = pkgs.rust-bin.stable."1.98.1".minimal; + rust-toolchain = rust-stable.override { # `minimal` rather than `default`, which adds 740 MB of offline HTML # docs to a closure every CI job downloads. extensions = [ @@ -634,6 +635,17 @@ # the dev shell, which every CI job downloads. rust-nightly = pkgs.rust-bin.nightly."2026-10-18".minimal; + # The gate's `just rs cross-lint` runs clippy for the macOS and Windows + # targets from Linux with it: the dev shell's compiler plus those + # targets' std, kept out of the dev shell, which every CI job downloads. + rust-cross = rust-stable.override { + extensions = [ "clippy" ]; + targets = [ + "aarch64-apple-darwin" + "x86_64-pc-windows-msvc" + ]; + }; + # `nix develop .#obs`: the default shell plus obs-studio, which linking # the plugin on Linux needs (`just obs build`, `just obs ci`). Kept out # of the default shell because it pulls in ~3 GB (CEF, mostly) that diff --git a/quest/m0/ci/platform-cross-lint.md b/quest/m0/ci/platform-cross-lint.md deleted file mode 100644 index a3ad9f646d..0000000000 --- a/quest/m0/ci/platform-cross-lint.md +++ /dev/null @@ -1,56 +0,0 @@ -# [M] The merge gate lints macOS and Windows code from Linux - -## Goal - -`just ci`, which the merge queue runs on its Linux runner, runs clippy on the -changed Rust crates and their dependents for macOS and Windows targets, so a -platform-gated compile error or unfulfilled lint expectation fails the queue -instead of the nightly macOS and Windows lanes after it lands. Tests stay on -Linux, and real macOS and Windows runners stay out of the gate. - -## Plan - -From moq-dev/quest's 2026-11-18 mistake audit -([moq-dev/quest#786](https://github.com/moq-dev/quest/pull/786)): 10 runtime -escapes came from Linux-only behavior or platform-gated code that only the -nightly lanes, or no lane, exercised. Six of them were `just check` failures -on macOS, fixed by [moq-dev/moq#8538](https://github.com/moq-dev/moq/pull/8538). -Two of those were unfulfilled `#[expect]`s that only a macOS build saw, one of -them a clippy lint. - -Decided 2026-11-19 (maintainer): - -- ✅ A cheap cross-target check from Linux in the merge gate (rejected: real - macOS and Windows runners in the gate; drop). The pick of - [moq-dev/quest#786](https://github.com/moq-dev/quest/pull/786). -- ✅ clippy, not `cargo check` (rejected: `cargo check`). Unfulfilled clippy - expectations are part of the class, and clippy costs about what check does. - Scope is not part of that choice. It stays: changed crates plus dependents. - -Recommended: - -- Reuse `sh/rs/select.sh`'s `platform` selection and flags (moq-gst excluded, - the cli's device features on). Today it runs `cargo check` on native hosts - through `just rs windows`/`macos`. The gate's run lints with - `--target` instead. -- Targets: `aarch64-apple-darwin`, and `x86_64-pc-windows-msvc`, the target - `release-binary.yml` ships. The [code audit](/quest/m3/audit-code.md) already - ran clippy for macOS and `x86_64-pc-windows-gnu` from Linux with a - rust-overlay toolchain and `zig cc` for build scripts. Use the gnu target - only if msvc's SDK cannot come from Nix, and say why in the PR. -- A crate whose build script cannot cross-build fails loud. If it must be - left out, exclude it by name with the reason beside the exclusion, as - moq-gst is today; the nightly native lanes still cover it. -- Measure what it adds to a queue run, both a typical diff and a moq-net - edit. Put the measurements in the PR, as the [CI epic](/quest/m0/ci/README.md) - asks of a change that slows the gate. -- Show it catching a known break, such as reverting one of #8538's - `#[expect]` fixes. -- Once it gates, delete the code audit's step that runs the cross-target - clippy by hand. Also update `CONTRIBUTING.md`'s advice to dispatch - `platform.yml` for cfg-gated code, which then only needs dispatching to - run tests. - -## Related - -- [Code audit](/quest/m3/audit-code.md) - runs the same cross-target clippy by hand today diff --git a/quest/m3/audit-code.md b/quest/m3/audit-code.md index 336e0dc3bb..252b699577 100644 --- a/quest/m3/audit-code.md +++ b/quest/m3/audit-code.md @@ -69,13 +69,10 @@ lints [moq-dev/moq#6576](https://github.com/moq-dev/moq/pull/6576). ### Check first: lints - Already gated, so skip: `clippy::allow_attributes_without_reason`, - unfulfilled `expect`s, Biome's unused `biome-ignore`, ruff's `RUF100`, and + unfulfilled `expect`s (on Linux, macOS, and Windows), Biome's unused `biome-ignore`, ruff's `RUF100`, and pyright's unnecessary `type: ignore` in the Python wrapper. Review what those can't see. Generated and vendored bindings keep their blanket allows; `shellcheck disable` is out of scope. -- CI lints Linux only, so run clippy for `aarch64-apple-darwin` and - `x86_64-pc-windows-gnu` from Linux with a rust-overlay toolchain and - `zig cc` for build scripts. That found every stale suppression last run. - Swift: read the nightly macOS job's Swift step for warnings. TypeScript: run typescript-eslint's `no-deprecated` once it supports the pinned TypeScript, and consider joining CI. The CARLA sim's pyright needs the diff --git a/rs/justfile b/rs/justfile index 29177ac0d6..bc7606aa29 100644 --- a/rs/justfile +++ b/rs/justfile @@ -90,6 +90,11 @@ lint-changed $LIST: check-test-changed $LIST: sh/rs/select.sh check-test "$LIST" +# Clippy for macOS and Windows from this host, on the crates in a changed-file +# list (or `--all`) plus their dependents; the gate runs it on every Rust diff. +cross-lint-changed $LIST: + sh/rs/select.sh cross "$LIST" + # Like `fix`, but only the crates in a changed-file list plus their dependents. fix-changed $LIST: sh/rs/select.sh fix "$LIST" diff --git a/rs/moq-video/src/encode/backend/mod.rs b/rs/moq-video/src/encode/backend/mod.rs index ff1ca642bf..84fe0055e0 100644 --- a/rs/moq-video/src/encode/backend/mod.rs +++ b/rs/moq-video/src/encode/backend/mod.rs @@ -571,6 +571,13 @@ pub(crate) mod test_util { /// The mean bitrate after the first second, once rate control has settled. pub mean: u64, /// The most any one second carried after the first. + #[cfg_attr( + all( + feature = "openh264", + not(any(apple, all(target_os = "linux", any(feature = "nvidia", feature = "vaapi")))) + ), + expect(dead_code, reason = "only the hardware encoders' tests bound the peak") + )] pub peak: u64, } diff --git a/sh/dispatch-query.test.py b/sh/dispatch-query.test.py index be68200e5d..c99ccdfb3d 100644 --- a/sh/dispatch-query.test.py +++ b/sh/dispatch-query.test.py @@ -282,6 +282,7 @@ def stub_ci(self, just=""): "uniffi_bindgen_dart", "uv", "xml2rfc", + "zig", ): path = self.bin / tool path.write_text("#!/bin/sh\nexit 0\n") @@ -753,8 +754,19 @@ def test_ci_runs_one_lint_preamble_and_one_test_pass(self): def test_rust_lane_runs_only_the_lint_and_the_test_build(self): self.change("rs/kio/src/clock/mod.rs") calls = [call.split()[1] for call in self.run_ci() if call.startswith("rs ")] + # rs_cross is a lane of its own, so its call can land anywhere. + self.assertEqual(calls.count("cross-lint-changed"), 1) + calls.remove("cross-lint-changed") self.assertEqual(calls, ["lint-changed", "test-changed"]) + def test_the_cross_lint_follows_its_flake_pinned_toolchain(self): + for path, expected in (("flake.lock", True), ("flake.nix", True), ("js/net/src/index.ts", False)): + with self.subTest(path=path): + self.change(path) + calls = self.run_ci() + (self.repo / path).unlink() + self.assertEqual(any(call.startswith("rs cross-lint-changed ") for call in calls), expected) + def test_tooling_tests_follow_what_they_read(self): for path, expected in ( ("sh/rs/select.sh", True), @@ -799,8 +811,12 @@ def test_module_filter_splits_the_gate(self): with self.subTest(filter=filter): self.env["CHECK_MODULES"] = filter calls = self.run_ci("--all") - # cargo_nix is a module of its own that runs a recipe of rs/justfile. - rs = [call for call in calls if call.startswith("rs ") and not call.startswith("rs cargo-nix")] + # cargo_nix and rs_cross are modules of their own that run recipes of rs/justfile. + rs = [ + call + for call in calls + if call.startswith("rs ") and not call.startswith(("rs cargo-nix", "rs cross-lint-changed")) + ] self.assertEqual(rs, expected) # Every other module runs in the job that does not name one. self.assertEqual("gh check" in calls, filter.startswith("-")) diff --git a/sh/dispatch.sh b/sh/dispatch.sh index 218bd9444a..07eb2c6f25 100755 --- a/sh/dispatch.sh +++ b/sh/dispatch.sh @@ -119,6 +119,12 @@ module py '^(py/|sh/py/|pyproject\.toml$|uv\.lock$|rs/moq-ffi/|rs/uniffi-bindgen # doc samples. module rs '^(\.cargo/|nix/modules/moq-relay\.nix$|doc/lib/c/|doc/lib/samples\.sh$|sh/local\.(sh|ts)$|rs/|test/interop/clients/rust/|sh/rs/|Cargo\.(toml|lock)$|clippy\.toml$|rust-toolchain\.toml$|\.config/nextest\.toml$)' \ tools='cargo jq cc' compiles='check fix' fix +# Clippy for macOS and Windows over rs's selection, so a platform-gated error +# fails here rather than in the nightly native lanes. The flake pins its +# toolchain and the zig that compiles its build scripts' C, so a change there +# lints the whole workspace (see sh/rs/select.sh). +module rs_cross "${scope[rs]%)}|flake\.(nix|lock)$)" \ + tools='cargo jq nix zig' compiles=check # nix/Cargo.nix records each crate's dependencies, features, and targets, # read from the manifests, the lockfile, and the files cargo discovers targets # from. The pinned crate2nix comes from flake.lock. @@ -430,6 +436,7 @@ step() { # The check keeps docs and the isolated default-media lint; the test # phase enforces the other clippy checks in its existing build. check:rs) run just rs lint-changed "$rs_list" ;; + check:rs_cross) run just rs cross-lint-changed "$rs_list" ;; check:carla_bridge) run just carla bridge-check ;; check:bench) run python3 bench/compare.test.py diff --git a/sh/rs/cross-lint.sh b/sh/rs/cross-lint.sh new file mode 100755 index 0000000000..a30f59dd10 --- /dev/null +++ b/sh/rs/cross-lint.sh @@ -0,0 +1,33 @@ +#!/usr/bin/env bash +# Run clippy for macOS and Windows from any host, so a platform-gated compile +# error or unfulfilled lint expectation fails the gate rather than the nightly +# native lanes. The selection comes from `sh/rs/select.sh cross`; the targets +# are the Mac runner's and the one release-binary.yml ships for Windows. +# +# Usage: sh/rs/cross-lint.sh CARGO_ARGS... +set -euo pipefail + +cd "$(git rev-parse --show-toplevel)" + +targets=(aarch64-apple-darwin x86_64-pc-windows-msvc) + +# The dev shell's compiler plus those targets' std, pinned in flake.nix. +sysroot=$(nix build --no-link --print-out-paths .#rust-cross) +export PATH="$sysroot/bin:$PATH" +# Put the Cargo shim `mbx setup` installs back in front, as the dev shell +# does, so the build stays cached. +mbx_shim=$( (mbx setup --status 2>/dev/null || true) | sed -n '1s/.*: //p') +if [[ -x "$mbx_shim" ]]; then + PATH="${mbx_shim%/*}:$PATH" +fi +export RUSTC="$sysroot/bin/rustc" + +# A build script's C and C++ for a foreign target go through zig, which +# carries every target's libc headers. +for target in "${targets[@]}"; do + var=${target//-/_} + export "CC_$var=$PWD/sh/rs/zig-cc.sh" "CXX_$var=$PWD/sh/rs/zig-c++.sh" "AR_$var=$PWD/sh/rs/zig-ar.sh" +done + +# Both targets in one build share its host build scripts and proc macros. +cargo clippy --locked "${targets[@]/#/--target=}" --all-targets "$@" -- -D warnings diff --git a/sh/rs/select.sh b/sh/rs/select.sh index b06d1bce6f..4cd3fb7031 100755 --- a/sh/rs/select.sh +++ b/sh/rs/select.sh @@ -1,14 +1,15 @@ #!/usr/bin/env bash # Run `just rs check|check-test|lint|fix|test` on the crates a diff touches, -# plus their dependents. `platform` is the Windows and macOS compile. +# plus their dependents. `platform` is the Windows and macOS compile on those +# hosts, and `cross` lints for both from any host. # -# Usage: sh/rs/select.sh check|check-test|lint|fix|test|platform|uring LISTFILE|--all +# Usage: sh/rs/select.sh check|check-test|lint|fix|test|platform|cross|uring LISTFILE|--all # # LISTFILE holds the changed paths, one per line. `--all` is the whole # workspace, as is a change to anything every crate is built or tested by. set -euo pipefail -usage="usage: sh/rs/select.sh check|check-test|lint|fix|test|platform|uring LISTFILE|--all" +usage="usage: sh/rs/select.sh check|check-test|lint|fix|test|platform|cross|uring LISTFILE|--all" action=${1:?$usage} list=${2:?$usage} @@ -20,7 +21,12 @@ select_packages() { echo ALL return fi - if [[ "$list" == --all ]] || grep -qE '^(\.cargo/.*|sh/local\.(sh|ts)|Cargo\.(toml|lock)|clippy\.toml|rust-toolchain\.toml|rs/justfile|sh/rs/(select|platform|nextest)\.sh|\.config/nextest\.toml)$' "$list"; then + # The flake pins the cross toolchain and zig. + if [[ "$action" == cross && -f "$list" ]] && grep -qE '^flake\.(nix|lock)$' "$list"; then + echo ALL + return + fi + if [[ "$list" == --all ]] || grep -qE '^(\.cargo/.*|sh/local\.(sh|ts)|Cargo\.(toml|lock)|clippy\.toml|rust-toolchain\.toml|rs/justfile|sh/rs/(select|platform|cross-lint|zig-(cc|c\+\+|ar)|nextest)\.sh|\.config/nextest\.toml)$' "$list"; then echo ALL return fi @@ -232,10 +238,15 @@ case "$action" in if ((${#features[@]})); then flags+=(--features "${features[*]}"); fi just rs test "${flags[@]}" ${timings[@]+"${timings[@]}"} ;; - platform) - # moq-gst links GStreamer via pkg-config, which the runners don't have. + platform | cross) + # moq-gst links GStreamer via pkg-config, which neither the runners nor + # a cross build have. if [[ "$packages" == ALL ]]; then flags+=(--exclude moq-gst) + # libFuzzer's C++ includes a Linux header zig's macOS libc lacks, + # and fuzzing runs only on Linux. A diff's selection never holds a + # `*-fuzz` crate. + [[ "$action" != cross ]] || flags+=(--exclude moq-auth-fuzz --exclude qmux-fuzz) else flags=() for id in $packages; do @@ -253,7 +264,11 @@ case "$action" in # outside the selection; a change to anything they reach selects # moq-cli anyway. if wants moq-cli; then flags+=(--features "moq-cli/play moq-cli/capture moq-cli/pipewire moq-cli/pulseaudio"); fi - cargo check --locked "${flags[@]}" --all-targets + if [[ "$action" == cross ]]; then + sh/rs/cross-lint.sh "${flags[@]}" + else + cargo check --locked "${flags[@]}" --all-targets + fi ;; *) echo "$usage" >&2 diff --git a/sh/rs/zig-ar.sh b/sh/rs/zig-ar.sh new file mode 100755 index 0000000000..51ee0cff68 --- /dev/null +++ b/sh/rs/zig-ar.sh @@ -0,0 +1,3 @@ +#!/usr/bin/env bash +# sh/rs/zig-cc.sh's archiver, the AR sh/rs/cross-lint.sh hands to build scripts. +ZIG_CC_MODE="ar" exec "$(dirname "$0")/zig-cc.sh" "$@" diff --git a/sh/rs/zig-c++.sh b/sh/rs/zig-c++.sh new file mode 100755 index 0000000000..e23ad62b46 --- /dev/null +++ b/sh/rs/zig-c++.sh @@ -0,0 +1,3 @@ +#!/usr/bin/env bash +# sh/rs/zig-cc.sh for C++, the CXX sh/rs/cross-lint.sh hands to build scripts. +ZIG_CC_MODE=c++ exec "$(dirname "$0")/zig-cc.sh" "$@" diff --git a/sh/rs/zig-cc.sh b/sh/rs/zig-cc.sh new file mode 100755 index 0000000000..fe89ae2eef --- /dev/null +++ b/sh/rs/zig-cc.sh @@ -0,0 +1,45 @@ +#!/usr/bin/env bash +# The C compiler sh/rs/cross-lint.sh hands to a build script for a macOS or +# Windows target; sh/rs/zig-c++.sh and sh/rs/zig-ar.sh are its C++ compiler and +# archiver. zig carries the libc headers of every target it supports, so no +# Apple or Windows SDK is needed. cc-rs adds the target as Apple's or LLVM's +# flags, which zig rejects in favour of its own, taken here from the TARGET +# Cargo gives the build script. +set -euo pipefail + +mode=${ZIG_CC_MODE:-cc} + +case "${TARGET:?Cargo sets TARGET for a build script}" in + aarch64-apple-darwin) target=aarch64-macos ;; + # MinGW's headers stand in for the MSVC SDK, which no free package + # carries. A lint links nothing, so the objects' ABI never matters. + # cc-rs archives for MSVC with lib.exe's arguments. + x86_64-pc-windows-msvc) + target=x86_64-windows-gnu + [[ "$mode" != ar ]] || mode=lib + ;; + *) + echo "zig-cc: no zig target for $TARGET" >&2 + exit 1 + ;; +esac + +case "$mode" in + ar | lib) exec zig "$mode" "$@" ;; +esac + +args=() +skip= +for arg; do + if [[ -n "$skip" ]]; then + skip= + continue + fi + case "$arg" in + -arch) skip=1 ;; + -mmacosx-version-min=* | --target=*) ;; + *) args+=("$arg") ;; + esac +done + +exec zig "$mode" -target "$target" ${args[@]+"${args[@]}"}