70
build.zig
70
build.zig
@@ -1,30 +1,25 @@
|
||||
const std = @import("std");
|
||||
const vkgen = @import("vulkan-zig");
|
||||
const glfw_util = @import("glfw");
|
||||
|
||||
pub fn build(b: *std.Build) void {
|
||||
const target = b.standardTargetOptions(.{});
|
||||
const optimize = b.standardOptimizeOption(.{});
|
||||
|
||||
const glfw_dep = b.dependency("glfw", .{});
|
||||
glfw_util.install(glfw_dep, b);
|
||||
const optimize = b.standardOptimizeOption(.{});
|
||||
|
||||
const vk = b.dependency("vulkan-zig", .{
|
||||
.registry = @as([]const u8, b.pathFromRoot("reg/vk.xml")),
|
||||
});
|
||||
const vkmod = vk.module("vulkan-zig");
|
||||
|
||||
const cimgui = b.dependency("cimgui", .{});
|
||||
|
||||
const exe = b.addExecutable(.{
|
||||
.name = "zig-glfw-vulkan",
|
||||
.name = "scratchzig",
|
||||
.root_source_file = b.path("src/main.zig"),
|
||||
.target = target,
|
||||
.optimize = optimize,
|
||||
});
|
||||
exe.root_module.addImport("vk", vk.module("vulkan-zig"));
|
||||
exe.root_module.addImport("cimgui", cimgui.module("cimgui"));
|
||||
glfw_util.link(glfw_dep, exe);
|
||||
b.installArtifact(exe);
|
||||
|
||||
const shaders = vkgen.ShaderCompileStep.create(
|
||||
b,
|
||||
@@ -35,6 +30,18 @@ pub fn build(b: *std.Build) void {
|
||||
shaders.add("triangle_frag", "src/shaders/triangle.frag", .{});
|
||||
exe.root_module.addImport("shaders", shaders.getModule());
|
||||
|
||||
// this requires PKG_CONFIG_PATH to be set. something like:
|
||||
// ~/.local/lib/pkgconfig/
|
||||
exe.linkSystemLibrary2("glfw3", .{
|
||||
.needed = true,
|
||||
.preferred_link_mode = .static,
|
||||
.use_pkg_config = .force,
|
||||
});
|
||||
exe.linkLibC();
|
||||
exe.root_module.addImport("vk", vkmod);
|
||||
|
||||
b.installArtifact(exe);
|
||||
|
||||
const run_cmd = b.addRunArtifact(exe);
|
||||
run_cmd.step.dependOn(b.getInstallStep());
|
||||
|
||||
@@ -44,4 +51,51 @@ pub fn build(b: *std.Build) void {
|
||||
|
||||
const run_step = b.step("run", "Run the app");
|
||||
run_step.dependOn(&run_cmd.step);
|
||||
|
||||
const exe_unit_tests = b.addTest(.{
|
||||
.root_source_file = b.path("src/main.zig"),
|
||||
.target = target,
|
||||
.optimize = optimize,
|
||||
});
|
||||
exe_unit_tests.linkSystemLibrary2("glfw3", .{
|
||||
.needed = true,
|
||||
.preferred_link_mode = .static,
|
||||
.use_pkg_config = .force,
|
||||
});
|
||||
exe_unit_tests.linkLibC();
|
||||
const run_exe_unit_tests = b.addRunArtifact(exe_unit_tests);
|
||||
|
||||
const dsa_unit_tests = b.addTest(.{
|
||||
.name = "dsa.zig tests",
|
||||
.root_source_file = b.path("src/dsa.zig"),
|
||||
.target = target,
|
||||
.optimize = optimize,
|
||||
});
|
||||
const run_dsa_unit_tests = b.addRunArtifact(dsa_unit_tests);
|
||||
|
||||
const test_step = b.step("test", "Run unit tests");
|
||||
test_step.dependOn(&run_exe_unit_tests.step);
|
||||
test_step.dependOn(&run_dsa_unit_tests.step);
|
||||
|
||||
const inspect = b.addExecutable(.{
|
||||
.name = "vkinspect",
|
||||
.root_source_file = b.path("src/inspect.zig"),
|
||||
.target = target,
|
||||
.optimize = optimize,
|
||||
});
|
||||
inspect.linkSystemLibrary2("vulkan", .{
|
||||
.needed = true,
|
||||
.preferred_link_mode = .dynamic,
|
||||
});
|
||||
inspect.linkSystemLibrary2("glfw3", .{
|
||||
.needed = true,
|
||||
.preferred_link_mode = .static,
|
||||
.use_pkg_config = .force,
|
||||
});
|
||||
exe_unit_tests.linkLibC();
|
||||
inspect.root_module.addImport("vk", vkmod);
|
||||
inspect.linkLibC();
|
||||
const run_inspect = b.addRunArtifact(inspect);
|
||||
const inspect_step = b.step("vki", "Vulkan Inspect");
|
||||
inspect_step.dependOn(&run_inspect.step);
|
||||
}
|
||||
|
Reference in New Issue
Block a user