133 lines
3.6 KiB
Zig
133 lines
3.6 KiB
Zig
const std = @import("std");
|
|
|
|
const CommonArgs = struct {
|
|
target: std.Build.ResolvedTarget,
|
|
optimize: std.builtin.OptimizeMode,
|
|
ona_module: *std.Build.Module,
|
|
};
|
|
|
|
pub fn build(b: *std.Build) void {
|
|
const target = b.standardTargetOptions(.{});
|
|
const optimize = b.standardOptimizeOption(.{});
|
|
|
|
const coral_module = b.addModule("coral", .{
|
|
.root_source_file = b.path("src/coral/coral.zig"),
|
|
.target = target,
|
|
.optimize = optimize,
|
|
});
|
|
|
|
const ext_module = b.createModule(.{
|
|
.root_source_file = b.path("src/ext/ext.zig"),
|
|
.target = target,
|
|
.optimize = optimize,
|
|
.link_libc = true,
|
|
});
|
|
|
|
ext_module.linkSystemLibrary("SDL3", .{
|
|
.needed = true,
|
|
.preferred_link_mode = .dynamic,
|
|
});
|
|
|
|
const ona_module = b.addModule("ona", .{
|
|
.root_source_file = b.path("src/ona/ona.zig"),
|
|
.target = target,
|
|
.optimize = optimize,
|
|
.link_libc = true,
|
|
|
|
.imports = &.{
|
|
.{
|
|
.name = "ext",
|
|
.module = ext_module,
|
|
},
|
|
.{
|
|
.name = "coral",
|
|
.module = coral_module,
|
|
},
|
|
},
|
|
});
|
|
|
|
scan_demos(b, .{
|
|
.target = target,
|
|
.optimize = optimize,
|
|
.ona_module = ona_module,
|
|
});
|
|
|
|
const test_tests = b.addTest(.{
|
|
.root_module = b.createModule(.{
|
|
.root_source_file = b.path("src/tests.zig"),
|
|
.target = target,
|
|
.optimize = optimize,
|
|
|
|
.imports = &.{
|
|
.{
|
|
.name = "coral",
|
|
.module = coral_module,
|
|
},
|
|
},
|
|
}),
|
|
});
|
|
|
|
const test_step = b.step("test", "Run unit tests");
|
|
|
|
test_step.dependOn(&b.addRunArtifact(test_tests).step);
|
|
test_step.dependOn(&b.addInstallArtifact(test_tests, .{}).step);
|
|
}
|
|
|
|
fn scan_demos(b: *std.Build, common: CommonArgs) void {
|
|
const build_demos_step = b.step("demos", "Build demos");
|
|
|
|
b.default_step.dependOn(build_demos_step);
|
|
|
|
const cwd = std.fs.cwd();
|
|
|
|
var demos_dir = cwd.openDir("src/demos/", .{ .iterate = true }) catch {
|
|
return build_demos_step.dependOn(&b.addFail("failed to open demo files directory").step);
|
|
};
|
|
|
|
defer {
|
|
demos_dir.close();
|
|
}
|
|
|
|
var demos_iterator = demos_dir.iterate();
|
|
|
|
while (demos_iterator.next() catch {
|
|
return build_demos_step.dependOn(&b.addFail("failed to iterate over next entry in demos directory").step);
|
|
}) |entry| {
|
|
if (entry.kind != .file) {
|
|
continue;
|
|
}
|
|
|
|
if (!std.mem.eql(u8, std.fs.path.extension(entry.name), ".zig")) {
|
|
continue;
|
|
}
|
|
|
|
const demo_executable = b.addExecutable(.{
|
|
.name = std.fmt.allocPrint(b.allocator, "{s}_demo", .{std.fs.path.stem(entry.name)}) catch {
|
|
return build_demos_step.dependOn(&b.addFail("failed to allocate demo name buffer").step);
|
|
},
|
|
|
|
.root_module = b.createModule(.{
|
|
.root_source_file = b.path(b.pathJoin(&.{ "src/demos/", entry.name })),
|
|
.target = common.target,
|
|
.optimize = common.optimize,
|
|
|
|
.imports = &.{
|
|
.{
|
|
.name = "ona",
|
|
.module = common.ona_module,
|
|
},
|
|
},
|
|
}),
|
|
});
|
|
|
|
demo_executable.linkSystemLibrary2("SDL3", .{
|
|
.needed = true,
|
|
.preferred_link_mode = .dynamic,
|
|
});
|
|
|
|
const demo_installation = b.addInstallArtifact(demo_executable, .{});
|
|
|
|
build_demos_step.dependOn(&demo_installation.step);
|
|
}
|
|
}
|