zzz/build.zig

210 lines
7.8 KiB
Zig

const std = @import("std");
pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
const assets = b.addInstallDirectory(.{
.source_dir = b.path("assets"),
.install_dir = .bin,
.install_subdir = "assets",
});
// const sdl3 = b.dependency("sdl3", .{
// .target = target,
// .optimize = .Debug,
// // Lib options.
// // .callbacks = false,
// // .ext_image = false,
// // .ext_net = false,
// // .ext_ttf = false,
// // .log_message_stack_size = 1024,
// // .main = false,
// // .renderer_debug_text_stack_size = 1024,
// // Options passed directly to https://github.com/castholm/SDL (SDL3 C Bindings):
// // .c_sdl_preferred_linkage = .static,
// // .c_sdl_strip = false,
// // .c_sdl_sanitize_c = .off,
// // .c_sdl_lto = .none,
// // .c_sdl_emscripten_pthreads = false,
// // .c_sdl_install_build_config_h = false,
// // Options if `ext_image` is enabled:
// // .image_enable_bmp = true,
// // .image_enable_gif = true,
// // .image_enable_jpg = true,
// // .image_enable_lbm = true,
// // .image_enable_pcx = true,
// // .image_enable_png = true,
// // .image_enable_pnm = true,
// // .image_enable_qoi = true,
// // .image_enable_svg = true,
// // .image_enable_tga = true,
// // .image_enable_xcf = true,
// // .image_enable_xpm = true,
// // .image_enable_xv = true,
// });
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 },
},
})
});
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 },
},
}),
});
const freetype_module = b.addModule("mach-freetype", .{
.root_source_file = b.path("src/freetype/freetype.zig"),
});
if (b.lazyDependency("freetype", .{
.target = target,
.optimize = optimize,
.use_system_zlib = false,
.enable_brotli = false,
})) |dep| {
// freetype_tests.root_module.linkLibrary(dep.artifact("freetype"));
freetype_module.linkLibrary(dep.artifact("freetype"));
// harfbuzz_module.linkLibrary(dep.artifact("freetype"));
// harfbuzz_tests.root_module.linkLibrary(dep.artifact("freetype"));
}
client.root_module.addImport("freetype", freetype_module);
client.root_module.addCSourceFile(.{ .file = b.path("vendor/kb_text_shape/kb_text_shape.h"), .language = .c, .flags = &.{"-DKB_TEXT_SHAPE_IMPLEMENTATION"} });
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", .{});
client.root_module.addImport("zmath", zmath.module("root"));
server.root_module.addImport("zmath", zmath.module("root"));
shared.addImport("zmath", zmath.module("root"));
const znet_dep = b.dependency("znet", .{
.target = target,
.optimize = optimize,
});
const znet_mod = znet_dep.module("znet");
const znet_artifact = znet_dep.artifact("znet");
client.root_module.addImport("znet", znet_mod);
client.linkLibrary(znet_artifact);
server.root_module.addImport("znet", znet_mod);
server.linkLibrary(znet_artifact);
const bufzilla = b.dependency("bufzilla", .{});
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);
const raylib_dep = b.dependency("raylib", .{ .target = target, .optimize = optimize });
const raylib = raylib_dep.artifact("raylib");
raylib.root_module.addCMacro("SUPPORT_CUSTOM_FRAME_CONTROL", "");
client.linkLibrary(raylib);
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.
}