File for Divorce from LLVM · Issue #16270 · ziglang/zig · GitHub
source link: https://github.com/ziglang/zig/issues/16270
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
File for Divorce from LLVM #16270
2 of 19 tasks
andrewrk opened this issue Jun 29, 2023 · 21 comments
2 of 19 tasks
File for Divorce from LLVM #16270
andrewrk opened this issue Jun 29, 2023 · 21 comments
Comments
Member
I'm sorry honey, it's just not working out. Our relationship worked when we were younger, but we're both older now and we've grown apart. This issue is to fully eliminate LLVM, Clang, and LLD libraries from the Zig project. The remaining ties to these projects are as follows: This will remove C++, Objective-C, and Objective-C++ compilation capabilities from Zig. In the near term, the machine code generated by Zig will become less competitive. Long-term, it may catch up or even surpass LLVM and GCC. In the near term it would also reduce the number of targets Zig supports, since LLVM has a nice laundry list. However, LLVM supports fewer targets than you think... we are constantly running into bugs and embarrassing O(N^2) code for pretty much every target except x86, aarch64, and webassembly. Long-term, Zig plans to have Contributor-Friendly IR, or something equivalent, to optimize for low maintenance for supporting many targets that LLVM would never even dream of, for example MOS #6502. Note that there would still be an LLVM backend for outputting In exchange, Zig gains these benefits:
|
added the proposal This issue suggests modifications. If it also has the "accepted" label then it is planned. label
Contributor
I see the 1.0.0 milestone for this, is it meant to be a blocker for 1.0? or simply the goal |
Member
Author
The milestone, on an issue labeled "proposal", means that a decision must be made to accept or reject that proposal before tagging the release corresponding to that milestone. For an issue labeled "accepted", the milestone means that it must be implemented by then. So, if this proposal is accepted, then I will evaluate at that time which milestone to move it to. |
Contributor
IMO, this is the biggest question. One of the most compelling reasons to use Zig is runtime performance of software written in Zig. Without LLVM's optimization passes, what will that look like? |
Contributor
Zig will continue to implement optimization passes of its own over time and get faster. |
Sponsor
Contributor
So here the projects that depend on the ability to compile C++ that I currently developing:
And also some NDA game platform that have C++ only API that will require some C++-to-C glue code to be compiled, but obviously not implemented. To me, the ability to seamlessly build any C, C++ and Obj-C is a big selling point of the Zig toolchain even if it is behind a optional flag to enable LLVM and Clang when compiling Zig. A part of the hype momentum around Zig is due to that fact. If this happens, I think I will remove my donation to the Zig Software Foundation. TL;DR: Lots of libraries in the game development world (closed or open source) require the ability to compile C++. |
Contributor
I think this proposal would hurt the Zig ecosystem more than it would help it, due to several reasons:
Imho, this proposal strongly violates the
idea, as the current direction we're heading is a really good unified native build environment based on a single static executable that can serve projects in arbitrar, sizes, shipping compilers for several major languages, a huge ass support for targets and a build system, making work in systems programming fun, even if one doesnt use Zig as a language. We are on a good way to replace a huge list of tools with a single executable, making contributions to projects build on Zig fun, easy and platform independent. When this proposal is accepted, in addition to Zig one will need to have the following tools installed:
We can potentially replace all of those tools wit a single, equally powerful executable, making the live easier for all native devs out there personal projects that would be affected: |
I'm still a beginner I believe, but if it is at all worth it for me to give my point of view, Zig's ability to replace all of the build tools mentioned above is a big reason I was interested in Zig in the first place. I struggled a lot with all the different build systems and Zig is a really refreshing breath of fresh air. I have two personal projects that use zgui heavily and I had planned on continuing. |
Sponsor
Contributor
With Mach engine we have two dependencies that would be very, very painful to remove (would set us back years):
It will be a long time before Zig's SPIRV backend is capable enough to generate non-GPGPU shaders for graphics APIs (if ever, since it would likely require major language changes) - so I don't see a way for us to escape these aside from replicating what these two projects -- LLVM forks -- do on our side. Every other C++ dependency I believe we could safely escape from. |
Sponsor
Contributor
A positive long-term effect of this change is that it would push us as a community away from wrapping C++ code and towards more pure-Zig solutions. Many of the comments in this thread are about people using zgui, wwise, zig-gamedev, assimp, and other C++ libraries wrapped with Zig. It gives you a leg up in the short term, but I worry in the long-term that people's gamedev experiences coming to Zig will be 'initially I saw a nice language... then I encountered the guts of the libraries I was told to use were large, clunky C++ codebases' |
Also a beginner, but I think being able to use Zig as a C++ build system (which is what I use for all my private C++ projects) is an invaluable feature to me and I believe many other people. The simplicity of Zig, having a compiler and a build system contained within a single executable (with the added bonus of being easily cross platform), is really cool, and it would be kinda unfortunate to see that feature be removed as an effect of removing clang and friends. However, if this does go through, the ability to fallback to generating |
Contributor
One of my friends pointed out that nothing stops you from invoking clang in a build.zig to compile C++ dependencies, even if Zig stops including clang. I wonder how much of a problem that would really be for these projects? |
Contributor
doing that would be an additional dependency without the ease of zigs cross compilation |
Contributor
Hmm, the more I think about this proposal the less I like it. I'm feeling it would be better to make the LLVM backend non-default (that is, switch |
I think I can speak for all gamedevs by saying that removing C++ compilation would be a disaster. Too many amazing existing gamedev libraries and tools are built on C++ that disallowing easy use would strangle adoption in that field, as well as complicate existing projects. dear imgui is the obvious example but it's not the only one. |
It's easy to imagine that in the long term, this change will push us towards "rewrite it in zig" with all the benefits that would entail, but the downside is that the existing corpus becomes inaccessible; limiting our options heavily even once zigs ecosystem matures |
Contributor
I think llvm is needed until ecosystem of pure-zig library is very very mature and rich. Yeah we want faster compiling speed and smaller tarball, but not at the risk of losing one-zig-to-rule-all. |
I love the ambition of this proposal, but to reiterate what has already been stated, losing c++ compilation would be losing one of the main selling points of zig. I was drawn to zig in part because it reduces the hellishness of depending on c/c++ projects. Zig having a c++ compiler inside it also has the benefit of there being less c++ to have to deal with, less python to have to deal with, less cmake to have to deal with. On the other hand, the core of this proposal has too many benefits for it to be rejected entirely. I think reducing the scope would be beneficial. How about:
|
Contributor
I totally get the desire to get rid of huge third-party dependencies that bring a lot of baggage. There's also something to be said for avoiding an LLVM monoculture in the programming language space. Even so, I see this as a net negative for users. What drew me to Zig in the first place was the pragmatic approach of acknowledging that there is a world outside of Zig that needs to be interoperated with for the foreseeable future and even providing a best-in-class cross-compilation experience along with that. I built my project integrating Zig build support with the .NET/MSBuild ecosystem on that selling point. On the whole, I think this proposal would be an unfortunate (if well-intentioned) bait-and-switch, considering the Zig website for a while has advertised this: In addition, these blog posts drove a lot of attention to Zig in the past: Just to be super clear: I don't mean to insinuate bad faith or anything of the sort here. But I think it's fair to say that you have to contend with the fact that this proposal would pull features that are not only usable today, but are also prominently advertised. All that said... assuming this is even remotely practical, maybe there's a potential middle ground: Would it be possible for Zig to continue to use the Clang frontend to provide C-family support, but rip out the LLVM IR lowering and replace it with lowering to ZIR/AIR? (I guess this is more or less how Aro would be integrated too?) If this could be done, the codegen dependency on LLVM could be killed, achieving at least some of the goals of this proposal. There's probably also no reason to keep LLD support around as long as zld can catch up, so that eventually goes too. And users remain happy. Some of the build and distro woes would remain, of course, but, that's compromise. |
Contributor
I’m fully in favor of making it possible to use Zig without any LLVM components, but I agree with many of the comments here that it’s important for Zig to maintain the capabilities that it currently has in terms of cross-compilation, compiling C/C++ code seamlessly, and generating maximally performant binaries. These factors are big drivers of Zig’s adoption, and I fear that damaging them (even temporarily as in the case of code generation quality) would seriously hurt Zig’s future. Personally, I work in the robotics space, where C++ is the dominant language for many libraries and frameworks. I think Zig has a lot of potential in this space, but being able to integrate with existing libraries is absolutely essential for adoption. |
Sponsor
Contributor
Is there a story in this proposal for JIT compilation? I have a Zig project with currently relies on LLVM's Orc to JIT-compile audio DSP functions. I'm not particularly stoked about or attached to Orc itself, but it does give me in-process compilation with low-milliseconds latency, something I'd need for dynamic real-time audio applications. WebAssembly would not be an issue here because I wrote the Wasm compiler myself, but for x86_64 and friends I would need a replacement. Passing LLVM bitcode to a separate process might work but would feel like a downgrade. Vendoring and embedding the Zig compiler source might be the best option in that case. (Aside: I have started work on reading and writing LLVM bitcode from Zig, and if this is accepted would be happy to resume work on that.) |
Sponsor
Contributor
I'll start by stating my opinion: the C language frontends are super important to me for Zig to maintain. I agree with others on the point that Zig being a C/C++ compiler is a big point of attraction that brought me to the language. I started with loving that idea, and ultimately fell in the love with the language, and now I use both. I don't have anything more to add to that that the others above haven't. I'll add my own personal experience. I have many personal Zig projects, but my biggest one that people tend to know about in the community is my terminal emulator. There are two important dependencies that would be impacted by this:
Andrew, your dislike of C++ is well known! I don't love it either (to put it kindly). If, as an audacious goal, you wanted Zig to lower C++ usage, I think Zig being able to compile existing projects and enable iterative migration away from C++ to Zig is the way to do it. I think if Zig doesn't support C++, the C++ "people" would just avoid Zig altogether. |
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK