diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index f5f27fbbcd..a779d5bb5d 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -23,12 +23,20 @@ jobs: - name: Build (linux) if: matrix.os == 'ubuntu-latest' run: | - zig build -Doptimize=ReleaseFast -Dno-fileselector -fno-sys=libxkbcommon -Dxkb-config-root="" -Dx-locale-root="" - zig build -Doptimize=ReleaseFast -Dno-fileselector -Dlegacy + zig build -Dtarget=x86_64-linux-musl -Dno-fileselector -fno-sys=libxkbcommon -Dxkb-config-root="" -Dx-locale-root="" + zig build -Dtarget=x86_64-linux-musl -Dno-fileselector -Dlegacy + zig build -Dtarget=x86_64-linux-gnu -Dlinkage=dynamic -Dno-fileselector -fno-sys=libxkbcommon -Dxkb-config-root="" -Dx-locale-root="" + zig build -Dtarget=x86_64-linux-gnu -Dlinkage=dynamic -Dno-fileselector -Dlegacy - name: Build (macOS) if: matrix.os == 'macos-latest' - run: zig build -Doptimize=ReleaseFast -Dno-fileselector + run: zig build -Dno-fileselector + + - name: Build (cross-compile freebsd) + if: matrix.os == 'ubuntu-latest' + run: | + zig build -Dtarget=native-freebsd -Dno-fileselector -fno-sys=libxkbcommon -Dxkb-config-root=/usr/local/share/X11/xkb -Dx-locale-root=/usr/local/lib/X11/locale + zig build -Dtarget=native-freebsd -Dno-fileselector -Dlegacy - name: Build (windows) if: matrix.os == 'windows-latest' diff --git a/README.md b/README.md index 3e7c2f7524..96eabc5e59 100644 --- a/README.md +++ b/README.md @@ -23,10 +23,12 @@ zig build run When building for Windows or macOS, no system dependencies are required. -The graphical profiler has the following dependencies on linux: +The graphical profiler has the following dependencies on Linux and FreeBSD: -- `libGL`: runtime dependency +- `libGL`, `libGLX`: runtime dependency - `libEGL`: runtime dependency, not required when using `-Dlegacy` +- `libwayland-*` runtime dependencies to run a native wayland session +- `libX*` runtime dependencies to run a X11 session, only required when using `-Dlegacy` - `libxkbcommon`: not required when using `-Dlegacy` - `libdbus-1`: can be disabled with `-Dno-fileselector` or `-Dportal=false` - `libgtk+-3.0`: only required when using `-Dportal=false` @@ -48,8 +50,16 @@ zig build run -Dtarget=x86_64-windows -fwine # run the tracy profiler with Wine #### Linux -Cross compiling to macOS can successfully produce a binary. The binary has a runtime dependency on `libGL` and will fail if it can't be found with `dlopen`. +This will produce a dynamically linked executable that will try to `dlopen` various runtime libraries. This is not guaranteed to work as all distros like NixOS. ```bash -zig build -Dtarget=x86_64-linux -Dno-fileselector -Dlegacy +zig build -Dtarget=x86_64-linux-gnu -Dlinkage=dynamic -Dno-fileselector -fno-sys=libxkbcommon -Dxkb-config-root=/usr/share/X11/xkb -Dx-locale-root=/usr/share/X11/locale +zig build -Dtarget=x86_64-linux-gnu -Dlinkage=dynamic -Dno-fileselector -Dlegacy +``` + +#### FreeBSD + +```bash +zig build -Dtarget=x86_64-freebsd -Dno-fileselector -fno-sys=libxkbcommon -Dxkb-config-root=/usr/local/share/X11/xkb -Dx-locale-root=/usr/local/lib/X11/locale +zig build -Dtarget=x86_64-freebsd -Dno-fileselector -Dlegacy ``` diff --git a/build.zig b/build.zig index d549e1162b..91789763d5 100644 --- a/build.zig +++ b/build.zig @@ -125,19 +125,22 @@ pub fn build(b: *std.Build) !void { // Profiler / Server Options const no_fileselector = b.option(bool, "no-fileselector", "Disable the file selector") orelse false; const portal = b.option(bool, "portal", "Use xdg-desktop-portal instead of GTK") orelse true; // upstream uses gtk as the default - const legacy = b.option(bool, "legacy", "Instead of Wayland, use the legacy X11 backend on Linux") orelse false; + const legacy = b.option(bool, "legacy", "Instead of Wayland, use the legacy X11 backend on Linux or FreeBSD") orelse false; const no_statistics = b.option(bool, "no-statistics", "Disable calculation of statistics") orelse false; const self_profile = b.option(bool, "self-profile", "Enable self-profiling") orelse false; const no_parallel_stl = b.option(bool, "no-parallel-stl", "Disable parallel STL") orelse true; - const use_wayland = target.result.os.tag == .linux and !legacy; + const use_wayland = !legacy and switch (target.result.os.tag) { + .linux, .freebsd => true, + else => false, + }; const ini = createIni(b, common_module_options); const base64 = createBase64(b, common_module_options); const md4c = createMd4c(b, common_module_options); const pugixml = createPugixml(b, common_module_options); const tidy = createTidyHtml5(b, common_module_options); - const imgui = createImgui(b, common_module_options, legacy, link_system_glfw, link_system_freetype); + const imgui = createImgui(b, common_module_options, use_wayland, link_system_glfw, link_system_freetype); const zstd = if (link_system_zstd) null else if (b.lazyDependency("zstd", .{ .target = target, .optimize = optimize, @@ -168,7 +171,7 @@ pub fn build(b: *std.Build) !void { })) |dependency| dependency.artifact("nfd") else null; const tracy_server = b.addLibrary(.{ - .linkage = linkage, + .linkage = .static, .name = "tracy-server", .root_module = b.createModule(.{ .target = target, @@ -452,8 +455,8 @@ pub fn build(b: *std.Build) !void { .optimize = optimize, .@"xkb-config-root" = xkb_config_root, .@"x-locale-root" = x_locale_root, - })) |wayland| { - tracy_profiler.root_module.linkLibrary(wayland.artifact("xkbcommon")); + })) |libxkbcommon| { + tracy_profiler.root_module.linkLibrary(libxkbcommon.artifact("xkbcommon")); } } @@ -554,8 +557,7 @@ pub fn build(b: *std.Build) !void { if (b.lazyDependency("glfw", .{ .target = target, .optimize = optimize, - .x11 = if (target.result.os.tag == .linux) legacy else true, - .wayland = true, + .wayland = false, })) |glfw_dependency| { tracy_profiler.root_module.linkLibrary(glfw_dependency.artifact("glfw")); } @@ -901,7 +903,7 @@ fn createRpcmalloc(b: *std.Build, options: std.Build.Module.CreateOptions) *std. fn createImgui( b: *std.Build, options: std.Build.Module.CreateOptions, - legacy: bool, + use_wayland: bool, link_system_glfw: bool, link_system_freetype: bool, ) *std.Build.Step.Compile { @@ -931,26 +933,22 @@ fn createImgui( "imgui_widgets.cpp", }, }); - if (link_system_glfw) { - imgui.root_module.linkSystemLibrary("glfw3", .{}); - } else { - if (b.lazyDependency("glfw", .{ - .target = options.target.?, - .optimize = options.optimize.?, - .x11 = if (options.target.?.result.os.tag == .linux) legacy else true, - .wayland = true, - })) |glfw_dependency| { - imgui.root_module.linkLibrary(glfw_dependency.artifact("glfw")); + if (!use_wayland) { + imgui.root_module.addCSourceFile(.{ .file = upstream.path("backends/imgui_impl_glfw.cpp") }); + if (link_system_glfw) { + imgui.root_module.linkSystemLibrary("glfw3", .{}); + } else { + if (b.lazyDependency("glfw", .{ + .target = options.target.?, + .optimize = options.optimize.?, + .wayland = false, + })) |glfw_dependency| { + imgui.root_module.linkLibrary(glfw_dependency.artifact("glfw")); + } } } - imgui.root_module.addCSourceFiles(.{ - .root = upstream.path("backends"), - .files = &.{ - "imgui_impl_glfw.cpp", - "imgui_impl_opengl3.cpp", - }, - }); + imgui.root_module.addCSourceFile(.{ .file = upstream.path("backends/imgui_impl_opengl3.cpp") }); imgui.installHeadersDirectory(upstream.path("backends"), "imgui", .{}); imgui.root_module.addCMacro("GLFW_INCLUDE_NONE", "1"); if (imgui.root_module.optimize != .Debug) { diff --git a/build.zig.zon b/build.zig.zon index b377be20b6..9984f372e6 100644 --- a/build.zig.zon +++ b/build.zig.zon @@ -4,9 +4,9 @@ .fingerprint = 0x255a89eecd27f4ce, // Changing this has security and trust implications. .minimum_zig_version = "0.15.1", .dependencies = .{ - .glfw = .{ // A fork of GLFW packaged for the Zig build system - .url = "git+https://github.com/terraquad/glfw.git#00a723504e6451d8210031ec7940f2a6841cc0a6", - .hash = "glfw_c-3.4.0-_9LYGLaqGQAI0baWDUTJHNdld2y6gKrsbLvOwUse4Q6x", + .glfw = .{ // glfw ported to the zig build system + .url = "git+https://github.com/Techatrix/glfw.git#5ab24844c4982f1665985bd2a808a62c8cbeb97b", + .hash = "glfw-3.4.0-yvF4PIFDMwBvlU52tuJU9_ijSCazcLeWvYsdaBJm7HQ6", .lazy = true, }, .capstone = .{ // Availability for capstone as Zig dependency @@ -15,8 +15,8 @@ .lazy = true, }, .curl = .{ // curl ported to the zig build system - .url = "git+https://github.com/allyourcodebase/curl.git#0180cf1de923f479633b0d7a13aee4ad482b3ead", - .hash = "curl-8.15.0-mFDAWPDvAACDblXwmIxaAM-mCWYYk8JgfWpuKFQ9pKAT", + .url = "git+https://github.com/allyourcodebase/curl.git#fc863d6cbc4a694ff5bb11fc59470142c8682e2b", + .hash = "curl-8.18.0-mFDAWK_0AABsv8MPtSIjAPCVElXbt1vbzgBOs7plIlUJ", .lazy = true, }, .zstd = .{ // zstd ported to the zig build system @@ -40,8 +40,8 @@ // .lazy = true, // }, .wayland = .{ - .url = "git+https://github.com/allyourcodebase/wayland.git?ref=1.24.0-2#209cdc0d604facd02f67a93a145188d10a54f1ce", - .hash = "wayland-1.24.0-2-dxEBa4RlAAABLcAFSA_vUHi0KqowweDZzkcOQ8KNG4N7", + .url = "git+https://github.com/allyourcodebase/wayland.git?ref=1.24.0-3#c3e9e7b92a135badb24643da7be8a441a060af9d", + .hash = "wayland-1.24.0-3-dxEBa6N9AAD5fW7Hq-V8ngPRpUTky6PmnHxVFRPvn1aI", .lazy = true, }, .wayland_protocols = .{ diff --git a/import/src/import-chrome.cpp b/import/src/import-chrome.cpp index 33db741e97..cc6863275c 100644 --- a/import/src/import-chrome.cpp +++ b/import/src/import-chrome.cpp @@ -15,7 +15,7 @@ #ifdef _MSC_VER # define stat64 _stat64 #endif -#if defined __APPLE__ +#if defined __APPLE__ || defined __FreeBSD__ || (defined __linux__ && !defined __GLIBC__) # define stat64 stat #endif diff --git a/import/src/import-fuchsia.cpp b/import/src/import-fuchsia.cpp index 785979c198..0262232d13 100644 --- a/import/src/import-fuchsia.cpp +++ b/import/src/import-fuchsia.cpp @@ -23,7 +23,7 @@ #ifdef _MSC_VER #define stat64 _stat64 #endif -#if defined __APPLE__ +#if defined __APPLE__ || defined __FreeBSD__ || (defined __linux__ && !defined __GLIBC__) #define stat64 stat #endif diff --git a/profiler/src/BackendWayland.cpp b/profiler/src/BackendWayland.cpp index 961904599d..07ced68068 100644 --- a/profiler/src/BackendWayland.cpp +++ b/profiler/src/BackendWayland.cpp @@ -7,7 +7,6 @@ #include "imgui/imgui_impl_opengl3.h" #include -#include #include #include #include @@ -38,6 +37,14 @@ #include "RunQueue.hpp" #include "profiler/TracyConfig.hpp" +#ifdef __linux__ +#include +#endif + +#ifdef __FreeBSD__ +#include +#endif + constexpr ImGuiKey s_keyTable[] = { /* 0 */ ImGuiKey_None, /* 1 */ ImGuiKey_Escape, diff --git a/profiler/src/winmain.cpp b/profiler/src/winmain.cpp index 6cc2fcf9bf..af4778d04e 100644 --- a/profiler/src/winmain.cpp +++ b/profiler/src/winmain.cpp @@ -4,6 +4,7 @@ # include # include +#if defined(__x86_64__) || defined(__i386__) static inline void CpuId( uint32_t* regs, uint32_t leaf ) { memset(regs, 0, sizeof(uint32_t) * 4); @@ -13,6 +14,7 @@ static inline void CpuId( uint32_t* regs, uint32_t leaf ) __get_cpuid( leaf, regs, regs+1, regs+2, regs+3 ); #endif } +#endif namespace tracy { @@ -24,6 +26,7 @@ int main( int argc, char** argv ); int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszCmd, int nCmd ) { + #if defined(__x86_64__) || defined(__i386__) { uint32_t regs[4]; CpuId( regs, 0 ); @@ -52,6 +55,7 @@ int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszCmd, return 0; } } + #endif return main( __argc, __argv ); }