const std = @import("std");
const Builder = std.build.Builder;
const Step = std.build.Step;
const assert = std.debug.assert;
const mem = std.mem;
const ScanProtocolsStep = @import("deps/zig-wayland/build.zig").ScanProtocolsStep;
/// While a agertu release is in development, this string should contain
/// the version in development with the "-dev" suffix. When a release is
/// tagged, the "-dev" suffix should be removed for the commit that gets tagged.
/// Directly after the tagged commit, the version should be bumped and the "-dev"
/// suffix added.
const version = "2.O.0-dev";
pub fn build(b: *Builder) !void {
const target = b.standardTargetOptions(.{});
const mode = b.standardReleaseOptions();
const full_version = blk: {
if (mem.endsWith(u8, version, "-dev")) {
var ret: u8 = undefined;
const git_describe_long = b.execAllowFail(
&[_][]const u8{ "git", "-C", b.build_root, "describe", "--long" },
&ret,
.Inherit,
) catch break :blk version;
var it = mem.split(u8, mem.trim(u8, git_describe_long, &std.ascii.spaces), "-");
_ = it.next().?; // previous tag
const commit_count = it.next().?;
const commit_hash = it.next().?;
assert(it.next() == null);
assert(commit_hash[0] == 'g');
// Follow semantic versioning, e.g. 0.2.0-dev.42+d1cf95b
break :blk try std.fmt.allocPrintZ(b.allocator, version ++ ".{s}+{s}", .{
commit_count,
commit_hash[1..],
});
} else {
break :blk version;
}
};
const scanner = ScanProtocolsStep.create(b);
scanner.addSystemProtocol("stable/xdg-shell/xdg-shell.xml");
scanner.addProtocolPath("protocol/river-status-unstable-v1.xml");
scanner.addProtocolPath("protocol/wlr-layer-shell-unstable-v1.xml");
const exe = b.addExecutable("agertu", "src/main.zig");
exe.setTarget(target);
exe.setBuildMode(mode);
const options = b.addOptions();
options.addOption([]const u8, "version", full_version);
exe.addOptions("build_options", options);
exe.step.dependOn(&scanner.step);
exe.addPackagePath("ini", "common/ini.zig");
scanner.generate("wl_compositor", 4);
scanner.generate("wl_shm", 1);
scanner.generate("wl_output", 4);
scanner.generate("zwlr_layer_shell_v1", 4);
scanner.generate("zriver_status_manager_v1", 2);
const wayland = std.build.Pkg{
.name = "wayland",
.path = .{ .generated = &scanner.result },
};
exe.addPackage(wayland);
exe.linkLibC();
exe.linkSystemLibrary("wayland-client");
const pixman = std.build.Pkg{
.name = "pixman",
.path = .{ .path = "deps/zig-pixman/pixman.zig" },
};
exe.addPackage(pixman);
exe.linkSystemLibrary("pixman-1");
const fcft = std.build.Pkg{
.name = "fcft",
.path = .{ .path = "deps/zig-fcft/fcft.zig" },
.dependencies = &[_]std.build.Pkg{pixman},
};
exe.addPackage(fcft);
exe.linkSystemLibrary("fcft");
{
const tests = b.addTest("src/test_main.zig");
tests.setTarget(target);
tests.addPackage(wayland);
tests.addPackage(pixman);
tests.linkSystemLibrary("pixman-1");
tests.addPackage(fcft);
tests.linkSystemLibrary("fcft");
tests.setBuildMode(mode);
const test_step = b.step("test", "Run all tests");
test_step.dependOn(&tests.step);
}
// TODO: remove when https://github.com/ziglang/zig/issues/131 is implemented
scanner.addCSource(exe);
exe.install();
b.installFile("doc/agertu.1", "share/man/man1/agertu.1");
const run_cmd = exe.run();
run_cmd.step.dependOn(b.getInstallStep());
const run_step = b.step("run", "Run the app");
run_step.dependOn(&run_cmd.step);
}