-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.zig
More file actions
83 lines (63 loc) · 2.78 KB
/
build.zig
File metadata and controls
83 lines (63 loc) · 2.78 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
const std = @import("std");
const assert = std.debug.assert;
const fs = std.fs;
const mem = std.mem;
const Scanner = @import("wayland").Scanner;
/// While a riverdeck 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.
const version = "0.7.0";
pub fn build(b: *std.Build) !void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
const pie = b.option(bool, "pie", "Build a Position Independent Executable") orelse false;
const full_version = blk: {
if (mem.endsWith(u8, version, "-dev")) {
var ret: u8 = undefined;
const git_describe_long = b.runAllowFail(
&[_][]const u8{ "git", "-C", b.build_root.path orelse ".", "describe", "--long" },
&ret,
.Inherit,
) 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 try std.fmt.allocPrintSentinel(b.allocator, version ++ ".{s}+{s}", .{
commit_count,
commit_hash[1..],
}, 0);
} else {
break :blk version;
}
};
const options = b.addOptions();
options.addOption([]const u8, "version", full_version);
const scanner = Scanner.create(b, .{});
scanner.addCustomProtocol(b.path("protocol/river-layout-v3.xml"));
scanner.generate("wl_output", 4);
scanner.generate("river_layout_manager_v3", 2);
const wayland = b.createModule(.{ .root_source_file = scanner.result });
const flags = b.createModule(.{ .root_source_file = b.path("common/flags.zig") });
const riverdeck = b.addExecutable(.{
.name = "riverdeck",
.root_module = b.createModule(.{
.root_source_file = b.path("src/main.zig"),
.target = target,
.optimize = optimize,
}),
});
riverdeck.root_module.addOptions("build_options", options);
riverdeck.linkLibC();
riverdeck.root_module.addImport("wayland", wayland);
riverdeck.linkSystemLibrary("wayland-client");
riverdeck.root_module.addImport("flags", flags);
riverdeck.pie = pie;
b.installArtifact(riverdeck);
b.installFile("doc/riverdeck.1", "share/man/man1/riverdeck.1");
}