const std = @import("std"); pub fn build(b: *std.Build) void { const target = b.standardTargetOptions(.{ .default_target = .{ .cpu_model = .native } }); const optimize = b.standardOptimizeOption(.{ .preferred_optimize_mode = .ReleaseFast }); const assets = b.addInstallDirectory(.{ .source_dir = b.path("assets"), .install_dir = .bin, .install_subdir = "assets", }); const shared = b.addModule("shared", .{ .root_source_file = b.path("src/shared/shared.zig"), .target = target, }); const client = b.addExecutable(.{ .name = "client", .root_module = b.createModule(.{ .root_source_file = b.path("src/client/main.zig"), .target = target, .optimize = optimize, .imports = &.{ .{ .name = "shared", .module = shared }, }, }), .use_llvm = true, }); client.root_module.strip = true; const server = b.addExecutable(.{ .name = "server", .root_module = b.createModule(.{ .root_source_file = b.path("src/server/main.zig"), .target = target, .optimize = optimize, .imports = &.{ .{ .name = "shared", .module = shared }, }, }), .use_llvm = true, }); server.root_module.strip = true; const ztracy = b.dependency( "ztracy", .{ .enable_ztracy = true, .enable_fibers = false, .on_demand = false, } ); client.root_module.addImport("ztracy", ztracy.module("root")); client.linkLibrary(ztracy.artifact("tracy")); const mach_freetype = b.dependency("mach_freetype", .{ .target = target, .optimize = optimize, }); client.root_module.addImport("mach-freetype", mach_freetype.module("mach-freetype")); client.root_module.addImport("mach-harfbuzz", mach_freetype.module("mach-harfbuzz")); client.root_module.addCSourceFile(.{ .file = b.path("vendor/kb_text_shape/kb_text_shape.h"), .language = .c, .flags = &.{ "-DKB_TEXT_SHAPE_IMPLEMENTATION", "-O3", // Maximum optimization // "-ffast-math", // Allows algebraic reorganizations (risky for precision, great for speed) // "-fno-plt", // Reduces overhead for library calls // "-march=native", // Use every instruction your CPU has // "-flto", // Enable LTO for the C side specifically }, }); const kb_text_shape = b.addTranslateC(.{ .root_source_file = b.path("vendor/kb_text_shape/kb_text_shape.h"), .target = target, .optimize = optimize, }); client.root_module.addImport("kb", kb_text_shape.createModule()); client.root_module.addCSourceFile(.{ .file = b.path("vendor/stb/stb_rect_pack.h"), .language = .c, .flags = &.{} }); const stb_rect_pack = b.addTranslateC(.{ .root_source_file = b.path("vendor/stb/stb_rect_pack.h"), .target = target, .optimize = optimize, }); client.root_module.addImport("stb_rect_pack", stb_rect_pack.createModule()); const zmath = b.dependency( "zmath", .{ .target = target, .optimize = optimize, } ); client.root_module.addImport("zmath", zmath.module("root")); server.root_module.addImport("zmath", zmath.module("root")); shared.addImport("zmath", zmath.module("root")); const znet = b.dependency( "znet", .{ .target = target, .optimize = optimize, } ); client.root_module.addImport("znet", znet.module("znet")); server.root_module.addImport("znet", znet.module("znet")); const bufzilla = b.dependency( "bufzilla", .{ .target = target, .optimize = optimize, }); client.root_module.addImport("bufzilla", bufzilla.module("bufzilla")); server.root_module.addImport("bufzilla", bufzilla.module("bufzilla")); const raylib_dep = b.dependency("raylib_zig", .{ .target = target, .optimize = optimize, }); const raylib = raylib_dep.module("raylib"); // main raylib module const raygui = raylib_dep.module("raygui"); // raygui module const raylib_artifact = raylib_dep.artifact("raylib"); // raylib C library raylib_artifact.root_module.addCMacro("SUPPORT_CUSTOM_FRAME_CONTROL", ""); client.linkLibrary(raylib_artifact); client.root_module.addImport("raylib", raylib); client.root_module.addImport("raygui", raygui); b.installArtifact(client); b.installArtifact(server); b.getInstallStep().dependOn(&assets.step); const run_step = b.step("run", "Run the app"); const run_cmd_client = b.addRunArtifact(client); const run_cmd_server = b.addRunArtifact(server); run_step.dependOn(&run_cmd_client.step); run_step.dependOn(&run_cmd_server.step); run_cmd_client.step.dependOn(b.getInstallStep()); run_cmd_server.step.dependOn(b.getInstallStep()); if (b.args) |args| { run_cmd_client.addArgs(args); } // Creates an executable that will run `test` blocks from the provided module. // Here `mod` needs to define a target, which is why earlier we made sure to // set the releative field. // const mod_tests = b.addTest(.{ // .root_module = mod, // }); // A run step that will run the test executable. // const run_mod_tests = b.addRunArtifact(mod_tests); // Creates an executable that will run `test` blocks from the executable's // root module. Note that test executables only test one module at a time, // hence why we have to create two separate ones. // const exe_tests = b.addTest(.{ // .root_module = exe.root_module, // }); // A run step that will run the second test executable. // const run_exe_tests = b.addRunArtifact(exe_tests); // A top level step for running all tests. dependOn can be called multiple // times and since the two run steps do not depend on one another, this will // make the two of them run in parallel. // const test_step = b.step("test", "Run tests"); // test_step.dependOn(&run_mod_tests.step); // test_step.dependOn(&run_exe_tests.step); // Just like flags, top level steps are also listed in the `--help` menu. // // The Zig build system is entirely implemented in userland, which means // that it cannot hook into private compiler APIs. All compilation work // orchestrated by the build system will result in other Zig compiler // subcommands being invoked with the right flags defined. You can observe // these invocations when one fails (or you pass a flag to increase // verbosity) to validate assumptions and diagnose problems. // // Lastly, the Zig build system is relatively simple and self-contained, // and reading its source code will allow you to master it. }