Skip to content

Commit f070737

Browse files
committed
Run CI's Linux clippy in the train preflight, cross-checked with zig
A Linux-only lint or compile error was found only by a CI train, about ten minutes per round; the module-wiring landing took four. The preflight now runs clippy -D warnings for x86_64-unknown-linux-gnu over the crates CI lints, read from tests.yml, using zig as the C cross-compiler for ring's build script (through two small shims). The llama worker stays CI-only because its CMake build cannot be cross-built this way. Without zig or the rust target it is a notice. Proved both ways: a Linux-only dead function refuses the preflight while macOS clippy stays green, and a clean tree passes in about 50 s. Also drop the macOS block's lock-restore machinery and stale siblings.lock comments: dependencies are exact crates.io pins now, so it runs --locked.
1 parent e088d79 commit f070737

3 files changed

Lines changed: 56 additions & 31 deletions

File tree

‎scripts/lib/zig-ar.sh‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/bin/sh
2+
# Archiver paired with zig-cc-linux.sh: cc-rs runs AR as a single program
3+
# path, so "zig ar" needs a wrapper of its own.
4+
exec zig ar "$@"

‎scripts/lib/zig-cc-linux.sh‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/bin/sh
2+
# C compiler shim for checking the Linux target from a Mac (see the Linux
3+
# clippy block in scripts/train-push.local.sh). Crates with C build scripts
4+
# (ring) call the target's C compiler through cc-rs, which passes
5+
# --target=x86_64-unknown-linux-gnu. zig cannot parse the "unknown" vendor
6+
# field and fails, so drop that flag and name zig's own spelling of the target.
7+
for arg do
8+
shift
9+
case "$arg" in --target=*) continue ;; esac
10+
set -- "$@" "$arg"
11+
done
12+
exec zig cc -target x86_64-linux-gnu "$@"

‎scripts/train-push.local.sh‎

