r/Zig

LLDB is awesome and found a way to foot-gun myself with defer
▲ 34 r/Zig

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

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.

u/ChCkN007_ — 1 day ago
▲ 54 r/Zig

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

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

u/ReindeerSimilar2748 — 2 days ago
▲ 8 r/Zig

I want use ZIG (Is this good solution?)

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!

reddit.com
u/savaw2 — 2 days ago
▲ 39 r/Zig

I was surprised the LSP is able to parse this. Good job ZLS 👍

u/rilefest — 2 days ago
▲ 250 r/Zig+1 crossposts

What Zig felt like, coming from Rust

Just want to share my experiance on my first Zig project coming from Rust. Open to comments :)

besok.github.io
u/tigraboris — 4 days ago
▲ 17 r/Zig+1 crossposts

I’m writing a PS5 emulator in Zig

Hey everyone,

I’ve been working on an experimental PS5 emulator written in Zig called PS5PCEM.

It’s still very early, but some 2D games already reach actual gameplay. Native Windows launcher is also there, it can load decrypted titles, run guest code, translate RDNA2 shaders and present frames through Vulkan.

Repo:
https://github.com/iStark/PS5PCEM

I’d be grateful if anyone tests game launches on it or helps with development.

u/Cautious_Oil5563 — 4 days ago
▲ 36 r/Zig

What are some usecases of multi-item pointers

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.

reddit.com
u/thegeekywanderer — 4 days ago
▲ 80 r/Zig+1 crossposts

Why i'm building my game engine in Zig

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 :)

youtu.be
u/Pokelego11 — 5 days ago
▲ 48 r/Zig

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

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!

reddit.com
u/pbarot2009 — 5 days ago
▲ 2 r/Zig

Logs compression algorithm built in zig 0.16

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

reddit.com
u/Maleficent_Yellow141 — 5 days ago
▲ 47 r/Zig

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

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.

reddit.com
u/fredhors — 6 days ago
▲ 26 r/Zig

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?

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.

reddit.com
u/Proper_Meaning7756 — 6 days ago
▲ 1 r/Zig+1 crossposts

I built a new systems language in Rust. Meet Cyrus

My friend and I have been working on a new programming language called Cyrus, and we wrote the compiler entirely in Rust

The TL;DR: Cyrus is a strictly imperative, low-level systems language. We built it for developers who want the absolute, unfiltered control of C but crave modern ergonomics without a Garbage Collector or the strict rules of a borrow checker.

Core Features:

  • Manual Memory Control: Bring your own allocator and use defer for clean, predictable resource management.

  • Explicit Semantics: Absolutely no silent type truncation, hidden control flow, or automatic rules wrapping your decisions.

  • Bare-Metal Ready: Full support for inline assembly, pointer arithmetic, and naked functions.

  • Modern Ergonomics: Compile-time generics, strict type safety, and seamless bidirectional C interop (extern(c)).

You can check out the project and our full design philosophy on GitHub:

GITHUB REPO

We are currently working on self-hosting the compiler and would love to hear your thoughts on the syntax or the architecture

u/The_Judge26 — 6 days ago
▲ 22 r/Zig

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

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.

reddit.com
u/Terrible-Carrot-7437 — 8 days ago
▲ 69 r/Zig

Sdl2 Breakout

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!

u/BasicCheesecake8255 — 11 days ago
▲ 124 r/Zig

UDP Client & Server in Zig

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 :)

youtu.be
u/Pokelego11 — 12 days ago
▲ 47 r/Zig+1 crossposts

Fig — Universal config file parser + editor

I wanted to share a project I've been working on this summer (since May). It is like pandoc but for config files, and you can programmatically edit them too!

$ fig get config.yaml
hello: world
$ fig comment config.yaml --inline hello "this is a comment"
$ fig get config.yaml
hello: world # this is a comment
$ fig get config.yaml -o jsonc
{
  "hello": "world" // this is a comment
}
$ fig edit config.yaml hello everyone
$ fig get config.yaml -o toml
hello = "everyone" # this is a comment

This was my first Zig project, and it has grown a lot. Now it is a mature library you can use for your projects. Let me know what you think!

github.com
u/adammharris — 11 days ago