const std = @import("std");
const vkgen = @import("vulkan-zig");

pub fn build(b: *std.Build) void {
    const target = b.standardTargetOptions(.{});
    const optimize = b.standardOptimizeOption(.{
        // .preferred_optimize_mode = .ReleaseSafe,
    });

    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", .{});

    // nu.linkSystemLibrary("glfw3", .{
    //     .needed = true,
    //     .preferred_link_mode = .static,
    //     .use_pkg_config = .force,
    // });

    const exe = b.addExecutable(.{
        .name = "scratchzig",
        .root_source_file = b.path("src/main.zig"),
        .target = target,
        .optimize = optimize,
    });
    // exe.root_module.addImport("nu", nu);
    exe.root_module.addImport("vk", vkmod);
    exe.root_module.addImport("cimgui", cimgui.module("cimgui"));
    exe.root_module.linkSystemLibrary("glfw3", .{
        .needed = true,
        .preferred_link_mode = .static,
        .use_pkg_config = .force,
    });
    exe.linkLibC();

    const shaders = vkgen.ShaderCompileStep.create(
        b,
        &[_][]const u8{ "glslc", "--target-env=vulkan1.3" },
        "-o",
    );
    shaders.add("triangle_vert", "src/shaders/triangle.vert", .{});
    shaders.add("triangle_frag", "src/shaders/triangle.frag", .{});
    exe.root_module.addImport("shaders", shaders.getModule());

    b.installArtifact(exe);

    const run_cmd = b.addRunArtifact(exe);
    run_cmd.step.dependOn(b.getInstallStep());

    if (b.args) |args| {
        run_cmd.addArgs(args);
    }

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

    // const devel_step = b.step("dev", "Build development tools and test runners");
    // devel_step.dependOn(&nu_test_runner.step);
}
