const std = @import("std"); pub fn build(b: *std.Build) void { const target = b.standardTargetOptions(.{}); const optimize = b.standardOptimizeOption(.{}); const admin_controls = b.option(bool, "admin-controls", "Enable in-game development admin controls") orelse false; const base_c_flags = [_][]const u8{ "-std=c99", "-Wall", "-Wextra", "-O2", }; const admin_c_flags = [_][]const u8{ "-std=c99", "-Wall", "-Wextra", "-O2", "-DROGGED_ADMIN_CONTROLS=1", }; const c_flags = if (admin_controls) &admin_c_flags else &base_c_flags; // RNG library const rng_lib = b.addLibrary(.{ .name = "rng", .root_module = b.createModule(.{ .target = target, .optimize = optimize, .link_libc = true, }), }); rng_lib.root_module.addCSourceFiles(.{ .files = &[_][]const u8{"libs/rng/rng.c"}, .flags = c_flags, }); rng_lib.root_module.addIncludePath(b.path("libs/rng")); // Map library const map_lib = b.addLibrary(.{ .name = "map", .root_module = b.createModule(.{ .target = target, .optimize = optimize, .link_libc = true, }), }); map_lib.root_module.addCSourceFiles(.{ .files = &[_][]const u8{ "libs/map/map.c", "libs/map/utils.c", }, .flags = c_flags, }); // map.h includes common.h and settings.h which live in src/ map_lib.root_module.addIncludePath(b.path("src")); // map.c includes rng/rng.h via libs/ root map_lib.root_module.addIncludePath(b.path("libs")); // utils.h is co-located with map.c map_lib.root_module.addIncludePath(b.path("libs/map")); // Tileset library const tileset_obj = b.addObject(.{ .name = "tileset", .root_module = b.createModule(.{ .target = target, .optimize = optimize, .link_libc = true, }), }); tileset_obj.root_module.addCSourceFiles(.{ .files = &[_][]const u8{ "libs/tileset/tileset.c", "libs/tileset/tileset_paint.c", }, .flags = c_flags, }); // tileset.h includes settings.h which lives in src/ tileset_obj.root_module.addIncludePath(b.path("src")); // tileset.c includes tileset.h which is co-located tileset_obj.root_module.addIncludePath(b.path("libs/tileset")); tileset_obj.root_module.linkSystemLibrary("raylib", .{}); // Zig combat library. This must be compiled as an object and linked // directly to bypassing the archive step, or it yields a corrupt // archive that forces the user to clear the cache each time. const combat_obj = b.addObject(.{ .name = "combat", .root_module = b.createModule(.{ .root_source_file = b.path("libs/combat/combat.zig"), .target = target, .optimize = optimize, .link_libc = true, }), }); // common.h and settings.h live in src/; rng.h exposed bare from libs/rng combat_obj.root_module.addIncludePath(b.path("src")); combat_obj.root_module.addIncludePath(b.path("libs/rng")); // C sources remaining in src/ const c_sources = [_][]const u8{ "src/audio.c", "src/enemy.c", "src/items.c", "src/main.c", "src/movement.c", "src/player.c", "src/render.c", "src/settings.c", }; // Main executable const exe = b.addExecutable(.{ .name = "roguelike", .root_module = b.createModule(.{ .target = target, .optimize = optimize, .link_libc = true, }), }); exe.root_module.addCSourceFiles(.{ .files = &c_sources, .flags = c_flags, }); // src/ for own headers; libs/ so "rng/rng.h" and "map/map.h" resolve exe.root_module.addIncludePath(b.path("src")); exe.root_module.addIncludePath(b.path("libs")); exe.root_module.linkLibrary(rng_lib); exe.root_module.linkLibrary(map_lib); exe.root_module.addObject(tileset_obj); exe.root_module.addObject(combat_obj); exe.root_module.linkSystemLibrary("raylib", .{}); exe.root_module.linkSystemLibrary("m", .{}); exe.root_module.linkSystemLibrary("pthread", .{}); exe.root_module.linkSystemLibrary("dl", .{}); exe.root_module.linkSystemLibrary("rt", .{}); b.installArtifact(exe); // Run step const run_cmd = b.addRunArtifact(exe); run_cmd.step.dependOn(b.getInstallStep()); if (b.args) |args| { run_cmd.addArgs(args); } const run_step = b.step("run", "Build and run the roguelike"); run_step.dependOn(&run_cmd.step); }