2020-04-12 04:37:18 -07:00
|
|
|
const std = @import("std");
|
2020-03-19 08:29:22 -07:00
|
|
|
|
2020-04-12 04:37:18 -07:00
|
|
|
pub fn build(b: *std.build.Builder) !void {
|
2020-03-19 08:29:22 -07:00
|
|
|
// Standard target options allows the person running `zig build` to choose
|
|
|
|
// what target to build for. Here we do not override the defaults, which
|
|
|
|
// means any target is allowed, and the default is native. Other options
|
|
|
|
// for restricting supported target set are available.
|
|
|
|
const target = b.standardTargetOptions(.{});
|
|
|
|
|
|
|
|
// Standard release options allow the person running `zig build` to select
|
|
|
|
// between Debug, ReleaseSafe, ReleaseFast, and ReleaseSmall.
|
|
|
|
const mode = b.standardReleaseOptions();
|
|
|
|
|
2020-05-04 02:10:23 -07:00
|
|
|
const xwayland = b.option(
|
|
|
|
bool,
|
|
|
|
"xwayland",
|
|
|
|
"Set to true to enable xwayland support",
|
|
|
|
) orelse false;
|
|
|
|
|
2020-06-04 15:24:17 -07:00
|
|
|
const examples = b.option(
|
|
|
|
bool,
|
|
|
|
"examples",
|
|
|
|
"Set to true to build examples",
|
|
|
|
) orelse false;
|
|
|
|
|
2020-04-12 04:37:18 -07:00
|
|
|
const scan_protocols = ScanProtocolsStep.create(b);
|
|
|
|
|
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);
|
|
|
|
river.addBuildOption(bool, "xwayland", xwayland);
|
2020-04-12 04:37:18 -07:00
|
|
|
|
2020-05-19 09:22:22 -07:00
|
|
|
addProtocolDeps(river, &scan_protocols.step);
|
|
|
|
addServerDeps(river);
|
2020-04-08 15:05:28 -07:00
|
|
|
|
2020-05-19 09:22:22 -07:00
|
|
|
river.install();
|
|
|
|
|
|
|
|
const run_cmd = river.run();
|
|
|
|
run_cmd.step.dependOn(b.getInstallStep());
|
|
|
|
|
|
|
|
const run_step = b.step("run", "Run the compositor");
|
|
|
|
run_step.dependOn(&run_cmd.step);
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
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);
|
|
|
|
|
|
|
|
addProtocolDeps(riverctl, &scan_protocols.step);
|
|
|
|
|
|
|
|
riverctl.linkLibC();
|
|
|
|
riverctl.linkSystemLibrary("wayland-client");
|
|
|
|
|
|
|
|
riverctl.install();
|
|
|
|
}
|
|
|
|
|
2020-06-04 15:24:17 -07:00
|
|
|
if (examples) {
|
|
|
|
const status = b.addExecutable("status", "example/status.zig");
|
|
|
|
status.setTarget(target);
|
|
|
|
status.setBuildMode(mode);
|
|
|
|
|
|
|
|
addProtocolDeps(status, &scan_protocols.step);
|
|
|
|
|
|
|
|
status.linkLibC();
|
|
|
|
status.linkSystemLibrary("wayland-client");
|
|
|
|
|
|
|
|
status.install();
|
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
river_test.addBuildOption(bool, "xwayland", xwayland);
|
|
|
|
|
|
|
|
addProtocolDeps(river_test, &scan_protocols.step);
|
|
|
|
addServerDeps(river_test);
|
|
|
|
|
|
|
|
const test_step = b.step("test", "Run the tests");
|
|
|
|
test_step.dependOn(&river_test.step);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn addServerDeps(exe: *std.build.LibExeObjStep) void {
|
2020-04-15 03:47:55 -07:00
|
|
|
exe.addCSourceFile("include/bindings.c", &[_][]const u8{"-std=c99"});
|
2020-04-12 04:54:03 -07:00
|
|
|
exe.addIncludeDir(".");
|
2020-04-03 09:53:36 -07:00
|
|
|
|
2020-04-12 04:54:03 -07:00
|
|
|
exe.linkLibC();
|
2020-05-02 07:04:14 -07:00
|
|
|
exe.linkSystemLibrary("pixman-1");
|
2020-04-12 04:54:03 -07:00
|
|
|
exe.linkSystemLibrary("wayland-server");
|
|
|
|
exe.linkSystemLibrary("wlroots");
|
|
|
|
exe.linkSystemLibrary("xkbcommon");
|
2020-03-19 08:29:22 -07:00
|
|
|
}
|
2020-04-12 04:37:18 -07:00
|
|
|
|
2020-05-19 09:22:22 -07:00
|
|
|
fn addProtocolDeps(exe: *std.build.LibExeObjStep, protocol_step: *std.build.Step) void {
|
|
|
|
exe.step.dependOn(protocol_step);
|
|
|
|
exe.addIncludeDir("protocol");
|
2020-05-24 11:58:39 -07:00
|
|
|
exe.addCSourceFile("protocol/river-control-unstable-v1-protocol.c", &[_][]const u8{"-std=c99"});
|
2020-06-04 07:56:58 -07:00
|
|
|
exe.addCSourceFile("protocol/river-status-unstable-v1-protocol.c", &[_][]const u8{"-std=c99"});
|
2020-05-19 09:22:22 -07:00
|
|
|
}
|
|
|
|
|
2020-04-12 04:37:18 -07:00
|
|
|
const ScanProtocolsStep = struct {
|
|
|
|
builder: *std.build.Builder,
|
|
|
|
step: std.build.Step,
|
|
|
|
|
|
|
|
fn create(builder: *std.build.Builder) *ScanProtocolsStep {
|
|
|
|
const self = builder.allocator.create(ScanProtocolsStep) catch unreachable;
|
|
|
|
self.* = init(builder);
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
fn init(builder: *std.build.Builder) ScanProtocolsStep {
|
|
|
|
return ScanProtocolsStep{
|
|
|
|
.builder = builder,
|
|
|
|
.step = std.build.Step.init("Scan Protocols", builder.allocator, make),
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
fn make(step: *std.build.Step) !void {
|
|
|
|
const self = @fieldParentPtr(ScanProtocolsStep, "step", step);
|
|
|
|
|
|
|
|
const protocol_dir = std.fmt.trim(try self.builder.exec(
|
|
|
|
&[_][]const u8{ "pkg-config", "--variable=pkgdatadir", "wayland-protocols" },
|
|
|
|
));
|
|
|
|
|
|
|
|
const protocol_dir_paths = [_][]const []const u8{
|
|
|
|
&[_][]const u8{ protocol_dir, "stable/xdg-shell/xdg-shell.xml" },
|
|
|
|
&[_][]const u8{ "protocol", "wlr-layer-shell-unstable-v1.xml" },
|
2020-05-24 11:58:39 -07:00
|
|
|
&[_][]const u8{ "protocol", "river-control-unstable-v1.xml" },
|
2020-06-03 04:25:17 -07:00
|
|
|
&[_][]const u8{ "protocol", "river-status-unstable-v1.xml" },
|
|
|
|
};
|
|
|
|
|
|
|
|
const server_protocols = [_][]const u8{
|
|
|
|
"xdg-shell",
|
|
|
|
"wlr-layer-shell-unstable-v1",
|
|
|
|
"river-control-unstable-v1",
|
|
|
|
"river-status-unstable-v1",
|
|
|
|
};
|
|
|
|
|
|
|
|
const client_protocols = [_][]const u8{
|
|
|
|
"river-control-unstable-v1",
|
|
|
|
"river-status-unstable-v1",
|
2020-04-12 04:37:18 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
for (protocol_dir_paths) |dir_path| {
|
|
|
|
const xml_in_path = try std.fs.path.join(self.builder.allocator, dir_path);
|
|
|
|
|
|
|
|
// Extension is .xml, so slice off the last 4 characters
|
|
|
|
const basename = std.fs.path.basename(xml_in_path);
|
|
|
|
const basename_no_ext = basename[0..(basename.len - 4)];
|
|
|
|
|
|
|
|
const code_out_path = try std.mem.concat(
|
|
|
|
self.builder.allocator,
|
|
|
|
u8,
|
|
|
|
&[_][]const u8{ "protocol/", basename_no_ext, "-protocol.c" },
|
|
|
|
);
|
|
|
|
_ = try self.builder.exec(
|
|
|
|
&[_][]const u8{ "wayland-scanner", "private-code", xml_in_path, code_out_path },
|
|
|
|
);
|
2020-05-19 09:22:22 -07:00
|
|
|
|
2020-06-03 04:25:17 -07:00
|
|
|
for (server_protocols) |server_protocol| {
|
|
|
|
if (std.mem.eql(u8, basename_no_ext, server_protocol)) {
|
|
|
|
const header_out_path = try std.mem.concat(
|
|
|
|
self.builder.allocator,
|
|
|
|
u8,
|
|
|
|
&[_][]const u8{ "protocol/", basename_no_ext, "-protocol.h" },
|
|
|
|
);
|
|
|
|
_ = try self.builder.exec(
|
|
|
|
&[_][]const u8{ "wayland-scanner", "server-header", xml_in_path, header_out_path },
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (client_protocols) |client_protocol| {
|
|
|
|
if (std.mem.eql(u8, basename_no_ext, client_protocol)) {
|
|
|
|
const header_out_path = try std.mem.concat(
|
|
|
|
self.builder.allocator,
|
|
|
|
u8,
|
|
|
|
&[_][]const u8{ "protocol/", basename_no_ext, "-client-protocol.h" },
|
|
|
|
);
|
|
|
|
_ = try self.builder.exec(
|
|
|
|
&[_][]const u8{ "wayland-scanner", "client-header", xml_in_path, header_out_path },
|
|
|
|
);
|
|
|
|
}
|
2020-05-19 09:22:22 -07:00
|
|
|
}
|
2020-04-12 04:37:18 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|