diff --git a/.config/nextest.toml b/.config/nextest.toml index 49d5913fe55..88350511582 100644 --- a/.config/nextest.toml +++ b/.config/nextest.toml @@ -19,8 +19,8 @@ slow-timeout = { period = "30s", terminate-after = 2 } # race until proven otherwise (see Root Cause First in AGENTS.md). retries = 0 -# PR recipes build library, binary, and integration-test targets. Nightly keeps -# the exhaustive target compile, but executes benches through cargo bench smokes. +# The PR gate compiles benches to lint them, but never runs them here; Nightly +# executes them through cargo bench smokes. default-filter = "not kind(bench)" # Limit ring concurrency within one invocation. Unit-test workers use small diff --git a/rs/justfile b/rs/justfile index 8fafe882020..f75b16a56c0 100644 --- a/rs/justfile +++ b/rs/justfile @@ -293,9 +293,11 @@ media-features *args: # nextest kills a wedged test (`.config/nextest.toml` sets the timeout), but # skips doctests; `just rs doctest` covers those. clippy-driver as the workspace # wrapper enforces lint findings from the same compile. `--tests` builds library, -# binary, and integration-test targets, including binary-only crates; benches and -# examples compile and lint in Nightly's `features`. `build.warnings` denies -# warnings without changing cargo's artifact fingerprint, unlike RUSTFLAGS. +# binary, and integration-test targets, including binary-only crates. The gate +# (sh/rs/select.sh's `test`) adds `--benches --examples` and the features those +# targets require, so their lints fail the PR rather than Nightly; nextest's +# default filter leaves the benches unrun. `build.warnings` denies warnings +# without changing cargo's artifact fingerprint, unlike RUSTFLAGS. # Run library, binary, and integration tests, enforcing clippy from the same compile. [positional-arguments] diff --git a/rs/moq-pattern/benches/matching.rs b/rs/moq-pattern/benches/matching.rs index 2b2f605bb39..5677acf620d 100644 --- a/rs/moq-pattern/benches/matching.rs +++ b/rs/moq-pattern/benches/matching.rs @@ -151,8 +151,8 @@ const MAX_MESSAGE: usize = u16::MAX as usize; /// A QUIC varint's size, as `AUTH_OK` writes counts and lengths. fn varint(value: usize) -> usize { match value { - ..64 => 1, - ..16384 => 2, + 0..64 => 1, + 64..16384 => 2, _ => 4, } } diff --git a/sh/rs/select.sh b/sh/rs/select.sh index 1d50728277c..94b6f26aa41 100755 --- a/sh/rs/select.sh +++ b/sh/rs/select.sh @@ -50,8 +50,8 @@ select_packages() { local seeds benches edges selected # A crate's `benches/` builds only its own bench targets, which no other crate can - # depend on and the test build never compiles, so it selects that crate alone - # (for its lint) rather than every dependent's tests. + # depend on, so it selects that crate alone (for its lint) rather than every + # dependent's tests. benches=$(sed -n 's|^rs/\([^/]*\)/benches/.*|\1|p' "$list") # A target can also sit outside its crate, as moq-cli's interop examples # under test/interop/clients/rust/ do, so a change in the directory of a @@ -176,6 +176,9 @@ case "$action" in # A selection can hold nothing testable, and # nextest exits 4 on that; the whole workspace finding none really is wrong. [[ "$packages" == ALL ]] || flags+=(--no-tests=pass) + # Benches and examples join the build only to be linted; nextest's + # default filter leaves the benches unrun. + flags+=(--benches --examples) # CI keeps Cargo's per-crate build timings, which check.yml uploads. timings=() [[ "${GITHUB_ACTIONS:-}" != true ]] || timings=(--timings) @@ -184,8 +187,11 @@ case "$action" in # features only add code, so every test still runs. Cargo rejects a # feature of a package outside the selection, hence the explicit picks. features=() + # The crates the build holds, for their targets' features below. + building=$names if wants '(moq-video|moq-audio)'; then [[ "$packages" == ALL ]] || flags+=(--package moq-video --package moq-audio) + building+=" moq-video moq-audio" features+=(moq-video/capture moq-audio/capture moq-audio/playback) fi if wants moq-cli; then features+=(moq-cli/play moq-cli/openh264); fi @@ -194,6 +200,26 @@ case "$action" in # The relay's io_uring listener, Linux-only. A moq-uring change selects # the relay too, as its dependent. if [[ "$(uname -s)" == Linux ]] && wants moq-relay; then features+=(moq-relay/io-uring); fi + # Cargo skips a bench or example whose `required-features` are off without + # a word, and a bench-only change selects its crate alone, so no dependent + # turns them on. Turn on every one the built crates' targets name. All of + # them are additive and build wherever the gate runs; moq-uring's targets + # compile to nothing off Linux. + required=$( + set -e + cargo metadata --locked --format-version 1 --no-deps | jq -r --arg names "$building" --arg all "$packages" ' + ($names | split(" ") | map(select(. != ""))) as $want + | .packages[] + | select(if $all == "ALL" then (.name | endswith("-fuzz") | not) else (.name as $n | $want | index($n) != null) end) + | .name as $name + | .targets[] + | select(.kind // [] | any(. == "bench" or . == "example")) + | (.["required-features"] // [])[] + | "\($name)/\(.)"' | sort -u | tr '\n' ' ' + ) + for feature in $required; do + [[ " ${features[*]-} " == *" $feature "* ]] || features+=("$feature") + done if ((${#features[@]})); then flags+=(--features "${features[*]}"); fi just rs test "${flags[@]}" ${timings[@]+"${timings[@]}"} ;; diff --git a/sh/rs/select.test.py b/sh/rs/select.test.py index 3d7e59ee5f6..b0a3bf0311d 100644 --- a/sh/rs/select.test.py +++ b/sh/rs/select.test.py @@ -15,6 +15,29 @@ LINUX = os.uname().sysname == "Linux" +def target_features(): + """Every bench and example `required-features`, as `crate/feature`, for the workspace.""" + metadata = json.loads( + subprocess.run( + ["cargo", "metadata", "--locked", "--format-version", "1", "--no-deps"], + cwd=ROOT, + check=True, + capture_output=True, + text=True, + ).stdout + ) + return sorted( + { + f"{package['name']}/{feature}" + for package in metadata["packages"] + if not package["name"].endswith("-fuzz") + for target in package["targets"] + if {"bench", "example"} & set(target["kind"]) + for feature in target.get("required-features", []) + } + ) + + def dispatch_scope(): """The rs module's impact pattern, as sh/dispatch.sh registers it.""" return re.search(r"^module rs '([^']*)'", (ROOT / "sh/dispatch.sh").read_text(), re.M).group(1) @@ -50,11 +73,12 @@ def selected(self, *paths, action="lint", github_actions=False): return calls.read_text().splitlines() if calls.exists() else [] def test_nextest_launcher_selects_workspace(self): + features = [*DEVICE_FEATURES.split(), "moq-tokio/webrtc", *(["moq-relay/io-uring"] if LINUX else [])] + features += [feature for feature in target_features() if feature not in features] for github_actions in (False, True): for action in ("check", "check-test", "lint", "test"): with self.subTest(action=action, github_actions=github_actions): - suffix = f" --features {DEVICE_FEATURES} moq-tokio/webrtc" if action == "test" else "" - suffix += " moq-relay/io-uring" if LINUX and action == "test" else "" + suffix = f" --benches --examples --features {' '.join(features)}" if action == "test" else "" suffix += " --timings" if github_actions and action == "test" else "" self.assertIn( f"rs {action} --workspace {FUZZ_EXCLUDES}{suffix}", @@ -117,7 +141,8 @@ def test_device_features_join_the_one_test_build(self): with self.subTest(path=path): calls = self.selected(path, action="test") self.assertEqual(len(calls), 1, calls) - self.assertTrue(calls[0].endswith(f" --features {features}"), calls) + # The targets' required features follow the device ones. + self.assertIn(f" --features {features}", calls[0]) # moq-tokio's WebRTC module is off by default too. calls = self.selected("rs/moq-tokio/src/webrtc.rs", action="test") self.assertEqual(len(calls), 1, calls) @@ -195,6 +220,20 @@ def test_a_bench_selects_only_its_crate(self): calls = self.selected(bench, "rs/moq-stats/src/lib.rs", action="test") self.assertTrue(any("/rs/moq-relay#" in call for call in calls), calls) + def test_a_bench_alone_enables_its_required_features(self): + # Alone in the selection, no dependent turns these on, and cargo would + # skip the targets without a word. + for bench, feature in ( + ("rs/moq-stats/benches/producer_tick.rs", "moq-stats/bench"), + ("rs/moq-net/benches/codec.rs", "moq-net/fuzz"), + ("rs/moq-relay/benches/session.rs", "moq-relay/test-support"), + ("rs/moq-quic/benches/wire.rs", "moq-quic/fuzz"), + ): + with self.subTest(bench=bench): + (call,) = [call for call in self.selected(bench, action="test") if call.startswith("rs test ")] + self.assertIn(" --benches --examples ", call) + self.assertIn(feature, call.split(" --features ", 1)[1].split()) + class MetadataTest(unittest.TestCase): def setUp(self): @@ -263,7 +302,10 @@ def test_valid_metadata_selects_dependents_without_errors(self): self.assertEqual(result.stderr, "") self.assertEqual( self.calls.read_text().splitlines(), - ["rs test --package path+file:///rs/dependent#1.0.0 --package path+file:///rs/seed#1.0.0 --no-tests=pass"], + [ + "rs test --package path+file:///rs/dependent#1.0.0 --package path+file:///rs/seed#1.0.0" + " --no-tests=pass --benches --examples" + ], ) def test_malformed_metadata_stops_before_running_tests(self):