Description
Zig is able to compile C code, however, its command-line interface differs from existing C compilers. This means it cannot be swapped out for other C-compilers as existing build systems wouldn't know how to compile C code with Zig's unique command-line interface.
To remedy this, it is proposed zig add support for existing c compiler command-line interfaces.
Here are some thoughts about how this could be done:
Command-line translation
A tool could be created that takes a set of command-line arguments meant for an existing C compiler like gcc/clang and translates them to the zig equivalent.
I've created a prototype for this here: https://github.com/marler8997/zigcc
The current challenge with this solution is being able to invoke zig's clang entry point with libc options. It's easy enough to invoke zig cc
, but I'm not sure how to properly glean the other clang options I need to compile C code and how to make sure libc is also built. i.e. zig cc -isystem ...
. If we could support this, then clang's entire command-line interface will be available to be used by this wrapper tool. This seems to scale better rather than trying to expose each clang semantic with something in the zig command-line interface.
New Commands
Add new commands to zig, (i.e. zig gcc
or zig clang
) that emulates the respective compiler's command-line interface
Symbolic links
Symbolic links could be used to signal zig to run in a particular mode, i.e.
zig
zig-clang > zig
zig-gcc > zig
These would essentially do the same thing as the "New Command" mechanism, except it wouldn't require an extra parameter. This might make zig compatible with more projects. On windows this could be done by making zig-clang.bat
/zig-gcc.bat
batch scripts that just forward the call to zig.
Version Message
Some build systems will run the C-compiler and check the version information to know how to use it. Printing the compiler-version from the other C compiler that zig is emulating could help compatibility in some projects. Furthermore, we may want to leave the door open to supporting multiple versions of different C compiler if the need arises.