-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.zig
More file actions
162 lines (142 loc) · 5.83 KB
/
build.zig
File metadata and controls
162 lines (142 loc) · 5.83 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
151
152
153
154
155
156
157
158
159
160
161
162
const std = @import("std");
pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
const test_filters = b.option([]const []const u8, "test-filter", "Skip tests that do not match any filter") orelse &[0][]const u8{};
// Prepare praxis module
const praxis = b.dependency("praxis", .{ .target = target, .optimize = optimize });
const praxis_module = praxis.module("praxis");
const zstbi = b.dependency("zstbi", .{ .target = target, .optimize = optimize });
const zstbi_module = zstbi.module("root");
add_imports(b, &target, zstbi_module);
const zg = b.dependency("zg", .{ .target = target, .optimize = optimize });
const lib_mod = b.addModule("resources", .{
.root_source_file = b.path("src/root.zig"),
.target = target,
.optimize = optimize,
.imports = &.{
.{ .name = "praxis", .module = praxis_module },
.{ .name = "zstbi", .module = zstbi_module },
.{ .name = "Normalize", .module = zg.module("Normalize") },
},
});
const lib = b.addLibrary(.{
.linkage = .static,
.name = "resources",
.root_module = lib_mod,
});
b.installArtifact(lib);
const tests = b.addTest(.{
.root_module = b.createModule(.{
.root_source_file = b.path("src/test.zig"),
.target = target,
.optimize = optimize,
.imports = &.{
.{ .name = "praxis", .module = praxis_module },
.{ .name = "zstbi", .module = zstbi_module },
.{ .name = "Normalize", .module = zg.module("Normalize") },
},
}),
.filters = test_filters,
});
const test_folder = b.path("./test/");
const opts = b.addOptions();
opts.addOptionPath("test_folder", test_folder);
tests.root_module.addImport("test_folder", opts.createModule());
tests.root_module.addAnonymousImport("wav_32", .{
.root_source_file = b.path("./test/test_32bit.wav"),
});
tests.root_module.addAnonymousImport("wav_16", .{
.root_source_file = b.path("./test/test_16bit.wav"),
});
tests.root_module.addAnonymousImport("wav_32_stereo", .{
.root_source_file = b.path("./test/test_32bit_stereo.wav"),
});
tests.root_module.addAnonymousImport("wav_fade_edges", .{
.root_source_file = b.path("./test/test_wav_fade_edges.wav"),
});
const run_tests = b.addRunArtifact(tests);
const test_step = b.step("test", "Run unit tests");
test_step.dependOn(&run_tests.step);
const install_docs = b.addInstallDirectory(.{
.source_dir = lib.getEmittedDocs(),
.install_dir = .prefix,
.install_subdir = "docs",
});
const docs_step = b.step("docs", "Generate docs into zig-out/docs");
docs_step.dependOn(&install_docs.step);
// Build the helper `resources` command.
const exe_mod = b.createModule(.{
.root_source_file = b.path("cmd/main.zig"),
.target = target,
.optimize = optimize,
});
exe_mod.addImport("resources", lib_mod);
const zeit = b.dependency("zeit", .{ .target = target, .optimize = optimize });
const zeit_module = zeit.module("zeit");
exe_mod.addImport("zeit", zeit_module);
const exe = b.addExecutable(.{
.name = "resources",
.root_module = exe_mod,
});
b.installArtifact(exe);
}
pub fn add_imports(
b: *std.Build,
target: *const std.Build.ResolvedTarget,
lib: *std.Build.Module,
) void {
// For TranslateC to work, we need the system library headers
switch (target.result.os.tag) {
.macos => {
const sdk = std.zig.system.darwin.getSdk(b.allocator, b.graph.io, &target.result) orelse
@panic("macOS SDK is missing");
lib.addSystemIncludePath(.{ .cwd_relative = b.pathJoin(&.{
sdk,
"/usr/include",
}) });
lib.addSystemFrameworkPath(.{ .cwd_relative = b.pathJoin(&.{
sdk,
"/System/Library/Frameworks",
}) });
},
.ios => {
const sdk = std.zig.system.darwin.getSdk(b.allocator, b.graph.io, &target.result) orelse
@panic("macOS SDK is missing");
lib.addSystemIncludePath(.{ .cwd_relative = b.pathJoin(&.{
sdk,
"/usr/include",
}) });
lib.addSystemFrameworkPath(.{ .cwd_relative = b.pathJoin(&.{
sdk,
"/System/Library/Frameworks",
}) });
},
.linux => {
if (target.result.abi.isAndroid()) {
// When building for android, we need to use the android linux headers
if (FindNDK.find(b.graph.io, b.graph.environ_map) catch null) |android_ndk| {
std.log.info("Using android c headers: {any}", .{android_ndk});
lib.addSystemIncludePath(.{ .cwd_relative = b.pathJoin(&.{
android_ndk,
"toolchains/llvm/prebuilt/darwin-x86_64/sysroot/usr/include/",
}) });
lib.addSystemIncludePath(.{ .cwd_relative = b.pathJoin(&.{
android_ndk,
"toolchains/llvm/prebuilt/darwin-x86_64/sysroot/usr/include/aarch64-linux-android/",
}) });
} else {
@panic("android/linux build requires ndk. Set ANDROID_NDK_HOME");
}
}
},
else => {
std.log.debug(
"add_imports not supported on {s}",
.{@tagName(target.result.os.tag)},
);
@panic("add_imports only supports macos, ios, and linux. Please add windows support");
},
}
}
pub const FindNDK = @import("build/find_ndk.zig").FindNDK;