const std = @import("std"); const Build = std.Build; const program_name = "fortunes-foundation"; pub fn build(b: *Build) !void { const optimize: std.builtin.OptimizeMode = b.standardOptimizeOption(.{}); const target: Build.ResolvedTarget = b.standardTargetOptions(.{}); const tracy_enable = b.option(bool, "tracy_enable", "Enables Tracy support in the final executable") orelse false; const tracy_callstack = b.option(u32, "tracy_callstack", "Size of the collected callstack") orelse 0; const dancer_static_lib = dancer_static_lib: { const odin_exec = b.addSystemCommand(&.{ "odin", "build", "-build-mode:static", "-microarch:x86-64-v3" }); odin_exec.addArg(switch (optimize) { .Debug => "-o:minimal", .ReleaseSafe => "-o:speed", .ReleaseFast => "-o:aggressive", .ReleaseSmall => "-o:size", }); if (optimize == .Debug or tracy_enable) { odin_exec.addArg("-debug"); } if (optimize == .ReleaseFast) { odin_exec.addArg("-disable-assert"); } if (tracy_enable) { odin_exec.addArg("-define:TRACY_ENABLE=true"); odin_exec.addArg(b.fmt("-define:TRACY_CALLSTACK={}", .{tracy_callstack})); } const dancer_static_lib = odin_exec.addPrefixedOutputFileArg("-out:", switch (target.result.abi) { else => "game.a", }); odin_exec.addDirectoryArg(b.path(switch (target.result.cpu.arch) { .wasm32, .wasm64 => "src/main_web", else => "src/main_desktop/", })); odin_exec.has_side_effects = true; break :dancer_static_lib dancer_static_lib; }; const exe_mod = b.addModule(program_name, .{ .target = target, .optimize = optimize, .link_libc = true, .link_libcpp = true, }); exe_mod.addObjectFile(dancer_static_lib); const raylib_dep = b.dependency("raylib", .{ .target = target, .optimize = .ReleaseFast, .linux_display_backend = .X11, .opengl_version = .auto, .raygui = true, }); const raylib_compile = raylib_dep.artifact("raylib"); exe_mod.linkLibrary(raylib_compile); if (tracy_enable) { const tracy_dep = b.dependency("tracy", .{}); const tracy_mod = b.addModule("tracy", .{ .target = target, .optimize = .ReleaseFast, .link_libc = true, .link_libcpp = true, }); tracy_mod.addCMacro("TRACY_ENABLE", "1"); tracy_mod.addCMacro("TRACY_CALLSTACK", "16"); // tracy_mod.addCMacro("TRACY_VERBOSE", "1"); // Enable this if sampling is missing. // tracy_mod.addCMacro("TRACY_DISALLOW_HW_TIMER", "1"); if (target.query.os_tag == .linux) { tracy_mod.addCMacro("TRACY_LIBUNWIND_BACKTRACE", "1"); } tracy_mod.addCSourceFile(.{ .file = tracy_dep.path("public/TracyClient.cpp"), .language = .cpp, }); exe_mod.addObject(b.addObject(.{ .name = "tracy", .root_module = tracy_mod })); } if ((optimize == .ReleaseSmall or optimize == .ReleaseFast) and !tracy_enable) exe_mod.strip = true; const exe = b.addExecutable(.{ .root_module = exe_mod, .name = program_name, }); exe.lto = if (optimize != .Debug) .full else .none; exe.pie = false; exe.bundle_ubsan_rt = true; exe.bundle_compiler_rt = true; b.installArtifact(exe); b.step("run", "Run the game").dependOn(&b.addRunArtifact(exe).step); }