const std = @import("std"); const bh = @import("bh"); pub fn addShaderDefinition( b: *std.Build, comptime sdl3Path: []const u8, target: std.Build.ResolvedTarget, optimize: std.builtin.OptimizeMode, shaderName: []const u8, jsonPath: std.Build.LazyPath, ) *std.Build.Module { // Create the spvReflect2 executable const spvReflect = b.addExecutable(.{ .name = "spvReflect2", .root_module = b.createModule(.{ .target = b.graph.host, .optimize = optimize, .root_source_file = b.path(sdl3Path ++ "/spvreflect/spvReflect2.zig"), }), }); // Run the spvReflect2 executable const runReflect = b.addRunArtifact(spvReflect); runReflect.addFileArg(jsonPath); const reflectedZigOut = runReflect.addOutputFileArg(b.fmt("reflected/{s}.zig", .{shaderName})); const module = b.createModule(.{ .root_source_file = reflectedZigOut, .optimize = optimize }); const dep = b.dependency("shaderTypes", .{ .target = target, .optimize = optimize, }); module.addImport("shaderTypes", dep.module("shaderTypes")); return module; } pub fn shaderDefintion( b: *std.Build, module: *std.Build.Module, comptime sdl3Path: []const u8, target: std.Build.ResolvedTarget, optimize: std.builtin.OptimizeMode, shaderName: []const u8, jsonPath: std.Build.LazyPath, ) void { const mod = addShaderDefinition(b, sdl3Path, target, optimize, shaderName, jsonPath); module.addImport(shaderName, mod); } pub fn build(b: *std.Build) void { const opts = bh.declareOptions(b); const preferred_linkage: std.builtin.LinkMode = if (opts.static_build) .static else .dynamic; const sdl_dep = b.dependency("sdl", .{ .target = opts.target, .optimize = opts.optimize, .preferred_linkage = preferred_linkage, }); const sdl3_lib = sdl_dep.artifact("SDL3"); const sdl3_fwd = b.addModule("SDL3", .{ .target = opts.target, .optimize = opts.optimize, .root_source_file = b.path("src/sdl3_lib_fwd.zig"), }); sdl3_fwd.linkLibrary(sdl3_lib); const mod = b.addModule("sdl3", .{ .target = opts.target, .optimize = opts.optimize, .root_source_file = b.path("src/sdl3.zig"), }); const shaderTypes = b.dependency("shaderTypes", .{ .target = opts.target, .optimize = opts.optimize, }); mod.addImport("shaderTypes", shaderTypes.module("shaderTypes")); mod.addIncludePath(b.path("SDL/include")); mod.linkLibrary(sdl3_lib); const test_step2 = b.step("test", "run unit tests for sdl3"); const tests2 = b.addExecutable(.{ .name = "hello-sdl", .root_module = b.createModule(.{ .target = opts.target, .optimize = opts.optimize, .root_source_file = b.path("src/samples/compiletest.zig"), .link_libc = true, }), }); const test_step = b.step("test-triangle", "run unit tests for sdl3"); const tests = b.addExecutable(.{ .name = "hello-triangle", .root_module = b.createModule(.{ .target = opts.target, .optimize = opts.optimize, .root_source_file = b.path("src/samples/hello-triangle.zig"), .link_libc = true, }), }); const hello_window = b.step("hello-window", "test window"); const hello_window_exe = b.addExecutable(.{ .name = "hello-window", .root_module = b.createModule(.{ .target = opts.target, .optimize = opts.optimize, .root_source_file = b.path("src/samples/hello-window.zig"), .link_libc = true, }), }); hello_window.dependOn(&hello_window_exe.step); hello_window_exe.root_module.addImport("sdl3", mod); tests.root_module.addImport("sdl3", mod); const vertexDefinitions = addShaderDefinition(b, ".", opts.target, opts.optimize, "hello-triangle.vert", b.path("content/hello-triangle.vert.json")); tests.root_module.addImport("hello-triangle.vert", vertexDefinitions); const runArtifact = b.addRunArtifact(tests); test_step.dependOn(&runArtifact.step); const runArtifact2 = b.addRunArtifact(tests2); test_step2.dependOn(&runArtifact2.step); b.installArtifact(hello_window_exe); b.installArtifact(sdl3_lib); b.installArtifact(tests); b.installArtifact(tests2); }