-
-
Notifications
You must be signed in to change notification settings - Fork 163
Expand file tree
/
Copy pathbuild.zig
More file actions
260 lines (222 loc) · 10.9 KB
/
build.zig
File metadata and controls
260 lines (222 loc) · 10.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
// SPDX-FileCopyrightText: © 2020 The River Developers
// SPDX-License-Identifier: GPL-3.0-only
const std = @import("std");
const assert = std.debug.assert;
const Build = std.Build;
const fs = std.fs;
const mem = std.mem;
const manifest = @import("build.zig.zon");
const version = manifest.version;
const Scanner = @import("wayland").Scanner;
const Translator = @import("translate_c").Translator;
pub fn build(b: *Build) !void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
const strip = b.option(bool, "strip", "Omit debug information") orelse false;
const pie = b.option(bool, "pie", "Build a Position Independent Executable") orelse false;
const use_llvm = b.option(bool, "llvm", "Force use of Zig's LLVM backend and the lld linker");
const omit_frame_pointer = switch (optimize) {
.Debug, .ReleaseSafe => false,
.ReleaseFast, .ReleaseSmall => true,
};
const man_pages = b.option(
bool,
"man-pages",
"Set to true to build man pages. Requires scdoc. Defaults to true if scdoc is found.",
) orelse scdoc_found: {
_ = b.findProgram(&.{"scdoc"}, &.{}) catch |err| switch (err) {
error.FileNotFound => break :scdoc_found false,
};
break :scdoc_found true;
};
const xwayland = b.option(
bool,
"xwayland",
"Set to true to enable xwayland support",
) orelse false;
const full_version = blk: {
if (b.option([]const u8, "version-string", "Override `river -version` output.")) |version_override| {
break :blk version_override;
} else if (mem.endsWith(u8, version, "-dev")) {
var ret: u8 = undefined;
const git_describe_long = b.runAllowFail(
&.{ "git", "-C", b.build_root.path orelse ".", "describe", "--long" },
&ret,
.ignore,
) catch break :blk version;
var it = mem.splitSequence(u8, mem.trim(u8, git_describe_long, &std.ascii.whitespace), "-");
_ = 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 b.fmt(version ++ ".{s}+{s}", .{ commit_count, commit_hash[1..] });
} else {
break :blk version;
}
};
const options = b.addOptions();
options.addOption(bool, "xwayland", xwayland);
options.addOption([]const u8, "version", full_version);
const scanner = Scanner.create(b, .{});
scanner.addSystemProtocol("stable/tablet/tablet-v2.xml");
scanner.addSystemProtocol("stable/xdg-shell/xdg-shell.xml");
scanner.addSystemProtocol("staging/color-management/color-management-v1.xml");
scanner.addSystemProtocol("staging/color-representation/color-representation-v1.xml");
scanner.addSystemProtocol("staging/cursor-shape/cursor-shape-v1.xml");
scanner.addSystemProtocol("staging/ext-session-lock/ext-session-lock-v1.xml");
scanner.addSystemProtocol("staging/tearing-control/tearing-control-v1.xml");
scanner.addSystemProtocol("unstable/pointer-constraints/pointer-constraints-unstable-v1.xml");
scanner.addSystemProtocol("unstable/pointer-gestures/pointer-gestures-unstable-v1.xml");
scanner.addSystemProtocol("unstable/xdg-decoration/xdg-decoration-unstable-v1.xml");
scanner.addSystemProtocol("unstable/xdg-foreign/xdg-foreign-unstable-v2.xml");
scanner.addCustomProtocol(b.path("protocol/river-window-management-v1.xml"));
scanner.addCustomProtocol(b.path("protocol/river-xkb-bindings-v1.xml"));
scanner.addCustomProtocol(b.path("protocol/river-layer-shell-v1.xml"));
scanner.addCustomProtocol(b.path("protocol/river-input-management-v1.xml"));
scanner.addCustomProtocol(b.path("protocol/river-libinput-config-v1.xml"));
scanner.addCustomProtocol(b.path("protocol/river-xkb-config-v1.xml"));
scanner.addCustomProtocol(b.path("protocol/upstream/wlr-layer-shell-unstable-v1.xml"));
scanner.addCustomProtocol(b.path("protocol/upstream/wlr-output-power-management-unstable-v1.xml"));
scanner.addCustomProtocol(b.path("protocol/upstream/virtual-keyboard-unstable-v1.xml"));
// 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 thing that can happen due to a version being too
// old is that river fails to compile.
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);
scanner.generate("zwp_tablet_manager_v2", 1);
scanner.generate("zxdg_decoration_manager_v1", 1);
scanner.generate("zxdg_importer_v2", 1);
scanner.generate("zxdg_exporter_v2", 1);
scanner.generate("ext_session_lock_manager_v1", 1);
scanner.generate("wp_cursor_shape_manager_v1", 1);
scanner.generate("wp_tearing_control_manager_v1", 1);
scanner.generate("wp_color_manager_v1", 2);
scanner.generate("wp_color_representation_manager_v1", 1);
scanner.generate("river_window_manager_v1", 4);
scanner.generate("river_xkb_bindings_v1", 3);
scanner.generate("river_layer_shell_v1", 1);
scanner.generate("river_input_manager_v1", 2);
scanner.generate("river_libinput_config_v1", 2);
scanner.generate("river_xkb_config_v1", 2);
scanner.generate("zwlr_output_power_manager_v1", 1);
scanner.generate("zwlr_layer_shell_v1", 4);
scanner.generate("zwp_virtual_keyboard_manager_v1", 1);
const wayland = b.createModule(.{ .root_source_file = scanner.result });
const xkbcommon = b.dependency("xkbcommon", .{}).module("xkbcommon");
const pixman = b.dependency("pixman", .{}).module("pixman");
const wlroots = b.dependency("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;
const wlroots_pkgconf = "wlroots-0.20";
wlroots.linkSystemLibrary(wlroots_pkgconf, .{});
const flags = b.createModule(.{ .root_source_file = b.path("common/flags.zig") });
const slotmap = b.createModule(.{ .root_source_file = b.path("common/slotmap.zig") });
const translate_c: Translator = .init(b.dependency("translate_c", .{}), .{
.name = "c",
.c_source_file = b.path("river/c.h"),
.target = target,
.optimize = optimize,
});
translate_c.linkSystemLibrary("libevdev", .{});
translate_c.linkSystemLibrary("libinput", .{});
{
const river = b.addExecutable(.{
.name = "river",
.root_module = b.createModule(.{
.root_source_file = b.path("river/main.zig"),
.target = target,
.optimize = optimize,
.strip = strip,
.link_libc = true,
}),
.use_llvm = use_llvm,
.use_lld = use_llvm,
});
river.root_module.addOptions("build_options", options);
river.root_module.linkSystemLibrary("libevdev", .{});
river.root_module.linkSystemLibrary("libinput", .{});
river.root_module.linkSystemLibrary("wayland-server", .{});
river.root_module.linkSystemLibrary(wlroots_pkgconf, .{});
river.root_module.linkSystemLibrary("xkbcommon", .{});
river.root_module.linkSystemLibrary("pixman-1", .{});
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("slotmap", slotmap);
river.root_module.addImport("c", translate_c.mod);
river.root_module.addCSourceFile(.{
.file = b.path("river/wlroots_log_wrapper.c"),
.flags = &.{ "-std=c99", "-O2" },
});
river.pie = pie;
river.root_module.omit_frame_pointer = omit_frame_pointer;
b.installArtifact(river);
}
{
const wf = Build.Step.WriteFile.create(b);
const pc_file = wf.add("river-protocols.pc", b.fmt(
\\prefix={s}
\\datarootdir=${{prefix}}/share
\\pkgdatadir=${{pc_sysrootdir}}${{datarootdir}}/river-protocols
\\
\\Name: river-protocols
\\URL: https://isaacfreund.com/software/river
\\Description: Protocol files for river, a non-monolithic Wayland compositor
\\Version: {s}
, .{ b.install_prefix, full_version }));
b.getInstallStep().dependOn(&b.addInstallFile(pc_file, "share/pkgconfig/river-protocols.pc").step);
inline for (&.{
"river-window-management-v1.xml",
"river-xkb-bindings-v1.xml",
"river-layer-shell-v1.xml",
"river-input-management-v1.xml",
"river-libinput-config-v1.xml",
"river-xkb-config-v1.xml",
}) |protocol| {
b.installFile("protocol/" ++ protocol, "share/river-protocols/stable/" ++ protocol);
}
}
if (man_pages) {
inline for (.{"river"}) |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.
scdoc.addFileArg(b.path("doc/" ++ page ++ ".1.scd"));
const stdout = scdoc.captureStdOut(.{});
b.getInstallStep().dependOn(&b.addInstallFile(stdout, "share/man/man1/" ++ page ++ ".1").step);
}
}
{
const slotmap_test = b.addTest(.{
.root_module = b.createModule(.{
.root_source_file = b.path("common/slotmap.zig"),
.target = target,
.optimize = optimize,
}),
.use_llvm = use_llvm,
.use_lld = use_llvm,
});
const run_slotmap_test = b.addRunArtifact(slotmap_test);
const test_step = b.step("test", "Run the tests");
test_step.dependOn(&run_slotmap_test.step);
}
}