Live data from Hacker News

Aro – Zig's new C compiler

github.com

51–60 of 130 posts

Re: Aro – Zig's new C compiler

#52
post #51

Wait, so you still need zig, and zig still needs LLVM. If you have LLVM, you have clang. What is the value proposition of this compiler, then?

The Zig self-hosted x86 backend is nearly complete (and is already capable of building the Zig compiler itself). So it's part of the path toward not needing LLVM or clang at all.

Re: Aro – Zig's new C compiler

#53
post #49

It seems like I can't include standard header files, so it can't compile a common hello world. I guess that'd be useful to mention on the README, or maybe I'm doing something wrong? main.c:1:10: fatal error: 'stdio.h' not found #include It'd be nice if header inclusion, and -l options work. This would allow benchmarking Aro against some other compilers on a wide range of C files. Usually sqlite3.c is my first go-to f…

System header search paths are only implemented on Linux currently. You should be able to parse sqlite3.c on Linux with

   arocc -fsyntax-only -Wno-unknown-attributes sqlite3.c

Re: Aro – Zig's new C compiler

#55
post #50
post #47

Earlier quoted context omitted.

I know that he is but this is incredibly off-topic. Aro deserves the attention it is getting, without the discussion getting hijacked by another project. D would deserve attention too, in a separate post, or here if it was explained how it relates to Aro.

Walter's comment could be read more charitably and could show his interest in Zig and similar choices that are made. The last sentence, or, indeed, the whole comment, can be read like "We did this for D, and it works well. [go for it]". I don't think D is casting any shadow on Zig. Both languages play in the same field, D is older but I feel like we hear about Zig way more these days. His comment is likely to interes…

I have profound respect for Walter and all his work, same for Andrei; but his comment was off-topic.

Re: Aro – Zig's new C compiler

#56

The ReadMe is quite lacking … - why create a competing front end to Zig? - what problems is it solving? - what’s different than the official Zig frontend? Etc

A lot of the work happening in Zig includes experiments which may or may not end up kept long term. What this would solve: compile C without requiring LLVM. The plan in the community is to have LLVM as an optional dependency, and not required by default.

Re: Aro – Zig's new C compiler

#57
post #18
post #12

Earlier quoted context omitted.

Is it possible to do what Zig does and cross compile to any OS/arch, from any OS/arch? Last I tried, I found some compiler options and commands to do it, but they were badly explained, I tried for hours and it just didn't work at all, so I gave up.

Generally, the hard part isn't the cross compiler (nor, these days, the cross binutils), but the cross libraries . There are at least 3 ways (/usr/lib/$ARCH, /usr/$ARCH/lib, /$CHROOT/usr/lib/) to set up the libraries, all incompatible with each other. Zig is notable for putting a lot of work into hard-coding basic C libraries, though of course you still need a scattering of other C libraries for most real-world progr…

The nixpkgs have a rather elegant way to deal with that. Let's presume you need a libpng for an armv7 platform, such as an old RaspberryPi. Then Nix allows you to

- get a suitable cross compiler toolchain

- pick whether you want dynamic or static linking (most likely static when the target system does not come with /nix/store)

- compile all prerequisites for the library such as transitive dependencies

- compile the library with the cross compiler for the selected target arch

All in one command line call, that does not require you to 'apt-get install' any of the tools manually:

  nix-build '' -A pkgsStatic.libpng --arg crossSystem '{ config = "armv7a-unknown-linux-gnueabihf"; }'

Re: Aro – Zig's new C compiler

#58
post #53
post #49

It seems like I can't include standard header files, so it can't compile a common hello world. I guess that'd be useful to mention on the README, or maybe I'm doing something wrong? main.c:1:10: fatal error: 'stdio.h' not found #include It'd be nice if header inclusion, and -l options work. This would allow benchmarking Aro against some other compilers on a wide range of C files. Usually sqlite3.c is my first go-to f…

System header search paths are only implemented on Linux currently. You should be able to parse sqlite3.c on Linux with arocc -fsyntax-only -Wno-unknown-attributes sqlite3.c

I'm primarily interested in full compilation performance, but thanks for the tip!

Re: Aro – Zig's new C compiler

#59
post #31

Earlier quoted context omitted.

The Zig compiler has used Data Oriented Design for a long time, so any recent version has that, yes. The most substantial part of running the compiler right now is LLVM, hence the focus to provide an alternative. The other big focus right now is incremental compilation, which will make recompilations very fast.

The talk I am referring to is from 2024 and shows some metrics improving by 30% or more. And Andrew said that's not yet shipped: https://www.youtube.com/watch?v=IroPQ150F6c So, are you sure about that?? EDIT: ok, the talk was uploaded just last week, but someone in the comments clarified that: > The original talk is from 2021.. Thank you for reuploading. I feel stupid now :/

Recently Andrew posted that the compiler can compile itself without LLVM in under 10 seconds: https://mastodon.social/@andrewrk/112752924367683101

Re: Aro – Zig's new C compiler

#60

Earlier quoted context omitted.

It says it's a C frontend for `zig translate-c` which translates C code to Zig code. `zig translate-c` is not required for most Zig projects or even for most Zig projects that interop with C.

translate-c is not required for compiling pure Zig code. However, the plan is to remove the "@cImport" built in. So if your project is importing a c header, in the future you'll add build step translating it from c to Zig, and then you import it into your Zig code as a module.

It's super exciting. c2nim is one of the things that makes using Nim in _super_ odd places (like professional embedded firmware development) feasible, and translate-c brings Zig that much closer to what I'd love from it! Embedded Zig is going to be rad, once we get there.
Post reply on HN