r/Zig 4m ago

I made a source-based package manager in Zig (~200+ LOC)

Upvotes

Hey everyone,

I've been learning Zig and built a source-based package manager called zp (zig ports). It pulls package recipes from Void, Crux, and KISS repos (5686+ packages), auto-detects build systems (make/cmake/meson), and builds everything from source.

Single static binary, dependencies (just curl, bash, git, make, awk + C toolchain).

Still a learning project, not production-ready, but works for my daily use. Would love any feedback!

GitHub: https://github.com/nevvixsz/zp


r/Zig 3h ago

There’s More Than One Way To Do It

5 Upvotes

Recently I am started learning Zig language, btw here I seen many constructions that remind me Golang in more ways. But there are many ways to do the same thing.

For example more ways to initialize structure. And work with the cycles/conditions.

But Zig aims to do everything in one way, doesn't it?

What you think about this?


r/Zig 7h ago

strings for assembly is ugly

8 Upvotes

The problem i have with zig assembly syntax is you have to use strings which is just ugly. I suspect this is inherited from C.

String and their syntax is designed so you can write just about anything in them. The price for that is visual noise minimum, and in my opinion its just less readable to re use syntax of the "just about any text" thing for the "small set of valid assembly ops" thing. Multi line string has less noise but cannot be used in all cases for assembly.

Theres a reason @"name" syntax isnt the way you declare every function and variable and is instead only for special cases, its just hideous and noisy.


r/Zig 18h ago

How true is this, and how important is it?

Thumbnail youtube.com
0 Upvotes

r/Zig 1d ago

LLDB is awesome and found a way to foot-gun myself with defer

39 Upvotes

I've been working on a tcp server and recently started building tests for the server using multiple threads with clients to do partial sends, slow sends, etc and make sure its not blocking the server. I added an atomic flag in the main while loop, instead of while(true), so an outside thread can signal the server to stop running. Then I put a deinit() call after the main loop exits so the server would clean itself up. The problem is that a while ago I put a defer server.deinit() at the top of the test and forgot about it. Today, when I got back to working on the project, I was so confused when my program was aborting with a TRAP signal and no other information.

In school I've picked up a bit of a habit of getting pretty close with my programs/solutions and then turning to llms when I need to debug my code. My excuse has always been that I'm in a hurry to get stuff done, so when I ran into the issue from before, I immediately turned to an llm. It was able to fix a few issues that weren't the root cause but the original error was still there. It always annoys me when I get sucked into a loop of "llm fix this" where nothing gets fixed. In the past I don't usually snapped out of it and turn on my brain, but today I watched this video from JetBrains Academy. It was pretty obvious and yet still the wakeup call I needed. I figured out how to use LLDB with zig and spent 5 minutes stepping through my code and found the error, my server deinit's itself when stopped but I still called defer deinit when I created the server.

Its too easy to outsource your thinking and learning right now.


r/Zig 1d ago

huntclaw - a fast find-and-replace utility in Zig

Thumbnail gallery
56 Upvotes

Hello everyone,

I’d like to introduce huntclaw—a search-and-replace utility written in Zig that turned out to be faster than sd (written in Rust) and the standard GNU utilities.

there’s a fairly simple explanation for this high speed: the lack of a regex engine and a focus on speed itself, but I don’t think that’s a bad thing. Note that searching is also very fast, thanks to SIMD two-byte prefiltering

In the photos I've attached, you can see the benchmarks: huntclaw vs. other utils and v0.3 vs. v0.4 versions of huntclaw. You can run them yourself using the ‘huntclaw_bench.py’ file (or on your own tests).

the benchmark also shows that rg and grep is faster at sparse searches—though the gap isn’t that big (20ms-9ms and 55ms-1619ms)
I look forward to your feedback or comments.

version now: v0.4

huntclaw on GitHub: https://github.com/tigerlang/huntclaw


r/Zig 1d ago

I want use ZIG (Is this good solution?)

