#Build specific code

1 messages · Page 1 of 1 (latest)

leaden cargo
#

Is there way to tell zig, code should only specific builds, say i only want something in a dedug build, or a windows build
Say this function here, on a release build this would call the log function, but will the call still be there or is optimise out completely.
I can not make the if comptime if as log function prints to console and does file io, so can not be called at comptine it self

    pub fn trace(comptime message: []const u8, args: anytype) void {
        if (debugBuild) {
            log(LogLevel.TRACE, message, args);
        }
    }

For platform I am guessing if i do something like this, only one file is being imported, there for only on of them is being built as this should run at comptime

    const platformType = switch (builtin.os.tag) {
        .linux => @import("linux.zig").PlatformLinux,
        .windows => @import("windows.zig").PlatformWindow,
        .macos => @import("glfw.zig").PlatformGLFW,
        else => @compileError("Unsupported platform"),
    };

teal dragon
#

all ifs and switches of comptime-known values branch at comptime regardless of whether it is in a comptime or runtime scope

nova jewel
#

i think if you want to guarantee it's comptime, you could do if (comptime debugBuild), which will give you an error if debugBuild is not comptime-known