-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Add support for zig cc
as C compiler.
#13757
Conversation
Why does this feature exist in Zig? Does it allow you to easily compile Zig and C code in the same project (and potentially Nim and Zig code now)? |
I can imagine a number of philosophical and practical reasons in addition to what you mention. Zig already ships with LLVM for code generation, so including Clang is not a big deal. At the same time one of Zig's aims is to make cross-compilation easy, so it bundles the stdlib for a whole bunch of targets, which it can compile on demand, thanks to the bundled Clang. @andrewrk can give you the definitive answer. The use case of compiling Zig and Nim together is not something I had considered but, given Nim compiles to C, it should be fairly feasible. |
Hi 👋 I'm responding to a request from zahary on IRC to explain a little bit about this. The reason the zig compiler has a C compiler in it is the following reasoning:
So yes it is just clang doing the compilation, and LLD doing the linking. But the main benefit that zig brings here is that has no system dependencies, so it will "just work" everywhere. (Also the cross compiling stuff which was noted above) more details on this blog post If Nim wants to explore this possibility, I would be happy to coordinate! |
@juancarlospaco tinyc is not really comparable to Zig. Zig compiler uses LLVM for both C and Zig, so it's basically on the same level for C code as Clang |
Won't there be an additional burden to maintain the Zig cc compatibility and regression testing? |
@ksandvik no one says it will be default, Nim supports quite a lot of compilers but most of them aren't really tested, see for example https://github.com/nim-lang/Nim/blob/devel/compiler/extccomp.nim#L94 or https://github.com/nim-lang/Nim/blob/devel/compiler/extccomp.nim#L215 or https://github.com/nim-lang/Nim/blob/devel/compiler/extccomp.nim#L242 The only tested compilers are Clang, GCC, and VCC really, all others are mostly community-supported (if someone uses them and finds a but they might fix it, etc) |
There is a better way to do this but the PR follows the existing practice so it's fine. Will be merged after 1.2 is out. |
Why not just merge now? This PR isn't likely to break anything. |
@hessammehr is this supposed to work as-is or would I need additional compilation flags to pass to nim / zig?
ditto with |
What version of zig are you using? |
@timotheecour did you download the latest master from there? |
FWIW, 0.6.0 is scheduled to be released on Monday. |
i did |
What would be the command to compile
And when I run
|
I believe |
@hessammehr Thanks, now it tries to compile the file containing
It seems, that this doesn't work on linux too: https://forum.nim-lang.org/t/5939#38185 (similiar or same error like mine) |
This goes beyond my knowledge of how the nim compiler works but it seems like the C code produced in this case is different, since compiling it with clang gives the same error.
|
Ok, thanks, so I guess it's not a problem with zig. |
@Tim-St I think I have a fix for your issue. Probably best if you open a new issue since this PR has been closed. |
@hessammehr @andrewrk I've retried now that zig 0.6.0 was released but I'm now hitting 'Unable to find target for this triple (no targets are registered)', see ziglang/zig#5055 ; any idea how to use it on OSX? |
With the upcoming release of Zig 0.6,
zig cc
can be used as a convenient and portable cross-compiler and a drop-in replacement for clang. This PR allows Nim to use Zig as its C compiler using--cc=zig
. Further, you can easily cross-compile like so: