Skip to content
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

Closed
marler8997 opened this issue Aug 17, 2019 · 5 comments
Closed
Labels
accepted This proposal is planned. contributor friendly This issue is limited in scope and/or knowledge of Zig internals. proposal This issue suggests modifications. If it also has the "accepted" label then it is planned. zig cc Zig as a drop-in C compiler feature
Milestone

Comments

@marler8997
Copy link
Contributor

marler8997 commented Aug 17, 2019

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.

@andrewrk andrewrk added this to the 0.6.0 milestone Aug 18, 2019
@andrewrk andrewrk added the proposal This issue suggests modifications. If it also has the "accepted" label then it is planned. label Aug 18, 2019
@marler8997
Copy link
Contributor Author

Transferring discussion to this thread (#3102 (comment))

The current question is, what is the equivalent of -o on the zig comand-line?

@andrewrk
Copy link
Member

The current question is, what is the equivalent of -o on the zig comand-line?

There isn't one. That would be one of the problems to solve for this issue.

@andrewrk andrewrk changed the title C command-line mode use case: ability to use zig as a drop-in replacement for a C compiler Aug 21, 2019
@andrewrk andrewrk added the accepted This proposal is planned. label Nov 27, 2019
@andrewrk andrewrk added the contributor friendly This issue is limited in scope and/or knowledge of Zig internals. label Jan 27, 2020
@mikdusan
Copy link
Member

Andrew just did a stream on this issue: https://www.twitch.tv/videos/571523138

note: unsure how long that link will remain valid

@daurnimator
Copy link
Contributor

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

@andrewrk
Copy link
Member

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.

@andrewrk andrewrk added the zig cc Zig as a drop-in C compiler feature label Mar 22, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
accepted This proposal is planned. contributor friendly This issue is limited in scope and/or knowledge of Zig internals. proposal This issue suggests modifications. If it also has the "accepted" label then it is planned. zig cc Zig as a drop-in C compiler feature
Projects
None yet
Development

No branches or pull requests

4 participants