Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 0 additions & 15 deletions quest/m0/ci/c-fixtures-gate.md

This file was deleted.

7 changes: 4 additions & 3 deletions rs/justfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 4 additions & 3 deletions sh/dispatch.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
53 changes: 39 additions & 14 deletions sh/rs/c-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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/<triple>/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/<triple>/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

Expand Down Expand Up @@ -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"
Expand Down
4 changes: 4 additions & 0 deletions sh/rs/select.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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("/");
Expand Down Expand Up @@ -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
;;
Expand Down
20 changes: 19 additions & 1 deletion sh/rs/select.test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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):
Expand Down