147 lines
4.6 KiB
Zig
147 lines
4.6 KiB
Zig
const std = @import("std");
|
|
const sokol = @import("sokol");
|
|
|
|
pub fn build(b: *std.Build) !void {
|
|
const target = b.standardTargetOptions(.{});
|
|
const optimize = b.standardOptimizeOption(.{});
|
|
|
|
const has_imgui = b.option(bool, "imgui", "ImGui integration") orelse (optimize == .Debug);
|
|
const has_tracy = b.option(bool, "tracy", "Tracy integration") orelse (optimize == .Debug);
|
|
|
|
const exe = b.addExecutable(.{
|
|
.name = "game_2025_12_13",
|
|
.root_module = b.createModule(.{
|
|
.root_source_file = b.path("src/main.zig"),
|
|
.target = target,
|
|
.optimize = optimize,
|
|
.link_libc = true
|
|
}),
|
|
});
|
|
const exe_mod = exe.root_module;
|
|
|
|
const tracy_dependency = b.dependency("tracy", .{
|
|
.target = target,
|
|
.optimize = optimize,
|
|
.tracy_enable = has_tracy,
|
|
.tracy_only_localhost = true
|
|
});
|
|
exe_mod.linkLibrary(tracy_dependency.artifact("tracy"));
|
|
exe_mod.addImport("tracy", tracy_dependency.module("tracy"));
|
|
|
|
const stb_dependency = b.dependency("stb", .{});
|
|
exe_mod.addIncludePath(stb_dependency.path("."));
|
|
|
|
const sokol_c_dependency = b.dependency("sokol_c", .{});
|
|
exe_mod.addIncludePath(sokol_c_dependency.path("util"));
|
|
|
|
const fontstash_dependency = b.dependency("fontstash", .{});
|
|
exe_mod.addIncludePath(fontstash_dependency.path("src"));
|
|
|
|
const libxml2_dependency = b.dependency("libxml2", .{
|
|
.target = target,
|
|
.optimize = optimize,
|
|
.linkage = .static,
|
|
});
|
|
|
|
{
|
|
const libtmx_dependency = b.dependency("libtmx", .{});
|
|
const libtmx = b.addLibrary(.{
|
|
.name = "tmx",
|
|
.root_module = b.createModule(.{
|
|
.target = target,
|
|
.optimize = optimize,
|
|
.link_libc = true
|
|
}),
|
|
});
|
|
libtmx.installHeader(libtmx_dependency.path("src/tmx.h"), "tmx.h");
|
|
libtmx.root_module.addCSourceFiles(.{
|
|
.root = libtmx_dependency.path("src"),
|
|
.files = &.{
|
|
"tmx.c",
|
|
"tmx_utils.c",
|
|
"tmx_err.c",
|
|
"tmx_xml.c",
|
|
"tmx_mem.c",
|
|
"tmx_hash.c"
|
|
},
|
|
.flags = &.{
|
|
"-fno-delete-null-pointer-checks"
|
|
}
|
|
});
|
|
libtmx.linkLibrary(libxml2_dependency.artifact("xml"));
|
|
|
|
exe_mod.linkLibrary(libtmx);
|
|
}
|
|
|
|
const sokol_dependency = b.dependency("sokol", .{
|
|
.target = target,
|
|
.optimize = optimize,
|
|
.with_sokol_imgui = has_imgui
|
|
});
|
|
|
|
exe_mod.addImport("sokol", sokol_dependency.module("sokol"));
|
|
exe_mod.linkLibrary(sokol_dependency.artifact("sokol_clib"));
|
|
|
|
var cflags_buffer: [64][]const u8 = undefined;
|
|
var cflags = std.ArrayListUnmanaged([]const u8).initBuffer(&cflags_buffer);
|
|
switch (sokol.resolveSokolBackend(.auto, target.result)) {
|
|
.d3d11 => try cflags.appendBounded("-DSOKOL_D3D11"),
|
|
.metal => try cflags.appendBounded("-DSOKOL_METAL"),
|
|
.gl => try cflags.appendBounded("-DSOKOL_GLCORE"),
|
|
.gles3 => try cflags.appendBounded("-DSOKOL_GLES3"),
|
|
.wgpu => try cflags.appendBounded("-DSOKOL_WGPU"),
|
|
else => @panic("unknown sokol backend"),
|
|
}
|
|
exe_mod.addIncludePath(b.path("src/libs"));
|
|
exe_mod.addCSourceFile(.{
|
|
.file = b.path("src/libs/sokol_fontstash_impl.c"),
|
|
.flags = cflags.items
|
|
});
|
|
|
|
exe_mod.addCSourceFile(.{
|
|
.file = b.path("src/libs/stb_image.c"),
|
|
.flags = &.{}
|
|
});
|
|
|
|
if (has_imgui) {
|
|
if (b.lazyDependency("cimgui", .{
|
|
.target = target,
|
|
.optimize = optimize,
|
|
})) |cimgui_dependency| {
|
|
sokol_dependency.artifact("sokol_clib").addIncludePath(cimgui_dependency.path("src"));
|
|
exe_mod.addImport("cimgui", cimgui_dependency.module("cimgui"));
|
|
}
|
|
}
|
|
|
|
var options = b.addOptions();
|
|
options.addOption(bool, "has_imgui", has_imgui);
|
|
options.addOption(bool, "has_tracy", has_tracy);
|
|
exe_mod.addOptions("options", options);
|
|
|
|
b.installArtifact(exe);
|
|
|
|
{
|
|
const run_step = b.step("run", "Run the app");
|
|
|
|
const run_cmd = b.addRunArtifact(exe);
|
|
run_step.dependOn(&run_cmd.step);
|
|
|
|
run_cmd.step.dependOn(b.getInstallStep());
|
|
|
|
if (b.args) |args| {
|
|
run_cmd.addArgs(args);
|
|
}
|
|
}
|
|
|
|
{
|
|
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);
|
|
}
|
|
}
|