-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.zig
More file actions
161 lines (130 loc) · 5.24 KB
/
build.zig
File metadata and controls
161 lines (130 loc) · 5.24 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
const std = @import("std");
const Tag = std.Target.Os.Tag;
const builtin = @import("builtin");
const NAME = "zinit";
const EXAMPLES = "examples";
const examples = [_]Example{
.{ .name = "helloworld", .path = EXAMPLES ++ "/helloworld.zig" },
.{ .name = "drag_drop", .path = EXAMPLES ++ "/drag_drop.zig" },
.{ .name = "raw_input", .path = EXAMPLES ++ "/raw_input.zig" },
.{ .name = "dev", .path = EXAMPLES ++ "/dev.zig" },
};
pub fn build(b: *std.Build) !void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
const module = b.addModule(NAME, .{
.root_source_file = b.path("src/root.zig"),
.target = target,
.optimize = optimize,
});
var deps: std.ArrayList(std.Build.Module.Import) = .empty;
defer deps.deinit(b.allocator);
const uuid = b.dependency("uuid", .{});
try deps.append(b.allocator, .{ .name = NAME, .module = module });
try deps.append(b.allocator, .{ .name = "uuid", .module = uuid.module("uuid") });
var assets_dir = b.addInstallDirectory(.{
.source_dir = b.path("examples/assets"),
.install_dir = .bin,
.install_subdir = "assets",
});
module.addImport("uuid", uuid.module("uuid"));
switch (builtin.target.os.tag) {
.windows => {
const windows_zig = b.dependency("windows", .{});
// Note: To build exe so a console window doesn't appear
// Add this to any exe build: `exe.subsystem = .Windows;`
module.addImport("windows", windows_zig.module("windows"));
try deps.append(b.allocator, .{ .name = "windows", .module = windows_zig.module("windows") });
},
.linux => {
const Scanner = @import("wayland").Scanner;
module.linkSystemLibrary("wayland-client", .{});
module.linkSystemLibrary("wayland-cursor", .{});
// TODO: Remove this in favor of https://codeberg.org/ifreund/zig-xkbcommon when
// is updated to zig v0.15.1
module.linkSystemLibrary("xkbcommon", .{});
module.linkSystemLibrary("dbus-1", .{});
module.addIncludePath(.{ .cwd_relative = "/usr/include/dbus-1.0" });
module.addIncludePath(.{ .cwd_relative = "/usr/lib/x86_64-linux-gnu/dbus-1.0/include" });
const scanner = Scanner.create(b, .{});
const wayland = b.createModule(.{ .root_source_file = scanner.result });
// Stable
scanner.addSystemProtocol("stable/xdg-shell/xdg-shell.xml");
scanner.addSystemProtocol("stable/tablet/tablet-v2.xml");
// Staging
scanner.addSystemProtocol("staging/cursor-shape/cursor-shape-v1.xml");
// Unstable
scanner.addSystemProtocol("unstable/xdg-decoration/xdg-decoration-unstable-v1.xml");
scanner.generate("wl_compositor", 1);
scanner.generate("wl_shm", 1);
scanner.generate("wl_output", 1);
scanner.generate("xdg_wm_base", 1);
scanner.generate("zxdg_decoration_manager_v1", 1);
scanner.generate("wp_cursor_shape_manager_v1", 1);
scanner.generate("wl_seat", 1);
module.addImport("wayland", wayland);
try deps.append(b.allocator, .{ .name = "wayland", .module = wayland });
},
else => {},
}
const test_module = b.createModule(.{
.root_source_file = b.path("src/root.zig"),
.target = target,
.optimize = optimize,
});
const lib_unit_tests = b.addTest(.{ .root_module = test_module });
const run_lib_unit_tests = b.addRunArtifact(lib_unit_tests);
const test_step = b.step("test", "Run unit tests");
test_step.dependOn(&run_lib_unit_tests.step);
inline for (examples) |example| {
addExample(
b,
target,
optimize,
example,
deps.items,
builtin.target.os.tag == .linux,
&.{
.{ "wayland-client", .linux },
},
&assets_dir.step,
);
}
}
const Example = struct {
name: []const u8,
path: []const u8,
};
pub fn addExample(
b: *std.Build,
target: std.Build.ResolvedTarget,
optimize: std.builtin.OptimizeMode,
comptime example: Example,
imports: []const std.Build.Module.Import,
link_lib_c: bool,
system_libraries: []const std.meta.Tuple(&.{ []const u8, Tag }),
assets_dir: *std.Build.Step,
) void {
const exe = b.addExecutable(.{ .name = example.name, .root_module = b.createModule(.{
.root_source_file = b.path(example.path),
.target = target,
.optimize = optimize,
.imports = imports,
}) });
exe.addWin32ResourceFile(.{ .file = b.path("app.rc") });
exe.step.dependOn(assets_dir);
b.installArtifact(exe);
if (link_lib_c) exe.linkLibC();
for (system_libraries) |library| {
if (library[1] == builtin.target.os.tag) {
exe.linkSystemLibrary(library[0]);
}
}
const ecmd = b.addRunArtifact(exe);
ecmd.step.dependOn(b.getInstallStep());
if (b.args) |args| {
ecmd.addArgs(args);
}
const estep = b.step("example-" ++ example.name, "Run example-" ++ example.name);
estep.dependOn(&ecmd.step);
}