ona/build.zig

60 lines
1.6 KiB
Zig
Raw Normal View History

2022-08-10 15:52:16 +02:00
const std = @import("std");
2022-10-17 11:34:04 +02:00
///
/// Builds the engine, tools, and dependencies of all.
///
2022-08-10 15:52:16 +02:00
pub fn build(builder: *std.build.Builder) void {
const target = builder.standardTargetOptions(.{});
const mode = builder.standardReleaseOptions();
2022-10-17 11:34:04 +02:00
const ona_pkg = projectPkg("ona", &.{});
2022-08-10 15:52:16 +02:00
2022-10-17 11:34:04 +02:00
// Engine executable.
2022-08-10 15:52:16 +02:00
{
2022-10-17 11:34:04 +02:00
const engine_exe = builder.addExecutable("ona", "./src/engine/main.zig");
const oar_pkg = projectPkg("oar", &.{ona_pkg});
2022-08-10 15:52:16 +02:00
2022-10-17 11:34:04 +02:00
engine_exe.addPackage(oar_pkg);
engine_exe.addPackage(ona_pkg);
engine_exe.setTarget(target);
engine_exe.setBuildMode(mode);
engine_exe.install();
engine_exe.addIncludeDir("./ext");
engine_exe.linkSystemLibrary("SDL2");
engine_exe.linkLibC();
2022-08-10 15:52:16 +02:00
2022-10-17 11:34:04 +02:00
const run_cmd = engine_exe.run();
2022-08-10 15:52:16 +02:00
run_cmd.step.dependOn(builder.getInstallStep());
if (builder.args) |args| run_cmd.addArgs(args);
builder.step("run", "Run Ona application").dependOn(&run_cmd.step);
}
2022-10-17 11:34:04 +02:00
// Oar executable.
{
}
2022-08-10 15:52:16 +02:00
// Ona tests.
{
const ona_tests = builder.addTestExe("test", "./src/main.zig");
2022-08-10 15:52:16 +02:00
ona_tests.setTarget(target);
ona_tests.setBuildMode(mode);
builder.step("test", "Run Ona unit tests").dependOn(&ona_tests.step);
}
}
2022-10-17 11:34:04 +02:00
///
/// Returns a [std.build.Pkg] within the project codebase path at `name` with `dependencies` as its
/// dependencies.
///
fn projectPkg(comptime name: []const u8, dependencies: []const std.build.Pkg) std.build.Pkg {
return std.build.Pkg{
.name = name,
.path = .{.path = "./src/" ++ name ++ "/main.zig"},
.dependencies = dependencies,
};
}