diff options
| author | Gabriel Schneider <[email protected]> | 2026-06-21 22:07:17 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-06-21 22:20:49 -0300 |
| commit | fb3a18c59c6e21892762c3e22af8e0011e5eb2eb (patch) | |
| tree | 887551cb80a9b46f62dddcb84ab8ae31807cc025 /build.zig | |
| parent | ef5b907d3077c1d00e5468f3b3c4935b3f51b923 (diff) | |
| download | pardes-fb3a18c59c6e21892762c3e22af8e0011e5eb2eb.tar.gz pardes-fb3a18c59c6e21892762c3e22af8e0011e5eb2eb.zip | |
treesitter vibes?
Diffstat (limited to 'build.zig')
| -rw-r--r-- | build.zig | 65 |
1 files changed, 65 insertions, 0 deletions
@@ -3,6 +3,9 @@ const std = @import("std"); pub fn build(b: *std.Build) void { const optimize = b.standardOptimizeOption(.{}); const target = b.standardTargetOptions(.{}); + var threaded: std.Io.Threaded = .init(b.allocator, .{}); + defer threaded.deinit(); + const io = threaded.io(); const exe = b.addExecutable(.{ .name = "pardes", @@ -10,6 +13,7 @@ pub fn build(b: *std.Build) void { .target = target, .optimize = optimize, .root_source_file = b.path("main.zig"), + .link_libc = true, }), }); const tests = b.addExecutable(.{ @@ -73,6 +77,67 @@ pub fn build(b: *std.Build) void { vaxis_mod.addImport("uucode", uucode_mod); exe.root_module.addImport("vaxis", vaxis_mod); + const tree_sitter = b.dependency("tree_sitter", .{ + .target = target, + .optimize = optimize, + }); + exe.root_module.addImport("tree-sitter", tree_sitter.module("tree_sitter")); + + const ts_rust_dep = b.dependency("ts_rust", .{}); + const ts_c_dep = b.dependency("ts_c", .{}); + const ts_zig_dep = b.dependency("ts_zig", .{}); + const c_query_path = ts_c_dep.path("queries/highlights.scm").getPath(b); + const rust_query_path = ts_rust_dep.path("queries/highlights.scm").getPath(b); + const zig_query_path = ts_zig_dep.path("queries/highlights.scm").getPath(b); + const c_query = std.Io.Dir.cwd().readFileAlloc(io, c_query_path, b.allocator, .limited(0x100000)) catch @panic("read c highlights"); + const rust_query = std.Io.Dir.cwd().readFileAlloc(io, rust_query_path, b.allocator, .limited(0x100000)) catch @panic("read rust highlights"); + const zig_query = std.Io.Dir.cwd().readFileAlloc(io, zig_query_path, b.allocator, .limited(0x100000)) catch @panic("read zig highlights"); + const ts_queries = b.addOptions(); + ts_queries.addOption([]const u8, "c_highlights", c_query); + ts_queries.addOption([]const u8, "rust_highlights", rust_query); + ts_queries.addOption([]const u8, "zig_highlights", zig_query); + exe.root_module.addOptions("ts_queries", ts_queries); + + const rust_parser_lib = b.addLibrary(.{ + .name = "tree-sitter-rust", + .root_module = b.createModule(.{ + .target = target, + .optimize = optimize, + .link_libc = true, + }), + .linkage = .static, + }); + rust_parser_lib.root_module.addCSourceFile(.{ .file = ts_rust_dep.path("src/parser.c") }); + rust_parser_lib.root_module.addCSourceFile(.{ .file = ts_rust_dep.path("src/scanner.c") }); + rust_parser_lib.root_module.addIncludePath(ts_rust_dep.path("src")); + exe.root_module.linkLibrary(rust_parser_lib); + + const c_parser_lib = b.addLibrary(.{ + .name = "tree-sitter-c", + .root_module = b.createModule(.{ + .target = target, + .optimize = optimize, + .link_libc = true, + }), + .linkage = .static, + }); + c_parser_lib.root_module.addCSourceFile(.{ .file = ts_c_dep.path("src/parser.c") }); + c_parser_lib.root_module.addIncludePath(ts_c_dep.path("src")); + exe.root_module.linkLibrary(c_parser_lib); + + const zig_parser_lib = b.addLibrary(.{ + .name = "tree-sitter-zig", + .root_module = b.createModule(.{ + .target = target, + .optimize = optimize, + .link_libc = true, + }), + .linkage = .static, + }); + zig_parser_lib.root_module.addCSourceFile(.{ .file = ts_zig_dep.path("src/parser.c") }); + zig_parser_lib.root_module.addIncludePath(ts_zig_dep.path("src")); + exe.root_module.linkLibrary(zig_parser_lib); + const run_exe = b.addRunArtifact(exe); const run = b.step("run", "descend to the pardes"); |
