Get optimization mode currently compiling

There’s 4 of them:

    Debug,
    ReleaseSafe,
    ReleaseFast,
    ReleaseSmall,

And I wonder, how to get the mode we’re compiling, for example, in Rust you can determine the mode using cfg!(debug_assertions), how to do that in Zig without adding any options in build.zig?

const builtin = @import("builtin");
const mode = builtin.mode;

The type of builtin.mode is std.builtin.OptimizeMode:

Example usage:

4 Likes

Thank you mister