12 ms·
Zig Libc
- deleted 9mo ago[deleted]
- cies 9mo agoSuper 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 9mo agoThere'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 9mo ago> they are currently quite terrible at Zig hard disagree (example elsewhere)
- nesarkvechnep 9mo 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 9mo agoThis 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 9mo agoHave 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 9mo agoYou must have not tried this with an LLM agent in the past few months.
- ale 9mo agoi tested sonnet 4.5 just last week on a zig codebase and it has to be instructed the std.ArrayList syntax every time.
- benatkin 9mo agoTry 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 https://news.ycombinator.com/item?id=46723384
- rudedogg 9mo agoI made a Zig agent skill yesterday if interested: https://github.com/rudedogg/zig-skills/ 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 :| )
- jzelinskie 9mo agoCool 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 9mo agoYes but we already have to do that for our own standard library. For shared codepaths (e.g. math) it's strictly fewer potential bugs.
- xrd 9mo ago"Abolish ICE" at the bottom. Obviously a Bad Bunny fan, as I am.
- adzm 9mo agoI too am sick of internal compiler errors
- matheusmoreira 9mo agoI too am sick of intrusion countermeasures electronics. Think of all the poor netrunners out there.
- AndyKelley 9mo agoThe 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-march-portland-ice-facility-protest/ 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.
- MiltarizdMerica 9mo ago[flagged]
- pixelpoet 9mo agoThese few-minutes-old accounts swooping in on hot button issues to try persuade people are such a goddamn scourge, I wish there were something that could be done about it. In the end I probably just need to leave HN for a while because it's really doing a number on what's left of my ability to trust what I read online.
- meisel 9mo 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 9mo agoSeems 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 9mo agoIt 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 9mo agoRight, 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.
- DannyBee 9mo agoCalling this "properly" is a stretch at best. I will say first that C libc does this - the functions are inline defined in header files, but this is mainly a pre-LTO artifact. Otherwise it has no particular advantage other than disk space, it's the equivalent of just catting all your source files together and compiling that. If you thikn it's better to do in the frontend, cool, you could make it so all the code gets seen by the frontend by fake compiling all the stuff, writing the original source to an object file special section, and then make the linker really call the frontend with all those special sections. You can even do it without the linker if you want. Now you have all the code in the frontend if that's what you want (I have no idea why you'd want this). It has the disadvantage that it's the equivalent of this, without choice. If you look far enough back, lots of C/C++ projects used to do this kind of thing when they needed performance in the days before LTO, or they just shoved the function definitions in header files, but stopped because it has a huge forced memory and compilation speed footprint. Then we moved to precompiled headers to fix the latter, then LTO to fix the former and the latter. Everything old is new again. In the end, you are also much better off improving the ability to take lots of random object files with IR and make it optimize well than trying to ensure that all possible source code will be present to the frontend for a single compile. Lots of languages and compilers went down this path and it just doesn't work in practice for real users. So doing stuff in the linker (and it's not really the linker, the linker is just calling the compiler with the code, whether that compiler is a library or a separate executable) is not a hack, it's the best compilation strategy you can realistically use, because the latter is essentially a dream land where nobody has third party libraries they link or subprojects that are libraries or multiple compilation processes and .... Zig always seems to do this thing in blog posts and elsewhere where they add these remarks that often imply there is only one true way of doing it right and they are doing it. It often comes off as immature and honestly a turnoff from wanting to use it for real.
- OsamaJaber 9mo ago250 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 9mo agoThat'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.
- WalterBright 9mo agoD can import C files directly, and can do C-source to D-source translation. D can compile a project with a C and a D source file with: dmd foo.d bar.c ./foo
- audunw 9mo agoDo you have to bring up D in every Zig related post? I do like D. I've written a game in it and enjoyed it a lot. I would encourage others to check it out. But it's not a C replacement. BetterC feels like an afterthought. A nice bonus. Not a primary focus. E.g. the language is designed to use exceptions for error handling, so of course there's no feature for BetterC dedicated to error handling. Being a better C is the one and only focus of Zig. So it has features for doing error handling without exceptions. D is not going to replace C, perhaps for the same reasons subsets of C++ didn't. I don't know if Zig and Rust will. But there's a better chance since they actually bring a lot of stuff to the table that arguably make them better at being a C-like language than C. I am really hyped to see how embedded development will be in Zig after the new IO interface lands.
- self_awareness 9mo ago[flagged]
- deleted 9mo ago[deleted]
- pravetz259 9mo agoOne can say words against one injustice without being required to mention every injustice.
- self_awareness 9mo ago[flagged]
- deleted 9mo ago[deleted]
- nameconflicts 9mo ago[flagged]
- shpongled 9mo agoAs someone who has been primarily writing Rust for the past 8+ years, I am actually unaware of any political drama surrounding Rust. It's just a programming language.
- generichuman 9mo agoThis 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 9mo agoThis 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 9mo agoThat'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 9mo agodo 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?
- Cloudef 9mo agoIt's completely possible to implement printf. here is my impl (not 100% correct yet) of snprintf for my custom libc implemented on top of a platform I'm working on <https://zigbin.io/ab1e79 https://zigbin.io/ab1e79> The va_arg stuff are extern because zig's va arg stuff is pretty broken at the moment. Here's a C++ game ported to web using said libc running on top of the custom platform and web frontend that implements the platform ABI <https://cloudef.pw/sorvi/#supertux.sorvi https://cloudef.pw/sorvi/#supertux.sorvi> (you might need javascript.options.wasm_js_promise_integration enabled if using firefox based browser)
- tiffanyh 9mo agoDoes 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 https://news.ycombinator.com/item?id=38039689
- actionfromafar 9mo agohttps://news.ycombinator.com/reply?id=46864849&goto=item%3Fid%3D46858622%2346864849 https://news.ycombinator.com/reply?id=46864849&goto=item%3Fi...
- AndyKelley 9mo agoThis 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 9mo 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 9mo agoNot all of libc is syscalls. E.g. strlen() is zib libc but open() goes to system libc.
- tialaramex 9mo agoGood point. C's "freestanding" mode, analogous to Rust's nostd, does not provide any functions at all, just some type definitions and constants which obviously evaporate when compiled. Rust's nostd not only can compute how long a string is, it can unstably sort a slice, do atomic operations if they exist on your hardware, lots of fancy stuff but as a consequence even nostd has an actual library of code, a similar but maybe less organized situation occurs in C++. Most of the time this is simply better, why hand write your own crap sort when your compiler vendor can just provide an optimised sort for your platform? But on very, very tiny systems this might be unaffordable. Anyway, C doesn't have Rust's core versus std distinction and so libc is a muddle of both the "Just useful library stuff" like strlen or qsort and features like open which are bound to the operating system specifics.
- squirrellous 9mo agoI’m sure this has crossed someone’s mind but why isn’t this called zlibc? :-)
- anitil 9mo agoThere are so many scary parts of libc, this is a really exciting project
- LarsKrimi 9mo agoThere 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.. :)
- LAC-Tech 9mo agoDoes Zig does have the man power to keep these up to date? I think we either need to make operating systems not in C, or just accept that at some level we rely on C.
- stevefan1999 9mo agoNot C. PDP-11
- mastermage 9mo agoThat just reminds me anyone know whether rust has something similar? Not wanting to start any Rust v. Zig debate. I am just wanting to be even more independant when it comes to some of my Rust projects.
- erk__ 9mo agoThere is a couple libc implementations: - c-ward [0] a libc implementation in Rust - relibc [1] a libc implementation in Rust mainly for use in the Redox os (but works with linux as well) - rustix [2] safe bindings to posix apis without using C [0]: https://github.com/sunfishcode/c-ward https://github.com/sunfishcode/c-ward [1]: https://gitlab.redox-os.org/redox-os/relibc/ https://gitlab.redox-os.org/redox-os/relibc/ [2]: https://github.com/bytecodealliance/rustix https://github.com/bytecodealliance/rustix
- mastermage 8mo agorealy cool thank you
- voidUpdate 9mo agoDoes anyone know if there is a timeline on when Zig might achieve 1.0? I've been interested in the language for a while, but I'm a bit concerned about writing anything important in it when it seems to be evolving so much at the moment
- Zambyte 9mo agoNobody knows, but for what it's worth, existing large projects that are used in production environments have been fairly good at keeping up with Zig releases. See: Bun, Ghostty, and Tigerbeetle for good examples of this. Because the semantics of Zig are relatively simple, porting to the latest version is usually as simple as bumping your compiler version, trying to build, making a fairly mindless, mechanical change, and repeating until it builds. The biggest thing holding me back from using Zig for important projects is the willingness of my peers to adopt it, but I'm just building projects that I can build myself until they are convinced :)
- jibal 9mo agoThere's no timeline for 1.0 You might find this interesting: https://www.youtube.com/watch?v=x3hOiOcbgeA https://www.youtube.com/watch?v=x3hOiOcbgeA