-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.zig
More file actions
109 lines (90 loc) · 2.93 KB
/
Copy pathbuild.zig
File metadata and controls
109 lines (90 loc) · 2.93 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
const std = @import("std");
const Tag = std.Target.Os.Tag;
const builtin = @import("builtin");
const NAME = "menu";
const EXAMPLES = "examples";
const examples = [_]Example{
.{ .name = "menu", .path = EXAMPLES ++ "/menu.zig" },
.{ .name = "taskbar", .path = EXAMPLES ++ "/taskbar.zig" },
};
pub fn build(b: *std.Build) !void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
var deps: std.ArrayList(std.Build.Module.Import) = .empty;
defer deps.deinit(b.allocator);
const mod = b.addModule("menu_zig", .{
.root_source_file = b.path("src/root.zig"),
.target = target,
.optimize = optimize,
});
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;`
mod.addImport("windows", windows_zig.module("windows"));
try deps.append(b.allocator, .{ .name = "windows", .module = windows_zig.module("windows") });
},
else => {}
}
try deps.append(b.allocator, .{ .name = NAME, .module = mod });
inline for (examples) |example| {
addExample(
b,
target,
optimize,
example,
deps.items,
builtin.target.os.tag == .linux,
&.{
.{ "wayland-client", .linux },
},
null,
);
}
}
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 estep = b.step("run-" ++ example.name, "Run example " ++ example.name);
const exe = b.addExecutable(.{ .name = example.name, .root_module = b.createModule(.{
.root_source_file = b.path(example.path),
.target = target,
.optimize = optimize,
.imports = imports,
}) });
if (b.lazyDependency("zinit", .{
.target = target,
.optimize = optimize,
})) |zinit_dep| {
exe.root_module.addImport("zinit", zinit_dep.module("zinit"));
}
// exe.addWin32ResourceFile(.{ .file = b.path("app.rc") });
if (assets_dir) |ad| {
exe.step.dependOn(ad);
}
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);
}
estep.dependOn(&ecmd.step);
}