NYXGFX/build.zig
2026-08-11 21:26:15 +01:00

111 lines
2.9 KiB
Zig

const std = @import("std");
pub fn build(b: *std.Build) !void {
// --- TARGET ---
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
// --- MOD ---
const mod = b.addModule("NYXGFX", .{
.root_source_file = b.path("src/gfx.zig"),
.target = target,
.optimize = optimize,
});
const mod_tests = b.addTest(.{
.root_module = mod,
});
const run_mod_tests = b.addRunArtifact(mod_tests);
const test_step = b.step("test", "Run tests");
test_step.dependOn(&run_mod_tests.step);
//
// DEPENDANCIES
//
const gtl = b.dependency("gtl", .{
.target = target,
.optimize = optimize,
});
mod.addImport("gtl", gtl.module("gtl"));
const math = b.dependency("NYXMath", .{
.target = target,
.optimize = optimize,
});
mod.addImport("math", math.module("NYXMath"));
//
// SYSTEM DEPENDENCIES
//
const vulkan = b.addTranslateC(.{
.target = target,
.optimize = optimize,
.root_source_file = b.path("./src/vendor/vulkan/vulkan.h"),
});
mod.addImport("vulkan", vulkan.createModule());
mod.linkSystemLibrary("vulkan", .{});
//
// EXAMPLES
//
inline for ([_]struct {
name: []const u8,
src: []const u8,
}{
.{ .name = "simple", .src = "examples/simple/simple.zig" },
}) |excfg| {
const ex_name = excfg.name;
const ex_src = excfg.src;
const ex_build_desc = try std.fmt.allocPrint(
b.allocator,
"build the {s} example",
.{ex_name},
);
const ex_run_stepname = try std.fmt.allocPrint(
b.allocator,
"run-{s}",
.{ex_name},
);
const ex_run_stepdesc = try std.fmt.allocPrint(
b.allocator,
"run the {s} example",
.{ex_name},
);
const example_run_step = b.step(ex_run_stepname, ex_run_stepdesc);
const example_step = b.step(ex_name, ex_build_desc);
const exe_mod = b.addModule(ex_name, .{
.root_source_file = b.path(ex_src),
.target = target,
.optimize = optimize,
});
var example = b.addExecutable(.{
.name = ex_name,
.root_module = exe_mod,
});
example.root_module.addImport("gfx", mod);
const sdl = b.addTranslateC(.{
.target = target,
.optimize = optimize,
.root_source_file = b.path("examples/vendor/sdl3.h"),
});
example.root_module.addImport("sdl", sdl.createModule());
example.root_module.linkSystemLibrary("SDL3", .{});
const example_run = b.addRunArtifact(example);
example_run_step.dependOn(&example_run.step);
const example_build_step = b.addInstallArtifact(example, .{});
example_step.dependOn(&example_build_step.step);
}
}