Zig Libc

202 points by ingve 12 hours ago on hackernews | 63 comments
Super cool project.

I expect a lot of C code may be quite mechanically translated to Zig (by help of LLMs). Unlike C->Rust or C->C++, where there's more of a paradigm shift.

Retro_Dev | 7 hours ago

There's solid reason for the translation here; the Zig core team is aiming to eliminate duplicated code and C functions, and avoid the need to track libc from multiple sources. In the future, LLMs could serve as part of this, but they are currently quite terrible at Zig (as far as I understand it, it's not a lack of Zig code samples, it's an imbalance of OLD Zig to NEW Zig, as Zig changes quite frequently).

You would need to consider if it is even worth it translating your C code. If the paradigm is identical and the entire purpose would be "haha it is now one language," surely you could just compile and link the C code with libzigc... In my opinion, it's not worth translating code if the benefit of "hey look one language" requires the cost of "let's pray the LLM didn't hallucinate or make a mistake while translating the code."

dnautics | an hour ago

> they are currently quite terrible at Zig

hard disagree (example elsewhere)

nesarkvechnep | 8 hours ago

"Furthermore, when this work is combined with the recent std.Io changes, there is potential for users to seamlessly control how libc performs I/O - for example forcing all calls to read and write to participate in an io_uring event loop"

This is exciting! I particularly care more about kqueue but I guess the quote applies to it too.

nemo1618 | 8 hours ago

This strikes me as a very agent-friendly problem. Given a harness that enforces sufficiently-rigorous tests, I'm sure you could spin up an agent loop that methodically churns through these functions one by one, finishing in a few days.

henning | 8 hours ago

Have you ever used an LLM with Zig? It will generate syntactically invalid code. Zig breaks so often and LLMs have such an eternally old knowledge cutoff that they only know old ass broken versions.

The same goes for TLA+ and all the other obscure things people think would be great to use with LLMs, and they would, if there was as much training data as there was for JavaScript and Python.

Graziano_M | 7 hours ago

You must have not tried this with an LLM agent in the past few months.
i tested sonnet 4.5 just last week on a zig codebase and it has to be instructed the std.ArrayList syntax every time.

benatkin | 4 hours ago

Try it again. This time do something different with CLAUDE.md. By the way it's happy to edit its own CLAUDE.md files (don't have an agent edit another agent's CLAUDE.md files though [0])

0: https://news.ycombinator.com/item?id=46723384

rudedogg | 3 hours ago

I made a Zig agent skill yesterday if interested: https://github.com/rudedogg/zig-skills/

Claude getting the ArrayList API wrong every time was a major reason why

It’s AI generated but should help. I need to test and review it more (noticed it mentions async which isn’t in 0.15.x :| )

ezekiel68 | 6 hours ago

To be fair, this was true of early public LLMs with rust code too. As more public zig repositories (and blogs / docs / videos) come online, they will improve. I agree it's a mess currently.

dnautics | an hour ago

i find claude does quite well with zig. this project is like > 95% claude, and it's an incredibly complicated codebase [0] (which is why i am not doing it by hand):

https://github.com/ityonemo/clr

[0] generates a dynamically loaded library which does sketchy shit to access the binary representation of datastructures in the zig compiler, and then transpiles the IR to zig code which has to be rerun to do the analysis.

AndyKelley | 5 hours ago

hallucinations in a libc implementation would be especially bad

jzelinskie | 8 hours ago

Cool idea, for sure, but I can't help but wonder: for the code that's been ported, is there a concern that you'd have to perpetually watch out for CVEs in glibc/musl and determine if they also apply to the Zig implementations?

AndyKelley | 6 hours ago

Yes but we already have to do that for our own standard library. For shared codepaths (e.g. math) it's strictly fewer potential bugs.
"Abolish ICE" at the bottom. Obviously a Bad Bunny fan, as I am.
I too am sick of internal compiler errors

matheusmoreira | 7 hours ago

I too am sick of intrusion countermeasures electronics. Think of all the poor netrunners out there.

AndyKelley | 6 hours ago

The very same day I sat at home writing this devlog like a coward, less than five miles away, armed forces who are in my city against the will of our elected officials shot tear gas, unprovoked, at peaceful protestors, including my wife.

https://www.kptv.com/2026/01/31/live-labor-unions-rally-marc...

This isn't some hypothetical political agenda I'm using my platform to push. There's a nonzero chance I go out there next weekend to peacefully protest, and get shot like Alex Pretti.

Needless to say, if I get shot by ICE, it's not good for the Zig project. And they've brought the battle to my doorstep, almost literally.

Abolish ICE.

My 85 year old mom lives in Portland and she attends rallies frequently. If you know of any way to support you or other local people doing this work, I'm very interested. My email is on my profile page.

I have a friend who is in Minneapolis. He's involved in caravans which are tracking ICE. He wasn't the driver in the last one. But, the ICE vehicle they tailed suddenly started going in a very direct path, instead of randomly driving. The driver figured it out first. They drove to the driver's house and then stood outside of their car for ten minutes staring at his house. Cars in Minnesota have their license plates on both the front and the back.

