hadean-zig/build.zig

94 lines
2.7 KiB
Zig

const std = @import("std");
pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
// === [ C IMPORTS ] ===
const c = b.addModule("c", .{
.root_source_file = b.path("src/c.zig"),
.target = target,
.optimize = optimize,
});
c.linkSystemLibrary("SDL3", .{});
c.addIncludePath(b.path("open-simplex/include"));
c.linkSystemLibrary("SDL3_image", .{});
// === [ ENGINE ] ===
const engine = b.addModule("engine", .{
.root_source_file = b.path("src/engine/root.zig"),
.target = target,
.optimize = optimize,
});
engine.addImport("engine", engine);
engine.addImport("c", c);
// === [ GAME CODE ] ===
const hadean = b.addModule("hadean", .{
.root_source_file = b.path("src/hadean/hadean.zig"),
.target = target,
.optimize = optimize,
});
hadean.addImport("c", c);
hadean.addImport("engine", engine);
hadean.addImport("hadean", hadean);
// === [ EXECUTABLE ] ===
const exe = b.addExecutable(.{
.name = "hadean",
.root_source_file = b.path("src/main.zig"),
.target = target,
.optimize = optimize,
});
exe.root_module.addImport("engine", engine);
exe.root_module.addImport("hadean", hadean);
exe.root_module.addImport("c", c);
exe.addCSourceFile(.{ .file = b.path("open-simplex/src/OpenSimplex2F.c") });
exe.addIncludePath(b.path("open-simplex/include"));
exe.linkLibC();
exe.root_module.addRPathSpecial("$ORIGIN/../lib");
b.getInstallStep().dependOn(&(b.addInstallFile(.{
.cwd_relative = "/usr/local/lib/libSDL3.so.0.1.7"
}, "lib/libSDL3.so.0")).step);
b.getInstallStep().dependOn(&(b.addInstallFile(.{
.cwd_relative = "/usr/local/lib/libSDL3_image.so.0.1.0"
}, "lib/libSDL3_image.so.0")).step);
b.getInstallStep().dependOn(&(b.addInstallFile(
b.path("assets/textures.png"),
"assets/textures.png"
)).step);
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 app");
run_step.dependOn(&run_cmd.step);
const pathfinder_perf_test = b.addTest(.{
.root_source_file = b.path("src/hadean/PathFinder.zig"),
.target = target,
.optimize = optimize,
});
pathfinder_perf_test.root_module.addImport("engine", engine);
const run_pathfinder_perf_test = b.addRunArtifact(pathfinder_perf_test);
const test_step = b.step("pathfinder_perf_test", "Run PathFinder Performance Test");
test_step.dependOn(&run_pathfinder_perf_test.step);
// because engine and hadean are diff modules their c modules
// get different caches, causing opaques to be different between them.
// kinda makes sense, because zig is namespacy and c is not!
// it would be nice to in some way ensure both got the same version, though.
}