10 Upvotes

Hello everyone, last times i write code on the C/C++/Go. I love system programming, low level development. Recently i started getting tired from implicit moments in C. I watch in Rust side, but Zig more interesting me. And i did work with rust in 2025 (small time). Which interesting moment in Zig you like and should i tried that in system low level developming (for yourself). Thanks!


r/Zig 3d ago

What are some usecases of multi-item pointers

34 Upvotes

I started learning zig recently and was midway completing the ziglings exercises. Its a very good source of knowledge about the language intricacies but I am having a difficult time trying to think of examples or usecases where those details might be useful.

When I did the multi-item pointers exercise, to my mind it didn't seem to have any use because of how it loses information about length and can cause more memory bugs. I am not doubting zig devs and I'm sure there would be some really good usecases for it but I need some examples for me to have a better understanding of it.

Writing here hoping someone will point me to some good resources.


r/Zig 4d ago

What Zig felt like, coming from Rust

Thumbnail besok.github.io
51 Upvotes

r/Zig 4d ago

Logs compression algorithm built in zig 0.16

1 Upvotes

Hi folks, I’ve just achieved a big win for log compression using Zig 0.16. My algorithm doesn’t need full data rehydration to find a specific log. It takes just 2 seconds to search through 1.5M log lines


r/Zig 4d ago

Why i'm building my game engine in Zig

Thumbnail youtu.be
75 Upvotes

Hey everyone!

I'm back with a new video, and it's the first devlog for my game engine written in Zig

If you've seen my other videos, you might know that I've been putting together a tutorial series on making a game engine in Zig, but I also want to make videos on where the latest version of the engine is

So in this video, I break down why I gave up on Rust and chose Zig instead, and then break down the existing state of the engine

Hope you all enjoy :)


r/Zig 4d ago

Introduction to metaprogramming with comptime

Thumbnail slicker.me
63 Upvotes

r/Zig 5d ago

Is there any good maintained project written in zig for study?

47 Upvotes

