1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
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, @backingInt(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 },
.{ .name = "scope", .module = sb.modules.scope },
};
// The editor: helix's keys over a value kept in State. Its tree-sitter
// set is the smallest there is (Zig's grammar), as the language's own
// grammar is handed in at run time.
const pardes = b.dependency("pardes", .{ .target = target, .optimize = optimize, .@"tree-sitter" = .zig, .editor = true });
const app = sb.app(.{ .name = "live", .root_source_file = b.path("src/main.zig"), .imports = &.{
.{ .name = "Lang", .module = lang },
.{ .name = "shaders", .module = shaders.module },
.{ .name = "scope", .module = sb.modules.scope },
.{ .name = "pardes-editor", .module = pardes.module("pardes-editor") },
} });
// The language's tree-sitter grammar: grammar/grammar.js and the
// parser.c generated from it, committed (the build never runs the
// generator); its colours and a new line's indent, queries/.
const grammar = b.addLibrary(.{ .name = "tree-sitter-live", .linkage = .static, .root_module = b.createModule(.{ .target = target, .optimize = .ReleaseFast, .link_libc = true, .pic = true }) });
grammar.root_module.addCSourceFile(.{ .file = b.path("grammar/src/parser.c") });
grammar.root_module.addIncludePath(b.path("grammar/src"));
app.module.linkLibrary(grammar);
app.module.addAnonymousImport("highlights.scm", .{ .root_source_file = b.path("queries/highlights.scm") });
app.module.addAnonymousImport("indents.scm", .{ .root_source_file = b.path("queries/indents.scm") });
const steps = app.addSteps(.{ .scripts = &.{ b.path("test/live.script"), b.path("test/story.script") }, .tests = &.{b.path("test/grammar.zig")} });
const lang_test = b.addTest(.{ .root_module = b.createModule(.{ .root_source_file = b.path("src/Lang.zig"), .target = target, .optimize = optimize }) });
steps.test_step.dependOn(&b.addRunArtifact(lang_test).step);
// 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);
}
|