2zw
[root] / build.zig
const std = @import("std");
pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{ .preferred_optimize_mode = .ReleaseSmall });
const exe = b.addExecutable(.{
.name = "2zw",
.root_module = b.createModule(.{
.root_source_file = b.path("src/main.zig"),
.target = target,
.optimize = optimize,
}),
});
exe.root_module.strip = true;
exe.linkLibC();
exe.linkSystemLibrary("X11");
exe.linkSystemLibrary("Xrandr");
exe.linkSystemLibrary("Xft");
exe.linkSystemLibrary("Xext");
exe.linkSystemLibrary("z");
exe.linkSystemLibrary("png");
exe.linkSystemLibrary("expat");
if (target.result.os.tag == .openbsd) {
exe.addSystemIncludePath(lazyAbsolutePath("/usr/X11R6/include"));
exe.addLibraryPath(lazyAbsolutePath("/usr/X11R6/lib"));
exe.linkSystemLibrary("xcb");
exe.linkSystemLibrary("Xau");
exe.linkSystemLibrary("Xdmcp");
exe.linkSystemLibrary("Xrender");
exe.linkSystemLibrary("fontconfig");
exe.linkSystemLibrary("freetype");
}
b.installArtifact(exe);
const run_cmd = b.addRunArtifact(exe);
run_cmd.step.dependOn(b.getInstallStep());
if (b.args) |args| {
run_cmd.addArgs(args);
}
const run_step = b.step("run", "Run the app");
run_step.dependOn(&run_cmd.step);
const unit_tests = b.addTest(.{ .root_module = exe.root_module });
const run_unit_tests = b.addRunArtifact(unit_tests);
const test_step = b.step("test", "Run unit tests");
test_step.dependOn(&run_unit_tests.step);
}
fn lazyAbsolutePath(path: []const u8) std.Build.LazyPath {
if (@hasField(std.Build.LazyPath, "path")) {
return .{ .path = path };
} else if (@hasField(std.Build.LazyPath, "cwd_relative")) {
return .{ .cwd_relative = path };
} else {
@compileError("unsupported Zig std.Build.LazyPath layout; please update lazyAbsolutePath");
}
}