zig-river-init/build.zig
2025-01-03 13:37:31 -06:00

91 lines
2.9 KiB
Zig

const std = @import("std");
const Scanner = @import("wayland").Scanner;
const path = @import("src/path.zig");
pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
const rivertile = b.option([]const u8, "rivertile", "path to rivertile binary") orelse rivertile: {
const p = path.expandPath(b.allocator, "rivertile") catch {
break :rivertile "rivertile";
} orelse {
break :rivertile "rivertile";
};
break :rivertile p;
};
const fuzzel = b.option([]const u8, "fuzzel", "path to fuzzel binary") orelse fuzzel: {
const p = path.expandPath(b.allocator, "fuzzel") catch {
break :fuzzel "fuzzel";
} orelse {
break :fuzzel "fuzzel";
};
break :fuzzel p;
};
const gdbus = b.option([]const u8, "gdbus", "path to gdbus binary") orelse gdbus: {
const p = path.expandPath(b.allocator, "gdbus") catch {
break :gdbus "gdbus";
} orelse {
break :gdbus "gdbus";
};
break :gdbus p;
};
const build_options = b.addOptions();
build_options.addOption([]const u8, "rivertile", rivertile);
build_options.addOption([]const u8, "fuzzel", fuzzel);
build_options.addOption([]const u8, "gdbus", gdbus);
const scanner = Scanner.create(b, .{});
const wayland = b.createModule(.{ .root_source_file = scanner.result });
scanner.addCustomProtocol("src/river/river-control-unstable-v1.xml");
scanner.addCustomProtocol("src/river/river-status-unstable-v1.xml");
scanner.generate("wl_output", 4);
scanner.generate("wl_seat", 7);
scanner.generate("zriver_control_v1", 1);
scanner.generate("zriver_status_manager_v1", 1);
const exe = b.addExecutable(.{
.name = "init",
.root_source_file = b.path("src/main.zig"),
.target = target,
.optimize = optimize,
});
exe.root_module.addOptions("build_options", build_options);
exe.root_module.addImport("wayland", wayland);
exe.linkSystemLibrary2("wayland-client", .{});
exe.linkLibC();
scanner.addCSource(exe);
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 exe_unit_tests = b.addTest(.{
.root_source_file = b.path("src/main.zig"),
.target = target,
.optimize = optimize,
});
const run_exe_unit_tests = b.addRunArtifact(exe_unit_tests);
// Similar to creating the run step earlier, this exposes a `test` step to
// the `zig build --help` menu, providing a way for the user to request
// running the unit tests.
const test_step = b.step("test", "Run unit tests");
test_step.dependOn(&run_exe_unit_tests.step);
}