diff --git a/build.zig b/build.zig index b5156b5..19331f1 100644 --- a/build.zig +++ b/build.zig @@ -14,21 +14,17 @@ pub fn build(b: *std.Build) !void { .native => |exe| { b.installArtifact(exe); - { - const run_cmd = b.addRunArtifact(exe); - if (b.args) |args| { - run_cmd.addArgs(args); - } - run_cmd_step = &run_cmd.step; - } + const run_cmd = b.addRunArtifact(exe); + run_cmd.addPassthruArgs(); + run_cmd_step = &run_cmd.step; - // { - // const exe_tests = b.addTest(.{ .root_module = exe_mod, }); - // const run_exe_tests = b.addRunArtifact(exe_tests); - // - // const test_step = b.step("test", "Run tests"); - // test_step.dependOn(&run_exe_tests.step); - // } + { + const exe_tests = b.addTest(.{ .root_module = exe.root_module, }); + const run_exe_tests = b.addRunArtifact(exe_tests); + + const test_step = b.step("test", "Run tests"); + test_step.dependOn(&run_exe_tests.step); + } }, .wasm => { // TODO: @@ -67,7 +63,7 @@ fn buildProject(ctx: Context, target: Build.ResolvedTarget, optimize: std.builti }; const is_wasm = target.result.cpu.arch.isWasm(); - const is_debug = optimize == .Debug; + const is_debug = optimize == .debug; const has_imgui = b.option(bool, "imgui", "ImGui integration") orelse is_debug; const assets_from_filesystem = b.option(bool, "assets-filesystem", "Allow reading assets from filesystem") orelse is_debug; @@ -101,7 +97,9 @@ fn buildProject(ctx: Context, target: Build.ResolvedTarget, optimize: std.builti { const build_options = b.addOptions(); build_options.addOption(bool, "has_imgui", has_imgui); - build_options.addOption(?[]const u8, "assets_dir", if (assets_from_filesystem) assets_dir.getPath(b) else null); + if (assets_from_filesystem) { + build_options.addOptionPathDirectory("assets_dir", assets_dir); + } platform_mod.addOptions("build_options", build_options); platform_mod.addImport("embedded_assets", try createAssetsModule(b, assets_dir, &asset_files)); @@ -182,8 +180,8 @@ fn buildProject(ctx: Context, target: Build.ResolvedTarget, optimize: std.builti }); if (target.result.os.tag == .windows) { - const has_console = win32_has_console orelse (optimize == .Debug); - exe.subsystem = if (has_console) .Console else .Windows; + const has_console = win32_has_console orelse is_debug; + exe.subsystem = if (has_console) .console else .windows; if (win32_icon_png) |icon_png| { buildWin32ResourceFile(ctx, exe.root_module, .{ diff --git a/build.zig.zon b/build.zig.zon index e01864b..6c2eafc 100644 --- a/build.zig.zon +++ b/build.zig.zon @@ -4,12 +4,12 @@ .fingerprint = 0xf440b4e6e51f5206, // Changing this has security and trust implications. .dependencies = .{ .sokol = .{ - .url = "git+https://github.com/floooh/sokol-zig.git#ff40f04d4f51c73b2bf460d87fd2d7aa0dedc22f", - .hash = "sokol-0.1.0-pb1HKygbQQCINV-qSe4SFm92QWaT_95VpWTJkwYqzOrX", + .url = "git+https://github.com/floooh/sokol-zig.git#e371234960812882406a296c4f3154321a16ee4d", + .hash = "sokol-0.1.0-pb1HK0kUQABqwuelY7BmmQmAm-jLBZKJ7uyoxkdS49Ib", }, .cimgui = .{ - .url = "git+https://github.com/floooh/dcimgui.git#e2f0e0d93adec02743c55940be23ffe286e857f7", - .hash = "cimgui-0.1.0-44ClkR8dmgDqqnfloyLE1bUAtl4zSKTT1wxaHSEC0ikV", + .url = "git+https://github.com/floooh/dcimgui.git#ef68bcf1ea0a8218f4a2f24fb9414515ecbf5af4", + .hash = "cimgui-0.1.0-44ClkVBEnABUEg0-NuUgCcvqhRLr9BCUWHFbuVYt9Nuv", .lazy = true }, .stb = .{ diff --git a/libs/stb/build.zig b/libs/stb/build.zig index a601475..bccc206 100644 --- a/libs/stb/build.zig +++ b/libs/stb/build.zig @@ -2,36 +2,97 @@ const std = @import("std"); const Build = std.Build; const LazyPath = Build.LazyPath; -pub fn build(b: *std.Build) void { +pub fn build(b: *std.Build) !void { const target = b.standardTargetOptions(.{}); const optimize = b.standardOptimizeOption(.{}); - buildSTBModule(b, target, optimize, "stb_image", b.path("src/stb_image.zig"), b.path("src/stb_image_impl.c")); - buildSTBModule(b, target, optimize, "stb_vorbis", b.path("src/stb_vorbis.zig"), b.path("src/stb_vorbis_impl.c")); - buildSTBModule(b, target, optimize, "stb_rect_pack", b.path("src/stb_rect_pack.zig"), b.path("src/stb_rect_pack_impl.c")); - buildSTBModule(b, target, optimize, "stb_truetype", b.path("src/stb_truetype.zig"), b.path("src/stb_truetype_impl.c")); + try buildSTBModule(b, target, optimize, .{ + .name = "stb_image", + .zig_file = b.path("src/stb_image.zig"), + .header_name = "stb_image.h", + .defines = &.{ "STBI_NO_STDIO" }, + .impl_define = "STB_IMAGE_IMPLEMENTATION" + }); + try buildSTBModule(b, target, optimize, .{ + .name = "stb_vorbis", + .zig_file = b.path("src/stb_vorbis.zig"), + .header_name = "stb_vorbis.c", + .defines = &.{ "STB_VORBIS_NO_INTEGER_CONVERSION", "STB_VORBIS_NO_STDIO" }, + .header_only_define = "STB_VORBIS_HEADER_ONLY" + }); + try buildSTBModule(b, target, optimize, .{ + .name = "stb_rect_pack", + .zig_file = b.path("src/stb_rect_pack.zig"), + .header_name = "stb_rect_pack.h", + .impl_define = "STB_RECT_PACK_IMPLEMENTATION" + }); + try buildSTBModule(b, target, optimize, .{ + .name = "stb_truetype", + .zig_file = b.path("src/stb_truetype.zig"), + .header_name = "stb_truetype.h", + // TODO: .defines = &.{ "STBTT_STATIC" }, + .impl_define = "STB_TRUETYPE_IMPLEMENTATION" + }); } +const STBModuleOptions = struct { + name: []const u8, + zig_file: LazyPath, + header_name: []const u8, + defines: []const []const u8 = &.{}, + impl_define: ?[]const u8 = null, + header_only_define: ?[]const u8 = null, +}; + fn buildSTBModule( b: *std.Build, target: Build.ResolvedTarget, optimize: std.builtin.OptimizeMode, - name: []const u8, - zig_file: LazyPath, - impl_file: LazyPath -) void { + opts: STBModuleOptions +) !void { const stb_dependency = b.dependency("stb", .{}); - const mod = b.addModule(name, .{ + const mod = b.addModule(opts.name, .{ .target = target, .optimize = optimize, - .root_source_file = zig_file, + .root_source_file = opts.zig_file, .link_libc = true, }); - mod.addIncludePath(stb_dependency.path(".")); - mod.addCSourceFile(.{ - .file = impl_file, - .flags = &.{} - }); + const write_file_step = b.addWriteFiles(); + + { + var translate_c_contents: std.ArrayList(u8) = .empty; + try translate_c_contents.appendSlice(b.graph.arena, "#include \""); + try translate_c_contents.appendSlice(b.graph.arena, opts.header_name); + try translate_c_contents.appendSlice(b.graph.arena, "\""); + + const translate_c = b.addTranslateC(.{ + .root_source_file = write_file_step.add("c.h", translate_c_contents.items), + .target = target, + .optimize = optimize, + }); + translate_c.addIncludePath(stb_dependency.path(".")); + for (opts.defines) |define| { + translate_c.defineCMacro(define, null); + } + if (opts.header_only_define) |header_only_define| { + translate_c.defineCMacro(header_only_define, null); + } + mod.addImport("c", translate_c.createModule()); + } + + { + mod.addCSourceFile(.{ + .file = write_file_step.add("impl.c", b.fmt("#include \"{s}\"", .{opts.header_name})), + .flags = &.{} + }); + mod.addIncludePath(stb_dependency.path(".")); + for (opts.defines) |define| { + mod.addCMacro(define, ""); + } + if (opts.impl_define) |impl_define| { + mod.addCMacro(impl_define, ""); + } + } } diff --git a/libs/stb/src/stb_image.zig b/libs/stb/src/stb_image.zig index 1c357a8..65e3984 100644 --- a/libs/stb/src/stb_image.zig +++ b/libs/stb/src/stb_image.zig @@ -1,9 +1,6 @@ const std = @import("std"); -const c = @cImport({ - @cDefine("STBI_NO_STDIO", {}); - @cInclude("stb_image.h"); -}); +const c = @import("c"); const STBImage = @This(); diff --git a/libs/stb/src/stb_image_impl.c b/libs/stb/src/stb_image_impl.c deleted file mode 100644 index eeee84a..0000000 --- a/libs/stb/src/stb_image_impl.c +++ /dev/null @@ -1,3 +0,0 @@ -#define STB_IMAGE_IMPLEMENTATION -#define STBI_NO_STDIO -#include "stb_image.h" diff --git a/libs/stb/src/stb_rect_pack.zig b/libs/stb/src/stb_rect_pack.zig index 18065eb..791a5d6 100644 --- a/libs/stb/src/stb_rect_pack.zig +++ b/libs/stb/src/stb_rect_pack.zig @@ -1,8 +1,6 @@ const std = @import("std"); -const c = @cImport({ - @cInclude("stb_rect_pack.h"); -}); +const c = @import("c"); const STBRectPack = @This(); diff --git a/libs/stb/src/stb_rect_pack_impl.c b/libs/stb/src/stb_rect_pack_impl.c deleted file mode 100644 index 31c4106..0000000 --- a/libs/stb/src/stb_rect_pack_impl.c +++ /dev/null @@ -1,2 +0,0 @@ -#define STB_RECT_PACK_IMPLEMENTATION -#include "stb_rect_pack.h" diff --git a/libs/stb/src/stb_truetype.zig b/libs/stb/src/stb_truetype.zig index a63cfe6..c2bacf0 100644 --- a/libs/stb/src/stb_truetype.zig +++ b/libs/stb/src/stb_truetype.zig @@ -1,8 +1,6 @@ const std = @import("std"); -const c = @cImport({ - @cInclude("stb_truetype.h"); -}); +const c = @import("c"); pub const Box = struct { x0: i32, diff --git a/libs/stb/src/stb_truetype_impl.c b/libs/stb/src/stb_truetype_impl.c deleted file mode 100644 index 9f0bf61..0000000 --- a/libs/stb/src/stb_truetype_impl.c +++ /dev/null @@ -1,4 +0,0 @@ -#define STB_TRUETYPE_IMPLEMENTATION -// TODO: #define STBTT_STATIC -#include "stb_truetype.h" - diff --git a/libs/stb/src/stb_vorbis.zig b/libs/stb/src/stb_vorbis.zig index ea25583..bd3a99d 100644 --- a/libs/stb/src/stb_vorbis.zig +++ b/libs/stb/src/stb_vorbis.zig @@ -2,12 +2,7 @@ const std = @import("std"); const assert = std.debug.assert; const log = std.log.scoped(.stb_vorbis); -const c = @cImport({ - @cDefine("STB_VORBIS_NO_INTEGER_CONVERSION", {}); - @cDefine("STB_VORBIS_NO_STDIO", {}); - @cDefine("STB_VORBIS_HEADER_ONLY", {}); - @cInclude("stb_vorbis.c"); -}); +const c = @import("c"); const STBVorbis = @This(); diff --git a/libs/stb/src/stb_vorbis_impl.c b/libs/stb/src/stb_vorbis_impl.c deleted file mode 100644 index 4a53456..0000000 --- a/libs/stb/src/stb_vorbis_impl.c +++ /dev/null @@ -1,3 +0,0 @@ -#define STB_VORBIS_NO_INTEGER_CONVERSION -#define STB_VORBIS_NO_STDIO -#include "stb_vorbis.c" diff --git a/libs/tracy/build.zig b/libs/tracy/build.zig index 53e8992..a21a28f 100644 --- a/libs/tracy/build.zig +++ b/libs/tracy/build.zig @@ -1,7 +1,7 @@ const std = @import("std"); const digits2 = std.fmt.digits2; -pub fn build(b: *std.Build) void { +pub fn build(b: *std.Build) !void { const target = b.standardTargetOptions(.{}); const optimize = b.standardOptimizeOption(.{}); @@ -29,110 +29,113 @@ pub fn build(b: *std.Build) void { const tracy_timer_fallback = b.option(bool, "tracy_timer_fallback", "Use lower resolution timers") orelse false; const shared = b.option(bool, "shared", "Build the tracy client as a shared libary") orelse false; - const options = b.addOptions(); - options.addOption(bool, "tracy_enable", tracy_enable); - options.addOption(bool, "tracy_on_demand", tracy_on_demand); - options.addOption(?u8, "tracy_callstack", tracy_callstack); - options.addOption(bool, "tracy_no_callstack", tracy_no_callstack); - options.addOption(bool, "tracy_no_callstack_inlines", tracy_no_callstack_inlines); - options.addOption(bool, "tracy_only_localhost", tracy_only_localhost); - options.addOption(bool, "tracy_no_broadcast", tracy_no_broadcast); - options.addOption(bool, "tracy_only_ipv4", tracy_only_ipv4); - options.addOption(bool, "tracy_no_code_transfer", tracy_no_code_transfer); - options.addOption(bool, "tracy_no_context_switch", tracy_no_context_switch); - options.addOption(bool, "tracy_no_exit", tracy_no_exit); - options.addOption(bool, "tracy_no_sampling", tracy_no_sampling); - options.addOption(bool, "tracy_no_verify", tracy_no_verify); - options.addOption(bool, "tracy_no_vsync_capture", tracy_no_vsync_capture); - options.addOption(bool, "tracy_no_frame_image", tracy_no_frame_image); - options.addOption(bool, "tracy_no_system_tracing", tracy_no_system_tracing); - options.addOption(bool, "tracy_delayed_init", tracy_delayed_init); - options.addOption(bool, "tracy_manual_lifetime", tracy_manual_lifetime); - options.addOption(bool, "tracy_fibers", tracy_fibers); - options.addOption(bool, "tracy_no_crash_handler", tracy_no_crash_handler); - options.addOption(bool, "tracy_timer_fallback", tracy_timer_fallback); - options.addOption(bool, "shared", shared); - const dep_src = b.dependency("src", .{}); + const is_windows = target.result.os.tag == .windows; - const tracy_module = b.addModule("tracy", .{ - .root_source_file = b.path("src/root.zig"), - .target = target, - .optimize = optimize, - }); + const arena = b.graph.arena; + var defines: std.ArrayList(CDefine) = .empty; + inline for (.{ + .{ tracy_enable , "TRACY_ENABLE" , "1" }, + .{ tracy_on_demand , "TRACY_ON_DEMAND" , "1" }, + .{ tracy_no_callstack , "TRACY_NO_CALLSTACK" , "1" }, + .{ tracy_no_callstack_inlines, "TRACY_NO_CALLSTACK_INLINES", "1" }, + .{ tracy_only_localhost , "TRACY_ONLY_LOCALHOST" , "1" }, + .{ tracy_no_broadcast , "TRACY_NO_BROADCAST" , "1" }, + .{ tracy_only_ipv4 , "TRACY_ONLY_IPV4" , "1" }, + .{ tracy_no_code_transfer , "TRACY_NO_CODE_TRANSFER" , "1" }, + .{ tracy_no_context_switch , "TRACY_NO_CONTEXT_SWITCH" , "1" }, + .{ tracy_no_exit , "TRACY_NO_EXIT" , "1" }, + .{ tracy_no_sampling , "TRACY_NO_SAMPLING" , "1" }, + .{ tracy_no_verify , "TRACY_NO_VERIFY" , "1" }, + .{ tracy_no_vsync_capture , "TRACY_NO_VSYNC_CAPTURE" , "1" }, + .{ tracy_no_frame_image , "TRACY_NO_FRAME_IMAGE" , "1" }, + .{ tracy_no_system_tracing , "TRACY_NO_SYSTEM_TRACING" , "1" }, + .{ tracy_delayed_init , "TRACY_DELAYED_INIT" , "1" }, + .{ tracy_manual_lifetime , "TRACY_MANUAL_LIFETIME" , "1" }, + .{ tracy_fibers , "TRACY_FIBERS" , "1" }, + .{ tracy_no_crash_handler , "TRACY_NO_CRASH_HANDLER" , "1" }, + .{ tracy_timer_fallback , "TRACY_TIMER_FALLBACK" , "1" }, + }) |entry| { + const condition = entry[0]; + const name = entry[1]; + const value = entry[2]; + if (condition) { + try defines.append(arena, .{ .name = name, .value = value }); + } + } + if (tracy_callstack) |depth| { + try defines.append(arena, .{ .name = "TRACY_CALLSTACK", .value = "\"" ++ digits2(depth) ++ "\"" }); + } - tracy_module.addImport("tracy-options", options.createModule()); - tracy_module.addIncludePath(dep_src.path("./public")); - - const tracy_client = b.addLibrary(.{ - .linkage = if (shared) .dynamic else .static, - .name = "tracy", - .root_module = b.createModule(.{ + { + const tracy_module = b.addModule("tracy", .{ + .root_source_file = b.path("src/root.zig"), .target = target, .optimize = optimize, - }), - }); + }); - if (target.result.os.tag == .windows) { - tracy_client.root_module.linkSystemLibrary("dbghelp", .{}); - tracy_client.root_module.linkSystemLibrary("ws2_32", .{}); + const options = b.addOptions(); + options.addOption(bool, "tracy_enable", tracy_enable); + options.addOption(?u8, "tracy_callstack", tracy_callstack); + options.addOption(bool, "tracy_no_callstack", tracy_no_callstack); + options.addOption(bool, "tracy_fibers", tracy_fibers); + tracy_module.addImport("options", options.createModule()); + + const write_file_step = b.addWriteFiles(); + const translate_c = b.addTranslateC(.{ + .root_source_file = write_file_step.add("c.h", "#include "), + .target = target, + .optimize = optimize, + }); + translate_c.addIncludePath(dep_src.path("./public")); + if (shared and is_windows) { + translate_c.defineCMacro("TRACY_IMPORTS", "1"); + } + for (defines.items) |define| { + translate_c.defineCMacro(define.name, define.value); + } + tracy_module.addImport("c", translate_c.createModule()); } - if (target.result.abi != .msvc) { - tracy_client.root_module.link_libcpp = true; - } else { - tracy_client.root_module.link_libc = true; + + { + const mod = b.createModule(.{ + .target = target, + .optimize = optimize, + }); + + if (is_windows) { + mod.linkSystemLibrary("dbghelp", .{}); + mod.linkSystemLibrary("ws2_32", .{}); + } + if (target.result.abi != .msvc) { + mod.link_libcpp = true; + } else { + mod.link_libc = true; + } + mod.addCSourceFile(.{ + .file = dep_src.path("./public/TracyClient.cpp"), + .flags = if (is_windows) &.{"-fms-extensions"} else &.{}, + }); + if (shared and is_windows) { + mod.addCMacro("TRACY_EXPORTS", "1"); + } + for (defines.items) |define| { + mod.addCMacro(define.name, define.value); + } + + const tracy_client = b.addLibrary(.{ + .linkage = if (shared) .dynamic else .static, + .name = "tracy", + .root_module = mod + }); + tracy_client.installHeadersDirectory(dep_src.path("public"), "", .{ + .include_extensions = &.{".h", ".hpp"}, + }); + b.installArtifact(tracy_client); } - tracy_client.root_module.addCSourceFile(.{ - .file = dep_src.path("./public/TracyClient.cpp"), - .flags = if (target.result.os.tag == .windows) &.{"-fms-extensions"} else &.{}, - }); - tracy_client.installHeadersDirectory(dep_src.path("public"), "", .{ - .include_extensions = &.{".h", ".hpp"}, - }); - if (tracy_enable) - tracy_client.root_module.addCMacro("TRACY_ENABLE", "1"); - if (tracy_on_demand) - tracy_client.root_module.addCMacro("TRACY_ON_DEMAND", "1"); - if (tracy_callstack) |depth| { - tracy_client.root_module.addCMacro("TRACY_CALLSTACK", "\"" ++ digits2(depth) ++ "\""); - } - if (tracy_no_callstack) - tracy_client.root_module.addCMacro("TRACY_NO_CALLSTACK", "1"); - if (tracy_no_callstack_inlines) - tracy_client.root_module.addCMacro("TRACY_NO_CALLSTACK_INLINES", "1"); - if (tracy_only_localhost) - tracy_client.root_module.addCMacro("TRACY_ONLY_LOCALHOST", "1"); - if (tracy_no_broadcast) - tracy_client.root_module.addCMacro("TRACY_NO_BROADCAST", "1"); - if (tracy_only_ipv4) - tracy_client.root_module.addCMacro("TRACY_ONLY_IPV4", "1"); - if (tracy_no_code_transfer) - tracy_client.root_module.addCMacro("TRACY_NO_CODE_TRANSFER", "1"); - if (tracy_no_context_switch) - tracy_client.root_module.addCMacro("TRACY_NO_CONTEXT_SWITCH", "1"); - if (tracy_no_exit) - tracy_client.root_module.addCMacro("TRACY_NO_EXIT", "1"); - if (tracy_no_sampling) - tracy_client.root_module.addCMacro("TRACY_NO_SAMPLING", "1"); - if (tracy_no_verify) - tracy_client.root_module.addCMacro("TRACY_NO_VERIFY", "1"); - if (tracy_no_vsync_capture) - tracy_client.root_module.addCMacro("TRACY_NO_VSYNC_CAPTURE", "1"); - if (tracy_no_frame_image) - tracy_client.root_module.addCMacro("TRACY_NO_FRAME_IMAGE", "1"); - if (tracy_no_system_tracing) - tracy_client.root_module.addCMacro("TRACY_NO_SYSTEM_TRACING", "1"); - if (tracy_delayed_init) - tracy_client.root_module.addCMacro("TRACY_DELAYED_INIT", "1"); - if (tracy_manual_lifetime) - tracy_client.root_module.addCMacro("TRACY_MANUAL_LIFETIME", "1"); - if (tracy_fibers) - tracy_client.root_module.addCMacro("TRACY_FIBERS", "1"); - if (tracy_no_crash_handler) - tracy_client.root_module.addCMacro("TRACY_NO_CRASH_HANDLER", "1"); - if (tracy_timer_fallback) - tracy_client.root_module.addCMacro("TRACY_TIMER_FALLBACK", "1"); - if (shared and target.result.os.tag == .windows) - tracy_client.root_module.addCMacro("TRACY_EXPORTS", "1"); - b.installArtifact(tracy_client); } + +const CDefine = struct { + name: []const u8, + value: []const u8, +}; diff --git a/libs/tracy/src/root.zig b/libs/tracy/src/root.zig index 227867c..c0498a7 100644 --- a/libs/tracy/src/root.zig +++ b/libs/tracy/src/root.zig @@ -2,34 +2,9 @@ const std = @import("std"); const digits2 = std.fmt.digits2; const builtin = @import("builtin"); -const options = @import("tracy-options"); +const options = @import("options"); -const c = @cImport({ - if (options.tracy_enable) @cDefine("TRACY_ENABLE", {}); - if (options.tracy_on_demand) @cDefine("TRACY_ON_DEMAND", {}); - if (options.tracy_callstack) |depth| @cDefine("TRACY_CALLSTACK", "\"" ++ digits2(depth) ++ "\""); - if (options.tracy_no_callstack) @cDefine("TRACY_NO_CALLSTACK", {}); - if (options.tracy_no_callstack_inlines) @cDefine("TRACY_NO_CALLSTACK_INLINES", {}); - if (options.tracy_only_localhost) @cDefine("TRACY_ONLY_LOCALHOST", {}); - if (options.tracy_no_broadcast) @cDefine("TRACY_NO_BROADCAST", {}); - if (options.tracy_only_ipv4) @cDefine("TRACY_ONLY_IPV4", {}); - if (options.tracy_no_code_transfer) @cDefine("TRACY_NO_CODE_TRANSFER", {}); - if (options.tracy_no_context_switch) @cDefine("TRACY_NO_CONTEXT_SWITCH", {}); - if (options.tracy_no_exit) @cDefine("TRACY_NO_EXIT", {}); - if (options.tracy_no_sampling) @cDefine("TRACY_NO_SAMPLING", {}); - if (options.tracy_no_verify) @cDefine("TRACY_NO_VERIFY", {}); - if (options.tracy_no_vsync_capture) @cDefine("TRACY_NO_VSYNC_CAPTURE", {}); - if (options.tracy_no_frame_image) @cDefine("TRACY_NO_FRAME_IMAGE", {}); - if (options.tracy_no_system_tracing) @cDefine("TRACY_NO_SYSTEM_TRACING", {}); - if (options.tracy_delayed_init) @cDefine("TRACY_DELAYED_INIT", {}); - if (options.tracy_manual_lifetime) @cDefine("TRACY_MANUAL_LIFETIME", {}); - if (options.tracy_fibers) @cDefine("TRACY_FIBERS", {}); - if (options.tracy_no_crash_handler) @cDefine("TRACY_NO_CRASH_HANDLER", {}); - if (options.tracy_timer_fallback) @cDefine("TRACY_TIMER_FALLBACK", {}); - if (options.shared and builtin.os.tag == .windows) @cDefine("TRACY_IMPORTS", {}); - - @cInclude("tracy/TracyC.h"); -}); +const c = @import("c"); pub inline fn setThreadName(comptime name: [:0]const u8) void { if (!options.tracy_enable) return; diff --git a/src/platform/graphics.zig b/src/platform/graphics.zig index c3b13c8..ac80ec0 100644 --- a/src/platform/graphics.zig +++ b/src/platform/graphics.zig @@ -91,7 +91,7 @@ pub fn init(gpa: std.mem.Allocator, logger: sg.Logger) !void { .primitive_type = .TRIANGLES, .index_type = .UINT16, .colors = init: { - var s: [8]sg.ColorTargetState = [_]sg.ColorTargetState{.{}} ** 8; + var s: [8]sg.ColorTargetState = @splat(.{}); s[0] = .{ .blend = .{ .enabled = true, @@ -1270,8 +1270,8 @@ pub const Image = struct { pub fn maxPixelSize() usize { var result: usize = 0; - for (@typeInfo(Image.Format).@"enum".fields) |field| { - const pixel_size = Image.Format.pixelSize(@enumFromInt(field.value)); + for (@typeInfo(Image.Format).@"enum".field_values) |field_value| { + const pixel_size = Image.Format.pixelSize(@enumFromInt(field_value)); result = @max(result, pixel_size); } return result; diff --git a/src/platform/root.zig b/src/platform/root.zig index 9ddf6e4..e072183 100644 --- a/src/platform/root.zig +++ b/src/platform/root.zig @@ -614,9 +614,9 @@ pub fn run(App: type, opts: RunOptions) void { const io = opts.init.io; var assets_dir: ?Io.Dir = null; - if (build_options.assets_dir) |assets_dir_path| { + if (@hasDecl(build_options, "assets_dir")) { const cwd = Io.Dir.cwd(); - assets_dir = cwd.openDir(io, assets_dir_path, .{}) catch |e| blk: { + assets_dir = cwd.openDir(io, build_options.assets_dir, .{}) catch |e| blk: { log.err("Failed to open assets directory: {}", .{e}); break :blk null; };