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

When the compiler is built without LLVM, use Aro to compile C code instead of Clang #16269

Closed
andrewrk opened this issue Jun 29, 2023 · 3 comments
Labels
enhancement Solving this issue will likely involve adding new logic or components to the codebase. 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

@andrewrk
Copy link
Member

andrewrk commented Jun 29, 2023

After solving #16268 which is a prerequisite to this issue, this issue is to further reduce dependency on Clang by using Aro to compile .c files.

I suggest, at least at first, this happens by taking advantage of translate-c, and then passing the outputted .zig code through the full pipeline. I experimented a bit with upstreaming Aro in #10795 in which I attempted to lower C AST to AIR, and this was my conclusion:

I'm starting to wonder... should we perhaps lower to ZIR instead of AIR? The integration would be a lot less messy, and it's much more obvious how to parallelize it. One .c file would produce exactly one corresponding ZIR file. 🤔🤔🤔

So the two options I think are worth exploring:

  1. C code => Aro C AST => Translate C AST => zig source code
  2. From there, potentially give an additional lowering to Translate C AST:
    • => zig source code
    • => ZIR

Another possibility would be straight from Aro C AST to ZIR. There could be additional C-specific ZIR instructions added if necessary.

@andrewrk andrewrk added enhancement Solving this issue will likely involve adding new logic or components to the codebase. contributor friendly This issue is limited in scope and/or knowledge of Zig internals. breaking Implementing this issue could cause existing code to no longer compile or have different behavior. zig cc Zig as a drop-in C compiler feature labels Jun 29, 2023
@andrewrk andrewrk added this to the 0.14.0 milestone Jun 29, 2023
@andrewrk andrewrk added proposal This issue suggests modifications. If it also has the "accepted" label then it is planned. and removed contributor friendly This issue is limited in scope and/or knowledge of Zig internals. labels Jul 3, 2023
@ecstrema
Copy link

Just to be clear, what would be the benefits of using Aro instead of clang? Is it faster, is it because having everything in the same language is best for maintenance? Is it because Aro has some features Clang does not have?

Or is it for zig to become completely self-sufficient, and remove any dependency on code not written in zig?

@andrewrk
Copy link
Member Author

andrewrk commented Sep 26, 2023

The main benefit of using Aro instead of Clang is that it does not depend on Clang and LLVM, which are massive, problematic dependencies for many reasons. According to #16270, the plan is to depend on a third party package that does use LLVM and Clang for compiling C and C++ code in a fully clang-compatible manner, however, we still want a Zig binary that does not link against LLVM to be able to support, for example, -target x86_64-linux-musl -lc, which requires the ability to compile musl libc from source. For that we need a C compiler, but we do not need Clang.

There is also a plan to start converting the libc C code to Zig code: #2879

@andrewrk andrewrk changed the title use Aro to compile C code instead of clang When the compiler is built without LLVM, use Aro to compile C code instead of Clang Sep 26, 2023
@andrewrk andrewrk removed the breaking Implementing this issue could cause existing code to no longer compile or have different behavior. label Sep 26, 2023
@andrewrk andrewrk modified the milestones: 0.16.0, 0.14.0 Jul 20, 2024
@andrewrk
Copy link
Member Author

Instead, we will pursue #2879, untangling the Zig compiler entirely from C/C++. Dealing with the C/C++ ecosystem will move fully to the build system. An Aro package can compete with a Clang package to provide equivalent functionality.

@andrewrk andrewrk closed this as not planned Won't fix, can't repro, duplicate, stale Jul 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Solving this issue will likely involve adding new logic or components to the codebase. 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

2 participants