Repository navigation
Expand file tree
/
Copy pathbuild.zig
More file actions
133 lines (117 loc) · 4.17 KB
/
Copy pathbuild.zig
File metadata and controls
133 lines (117 loc) · 4.17 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
const std = @import("std");
pub fn build(b: *std.Build) void {
const optimize = b.standardOptimizeOption(.{});
const target = b.standardTargetOptions(.{});
const options = .{
.enable_ztracy = b.option(
bool,
"enable_ztracy",
"Enable Tracy profile markers",
) orelse false,
.enable_fibers = b.option(
bool,
"enable_fibers",
"Enable Tracy fiber support",
) orelse false,
.on_demand = b.option(
bool,
"on_demand",
"Build tracy with TRACY_ON_DEMAND",
) orelse false,
.callstack = b.option(
u32,
"callstack",
"If > 0, Builds tracy with TRACY_USE_CALLSTACK and sets TRACY_CALLSTACK to the depth provided.",
) orelse 0,
.shared = b.option(
bool,
"shared",
"Build as shared library",
) orelse false,
};
const options_step = b.addOptions();
inline for (std.meta.fields(@TypeOf(options))) |field| {
options_step.addOption(field.type, field.name, @field(options, field.name));
}
const options_module = options_step.createModule();
const translate_c = b.addTranslateC(.{
.root_source_file = b.path("libs/tracy/tracy/TracyC.h"),
.target = target,
.optimize = optimize,
.link_libc = true,
});
translate_c.addIncludePath(b.path("libs/tracy/tracy"));
translate_c.defineCMacro("TRACY_ENABLE", "");
translate_c.defineCMacro("TRACY_IMPORTS", "");
if (options.callstack > 0) {
translate_c.defineCMacro("TRACY_USE_CALLSTACK", "");
var callstack_buffer: [64]u8 = undefined;
const callstack_str_len = std.fmt.printInt(&callstack_buffer, @as(u32, options.callstack), 10, .lower, .{});
translate_c.defineCMacro("TRACY_CALLSTACK", callstack_buffer[0..callstack_str_len]);
}
const ztracy = b.addModule("root", .{
.root_source_file = b.path("src/ztracy.zig"),
.imports = &.{
.{ .name = "ztracy_options", .module = options_module },
},
});
ztracy.addImport("c", translate_c.createModule());
const tracy = b.addLibrary(.{
.name = "tracy",
.linkage = if (options.shared) .dynamic else .static,
.root_module = b.createModule(.{
.target = target,
.optimize = optimize,
}),
});
if (options.shared) {
tracy.root_module.addCMacro("TRACY_EXPORTS", "");
}
tracy.root_module.addIncludePath(b.path("libs/tracy/tracy"));
tracy.root_module.addCSourceFile(.{
.file = b.path("libs/tracy/TracyClient.cpp"),
.flags = &.{
"-fno-sanitize=undefined",
},
});
if (options.enable_ztracy) tracy.root_module.addCMacro("TRACY_ENABLE", "");
if (options.enable_fibers) {
tracy.root_module.addCMacro("TRACY_FIBERS", "");
translate_c.defineCMacro("TRACY_FIBERS", "");
}
if (options.on_demand) {
tracy.root_module.addCMacro("TRACY_ON_DEMAND", "");
translate_c.defineCMacro("TRACY_ON_DEMAND", "");
}
tracy.root_module.link_libc = true;
if (target.result.abi != .msvc) {
tracy.root_module.link_libcpp = true;
} else {
tracy.root_module.addCMacro("fileno", "_fileno");
}
switch (target.result.os.tag) {
.windows => {
tracy.root_module.linkSystemLibrary("ws2_32", .{});
tracy.root_module.linkSystemLibrary("dbghelp", .{});
},
.macos => {
if (b.lazyDependency("system_sdk", .{})) |system_sdk| {
tracy.root_module.addFrameworkPath(system_sdk.path("System/Library/Frameworks"));
}
},
else => {},
}
b.installArtifact(tracy);
const test_step = b.step("test", "Run ztracy tests");
const tests = b.addTest(.{
.name = "ztracy-tests",
.root_module = b.createModule(.{
.root_source_file = b.path("src/ztracy.zig"),
.target = target,
.optimize = optimize,
}),
});
tests.root_module.linkLibrary(tracy);
b.installArtifact(tests);
test_step.dependOn(&b.addRunArtifact(tests).step);
}