Is there any justification for that kind of intimidation? Did any of the Trump supporters vote for that? I hear about paid agitators on the left but not that kind of compensated actors. Is his name in a database now once they did the lookup?

baggy_trough | 6 hours ago

> against the will of our elected officials

Did you mean your local officials?

kstrauser | 5 hours ago

In the Federal model of US government, state authority overrides centralized government except in the explicit cases enumerated by the Constitution.

So yes, of course they mean their local officials, because in this case there isn’t an explicit line in the Constitution explaining why the feds are allowed to invade Minnesota.

baggy_trough | 4 hours ago

The Supreme Court has disagreed with you on the matter of federal immigration constitutional authority for more than a century. There isn’t any “invasion”; that’s a propaganda device.

actionfromafar | 4 hours ago

That's clever. Just slap the "immigration sticker" on ICE and do whatever you want.

kstrauser | 4 hours ago

And yet they didn’t brag about invading other states bordering, let’s see, Canada, just the blue one they had a political spat with.

dnautics | an hour ago

yep. It's not in the constitution, but in all practicality mcculloch vs maryland (which i would love to see repealed) disagrees

ghthor | 4 hours ago

Don’t do it, your project here on zig is a much larger net positive for civilization than you spending your time at those protests.

<3 zig and want io interface in everything!

lvl155 | 4 hours ago

Andy stay safe. We gotta all come to realization that none of this is possible if we let our democracy slip away. Millions before us died to preserve it. We owe it to them to put up a good fight.

xeonmc | 6 hours ago

I too am sick of internal combustion engines, a product of the last century.

himujjal | 3 hours ago

I don’t mind someone doing politics stuffs. Heck I am in for privacy and no enterprise model of software. Big Stallman fan here.

But I would really suggest keeping politics out of Zig stuffs.

I don’t even know what ICE is. Just read about it.

This is a show of power.

Like: “I am an American and since I am building the software, I am going to push MY politics into your throat”.

That means, to show similar power, I need to build a software as influential as Zig so that I can push my agendas of my country down your throats.

Heck let me do just that.

Keep politics to politics forums, keep code to code.

heavyset_go | 3 hours ago

The gall to tell someone what to create or not create, or say or not say with their own creation, for free for your own enjoyment.

sltkr | 3 hours ago

Pushing politics is explicitly against the Hacker News guidelines though.

If Andrew wants to make Zig the woke programming language for American Liberals, he is of course free to do so, but then he probably should not be posting on Hacker News in an attempt to proselytize.

rjrjrjrj | 2 hours ago

“Woke”: objecting to murder

sltkr | 2 hours ago

Nice attempt at gaslighting.

If Andrew only wrote “I object to murder” we wouldn't have this discussion. We're here because he wrote “Abolish ICE” instead. That's not denouncing murder, it's denouncing federal immigration law.

The woke don't object to murder. They cheered the murder of Charlie Kirk, they lamented the assassination attempts on Donald Trump because they _failed_, they celebrate Luigi Mangione as a martyr for their cause. Has Andrew ever used the Zig programming blog to condemn any of these (attempted) murders? I bet he hasn't—but feel free to prove me wrong!

So it's pretty clear that Andrew, just like most of the woke, doesn't object to murder. He loves murder. He only objects to democracy, to the rule of law, to the majority of Americans who don't support illegal immigration to the extent that he does.

If Andrew wants to use his programming language to take a stand against murder, he is welcome to do so! He has chosen to never do it. He has only used his platform to push woke politics, by supporting illegal immigration, and opposing law enforcement.

rjrjrjrj | 2 hours ago

“Pushing politics is explicitly against the Hacker News guidelines though.”

Cool tirade.

hakrgrl | an hour ago

"Be kind. Don't be snarky."

KingMob | an hour ago

Gaslighting?

You were ranting about how Alex Pretti's murder was justified just a few comments up.

STFU.

dminik | an hour ago

Objecting to murder is still politics, no? In fact, US republicans and democrats can't seem to agree who is fine to murder.

Republicans say that abortions are murder, but often also that prisoner executions are fine. Democrats tend to be in favor of abortions, but not of the death penalty.

I'm not making a moral judgement here, but I do want to ask. Is it just politics you don't agree with that you don't want Andrew to express?

I just want to say that I agree completely with you here. I had a suspicion of what kind of person Andrew was when I saw him with colored hair (so called 'danger hair') and basically knew it was over.

meisel | 7 hours ago

> It’s kind of like enabling LTO (Link-Time Optimization) across the libc boundary, except it’s done properly in the frontend instead of too late, in the linker

Why is the linker too late? Is Zig able to do optimizations in the frontend that, e.g., a linker working with LLVM IR is not?

ibejoeb | 7 hours ago

Seems like it ought to be able to do inlining and dead code stripping which, I think, wouldn't be viable at link time against optimized static libraries.

comex | 7 hours ago

It is viable against the IR that static libraries contain when LTO is enabled.

LTO essentially means “load the entire compiler backend into the linker and do half of the compilation work at link time”.

