summaryrefslogtreecommitdiff
path: root/build.zig
diff options
context:
space:
mode:
Diffstat (limited to 'build.zig')
-rw-r--r--build.zig93
1 files changed, 61 insertions, 32 deletions
diff --git a/build.zig b/build.zig
index 1b9a4351..f272e26e 100644
--- a/build.zig
+++ b/build.zig
@@ -2,6 +2,7 @@ const std = @import("std");
const AppKind = enum { main, replay };
const GhosttyArtifact = enum { ghostty, lib };
+const TreeSitterGrammars = enum { disabled, minimal, full };
pub fn build(b: *std.Build) void {
const requested_optimize = b.standardOptimizeOption(.{});
@@ -30,7 +31,11 @@ pub fn build(b: *std.Build) void {
const sdl = b.option(bool, "sdl", "build the SDL3 GPU UI frontend instead of the terminal backend") orelse false;
const sdl_backend = sdl or is_emscripten;
const replay_dump = b.option([]const u8, "replay-dump", "embed this replay dump .zon into pardes-replay");
- const syntax_highlighting = !is_emscripten;
+ const default_tree_sitter_grammars: TreeSitterGrammars = if (is_emscripten) .minimal else .full;
+ const tree_sitter_grammars = b.option(TreeSitterGrammars, "tree-sitter", "tree-sitter grammar set: disabled, minimal, full") orelse default_tree_sitter_grammars;
+ const syntax_highlighting = tree_sitter_grammars != .disabled;
+ const syntax_minimal_grammars = tree_sitter_grammars == .minimal or tree_sitter_grammars == .full;
+ const syntax_full_grammars = tree_sitter_grammars == .full;
const emscripten_include: ?std.Build.LazyPath = if (emscripten_sysroot) |sysroot|
.{ .cwd_relative = b.pathJoin(&.{ sysroot, "include" }) }
else
@@ -86,11 +91,15 @@ pub fn build(b: *std.Build) void {
const main_app_config = b.addOptions();
main_app_config.addOption(AppKind, "app_kind", .main);
main_app_config.addOption(bool, "syntax_highlighting", syntax_highlighting);
+ main_app_config.addOption(bool, "syntax_minimal_grammars", syntax_minimal_grammars);
+ main_app_config.addOption(bool, "syntax_full_grammars", syntax_full_grammars);
exe.root_module.addOptions("app_config", main_app_config);
const replay_app_config = b.addOptions();
replay_app_config.addOption(AppKind, "app_kind", .replay);
replay_app_config.addOption(bool, "syntax_highlighting", syntax_highlighting);
+ replay_app_config.addOption(bool, "syntax_minimal_grammars", syntax_minimal_grammars);
+ replay_app_config.addOption(bool, "syntax_full_grammars", syntax_full_grammars);
replay.root_module.addOptions("app_config", replay_app_config);
const replay_config = b.addOptions();
replay_config.addOption(bool, "embedded_dump", replay_dump != null);
@@ -245,12 +254,40 @@ pub fn build(b: *std.Build) void {
exe.root_module.addImport("zstbi", zstbi_mod);
replay.root_module.addImport("zstbi", zstbi_mod);
+ const replay_wasm_ready = is_emscripten and replay_dump != null and emscripten_sysroot != null;
+ const emcc_for_wasm = if (replay_wasm_ready) blk: {
+ const replay_obj = b.addObject(.{
+ .name = "pardes-replay",
+ .root_module = replay.root_module,
+ });
+ if (emscripten_libc_file) |libc_file| replay_obj.setLibCFile(libc_file);
+
+ const emcc_path = b.option([]const u8, "emcc", "path to emcc for replay-wasm final link") orelse "/usr/lib/emscripten/emcc";
+ const emcc = b.addSystemCommand(&.{emcc_path});
+ emcc.addFileArg(replay_obj.getEmittedBinDirectory().path(b, "pardes-replay_zcu.o"));
+ emcc.addFileArg(replay_obj.getEmittedBin());
+ emcc.addFileArg(b.path("vendor/stb/stb_truetype_impl.c"));
+ emcc.addFileArg(b.path("vendor/stb/font.c"));
+ emcc.addFileArg(zstbi_dep.path("src/zstbi.c"));
+ if (sdl_lib_for_wasm) |sdl_lib| emcc.addFileArg(sdl_lib.getEmittedBin());
+ break :blk emcc;
+ } else null;
+
if (syntax_highlighting) {
// 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 });
const tree_sitter_mod = tree_sitter.module("tree_sitter");
+ if (is_emscripten) {
+ for (tree_sitter_mod.link_objects.items) |link_object| switch (link_object) {
+ .other_step => |lib| {
+ if (emscripten_libc_file) |libc_file| lib.setLibCFile(libc_file);
+ if (emcc_for_wasm) |emcc| emcc.addFileArg(lib.getEmittedBin());
+ },
+ else => {},
+ };
+ }
exe.root_module.addImport("tree-sitter", tree_sitter_mod);
replay.root_module.addImport("tree-sitter", tree_sitter_mod);
@@ -261,14 +298,15 @@ pub fn build(b: *std.Build) void {
scanner: bool = false,
query: []const u8 = "queries/highlights.scm",
local_query: ?[]const u8 = null,
+ minimal: bool = false,
};
const grammars = [_]Grammar{
.{ .name = "ada", .dep = "ts_ada" },
.{ .name = "bash", .dep = "ts_bash", .scanner = true },
- .{ .name = "c", .dep = "ts_c" },
+ .{ .name = "c", .dep = "ts_c", .minimal = true },
.{ .name = "c_sharp", .dep = "ts_c_sharp", .scanner = true },
.{ .name = "clojure", .dep = "ts_clojure" },
- .{ .name = "cpp", .dep = "ts_cpp", .scanner = true },
+ .{ .name = "cpp", .dep = "ts_cpp", .scanner = true, .minimal = true },
.{ .name = "css", .dep = "ts_css", .scanner = true },
.{ .name = "elixir", .dep = "ts_elixir", .scanner = true },
.{ .name = "erlang", .dep = "ts_erlang", .scanner = true },
@@ -288,25 +326,29 @@ pub fn build(b: *std.Build) void {
.{ .name = "ruby", .dep = "ts_ruby", .scanner = true },
.{ .name = "rust", .dep = "ts_rust", .scanner = true },
.{ .name = "scala", .dep = "ts_scala", .scanner = true },
- .{ .name = "zig", .dep = "ts_zig" },
+ .{ .name = "zig", .dep = "ts_zig", .minimal = true },
};
const ts_queries = b.addOptions();
inline for (grammars) |g| {
- const dep = b.dependency(g.dep, .{});
- const query_path = if (g.local_query) |p| b.path(p) else dep.path(g.query);
- const query = std.Io.Dir.cwd().readFileAlloc(io, query_path.getPath(b), b.allocator, .limited(0x100000)) catch @panic("read " ++ g.name ++ " highlights");
- ts_queries.addOption([]const u8, g.name ++ "_highlights", query);
+ if (tree_sitter_grammars == .full or g.minimal) {
+ const dep = b.dependency(g.dep, .{});
+ const query_path = if (g.local_query) |p| b.path(p) else dep.path(g.query);
+ const query = std.Io.Dir.cwd().readFileAlloc(io, query_path.getPath(b), b.allocator, .limited(0x100000)) catch @panic("read " ++ g.name ++ " highlights");
+ ts_queries.addOption([]const u8, g.name ++ "_highlights", query);
- const lib = b.addLibrary(.{
- .name = "tree-sitter-" ++ g.name,
- .root_module = b.createModule(.{ .target = target, .optimize = optimize, .link_libc = true }),
- .linkage = .static,
- });
- lib.root_module.addCSourceFile(.{ .file = dep.path(g.src ++ "/parser.c") });
- if (g.scanner) lib.root_module.addCSourceFile(.{ .file = dep.path(g.src ++ "/scanner.c") });
- lib.root_module.addIncludePath(dep.path(g.src));
- exe.root_module.linkLibrary(lib);
- replay.root_module.linkLibrary(lib);
+ const lib = b.addLibrary(.{
+ .name = "tree-sitter-" ++ g.name,
+ .root_module = b.createModule(.{ .target = target, .optimize = optimize, .link_libc = true }),
+ .linkage = .static,
+ });
+ if (emscripten_libc_file) |libc_file| lib.setLibCFile(libc_file);
+ lib.root_module.addCSourceFile(.{ .file = dep.path(g.src ++ "/parser.c") });
+ if (g.scanner) lib.root_module.addCSourceFile(.{ .file = dep.path(g.src ++ "/scanner.c") });
+ lib.root_module.addIncludePath(dep.path(g.src));
+ exe.root_module.linkLibrary(lib);
+ replay.root_module.linkLibrary(lib);
+ if (emcc_for_wasm) |emcc| emcc.addFileArg(lib.getEmittedBin());
+ }
}
exe.root_module.addOptions("ts_queries", ts_queries);
replay.root_module.addOptions("ts_queries", ts_queries);
@@ -335,20 +377,7 @@ pub fn build(b: *std.Build) void {
} else if (emscripten_sysroot == null) {
replay_wasm_step.dependOn(&b.addFail("replay-wasm requires an Emscripten sysroot; pass --sysroot <emscripten>/cache/sysroot or set EM_CACHE/EMSDK").step);
} else {
- const replay_obj = b.addObject(.{
- .name = "pardes-replay",
- .root_module = replay.root_module,
- });
- if (emscripten_libc_file) |libc_file| replay_obj.setLibCFile(libc_file);
-
- const emcc_path = b.option([]const u8, "emcc", "path to emcc for replay-wasm final link") orelse "/usr/lib/emscripten/emcc";
- const emcc = b.addSystemCommand(&.{emcc_path});
- emcc.addFileArg(replay_obj.getEmittedBinDirectory().path(b, "pardes-replay_zcu.o"));
- emcc.addFileArg(replay_obj.getEmittedBin());
- emcc.addFileArg(b.path("vendor/stb/stb_truetype_impl.c"));
- emcc.addFileArg(b.path("vendor/stb/font.c"));
- emcc.addFileArg(zstbi_dep.path("src/zstbi.c"));
- if (sdl_lib_for_wasm) |sdl_lib| emcc.addFileArg(sdl_lib.getEmittedBin());
+ const emcc = emcc_for_wasm.?;
emcc.addPrefixedDirectoryArg("-I", b.path("vendor/stb"));
emcc.addPrefixedDirectoryArg("-I", zstbi_dep.path("libs/stbi"));
emcc.addArgs(&.{