Hi, zig noob here.
I’m trying to use zig as a build system for my cpp project.
So i’m tinkering with build.zig, and I thought std.Build.standardTargetOptions would return the native os of the computer running the build command.
But I got aix instead of windows. I thought this is because I’m using mingw, so I also tried PowerShell and window’s defualt cmd, but nothing changed.
My build command is just zig build run nothing more. Also tried zig build -Dtarget=x86_64-windows, but it remains same.
When I checked os using builtin.os.tag, it returns windows.
Should I have to use builtin.os.tag instead of std.Build.standardTargetOptions().result.os.tag?
Then why standardTargetOptions even exists?
Here is my build.zig file.
const std = @import("std");
pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const mode = b.standardOptimizeOption(.{ .preferred_optimize_mode = .ReleaseFast });
const exe = b.addExecutable(.{
.name = "softy",
.target = target,
.optimize = mode,
});
exe.addCSourceFiles(.{ .files = &.{
"src/main.cpp",
}, .flags = &.{
"-std=c++23",
"-Wall",
"-Wextra",
"-Wshadow",
"-Wnon-virtual-dtor",
"-pedantic",
"-Wno-gnu-anonymous-struct",
"-Wno-nested-anon-types",
"-Wformat",
"-Wformat=2",
"-Wconversion",
"-Wimplicit-fallthrough",
"-Werror=format-security",
"-D_FORTIFY_SOURCE=3",
"-fstrict-flex-arrays=3",
"-fstack-clash-protection",
"-fstack-protector-strong",
"-fPIE",
} });
exe.addIncludePath(b.path("./src"));
exe.linkLibCpp();
switch (target.result.os.tag) {
.windows => {
exe.addCSourceFile(.{ .file = b.path("src/window/window_win32.cpp") });
exe.linkSystemLibrary("gdi32");
},
.linux => {},
.macos => {},
else => @compileError("Unsupported OS"),
}
b.installArtifact(exe);
const run_cmd = b.addRunArtifact(exe);
run_cmd.step.dependOn(b.getInstallStep());
const run_step = b.step("run", "Run the app");
run_step.dependOn(&run_cmd.step);
}