raylib-template/build.zig
2025-12-05 03:27:30 +02:00

75 lines
2.1 KiB
Zig

const std = @import("std");
const zcc = @import("compile_commands");
pub fn build(b: *std.Build) !void {
const target = b.standardTargetOptions(.{ });
const optimize = b.standardOptimizeOption(.{});
const tracy_enabled = b.option(bool, "tracy", "Enable tracy profiling") orelse (optimize == .Debug);
var targets = std.ArrayList(*std.Build.Step.Compile){};
const mod = b.createModule(.{
.target = target,
.optimize = optimize,
.link_libc = true,
});
mod.addIncludePath(b.path("./src/"));
{
var src_dir = try std.fs.cwd().openDir("src", .{ .iterate = true });
defer src_dir.close();
var iter = src_dir.iterate();
while (try iter.next()) |entry| {
if (entry.kind == .file and std.mem.endsWith(u8, entry.name, ".c")) {
mod.addCSourceFile(.{
.file = b.path(b.pathJoin(&.{ "src", entry.name })),
.flags = &.{}
});
}
}
}
const raylib_dep = b.dependency("raylib", .{
.target = target,
.optimize = optimize
});
mod.linkLibrary(raylib_dep.artifact("raylib"));
const tracy_dep = b.dependency("tracy", .{
.tracy_enable = tracy_enabled,
});
mod.linkLibrary(tracy_dep.artifact("tracy"));
const incbin_dep = b.dependency("incbin", .{});
mod.addIncludePath(incbin_dep.path("."));
const exe = b.addExecutable(.{
.name = "gaem",
.root_module = mod
});
try targets.append(b.allocator, exe);
if (target.result.os.tag == .windows) {
const show_console = b.option(bool, "console", "Show windows console") orelse (optimize == .Debug);
exe.subsystem = if (show_console) .Console else .Windows;
}
b.installArtifact(exe);
{
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", "Run the program");
run_step.dependOn(&run_cmd.step);
}
_ = zcc.createStep(b, "cdb", try targets.toOwnedSlice(b.allocator));
}