-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathbuild.zig
115 lines (100 loc) · 3.33 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
104
105
106
107
108
109
110
111
112
113
114
115
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,
.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", "");
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 = if (options.shared) blk: {
const lib = b.addSharedLibrary(.{
.name = "tracy",
.target = target,
.optimize = optimize,
});
lib.root_module.addCMacro("TRACY_EXPORTS", "");
break :blk lib;
} else b.addStaticLibrary(.{
.name = "tracy",
.target = target,
.optimize = optimize,
});
tracy.addIncludePath(b.path("libs/tracy/tracy"));
tracy.addCSourceFile(.{
.file = b.path("libs/tracy/TracyClient.cpp"),
.flags = &.{
if (options.enable_ztracy) "-DTRACY_ENABLE" else "",
if (options.enable_fibers) "-DTRACY_FIBERS" else "",
"-fno-sanitize=undefined",
},
});
if (options.on_demand) tracy.root_module.addCMacro("TRACY_ON_DEMAND", "");
tracy.linkLibC();
if (target.result.abi != .msvc) {
tracy.linkLibCpp();
} else {
tracy.root_module.addCMacro("fileno", "_fileno");
}
switch (target.result.os.tag) {
.windows => {
tracy.linkSystemLibrary("ws2_32");
tracy.linkSystemLibrary("dbghelp");
},
.macos => {
if (b.lazyDependency("system_sdk", .{})) |system_sdk| {
tracy.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_source_file = b.path("src/ztracy.zig"),
.target = target,
.optimize = optimize,
});
tests.linkLibrary(tracy);
b.installArtifact(tests);
test_step.dependOn(&b.addRunArtifact(tests).step);
}