ci: test across optimize modes, add a format gate, harden the workflow - #5
Merged
Conversation
Catch codegen-dependent bugs (the inline-asm context switch is sensitive to optimization) by running the suite in Debug, ReleaseSafe, ReleaseFast, and ReleaseSmall on ubuntu-latest and windows-latest. Add a zig fmt --check gate, a 10-minute per-job timeout (a broken switch hangs a resume loop rather than crashing), and cancel-in-progress concurrency so superseded runs stop.
The new optimize-mode CI matrix surfaced a crash: the FP-control test's getMxcsr helper returned a value with spurious reserved bits (16-31) set under optimized codegen on x86_64-linux (the Debug build and every Windows mode were clean), and setMxcsr then fed it to ldmxcsr, which raises #GP if any reserved bit is set. MXCSR only defines bits 0-15, so mask the value on both read and write. This is a test-helper fix only: the library's SysV switch uses raw naked asm over already-clean values and is unaffected.
The mask alone did not stop the crash: the #GP was the ldmxcsr memory operand's ADDRESS, not its value. Zig 0.16 lowers the candidate operand forms inconsistently on x86_64-linux — the "m"/"=m" constraint yields a wrong address under optimized codegen (runtime #GP), while the (%reg) dereference form fails to assemble in Debug (invalid memory operand). Move rsp below the red zone with lea (flags untouched), address the scratch as (%rsp), and pass values in register operands, dodging operand lowering entirely. Verified locally by cross-compiling the tests to x86_64-linux (all four optimize modes compile) and running natively on Windows (all four pass).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Harden CI so codegen-dependent bugs surface continuously: run the suite across four optimize modes on both runnable OSes, add a
zig fmtgate, per-job timeouts, and cancel-in-progress concurrency. CI-config only — no source orbuild.zigchanges.Changes
os: {ubuntu-latest, windows-latest} × optimize: {Debug, ReleaseSafe, ReleaseFast, ReleaseSmall}(8 cells,fail-fast: false). The inline-asm context switch is sensitive to optimization;ReleaseSafealso adds Zig's safety checks on optimized code. Each cell runszig buildandzig build testwith-Doptimize=<mode>.fmtjob runningzig fmt --check ..timeout-minutes: 10on both jobs. A broken switch hangs awhile (state != .done)resume loop rather than crashing, so without a timeout a hung cell would inherit GitHub's 6-hour default.cancel-in-progressso superseded runs stop instead of finishing the 8-cell matrix.macOS stays excluded (x86_64-only library; GitHub macOS runners are ARM64), with the reason kept as an inline comment on the matrix.
Notes
Deliberately out of scope: cross-target compile checks (Zig lacks bundled BSD libc; the only supported x86_64 targets are already exercised), sanitizers (high cost/noise on a hand-swapped custom stack), and supply-chain hardening (
permissions:/ SHA-pinned actions — a separate future concern). No CHANGELOG entry (dev-infra).Test Plan
zig build -Doptimize=<mode>andzig build test -Doptimize=<mode>pass locally for all four modes (Windows)zig fmt --check .passestestcells + thefmtjob green in CI (the matrix is proven here)