Lines changed: 40 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -21,41 +21,50 @@ if [ "$(uname -s)" = "Darwin" ]; then
2121
if [ -d /Applications/Xcode.app ]; then
2222
export DEVELOPER_DIR="${DEVELOPER_DIR:-/Applications/Xcode.app/Contents/Developer}"
2323
fi
24-
# These two commands rewrite Cargo.lock as a side effect, because the sibling
25-
# path dependencies (../subconscious, ../commons) are other agents' working
26-
# checkouts and routinely sit ahead of siblings.lock. That rewrite dirties the
27-
# tree, and the NEXT train then refuses on a change this script made itself.
28-
#
29-
# --locked does not solve it: it refuses to run at all whenever a sibling has
30-
# moved, which here is most of the time, and those checkouts are not ours to
31-
# roll back. CI is unaffected either way because it checks the siblings out at
32-
# the pinned commits. So verify against whatever is on disk, then put the lock
33-
# back exactly as it was — and leave a deliberate lock edit alone.
34-
lock_was_clean=no
35-
git diff --quiet -- Cargo.lock 2>/dev/null && lock_was_clean=yes
36-
restore_lock() {
37-
if [ "$lock_was_clean" = yes ]; then
38-
git checkout -- Cargo.lock 2>/dev/null || true
39-
fi
40-
}
24+
# --locked: the subc and commons crates are exact crates.io pins in the root
25+
# Cargo.toml (no sibling path checkouts), so a Cargo.lock that would need
26+
# rewriting means the committed lock is wrong, which is worth refusing.
27+
# shellcheck disable=SC2086
28+
cargo clippy --locked $mac_crates --all-targets -- -D warnings \
29+
|| refuse "macOS-only crates failed clippy (CI cannot run these; see scripts/train-push.local.sh)"
30+
cargo test --locked -p synapse-engine-owned --lib \
31+
|| refuse "synapse-engine-owned lib tests failed (CI cannot run these)"
32+
fi
33+
34+
# Linux clippy, run here because otherwise a Linux-only failure (code behind
35+
# cfg(not(target_os = "macos")), or test helpers left dead when their callers
36+
# are macOS-only) is found only by a CI train about ten minutes later. It
37+
# checks the crates CI lints, read from tests.yml so the two lists cannot
38+
# drift. ring's build script needs a Linux C compiler, which zig provides
39+
# through the scripts/lib/zig-*.sh shims. Without zig or the rust target this is
40+
# a notice, not a refusal: CI still gates the train.
41+
linux_target=x86_64-unknown-linux-gnu
42+
if command -v zig >/dev/null 2>&1 && rustup target list --installed 2>/dev/null | grep -qx "$linux_target"; then
43+
ci_crates="$(sed -n 's/^ *SYNAPSE_CRATES: *//p' .github/workflows/tests.yml | head -1)"
44+
[ -n "$ci_crates" ] || refuse "could not read SYNAPSE_CRATES from .github/workflows/tests.yml for the Linux clippy check"
45+
# The llama worker's build script compiles llama.cpp through CMake, which
46+
# zig cannot cross-build from here; that one crate stays CI-only.
47+
ci_crates="$(printf '%s\n' "$ci_crates" | sed 's/-p synapse-worker-llama//')"
4148
# shellcheck disable=SC2086
42-
cargo clippy $mac_crates --all-targets -- -D warnings \
43-
|| { restore_lock; refuse "macOS-only crates failed clippy (CI cannot run these; see scripts/train-push.local.sh)"; }
44-
cargo test -p synapse-engine-owned --lib \
45-
|| { restore_lock; refuse "synapse-engine-owned lib tests failed (CI cannot run these)"; }
46-
restore_lock
49+
CC_x86_64_unknown_linux_gnu="$PWD/scripts/lib/zig-cc-linux.sh" \
50+
AR_x86_64_unknown_linux_gnu="$PWD/scripts/lib/zig-ar.sh" \
51+
cargo clippy --locked --target "$linux_target" $ci_crates --all-targets -- -D warnings \
52+
|| refuse "Linux-target clippy failed (the same check CI's linux job runs; see scripts/train-push.local.sh)"
53+
else
54+
say "NOTICE: skipping the Linux clippy preflight (needs zig and 'rustup target add $linux_target'); CI will be the first Linux check"
4755
fi
4856

49-
# The daily cron on tests.yml is this repository's only sample of "same sha,
50-
# siblings at their tips" (pushes build against siblings.lock, so a lock wave
51-
# that breaks the tips is invisible to them). Its result reaches nobody unless
52-
# something reads it, and three seats found multi-day red streaks this way
53-
# (fleet notices #486, #487, #490). Read it here, where every landing passes.
57+
# The daily cron on tests.yml is this repository's only scheduled sample of
58+
# master against the current toolchain and runner images, which a push-only
59+
# CI never sees change. Its result reaches nobody unless something reads it:
60+
# a red scheduled run raises no alert, and repositories in this fleet have sat
61+
# red for days before anyone looked. Read it here, where every landing passes.
5462
# NOTICES, not refusals: a scheduled red is about what already landed, and the
55-
# push in front of you may be its fix. --event schedule is filtered server-side,
56-
# so a push flood cannot empty the window (#489). The 48 h age bound is above
57-
# GitHub's routine queue lag (a cron landing five hours late is healthy) and
58-
# catches the case a green last run hides: a cron that fired, then stopped.
63+
# push in front of you may be its fix. --event schedule is filtered
64+
# server-side, so a burst of push runs cannot crowd the last scheduled run out
65+
# of the list. The 48 h age bound is above GitHub's routine queue lag (a cron
66+
# landing five hours late is healthy) and catches the case a green last run
67+
# hides: a cron that fired, then stopped.
5968
if command -v gh >/dev/null 2>&1; then
6069
sched="$(gh run list --event schedule --limit 1 --json conclusion,createdAt,headSha \
6170
--jq '.[] | "\(.conclusion) \(.createdAt[0:16]) \(.headSha[0:8])"' 2>/dev/null || true)"

0 commit comments

Comments
 (0)