My build.zig:
const std = @import("std");
const Translator = @import("translate_c").Translator;
pub fn build(b: *std.Build) void {
const includePath = b.option([]const u8, "include", "Specify include path.");
const libPath = b.option([]const u8, "lib", "Specify lib path.");
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
const glMod = b.createModule(.{
.root_source_file = b.path("src/gl.zig"),
.target = target,
.optimize = optimize,
});
// Linking OpenGL differs between Windows and Linux.
switch (target.result.os.tag) {
.linux => {
glMod.linkSystemLibrary("GL", .{});
},
.windows => {
glMod.linkSystemLibrary("opengl32", .{});
},
else => {},
}
const translate_c = b.dependency("translate_c", .{
.target = target,
.optimize = optimize,
});
// SDL2
const sdlTranslate = Translator.init(translate_c, .{
.c_source_file = b.path("src/c/sdl.h"),
.target = target,
.optimize = optimize,
.link_system_libs = &.{
.{ .name = "SDL2" },
},
});
if (includePath) |path| {
sdlTranslate.addIncludePath(.{ .cwd_relative = path });
}
if (libPath) |path| {
sdlTranslate.mod.addLibraryPath(.{ .cwd_relative = path });
}
// stb_image.h
const stbiTranslate = Translator.init(translate_c, .{
.c_source_file = b.path("src/c/stb_image.h"),
.target = target,
.optimize = optimize,
});
stbiTranslate.mod.addCSourceFile(.{
.file = b.path("src/c/stbi.c"),
.flags = &.{"-std=c99"},
});
// Main exe
const exe = b.addExecutable(.{
.name = "ziggin",
.root_module = b.createModule(
.{
.root_source_file = b.path("src/main.zig"),
.target = target,
.optimize = optimize,
.imports = &.{
.{
.name = "gl",
.module = glMod,
},
.{
.name = "sdl",
.module = sdlTranslate.mod,
},
.{
.name = "stbi",
.module = stbiTranslate.mod,
},
},
},
),
});
// Use -mwindows when building in release mode.
if (target.result.os.tag == .windows and optimize != .debug) {
exe.subsystem = .windows;
}
b.installArtifact(exe);
const run_step = b.step("run", "Run the app");
const run_cmd = b.addRunArtifact(exe);
run_step.dependOn(&run_cmd.step);
run_cmd.step.dependOn(b.getInstallStep());
}
Do I really need to handle for null here?
if (includePath) |path| {
sdlTranslate.addIncludePath(.{ .cwd_relative = path });
}
if (libPath) |path| {
sdlTranslate.mod.addLibraryPath(.{ .cwd_relative = path });
}
It doesn’t resolve to false in the if statement when they are unset?