#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)

hexed void
#

From what I can tell, its always using fat lto even tho I'm specifically passing it -flto=thin

#

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 :(

hexed void
#

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++?

loud valley
#

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?

mystic gale
#

By "outgrowing RAM capacity" do mean at compile, run, or link time?

hexed void
loud valley
hexed void
#

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

loud valley
#

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

hexed void
#

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.

loud valley
#

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

hexed void
#

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

loud valley
#

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

hexed void
#

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?

loud valley
#

i meant the zig build-{exe,obj,lib} cli

hexed void
#

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”

loud valley
#

i couldnt really tell you, sorry. ive never looked into how zig cc passes args

hexed void
#

No worries… I guess next step would be: how do I compile zig? I presume with zig. Are the compile instructions documented?

hexed void
#

Brilliant! Thanks! :)

green lava
#

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).