-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.zig
More file actions
94 lines (75 loc) · 2.74 KB
/
build.zig
File metadata and controls
94 lines (75 loc) · 2.74 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
const std = @import("std");
const Builder = std.build.Builder;
pub fn build(b: *Builder) !void {
// Standalone build
{
const mode = b.standardReleaseOptions();
const target = b.standardTargetOptions(.{});
const exe = b.addExecutable("zig-synth", "src/main.zig");
exe.setTarget(target);
exe.setBuildMode(mode);
exe.install();
switch (target.os_tag orelse std.builtin.os.tag) {
.macosx => {
const sdk_path_raw = try b.exec(&[_][]const u8{
"xcrun",
"-show-sdk-path",
});
const sdk_path = std.mem.trimRight(u8, sdk_path_raw, "\n");
const framework_path = try std.mem.concat(b.allocator, u8, &[_][]const u8{
sdk_path,
"/System/Library/Frameworks",
});
exe.addFrameworkDir(framework_path);
exe.linkFramework("CoreFoundation");
exe.linkFramework("AudioToolbox");
exe.linkFramework("CoreAudio");
exe.linkFramework("CoreMIDI");
},
else => {},
}
const run_cmd = exe.run();
run_cmd.step.dependOn(b.getInstallStep());
const run_step = b.step("run", "Run the app");
run_step.dependOn(&run_cmd.step);
}
// WASM build
{
const mode = b.standardReleaseOptions();
const lib = b.addStaticLibrary("zig-synth", "src/main.zig");
lib.setTarget(std.zig.CrossTarget{
.cpu_arch = .wasm32,
.os_tag = .freestanding,
});
lib.setBuildMode(mode);
lib.install();
const build_html = b.addExecutable("build-html", "build-html.zig");
build_html.setBuildMode(mode);
var run_build_cmd = build_html.run();
run_build_cmd.step.dependOn(&lib.step);
const cwd = try std.process.getCwdAlloc(b.allocator);
defer b.allocator.free(cwd);
const wasm_path = try std.fs.path.join(b.allocator, &[_][]const u8{
cwd,
b.lib_dir,
lib.out_filename,
});
defer b.allocator.free(wasm_path);
const out_html_path = try std.fs.path.join(b.allocator, &[_][]const u8{
cwd,
b.exe_dir,
"zig-synth.html",
});
run_build_cmd.addArg(wasm_path);
run_build_cmd.addArg(out_html_path);
b.default_step.dependOn(&run_build_cmd.step);
}
// Tests
{
const mode = b.standardReleaseOptions();
var main_tests = b.addTest("src/main.zig");
main_tests.setBuildMode(mode);
const test_step = b.step("test", "Run library tests");
test_step.dependOn(&main_tests.step);
}
}