A practical how-to for patching Zig’s standard library so you can fix bugs and experiment without vendoring the entire std. It starts with a concrete problem: Zig 0.17.0’s std.http.Client.connectUnix is broken and a simple Docker-unix-socket client triggers the compile error. Rather than duplicating std (which risks UB if internals change), the technique is to copy std into a local git repo, implement the small fix (the example is a ~60-line change), emit a git diff patch, and use the zig-patch package in build.zig to apply that patch at build time. The patched std is imported under the name std for the build, zig-patch caches patched outputs, and you remove the big vendored copy while still getting an immediate fix that will be removed once the fix ships upstream.
The writeup also covers composing multiple patches and a specific patch, zig-staticio, that exposes std.Options.io_vtable so the Io vtable becomes a comptime choice. That turns indirect vtable calls into direct calls, dramatically shrinking binaries (example: 145 KB → 31 KB) and enabling a custom minimal Io implementation. Building with a custom MyIo surfaces missing functions at compile time, forcing correct implementations for only the reachable operations and avoiding runtime surprises. The workflow thus gives stable-release users a safe, auditable, and incremental way to apply and share small std fixes and optimizations.
Summary generated by AI from the linked article. hn.today is not affiliated with Hacker News or Y Combinator.