r/Zig

zlob 1.6.0 - now with parallel gitignore based file walker
▲ 16 r/Zig

zlob 1.6.0 - now with parallel gitignore based file walker

I have released zlob 1.6.0 - it used to be a globbing library but now it also exposes the internal file walker. How is it better than std one?

- It includes gitignore parsing (so it doesn't list the files are ignored via .gitignore/.ignore)

- it uses platform specific apis to batch load the files and metadata (getdents64, getattrslistbulk, ntdll apis)

- it allows you to include custom white list include logic

- it allows you to request only the metadata you need (for statx/getattrslistblk on mac)

- it outputs the collected ignore rules for potential reuse

- depens on platform and amount of files 2-10x faster than ignore crate in rust

repo https://github.com/dmtrKovalenko/zlob

u/Qunit-Essential — 7 hours ago
▲ 127 r/Zig

The new Io interface makes me wanna quit Zig

I've started learning Zig just recently.
I have some background in C, so after reading and watching plenty of materials, Zig seemed like a natural transition. And this was true to a large extent, at least when it comes to syntax, most concepts made sense right away and I liked the language more and more as I learned it. I was walking over Ziglings, but got bored after finishing about a half and decided to just build something as it works better for my brain.
So I chose a small terminal text editor as a first project which felt like a good fit for Zig. The start was nice, I already started getting used to everything a struct, try statements, etc. But the moment I got to the io part, my excitement started to evaporate quickly.
Something as simple as reading from stdin is unreasoanbly hard. At first it looks like I just need a reader, so I declare one. But it turns out a reader does not expose any methods to actually read? It took me a while to figure out that it's interface is what I need:

var stdin_reader = Io.File.stdin().reader(init.io, &buf);
var stdin = &stdin_reader.interface;

I was thinking about just using std.c or std.posix everywhere, but then what's the point of using Zig?
Now I need to read from a file. I found some example on how to read from cwd, but I need to read from an arbitrary path. What do I do? I don't know. The documentation is almost non-existent. Google search doesn't help that much either.
I thought maybe I explore some codebases, so I cloned ghostty and tigerbettle, but both use earlier Zig versions with the old primitives. I can't imagine how expensive will it be to upgrade for those guys if starting a new project from scratch is that hard.
Can someone share your experience with the new Io interface? Am I the only one who struggles with it?

reddit.com
u/olzhas89 — 1 day ago
▲ 58 r/Zig

New open addressing hash table algorithm #2

Reference in GitHub. Contains Zig code.

I have been working on some interesting stuff and out of necessity had to extend my earlier work with incremental resizing to significantly reduce memory waste. The end result is a novel algorithm that the literature has not seen before. I trust that many of you will find the unique properties of the hash table interesting but useless in practice - it has a very specific use case.

The new thing is extending it with an open addressing variant of Linear Hashing. Linear hashing is a technique which enables incremental adjustments to the capacity of the hash table. It enables each individual insert() to also grow the hash table by a little and for each remove() to also shrink the hash table by a little. This means:

  • No O(table_size) grow/resize/shrink operations.
  • Ability to maintain the target load factor at ALL times - not just resize at some max load factor.
  • Significantly reduced tail latency for all operations.

The combined algorithm is now starting to be full of subtle invariants to maintain. I provide a "simplified" reference implementation of it which limits itself to the essence of the algorithm. I won't bother explaining the new algorithm in detail because it's too hard. Read the code and play around with it.

Hoping that many of you find this interesting. Happy 250th birthday USA!

▲ 38 r/Zig

How to import from C now?

Sorry to ask such a basic question but I'm genuinely not go on another journey to narnia to figure out where A.K hid `@cImport` and `@cInclude`.

(For the 'Just ask A.I' fan club, A.I is epistemologically stuck on the pre `std.process.init` zig for whatever reason. Also thought to ask this just incase anybody else was confused and searching too)

Please and thanks🙏 (0.17 dev version just incase that was needed)

reddit.com
u/Majestic_Poetry_1139 — 3 days ago
▲ 35 r/Zig

Looking for feedback on my project: Zentropy

I've been building Zentropy, a Redis alternative written in Zig. The goal is to create a lightweight, high-performance in-memory data store with a simple architecture.

It's still in development, and I'd love feedback from the Zig community:

Does the idea sound interesting?

What features would you expect from a Redis alternative?

Any suggestions on architecture, networking, or persistence?

Are there any Zig-specific patterns or libraries I should look into?

I've put some early code online for anyone curious enough to dig around and take a look. Any feedback, criticism, or ideas are welcome.

https://github.com/mailmug/zentropy

Thanks!

u/Reasonable-Pass9841 — 3 days ago
▲ 31 r/Zig

I turned my small Zig ls-like CLI into a reusable package

A while ago I shared zlist here — a small ls-like CLI I’ve been building while learning Zig.

At the time, a few people mentioned that the file listing/parsing logic might be useful outside of the CLI. That made a lot of sense, so I spent some time splitting the core logic out from the rendering layer.

zlist v0.1.1 is now usable as a standalone Zig package:

zig fetch --save git+https://github.com/here-Leslie-Lau/zlist

Then from another Zig project:

const zlist = @import("zlist");

More usage: https://github.com/here-Leslie-Lau/zlist/blob/main/docs/using-as-a-module.md

The idea is that the core package only gives you the listing data. It does not decide how things should be printed. The zl CLI still handles the terminal output, colors, icons, layout, etc.

It’s still early, and I’m not claiming this is some perfect library. This is mostly a learning project that slowly became a little more fun than I expected. But I’d really appreciate feedback on the package API, ownership rules, and whether the split between core/listing logic and CLI rendering feels reasonable.

Repo: https://github.com/here-Leslie-Lau/zlist

Thanks again for the earlier feedback — it really helped. My earlier post: https://www.reddit.com/r/Zig/comments/1shdvij/i_wrote_a_small_ls_alternative_in_zig/

u/here-Leslie-Lau — 4 days ago
▲ 619 r/Zig+1 crossposts

Finally finished a level for my game

I finally finished designing, decorating and scripting a single level for my vehicular puzzle/exploration game, Traction Point. Now I just need to do it 6-8 more times :D Quite happy with how this one turned out though. Custom engine, C++/Zig hybrid. 99% solo developed.

If you want to know more:

Steam page, YT, YT live streams

u/unvestigate — 7 days ago
▲ 14 r/Zig

zlsx - A fast, lightweight ls clone written in Zig with custom themes

Hey everyone!

I wanted to share my recent project called **zlsx** - a lightweight, high-performance clone of the core `ls` utility written entirely from scratch in Zig (tested on 0.17.0-dev and 0.16.0).

I built this to practice my system programming skills and learn more about memory management and standard library tools in Zig.

Current Features:

* High-performance execution.

* Custom, low-strain пастель-colors for terminal outputs inspired by Catppuccin Mocha (directories) and Nord (symlinks).

* Supports core flags: `-a`, `-1`, `-m`, `-h`, `-s`, `-T`, `-F`, `-r`, and sorting (`-t` / `-S`).

* Full POSIX double-dash `--` delimiter support for path parsing.

*Note: The `-l` flag is still under development, so for now it only shows file sizes and names.*

I'd really appreciate any feedback on the codebase, architecture, or formatting!

**GitHub Repository:** https://github.com/kakasha12f-ctrl/zlsx/tree/main

By the way, this is my first real project (200+ lines of pure Zig code), so please don't judge too harshly! 😅 Hope you like it.

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

Hi I am brand new to ZIG! My first day and project! super exited!

I am brand new to ZIGI just started today! Glad to be here I am super exited! Very Interested in being more involved in this community and learning. I come barring a small gift posted below use this pic as you please if that's not against the rules! I also plan on having my youtube channel I am making promote this in some way id love to learn and make tutorial and showcase my work. Good night everyone!

u/Separate_Escape_7748 — 5 days ago
▲ 17 r/Zig+2 crossposts

[feedback][code-review] histclean cli-tool

This is my first Zig project!!!

Part of my workflow is to use fzf to search my command history. And I always wanted to have a cli-tool to clean duplicate commands from my history (I don't know if such a tool already exists, I never searched). I could've tried to write that tool in any other language (Python, bash, C#) but the task wasn't interesting, and I wanted it to be a proper bin.

When I started learning Zig, it seemed a proper starting point to make a file manipulation project. So, histclean was born. A cli-tool to clean command history.

Since it's my first project, I'm looking for some feedback, or if someone can review my code. I want to learn more about Zig, but it's tiresome to feel I'm working alone. So any input is welcomed.

Another point is that, I use bash and I never used zsh or any other shell. And I think I could benefit some feedback regarding them, or if some use cases could generate bugs or unexpected output.

A list of things I still don't understand enough to have full confidence about:

  • build.zig and the build system.
  • fuzzy testing.
github.com
u/AbdSheikho — 8 days ago
▲ 75 r/Zig+2 crossposts

Building an API with Zig and Postgres

Hey everyone!

I'm following up on a post I made a couple weeks ago where I made a tutorial on building a basic CRUD API in Zig with just the standard library.

A lot of people seemed to enjoy the video and I got a lot of feedback on extending the video and turning it into a mini-series where we build a more full-fledged API.

So today I extended it from an in-memory datastore to using Postgres! The next video in the mini-series will be about scaling the API to handle thousands of concurrent requests but if you have any other ideas please let me know!

youtu.be
u/Pokelego11 — 8 days ago
▲ 25 r/Zig

Can you do extern in Zig like you would in C

Hi everyone,

I'm experimenting with a copy-and-patch stencil system and currently write my stencils in C. I need optimizer-opaque and hoistable holes. In C I found success with extern const + hidden. I'm looking for potentially porting those stencils to Zig but I'm struggling with finding a hole mechanism.

Here is an example:

#include <stdint.h>
    
extern const int64_t placeholder __attribute__((visibility("hidden")));
    
void filter_gt(const int64_t * restrict input, int64_t * restrict output, int32_t size, int32_t *out_size) {
  int32_t count = 0;    
  for (int32_t i = 0; i < size; ++i) {
    if (placeholder < input[i]) {
      output[count++] = input[i];
    }
  }
  *out_size = count;
}

For now I'm focusing on Mach-O and this generates a PAGE21/PAGEOFF12 LOAD. I'm trying to avoid GOT - but I believe that would be the potential alternative if I wanted to use Zig.

reddit.com
u/LagutTV — 8 days ago
▲ 1 r/Zig+1 crossposts

GitHub - dajneem23/z-codebase-memory-mcp: High-performance code intelligence MCP server. Indexes codebases into a persistent knowledge graph

High-performance code intelligence MCP server. Indexes codebases into a persistent knowledge graph — average repo in milliseconds. 158 languages, sub-ms queries, 99% fewer tokens. Single static binary, zero dependencies.

github.com
u/Dry_Nothing8736 — 7 days ago