diff --git a/quest/m0/ci/c-fixtures-gate.md b/quest/m0/ci/c-fixtures-gate.md deleted file mode 100644 index 23d5d215ff8..00000000000 --- a/quest/m0/ci/c-fixtures-gate.md +++ /dev/null @@ -1,15 +0,0 @@ -# [XS] The merge gate compiles the C fixtures against the generated header - -## Goal - -A PR that changes a libmoq C function's signature fails the merge gate if any `rs/libmoq/c-tests/*.c` still calls the old shape, instead of the break first showing up in Nightly. - -## Plan - -Found by the 11-17 Nightly triage: [moq-dev/moq#8999](https://github.com/moq-dev/moq/pull/8999) merged 3 minutes after [moq-dev/moq#8996](https://github.com/moq-dev/moq/pull/8996) added `moq_consume_catalog`'s `delay_us` argument, and `abort-unwanted.c` kept the 3-argument call until [moq-dev/moq#8941](https://github.com/moq-dev/moq/pull/8941). Nothing in the gate compiles those files. - -Recommended: `cc -fsyntax-only` each fixture against the generated header in the gate, about a second. `test/smoke/clients/c/subscribe.c` builds against the published package on purpose, so it stays out. - -The Swift break the same night (`SmokeTests.swift`, [moq-dev/moq#8906](https://github.com/moq-dev/moq/pull/8906) merging after [moq-dev/moq#8948](https://github.com/moq-dev/moq/pull/8948)) stays nightly-only: Swift doesn't build on Linux runners. - -Public API: none. Wire: none. diff --git a/rs/justfile b/rs/justfile index da3b4a090de..29177ac0d6f 100644 --- a/rs/justfile +++ b/rs/justfile @@ -235,9 +235,10 @@ audit: # Outside nextest because the staticlib link alone outlasts its hang budget. -# Compile and run libmoq's C fixtures, and the C doc samples, against libmoq.a. Must run on Unix. -c-tests: - sh/rs/c-tests.sh +# Compile and run libmoq's C fixtures, and the C doc samples, against libmoq.a; `--syntax` only compiles them against moq.h. Must run on Unix. +[positional-arguments] +c-tests *args: + sh/rs/c-tests.sh "$@" # The workspace-hack would supply third-party features a crate forgets to # declare, so CI runs this after `cargo hakari disable && cargo update diff --git a/sh/dispatch.sh b/sh/dispatch.sh index 637af46c8a5..54ff92cc636 100755 --- a/sh/dispatch.sh +++ b/sh/dispatch.sh @@ -115,9 +115,10 @@ module py '^(py/|sh/py/|pyproject\.toml$|uv\.lock$|rs/moq-ffi/|rs/uniffi-bindgen # sh/rs/select.sh widens to the whole workspace for inputs every crate shares. # moq-cli builds the Rust interop clients as examples from outside its # crate; sh/rs/select.test.py fails when a target's directory is missing. -# moq-relay's tests read its NixOS module. -module rs '^(\.cargo/|nix/modules/moq-relay\.nix$|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' compiles='check fix' fix +# moq-relay's tests read its NixOS module, and libmoq's lint compiles the C +# 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 # 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. diff --git a/sh/rs/c-tests.sh b/sh/rs/c-tests.sh index 4aae24e28dc..118b78e680f 100755 --- a/sh/rs/c-tests.sh +++ b/sh/rs/c-tests.sh @@ -4,8 +4,22 @@ # against the generated `moq.h`, plus the native libraries from # `rs/libmoq/native-libs` that cargo can't inject into a link it doesn't drive. # Unix only. +# +# `--syntax` only compiles the fixtures and doc samples against the header, +# with no staticlib, link, or run: the merge gate's second-long check that a +# libmoq signature change updated every caller. set -euo pipefail +syntax= +case "${1:-}" in + "") ;; + --syntax) syntax=1 ;; + *) + echo "usage: sh/rs/c-tests.sh [--syntax]" >&2 + exit 2 + ;; +esac + if [[ "${GITHUB_ACTIONS:-}" != true && "${LOCAL_SUPERVISED:-}" != 1 ]]; then exec bash "$(dirname "$0")/../local.sh" bash "$0" "$@" fi @@ -18,25 +32,29 @@ if ! command -v "$cc" >/dev/null; then exit 1 fi -cargo build --locked -p libmoq --features openh264 - -# Ask cargo where it put the staticlib and the header rather than assuming -# target/debug: CARGO_TARGET_DIR and a configured build target -# (`target//debug`) both move them, and guessing wrong would link a -# stale copy or nothing. Replays the build above from cache, so it costs a -# process, not a compile. -log=$(cargo build --locked -p libmoq --features openh264 --message-format=json) -lib=$(jq -r 'select(.reason == "compiler-artifact") | .filenames[] | select(endswith("/libmoq.a"))' <<<"$log" | tail -1) -if [ -z "$lib" ]; then - echo "cargo reported no libmoq.a for libmoq" >&2 - exit 1 +if [ -n "$syntax" ]; then + # `cargo check` runs build.rs, which writes the header, without codegen. + log=$(cargo check --locked -p libmoq --message-format=json) +else + cargo build --locked -p libmoq --features openh264 + # Ask cargo where it put the staticlib and the header rather than assuming + # target/debug: CARGO_TARGET_DIR and a configured build target + # (`target//debug`) both move them, and guessing wrong would link a + # stale copy or nothing. Replays the build above from cache, so it costs a + # process, not a compile. + log=$(cargo build --locked -p libmoq --features openh264 --message-format=json) + lib=$(jq -r 'select(.reason == "compiler-artifact") | .filenames[] | select(endswith("/libmoq.a"))' <<<"$log" | tail -1) + if [ -z "$lib" ]; then + echo "cargo reported no libmoq.a for libmoq" >&2 + exit 1 + fi + profile=$(dirname "$lib") fi -profile=$(dirname "$lib") # rs/libmoq/build.rs writes the header into its OUT_DIR. out_dir=$(jq -r 'select(.reason == "build-script-executed") | select(.package_id | test("/libmoq#")) | .out_dir' <<<"$log" | tail -1) include="$out_dir/include" if [ -z "$out_dir" ] || [ ! -f "$include/moq.h" ]; then - echo "$include/moq.h missing after 'cargo build --locked -p libmoq --features openh264'" >&2 + echo "cargo reported no generated moq.h for libmoq" >&2 exit 1 fi @@ -70,6 +88,13 @@ grep -oE '\b(moq|MOQ)_[A-Za-z0-9_]*' doc/lib/c/index.md | grep -v '_$' | sort -u fi done +if [ -n "$syntax" ]; then + for source in rs/libmoq/c-tests/*.c; do + "$cc" -fsyntax-only -Werror=implicit-function-declaration -I"$include" "$source" + done + exit 0 +fi + for source in rs/libmoq/c-tests/*.c; do bin="$out/$(basename "$source" .c)" "$cc" "$source" -I"$include" -L"$profile" -lmoq "${libs[@]}" -o "$bin" diff --git a/sh/rs/select.sh b/sh/rs/select.sh index a07f5ae95c8..7b34f7564cb 100755 --- a/sh/rs/select.sh +++ b/sh/rs/select.sh @@ -64,6 +64,8 @@ select_packages() { sed -n 's|^nix/modules/moq-relay\.nix$|moq-relay|p' "$list" # The gate's Send-depth proof of moq-net's session driver is this script. sed -n 's|^sh/rs/send-depth\.sh$|moq-net|p' "$list" + # The gate compiles the C fixtures and doc samples against libmoq's header. + sed -nE 's#^(sh/rs/c-tests\.sh|doc/lib/c/.*|doc/lib/samples\.sh)$#libmoq#p' "$list" jq -r --rawfile list "$list" ' def resolve: gsub("\\\\"; "/") | reduce split("/")[] as $s ([]; if $s == ".." then .[:-1] elif $s == "." then . else . + [$s] end) | join("/"); @@ -174,6 +176,8 @@ case "$action" in if wants moq-net; then just rs no-async; fi # The session driver's Send proof, which a deeper session state breaks. if [[ "$action" == lint ]] && wants moq-net; then just rs send-depth; fi + # Every C caller still matches libmoq's generated header. + if [[ "$action" == lint ]] && wants libmoq; then just rs c-tests --syntax; fi # moq-cli's media tasks are behind `play`; only check-test runs tests. if [[ "$action" == check-test ]] && wants moq-cli; then just rs play; fi ;; diff --git a/sh/rs/select.test.py b/sh/rs/select.test.py index 94a8e94f9fc..a519b938c22 100644 --- a/sh/rs/select.test.py +++ b/sh/rs/select.test.py @@ -126,7 +126,7 @@ def test_gate_proves_send_depth_for_net(self): # moq-net and its dependencies can deepen the session driver's Send proof. for path in ("rs/moq-net/src/lib.rs", "rs/kio/src/lib.rs", "Cargo.lock"): with self.subTest(path=path): - calls = self.selected(path) + calls = [call for call in self.selected(path) if call != "rs c-tests --syntax"] self.assertEqual(len(calls), 4, calls) self.assertTrue(calls[0].startswith("rs lint "), calls) self.assertEqual(calls[1], "rs media-defaults", calls) @@ -138,6 +138,24 @@ def test_gate_proves_send_depth_for_net(self): self.assertNotIn("rs send-depth", self.selected("rs/moq-net/src/lib.rs", action="test")) self.assertNotIn("rs send-depth", self.selected("rs/moq-auth/src/lib.rs")) + def test_gate_compiles_c_callers_against_libmoq(self): + # libmoq, a crate its header reaches, and the C callers' own inputs. + for path in ( + "rs/libmoq/src/lib.rs", + "rs/libmoq/c-tests/abort-unwanted.c", + "rs/moq-net/src/lib.rs", + "sh/rs/c-tests.sh", + "doc/lib/c/index.md", + "doc/lib/samples.sh", + "Cargo.lock", + ): + with self.subTest(path=path): + self.assertRegex(path, dispatch_scope()) + self.assertEqual(self.selected(path).count("rs c-tests --syntax"), 1) + # Only the lint phase runs it, and only for libmoq. + self.assertNotIn("rs c-tests --syntax", self.selected("rs/libmoq/src/lib.rs", action="test")) + self.assertNotIn("rs c-tests --syntax", self.selected("rs/moq-auth/src/lib.rs")) + def test_media_defaults_are_isolated_from_device_features(self): for path in ("rs/moq-audio/src/lib.rs", "rs/moq-video/src/lib.rs", "Cargo.lock"): for github_actions in (False, True):