Installs into .claude/skills of the current project.
Sponsors
SSkills DirectorySkills Directory
Know which skills are safe — weekly.
SSkills DirectorySkills Directory
Is that skill safe to install?
Are you the author of Zig Knowledge Patch?
Add the live security badge to your README. It updates with every re-scan.
[](https://www.skillsdirectory.com/skills/nevaberry-zig-knowledge-patch)
---
name: zig-knowledge-patch
description: Zig
version: "0.17.0"
license: MIT
metadata:
author: Nevaberry
---
# Zig knowledge patch
Load this skill when migrating Zig language constructs, standard-library APIs,
build scripts, packages, or target configuration. Use this quick reference for
common changes and the topic files for detailed rules and examples.
## Reference index
| Reference | Topics |
| --- | --- |
| [Language and builtins](references/language-and-builtins.md) | Removed syntax, mixins, atomics, pointer casts, comptime checks, type identity, reflection, switches, vectors |
| [I/O, formatting, compression, and networking](references/io-format-networking.md) | Buffered interfaces, file I/O, removed wrappers, formatting, flate, HTTP, TLS |
| [Memory and containers](references/memory-and-containers.md) | Allocators, page size, intrusive lists, fixed-capacity lists, queues, maps |
| [Standard library and processes](references/stdlib-and-processes.md) | Progress, child output, ZON ownership, CRC, UTF-8, platform-specific C declarations |
| [Build, packages, and tools](references/build-packages-and-tools.md) | Packages, fingerprints, headers, artifacts, watch mode, timing, incremental builds, IDE integration, objcopy, color |
| [Targets, platform, and toolchain](references/targets-platform-toolchain.md) | Minimum OS versions, target triples, backends, frame pointers, C sanitizers, libc, linker scripts |
## Breaking changes and deprecations
### Language migration
- Delete field-level `align(...)` attributes from packed unions; the compiler
rejects them. Removing `async` and `await` also removes `@frameSize`.
- For a namespaced mixin replacing `usingnamespace`, embed a zero-bit field
such as `counter: CounterMixin(Foo) = .{}` and call `foo.counter.increment()`.
Recover the containing object with
`const parent: *Foo = @alignCast(@fieldParentPtr("counter", self));`.
- For conditionally present declarations, use a `void` fallback such as
`pub const foo = if (have_foo) 123 else {};` and check
`@TypeOf(api.foo) != void` instead of `@hasDecl`.
- Replace `@setCold(true)` with `@branchHint(.cold)` as the first statement of
the hinted function or conditional block. A comptime-dependent function hint
can pass the condition in the argument: `@branchHint(if (fallback) .cold else .none);`.
- `std.builtin.CallingConvention` is a tagged union; `.c` resolves to the current
target's default C calling convention. Replace `@setAlignStack` with a calling
convention specifying the stack alignment guaranteed by the caller, in bytes,
such as `callconv(.withStackAlign(.c, 4))`.
- Inline assembly clobbers use a struct literal with a boolean field for each
clobbered register. Run `zig fmt` to migrate legacy string clobber lists.
### Atomic fences and comptime checks
`@fence` was removed. For a sequentially consistent store/load barrier, give all
participating stores and loads `.seq_cst` order. For reference counting, use
`refs.fetchSub(1, .acq_rel)` and destroy the value when the old count is 1, or use
a `.release` decrement followed by a `.acquire` load on the last-reference path.
An operator that can cause Illegal Behavior rejects an `undefined` operand at
comptime and causes Illegal Behavior at runtime. This includes checked integer
addition such as `0 + value` when `value: u32` is undefined.
A comptime integer coerced to a float must be exactly representable. Write a
float literal such as `const approx: f32 = 123_456_789.0;` to allow rounding.
`@memcpy` requires in-memory-compatible element types even at comptime and rejects
aliasing comptime arguments. Use an element-wise loop when copying must convert values.
### Buffered I/O migration
The caller supplies the buffer for `std.Io.Reader` and `std.Io.Writer`; the
implementation sets its minimum size. `reader.takeDelimiterExclusive('\n')` can
report `error.StreamTooLong` when a line exceeds the buffer or `error.ReadFailed`
when the underlying implementation has the error details.
```zig
var adapter = old_writer.adaptToNewApi(&.{});
const writer: *std.Io.Writer = &adapter.new_interface;
try writer.print("{s}", .{"example"});
```
The new interfaces replace `std.io.GenericReader`, `GenericWriter`, `AnyReader`,
and `AnyWriter`, and incorporate the buffering formerly provided by
`BufferedReader` and `BufferedWriter`.
| Removed API or use case | Migration |
| --- | --- |
| `CountingWriter` | Use `std.Io.Writer.Discarding` and its count, `std.Io.Writer.Allocating` and its accumulated length, or `std.Io.Writer.fixed` and its `end` position, depending on where the bytes go. |
| Seeking on a raw handle or `std.io.SeekableStream` | Use `std.fs.File.Reader` and `Writer`. |
| `std.posix.sendfile` | Use `File.Reader.sendFile`. |
| `File.writeFileAll` and `File.writeFileAllUnseekable` | Use `File.Writer`. |
| `std.fifo.LinearFifo` and `std.RingBuffer` for buffered byte streams | Use `std.Io.Reader` or `std.Io.Writer`. |
`Dir.atomicFile` takes a `write_buffer` option and gives you a `File.Writer`.
`std.compress.flate.Decompress` takes an explicit container and buffer; checksum
calculation belongs to the caller. Standard-library flate compression was removed.
### Containers and allocators
- Replace `std.DoublyLinkedList(T).Node` with an embedded
`std.DoublyLinkedList.Node`; recover the containing type with
`const item: *Item = @fieldParentPtr("node", node);`.
- Replace `std.BoundedArray` with `std.ArrayList(T).initBuffer` and the `Bounded`
methods. They report capacity exhaustion without allocating, and backing
storage must outlive the list's use.
- Initialize empty unmanaged lists and hash maps with `.empty` to migrate away
from deprecated field defaults. Use `std.ArrayHashMapUnmanaged` in place of
deprecated managed `std.ArrayHashMap`, passing the allocator where needed.
Replace `popOrNull` with `pop` on containers that used the old name for optional removal.
- Initialize the renamed allocator with
`var gpa: std.heap.DebugAllocator(.{}) = .init;`, use `gpa.allocator()`, and call
`gpa.deinit()` when finished. `std.heap.smp_allocator` is a process-wide singleton.
- Custom allocator vtables take `std.mem.Alignment` instead of `u8` and must
provide `remap`. Success returns a possibly relocated pointer; `null` leaves
allocation, copying, and freeing to the caller. Keep `resize` for in-place changes.
- Replace `std.mem.page_size` with `std.heap.pageSize()` for actual page-size
calculations, `std.heap.page_size_min` for comptime pointer alignment, and
`std.heap.page_size_max` for a comptime upper bound.
### Build, package, and tool compatibility
In `build.zig.zon`, package names must be bare Zig identifiers; both name and
version are limited to 32 bytes. Keep the toolchain-generated `fingerprint`
across package releases. For a fork of a maintained upstream, remove the field
and run `zig build` to obtain a new fingerprint.
Pass a `LazyPath` to `Compile.installHeader`, `Compile.installHeadersDirectory`,
and `b.addInstallHeaderFile`. To install the compiler-emitted header, explicitly
set `install_artifact.emitted_h = artifact.getEmittedH()`.
`Step.ObjCopy` takes one section name to keep; repeated `-j` options to
`zig objcopy` keep only the last section named. Some previously supported
`zig objcopy` operations now return an `unimplemented` error.
The split of build configuration and execution into separate processes breaks
ZLS compatibility with Zig 0.17.0.
## Common interfaces and features
### Formatting and HTTP response lifetimes
Custom `format` methods receive `*std.Io.Writer` and return
`std.Io.Writer.Error!void`. For per-call state, return
`std.fmt.Alt(Context, Context.render)` with `.data` initialized to the context
and print it with `{f}`.
Use `{t}` for tag or error names, `{b64}` for standard base64, `{x}` or `{X}`
for slice hex, `{B}` or `{Bi}` for byte sizes, and `{D}` for durations. Integer
specifiers such as `{d}` dispatch to a custom type's `formatNumber` method;
alignment widths count bytes.
For an HTTP GET, use `request`, `sendBodiless`, and `receiveHead`. Read or copy
needed strings from `response.head` before calling `response.reader(buffer)`,
which invalidates them. `std.http.Server.init` takes input and output interfaces;
`std.crypto.tls.Client` also depends on I/O interfaces instead of file or network types.
### Pointer casts, constructors, and reflection
`@ptrCast` can adjust an existing slice's length for a different element size,
or infer a slice length from the byte size of a single pointed-to value.
With a known result type, `try .initCapacity(...)` can resolve a fallible
constructor declared on that type. For type metadata construction, use
`sentinel_ptr` on array and pointer descriptors and `default_value_ptr` on struct
fields; read typed optionals with `sentinel()` and `defaultValue()`.
### Build observation and incremental compilation
`zig build --webui` keeps the build process alive and exposes build steps and a
manual rebuild control. Add `--time-report` for per-step timing and compile-step
breakdowns by phase, file, and declaration.
`zig build --watch` waits 50 ms after a detected file change by default; change
the delay with `--debounce <ms>`. On macOS, watch mode works with typical editors
through the File System Events API.
Incremental compilation remains experimental. For diagnostics-only builds, use
`-fincremental -fno-emit-bin`, or `zig build --watch -fincremental -Dno-bin` when
the build script exposes `-Dno-bin`. With the ELF linker's incremental support in
Zig 0.17.0, most projects targeting `x86_64-linux` can use
`zig build -fincremental --watch` to rebuild binaries as source files change.
Run `zig build --listen=-` to serve the configured build graph to IDEs and tools.
Clients can inspect steps, configured options, and dependencies; exposed module
names are still pending. Clients can request specific steps and receive step
start and completion events with errors and generated files.
### Backends and C sanitizer configuration
Debug builds for x86-64 default to the self-hosted backend except on NetBSD,
OpenBSD, and Windows. Select LLVM with `-fllvm` or set `.use_llvm = true` on a
build compile step. LLVM's SPIR-V backend also uses `-fllvm`; the self-hosted
SPIR-V backend remains the default.
`-fsanitize-c=full` links the UBSan runtime; `-fsanitize-c=trap` emits traps and
is also available as `zig cc -fsanitize-trap=undefined`. The `sanitize_c` build
field takes `?std.zig.SanitizeC`; migrate booleans to `.full` and `.off`.
Debug C builds include the UBSan runtime by default. Override runtime linkage
with `-fubsan-rt` to include it or `-fno-ubsan-rt` to omit it.