build: update to Zig 0.11.0
This commit is contained in:
230
build.zig
230
build.zig
@ -1,10 +1,10 @@
|
||||
const std = @import("std");
|
||||
const assert = std.debug.assert;
|
||||
const Build = std.Build;
|
||||
const fs = std.fs;
|
||||
const mem = std.mem;
|
||||
const zbs = std.build;
|
||||
|
||||
const ScanProtocolsStep = @import("deps/zig-wayland/build.zig").ScanProtocolsStep;
|
||||
const Scanner = @import("deps/zig-wayland/build.zig").Scanner;
|
||||
|
||||
/// While a river release is in development, this string should contain the version in development
|
||||
/// with the "-dev" suffix.
|
||||
@ -12,9 +12,9 @@ const ScanProtocolsStep = @import("deps/zig-wayland/build.zig").ScanProtocolsSte
|
||||
/// Directly after the tagged commit, the version should be bumped and the "-dev" suffix added.
|
||||
const version = "0.3.0-dev";
|
||||
|
||||
pub fn build(b: *zbs.Builder) !void {
|
||||
pub fn build(b: *Build) !void {
|
||||
const target = b.standardTargetOptions(.{});
|
||||
const mode = b.standardReleaseOptions();
|
||||
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;
|
||||
@ -24,7 +24,7 @@ pub fn build(b: *zbs.Builder) !void {
|
||||
"man-pages",
|
||||
"Set to true to build man pages. Requires scdoc. Defaults to true if scdoc is found.",
|
||||
) orelse scdoc_found: {
|
||||
_ = b.findProgram(&[_][]const u8{"scdoc"}, &[_][]const u8{}) catch |err| switch (err) {
|
||||
_ = b.findProgram(&.{"scdoc"}, &.{}) catch |err| switch (err) {
|
||||
error.FileNotFound => break :scdoc_found false,
|
||||
else => return err,
|
||||
};
|
||||
@ -60,12 +60,12 @@ pub fn build(b: *zbs.Builder) !void {
|
||||
var ret: u8 = undefined;
|
||||
|
||||
const git_describe_long = b.execAllowFail(
|
||||
&[_][]const u8{ "git", "-C", b.build_root, "describe", "--long" },
|
||||
&.{ "git", "-C", b.build_root.path orelse ".", "describe", "--long" },
|
||||
&ret,
|
||||
.Inherit,
|
||||
) catch break :blk version;
|
||||
|
||||
var it = mem.split(u8, mem.trim(u8, git_describe_long, &std.ascii.spaces), "-");
|
||||
var it = mem.split(u8, mem.trim(u8, git_describe_long, &std.ascii.whitespace), "-");
|
||||
_ = it.next().?; // previous tag
|
||||
const commit_count = it.next().?;
|
||||
const commit_hash = it.next().?;
|
||||
@ -73,10 +73,7 @@ pub fn build(b: *zbs.Builder) !void {
|
||||
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..],
|
||||
});
|
||||
break :blk b.fmt(version ++ ".{s}+{s}", .{ commit_count, commit_hash[1..] });
|
||||
} else {
|
||||
break :blk version;
|
||||
}
|
||||
@ -86,17 +83,19 @@ pub fn build(b: *zbs.Builder) !void {
|
||||
options.addOption(bool, "xwayland", xwayland);
|
||||
options.addOption([]const u8, "version", full_version);
|
||||
|
||||
const scanner = ScanProtocolsStep.create(b);
|
||||
const scanner = Scanner.create(b, .{});
|
||||
|
||||
scanner.addSystemProtocol("stable/xdg-shell/xdg-shell.xml");
|
||||
scanner.addSystemProtocol("staging/ext-session-lock/ext-session-lock-v1.xml");
|
||||
scanner.addSystemProtocol("unstable/pointer-gestures/pointer-gestures-unstable-v1.xml");
|
||||
scanner.addSystemProtocol("unstable/pointer-constraints/pointer-constraints-unstable-v1.xml");
|
||||
scanner.addSystemProtocol("unstable/xdg-decoration/xdg-decoration-unstable-v1.xml");
|
||||
scanner.addProtocolPath("protocol/river-control-unstable-v1.xml");
|
||||
scanner.addProtocolPath("protocol/river-status-unstable-v1.xml");
|
||||
scanner.addProtocolPath("protocol/river-layout-v3.xml");
|
||||
scanner.addProtocolPath("protocol/wlr-layer-shell-unstable-v1.xml");
|
||||
scanner.addProtocolPath("protocol/wlr-output-power-management-unstable-v1.xml");
|
||||
|
||||
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");
|
||||
|
||||
// These must be manually kept in sync with the versions wlroots supports
|
||||
// until wlroots gives the option to request a specific version.
|
||||
@ -120,72 +119,77 @@ pub fn build(b: *zbs.Builder) !void {
|
||||
scanner.generate("zwlr_layer_shell_v1", 4);
|
||||
scanner.generate("zwlr_output_power_manager_v1", 1);
|
||||
|
||||
const wayland = b.createModule(.{ .source_file = scanner.result });
|
||||
const xkbcommon = b.createModule(.{
|
||||
.source_file = .{ .path = "deps/zig-xkbcommon/src/xkbcommon.zig" },
|
||||
});
|
||||
const pixman = b.createModule(.{
|
||||
.source_file = .{ .path = "deps/zig-pixman/pixman.zig" },
|
||||
});
|
||||
const wlroots = b.createModule(.{
|
||||
.source_file = .{ .path = "deps/zig-wlroots/src/wlroots.zig" },
|
||||
.dependencies = &.{
|
||||
.{ .name = "wayland", .module = wayland },
|
||||
.{ .name = "xkbcommon", .module = xkbcommon },
|
||||
.{ .name = "pixman", .module = pixman },
|
||||
},
|
||||
});
|
||||
|
||||
const flags = b.createModule(.{ .source_file = .{ .path = "common/flags.zig" } });
|
||||
const globber = b.createModule(.{ .source_file = .{ .path = "common/globber.zig" } });
|
||||
|
||||
{
|
||||
const river = b.addExecutable("river", "river/main.zig");
|
||||
river.setTarget(target);
|
||||
river.setBuildMode(mode);
|
||||
const river = b.addExecutable(.{
|
||||
.name = "river",
|
||||
.root_source_file = .{ .path = "river/main.zig" },
|
||||
.target = target,
|
||||
.optimize = optimize,
|
||||
});
|
||||
river.addOptions("build_options", options);
|
||||
|
||||
const wayland = zbs.Pkg{
|
||||
.name = "wayland",
|
||||
.source = .{ .generated = &scanner.result },
|
||||
};
|
||||
const xkbcommon = zbs.Pkg{
|
||||
.name = "xkbcommon",
|
||||
.source = .{ .path = "deps/zig-xkbcommon/src/xkbcommon.zig" },
|
||||
};
|
||||
const pixman = zbs.Pkg{
|
||||
.name = "pixman",
|
||||
.source = .{ .path = "deps/zig-pixman/pixman.zig" },
|
||||
};
|
||||
const wlroots = zbs.Pkg{
|
||||
.name = "wlroots",
|
||||
.source = .{ .path = "deps/zig-wlroots/src/wlroots.zig" },
|
||||
.dependencies = &[_]zbs.Pkg{ wayland, xkbcommon, pixman },
|
||||
};
|
||||
|
||||
river.step.dependOn(&scanner.step);
|
||||
|
||||
river.linkLibC();
|
||||
river.linkSystemLibrary("libevdev");
|
||||
river.linkSystemLibrary("libinput");
|
||||
|
||||
river.addPackage(wayland);
|
||||
river.addModule("wayland", wayland);
|
||||
river.linkSystemLibrary("wayland-server");
|
||||
|
||||
river.addPackage(xkbcommon);
|
||||
river.addModule("xkbcommon", xkbcommon);
|
||||
river.linkSystemLibrary("xkbcommon");
|
||||
|
||||
river.addPackage(pixman);
|
||||
river.addModule("pixman", pixman);
|
||||
river.linkSystemLibrary("pixman-1");
|
||||
|
||||
river.addPackage(wlroots);
|
||||
river.addModule("wlroots", wlroots);
|
||||
river.linkSystemLibrary("wlroots");
|
||||
|
||||
river.addPackagePath("flags", "common/flags.zig");
|
||||
river.addPackagePath("globber", "common/globber.zig");
|
||||
river.addCSourceFile("river/wlroots_log_wrapper.c", &[_][]const u8{ "-std=c99", "-O2" });
|
||||
river.addModule("flags", flags);
|
||||
river.addModule("globber", globber);
|
||||
river.addCSourceFile(.{
|
||||
.file = .{ .path = "river/wlroots_log_wrapper.c" },
|
||||
.flags = &.{ "-std=c99", "-O2" },
|
||||
});
|
||||
|
||||
// TODO: remove when zig issue #131 is implemented
|
||||
scanner.addCSource(river);
|
||||
|
||||
river.strip = strip;
|
||||
river.pie = pie;
|
||||
river.install();
|
||||
|
||||
b.installArtifact(river);
|
||||
}
|
||||
|
||||
{
|
||||
const riverctl = b.addExecutable("riverctl", "riverctl/main.zig");
|
||||
riverctl.setTarget(target);
|
||||
riverctl.setBuildMode(mode);
|
||||
const riverctl = b.addExecutable(.{
|
||||
.name = "riverctl",
|
||||
.root_source_file = .{ .path = "riverctl/main.zig" },
|
||||
.target = target,
|
||||
.optimize = optimize,
|
||||
});
|
||||
riverctl.addOptions("build_options", options);
|
||||
|
||||
riverctl.step.dependOn(&scanner.step);
|
||||
riverctl.addPackagePath("flags", "common/flags.zig");
|
||||
riverctl.addPackage(.{
|
||||
.name = "wayland",
|
||||
.source = .{ .generated = &scanner.result },
|
||||
});
|
||||
riverctl.addModule("flags", flags);
|
||||
riverctl.addModule("wayland", wayland);
|
||||
riverctl.linkLibC();
|
||||
riverctl.linkSystemLibrary("wayland-client");
|
||||
|
||||
@ -193,21 +197,21 @@ pub fn build(b: *zbs.Builder) !void {
|
||||
|
||||
riverctl.strip = strip;
|
||||
riverctl.pie = pie;
|
||||
riverctl.install();
|
||||
|
||||
b.installArtifact(riverctl);
|
||||
}
|
||||
|
||||
{
|
||||
const rivertile = b.addExecutable("rivertile", "rivertile/main.zig");
|
||||
rivertile.setTarget(target);
|
||||
rivertile.setBuildMode(mode);
|
||||
const rivertile = b.addExecutable(.{
|
||||
.name = "rivertile",
|
||||
.root_source_file = .{ .path = "rivertile/main.zig" },
|
||||
.target = target,
|
||||
.optimize = optimize,
|
||||
});
|
||||
rivertile.addOptions("build_options", options);
|
||||
|
||||
rivertile.step.dependOn(&scanner.step);
|
||||
rivertile.addPackagePath("flags", "common/flags.zig");
|
||||
rivertile.addPackage(.{
|
||||
.name = "wayland",
|
||||
.source = .{ .generated = &scanner.result },
|
||||
});
|
||||
rivertile.addModule("flags", flags);
|
||||
rivertile.addModule("wayland", wayland);
|
||||
rivertile.linkLibC();
|
||||
rivertile.linkSystemLibrary("wayland-client");
|
||||
|
||||
@ -215,15 +219,13 @@ pub fn build(b: *zbs.Builder) !void {
|
||||
|
||||
rivertile.strip = strip;
|
||||
rivertile.pie = pie;
|
||||
rivertile.install();
|
||||
|
||||
b.installArtifact(rivertile);
|
||||
}
|
||||
|
||||
{
|
||||
const file = try fs.path.join(b.allocator, &[_][]const u8{ b.cache_root, "river-protocols.pc" });
|
||||
const pkgconfig_file = try fs.cwd().createFile(file, .{});
|
||||
|
||||
const writer = pkgconfig_file.writer();
|
||||
try writer.print(
|
||||
const wf = Build.Step.WriteFile.create(b);
|
||||
const pc_file = wf.add("river-protocols.pc", b.fmt(
|
||||
\\prefix={s}
|
||||
\\datadir=${{prefix}}/share
|
||||
\\pkgdatadir=${{datadir}}/river-protocols
|
||||
@ -232,16 +234,23 @@ pub fn build(b: *zbs.Builder) !void {
|
||||
\\URL: https://github.com/riverwm/river
|
||||
\\Description: protocol files for the river wayland compositor
|
||||
\\Version: {s}
|
||||
, .{ b.install_prefix, full_version });
|
||||
defer pkgconfig_file.close();
|
||||
, .{ b.install_prefix, full_version }));
|
||||
|
||||
b.installFile("protocol/river-layout-v3.xml", "share/river-protocols/river-layout-v3.xml");
|
||||
b.installFile(file, "share/pkgconfig/river-protocols.pc");
|
||||
b.getInstallStep().dependOn(&b.addInstallFile(pc_file, "share/pkgconfig/river-protocols.pc").step);
|
||||
}
|
||||
|
||||
if (man_pages) {
|
||||
const scdoc_step = ScdocStep.create(b);
|
||||
try scdoc_step.install();
|
||||
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.
|
||||
scdoc.addFileArg(.{ .path = "doc/" ++ page ++ ".1.scd" });
|
||||
|
||||
const stdout = scdoc.captureStdOut();
|
||||
b.getInstallStep().dependOn(&b.addInstallFile(stdout, "share/man/man1/" ++ page ++ ".1").step);
|
||||
}
|
||||
}
|
||||
|
||||
if (bash_completion) {
|
||||
@ -257,65 +266,14 @@ pub fn build(b: *zbs.Builder) !void {
|
||||
}
|
||||
|
||||
{
|
||||
const globber_test = b.addTest("common/globber.zig");
|
||||
globber_test.setTarget(target);
|
||||
globber_test.setBuildMode(mode);
|
||||
const globber_test = b.addTest(.{
|
||||
.root_source_file = .{ .path = "common/globber.zig" },
|
||||
.target = target,
|
||||
.optimize = optimize,
|
||||
});
|
||||
const run_globber_test = b.addRunArtifact(globber_test);
|
||||
|
||||
const test_step = b.step("test", "Run the tests");
|
||||
test_step.dependOn(&globber_test.step);
|
||||
test_step.dependOn(&run_globber_test.step);
|
||||
}
|
||||
}
|
||||
|
||||
const ScdocStep = struct {
|
||||
const scd_paths = [_][]const u8{
|
||||
"doc/river.1.scd",
|
||||
"doc/riverctl.1.scd",
|
||||
"doc/rivertile.1.scd",
|
||||
};
|
||||
|
||||
builder: *zbs.Builder,
|
||||
step: zbs.Step,
|
||||
|
||||
fn create(builder: *zbs.Builder) *ScdocStep {
|
||||
const self = builder.allocator.create(ScdocStep) catch @panic("out of memory");
|
||||
self.* = init(builder);
|
||||
return self;
|
||||
}
|
||||
|
||||
fn init(builder: *zbs.Builder) ScdocStep {
|
||||
return ScdocStep{
|
||||
.builder = builder,
|
||||
.step = zbs.Step.init(.custom, "Generate man pages", builder.allocator, make),
|
||||
};
|
||||
}
|
||||
|
||||
fn make(step: *zbs.Step) !void {
|
||||
const self = @fieldParentPtr(ScdocStep, "step", step);
|
||||
for (scd_paths) |path| {
|
||||
const command = try std.fmt.allocPrint(
|
||||
self.builder.allocator,
|
||||
"scdoc < {s} > {s}",
|
||||
.{ 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)];
|
||||
const basename_no_ext = fs.path.basename(path_no_ext);
|
||||
const section = path_no_ext[(path_no_ext.len - 1)..];
|
||||
|
||||
const output = try std.fmt.allocPrint(
|
||||
self.builder.allocator,
|
||||
"share/man/man{s}/{s}",
|
||||
.{ section, basename_no_ext },
|
||||
);
|
||||
|
||||
self.builder.installFile(path_no_ext, output);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
Reference in New Issue
Block a user