-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
use case: ability to use zig as a drop-in replacement for a C compiler #3089
Comments
Transferring discussion to this thread (#3102 (comment)) The current question is, what is the equivalent of |
There isn't one. That would be one of the problems to solve for this issue. |
Andrew just did a stream on this issue: https://www.twitch.tv/videos/571523138 note: unsure how long that link will remain valid |
Now available on youtube: https://www.youtube.com/watch?v=2u2lEJv7Ukw |
This is now available as of 7ffdf59. However there are quite a few follow-up tasks to do before this feature is really complete. I'll be opening new issues to track those tasks. |
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
orzig clang
) that emulates the respective compiler's command-line interfaceSymbolic links
Symbolic links could be used to signal zig to run in a particular mode, i.e.
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.
The text was updated successfully, but these errors were encountered: