Zig is a new language that shares many attributes with C but with stronger typing, easier memory allocation, support for name spacing and a host of other features. Its syntax, however, is reminiscent of JavaScript rather than C, which some may hold against it. Zig’s aim is to provide a very simple language with straightforward compilation that minimizes side-effects and delivers predictable, easy-to-trace execution. Zig also provides simplified access to LLVM’s cross-compilation capability. Some of our developers are using Zig as a cross-compiler even though they aren’t writing Zig code.
Zig is a novel language and worth looking into for applications where C is being considered or already in use as well as for low-level systems applications that require explicit memory manipulation.

Rewrite it in Rust

The RIIR mantra has been floating around for a while. It has been repeated with full conviction by some, and used to mock Rust by others.

Rewriting every C/C++ project would surely help bypass some of the aforementioned accidents of history, but it would also take an amount of effort that, while the FOSS community is able to put in. First of all, rewriting from scratch is hard: even the best projects will have undocumented and untested behavior, making it very hard to catch and fix regressions, and in the best case scenario you’ll produce a new implementation at best functionally equivalent to the old one, which is also why many rightfully consider full rewrites an outright dangerous idea.

On top of that, the FOSS community will never converge to a single language, which means that a deliberate rewrite effort will be uncoordinated. The disruptive changing language can be when the Python cryptography package added a Rust dependency which in turn changed the list of supported platforms and caused a lot of community leaders to butt heads. To improve the critical infrastructure it must improve the developer experience (DX) of systems programming, but rewriting everything is not the only answer.

Instead of running away from the C/C++ ecosystem, find a way of moving forward that doesn’t start by throwing in the trash everything that has been built in the last 40 years. C and C++ are still being moved forward by their respective committees, but progress has been really slow and very little of it has been made on the DX front. To trigger real change need to act independently but in harmony with the C/C++ ecosystem, which is why Zig is not only a language, but also a toolchain that can compile C/C++ code.

Improving the C/C++ ecosystem

While LLVM is now transitioning into an optional dependency in the Zig compiler, it will still be part of the 40mb archive you get when you download Zig as it’s very useful to deal with C/C++ code. Zig bundles a few different libcs to make cross-compilation work out of the box and exposes zig cc and zig c++, two commands that allow the use of Zig as in-place replacement for Clang.

One thing that LLVM can’t do, is link MachO executables for Apple Silicon (the new Apple ARM chips) and so a while ago Jakub started working on ZLD, an in-house linker that has already proven to be extremely useful on multiple different occasions while working on the Zig project.

We hope for ZLD to eventually replace lld entirely, making Zig even more independent from LLVM and helping us pursue the ultimate goal of enabling cross-compilation from any target for any target.

Build systems

If you are already using Zig to compile your C/C++ project, you can also get rid of your dependency on a build system by using zig build instead. Too many projects have a soup of undecipherable build config files that accumulate over the years because of various reasons.

Create a build.zig file and now you can build on all platforms without needing any extra dependency, not even build-essential, Xcode, or MSVC. This is already possible today and, for example, wasm3 is already supporting it.

If your build process depends on other tools, don’t worry, Zig also exposes:

  • zig ar
  • zig ranlib
  • zig dlltool
  • zig lib


When it comes to Open Source software, making things more fun and worth learning can be even more important than providing an economic incentive, but systems programming has been so stagnant that having to deal with it has become cripplingly demotivating.

Freeing the art of systems programming from the grips of C/C++ cruft is the only way to push for real change in our industry, but rewriting everything is not the answer. In the Zig project we’re making the C/C++ ecosystem more fun and productive. Today we have a compiler, a linker and a build system, and soon we’ll also have a package manager, making Zig a complete toolchain that can fetch dependencies and build C/C++/Zig projects from any target, for any target.

For more details contact info@vafion.com

Follow us on Social media  : Twitter |  Facebook | Instagram | Linkedin

Similar Posts:

    No similar blogs

Related Posts

Stay UpdatedSubscribe and Get the latest updates from Vafion