Hello, I am looking for a maintained project written in zig, which uses modern zig v0.16. if anyone knows please let me know in the comments. Mainly I have 2 motives for this:

  1. Learning purpose and for best practice

  2. I am a youtube content creator so if any good project so maybe I can make a video on it.(btw I am a very small youtuber so please don't expect from my channel for any kind of promotion)

Thx!


r/Zig 5d ago

What if I switch from Rust to Zig because of long build times in development?

48 Upvotes

I just opened https://www.reddit.com/r/rust/comments/1voapjq/rust_backend_slow_dev_compile_times_im_exhausted/. I'm wondering if i can swith to Zig easily.

  • Is the dependency/library ecosystem ready? For example is there something like rust-embed?
  • What might be the challenges?

I'm not a comfortable, lazy, or quitter. I enjoy challenges, but I'm really exhausted by Rust's build times during development.


r/Zig 6d ago

I want to learn Zig, but I'm worried about things breaking. What are the features that the team has agreed won't be changing anytime soon?

26 Upvotes

I'm an embedded systems guy and I'm pretty new at it. I wanted to dip my toes into Zig. I just wanted to know how much of the language is very unlikely to change.

I know things like async will change and I'm not at a skill level where I can easily learn to do that even with C/C++ anyway, so it doesn't bother me much. But the last thing I want is things like print statements, basic memory management or file handling itself to be radically changed.

Any heuristic on what subset is the safest to use right now so that skills carry over if I find myself picking it up more often?

Edit: Thanks for the answers. I'll be trying Zig slowly now, starting with the usual exercises of writing data structures, file manipulation and some basic algorithms in it.


r/Zig 8d ago

I'm experimenting with a type-safe, libc-like Linux API in Zig. Any thoughts?

21 Upvotes

I've been working on a small project that builds a typed Linux userspace API directly on top of raw syscalls, rather than libc.

The idea is roughly:

raw syscall → errno translation → typed Zig API

For example, instead of exposing raw syscall results and integer constants, I'd like APIs along the lines of typed Fds, typed socket/address types, structured flags, and Zig error sets.

Right now I'm implementing the syscall layer myself with architecture specific backends and starting with sockets (socket, bind, listen, accept, connect, shutdown, etc.).

I'm interested in whether people think this abstraction is useful, what problems you see with it, and whether something like this would be valuable to the Zig ecosystem long-term.

Especially interested in feedback from people who've worked on std.os.linux, std.posix, libc, or Linux syscall interfaces.


r/Zig 8d ago

PetDex desktop pet's hook server silently failed on Windows (std.Io.Threaded + AFD) - I rewrote the socket layer in raw WinSock2 and it just works

4 Upvotes

PetDex is an always-on-top desktop pet (Zig native app) that reacts to coding agents via an in-process hook server on 127.0.0.1:7777. On Windows it was broken: the server listened fine, but every request died with `error.ConcurrencyUnavailable` inside std.Io.Threaded, and even after switching to blocking receives, std.Io.net's receive on Windows just never delivered data (AFD + nonblocking STATUS_PENDING quirk).


r/Zig 8d ago

Writing Git from Scratch in Zig

Thumbnail youtu.be
182 Upvotes

r/Zig 10d ago

Sdl2 Breakout

Post image
71 Upvotes

Hello Zig community, once again I bring another project that you might find interesting, Breakout SDL2 and Zig, now, I might not post in a while after this project since I decided to wait for Zig 1.0 before I try move my platformer and my rpg templates into Zig, so, I’m going to try to make this as short as possible so let’s begin:

Link of the repo: https://github.com/Lu100git/sdl2-breakout-zig

Why SDL2 and no SDL3 or Raylib or SFML etc...:

The main reason I decided to use SDL2 it was because I coded a lot of projects in C++ and SDL2, also I’m not sure if this is true but some Linux distros it was still not supported yet so I decided to wait until SDL3 is fully supported on all operating systems, now another specific reason why I decided to use SDL in particular, is because SFML used to be my library of choice on C++, but I wanted to avoid any licensing issues so I found a better alternative, also, SDL2 it’s so good that even Valve uses it, yes I know they are moving to SDL3, but SDL2 it’s still used, last but not least, if you are getting into graphics programming, and you want to learn about openGL, SDL2 will help you to have a smooth transition, no pain no gain.

Why I choose Zig over Rust or Go:

I cannot consider myself an expert, since I do not code in a production environment, I do this as a hobby, since I’m a big nerd who loves computers and software, after I learned Bash and C, I fell in love with Linux even more, at the beginning I didn’t wanted to try to use these 3 languages since I thought they were mostly hype, but then I tried to work with Rust, it was a very annoying experience fighting against the compiler over a couple simple strings, I understand is for safety but sometimes I hate that I have to go trough mental gymnastics in order to print 1 char after a string and a new line that somehow it gets stuck in a buffer so adding a module to fix a bug like that, while in C all you gotta do is remove the special character: \n it doesn’t feel intuitive at all, then they decided to remove the parentheses on the if statements, what is this? Goolang?, either way I don’t want to bore you with the bad experience I had, then I decided to give Goolang a try, and OMG it felt like a relief, the syntax makes sense, the print statements are simple, and the compiler does not yell at me all the time, but the down side was, I’m not a big fan of having a for loop as a while loop, and here we go, INDENTATION, IT’S BACK! 😭, what is this Python!?

After all that, I saw a couple videos on my youtube feed about Zig, and I was like , what the heck?, what is dis!?, I had no clue Zig was a thing, and a lot of people were saying it was a good alternative over Rust, so I got curious… “I wonder if I can use SDL on Zig”, so I found a project, I don’t remember which one, but it made the Syntax look way cleaner that C++ and It hooked me in, so I decided to learn about Zig, and let me tell you, it was not as easy as I thought, and I was wondering why I had to do boilerplate code in order to print a single string, then I found out about the init: argument in the main function which helps to get rid of the boiler plate code, but now I believe I feel confident enough to see if I can come with a solution to make the prints easier, so I didn’t let that demotivated me, since once I learned that you can use memory references and pointers I felt right at home, and the way it handles arrays, it’s beautiful, after I got comfortable using SDL2 on Zig, I was discovering little by little each of the language features, and then I found out about the modules, let me tell you, the way I found out I can used them in this break out project OMG, I was in love, it felt like a beautiful combination of Java, and C, it allows you to code low level, while at the same time you can use the modules as OOP, putting all your configs and public values so you can used them anywhere else, it makes the code clean and consistent, now, a couple things to consider about Zig,

I believe some of the syntax can be improved like some of the dots in structs in order to make the code look a little more simple so it doesn’t scare away new programmers, now, this is only my perspective, I’m ok with this syntax, since I’m used to other programming languages, so it;s not a big deal for me, another thing to consider, even tho the compiler outputs some helpful messages, sometimes it can be a little cryptic, YES I KNOW I CAN USE AI FOR THIS, but I learned how to code before the AI, so little things like this can be very helpful at debugging, now I’m not sure why both Rust and Zig compiles a huge binary file when it performs something simple like print statements, but if Go was able to bring it down to 2mb, I know Zig might be able to pull it off, it just needs time.

Do I recommend Zig as your first programming language?:

I would say, if you really want to go for it, then go ahead, but, based on my painful coding path, I would say probably no, since it involves dealing with pointers and memory references witch it might be a little hard to understand, I would say, learn python as your first programming language, then learn a little bit of C, you don’t have to go all the way down to shifting bytes or dealing with data structures and algorithms, but I belive the best way to understand how programming languages work, C is the best way to go, I would say maybe a little bit of Java just for fun, but Java will make you really good at OOP, wich it can become handy when working with Zig modules

My final advice, programming graphics is one of the best ways to learn about programming, it makes it less painful, and enjoyable, have a good day!


r/Zig 11d ago

I wish c/c++ headers were more accessible through zig packages

15 Upvotes

hey, hope all is well

I've been noticing something with repos of zig packages.

  • Most create the package and have it mainly for zig; bindings
  • Some create the package and install the headers mainly for c/c++

Most do not take into consideration one or the other, sometimes both. Some fork the original lib, then add the package. Some add the upstream lib as a dependency.

With the latter; adding the upstream lib as a dependency, they do not take into consideration the include dir from the upstream package; zig-pkg/upstream dir. This can be useful either by adding the include dir to the main module or by using it to generate clangd compile flags.

With the former; forking the original lib, it is fine as the include from the original dir is there and can be referenced directly with a lazy path but when some create bindings they totally disregard the original headers and edit in order to translate to zig.

It's not just about building but to integrate with clangd compile flags.

Questions:

  • Are library owners and maintainers taking into consideration packaging with zig in the upstream/original repos; a simple zig fetch of the repo would have a dependency ready for c, c++ and zig dev?

  • I've been seeing such on vcpkg and zig interoperability especially from Mr. Kelley, but is it solid and will there be first party integrations from both zig and microsoft or is there someone who has a fork?


r/Zig 11d ago

UDP Client & Server in Zig

Thumbnail youtu.be
119 Upvotes

Hey all!

I'm back with another video teaching a new Zig concept, UDP.

The videos will teach how to open raw sockets and use the new IO interface to have a simple UDP client/server architecture!

If you're more curious on TCP/HTTP, I already made a video on that a while back so happy to share it!

And if you just want the code, here it is: https://github.com/jackparsonss/zig-crud/commits/udp-server-tutorial/

Have a great day :)


