From 8395bb74709154bdc3759bf1ae72efff8d72ed72 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Sun, 1 Oct 2023 17:11:04 -0700 Subject: [PATCH] pkg/tracy --- build.zig | 13 +++-- build.zig.zon | 1 + pkg/tracy/build.zig | 129 ++++++++++++++++++++++++++------------------ 3 files changed, 85 insertions(+), 58 deletions(-) diff --git a/build.zig b/build.zig index 942470e39..af2522974 100644 --- a/build.zig +++ b/build.zig @@ -15,7 +15,6 @@ const XCFrameworkStep = @import("src/build/XCFrameworkStep.zig"); const Version = @import("src/build/Version.zig"); const glfw = @import("vendor/mach-glfw/build.zig"); -const tracylib = @import("pkg/tracy/build.zig"); const system_sdk = @import("vendor/mach-glfw/system_sdk.zig"); // Do a comptime Zig version requirement. The required Zig version is @@ -672,6 +671,10 @@ fn addDeps( .target = step.target, .optimize = step.optimize, }); + const tracy_dep = b.dependency("tracy", .{ + .target = step.target, + .optimize = step.optimize, + }); const zlib_dep = b.dependency("zlib", .{ .target = step.target, .optimize = step.optimize, @@ -691,7 +694,7 @@ fn addDeps( if (step.target.getCpuArch() == .wasm32) { // We link this package but its a no-op since Tracy // never actually WORKS with wasm. - step.addModule("tracy", tracylib.module(b)); + step.addModule("tracy", tracy_dep.module("tracy")); step.addModule("utf8proc", utf8proc_dep.module("utf8proc")); step.addModule("zig-js", js_dep.module("zig-js")); @@ -743,10 +746,10 @@ fn addDeps( } // Tracy - step.addModule("tracy", tracylib.module(b)); + step.addModule("tracy", tracy_dep.module("tracy")); if (tracy) { - var tracy_step = try tracylib.link(b, step); - system_sdk.include(b, tracy_step, .{}); + step.linkLibrary(tracy_dep.artifact("tracy")); + try static_libs.append(tracy_dep.artifact("tracy").getEmittedBin()); } // utf8proc diff --git a/build.zig.zon b/build.zig.zon index 98f27d840..287218f8d 100644 --- a/build.zig.zon +++ b/build.zig.zon @@ -23,6 +23,7 @@ .libpng = .{ .path = "./pkg/libpng" }, .macos = .{ .path = "./pkg/macos" }, .pixman = .{ .path = "./pkg/pixman" }, + .tracy = .{ .path = "./pkg/tracy" }, .utf8proc = .{ .path = "./pkg/utf8proc" }, .zlib = .{ .path = "./pkg/zlib" }, }, diff --git a/pkg/tracy/build.zig b/pkg/tracy/build.zig index 23c94422d..86140938a 100644 --- a/pkg/tracy/build.zig +++ b/pkg/tracy/build.zig @@ -1,68 +1,91 @@ const std = @import("std"); -/// Directories with our includes. -const root = thisDir() ++ "../../../vendor/tracy/"; +pub fn build(b: *std.Build) !void { + const target = b.standardTargetOptions(.{}); + const optimize = b.standardOptimizeOption(.{}); -pub fn module(b: *std.Build) *std.build.Module { - return b.createModule(.{ - .source_file = .{ .path = (comptime thisDir()) ++ "/tracy.zig" }, - }); -} + _ = b.addModule("tracy", .{ .source_file = .{ .path = "tracy.zig" } }); -fn thisDir() []const u8 { - return std.fs.path.dirname(@src().file) orelse "."; -} - -pub fn link(b: *std.Build, step: *std.build.LibExeObjStep) !*std.build.LibExeObjStep { - const tracy = try buildTracy(b, step); - step.linkLibrary(tracy); - step.addIncludePath(.{ .path = root }); - return tracy; -} - -pub fn buildTracy( - b: *std.Build, - step: *std.build.LibExeObjStep, -) !*std.build.LibExeObjStep { - const target = step.target; + const upstream = b.dependency("tracy", .{}); const lib = b.addStaticLibrary(.{ .name = "tracy", - .target = step.target, - .optimize = step.optimize, + .target = target, + .optimize = optimize, }); - - var flags = std.ArrayList([]const u8).init(b.allocator); - defer flags.deinit(); - - try flags.appendSlice(&.{ - "-DTRACY_ENABLE", - "-fno-sanitize=undefined", - }); - - if (target.isWindows()) { - try flags.appendSlice(&.{ - "-D_WIN32_WINNT=0x601", - }); - } - - lib.addIncludePath(.{ .path = root }); - lib.addCSourceFile(.{ - .file = .{ .path = try std.fs.path.join( - b.allocator, - &.{ root, "TracyClient.cpp" }, - ) }, - .flags = flags.items, - }); - lib.linkLibC(); - lib.linkSystemLibrary("c++"); - - if (lib.target.isWindows()) { + lib.linkLibCpp(); + if (target.isWindows()) { lib.linkSystemLibrary("Advapi32"); lib.linkSystemLibrary("User32"); lib.linkSystemLibrary("Ws2_32"); lib.linkSystemLibrary("DbgHelp"); } - return lib; + lib.addIncludePath(upstream.path("")); + + var flags = std.ArrayList([]const u8).init(b.allocator); + defer flags.deinit(); + try flags.appendSlice(&.{ + "-DTRACY_ENABLE", + "-fno-sanitize=undefined", + }); + if (target.isWindows()) { + try flags.appendSlice(&.{ + "-D_WIN32_WINNT=0x601", + }); + } + + lib.addCSourceFile(.{ + .file = upstream.path("TracyClient.cpp"), + .flags = flags.items, + }); + + lib.installHeadersDirectoryOptions(.{ + .source_dir = upstream.path(""), + .install_dir = .header, + .install_subdir = "", + .include_extensions = &.{ ".h", ".hpp" }, + }); + + b.installArtifact(lib); } + +const headers = &.{ + "TracyC.h", + "TracyOpenGL.hpp", + "Tracy.hpp", + "TracyD3D11.hpp", + "TracyD3D12.hpp", + "TracyOpenCL.hpp", + "TracyVulkan.hpp", + "client/TracyCallstack.h", + "client/TracyScoped.hpp", + "client/TracyStringHelpers.hpp", + "client/TracySysTrace.hpp", + "client/TracyDxt1.hpp", + "client/TracyRingBuffer.hpp", + "client/tracy_rpmalloc.hpp", + "client/TracyDebug.hpp", + "client/TracyLock.hpp", + "client/TracyThread.hpp", + "client/TracyArmCpuTable.hpp", + "client/TracyProfiler.hpp", + "client/TracyCallstack.hpp", + "client/TracySysTime.hpp", + "client/TracyFastVector.hpp", + "common/TracyApi.h", + "common/TracyYield.hpp", + "common/tracy_lz4hc.hpp", + "common/TracySystem.hpp", + "common/TracyProtocol.hpp", + "common/TracyQueue.hpp", + "common/TracyUwp.hpp", + "common/TracyAlloc.hpp", + "common/TracyAlign.hpp", + "common/TracyForceInline.hpp", + "common/TracyColor.hpp", + "common/tracy_lz4.hpp", + "common/TracyStackFrames.hpp", + "common/TracySocket.hpp", + "common/TracyMutex.hpp", +};