rakivo
July 23, 2024, 7:36pm
1
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
:
pub const OptimizeMode = enum {
Debug,
ReleaseSafe,
ReleaseFast,
ReleaseSmall,
};
Example usage:
/// Indicate that we are now terminating with a successful exit code.
/// In debug builds, this is a no-op, so that the calling code's
/// cleanup mechanisms are tested and so that external tools that
/// check for resource leaks can be accurate. In release builds, this
/// calls exit(0), and does not return.
pub fn cleanExit() void {
if (builtin.mode == .Debug) {
return;
} else {
std.debug.lockStdErr();
exit(0);
}
}
4 Likes