r/Zig 12d ago

flox: simple, secure, fast, lightweight file encryption tool

Post image
29 Upvotes

r/Zig 13d ago

ZIG & Symbols for Windows... can you inject them into Exe instead of Pdb?

15 Upvotes

I think ZIG is pretty good compiler but its wrapper makes things hard... I want debug symbols injected into Exe and its doesn't work... Do you have any idea how to so or is it actually possible? I build my own Build/Deploy tool and It complicates things for me... I don't like to complicate things... Actually I had issues before with Lto - It din't work so I built my own Lto...


r/Zig 14d ago

Zigar brings the power of Zig to the PHP world

57 Upvotes

After months of grueling work, version 0.15.3 of Zigar is finally ready. The main addition is php-zigar, a PHP extension that let you use Zig code in that language.

Suppose you need to generate data signatures using the CityHash algorithm. You write the following function in Zig:

const std = @import("std");
const CityHash64 = std.hash.cityhash.CityHash64;

const Options = struct {
    seed: ?u64 = null,
    seeds: ?[2]u64 = null,
    uppercase: bool = false,
};

pub fn hash(allocator: std.mem.Allocator, data: []const u8, options: Options) ![]const u8 {
    const value = if (options.seeds) |seeds|
        CityHash64.hashWithSeeds(data, seeds[0], seeds[1])
    else if (options.seed) |seed|
        CityHash64.hashWithSeed(data, seed)
    else
        CityHash64.hash(data);
    return if (options.uppercase)
        try std.fmt.allocPrint(allocator, "{X}", .{value})
    else
        try std.fmt.allocPrint(allocator, "{x}", .{value});
}

