-
-
Notifications
You must be signed in to change notification settings - Fork 22
/
build.zig
103 lines (90 loc) · 4.38 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
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
const builtin = @import("builtin");
const std = @import("std");
const fs = std.fs;
const log = std.log;
const tests = @import("test/test.zig");
const Allocator = std.mem.Allocator;
pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const mode = b.standardOptimizeOption(.{});
const enable_logging = b.option(bool, "log", "Whether to enable logging") orelse (mode == .Debug);
const enable_tracy = b.option([]const u8, "tracy", "Enable Tracy integration. Supply path to Tracy source");
const tracy_callstack_depth = b.option(usize, "tracy-callstack-depth", "Set Tracy callstack depth") orelse 20;
const strip = b.option(bool, "strip", "Omit debug information") orelse blk: {
if (enable_tracy != null) break :blk false;
break :blk null;
};
const use_llvm = b.option(bool, "use-llvm", "Whether to use LLVM") orelse true;
const sanitize_thread = b.option(bool, "sanitize-thread", "Enable thread-sanitization") orelse false;
const single_threaded = b.option(bool, "single-threaded", "Force single-threaded") orelse false;
const yaml = b.dependency("zig-yaml", .{
.target = target,
.optimize = mode,
});
const dis_x86_64 = b.dependency("zig-dis-x86_64", .{
.target = target,
.optimize = mode,
});
const exe = b.addExecutable(.{
.name = "bold",
.root_source_file = b.path("src/main.zig"),
.target = target,
.optimize = mode,
.use_llvm = use_llvm,
.sanitize_thread = sanitize_thread,
.single_threaded = single_threaded,
});
exe.root_module.addImport("yaml", yaml.module("yaml"));
exe.root_module.addImport("dis_x86_64", dis_x86_64.module("dis_x86_64"));
exe.root_module.strip = strip;
exe.linkLibC();
const exe_opts = b.addOptions();
exe.root_module.addOptions("build_options", exe_opts);
exe_opts.addOption(bool, "enable_logging", enable_logging);
exe_opts.addOption(bool, "enable_tracy", enable_tracy != null);
exe_opts.addOption(usize, "tracy_callstack_depth", tracy_callstack_depth);
if (enable_tracy) |tracy_path| {
const client_cpp = fs.path.join(
b.allocator,
&[_][]const u8{ tracy_path, "TracyClient.cpp" },
) catch unreachable;
// On mingw, we need to opt into windows 7+ to get some features required by tracy.
const tracy_c_flags: []const []const u8 = if (target.result.os.tag == .windows and target.result.abi == .gnu)
&[_][]const u8{ "-DTRACY_ENABLE=1", "-fno-sanitize=undefined", "-D_WIN32_WINNT=0x601" }
else
&[_][]const u8{ "-DTRACY_ENABLE=1", "-fno-sanitize=undefined" };
exe.addIncludePath(.{ .cwd_relative = tracy_path });
exe.addCSourceFile(.{ .file = .{ .cwd_relative = client_cpp }, .flags = tracy_c_flags });
exe.root_module.linkSystemLibrary("c++", .{ .use_pkg_config = .no });
if (target.result.os.tag == .windows) {
exe.linkSystemLibrary("dbghelp");
exe.linkSystemLibrary("ws2_32");
}
}
b.installArtifact(exe);
const has_zig = b.option(bool, "has-zig", "Whether the Zig compiler is in path") orelse false;
const has_objc_msgsend_stubs = b.option(bool, "has-objc-msgsend-stubs", "Whether the system compiler supports '-fobjc-msgsend-selector-stubs' flag") orelse false;
const is_nix = b.option(bool, "nix", "Whether the host is Nix-based") orelse false;
const unit_tests = b.addTest(.{
.root_source_file = b.path("src/MachO.zig"),
.target = target,
.optimize = mode,
.use_llvm = use_llvm,
.sanitize_thread = sanitize_thread,
.single_threaded = single_threaded,
});
const unit_tests_opts = b.addOptions();
unit_tests.root_module.addOptions("build_options", unit_tests_opts);
unit_tests_opts.addOption(bool, "enable_logging", enable_logging);
unit_tests_opts.addOption(bool, "enable_tracy", enable_tracy != null);
unit_tests.root_module.addImport("yaml", yaml.module("yaml"));
unit_tests.root_module.addImport("dis_x86_64", dis_x86_64.module("dis_x86_64"));
unit_tests.linkLibC();
const test_step = b.step("test", "Run tests");
test_step.dependOn(&b.addRunArtifact(unit_tests).step);
test_step.dependOn(tests.addTests(b, exe, .{
.has_zig = has_zig,
.has_objc_msgsend_stubs = has_objc_msgsend_stubs,
.is_nix = is_nix,
}));
}