2020-04-12 04:37:18 -07:00
|
|
|
const std = @import("std");
|
2021-03-22 05:16:24 -07:00
|
|
|
const assert = std.debug.assert;
|
2021-03-22 03:54:02 -07:00
|
|
|
const fs = std.fs;
|
2021-03-22 05:16:24 -07:00
|
|
|
const mem = std.mem;
|
2020-11-03 15:23:21 -08:00
|
|
|
const zbs = std.build;
|
2020-03-19 08:29:22 -07:00
|
|
|
|
2020-11-02 04:59:59 -08:00
|
|
|
const ScanProtocolsStep = @import("deps/zig-wayland/build.zig").ScanProtocolsStep;
|
|
|
|
|
2021-07-24 02:31:17 -07:00
|
|
|
/// While a river 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.
|
2023-01-01 16:55:16 -08:00
|
|
|
const version = "0.3.0-dev";
|
2021-07-24 02:31:17 -07:00
|
|
|
|
2020-11-03 15:23:21 -08:00
|
|
|
pub fn build(b: *zbs.Builder) !void {
|
2020-03-19 08:29:22 -07:00
|
|
|
const target = b.standardTargetOptions(.{});
|
|
|
|
const mode = b.standardReleaseOptions();
|
|
|
|
|
2022-05-22 06:25:38 -07:00
|
|
|
const strip = b.option(bool, "strip", "Omit debug information") orelse false;
|
|
|
|
const pie = b.option(bool, "pie", "Build a Position Independent Executable") orelse false;
|
|
|
|
|
2020-06-15 04:16:38 -07:00
|
|
|
const man_pages = b.option(
|
|
|
|
bool,
|
|
|
|
"man-pages",
|
|
|
|
"Set to true to build man pages. Requires scdoc. Defaults to true if scdoc is found.",
|
2020-06-15 05:22:09 -07:00
|
|
|
) orelse scdoc_found: {
|
|
|
|
_ = b.findProgram(&[_][]const u8{"scdoc"}, &[_][]const u8{}) catch |err| switch (err) {
|
|
|
|
error.FileNotFound => break :scdoc_found false,
|
|
|
|
else => return err,
|
|
|
|
};
|
|
|
|
break :scdoc_found true;
|
|
|
|
};
|
2020-06-15 04:16:38 -07:00
|
|
|
|
2021-03-13 08:54:15 -08:00
|
|
|
const bash_completion = b.option(
|
|
|
|
bool,
|
|
|
|
"bash-completion",
|
|
|
|
"Set to true to install bash completion for riverctl. Defaults to true.",
|
|
|
|
) orelse true;
|
|
|
|
|
2021-03-13 08:06:39 -08:00
|
|
|
const zsh_completion = b.option(
|
|
|
|
bool,
|
|
|
|
"zsh-completion",
|
|
|
|
"Set to true to install zsh completion for riverctl. Defaults to true.",
|
|
|
|
) orelse true;
|
|
|
|
|
2021-03-16 08:16:47 -07:00
|
|
|
const fish_completion = b.option(
|
|
|
|
bool,
|
|
|
|
"fish-completion",
|
|
|
|
"Set to true to install fish completion for riverctl. Defaults to true.",
|
|
|
|
) orelse true;
|
|
|
|
|
2021-10-11 03:44:46 -07:00
|
|
|
const xwayland = b.option(
|
|
|
|
bool,
|
|
|
|
"xwayland",
|
|
|
|
"Set to true to enable xwayland support",
|
|
|
|
) orelse false;
|
|
|
|
|
2021-07-24 02:31:17 -07:00
|
|
|
const full_version = blk: {
|
|
|
|
if (mem.endsWith(u8, version, "-dev")) {
|
|
|
|
var ret: u8 = undefined;
|
2022-05-16 13:34:43 -07:00
|
|
|
|
|
|
|
const git_describe_long = b.execAllowFail(
|
|
|
|
&[_][]const u8{ "git", "-C", b.build_root, "describe", "--long" },
|
2021-07-24 02:31:17 -07:00
|
|
|
&ret,
|
|
|
|
.Inherit,
|
|
|
|
) catch break :blk version;
|
2022-05-16 13:34:43 -07:00
|
|
|
|
|
|
|
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..],
|
2021-11-02 15:54:44 -07:00
|
|
|
});
|
2021-07-24 02:31:17 -07:00
|
|
|
} else {
|
|
|
|
break :blk version;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-10-11 03:44:46 -07:00
|
|
|
const options = b.addOptions();
|
|
|
|
options.addOption(bool, "xwayland", xwayland);
|
|
|
|
options.addOption([]const u8, "version", full_version);
|
|
|
|
|
2020-11-03 15:23:21 -08:00
|
|
|
const scanner = ScanProtocolsStep.create(b);
|
|
|
|
scanner.addSystemProtocol("stable/xdg-shell/xdg-shell.xml");
|
2021-12-29 20:27:50 -08:00
|
|
|
scanner.addSystemProtocol("staging/ext-session-lock/ext-session-lock-v1.xml");
|
2021-02-14 10:32:04 -08:00
|
|
|
scanner.addSystemProtocol("unstable/pointer-gestures/pointer-gestures-unstable-v1.xml");
|
2021-02-15 12:07:29 -08:00
|
|
|
scanner.addSystemProtocol("unstable/pointer-constraints/pointer-constraints-unstable-v1.xml");
|
2020-11-02 04:59:59 -08:00
|
|
|
scanner.addProtocolPath("protocol/river-control-unstable-v1.xml");
|
2020-11-03 15:23:21 -08:00
|
|
|
scanner.addProtocolPath("protocol/river-status-unstable-v1.xml");
|
2021-07-15 04:22:37 -07:00
|
|
|
scanner.addProtocolPath("protocol/river-layout-v3.xml");
|
2020-11-03 15:23:21 -08:00
|
|
|
scanner.addProtocolPath("protocol/wlr-layer-shell-unstable-v1.xml");
|
|
|
|
scanner.addProtocolPath("protocol/wlr-output-power-management-unstable-v1.xml");
|
2020-04-12 04:37:18 -07:00
|
|
|
|
2022-05-09 12:56:28 -07:00
|
|
|
// These must be manually kept in sync with the versions wlroots supports
|
2022-06-03 14:31:07 -07:00
|
|
|
// until wlroots gives the option to request a specific version.
|
2022-05-09 12:56:28 -07:00
|
|
|
scanner.generate("wl_compositor", 4);
|
|
|
|
scanner.generate("wl_subcompositor", 1);
|
|
|
|
scanner.generate("wl_shm", 1);
|
|
|
|
scanner.generate("wl_output", 4);
|
|
|
|
scanner.generate("wl_seat", 7);
|
|
|
|
scanner.generate("wl_data_device_manager", 3);
|
|
|
|
|
|
|
|
scanner.generate("xdg_wm_base", 2);
|
|
|
|
scanner.generate("zwp_pointer_gestures_v1", 3);
|
|
|
|
scanner.generate("zwp_pointer_constraints_v1", 1);
|
2021-12-29 20:27:50 -08:00
|
|
|
scanner.generate("ext_session_lock_manager_v1", 1);
|
2022-05-09 12:56:28 -07:00
|
|
|
|
|
|
|
scanner.generate("zriver_control_v1", 1);
|
2022-12-01 12:05:14 -08:00
|
|
|
scanner.generate("zriver_status_manager_v1", 4);
|
2022-08-14 07:34:18 -07:00
|
|
|
scanner.generate("river_layout_manager_v3", 2);
|
2022-05-09 12:56:28 -07:00
|
|
|
|
|
|
|
scanner.generate("zwlr_layer_shell_v1", 4);
|
|
|
|
scanner.generate("zwlr_output_power_manager_v1", 1);
|
|
|
|
|
2020-05-19 09:22:22 -07:00
|
|
|
{
|
2020-06-01 06:56:50 -07:00
|
|
|
const river = b.addExecutable("river", "river/main.zig");
|
2020-05-19 09:22:22 -07:00
|
|
|
river.setTarget(target);
|
|
|
|
river.setBuildMode(mode);
|
2021-10-11 03:44:46 -07:00
|
|
|
river.addOptions("build_options", options);
|
2020-04-12 04:37:18 -07:00
|
|
|
|
2020-11-03 15:23:21 -08:00
|
|
|
addServerDeps(river, scanner);
|
2020-04-08 15:05:28 -07:00
|
|
|
|
2022-05-22 06:25:38 -07:00
|
|
|
river.strip = strip;
|
|
|
|
river.pie = pie;
|
2020-05-19 09:22:22 -07:00
|
|
|
river.install();
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2020-06-01 06:56:50 -07:00
|
|
|
const riverctl = b.addExecutable("riverctl", "riverctl/main.zig");
|
2020-05-19 09:22:22 -07:00
|
|
|
riverctl.setTarget(target);
|
|
|
|
riverctl.setBuildMode(mode);
|
2021-10-11 03:44:46 -07:00
|
|
|
riverctl.addOptions("build_options", options);
|
2020-05-19 09:22:22 -07:00
|
|
|
|
2020-11-02 04:59:59 -08:00
|
|
|
riverctl.step.dependOn(&scanner.step);
|
2021-07-24 10:31:04 -07:00
|
|
|
riverctl.addPackagePath("flags", "common/flags.zig");
|
2021-10-11 03:44:46 -07:00
|
|
|
riverctl.addPackage(.{
|
|
|
|
.name = "wayland",
|
2022-11-04 16:29:51 -07:00
|
|
|
.source = .{ .generated = &scanner.result },
|
2021-10-11 03:44:46 -07:00
|
|
|
});
|
2020-05-19 09:22:22 -07:00
|
|
|
riverctl.linkLibC();
|
|
|
|
riverctl.linkSystemLibrary("wayland-client");
|
|
|
|
|
2020-11-02 04:59:59 -08:00
|
|
|
scanner.addCSource(riverctl);
|
|
|
|
|
2022-05-22 06:25:38 -07:00
|
|
|
riverctl.strip = strip;
|
|
|
|
riverctl.pie = pie;
|
2020-05-19 09:22:22 -07:00
|
|
|
riverctl.install();
|
|
|
|
}
|
|
|
|
|
2020-06-16 05:48:30 -07:00
|
|
|
{
|
|
|
|
const rivertile = b.addExecutable("rivertile", "rivertile/main.zig");
|
|
|
|
rivertile.setTarget(target);
|
|
|
|
rivertile.setBuildMode(mode);
|
2021-10-11 03:44:46 -07:00
|
|
|
rivertile.addOptions("build_options", options);
|
2020-10-02 06:53:08 -07:00
|
|
|
|
|
|
|
rivertile.step.dependOn(&scanner.step);
|
2021-07-24 09:29:48 -07:00
|
|
|
rivertile.addPackagePath("flags", "common/flags.zig");
|
2021-10-11 03:44:46 -07:00
|
|
|
rivertile.addPackage(.{
|
|
|
|
.name = "wayland",
|
2022-11-04 16:29:51 -07:00
|
|
|
.source = .{ .generated = &scanner.result },
|
2021-10-11 03:44:46 -07:00
|
|
|
});
|
2020-10-02 06:53:08 -07:00
|
|
|
rivertile.linkLibC();
|
|
|
|
rivertile.linkSystemLibrary("wayland-client");
|
|
|
|
|
|
|
|
scanner.addCSource(rivertile);
|
|
|
|
|
2022-05-22 06:25:38 -07:00
|
|
|
rivertile.strip = strip;
|
|
|
|
rivertile.pie = pie;
|
2020-06-16 05:48:30 -07:00
|
|
|
rivertile.install();
|
|
|
|
}
|
|
|
|
|
2021-07-28 05:41:40 -07:00
|
|
|
{
|
|
|
|
const file = try fs.path.join(b.allocator, &[_][]const u8{ b.cache_root, "river-protocols.pc" });
|
2022-02-07 13:07:27 -08:00
|
|
|
const pkgconfig_file = try fs.cwd().createFile(file, .{});
|
2021-07-28 05:41:40 -07:00
|
|
|
|
|
|
|
const writer = pkgconfig_file.writer();
|
|
|
|
try writer.print(
|
|
|
|
\\prefix={s}
|
|
|
|
\\datadir=${{prefix}}/share
|
|
|
|
\\pkgdatadir=${{datadir}}/river-protocols
|
|
|
|
\\
|
|
|
|
\\Name: river-protocols
|
2021-11-01 03:28:43 -07:00
|
|
|
\\URL: https://github.com/riverwm/river
|
2021-07-28 05:41:40 -07:00
|
|
|
\\Description: protocol files for the river wayland compositor
|
|
|
|
\\Version: {s}
|
|
|
|
, .{ b.install_prefix, full_version });
|
|
|
|
defer pkgconfig_file.close();
|
|
|
|
|
|
|
|
b.installFile("protocol/river-layout-v3.xml", "share/river-protocols/river-layout-v3.xml");
|
|
|
|
b.installFile(file, "share/pkgconfig/river-protocols.pc");
|
|
|
|
}
|
2021-07-25 10:31:38 -07:00
|
|
|
|
2020-06-15 05:22:09 -07:00
|
|
|
if (man_pages) {
|
2020-06-15 04:16:38 -07:00
|
|
|
const scdoc_step = ScdocStep.create(b);
|
|
|
|
try scdoc_step.install();
|
|
|
|
}
|
|
|
|
|
2021-03-13 08:54:15 -08:00
|
|
|
if (bash_completion) {
|
2021-07-25 10:31:38 -07:00
|
|
|
b.installFile("completions/bash/riverctl", "share/bash-completion/completions/riverctl");
|
2021-03-13 08:54:15 -08:00
|
|
|
}
|
|
|
|
|
2021-03-13 08:06:39 -08:00
|
|
|
if (zsh_completion) {
|
2021-07-25 10:31:38 -07:00
|
|
|
b.installFile("completions/zsh/_riverctl", "share/zsh/site-functions/_riverctl");
|
2021-03-13 08:06:39 -08:00
|
|
|
}
|
|
|
|
|
2021-03-16 08:16:47 -07:00
|
|
|
if (fish_completion) {
|
2021-07-25 10:31:38 -07:00
|
|
|
b.installFile("completions/fish/riverctl.fish", "share/fish/vendor_completions.d/riverctl.fish");
|
2021-03-16 08:16:47 -07:00
|
|
|
}
|
|
|
|
|
2020-05-19 09:22:22 -07:00
|
|
|
{
|
2020-06-01 06:56:50 -07:00
|
|
|
const river_test = b.addTest("river/test_main.zig");
|
2020-05-19 09:22:22 -07:00
|
|
|
river_test.setTarget(target);
|
|
|
|
river_test.setBuildMode(mode);
|
2021-10-11 03:44:46 -07:00
|
|
|
river_test.addOptions("build_options", options);
|
2020-05-19 09:22:22 -07:00
|
|
|
|
2020-11-03 15:23:21 -08:00
|
|
|
addServerDeps(river_test, scanner);
|
2020-05-19 09:22:22 -07:00
|
|
|
|
|
|
|
const test_step = b.step("test", "Run the tests");
|
|
|
|
test_step.dependOn(&river_test.step);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-03 15:23:21 -08:00
|
|
|
fn addServerDeps(exe: *zbs.LibExeObjStep, scanner: *ScanProtocolsStep) void {
|
2021-10-11 03:44:46 -07:00
|
|
|
const wayland = zbs.Pkg{
|
|
|
|
.name = "wayland",
|
2022-11-04 16:29:51 -07:00
|
|
|
.source = .{ .generated = &scanner.result },
|
2021-10-11 03:44:46 -07:00
|
|
|
};
|
|
|
|
const xkbcommon = zbs.Pkg{
|
|
|
|
.name = "xkbcommon",
|
2022-11-04 16:29:51 -07:00
|
|
|
.source = .{ .path = "deps/zig-xkbcommon/src/xkbcommon.zig" },
|
2021-10-11 03:44:46 -07:00
|
|
|
};
|
|
|
|
const pixman = zbs.Pkg{
|
|
|
|
.name = "pixman",
|
2022-11-04 16:29:51 -07:00
|
|
|
.source = .{ .path = "deps/zig-pixman/pixman.zig" },
|
2021-10-11 03:44:46 -07:00
|
|
|
};
|
2020-11-03 15:23:21 -08:00
|
|
|
const wlroots = zbs.Pkg{
|
|
|
|
.name = "wlroots",
|
2022-11-04 16:29:51 -07:00
|
|
|
.source = .{ .path = "deps/zig-wlroots/src/wlroots.zig" },
|
2020-11-03 15:23:21 -08:00
|
|
|
.dependencies = &[_]zbs.Pkg{ wayland, xkbcommon, pixman },
|
|
|
|
};
|
|
|
|
|
|
|
|
exe.step.dependOn(&scanner.step);
|
2020-04-03 09:53:36 -07:00
|
|
|
|
2020-04-12 04:54:03 -07:00
|
|
|
exe.linkLibC();
|
2020-08-24 05:52:47 -07:00
|
|
|
exe.linkSystemLibrary("libevdev");
|
2021-06-03 20:51:15 -07:00
|
|
|
exe.linkSystemLibrary("libinput");
|
2020-04-12 04:37:18 -07:00
|
|
|
|
2020-11-03 15:23:21 -08:00
|
|
|
exe.addPackage(wayland);
|
|
|
|
exe.linkSystemLibrary("wayland-server");
|
2020-04-12 04:37:18 -07:00
|
|
|
|
2020-11-03 15:23:21 -08:00
|
|
|
exe.addPackage(xkbcommon);
|
|
|
|
exe.linkSystemLibrary("xkbcommon");
|
2020-04-12 04:37:18 -07:00
|
|
|
|
2020-11-03 15:23:21 -08:00
|
|
|
exe.addPackage(pixman);
|
|
|
|
exe.linkSystemLibrary("pixman-1");
|
2020-04-12 04:37:18 -07:00
|
|
|
|
2020-11-03 15:23:21 -08:00
|
|
|
exe.addPackage(wlroots);
|
|
|
|
exe.linkSystemLibrary("wlroots");
|
2020-05-19 09:22:22 -07:00
|
|
|
|
2021-07-24 09:29:48 -07:00
|
|
|
exe.addPackagePath("flags", "common/flags.zig");
|
2021-07-24 16:22:36 -07:00
|
|
|
exe.addCSourceFile("river/wlroots_log_wrapper.c", &[_][]const u8{ "-std=c99", "-O2" });
|
2021-07-24 07:44:11 -07:00
|
|
|
|
2020-11-03 15:23:21 -08:00
|
|
|
// TODO: remove when zig issue #131 is implemented
|
|
|
|
scanner.addCSource(exe);
|
|
|
|
}
|
2020-06-15 04:16:38 -07:00
|
|
|
|
|
|
|
const ScdocStep = struct {
|
|
|
|
const scd_paths = [_][]const u8{
|
|
|
|
"doc/river.1.scd",
|
|
|
|
"doc/riverctl.1.scd",
|
2020-06-16 08:06:24 -07:00
|
|
|
"doc/rivertile.1.scd",
|
2020-06-15 04:16:38 -07:00
|
|
|
};
|
|
|
|
|
2020-11-03 15:23:21 -08:00
|
|
|
builder: *zbs.Builder,
|
|
|
|
step: zbs.Step,
|
2020-06-15 04:16:38 -07:00
|
|
|
|
2020-11-03 15:23:21 -08:00
|
|
|
fn create(builder: *zbs.Builder) *ScdocStep {
|
2020-07-05 13:49:17 -07:00
|
|
|
const self = builder.allocator.create(ScdocStep) catch @panic("out of memory");
|
2020-06-15 04:16:38 -07:00
|
|
|
self.* = init(builder);
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2020-11-03 15:23:21 -08:00
|
|
|
fn init(builder: *zbs.Builder) ScdocStep {
|
2020-06-15 04:16:38 -07:00
|
|
|
return ScdocStep{
|
|
|
|
.builder = builder,
|
2021-10-11 03:44:46 -07:00
|
|
|
.step = zbs.Step.init(.custom, "Generate man pages", builder.allocator, make),
|
2020-06-15 04:16:38 -07:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2020-11-03 15:23:21 -08:00
|
|
|
fn make(step: *zbs.Step) !void {
|
2020-06-15 04:16:38 -07:00
|
|
|
const self = @fieldParentPtr(ScdocStep, "step", step);
|
|
|
|
for (scd_paths) |path| {
|
|
|
|
const command = try std.fmt.allocPrint(
|
|
|
|
self.builder.allocator,
|
2021-05-23 04:35:37 -07:00
|
|
|
"scdoc < {s} > {s}",
|
2020-06-15 04:16:38 -07:00
|
|
|
.{ path, path[0..(path.len - 4)] },
|
|
|
|
);
|
|
|
|
_ = try self.builder.exec(&[_][]const u8{ "sh", "-c", command });
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn install(self: *ScdocStep) !void {
|
|
|
|
self.builder.getInstallStep().dependOn(&self.step);
|
|
|
|
|
|
|
|
for (scd_paths) |path| {
|
|
|
|
const path_no_ext = path[0..(path.len - 4)];
|
2021-03-22 03:54:02 -07:00
|
|
|
const basename_no_ext = fs.path.basename(path_no_ext);
|
2020-06-15 04:16:38 -07:00
|
|
|
const section = path_no_ext[(path_no_ext.len - 1)..];
|
|
|
|
|
|
|
|
const output = try std.fmt.allocPrint(
|
|
|
|
self.builder.allocator,
|
2021-05-23 04:35:37 -07:00
|
|
|
"share/man/man{s}/{s}",
|
2020-06-15 04:16:38 -07:00
|
|
|
.{ section, basename_no_ext },
|
|
|
|
);
|
|
|
|
|
|
|
|
self.builder.installFile(path_no_ext, output);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|