2zw

Owner: IIIlllIIIllI URL: git@git.0x00nyx.xyz:seb/2zw.git

build.zig

const std = @import("std");

pub fn build(b: *std.Build) void {
    const target = b.standardTargetOptions(.{});
    const optimize = b.standardOptimizeOption(.{});
    const exe = b.addExecutable(.{
        .name = "2zw",
        .root_source_file = b.path("src/main.zig"),
        .target = target,
        .optimize = optimize,
    });

    exe.linkLibC();
    exe.linkSystemLibrary("X11");
    exe.linkSystemLibrary("Xrandr");
    exe.linkSystemLibrary("Xft");

    if (target.result.os.tag == .openbsd) {
        exe.addSystemIncludePath(lazyAbsolutePath("/usr/X11R6/include"));
        exe.addLibraryPath(lazyAbsolutePath("/usr/X11R6/lib"));
    }
    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_source_file = b.path("src/main.zig"),
        .target = target,
        .optimize = optimize,
    });
    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");
    }
}