Remix.run Logo
Zig Libc(ziglang.org)
161 points by ingve 10 hours ago | 42 comments
tiffanyh an hour ago | parent | next [-]

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

AndyKelley 44 minutes ago | parent | next [-]

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.

actionfromafar an hour ago | parent | prev [-]

https://news.ycombinator.com/reply?id=46864849&goto=item%3Fi...

OsamaJaber 4 hours ago | parent | prev | next [-]

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

xrd 5 hours ago | parent | prev | next [-]

"Abolish ICE" at the bottom. Obviously a Bad Bunny fan, as I am.

AndyKelley 4 hours ago | parent | next [-]

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.

lvl155 an hour ago | parent | next [-]

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.

baggy_trough 3 hours ago | parent | prev | next [-]

> against the will of our elected officials

Did you mean your local officials?

kstrauser 2 hours ago | parent [-]

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 2 hours ago | parent [-]

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.

kstrauser an hour ago | parent | next [-]

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

actionfromafar 2 hours ago | parent | prev [-]

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

ghthor an hour ago | parent | prev | next [-]

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!

xrd 3 hours ago | parent | prev [-]

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?

adzm 4 hours ago | parent | prev | next [-]

I too am sick of internal compiler errors

himujjal an hour ago | parent | prev | next [-]

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 21 minutes ago | parent [-]

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 6 minutes ago | parent [-]

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.

xeonmc 3 hours ago | parent | prev | next [-]

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

matheusmoreira 4 hours ago | parent | prev [-]

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

jzelinskie 5 hours ago | parent | prev | next [-]

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 4 hours ago | parent [-]

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.

generichuman 2 hours ago | parent | prev | next [-]

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 2 hours ago | parent [-]

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 an hour ago | parent [-]

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.

meisel 4 hours ago | parent | prev | next [-]

> 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 4 hours ago | parent [-]

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 4 hours ago | parent [-]

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.

gary_0 an hour ago | parent | next [-]

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

ibejoeb 4 hours ago | parent | prev [-]

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.

nesarkvechnep 5 hours ago | parent | prev | next [-]

"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.

squirrellous an hour ago | parent | prev | next [-]

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

cies 6 hours ago | parent | prev | next [-]

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 5 hours ago | parent [-]

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."

nemo1618 5 hours ago | parent | prev [-]

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.

AndyKelley 3 hours ago | parent | next [-]

hallucinations in a libc implementation would be especially bad

henning 5 hours ago | parent | prev [-]

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.

ezekiel68 3 hours ago | parent | next [-]

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.

Graziano_M 4 hours ago | parent | prev [-]

You must have not tried this with an LLM agent in the past few months.

ale 3 hours ago | parent [-]

i tested sonnet 4.5 just last week on a zig codebase and it has to be instructed the std.ArrayList syntax every time.

rudedogg 38 minutes ago | parent | next [-]

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

benatkin an hour ago | parent | prev [-]

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