zig-standards
Use when writing, reviewing, testing, formatting, or configuring any Zig code (.zig files, build.zig, build.zig.zon) in a touchstone repo — exact-version-pinned compiler (Zig is pre-1.0 and moving), zig fmt, zig build/test, comptime generics, explicit allocators, error unions, cross-compilation. Invoke before adding deps, touching memory/allocators, choosing a release mode, or wiring C interop. Not for cross-cutting supply-chain (security-standards) or pipeline (ci-cd-standards) concerns.
- License 许可
- MIT
- 最近更新
- 2026-08-26
- Stars
- ★ 0
- Forks
- 0
01 前言 Front Matter
- name
- zig-standards
- license
- MIT
- metadata
- { "author": "touchstone", "version": "0.2.0" }
- description
- Use when writing, reviewing, testing, formatting, or configuring any Zig code (.zig files, build.zig, build.zig.zon) in a touchstone repo — exact-version-pinned compiler (Zig is pre-1.0 and moving), zig fmt, zig build/test, comptime generics, explicit allocators, error unions, cross-compilation. Invoke before adding deps, touching memory/allocators, choosing a release mode, or wiring C interop. Not for cross-cutting supply-chain (security-standards) or pipeline (ci-cd-standards) concerns.
03 SKILL.md 正文
Zig Standards
Full standard: standards/languages/zig.md in the touchstone repo. This skill inlines the
load-bearing rules so it stays useful even when installed standalone in ~/.claude/skills/:
Always
- Pin the exact compiler — Zig is pre-1.0; there's no rustup/nvm, the binary is the version. Commit a
.zigversion, pin it in CI, setminimum_zig_versioninbuild.zig.zon, and treat every bump as a real migration (std + build API churn each release). - Format with
zig fmt --check .(one canonical style, no config); build and test withzig build+zig build testwired as steps inbuild.zig. - Add dependencies only via
zig fetch --save(writes URL + pinned content hash intobuild.zig.zon); commitbuild.zig.zon. Never hand-edit a hash. - Generics are
comptimefunctions returningtype— no macros, no preprocessor, no hidden codegen.
Don't get burned
- Memory: library functions take an
Allocatorparam (no hidden/global allocation); pair everyalloc/createwith onefree/destroy;deferto release,errdeferto unwind on the error path. An arena for request-scoped lifetimes. - Leaks are test failures: use
std.testing.allocatorin every test that allocates; run binaries on theDebugAllocator(formerlyGeneralPurposeAllocator) in Debug/ReleaseSafe to catch leaks/double-free/use-after-free. - Errors are values (
!T): propagate withtry, handle withcatch— never a blindcatch {}orcatch unreachable; no@panic/unreachableon bad input (that's for stating invariants). - No hidden control flow: no exceptions, no destructors, no operator overloading — what you read is what runs; keep that property in your own APIs.
- Release modes are a deliberate choice: ship ReleaseSafe (checks on, near-Fast speed) unless a profiled hot path justifies ReleaseFast/Small, which disable safety checks and make overflow/OOB real UB.
- C interop crosses the safety boundary:
@cImport/zig ccgive zero-boilerplate C builds (Zig can replace Make/CMake and cross-compile C for free), but wrap C APIs in a validating Zig layer that owns lifetimes. - Cross-compilation is the default superpower:
zig build -Dtarget=…builds any target from any host with no cross-toolchain; target static*-linux-muslfor distroless containers.
Done
zig fmt --check . clean · zig build + zig build test green with no leaks (std.testing.allocator) · built on the pinned version with minimum_zig_version set · build.zig.zon committed, deps added via zig fetch --save · library funcs take an Allocator, errors propagated/handled (none dropped) · ships ReleaseSafe unless a profiled hot path says otherwise. See standards/languages/zig.md.
04 同仓库更多 Skills
ok-standards
Use when writing shell, per standards/languages/shell.md.
demo-standards
Use when editing demo code in a touchstone fixture repo, a deliberately ordinary description that is long enough to clear the forty character minimum.
demo-standards
Use when editing demo code in a touchstone fixture repo, a deliberately ordinary description that is long enough to clear the forty character minimum.
demo-standards
Use when editing demo code in a touchstone fixture repo, a deliberately ordinary description that is long enough to clear the forty character minimum.
demo-standards
Use when editing demo code in a touchstone fixture repo, a deliberately ordinary description that is long enough to clear the forty character minimum.
demo-standards
Use when editing demo code in a touchstone fixture repo, a deliberately ordinary description that is long enough to clear the forty character minimum.