-
Notifications
You must be signed in to change notification settings - Fork 9
/
build.zig
193 lines (177 loc) · 5.71 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
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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
const std = @import("std");
pub fn build(b: *std.Build) !void {
const optimize = b.standardOptimizeOption(.{ .preferred_optimize_mode = .ReleaseFast });
const target = b.standardTargetOptions(.{});
const dep_stb = b.dependency("stb", .{});
const stb_module = b.addModule("stb", .{
.root_source_file = b.path("external/stb.zig"),
.target = target,
.optimize = optimize,
});
stb_module.addIncludePath(dep_stb.path(""));
stb_module.addCSourceFile(.{ .file = b.path("external/stb.c") });
const av_module = b.addModule("av", .{
.root_source_file = b.path("external/av.zig"),
.target = target,
.optimize = optimize,
});
linkFfmpeg(av_module);
const libglyph = b.addModule("libglyph", .{
.root_source_file = b.path("src/core.zig"),
.target = target,
.optimize = optimize,
.imports = &.{
.{ .name = "stb", .module = stb_module },
},
});
const term_module = b.addModule("libglyphterm", .{
.root_source_file = b.path("src/term.zig"),
.target = target,
.optimize = optimize,
.imports = &.{
.{ .name = "libglyph", .module = libglyph },
},
});
const video_module = b.addModule("libglyphav", .{
.root_source_file = b.path("src/video.zig"),
.target = target,
.optimize = optimize,
.imports = &.{
.{ .name = "stb", .module = stb_module },
.{ .name = "av", .module = av_module },
.{ .name = "libglyph", .module = libglyph },
.{ .name = "libglyphterm", .module = term_module },
},
});
const image_module = b.addModule("libglyphimg", .{
.root_source_file = b.path("src/image.zig"),
.imports = &.{
.{ .name = "stb", .module = stb_module },
.{ .name = "av", .module = av_module },
.{ .name = "libglyph", .module = libglyph },
.{ .name = "libglyphterm", .module = term_module },
},
});
try runZig(
b,
target,
optimize,
libglyph,
image_module,
video_module,
term_module,
);
}
fn setupExecutable(
b: *std.Build,
name: []const u8,
target: std.Build.ResolvedTarget,
optimize: std.builtin.OptimizeMode,
libglyph: *std.Build.Module,
image_module: *std.Build.Module,
video_module: *std.Build.Module,
term_module: *std.Build.Module,
link_libc: bool,
) !*std.Build.Step.Compile {
const exe = b.addExecutable(.{
.name = name,
.root_source_file = b.path("src/main.zig"),
.target = target,
.optimize = optimize,
.link_libc = link_libc,
});
const clap = b.dependency("clap", .{});
exe.root_module.addImport("clap", clap.module("clap"));
exe.root_module.addImport("libglyph", libglyph);
exe.root_module.addImport("libglyphimg", image_module);
exe.root_module.addImport("libglyphav", video_module);
exe.root_module.addImport("libglyphterm", term_module);
return exe;
}
fn setupTest(
b: *std.Build,
name: []const u8,
target: std.Build.ResolvedTarget,
optimize: std.builtin.OptimizeMode,
libglyph: *std.Build.Module,
image_module: *std.Build.Module,
video_module: *std.Build.Module,
term_module: *std.Build.Module,
link_libc: bool,
) !*std.Build.Step.Compile {
const unit_test = b.addTest(.{
.name = name,
.root_source_file = b.path("src/main.zig"),
.target = target,
.optimize = optimize,
.link_libc = link_libc,
});
const clap = b.dependency("clap", .{});
unit_test.root_module.addImport("clap", clap.module("clap"));
unit_test.root_module.addImport("libglyph", libglyph);
unit_test.root_module.addImport("libglyphimg", image_module);
unit_test.root_module.addImport("libglyphav", video_module);
unit_test.root_module.addImport("libglyphterm", term_module);
return unit_test;
}
fn linkFfmpeg(lib: *std.Build.Module) void {
lib.linkSystemLibrary("libavformat", .{ .use_pkg_config = .force });
lib.linkSystemLibrary("libavcodec", .{ .use_pkg_config = .force });
lib.linkSystemLibrary("libavutil", .{ .use_pkg_config = .force });
lib.linkSystemLibrary("libswscale", .{ .use_pkg_config = .force });
lib.linkSystemLibrary("libswresample", .{ .use_pkg_config = .force });
}
fn runZig(
b: *std.Build,
target: std.Build.ResolvedTarget,
optimize: std.builtin.OptimizeMode,
libglyph: *std.Build.Module,
image_module: *std.Build.Module,
video_module: *std.Build.Module,
term_module: *std.Build.Module,
) !void {
const exe = try setupExecutable(
b,
"asciigen",
target,
optimize,
libglyph,
image_module,
video_module,
term_module,
true,
);
const exe_check = try setupExecutable(
b,
"asciigen-check",
target,
optimize,
libglyph,
image_module,
video_module,
term_module,
false,
);
const check_step = b.step("check", "Run the check");
check_step.dependOn(&exe_check.step);
b.installArtifact(exe);
const run_cmd = b.addRunArtifact(exe);
run_cmd.step.dependOn(b.getInstallStep());
if (b.args) |args| run_cmd.addArgs(args);
const run_step = b.step("run", "Run the app");
run_step.dependOn(&run_cmd.step);
const test_step = b.step("test", "Run the test");
const unit_tests = try setupTest(
b,
"asciigen-check",
target,
optimize,
libglyph,
image_module,
video_module,
term_module,
false,
);
const run_unit_tests = b.addRunArtifact(unit_tests);
test_step.dependOn(&run_unit_tests.step);
}