#When using zig as a drop in c / c++ compiler, does it support thin lto via the zig c++ -flto=thin
1 messages · Page 1 of 1 (latest)
I'm currently compiling godot with zig. Been doing so for a while. But as projects do, it is growing in size and fat lto has since outgrown my RAM capacity. Now I'm trying to use thin lto, but it keeps outgrowing my RAM capacity. Which makes me think it is not using thin lto :(
Ran zig to compile a hello world project and got this output in verbose debug mode:
Here is the simple hello world project
Ignore the long path for zig compilation. That is due to how I'm installing it. Just run:
ZIG_CC_LOG_LEVEL=debug zig c++ -v -O2 -flto=thin main.cpp hello.cpp -o hello_world_zig
Looking at the output, it looks like zig is only ever using fat lto. It doest not appear to use thin lto
Have I potentially found a bug? Or is there a different way I should be passing -flto=thin when comping with zig c++?
it looks like zigs lto flag is just a bool, if theres not one already an issue could probably be filed to support thin
is there any reason you need to be using lto?
By "outgrowing RAM capacity" do mean at compile, run, or link time?
Yes. I’m compiling the Godot game engine here with zig c++
https://github.com/Lange-Studios/godot-src
Godot has it documented that lto brings a a significant performance boost AND file size reduction. Which I can attest to from experience as well
Link time
well sure
but you dont have any performance if you cant even compile it :p
lol I was compiling prior with full lto. The project has been growing in size and full lto does not scale well. I’ll either need to:
- buy more ram
- Start aggressively apply cpp defines to disable Godot modules I don’t need. But that is less than ideal for general purpose usage.
- Thin LTO! :)
https://clang.llvm.org/docs/ThinLTO.html
haha but I appreciate the joke ;)
Or maybe I can click this link to download more ram? 👀😅
Does zig have an arg that indicates to pass a flag directly to clang rather than intercepting it by zig? Similar to how zig cc -z -some-arg passes -some-arg directly to ld.lld
``zig c++ -clang-arg,-flto=thin similar
not that i know of
theres zig clang but youre not meant to use it, iiuc its literally clang meaning you dont get any of zigs benefits
id open an issue about thin lto
Will do! Thanks! How complex would this be to implement myself? Assuming it takes to long for someone else to pick up? It seems like the easiest and most general purpose solution to future issues like this would be adding an arg to forward args directly to clang.
not sure, i saw that the lto option was just a bool even down to zigs llvm bindings but i didnt investigate if thats only in the bindings or the llvm api itself
so complexity could probably range from like 5 lines to possibly changing how some things interact with llvm, i really have no idea tho
Cool beans. I’ll open an issue then! :)
how about adding a feature to simply forward any arg if the preceding arg was something like “-clang-arg”? On surface, it sounds like that would be easy
i dont see anything wrong with that but at the same time i kinda feel it wouldve been done if it was desired
people have needed to add flags that zig doesnt expose plenty of times and something similar is already done to pass C flags on the normal zig CLI
at the same time i kinda feel it wouldve been done if it was desired
I desire it 😎
people have needed to add flags that zig doesnt expose plenty of times and something similar is already done to pass C flags on the normal zig CLI
How do you do this? Aren’t “normal c flags” just clang args? clang is the c compiler / cli right?
i meant the zig build-{exe,obj,lib} cli
Ah gotcha. Where should I start if I wanted to add an arg to “zig cc / c++” to forward the next arg to clang?
As in the zig codebase. Where are those args processed in “zig cc”
i couldnt really tell you, sorry. ive never looked into how zig cc passes args
No worries… I guess next step would be: how do I compile zig? I presume with zig. Are the compile instructions documented?
Brilliant! Thanks! :)
The cli parsing is done in src/main.zig, there's just a big loop that goes over argv (possibly inside a subcommand-specific function, just start reading through main()/search for the subcommand you're invoking and it should be relatively straightforward).