summaryrefslogtreecommitdiff
path: root/build.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-08-09 10:41:33 -0300
committerGabriel Schneider <[email protected]>2026-08-10 09:17:07 -0300
commit9085cb5bfdd0b78ff3a62c0c71fc231dd7b5052a (patch)
tree91fce278abc85e4f7491de8b5f02184c8a2d5a56 /build.zig
parent2b1fac6fecbf7d7cc08f9dad24687b05e9968c9a (diff)
downloadpardes-9085cb5bfdd0b78ff3a62c0c71fc231dd7b5052a.tar.gz
pardes-9085cb5bfdd0b78ff3a62c0c71fc231dd7b5052a.zip
replace ArrayLists with bounded storage
Diffstat (limited to 'build.zig')
-rw-r--r--build.zig91
1 files changed, 42 insertions, 49 deletions
diff --git a/build.zig b/build.zig
index c150c9b5..e399f537 100644
--- a/build.zig
+++ b/build.zig
@@ -1,6 +1,7 @@
const std = @import("std");
const mupdf_build = @import("mupdf.zig");
const snap_build = @import("build/snap.zig");
+const grammar_manifest = @import("src/grammar_manifest.zig");
pub const Platform = enum { tty, gui, web, macos };
@@ -258,47 +259,11 @@ pub fn build(b: *std.Build) void {
root_mod.addImport("tree-sitter", tree_sitter_mod);
hx_core_mod.addImport("tree-sitter", tree_sitter_mod);
- const Grammar = struct {
- name: []const u8,
- dep: []const u8,
- src: []const u8 = "src",
- scanner: bool = false,
- query: []const u8 = "queries/highlights.scm",
- minimal: bool = false,
- };
- const grammars = [_]Grammar{
- .{ .name = "ada", .dep = "ts_ada" },
- .{ .name = "bash", .dep = "ts_bash", .scanner = true },
- .{ .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, .minimal = true },
- .{ .name = "css", .dep = "ts_css", .scanner = true },
- .{ .name = "elixir", .dep = "ts_elixir", .scanner = true },
- .{ .name = "erlang", .dep = "ts_erlang", .scanner = true },
- .{ .name = "fortran", .dep = "ts_fortran", .scanner = true },
- .{ .name = "go", .dep = "ts_go" },
- .{ .name = "haskell", .dep = "ts_haskell", .scanner = true },
- .{ .name = "html", .dep = "ts_html", .scanner = true },
- .{ .name = "java", .dep = "ts_java" },
- .{ .name = "javascript", .dep = "ts_javascript", .scanner = true },
- .{ .name = "json", .dep = "ts_json" },
- .{ .name = "kotlin", .dep = "ts_kotlin", .scanner = true },
- .{ .name = "ocaml", .dep = "ts_ocaml", .src = "grammars/ocaml/src", .scanner = true },
- .{ .name = "pascal", .dep = "ts_pascal" },
- .{ .name = "php", .dep = "ts_php", .src = "php/src", .scanner = true },
- .{ .name = "powershell", .dep = "ts_powershell", .scanner = true },
- .{ .name = "python", .dep = "ts_python", .scanner = true },
- .{ .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", .minimal = true },
- };
const ts_queries = b.addOptions();
- inline for (grammars) |g| {
+ inline for (grammar_manifest.all) |g| {
if (tree_sitter_grammars == .full or
- (tree_sitter_grammars == .minimal and g.minimal) or
- (tree_sitter_grammars == .zig and std.mem.eql(u8, g.name, "zig")))
+ (tree_sitter_grammars == .minimal and g.tier != .full) or
+ (tree_sitter_grammars == .zig and g.tier == .zig))
{
const dep = b.dependency(g.dep, .{});
const query_path = dep.path(g.query);
@@ -530,8 +495,20 @@ pub fn build(b: *std.Build) void {
// hand it to the backend, which consults it exactly where ZLS gave up.
// Costs one build option and stays correct by construction — a dependency
// that is added or renamed above cannot forget to update it.
- var mod_names: std.ArrayList([]const u8) = .empty;
- var mod_roots: std.ArrayList([]const u8) = .empty;
+ var module_count: usize = 0;
+ {
+ var it = root_mod.import_table.iterator();
+ while (it.next()) |e| {
+ const lp = e.value_ptr.*.root_source_file orelse continue;
+ switch (lp) {
+ .src_path, .cwd_relative => module_count += 1,
+ else => continue,
+ }
+ }
+ }
+ const mod_names = b.allocator.alloc([]const u8, module_count) catch @panic("OOM");
+ const mod_roots = b.allocator.alloc([]const u8, module_count) catch @panic("OOM");
+ var module_index: usize = 0;
{
var it = root_mod.import_table.iterator();
while (it.next()) |e| {
@@ -543,12 +520,14 @@ pub fn build(b: *std.Build) void {
.cwd_relative => |cr| cr,
else => continue,
};
- mod_names.append(b.allocator, e.key_ptr.*) catch @panic("OOM");
- mod_roots.append(b.allocator, abs) catch @panic("OOM");
+ mod_names[module_index] = e.key_ptr.*;
+ mod_roots[module_index] = abs;
+ module_index += 1;
}
}
- opts.addOption([]const []const u8, "module_names", mod_names.items);
- opts.addOption([]const []const u8, "module_roots", mod_roots.items);
+ std.debug.assert(module_index == module_count);
+ opts.addOption([]const []const u8, "module_names", mod_names);
+ opts.addOption([]const []const u8, "module_roots", mod_roots);
root_mod.addOptions("pardes_config", opts);
hx_core_mod.addOptions("pardes_config", opts);
@@ -955,18 +934,32 @@ fn compileGlsl(b: *std.Build, src: []const u8, stage: []const u8, out: []const u
/// .toml or a .json is skipped, which is what lets the upstream LICENSE files
/// sit beside the themes they cover.
fn vendoredThemes(b: *std.Build, io: std.Io) []const []const u8 {
+ var count: usize = 0;
+ {
+ var dir = b.build_root.handle.openDir(io, "vendor/themes", .{ .iterate = true }) catch @panic("open vendor/themes");
+ defer dir.close(io);
+ var it = dir.iterate();
+ while (it.next(io) catch @panic("read vendor/themes")) |e| {
+ if (!std.mem.endsWith(u8, e.name, ".toml") and !std.mem.endsWith(u8, e.name, ".json")) continue;
+ count += 1;
+ }
+ }
+
+ const names = b.allocator.alloc([]const u8, count) catch @panic("OOM");
var dir = b.build_root.handle.openDir(io, "vendor/themes", .{ .iterate = true }) catch @panic("open vendor/themes");
defer dir.close(io);
- var names: std.ArrayList([]const u8) = .empty;
var it = dir.iterate();
+ var index: usize = 0;
while (it.next(io) catch @panic("read vendor/themes")) |e| {
if (!std.mem.endsWith(u8, e.name, ".toml") and !std.mem.endsWith(u8, e.name, ".json")) continue;
- names.append(b.allocator, b.dupe(e.name)) catch @panic("OOM");
+ names[index] = b.dupe(e.name);
+ index += 1;
}
- std.mem.sort([]const u8, names.items, {}, struct {
+ std.debug.assert(index == names.len);
+ std.mem.sort([]const u8, names, {}, struct {
fn lt(_: void, a: []const u8, c: []const u8) bool {
return std.mem.order(u8, a, c) == .lt;
}
}.lt);
- return names.items;
+ return names;
}