git.s-ol.nu openxPriments / main build.zig
main

Tree @main (Download .tar.gz)

build.zig @mainraw · history · blame

const std = @import("std");
const vkgen = @import("lib/vulkan/generator/index.zig");
const xrgen = @import("lib/openxr/generator/index.zig");
const dggen = @import("lib/diligent/index.zig");
const Step = std.build.Step;
const Builder = std.build.Builder;

pub fn build(b: *Builder) void {
    const target = b.standardTargetOptions(.{});
    const mode = b.standardReleaseOptions();

    const exe = b.addExecutable("openxPriments", "src/main.zig");
    exe.setTarget(target);
    exe.setBuildMode(mode);
    exe.install();
    exe.linkSystemLibrary("c");
    exe.linkSystemLibrary("vulkan");
    exe.linkSystemLibrary("openxr_loader");
    exe.linkSystemLibrary("GraphicsEngineVk");
    exe.linkSystemLibrary("DiligentCore");
    exe.linkSystemLibrary("DiligentTools");
    exe.linkSystemLibrary("DiligentFX");

    exe.addPackagePath("glm", "lib/glm/glm.zig");

    const gen_dg = dggen.DgGenerateStep.init(b, "lib/DiligentEngine", "dg.zig");
    gen_dg.addDeps(exe, "Debug");

    const vk_xml_path = b.option([]const u8, "vulkan-registry", "Override the path to the Vulkan registry") orelse "res/vk.xml";
    const gen_vk = vkgen.VkGenerateStep.init(b, vk_xml_path, "vk.zig");
    exe.step.dependOn(&gen_vk.step);
    exe.addPackage(gen_vk.package);

    const xr_xml_path = b.option([]const u8, "openxr-registry", "Override the path to the OpenXR registry") orelse "res/xr.xml";
    const gen_xr = xrgen.XrGenerateStep.init(b, xr_xml_path, "xr.zig");
    const dep_list = [_]std.build.Pkg{gen_vk.package};
    gen_xr.package.dependencies = dep_list[0..];
    exe.step.dependOn(&gen_xr.step);
    exe.addPackage(gen_xr.package);

    const run_cmd = exe.run();
    run_cmd.step.dependOn(b.getInstallStep());
    const run_step = b.step("run", "Run the example example");
    run_step.dependOn(&run_cmd.step);

    const renderdoc = b.option(bool, "renderdoc", "Enable Renderdoc debugging") orelse false;
    exe.addBuildOption(bool, "renderdoc", renderdoc);
    if (renderdoc) {
        exe.linkSystemLibrary("renderdoc");
        run_cmd.setEnvironmentVariable("VK_INSTANCE_LAYERS", "VK_LAYER_RENDERDOC_Capture");
    }
}