It’s a great big hack, but it does work.

ibejoeb | 6 hours ago

Right, but I think that's what the question of "Why is the linker too late?" is getting at. With zig libc, the compiler can do it, so you don't need fat objects and all that.

---

expanding: so, this means that you can do cross-boundary optimizations without LTO and with pre-built artifacts. I think.

gary_0 | 4 hours ago

As I understand it, compiling each source file separately and linking together the result was historically kind of a hack too, or at least a compromise, because early unix machines didn't have enough memory to compile the whole program at once (or even just hold multiple source files in memory at a time). Although later on, doing it this way did allow for faster recompilation because you didn't need to re-ingest source files that hadn't been changed (although this stopped being true for template-heavy C++ code).

OsamaJaber | 7 hours ago

250 C files were deleted. 2032 to go. Watching Zig slowly eat libc from the inside is one of the more satisfying long term projects to follow

LexiMax | 31 minutes ago

That's something I've always admired about Zig.

A lot of languages claim to be a C replacement, but Zig is the second language I've seen that seemed like it had a reasonable plan to do so at any appreciable scale. The language makes working with the C ABI pretty easy, but it also has a build system that can seamlessly integrate Zig and C together, as well as having a translate-c that actually works shockingly well in the code I've put through it.

The only thing it didn't do was be 99% compatible with existing C codebases...which was the C++ strategy, the first language I can think of with such a plan. And frankly, I think Zig keeping C's relative simplicity while avoiding some of the pitfalls of the language proper was the better play.

generichuman | 5 hours ago

This is very exciting for zig projects linking C libraries. Though I'm curious about the following case:

Let's say I'm building a C program targeting Windows with MinGW & only using Zig as a cross compiler. Is there a way to still statically link MinGW's libc implementation or does this mean that's going away and I can only statically link ziglibc even if it looks like MinGW from the outside?

AndyKelley | 5 hours ago

This use case is unchanged.

If you specify -target x86_64-windows-gnu -lc then some libc functions are provided by Zig, some are provided by vendored mingw-w64 C files, and you don't need mingw-w64 installed separately; Zig provides everything.

You can still pass --libc libc.txt to link against an externally provided libc, such as a separate mingw-w64 installation you have lying around, or even your own libc installation if you want to mess around with that.

Both situations unchanged.

generichuman | 4 hours ago

That's cool. I imagine I could also maintain a MinGW package that can be downloaded through the Zig package manager and statically linked without involving the zig libc? (Such that the user doesn't need to install anything but zig)

That's a good way to sell moving over to the zig build system, and eventually zig the language itself in some real-world scenarios imo.

dnautics | an hour ago

do you suspect it will be possible to implement printf??

while we're talking about printf, can i incept in you the idea of making an io.printf function that does print-then-flush?

tiffanyh | 4 hours ago

Does this mean long term Zig won’t run on OpenBSD?

Because doesn’t OpenBSD block direct syscalls & force everything to go through libc.

https://news.ycombinator.com/item?id=38039689

actionfromafar | 4 hours ago

AndyKelley | 3 hours ago

This affects static libc only. If you pass -dynamic -lc then the libc functions are provided by the target system. Some systems only support dynamic libc, such as macOS. I think OpenBSD actually does support static libc though.

winterqt | 2 hours ago

> I think OpenBSD actually does support static libc though.

How does that work, with syscalls being unable to be called except from the system’s libc? I’d be a bit surprised if any binary’s embedded libc would support this model.

pretendgeneer | 2 hours ago

Not all of libc is syscalls. E.g. strlen() is zib libc but open() goes to system libc.

oguz-ismail2 | 2 hours ago

> How does that work, with syscalls being unable to be called except from the system’s libc?

OpenBSD allows system calls being made from shared libraries whose names start with `libc.so.' and all static binaries, as long as they include an `openbsd.syscalls' section listing call sites.

mananaysiempre | 2 hours ago

For static executables, “the system’s libc” is of course not a thing. To support those, OpenBSD requires them to include an exhaustive list of all addresses of syscall instructions in a predefined place[1].

(With that said, OpenBSD promises no stability if you choose to bypass libc. What it promises instead is that it will change things in incompatible ways that will hurt. It’s up to you whether the pain that thus results from supporting OpenBSD is worth it.)

[1] https://nullprogram.com/blog/2025/03/06/

AndyKelley | 2 hours ago

Sorry I got mixed up with FreeBSD: https://codeberg.org/ziglang/zig/issues/30981 (original github link has more information)

squirrellous | 4 hours ago

I’m sure this has crossed someone’s mind but why isn’t this called zlibc? :-)

lioeters | 2 hours ago

I rather like "libz".

kibibu | an hour ago

Perhaps to avoid confusion with zlib?

https://www.zlib.net/

anitil | 2 hours ago

There are so many scary parts of libc, this is a really exciting project

LarsKrimi | an hour ago

There are many useful functions too. Like "memfrob" and "strfry". I hope the Zig libc makes those available too

Just joking of course. Those are sadly only in glibc.. :)