-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.zig
76 lines (59 loc) · 1.79 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
const std = @import("std");
const CrossTarget = std.zig.CrossTarget;
const fs = std.fs;
const path = std.fs.path;
const info = std.log.info;
const endsWith = std.mem.endsWith;
const concat = std.mem.concat;
const lastIndexOfScalar = std.mem.lastIndexOfScalar;
pub fn build(b: *std.build.Builder) !void {
b.setPreferredReleaseMode(.ReleaseFast);
const mode = b.standardReleaseOptions();
// find all zig source code
const src_dir_name = "src";
// TODO: Perhaps derive a convention for root-level libraries
var src_dir = try fs.cwd().openIterableDir(src_dir_name, .{});
defer src_dir.close();
var src_dir_it = src_dir.iterate();
while (try src_dir_it.next()) |entry| {
if (entry.kind != .File) {
continue;
}
const lib_file_name = entry.name;
if (!endsWith(u8, lib_file_name, ".zig")) {
continue;
}
const lib_file = b.fmt("{s}/{s}", .{
src_dir_name,
lib_file_name,
});
const ext_index = lastIndexOfScalar(
u8,
lib_file_name,
'.',
) orelse 0;
const lib_name = lib_file_name[0..ext_index];
const lib = b.addSharedLibrary(
lib_name,
lib_file,
.unversioned,
);
lib.setTarget(CrossTarget{
.cpu_arch = .wasm32,
.os_tag = .freestanding,
});
lib.setBuildMode(mode);
lib.install();
const lib_test = b.addTest(lib_file);
lib_test.setBuildMode(mode);
const lib_test_name = b.fmt("{s}{s}", .{
"test-",
lib_name,
});
const test_step = b.step(
lib_test_name,
"Run library tests",
);
test_step.dependOn(&lib_test.step);
}
}