-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.zig
More file actions
99 lines (82 loc) · 3.92 KB
/
build.zig
File metadata and controls
99 lines (82 loc) · 3.92 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
const std = @import("std");
pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
const exe = b.addExecutable(.{
.name = "skred",
.target = target,
.optimize = optimize,
});
// --- Versioning Logic ---
const version_str = b.option([]const u8, "version", "Override version string") orelse version_blk: {
const file_content = b.build_root.handle.readFileAlloc(b.allocator, "VERSION.txt", 128) catch |err| {
std.debug.print("Error reading VERSION.txt: {s}\n", .{@errorName(err)});
std.process.exit(1);
};
break :version_blk std.mem.trim(u8, file_content, " \n\r\t");
};
exe.root_module.addCMacro("SKRED_VERSION", b.fmt("\"{s}\"", .{version_str}));
exe.root_module.addCMacro("_GNU_SOURCE", "1");
const os_tag = target.result.os.tag;
if (os_tag == .macos) {
exe.root_module.addCMacro("_IS_OSX_", "1");
exe.linkFramework("CoreAudio");
exe.linkFramework("CoreFoundation");
exe.stack_size = 0x800000;
} else if (os_tag == .linux) {
exe.linkSystemLibrary("asound");
} else if (os_tag == .windows) {
exe.root_module.addCMacro("_CRT_SECURE_NO_WARNINGS", "1");
exe.root_module.addCMacro("WIN32_LEAN_AND_MEAN", "1");
exe.linkSystemLibrary("ws2_32");
exe.linkSystemLibrary("winmm");
}
var sources = std.ArrayList([]const u8).init(b.allocator);
sources.appendSlice(&.{
"src/skred.c", "src/miniwav.c", "src/amysamples.c",
"src/retro/retro.c", "src/synth.c", "src/seq.c",
"src/skode.c", "src/ands.c", "src/udp.c",
"src/miniaudio.c", "src/skred-mem.c", "src/util.c",
"src/skqueue.c",
"src/synth-alloc.c",
}) catch unreachable;
if (os_tag != .windows) {
sources.append("src/bestline.c") catch unreachable;
} else {
exe.root_module.addCMacro("NO_BESTLINE", "1");
}
exe.addCSourceFiles(.{
.files = sources.items,
.flags = &.{ "-Wall", "-Wno-multichar", "-fcommon", "-fno-sanitize=all", "-include", "src/portable_win.h" },
});
exe.addIncludePath(b.path("src"));
exe.addIncludePath(b.path("src/retro"));
exe.linkLibC();
exe.linkSystemLibrary("m");
if (os_tag != .windows) exe.linkSystemLibrary("pthread");
if (os_tag == .linux) exe.linkSystemLibrary("rt");
b.installArtifact(exe);
// --- Bundle Step ---
const bundle_step = b.step("bundle", "Create release folder");
const install_bundle = b.addInstallArtifact(exe, .{
.dest_dir = .{ .override = .{ .custom = "bundle" } },
});
const copy_readme = b.addInstallFile(b.path("README.md"), "bundle/README.md");
const copy_license = b.addInstallFile(b.path("LICENSE.txt"), "bundle/LICENSE.txt");
const copy_sk = b.addInstallDirectory(.{ .source_dir = b.path("sk"), .install_dir = .{ .custom = "bundle" }, .install_subdir = "sk" });
const copy_wav = b.addInstallDirectory(.{ .source_dir = b.path("wav"), .install_dir = .{ .custom = "bundle" }, .install_subdir = "wav" });
const copy_docs = b.addInstallDirectory(.{ .source_dir = b.path("docs"), .install_dir = .{ .custom = "bundle" }, .install_subdir = "docs" });
bundle_step.dependOn(&install_bundle.step);
bundle_step.dependOn(©_readme.step);
bundle_step.dependOn(©_license.step);
bundle_step.dependOn(©_sk.step);
bundle_step.dependOn(©_wav.step);
bundle_step.dependOn(©_docs.step);
// --- Zip Step ---
const zip_filename = b.fmt("skred-{s}-{s}.zip", .{ @tagName(os_tag), version_str });
const zip_command = b.addSystemCommand(&.{ "zip", "-r", zip_filename, "bundle" });
zip_command.setCwd(.{ .cwd_relative = b.getInstallPath(.{ .custom = "" }, "") });
zip_command.step.dependOn(bundle_step);
const zip_step = b.step("zip", "Create a final .zip archive");
zip_step.dependOn(&zip_command.step);
}