diff options
Diffstat (limited to 'examples/live/build.zig')
| -rw-r--r-- | examples/live/build.zig | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/examples/live/build.zig b/examples/live/build.zig new file mode 100644 index 0000000..cc93612 --- /dev/null +++ b/examples/live/build.zig @@ -0,0 +1,43 @@ +const std = @import("std"); +const sketchbook = @import("sketchbook"); +const Lang = @import("src/Lang.zig"); + +pub fn build(b: *std.Build) void { + const target = b.standardTargetOptions(.{}); + const optimize = b.standardOptimizeOption(.{}); + const sb = sketchbook.init(b, .{ .target = target, .optimize = optimize }); + + // The interpreter's op numbers, from Lang.Op: one definition. + const ops = b.addWriteFiles(); + _ = ops.add("ops.glsl", comptime blk: { + var glsl: []const u8 = "// Generated from Lang.Op by build.zig; do not edit.\n"; + for (std.enums.values(Lang.Op)) |op| glsl = glsl ++ std.fmt.comptimePrint("const uint OP_{t} = {d}u;\n", .{ op, @intFromEnum(op) }); + break :blk glsl; + }); + const lang = b.createModule(.{ .root_source_file = b.path("src/Lang.zig") }); + const shaders = sb.addShaders(.{ + .layouts = .{ .module = lang, .types = &.{ "Picture", "Synth" } }, + .include_dirs = &.{ops.getDirectory()}, + .sources = &.{ + b.path("shaders/fullscreen.vert"), + b.path("shaders/picture.frag"), + b.path("shaders/synth.comp"), + }, + }); + const imports: []const std.Build.Module.Import = &.{ + .{ .name = "Lang", .module = lang }, + .{ .name = "shaders", .module = shaders.module }, + }; + + // The interpreter's GPU time over made-up tapes (`--profile-gpu`). + const probe = sb.app(.{ .name = "live-probe", .root_source_file = b.path("src/probe.zig"), .imports = imports }); + const run_probe = b.addRunArtifact(probe.addExecutable()); + run_probe.addArgs(&.{ "--headless", "--fresh", "--profile-gpu", "--script" }); + run_probe.addFileArg(b.path("test/probe.script")); + run_probe.addArg("--state"); + _ = run_probe.addOutputFileArg("probe.xitdb"); + run_probe.setCwd(b.path(".")); + run_probe.stdio = .inherit; + run_probe.has_side_effects = true; + b.step("probe", "Time the interpreter on the GPU over made-up tapes").dependOn(&run_probe.step); +} |
