-
Notifications
You must be signed in to change notification settings - Fork 127
Expand file tree
/
Copy pathbuild.zig
More file actions
150 lines (138 loc) · 4.5 KB
/
build.zig
File metadata and controls
150 lines (138 loc) · 4.5 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
const std = @import("std");
pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
const use_llvm = b.option(bool, "llvm", "Use the LLVM backend for compile steps") orelse true;
const root_source_file = b.path("src/main.zig");
// Dependencies
const zigimg_dep = b.dependency("zigimg", .{
.optimize = optimize,
.target = target,
});
const uucode_dep = b.dependency("uucode", .{
.target = target,
.optimize = optimize,
.fields = @as([]const []const u8, &.{
"east_asian_width",
"grapheme_break",
"general_category",
"is_emoji_presentation",
}),
});
// Module
const vaxis_mod = b.addModule("vaxis", .{
.root_source_file = root_source_file,
.target = target,
.optimize = optimize,
});
vaxis_mod.addImport("zigimg", zigimg_dep.module("zigimg"));
vaxis_mod.addImport("uucode", uucode_dep.module("uucode"));
// Examples
const Example = enum {
cli,
counter,
fuzzy,
image,
main,
scroll,
split_view,
table,
text_input,
text_view,
list_view,
vaxis,
view,
vt,
};
var examples: std.EnumMap(Example, *std.Build.Module) = .init(.{});
inline for (std.meta.fields(Example)) |field| {
const example: Example = @enumFromInt(field.value);
examples.put(
example,
b.createModule(.{
.root_source_file = b.path(
b.fmt("examples/{t}.zig", .{example}),
),
.target = target,
.optimize = optimize,
.imports = &.{
.{ .name = "vaxis", .module = vaxis_mod },
},
}),
);
}
const example_option = b.option(Example, "example", "Example to run (default: text_input)") orelse .text_input;
const example_step = b.step("example", "Run example");
const example = b.addExecutable(.{
.name = b.fmt("example-{t}", .{example_option}),
.root_module = examples.get(example_option) orelse unreachable,
.use_llvm = use_llvm,
});
b.getInstallStep().dependOn(&example.step);
const example_run = b.addRunArtifact(example);
example_step.dependOn(&example_run.step);
// Benchmarks
const bench_step = b.step("bench", "Run benchmarks");
const bench = b.addExecutable(.{
.name = "bench",
.use_llvm = use_llvm,
.root_module = b.createModule(.{
.root_source_file = b.path("bench/bench.zig"),
.target = target,
.optimize = optimize,
.imports = &.{
.{ .name = "vaxis", .module = vaxis_mod },
},
}),
});
const bench_run = b.addRunArtifact(bench);
if (b.args) |args| {
bench_run.addArgs(args);
}
bench_step.dependOn(&bench_run.step);
// Tests
const tests_step = b.step("test", "Run tests");
const tests = b.addTest(.{
.use_llvm = use_llvm,
.root_module = b.createModule(.{
.root_source_file = b.path("src/main.zig"),
.target = target,
.optimize = optimize,
.imports = &.{
.{ .name = "zigimg", .module = zigimg_dep.module("zigimg") },
.{ .name = "uucode", .module = uucode_dep.module("uucode") },
},
}),
});
// Let's make sure that all of the examples compile and can run any tests
// that they may have defined.
var it = examples.iterator();
while (it.next()) |v| {
const e = b.addTest(.{
.use_llvm = use_llvm,
.root_module = v.value.*,
});
const r = b.addRunArtifact(e);
tests_step.dependOn(&r.step);
}
const tests_run = b.addRunArtifact(tests);
b.installArtifact(tests);
tests_step.dependOn(&tests_run.step);
// Docs
const docs_step = b.step("docs", "Build the vaxis library docs");
const docs_obj = b.addObject(.{
.name = "vaxis",
.use_llvm = use_llvm,
.root_module = b.createModule(.{
.root_source_file = root_source_file,
.target = target,
.optimize = optimize,
}),
});
const docs = docs_obj.getEmittedDocs();
docs_step.dependOn(&b.addInstallDirectory(.{
.source_dir = docs,
.install_dir = .prefix,
.install_subdir = "docs",
}).step);
}