diff options
Diffstat (limited to 'build.zig')
| -rw-r--r-- | build.zig | 34 |
1 files changed, 34 insertions, 0 deletions
@@ -4,6 +4,11 @@ pub fn build(b: *std.Build) void { const optimize = b.standardOptimizeOption(.{}); const target = b.standardTargetOptions(.{}); + // build-time IO, only used to slurp the grammars' highlights.scm queries. + var threaded: std.Io.Threaded = .init(b.allocator, .{}); + defer threaded.deinit(); + const io = threaded.io(); + // -Dtrace: make the e2e runner print the captured screen state (after each // pump/waitFor and on every assertion) so failures can be inspected live. // Usage: `zig build test -Dtrace`. @@ -90,6 +95,35 @@ pub fn build(b: *std.Build) void { const zstbi_mod = b.dependency("zstbi", .{ .target = target, .optimize = optimize }).module("root"); exe.root_module.addImport("zstbi", zstbi_mod); + // tree-sitter syntax highlighting for file panes: the Zig bindings + C runtime + // (the `tree-sitter` module), each grammar's parser.c linked as a static lib, + // and its highlights.scm read at build time into the `ts_queries` options module. + const tree_sitter = b.dependency("tree_sitter", .{ .target = target, .optimize = optimize }); + exe.root_module.addImport("tree-sitter", tree_sitter.module("tree_sitter")); + + const grammars = .{ + .{ "c", "ts_c", false }, + .{ "rust", "ts_rust", true }, + .{ "zig", "ts_zig", false }, + }; + const ts_queries = b.addOptions(); + inline for (grammars) |g| { + const dep = b.dependency(g[1], .{}); + const query = std.Io.Dir.cwd().readFileAlloc(io, dep.path("queries/highlights.scm").getPath(b), b.allocator, .limited(0x100000)) catch @panic("read " ++ g[0] ++ " highlights"); + ts_queries.addOption([]const u8, g[0] ++ "_highlights", query); + + const lib = b.addLibrary(.{ + .name = "tree-sitter-" ++ g[0], + .root_module = b.createModule(.{ .target = target, .optimize = optimize, .link_libc = true }), + .linkage = .static, + }); + lib.root_module.addCSourceFile(.{ .file = dep.path("src/parser.c") }); + if (g[2]) lib.root_module.addCSourceFile(.{ .file = dep.path("src/scanner.c") }); + lib.root_module.addIncludePath(dep.path("src")); + exe.root_module.linkLibrary(lib); + } + exe.root_module.addOptions("ts_queries", ts_queries); + // Install the exe so `zig build` (and `zig build install`) produces it in // zig-out/bin for global install, not just as a hidden dep of `run`/`test`. b.installArtifact(exe); |
