summaryrefslogtreecommitdiff
path: root/build.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-06-30 15:32:56 -0300
committerGabriel Schneider <[email protected]>2026-06-30 17:43:21 -0300
commit1f65d7368c9a31427b145f683eb891da16181b73 (patch)
tree88a3754e7d01906098af82335b84edb8754f31ca /build.zig
parenta68564e9fb9fb8be6d997db5e6ad9148fb506d18 (diff)
downloadpardes-1f65d7368c9a31427b145f683eb891da16181b73.tar.gz
pardes-1f65d7368c9a31427b145f683eb891da16181b73.zip
merging the colors into
Diffstat (limited to 'build.zig')
-rw-r--r--build.zig34
1 files changed, 34 insertions, 0 deletions
diff --git a/build.zig b/build.zig
index 88d2123a..d5bba19a 100644
--- a/build.zig
+++ b/build.zig
@@ -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);