What commands --release=fast does under the hood?

Hello, I want to know what commands “zig build –release=fast” runs under the hood. I searched in the docs but couldn’t find an explanation about it

Does it activate –march=native?

Does it activate –fast-math?

Etc, what are the raw commands that it runs under the hood?

--release sets the optimise mode gotten from b.standardOptimizeOption().

The difference from -Doptimize is that doesn’t propagate to dependencies unless passed explicitly, whereas --release does propagate.

You can use --verbose to see the commands executed by the build system.

It says it runs -OReleaseFast. What detailed optimization commands does -OReleaseFast run under the hood?

[tes]# zig build --release=fast --verbose
/root/system/bin/zig/zig build-exe -OReleaseFast --dep tes -Mroot=/root/tes/src/main.zig -Mtes=/root/tes/src/root.zig --cache-dir .zig-cache --global-cache-dir /root/.cache/zig --name tes --zig-lib-dir /root/system/bin/zig/lib/ --listen=-
install -C .zig-cache/o/c2fc5de5d59f82301f79d77dd866798c/tes /root/tes/zig-out/bin/tes

There isn’t any commands under that, zig includes a copy of LLVM/clang in itself which it calls directly.

It isn’t documented what clang flags it is equivalent to, and it certainly has/probably will change.

You’d have to look at the source, IDK where it calls clang.

Actually --verboce-cc exists, it might help, but I have a feeling it only applies to zig cc commands which your specific case doesn’t seem to be calling.

Try it anyway, I might be wrong.

The Zig compiler, when seeing ReleaseFast, adds -O2 to C compiler invocations. Also, the standard library and the compiler will omit some safety check code and debugging code. There may be some optimizations I missed. To -march=native, you need to set mcpu to native.

Marginally off-topic, but -Doptimize=ReleaseFast etc should usually be preferred over --release, see Tricks to improve optimization level? - #6 by squeek502

4 Likes