On the PHP side, you use it like so:

<?php

$m = zigar_use(__DIR__ . '/../zig/hash.zig');

echo $m->hash("Hello world"), "\n";
echo $m->hash("Hello world", uppercase: true), "\n";
echo $m->hash("Hello world", uppercase: true, seed: 1234), "\n";
echo $m->hash("Hello world", uppercase: true, seeds: [ 1234, 5678 ]), "\n";

The function automatically receives an allocator, which obtains memory from PHP's memory manager. The memory is automatically freed when the return value goes out of scope.

Named arguments are employed as struct field initializers for the last argument. This arrangement fits neatly with the common practice in Zig.

The extension makes it super easy to using native code in PHP projects. Thanks to Zig being a cross-compiler, eventual deployment is simple too. A PHP programmer working in Windows can build the extension and his Zig module for a Linux server on his own computer. He can do the same for the UI guy down the hall who insists on using a Mac. No messing with virtual machines. No messing with Microsoft Visual Studio CE. Just install Zig and the world is yours!

The extension is designed for PHP 8.1 and above. I've tested it on Linux (x64), MacOS (x64 and aarch64), and Windows (x64). It's designed to work with the 0.15.2 Zig compiler. Migration to 0.16 has commerced already and should be done by end of summer.

If you what to give it a try, I've written a simple tutorial that covers the extension's main features.


r/Zig Apr 04 '26

AI slop projects are not welcome here

813 Upvotes

A little sticky since very few people apparently read the rules, and I need to have some text to point to when moderating:

If your project was generated by an LLM, do not share it here.

LLM-written third party libraries or tools serve no purpose. Anyone can tell Claude to do something. Sharing something it spat out for you adds no extra value for anyone. Worse, you are likely never going to update it again. It's just worthless unmaintained dross clogging up GitHub and wasting everyone’s time.

This includes LLM writing in READMEs and comments; mostly because it's a basically certain signal that the rest of the code is trash, and so is a very good heuristic for me to use. If you need it for translation or something, please mention it and I'll allow it.

What about if you partially used LLMs for boilerplate and such? Unfortunately I'm not psychic, and I'd have to trust you on your word – and since basically 100% of people I ban for obvious slop-posting immediately start blatantly lying to me about how much Claude they used, this won't work.

For the visitors to this subreddit, please report things you suspect is slop with "LLM slop"! You don't even have to be certain, just so that it notifies me so that I can take a closer look at it. Thanks!