-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathbuild.zig
More file actions
76 lines (61 loc) · 2.08 KB
/
Copy pathbuild.zig
File metadata and controls
76 lines (61 loc) · 2.08 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
const std = @import("std");
pub fn build(b: *std.Build) !void {
// get target
const target = b.standardTargetOptions(.{});
// get optimize
const optimize = b.standardOptimizeOption(.{});
// export zig-tray module
const zigTray = switch (target.result.os.tag) {
.windows => b.addModule("tray", .{
.root_source_file = b.path("src/tray_windows.zig"),
}),
else => @panic("Unsupported platform, now only support windows"),
};
// generate docs
generateDocs(b, target, optimize);
// build example
example(b, target, optimize, zigTray);
}
/// for generate docs
fn generateDocs(
b: *std.Build,
target: std.Build.ResolvedTarget,
optimize: std.builtin.OptimizeMode,
) void {
const zig_tray_obj = b.addObject(.{
.name = "zig-tray-obj",
.root_source_file = b.path("src/tray_windows.zig"),
.target = target,
.optimize = optimize,
});
const docs_step = b.step("docs", "Generate docs");
const docs_install = b.addInstallDirectory(.{
.source_dir = zig_tray_obj.getEmittedDocs(),
.install_dir = .prefix,
.install_subdir = "docs",
});
docs_step.dependOn(&docs_install.step);
}
/// for build example
fn example(b: *std.Build, target: std.Build.ResolvedTarget, optimize: std.builtin.OptimizeMode, module: *std.Build.Module) void {
if (target.result.os.tag != .windows)
return;
// build example
const exe = b.addExecutable(.{
.name = "zig-tray",
.root_source_file = b.path("example/main.zig"),
.target = target,
.optimize = optimize,
});
exe.root_module.addImport("tray", module);
const installfile = b.addInstallFile(b.path("example/icon.ico"), "bin/icon.ico");
const artiface = b.addInstallArtifact(exe, .{});
const run_cmd = b.addRunArtifact(exe);
run_cmd.step.dependOn(&installfile.step);
run_cmd.step.dependOn(&artiface.step);
if (b.args) |args| {
run_cmd.addArgs(args);
}
const run_step = b.step("example", "Run the app");
run_step.dependOn(&run_cmd.step);
}