-
Notifications
You must be signed in to change notification settings - Fork 5
/
build.zig
125 lines (115 loc) · 3.72 KB
/
build.zig
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
const std = @import("std");
const Builder = std.build.Builder;
const FileSource = std.build.FileSource;
const Mode = std.builtin.Mode;
const EXAMPLES = [_][]const u8{
"arc",
"arc_negative",
"bezier",
"cairoscript",
"clip",
"clip_image",
"compositing",
"curve_rectangle",
"curve_to",
"dash",
"ellipse",
"fill_and_stroke2",
"fill_style",
"glyphs",
"gradient",
"grid",
"group",
"image",
"image_pattern",
"mask",
"multi_segment_caps",
"pango_simple",
"pythagoras_tree",
"rounded_rectangle",
"save_and_restore",
"set_line_cap",
"set_line_join",
"sierpinski",
"singular",
"spiral",
"spirograph",
"surface_image",
"surface_pdf",
"surface_svg",
"surface_xcb",
"text",
"text_align_center",
"text_extents",
"three_phases",
};
pub fn build(b: *Builder) void {
const target = b.standardTargetOptions(.{});
const mode = b.standardReleaseOptions();
// b.verbose = true;
// b.verbose_cimport = true;
// b.verbose_link = true;
const test_all_modes_step = b.step("test", "Run all tests in all modes.");
inline for ([_]Mode{ Mode.Debug, Mode.ReleaseFast, Mode.ReleaseSafe, Mode.ReleaseSmall }) |test_mode| {
const mode_str = comptime modeToString(test_mode);
const name = "test-" ++ mode_str;
const desc = "Run all tests in " ++ mode_str ++ " mode.";
const tests = b.addTest("src/pangocairo.zig");
tests.setBuildMode(test_mode);
tests.setTarget(target);
tests.setNamePrefix(mode_str ++ " ");
tests.linkLibC();
tests.linkSystemLibrary("xcb");
tests.linkSystemLibrary("pango");
tests.linkSystemLibrary("cairo");
tests.linkSystemLibrary("pangocairo");
const test_step = b.step(name, desc);
test_step.dependOn(&tests.step);
test_all_modes_step.dependOn(test_step);
}
// const examples_step = b.step("examples", "Build all examples");
inline for (EXAMPLES) |name| {
const example = b.addExecutable(name, "examples" ++ std.fs.path.sep_str ++ name ++ ".zig");
example.addPackage(.{ .name = "cairo", .path = FileSource{ .path = "src/cairo.zig" } });
if (shouldIncludeXcb(name)) {
example.addPackage(.{ .name = "xcb", .path = FileSource{ .path = "src/xcb.zig" } });
}
if (shouldIncludePango(name)) {
example.addPackage(.{ .name = "pangocairo", .path = FileSource{ .path = "src/pangocairo.zig" } });
}
example.setBuildMode(mode);
example.setTarget(target);
example.linkLibC();
example.linkSystemLibrary("cairo");
if (shouldIncludeXcb(name)) {
example.linkSystemLibrary("xcb");
}
example.linkSystemLibrary("pangocairo");
// example.install(); // uncomment to build ALL examples (it takes ~2 minutes)
// examples_step.dependOn(&example.step);
const run_cmd = example.run();
run_cmd.step.dependOn(b.getInstallStep());
const desc = "Run the " ++ name ++ " example";
const run_step = b.step(name, desc);
run_step.dependOn(&run_cmd.step);
}
// b.default_step.dependOn(test_all_modes_step);
}
fn modeToString(mode: Mode) []const u8 {
return switch (mode) {
Mode.Debug => "debug",
Mode.ReleaseFast => "release-fast",
Mode.ReleaseSafe => "release-safe",
Mode.ReleaseSmall => "release-small",
};
}
fn shouldIncludePango(comptime name: []const u8) bool {
var b = false;
if (name.len > 6) {
b = std.mem.eql(u8, name[0..6], "pango_");
}
return b;
}
fn shouldIncludeXcb(comptime name: []const u8) bool {
return std.mem.eql(u8, name, "surface_xcb");
}