Repository navigation
Expand file tree
/
Copy pathbuild.zig
More file actions
149 lines (131 loc) · 6.04 KB
/
Copy pathbuild.zig
File metadata and controls
149 lines (131 loc) · 6.04 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
const std = @import("std");
pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
// Pass no options through — fy's build.zig registers its own `target`
// and `optimize` via standard*Option, and zig surfaces a warning
// when we forward them. Our exe module takes the locally-resolved
// target/optimize anyway; fy just needs to compile to the same ABI,
// which matches since both default to the host.
const fy_dep = b.dependency("fy", .{});
const fy_mod = fy_dep.module("fy");
const exe_mod = b.createModule(.{
.root_source_file = b.path("src/main.zig"),
.target = target,
.optimize = optimize,
});
exe_mod.addImport("fy", fy_mod);
exe_mod.addImport("tamzen", b.createModule(.{ .root_source_file = b.path("vendor/tamzen/tamzen.zig") }));
// The version About shows, from build.zig.zon.
const options = b.addOptions();
options.addOption([]const u8, "version", @import("build.zig.zon").version);
exe_mod.addOptions("build_options", options);
const exe = b.addExecutable(.{
.name = "slab",
.root_module = exe_mod,
});
configureNativeDeps(b, exe_mod, target, optimize);
const kernel_probe_mod = b.createModule(.{
.root_source_file = b.path("src/kernel_probe.zig"),
.target = target,
.optimize = optimize,
});
kernel_probe_mod.addImport("fy", fy_mod);
configureNativeDeps(b, kernel_probe_mod, target, optimize);
const kernel_probe = b.addExecutable(.{
.name = "kernel-probe",
.root_module = kernel_probe_mod,
});
const kernel_probe_cmd = b.addRunArtifact(kernel_probe);
kernel_probe_cmd.addPassthruArgs();
const kernel_probe_step = b.step("kernel-probe", "Run a testable Fy DSP kernel fixture");
kernel_probe_step.dependOn(&kernel_probe_cmd.step);
// Headless machine workbench (docs/17 Track C): same adapter as the DAW.
const bench_mod = b.createModule(.{
.root_source_file = b.path("src/bench_main.zig"),
.target = target,
.optimize = optimize,
});
bench_mod.addImport("fy", fy_mod);
configureNativeDeps(b, bench_mod, target, optimize);
const bench = b.addExecutable(.{
.name = "bench",
.root_module = bench_mod,
});
const bench_cmd = b.addRunArtifact(bench);
bench_cmd.addPassthruArgs();
const bench_step = b.step("bench", "Render machines headless: sheets, reports, goldens");
bench_step.dependOn(&bench_cmd.step);
const install = b.addInstallArtifact(exe, .{});
b.getInstallStep().dependOn(&install.step);
// macOS ad-hoc codesign with JIT entitlements so fy's MAP_JIT pages
// execute. Signs the installed binary in place, gated on install.
const codesign = b.addSystemCommand(&[_][]const u8{
"codesign", "-s", "-", "--force", "--entitlements", "entitlements.plist", "--options", "runtime",
});
codesign.addFileArg(.{ .relative = .{ .base = .install_bin, .sub_path = exe.out_filename } });
codesign.step.dependOn(&install.step);
b.getInstallStep().dependOn(&codesign.step);
const run_cmd = b.addRunArtifact(exe);
run_cmd.step.dependOn(b.getInstallStep());
run_cmd.addPassthruArgs();
const run_step = b.step("run", "Run Slab");
run_step.dependOn(&run_cmd.step);
const test_filter = b.option([]const u8, "test-filter", "Only run tests whose name contains this substring");
const tests = b.addTest(.{
.root_module = exe_mod,
.filters = if (test_filter) |f| &.{f} else &.{},
});
const run_tests = b.addRunArtifact(tests);
const test_step = b.step("test", "Run unit tests");
test_step.dependOn(&run_tests.step);
const bench_tests = b.addTest(.{ .root_module = bench_mod });
test_step.dependOn(&b.addRunArtifact(bench_tests).step);
}
fn configureNativeDeps(b: *std.Build, mod: *std.Build.Module, target: std.Build.ResolvedTarget, optimize: std.builtin.OptimizeMode) void {
// C headers become modules src/c.zig imports (zig 0.17 has no @cImport).
const rl_c = b.addTranslateC(.{ .root_source_file = b.path("src/c_raylib.h"), .target = target, .optimize = optimize });
rl_c.addIncludePath(.{ .cwd_relative = "/opt/homebrew/include" });
mod.addImport("raylib_c", rl_c.createModule());
const ma_c = b.addTranslateC(.{ .root_source_file = b.path("src/c_miniaudio.h"), .target = target, .optimize = optimize });
ma_c.addIncludePath(b.path("vendor"));
mod.addImport("miniaudio_c", ma_c.createModule());
// raylib via homebrew.
mod.addIncludePath(.{ .cwd_relative = "/opt/homebrew/include" });
mod.addLibraryPath(.{ .cwd_relative = "/opt/homebrew/lib" });
mod.linkSystemLibrary("raylib", .{});
// LAME for MP3 export, static: the installed app needs no Homebrew.
mod.addObjectFile(.{ .cwd_relative = "/opt/homebrew/lib/libmp3lame.a" });
// miniaudio — vendored single-header, single-TU.
mod.addCSourceFile(.{
.file = b.path("vendor/miniaudio.c"),
.flags = &.{"-fno-sanitize=undefined"},
});
mod.addCSourceFile(.{
.file = b.path("src/native_dialog.m"),
.flags = &.{"-fobjc-arc"},
});
mod.addCSourceFile(.{
.file = b.path("src/native_app.m"),
.flags = &.{"-fobjc-arc"},
});
mod.addCSourceFile(.{
.file = b.path("src/native_ml.m"),
.flags = &.{"-fobjc-arc"},
});
mod.addCSourceFile(.{ .file = b.path("src/native_audio.c") });
mod.addCSourceFile(.{ .file = b.path("src/native_midi.c") });
mod.addCSourceFile(.{ .file = b.path("src/native_diag.c") });
mod.addIncludePath(b.path("vendor"));
// macOS frameworks needed by raylib + miniaudio.
mod.linkFramework("CoreAudio", .{});
mod.linkFramework("CoreMIDI", .{});
mod.linkFramework("AudioToolbox", .{});
mod.linkFramework("CoreFoundation", .{});
mod.linkFramework("Cocoa", .{});
mod.linkFramework("IOKit", .{});
mod.linkFramework("OpenGL", .{});
// The extractors' models (docs/30 §Stems).
mod.linkFramework("CoreML", .{});
mod.link_libc = true;
}