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;
|
2023-10-16 07:18:36 -07:00
|
|
|
const Build = std.Build;
|
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-03-19 08:29:22 -07:00
|
|
|
|
2024-05-20 02:33:04 -07:00
|
|
|
const Scanner = @import("zig-wayland").Scanner;
|
2020-11-02 04:59:59 -08:00
|
|
|
|
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.
|
2024-04-17 05:39:55 -07:00
|
|
|
const version = "0.4.0-dev";
|
2021-07-24 02:31:17 -07:00
|
|
|
|
2023-10-16 07:18:36 -07:00
|
|
|
pub fn build(b: *Build) !void {
|
2020-03-19 08:29:22 -07:00
|
|
|
const target = b.standardTargetOptions(.{});
|
2023-10-16 07:18:36 -07:00
|
|
|
const optimize = b.standardOptimizeOption(.{});
|
2020-03-19 08:29:22 -07:00
|
|
|
|
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;
|
2024-04-20 04:27:03 -07:00
|
|
|
const llvm = !(b.option(bool, "no-llvm", "(expirimental) Use non-LLVM x86 Zig backend") orelse false);
|
2022-05-22 06:25:38 -07:00
|
|
|
|
2024-03-07 07:28:00 -08:00
|
|
|
const omit_frame_pointer = switch (optimize) {
|
|
|
|
.Debug, .ReleaseSafe => false,
|
|
|
|
.ReleaseFast, .ReleaseSmall => true,
|
|
|
|
};
|
|
|
|
|
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: {
|
2023-10-16 07:18:36 -07:00
|
|
|
_ = b.findProgram(&.{"scdoc"}, &.{}) catch |err| switch (err) {
|
2020-06-15 05:22:09 -07:00
|
|
|
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
|
|
|
|
2024-03-07 07:19:22 -08:00
|
|
|
const git_describe_long = b.runAllowFail(
|
2023-10-16 07:18:36 -07:00
|
|
|
&.{ "git", "-C", b.build_root.path orelse ".", "describe", "--long" },
|
2021-07-24 02:31:17 -07:00
|
|
|
&ret,
|
|
|
|
.Inherit,
|
|
|
|
) catch break :blk version;
|
2022-05-16 13:34:43 -07:00
|
|
|
|
2023-10-16 07:18:36 -07:00
|
|
|
var it = mem.split(u8, mem.trim(u8, git_describe_long, &std.ascii.whitespace), "-");
|
2022-05-16 13:34:43 -07:00
|
|
|
_ = 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
|
2023-10-16 07:18:36 -07:00
|
|
|
break :blk b.fmt(version ++ ".{s}+{s}", .{ commit_count, commit_hash[1..] });
|
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);
|
|
|
|
|
2023-10-16 07:18:36 -07:00
|
|
|
const scanner = Scanner.create(b, .{});
|
|
|
|
|
2020-11-03 15:23:21 -08:00
|
|
|
scanner.addSystemProtocol("stable/xdg-shell/xdg-shell.xml");
|
2024-03-07 07:19:22 -08:00
|
|
|
scanner.addSystemProtocol("staging/cursor-shape/cursor-shape-v1.xml");
|
2021-12-29 20:27:50 -08:00
|
|
|
scanner.addSystemProtocol("staging/ext-session-lock/ext-session-lock-v1.xml");
|
2021-02-15 12:07:29 -08:00
|
|
|
scanner.addSystemProtocol("unstable/pointer-constraints/pointer-constraints-unstable-v1.xml");
|
2024-03-07 07:19:22 -08:00
|
|
|
scanner.addSystemProtocol("unstable/pointer-gestures/pointer-gestures-unstable-v1.xml");
|
2024-03-11 06:47:01 -07:00
|
|
|
scanner.addSystemProtocol("unstable/tablet/tablet-unstable-v2.xml");
|
2024-03-07 07:19:22 -08:00
|
|
|
scanner.addSystemProtocol("unstable/xdg-decoration/xdg-decoration-unstable-v1.xml");
|
2023-10-16 07:18:36 -07:00
|
|
|
|
|
|
|
scanner.addCustomProtocol("protocol/river-control-unstable-v1.xml");
|
|
|
|
scanner.addCustomProtocol("protocol/river-status-unstable-v1.xml");
|
|
|
|
scanner.addCustomProtocol("protocol/river-layout-v3.xml");
|
|
|
|
scanner.addCustomProtocol("protocol/wlr-layer-shell-unstable-v1.xml");
|
|
|
|
scanner.addCustomProtocol("protocol/wlr-output-power-management-unstable-v1.xml");
|
2020-04-12 04:37:18 -07:00
|
|
|
|
2023-12-05 02:37:15 -08:00
|
|
|
// Some of these versions may be out of date with what wlroots implements.
|
|
|
|
// This is not a problem in practice though as long as river successfully compiles.
|
|
|
|
// These versions control Zig code generation and have no effect on anything internal
|
|
|
|
// to wlroots. Therefore, the only thnig that can happen due to a version being too
|
|
|
|
// old is that river fails to compile.
|
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);
|
2023-03-05 13:39:47 -08:00
|
|
|
scanner.generate("zwp_pointer_constraints_v1", 1);
|
2024-03-11 06:47:01 -07:00
|
|
|
scanner.generate("zwp_tablet_manager_v2", 1);
|
2023-03-10 05:55:56 -08:00
|
|
|
scanner.generate("zxdg_decoration_manager_v1", 1);
|
2021-12-29 20:27:50 -08:00
|
|
|
scanner.generate("ext_session_lock_manager_v1", 1);
|
2024-01-04 09:05:03 -08:00
|
|
|
scanner.generate("wp_cursor_shape_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);
|
|
|
|
|
2024-05-20 02:33:04 -07:00
|
|
|
const wayland = b.createModule(.{ .root_source_file = scanner.result });
|
|
|
|
|
|
|
|
const xkbcommon = b.dependency("zig-xkbcommon", .{}).module("xkbcommon");
|
|
|
|
const pixman = b.dependency("zig-pixman", .{}).module("pixman");
|
|
|
|
|
|
|
|
const wlroots = b.dependency("zig-wlroots", .{}).module("wlroots");
|
|
|
|
wlroots.addImport("wayland", wayland);
|
|
|
|
wlroots.addImport("xkbcommon", xkbcommon);
|
|
|
|
wlroots.addImport("pixman", pixman);
|
|
|
|
|
|
|
|
// We need to ensure the wlroots include path obtained from pkg-config is
|
|
|
|
// exposed to the wlroots module for @cImport() to work. This seems to be
|
|
|
|
// the best way to do so with the current std.Build API.
|
|
|
|
wlroots.resolved_target = target;
|
2024-03-07 07:19:22 -08:00
|
|
|
wlroots.linkSystemLibrary("wlroots", .{});
|
2023-10-16 07:18:36 -07:00
|
|
|
|
2024-06-07 05:01:11 -07:00
|
|
|
const flags = b.createModule(.{ .root_source_file = b.path("common/flags.zig") });
|
|
|
|
const globber = b.createModule(.{ .root_source_file = b.path("common/globber.zig") });
|
2023-10-16 07:18:36 -07:00
|
|
|
|
2020-05-19 09:22:22 -07:00
|
|
|
{
|
2023-10-16 07:18:36 -07:00
|
|
|
const river = b.addExecutable(.{
|
|
|
|
.name = "river",
|
2024-06-07 05:01:11 -07:00
|
|
|
.root_source_file = b.path("river/main.zig"),
|
2023-10-16 07:18:36 -07:00
|
|
|
.target = target,
|
|
|
|
.optimize = optimize,
|
2024-03-07 07:19:22 -08:00
|
|
|
.strip = strip,
|
2024-04-20 04:27:03 -07:00
|
|
|
.use_llvm = llvm,
|
|
|
|
.use_lld = llvm,
|
2023-10-16 07:18:36 -07:00
|
|
|
});
|
2024-03-07 07:19:22 -08:00
|
|
|
river.root_module.addOptions("build_options", options);
|
2020-04-12 04:37:18 -07:00
|
|
|
|
2023-02-24 10:28:37 -08:00
|
|
|
river.linkLibC();
|
|
|
|
river.linkSystemLibrary("libevdev");
|
|
|
|
river.linkSystemLibrary("libinput");
|
|
|
|
river.linkSystemLibrary("wayland-server");
|
2024-05-20 02:33:04 -07:00
|
|
|
river.linkSystemLibrary("wlroots");
|
|
|
|
river.linkSystemLibrary("xkbcommon");
|
|
|
|
river.linkSystemLibrary("pixman-1");
|
2023-02-24 10:28:37 -08:00
|
|
|
|
2024-03-07 07:19:22 -08:00
|
|
|
river.root_module.addImport("wayland", wayland);
|
|
|
|
river.root_module.addImport("xkbcommon", xkbcommon);
|
|
|
|
river.root_module.addImport("pixman", pixman);
|
|
|
|
river.root_module.addImport("wlroots", wlroots);
|
|
|
|
river.root_module.addImport("flags", flags);
|
|
|
|
river.root_module.addImport("globber", globber);
|
2023-02-24 10:28:37 -08:00
|
|
|
|
2023-10-16 07:18:36 -07:00
|
|
|
river.addCSourceFile(.{
|
2024-06-07 05:01:11 -07:00
|
|
|
.file = b.path("river/wlroots_log_wrapper.c"),
|
2023-10-16 07:18:36 -07:00
|
|
|
.flags = &.{ "-std=c99", "-O2" },
|
|
|
|
});
|
2023-02-24 10:28:37 -08:00
|
|
|
|
|
|
|
// TODO: remove when zig issue #131 is implemented
|
|
|
|
scanner.addCSource(river);
|
2020-04-08 15:05:28 -07:00
|
|
|
|
2022-05-22 06:25:38 -07:00
|
|
|
river.pie = pie;
|
2024-03-07 07:19:22 -08:00
|
|
|
river.root_module.omit_frame_pointer = omit_frame_pointer;
|
2023-10-16 07:18:36 -07:00
|
|
|
|
|
|
|
b.installArtifact(river);
|
2020-05-19 09:22:22 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2023-10-16 07:18:36 -07:00
|
|
|
const riverctl = b.addExecutable(.{
|
|
|
|
.name = "riverctl",
|
2024-06-07 05:01:11 -07:00
|
|
|
.root_source_file = b.path("riverctl/main.zig"),
|
2023-10-16 07:18:36 -07:00
|
|
|
.target = target,
|
|
|
|
.optimize = optimize,
|
2024-03-07 07:19:22 -08:00
|
|
|
.strip = strip,
|
2024-04-20 04:27:03 -07:00
|
|
|
.use_llvm = llvm,
|
|
|
|
.use_lld = llvm,
|
2023-10-16 07:18:36 -07:00
|
|
|
});
|
2024-03-07 07:19:22 -08:00
|
|
|
riverctl.root_module.addOptions("build_options", options);
|
2020-05-19 09:22:22 -07:00
|
|
|
|
2024-03-07 07:19:22 -08:00
|
|
|
riverctl.root_module.addImport("flags", flags);
|
|
|
|
riverctl.root_module.addImport("wayland", wayland);
|
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.pie = pie;
|
2024-03-07 07:19:22 -08:00
|
|
|
riverctl.root_module.omit_frame_pointer = omit_frame_pointer;
|
2023-10-16 07:18:36 -07:00
|
|
|
|
|
|
|
b.installArtifact(riverctl);
|
2020-05-19 09:22:22 -07:00
|
|
|
}
|
|
|
|
|
2020-06-16 05:48:30 -07:00
|
|
|
{
|
2023-10-16 07:18:36 -07:00
|
|
|
const rivertile = b.addExecutable(.{
|
|
|
|
.name = "rivertile",
|
2024-06-07 05:01:11 -07:00
|
|
|
.root_source_file = b.path("rivertile/main.zig"),
|
2023-10-16 07:18:36 -07:00
|
|
|
.target = target,
|
|
|
|
.optimize = optimize,
|
2024-03-07 07:19:22 -08:00
|
|
|
.strip = strip,
|
2024-04-20 04:27:03 -07:00
|
|
|
.use_llvm = llvm,
|
|
|
|
.use_lld = llvm,
|
2023-10-16 07:18:36 -07:00
|
|
|
});
|
2024-03-07 07:19:22 -08:00
|
|
|
rivertile.root_module.addOptions("build_options", options);
|
2020-10-02 06:53:08 -07:00
|
|
|
|
2024-03-07 07:19:22 -08:00
|
|
|
rivertile.root_module.addImport("flags", flags);
|
|
|
|
rivertile.root_module.addImport("wayland", wayland);
|
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.pie = pie;
|
2024-03-07 07:19:22 -08:00
|
|
|
rivertile.root_module.omit_frame_pointer = omit_frame_pointer;
|
2023-10-16 07:18:36 -07:00
|
|
|
|
|
|
|
b.installArtifact(rivertile);
|
2020-06-16 05:48:30 -07:00
|
|
|
}
|
|
|
|
|
2021-07-28 05:41:40 -07:00
|
|
|
{
|
2023-10-16 07:18:36 -07:00
|
|
|
const wf = Build.Step.WriteFile.create(b);
|
|
|
|
const pc_file = wf.add("river-protocols.pc", b.fmt(
|
2021-07-28 05:41:40 -07:00
|
|
|
\\prefix={s}
|
|
|
|
\\datadir=${{prefix}}/share
|
|
|
|
\\pkgdatadir=${{datadir}}/river-protocols
|
|
|
|
\\
|
|
|
|
\\Name: river-protocols
|
2024-03-22 08:49:28 -07:00
|
|
|
\\URL: https://codeberg.org/river/river
|
2021-07-28 05:41:40 -07:00
|
|
|
\\Description: protocol files for the river wayland compositor
|
|
|
|
\\Version: {s}
|
2023-10-16 07:18:36 -07:00
|
|
|
, .{ b.install_prefix, full_version }));
|
2021-07-28 05:41:40 -07:00
|
|
|
|
|
|
|
b.installFile("protocol/river-layout-v3.xml", "share/river-protocols/river-layout-v3.xml");
|
2023-10-16 07:18:36 -07:00
|
|
|
b.getInstallStep().dependOn(&b.addInstallFile(pc_file, "share/pkgconfig/river-protocols.pc").step);
|
2021-07-28 05:41:40 -07:00
|
|
|
}
|
2021-07-25 10:31:38 -07:00
|
|
|
|
2020-06-15 05:22:09 -07:00
|
|
|
if (man_pages) {
|
2023-10-16 07:18:36 -07:00
|
|
|
inline for (.{ "river", "riverctl", "rivertile" }) |page| {
|
|
|
|
// Workaround for https://github.com/ziglang/zig/issues/16369
|
|
|
|
// Even passing a buffer to std.Build.Step.Run appears to be racy and occasionally deadlocks.
|
|
|
|
const scdoc = b.addSystemCommand(&.{ "/bin/sh", "-c", "scdoc < doc/" ++ page ++ ".1.scd" });
|
|
|
|
// This makes the caching work for the Workaround, and the extra argument is ignored by /bin/sh.
|
2024-06-07 05:01:11 -07:00
|
|
|
scdoc.addFileArg(b.path("doc/" ++ page ++ ".1.scd"));
|
2023-10-16 07:18:36 -07:00
|
|
|
|
|
|
|
const stdout = scdoc.captureStdOut();
|
|
|
|
b.getInstallStep().dependOn(&b.addInstallFile(stdout, "share/man/man1/" ++ page ++ ".1").step);
|
|
|
|
}
|
2020-06-15 04:16:38 -07:00
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
2023-03-12 07:40:42 -07:00
|
|
|
|
|
|
|
{
|
2023-10-16 07:18:36 -07:00
|
|
|
const globber_test = b.addTest(.{
|
2024-06-07 05:01:11 -07:00
|
|
|
.root_source_file = b.path("common/globber.zig"),
|
2023-10-16 07:18:36 -07:00
|
|
|
.target = target,
|
|
|
|
.optimize = optimize,
|
|
|
|
});
|
|
|
|
const run_globber_test = b.addRunArtifact(globber_test);
|
2023-03-12 07:40:42 -07:00
|
|
|
|
|
|
|
const test_step = b.step("test", "Run the tests");
|
2023-10-16 07:18:36 -07:00
|
|
|
test_step.dependOn(&run_globber_test.step);
|
2023-03-12 07:40:42 -07:00
|
|
|
}
|
2020-11-03 15:23:21 -08:00
|
|
|
}
|