summaryrefslogtreecommitdiff
path: root/build/library.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-17 13:26:02 -0300
committerGabriel Schneider <[email protected]>2026-11-17 13:26:17 -0300
commite5c57a863004914136c4e6b0fa13ed805b3b383d (patch)
tree4c3895acfcf310a82432546f9ed02c666a7daefa /build/library.zig
parent9aa2ac1a21bd96260538f2657ff37b63562380ff (diff)
downloadpardes-e5c57a863004914136c4e6b0fa13ed805b3b383d.tar.gz
pardes-e5c57a863004914136c4e6b0fa13ed805b3b383d.zip
build: build() cut into build/*.zig, as pure moves
build.zig 2,406 -> 658 lines; the pieces moved verbatim into a file per thing, each a function called where its code stood, so every step, module and option is made in the same order as before: build/docs.zig (the typst renders, builtins-json, command-line.txt), build/addons.zig (the GPU addons, the pdf addon and its benches, the image addon), build/patches.zig (vaxis, zstbi, ghostty's kitty loader, mvzr), build/gui.zig (the window's shells and its renderer and atlas tests), build/macos.zig (the app, dmg, e2e, its unit-test), build/tools.zig (harnesses, hx*, benches, perf, the syntax snapshots, lib-test, history), build/tests.zig (unit-test and its roots), build/library.zig (what a dependent package gets), build/core.zig (the options module, themes, grammars, uucode, the editor module, wireCore); mupdf.zig is build/mupdf.zig. A fragment takes what it uses as explicit parameters, or as one struct of exactly those (cloud9's and build/process.zig's pattern). Platform, PerfBuild and TreeSitterGrammars stay in build.zig: Options names an enum or struct by @typeName, so where they are declared is in every options file. Gate: zig build --print-configuration, -l and -h byte-identical to the base over bare (-Dhome-install=false), tui, gui, macos, tui and gui ReleaseFast, -Dpdf=false (tui, gui), -Dtree-sitter=minimal, musl, -Dtracy, and test/lib's -l and --print-configuration. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T
Diffstat (limited to 'build/library.zig')
-rw-r--r--build/library.zig69
1 files changed, 69 insertions, 0 deletions
diff --git a/build/library.zig b/build/library.zig
new file mode 100644
index 00000000..dcbb8938
--- /dev/null
+++ b/build/library.zig
@@ -0,0 +1,69 @@
+const std = @import("std");
+const TreeSitterGrammars = @import("../build.zig").TreeSitterGrammars;
+const core = @import("core.zig");
+const patches = @import("patches.zig");
+
+/// pardes as a library, all a package that depends on it is given: the
+/// `pardes-syntax` module (src/lib_syntax.zig), the grammars, highlighting
+/// and themes for a program that draws source text itself. It takes
+/// tree-sitter and the grammars of its `tree-sitter` option and no other
+/// dependency, so nothing else is fetched (build.zig.zon). test/lib is such
+/// a package, which `lib-test` builds.
+pub fn build(b: *std.Build) void {
+ const target = b.standardTargetOptions(.{});
+ const optimize = b.standardOptimizeOption(.{});
+ const tree_sitter_grammars = b.option(TreeSitterGrammars, "tree-sitter", "tree-sitter grammar set: disabled, zig, minimal (c/c++/zig), full") orelse .full;
+ var threaded: std.Io.Threaded = .init(b.allocator, .{});
+ defer threaded.deinit();
+ const io = threaded.io();
+ const mod = b.addModule("pardes-syntax", .{
+ .target = target,
+ .optimize = optimize,
+ .root_source_file = b.path("src/lib_syntax.zig"),
+ .link_libc = true,
+ });
+ mod.addOptions("pardes_config", core.shellOptions(b, .{
+ .tree_sitter_grammars = tree_sitter_grammars,
+ .tracy = false,
+ .workspace_tag = null,
+ .prebuilt_shaders = false,
+ .embed_sources = false,
+ .commit = null,
+ .change = null,
+ .built = null,
+ }, .tui));
+ const ts = core.treeSitter(b, io, target, if (optimize == .debug) .fast else optimize, tree_sitter_grammars);
+ const themes = core.generatedThemes(b, io, target, optimize);
+ core.wireCore(mod, .{
+ .themes = themes,
+ .tree_sitter = ts.mod,
+ .ts_libs = ts.libs.items,
+ .ts_queries = ts.queries,
+ .c_heap = b.createModule(.{ .target = target, .optimize = optimize, .root_source_file = b.path("src/c_heap.zig") }),
+ });
+ // The editor, `pardes-editor`, to a package that asks for it: uucode,
+ // mvzr and vaxis (with what its build names) are fetched then and only
+ // then. Of vaxis it takes the grapheme width, which uucode alone feeds.
+ if (!(b.option(bool, "editor", "also export `pardes-editor`, the text pane as a library (fetches uucode, mvzr and vaxis)") orelse false)) return;
+ const uucode = core.uucodeModule(b, target, optimize) orelse return;
+ const mvzr = patches.mvzr(b, io, b.lazyDependency("mvzr", .{ .target = target, .optimize = optimize }) orelse return, target, optimize);
+ const vaxis_dep = b.lazyDependency("vaxis", .{ .target = target, .optimize = optimize, .external_uucode = true }) orelse return;
+ const width = b.addWriteFiles();
+ _ = width.addCopyFile(vaxis_dep.path("src/gwidth.zig"), "gwidth.zig");
+ const vaxis = b.createModule(.{
+ .target = target,
+ .optimize = optimize,
+ .root_source_file = width.add("vaxis.zig", "pub const gwidth = @import(\"gwidth.zig\");\n"),
+ .imports = &.{.{ .name = "uucode", .module = uucode }},
+ });
+ _ = core.editorModule(b, "pardes-editor", target, optimize, .{
+ .tree_sitter_grammars = tree_sitter_grammars,
+ .tracy = false,
+ .workspace_tag = null,
+ .prebuilt_shaders = false,
+ .embed_sources = false,
+ .commit = null,
+ .change = null,
+ .built = null,
+ }, .{ .themes = themes, .tree_sitter = ts.mod, .ts_libs = ts.libs.items, .ts_queries = ts.queries, .uucode = uucode, .mvzr = mvzr, .vaxis = vaxis });
+}