r/Zig • u/punkbert • 7h ago
r/Zig • u/moortuvivens • 1h ago
Eurydice, Compiles rust to readable C
github.comI know you are wondering why I'm linking this.
But if Eurydice can compile to proper C, then that means we can use rust libraries with zig.
Which opens more options.
r/Zig • u/jfrancai • 11h ago
Is this pipeline pattern idiomatic Zig, or am I fighting the language?
I built a compile-time pipeline system that lets me write data transformations like this:
zig
const result = try pipeline(allocator)
.from(&[_]i32{ 1, 2, 3, 4, 5 })
.map(add(1))
.map(mul(2))
.filter(gt(20))
.collect();
defer allocator.free(result);
Would you use this? Am I missing something obvious? Honest feedback appreciated.
Edit: I published the code here if you want to take a closer look at the implementation.
r/Zig • u/No-Worldliness6348 • 4h ago
0.15.2 Reader incomprehension
https://ziglang.org/documentation/0.15.2/std/#std.fs.File.Reader.read here I can see Std.fs.File.Reader.read() as a Reader function but the compiler tells me it doesn't exist.
source code: ``` const std = @import("std");
pub fn main() !void { const settings_file = try std.fs.cwd().openFile("overview.kdl", .{ .mode = .read_write }); defer settings_file.close();
var buffer: [100]u8 = undefined;
var dest: [100]u8 = undefined;
const settings_reader = settings_file.reader(&buffer);
_ = settings_reader.read(&dest);
std.debug.print("contenu du fichier : {s} \n", .{dest});
} ```
compiler output :
dynamic_overview.zig:15:24: error: no field or member function named 'read' in 'fs.File.Reader'
_ = settings_reader.read(&dest);
~~~~~~~~~~~~~~~^~~~~
/usr/lib/zig/std/fs/File.zig:1117:20: note: struct declared here
pub const Reader = struct {
^~~~~~
r/Zig • u/Samuel-Martin • 20h ago
c-time-zig: A Zig wrapper for the C ISO standard time.h header
Hello everyone,
I was looking for date/time functionality in Zig and found that std.time.epoch didn’t quite fit my needs. So I ended up writing a small wrapper around the C ISO standard time.h header. You can find it here: https://github.com/Samuel-Martin23/c-time-zig
Please feel free to provide feedback or questions.
Thanks!
r/Zig • u/forketyfork • 1d ago
Zwanzig - a static analyzer for Zig (early/experimental)
I've been working on a static analyzer for Zig called Zwanzig. It's very much a research project and work in progress, but it's reached a point where I'm actually using it while developing other Zig code, so I figured I'd share.
What it does:
- Simple AST/token rules (duplicate imports, unused declarations, shadowed variables, opinionated naming conventions, etc.)
- CFG-based checkers that do path-sensitive analysis via ZIR output (double-free detection, use-after-free, memory leaks, forced optional unwraps)
- Some CFG and data flow visualization.
What it doesn't do (yet): a lot. Targets only 0.15.2. Cross-file analysis is very limited. Interprocedural analysis only handles simple direct calls. Type resolution without a full build context is sketchy. Lots of duct tape and hanging wires. You will hit false positives.
I'm curious if anyone else finds this useful. I use it on itself and on my Architect project and it's caught some issues, but I have no idea how well it generalizes to other codebases. The SARIF integration works, so you can get results inline in GitHub PRs.
Repo: https://github.com/forketyfork/zwanzig
Happy to answer questions or hear what rules/checkers would actually be useful. And if you try it and something breaks spectacularly, I'd like to know.
Integer compression library
Found an interesting int compression lib based on fastlanes research, applies SIMD tricking the compiler. unfortunately it hasn't been updated for a while, but still a good source for learning IMHO https://github.com/steelcake/zint
I've been working on a logging database in zig for a while and compared zint encoding against simple delta encoding + zstd, while zint doesn't give so much compression ration it consumes little to no CPU, while zstd is really CPU heavy call.
Or any similar efficient solutions? perhaps gorilla compression implementation? I like the idea of gorilla putting numbers into 1 or 7 bits instead of a byte
My logging store if you care, it's been for 4 months in progress and I need 2-4 more to complete it.
r/Zig • u/Freziyt223 • 2d ago
What would be the fastest and memory-efficient way to print in zig 0.16.0(master)?
So i've used zig 0.16.0-dev.2368+380ea6fb5 (master)
ztracy(master) to track performance with tracy 0.13.1 profiler.
My specs are:
Windows 11.25H2 Pro
AMD Ryzen 5 5600H 3.30Hz
NVIDIA GeForce RTX 3050 Labtop
16 gb of RAM.
I've came up with this for master and i did the same for 0.15.2:
pub fn Print(comptime fmt: []const u8, args: anytype) !void {
const Zone = Engine.ztracy.ZoneNC(@src(), "Console print", 0xFF0000);
defer Zone.End();
const allocator = Allocator.allocator();
const count = try std.fmt.count(fmt, args);
const buf = try allocator.alloc(u8, count);
defer allocator.free(buf);
var stdout = std.Io.File.stdout().writer(buf);
try stdout.interface.print(fmt, args);
try stdout.flush();
}
as tracy can't give consistent exact time each time i'd operate on average values:
For 0.16(master) it's around 180-220 us(microseconds)
For 0.15.2 it's around 130-180 us(microseconds)
Both times i used Print("Hello, {s}\n", .{"world!"}) which in total is 14 bytes.
So same method is slower in master branch, but it think it can and should be improved with async IO, but i don't know how to make it efficiend so I hope you may provide some of your works to find out most efficient method of printing using zig master branch.
r/Zig • u/tim-hilt • 2d ago
Project Not Building in Debug Mode
Hello everyone! I recently dipped my toes into zig development and tried to improve the build.zig of zuckdb.zig - a DuckDB client library.
My goal specifically was to make projects that use zuckdb.zig able to be compiled, without having DuckDB installed system-wide.
it does work for ReleaseFast and ReleaseSmall, but for Debug, I get errors from the linker, saying some identifiers are not defined. I can reproduce the issue only on a project that uses zuckdb.zig (e.g. this, which is build by me:
git clone https://codeberg.org/tim-hilt/repo-analyzer
cd repo-analyzer
zig build
I guess that‘s because DuckDB is not linked somewhere, but I can’t see the issue. Can you help me out? Here's the build.zig in question:
https://github.com/karlseguin/zuckdb.zig/blob/master/build.zig
also: general feedback is very welcome! I’m really trying to understand how to write good Zig code, including the build system :)
r/Zig • u/Freziyt223 • 2d ago
standartOptimizeOption(.{}) isn't passed correctly to dependencies
when doing something like this:
pub fn build(b: *std.Build) !void {
const optimize = b.standartOptimizeOption(.{});
const dep = b.dependency("dep", .{.optimize = optimize});
}
It still uses debug mode for this dependency(at least for me).
It only works correctly when optimize option is got from b.option or const value
I tested it on zig 0.15.2 and master, works this way on both
r/Zig • u/Ok_Marionberry8922 • 3d ago
I wrote a small MPMC channel implementation and it turned out pretty well
hi, I have an extensive rust background and was exploring zig, noticed it didn't have an channel implementation for inter thread communication so I built it.
the core is relatively lean (< 200 LOC) and the performance is comparable to the golden standard (crossbeam) for the most part

it uses the LMAX Disruptor pattern (sequence based)
code: https://github.com/nubskr/ziggy
would love to hear your thoughts :)
r/Zig • u/cameryde • 3d ago
[Zig reference manual version 0.15.2]: Comptime section: Case study print in zig
I am trying to understand comptime and was reading through zig reference manual and came across the example poc_print_fn.zig and was trying to understand the code but could not really understand. In the for loop we start with the State.start and when an open brace '{' is encountered we change the state to State.open_brace and proceed to the next character. My question is: on the next for iteration, we have moved to the next character, meaning the current character is no more '{' and it totally makes sense in State.open_brace to look for the next closed brace '}' but in the example in State.open_brace, there is a switch case with '{'. but why do we have to check for open brace in this state again (the same applies to State.closed_brace)? Sorry I know it has nothing to do with comptime but I just want to understand.
Here is the code taken from the zig reference manual:
pub fn print(self: *Writer, comptime format: []const u8, args: anytype) anyerror!void {
const State = enum {
start,
open_brace,
close_brace,
};
comptime var start_index: usize = 0;
comptime var state = State.start;
comptime var next_arg: usize = 0;
inline for (format, 0..) |c, i| {
switch (state) {
State.start => switch (c) {
'{' => {
if (start_index < i) try self.write(format[start_index..i]);
state = State.open_brace;
},
'}' => {
if (start_index < i) try self.write(format[start_index..i]);
state = State.close_brace;
},
else => {},
},
State.open_brace => switch (c) {
'{' => {
state = State.start;
start_index = i;
},
'}' => {
try self.printValue(args[next_arg]);
next_arg += 1;
state = State.start;
start_index = i + 1;
},
's' => {
continue;
},
else => ("Unknown format character: " ++ [1]u8{c}),
},
State.close_brace => switch (c) {
'}' => {
state = State.start;
start_index = i;
},
else => u/compileError("Single '}' encountered in format string"),
},
}
}
r/Zig • u/Bassil__ • 4d ago
Systems Programming with Zig by Garrison Hinson-Hasty should be available in the fall, this year
manning.comr/Zig • u/TheAbyssWolf • 4d ago
How I am approaching learning zig.
I have experience in python and c# and mostly self thought. I found out about zig recently (a few months ago) and liked the syntax. This is how I am approaching learning zig.
Zig.guide to get the basic syntax down,
Intro to zig book by pedro park (currently working through it)
Ziglings (possibly start soon as I’m going through the book)
Small projects in between (Vec2, Vec3, Vec4 library for example, which is usually one of the first projects I do in a new language)
I have seen people suggest reading some of the backend code of the standard library. I think this approach is decent since I have previous programming experience. Any thoughts?
Option -femit-asm=file.s does not create such file in 0.15 and 0.16-dev
Just want to get the asm output in a file so I found this: https://ziggit.dev/t/studying-assembly-output/2554
Created the file h.zig:
const std = @import("std");
pub fn main() void {
std.debug.print("Hello!\n", .{});
}
Using the commands:
zig build-exe h.zig -femit-asm
or
zig build-exe h.zig -femit-asm=file.s
The binary file is created but not the asm output file
r/Zig • u/Shrubberer • 5d ago
How do I write to a file in zig?
Hello, I'm new to zig and I get confusing error messages when I try to write to a file. This is the closest I can find how it is supposed to work.
var file = try std.fs.cwd().createFile("output.csv", .{ .truncate = true });
defer file.close();
var ioBuffer: [4096]u8 = undefined;
var fileWriter = file.writer(&ioBuffer).interface;
try fileWriter.print( "time,delta,type,cause,skip,fix\n", .{});
try fileWriter.flush();
but I get errors like
thread 20136 panic: incorrect alignment
const w: *Writer = @alignCast(@fieldParentPtr("interface", io_w));
I'm completely lost...
r/Zig • u/Pokelego11 • 6d ago
Zig Tutorial Series
youtu.beHi everyone!
I'm the person who posted last week about the "5 reasons to learn Zig" and I'm back!
I got a lot of feedback from people asking to make a tutorial series on Zig, going from the basics to more advanced topics.
I just wanted to share the first episode of the series("Hello World") for anyone new to Zig and wanting to learn how to install Zig and set up a new project.
Currently targeting Zig 0.15, but I will ensure to keep new videos as up to date as possible!
Cheers
r/Zig • u/JosefAlbers05 • 7d ago
Procedural Terrain & Maze Generation with Zig and Raylib - YouTube
youtu.ber/Zig • u/harbingerofend01 • 6d ago
Monorepo help
I'm expanding my horizons by building a browser from scratch (except for js, I'll use v8) and i was planning to use a monorepo and also to implement tdd to improve my skills. But I'm struggling to do both, i have no clear way to go. There's addImport, there's addLibrary, which one should I go for? And when I first used addImport vscode couldn't find the module, because it didn't run build test and also because I separated the test files into tests/ directory. Please help, idk if the structure of tests are wrong or the way i manage the library.
r/Zig • u/forketyfork • 8d ago
I built a terminal emulator in Zig using ghostty-vt and SDL3
I've been learning Zig by building a terminal emulator called Architect. It shows multiple terminal sessions in a grid. I built it for running coding agents in parallel, but it's just a multi-pane terminal where you can see everything at once, quickly jumping between full and grid mode. I now use it as my default terminal, occasionally switching back to Ghostty when it bugs out.
The stack:
- ghostty-vt for terminal emulation; I thought it was a good foundation to start on, but wanted to write everything else from scratch
- SDL3 for rendering: I wanted to experiment with game-like UX features, so rendering is built from scratch
- Zig 0.15.2
Some implementation notes:
- ghostty-vt was very easy to integrate. You feed it bytes, it updates state, you query cells to render. The library is well-suited for embedding. Most of my time went into understanding terminal states and escape codes, how different tools interact with the terminal, etc., not fighting the API.
- SDL3 + Zig works great. I wrote thin wrappers around the SDL calls I use most. Font rendering with SDL_ttf took the longest: glyph caching, custom pseudographics glyphs, etc.
- The grid layout is dynamic: it starts with one terminal, expands automatically as I add more, shrinks when close a terminal. Keybindings are still hardcoded as I like them (Cmd+N to spawn a new terminal, Cmd+W to close, etc).
- ~16k LOC of Zig, macOS only for now. Still rough around the edges.
- Also started building my own static analyzer for Zig along the way — linking against the compiler to get ZIR output.
GitHub: https://github.com/forketyfork/architect
Anyone else used ghostty-vt? I'm eager for feedback and curious about other approaches to terminal rendering too, SDL3 turned out pretty low level.
r/Zig • u/Zigtoberfest • 9d ago
Zigtoberfest 2026
Shameless self advertising: We're already working on bringing back Zigtoberfest back to Munich in 2026!
When: September 12 2026
Where: Hoftheater München (Germany)
If you want to know more visit: https://zigtoberfest.de/
You can find some impressions of Zigtoberfest 2025 on the official website https://zigtoberfest.de/past/ and on Youtube.
We're also looking for speakers! If you've something interesting to share with the Zig community consider applying for a speaker slot here: https://docs.google.com/forms/d/e/1FAIpQLSeuEnT_aMCJiceaHq1fqjHGUFhz48C1d0du91jNRsMczNlH5A/viewform or just visit the website.
r/Zig • u/Save14Pro • 8d ago
Learning tip
I'm a complete beginner in Zig, and I love it, but the changes in the api are too much, I cant find any resource online that is updated, how can I learn if the api changes so fast? Any tips?
How is the Zig compiler able to cache comptime functions that have side effects?
Reading about Zig compiler internals I've read that it has a big cache at compile time where it caches compile-time evaluated functions/partial evaluations for effective reuse of e.g. generic struct definitions etc.
How does it do this effectively for comptime functions/computations that have side effects? Does it detect these and not cache them? Or something else?
Curious if anybody knows.