NYXGFX/build.zig

200 lines
6 KiB
Zig
Raw Permalink Normal View History

2026-08-09 14:17:49 +01:00
const std = @import("std");
2026-08-11 21:26:15 +01:00
pub fn build(b: *std.Build) !void {
2026-08-09 14:17:49 +01:00
// --- 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,
.link_libc = true,
.link_libcpp = true,
2026-08-09 14:17:49 +01:00
});
const mod_tests = b.addTest(.{
.root_module = mod,
.use_lld = true,
.use_llvm = true,
2026-08-09 14:17:49 +01:00
});
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"));
2026-08-11 21:06:28 +01:00
const math = b.dependency("NYXMath", .{
.target = target,
.optimize = optimize,
});
mod.addImport("math", math.module("NYXMath"));
2026-08-09 14:17:49 +01:00
//
// SYSTEM DEPENDENCIES
//
const vulkan_headers = b.dependency("vulkan_headers", .{});
2026-08-09 14:17:49 +01:00
const vulkan = b.addTranslateC(.{
.target = target,
.optimize = optimize,
.root_source_file = b.path("src/vendor/vulkan/vulkan.h"),
2026-08-09 14:17:49 +01:00
});
vulkan.addIncludePath(vulkan_headers.path("include"));
2026-08-09 14:17:49 +01:00
mod.addImport("vulkan", vulkan.createModule());
mod.linkSystemLibrary("vulkan", .{});
2026-08-11 21:26:15 +01:00
2026-08-12 14:52:27 +01:00
const stb_image = b.addTranslateC(.{
.target = target,
.optimize = optimize,
.root_source_file = b.path("./src/vendor/stb_image/stb_image.h"),
});
mod.addImport("stb_image", stb_image.createModule());
mod.addCSourceFile(.{ .file = b.path("src/vendor/stb_image/stb_image.c") });
2026-08-12 20:31:05 +01:00
const fast_obj = b.addTranslateC(.{
.target = target,
.optimize = optimize,
.root_source_file = b.path("./src/vendor/fast_obj/fast_obj.h"),
});
mod.addImport("fast_obj", fast_obj.createModule());
mod.addCSourceFiles(.{ .files = &.{"src/vendor/fast_obj/fast_obj.c"} });
const check_step = b.step("check", "Check if compiles");
2026-08-11 21:26:15 +01:00
//
// EXAMPLES
//
inline for ([_]struct {
name: []const u8,
src: []const u8,
}{
.{ .name = "simple", .src = "examples/simple/simple.zig" },
2026-08-12 20:31:05 +01:00
.{ .name = "3D", .src = "examples/simple_3D/simple_3D.zig" },
.{ .name = "imgui", .src = "examples/imgui/imgui.zig" },
2026-08-11 21:26:15 +01:00
}) |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,
.link_libc = true,
.link_libcpp = true,
2026-08-11 21:26:15 +01:00
});
var example = b.addExecutable(.{
.name = ex_name,
.root_module = exe_mod,
.use_lld = true,
.use_llvm = true,
2026-08-11 21:26:15 +01:00
});
example.root_module.addImport("gfx", mod);
const common = b.addModule("common", .{
.root_source_file = b.path("examples/common.zig"),
});
example.root_module.addImport("common", common);
2026-08-11 21:26:15 +01:00
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", .{});
2026-08-12 20:31:05 +01:00
const example_math = b.dependency("NYXMath", .{
.target = target,
.optimize = optimize,
});
example.root_module.addImport("math", example_math.module("NYXMath"));
example.root_module.addIncludePath(b.path("examples/vendor/imgui"));
example.root_module.addCSourceFiles(.{
.root = b.path("examples/vendor/imgui"),
.files = &.{
"dcimgui.cpp",
"dcimgui_internal.cpp",
"dcimgui_impl_sdl3.cpp",
"dcimgui_impl_vulkan.cpp",
"imgui.cpp",
"imgui_demo.cpp",
"imgui_draw.cpp",
"imgui_tables.cpp",
"imgui_widgets.cpp",
"imgui_impl_sdl3.cpp",
"imgui_impl_vulkan.cpp",
},
.language = .cpp,
.flags = &.{"-std=c++17"},
});
const imgui = b.addTranslateC(.{
.target = target,
.optimize = optimize,
.root_source_file = b.path("examples/vendor/imgui/dcimgui.h"),
});
example.root_module.addImport("imgui", imgui.createModule());
const imgui_impl_sdl3 = b.addTranslateC(.{
.target = target,
.optimize = optimize,
.root_source_file = b.path("examples/vendor/imgui/dcimgui_impl_sdl3.h"),
});
example.root_module.addImport("imgui_impl_sdl3", imgui_impl_sdl3.createModule());
const imgui_impl_vulkan = b.addTranslateC(.{
.target = target,
.optimize = optimize,
.root_source_file = b.path("examples/vendor/imgui/dcimgui_impl_vulkan.h"),
});
example.root_module.addImport("imgui_impl_vulkan", imgui_impl_vulkan.createModule());
2026-08-11 21:26:15 +01:00
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);
2026-08-12 14:52:27 +01:00
check_step.dependOn(&example.step);
2026-08-11 21:26:15 +01:00
}
2026-08-09 14:17:49 +01:00
}