diff --git a/build.zig b/build.zig index 8bd227b01..e8cc06264 100644 --- a/build.zig +++ b/build.zig @@ -47,9 +47,6 @@ pub fn build(b: *std.build.Builder) !void { // Add the shared dependencies try addDeps(b, exe); - - // Tracy - if (tracy) try tracylib.link(b, exe, target); } // term.wasm @@ -62,7 +59,7 @@ pub fn build(b: *std.build.Builder) !void { wasm.setTarget(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }); wasm.setBuildMode(mode); wasm.setOutputDir("zig-out"); - wasm.addPackage(pkg_tracy); + wasm.addPackage(tracylib.pkg); const step = b.step("term-wasm", "Build the terminal.wasm library"); step.dependOn(&wasm.step); @@ -161,7 +158,8 @@ fn addDeps( try libuv.link(b, step); // Tracy - step.addPackage(pkg_tracy); + step.addPackage(tracylib.pkg); + try tracylib.link(b, step); } fn conformanceSteps( @@ -207,11 +205,6 @@ fn root() []const u8 { return std.fs.path.dirname(@src().file) orelse unreachable; } -pub const pkg_tracy = std.build.Pkg{ - .name = "tracy", - .source = .{ .path = root() ++ "/src/tracy/tracy.zig" }, -}; - /// ANSI escape codes for colored log output const color_map = std.ComptimeStringMap([]const u8, .{ &.{ "black", "30m" }, diff --git a/src/tracy/build.zig b/src/tracy/build.zig index 4afe8f4e0..e70fb6036 100644 --- a/src/tracy/build.zig +++ b/src/tracy/build.zig @@ -1,13 +1,32 @@ const std = @import("std"); -const Builder = std.build.Builder; -const LibExeObjStep = std.build.LibExeObjStep; -/// Build and link the Tracy client into the given executable. -pub fn link( - b: *Builder, - exe: *LibExeObjStep, - target: std.zig.CrossTarget, -) !void { +/// Directories with our includes. +const root = thisDir() ++ "../../../vendor/tracy/"; + +pub const pkg = std.build.Pkg{ + .name = "tracy", + .source = .{ .path = thisDir() ++ "/tracy.zig" }, +}; + +fn thisDir() []const u8 { + return std.fs.path.dirname(@src().file) orelse "."; +} + +pub fn link(b: *std.build.Builder, step: *std.build.LibExeObjStep) !void { + const tracy = try buildTracy(b, step); + step.linkLibrary(tracy); + step.addIncludePath(root); +} + +pub fn buildTracy( + b: *std.build.Builder, + step: *std.build.LibExeObjStep, +) !*std.build.LibExeObjStep { + const target = step.target; + const lib = b.addStaticLibrary("tracy", null); + lib.setTarget(step.target); + lib.setBuildMode(step.build_mode); + var flags = std.ArrayList([]const u8).init(b.allocator); defer flags.deinit(); @@ -22,24 +41,21 @@ pub fn link( }); } - const path = root(); - exe.addIncludePath(path); - exe.addCSourceFile(try std.fs.path.join( - exe.builder.allocator, - &.{ path, "TracyClient.cpp" }, + lib.addIncludePath(root); + lib.addCSourceFile(try std.fs.path.join( + lib.builder.allocator, + &.{ root, "TracyClient.cpp" }, ), flags.items); - exe.linkLibC(); - exe.linkSystemLibrary("c++"); + lib.linkLibC(); + lib.linkSystemLibrary("c++"); - if (exe.target.isWindows()) { - exe.linkSystemLibrary("Advapi32"); - exe.linkSystemLibrary("User32"); - exe.linkSystemLibrary("Ws2_32"); - exe.linkSystemLibrary("DbgHelp"); + if (lib.target.isWindows()) { + lib.linkSystemLibrary("Advapi32"); + lib.linkSystemLibrary("User32"); + lib.linkSystemLibrary("Ws2_32"); + lib.linkSystemLibrary("DbgHelp"); } -} -fn root() []const u8 { - return (std.fs.path.dirname(@src().file) orelse unreachable) ++ "/../../vendor/tracy/"; + return lib; }