Compiling ren-c with zig?

Has anyone tried to compile ren-c with zig? ( ).

They claim to be able to compile c-code using zig cc , and have an impressive list of cross compilation targets, wasm among them.

1 Like

I gave it a shot tonight just to see if it was easy. Doesn't look like a "it just works" situation.

I couldn't figure out how to get it to act like a C99 compiler. It defines __cplusplus but then doesn't provide the headers for C++ (like <string> or <type_traits>).

If you can research or ask to see how to get it to not define __cplusplus then I can take another crack at it. But right now I'm mostly worrying about existential questions of Ren-C... so not a lot of time for detours.


. I just hoped it might be an easy way for cross compiling. If it isn't it's not worth the time.

1 Like

Given that I'm back at coding with a bit more enthusiasm right now, I thought it would probably be worth it to take a crack at building Ren-C with Zig again.

Lo and behold, I managed to generate an x86_64 executable on Linux via Zig. Woo. :partying_face:

It also had test parity with GCC builds (at the moment a lot of failures, but no crashes).

Some of this turned out to be my mistake. I failed to notice the makefile was passing a "--std=c++17" and "-x c++" flag even though invoking zig in C mode (zig cc).

But I hacked through it in both C++ and C compilation modes.

While this may sound great, be prepared for a bit of disappointment...

That cross-compilation comes from the fact that Zig is dependent on LLVM (~169 MiB), just as Emscripten is.

There was a roadmap document in 2020 about letting go of the "training wheels". And circa October 2022, an issue on their GitHub offers "reasons why one want an LLVM-less binary", painting an optimistic picture:

  • The executable is 4.4 MiB instead of 169 MiB.

  • Bootstrapping it only requires a C compiler instead of requiring a modern C++ compiler, Python 3, bash, and CMake (also C++).

    • This would make it much easier to obtain a Zig compiler on a new operating system or a limited environment such as a calculator.

But that's still some future vision. They say currently "Zig is not very useful without enabling LLVM extensions." I think this just means that they're like every other project (including Red, including Ren-C)... talking about a future thing when that future may be very very far off.

It certainly doesn't hurt to have Ren-C's deep vetting for standards show it building successfully on yet another compiler. And if that compiler does perchance make a decision aiming in the same vicinity as Ren-C (e.g. "we're going to focus on Wasm, vs requiring to target every esoteric LLVM emitter") it may make a better choice than other toolchains.

But for the moment, their Wasm doesn't have the integration Emscripten provides, and it's not that much thinner so long as the LLVM dependency is there.