hadean-zig/build.zig

94 lines
2.7 KiB
Zig
Raw Permalink Normal View History

2024-08-21 15:57:18 -04:00
const std = @import("std");
pub fn build(b: *std.Build) void {
2025-01-02 05:28:40 -05:00
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
2025-02-15 06:17:46 -05:00
// === [ C IMPORTS ] ===
2025-01-02 05:28:40 -05:00
const c = b.addModule("c", .{
.root_source_file = b.path("src/c.zig"),
.target = target,
.optimize = optimize,
2024-08-21 15:57:18 -04:00
});
2025-01-02 05:28:40 -05:00
c.linkSystemLibrary("SDL3", .{});
c.addIncludePath(b.path("open-simplex/include"));
c.linkSystemLibrary("SDL3_image", .{});
2025-02-15 06:17:46 -05:00
// === [ ENGINE ] ===
2025-01-02 05:28:40 -05:00
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);
2025-02-15 06:17:46 -05:00
// === [ 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 ] ===
2025-01-02 05:28:40 -05:00
const exe = b.addExecutable(.{
.name = "hadean",
2025-02-15 06:17:46 -05:00
.root_source_file = b.path("src/main.zig"),
2025-01-02 05:28:40 -05:00
.target = target,
.optimize = optimize,
2024-09-03 13:13:28 -04:00
});
2025-02-15 06:17:46 -05:00
2025-01-02 05:28:40 -05:00
exe.root_module.addImport("engine", engine);
2025-02-15 06:17:46 -05:00
exe.root_module.addImport("hadean", hadean);
2025-01-02 05:28:40 -05:00
exe.root_module.addImport("c", c);
exe.addCSourceFile(.{ .file = b.path("open-simplex/src/OpenSimplex2F.c") });
2024-09-03 13:13:28 -04:00
exe.addIncludePath(b.path("open-simplex/include"));
2024-08-21 15:57:18 -04:00
exe.linkLibC();
2025-01-02 05:28:40 -05:00
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);
2025-02-15 06:17:46 -05:00
2025-01-02 05:28:40 -05:00
b.installArtifact(exe);
2025-02-15 06:17:46 -05:00
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);
2024-08-21 15:57:18 -04:00
2025-01-02 05:28:40 -05:00
// 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.
2024-08-21 15:57:18 -04:00
}