-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.zig
More file actions
106 lines (87 loc) · 2.9 KB
/
build.zig
File metadata and controls
106 lines (87 loc) · 2.9 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
const std = @import("std");
const builtin = @import("builtin");
const Tag = std.Target.Os.Tag;
const NAME = "notify";
const EXAMPLES = "examples";
const examples = [_]Example{
.{ .name = "dev", .path = "src/main.zig" },
.{ .name = "with_actions", .path = EXAMPLES ++ "/with_actions.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(NAME, .{
.root_source_file = b.path("src/root.zig"),
.target = target,
});
switch (builtin.target.os.tag) {
.windows => {
const windows_zig = b.dependency("windows", .{});
const windows_zig_mod = windows_zig.module("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_mod);
try deps.append(b.allocator, .{ .name = "windows", .module = windows_zig_mod });
},
else => {},
}
try deps.append(b.allocator, .{ .name = NAME, .module = mod });
var assets_dir = b.addInstallDirectory(.{
.source_dir = b.path("examples/assets"),
.install_dir = .bin,
.install_subdir = "assets",
});
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("run-" ++ example.name, "Run example " ++ example.name);
estep.dependOn(&ecmd.step);
}