summaryrefslogtreecommitdiff
path: root/build/core.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-17 13:35:31 -0300
committerGabriel Schneider <[email protected]>2026-11-17 13:45:32 -0300
commit7a1c66f1a15911763db42d890e9e8172fe404170 (patch)
tree2604fc13399b96b091af1350bc6b78d6e0a9f89a /build/core.zig
parente5c57a863004914136c4e6b0fa13ed805b3b383d (diff)
downloadpardes-7a1c66f1a15911763db42d890e9e8172fe404170.tar.gz
pardes-7a1c66f1a15911763db42d890e9e8172fe404170.zip
build: the core named once (core.module), the window's pieces made once
build/core.zig's module() makes every core: the shell, the core, the core without the terminal (core-test), pardes-isolate, the static, the bare build's window, the syntax module's (syntax-test) and the 9P test roots; each import and library a core takes is written there once, in the order the fold over core_mods and wireCore gave them, so every compile keeps its inputs. Parts holds what a core is made of, Core the few ways the products differ. Tracy's client and BSD libutil stay where they were (Tracy: the shell and the core; libutil: the shell), now said by a field. Gone: the core_mods fold and its buffers, wireCore and its eleven optional fields, the 9P roots' copies of core_module's import table and link objects. The editor library's and pardes-syntax's import lists are written out in full (editorModule, library.zig); TreeSitter.wire adds the grammars; ShellConfig has defaults, so the library's two literals are one. build/gui.zig's make() builds SDL, gui_c, sketchbook's renderer, HarfBuzz and the renderer's and atlas's tests once, and Window.wire links them into each window shell. One pardes-lspmock (tests and process-test shared it twice from one root); tools.program() makes the eleven uniform runner programs in a line each. The pdf benches (tools.pdfBenches) are made once the core is. Gates: zig build -l and -h byte-identical to the base over the matrix (bare, tui, gui, macos, ReleaseFast, -Dpdf=false, -Dtree-sitter=minimal, musl, -Dtracy), test/lib's configuration byte-identical. Warm rebuild of install addons and core-test shell-test unit-test process-test on the base's cache: tui every compile cached (0 rebuilt), 2339/2486 tests passed with the base's 4 known failures, the same counts as the base; gui one change: SDL3 had -DSDL_DISABLE_STB=1 added once per window shell (twice with -Dplatform=gui), now once, so libSDL3.a's cache path moves and pardes-gui and the shell-test root relink (their argv differ in that one path, nothing else); tests 2398/2545, as the base. Installed bin/pardes, image.so and pdf.so cmp-identical on tui; image.so and pdf.so identical on gui, pardes-gui differs by the relinked SDL3 (size 398,737,210 -> 398,733,114). zig build syntax-test, which did not compile on main, now compiles and passes (40/40). Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T
Diffstat (limited to 'build/core.zig')
-rw-r--r--build/core.zig175
1 files changed, 126 insertions, 49 deletions
diff --git a/build/core.zig b/build/core.zig
index 11b82e3a..2809ff46 100644
--- a/build/core.zig
+++ b/build/core.zig
@@ -56,17 +56,17 @@ pub fn command(b: *std.Build, argv: []const []const u8) ?[]const u8 {
pub const ShellConfig = struct {
tree_sitter_grammars: TreeSitterGrammars,
- tracy: bool,
+ tracy: bool = false,
/// null = "the platform's own default": the macOS shell hands the row to
/// its native menu bar, every other shell keeps the acme topbar.
- workspace_tag: ?bool,
- prebuilt_shaders: bool,
- embed_sources: bool,
- commit: ?[]const u8,
+ workspace_tag: ?bool = null,
+ prebuilt_shaders: bool = false,
+ embed_sources: bool = false,
+ commit: ?[]const u8 = null,
/// The jj change git HEAD is in, and when this configure ran: the
/// `Build` word's, stamped with the commit (see `stamp_commit`).
- change: ?[]const u8,
- built: ?[]const u8,
+ change: ?[]const u8 = null,
+ built: ?[]const u8 = null,
/// The library's editor (src/lib_editor.zig): a text with no pane, so
/// the core is not compiled (src/Editor.zig).
lib: bool = false,
@@ -135,6 +135,13 @@ pub const TreeSitter = struct {
mod: ?*std.Build.Module,
queries: ?*std.Build.Step.Options,
libs: std.ArrayList(*std.Build.Step.Compile),
+
+ /// tree-sitter, the grammars' parsers and their queries, into `m`.
+ pub fn wire(ts: TreeSitter, m: *std.Build.Module) void {
+ if (ts.mod) |x| m.addImport("tree-sitter", x);
+ for (ts.libs.items) |lib| m.linkLibrary(lib);
+ if (ts.queries) |x| m.addOptions("ts_queries", x);
+ }
};
/// tree-sitter's bindings, and for each grammar of the set its queries (the
@@ -220,11 +227,9 @@ pub fn uucodeModule(b: *std.Build, target: std.Build.ResolvedTarget, optimize: s
/// text pane's own code built with `lib`, so no pane and no core, over
/// tree-sitter, uucode and mvzr, with pardes-syntax in it as `.syntax`.
/// `library` exports it to a package that asks; hxdiff runs its cases on it.
-pub fn editorModule(b: *std.Build, name: ?[]const u8, target: std.Build.ResolvedTarget, optimize: std.builtin.OptimizeMode, cfg: ShellConfig, d: struct {
+pub fn editorModule(b: *std.Build, name: ?[]const u8, target: std.Build.ResolvedTarget, optimize: std.lang.Optimize, cfg: ShellConfig, d: struct {
themes: *std.Build.Module,
- tree_sitter: ?*std.Build.Module,
- ts_libs: []const *std.Build.Step.Compile,
- ts_queries: ?*std.Build.Step.Options,
+ ts: TreeSitter,
uucode: *std.Build.Module,
mvzr: *std.Build.Module,
/// vaxis's, or a module of its grapheme width alone (`library`): a
@@ -237,46 +242,118 @@ pub fn editorModule(b: *std.Build, name: ?[]const u8, target: std.Build.Resolved
.root_source_file = b.path("src/lib_editor.zig"),
.link_libc = true,
};
- const mod = if (name) |n| b.addModule(n, options) else b.createModule(options);
+ const m = if (name) |n| b.addModule(n, options) else b.createModule(options);
var lib_cfg = cfg;
lib_cfg.lib = true;
- mod.addOptions("pardes_config", shellOptions(b, lib_cfg, .tui));
- wireCore(mod, .{
- .plain = b.createModule(.{ .target = target, .optimize = optimize, .root_source_file = b.path("src/plain/plain.zig") }),
- .themes = d.themes,
- .tree_sitter = d.tree_sitter,
- .ts_libs = d.ts_libs,
- .ts_queries = d.ts_queries,
- .mvzr = d.mvzr,
- .uucode = d.uucode,
- .vaxis = d.vaxis,
- .c_heap = b.createModule(.{ .target = target, .optimize = optimize, .root_source_file = b.path("src/c_heap.zig") }),
- });
- return mod;
+ m.addOptions("pardes_config", shellOptions(b, lib_cfg, .tui));
+ m.addImport("plain", b.createModule(.{ .target = target, .optimize = optimize, .root_source_file = b.path("src/plain/plain.zig") }));
+ m.addImport("generated_themes", d.themes);
+ d.ts.wire(m);
+ m.addImport("mvzr", d.mvzr);
+ m.addImport("c_heap", b.createModule(.{ .target = target, .optimize = optimize, .root_source_file = b.path("src/c_heap.zig") }));
+ m.addImport("vaxis", d.vaxis);
+ m.addImport("uucode", d.uucode);
+ return m;
}
-pub fn wireCore(m: *std.Build.Module, d: struct {
- plain: ?*std.Build.Module = null,
- kind: ?*std.Build.Module = null,
- themes: ?*std.Build.Module = null,
- tree_sitter: ?*std.Build.Module = null,
- ts_libs: []const *std.Build.Step.Compile = &.{},
- ts_queries: ?*std.Build.Step.Options = null,
- mvzr: ?*std.Build.Module = null,
- c_heap: ?*std.Build.Module = null,
- vaxis: ?*std.Build.Module = null,
- uucode: ?*std.Build.Module = null,
- xitdb: ?*std.Build.Module = null,
-}) void {
- if (d.plain) |x| m.addImport("plain", x);
- if (d.kind) |x| m.addImport("pardes_addon", x);
- if (d.themes) |x| m.addImport("generated_themes", x);
- if (d.tree_sitter) |x| m.addImport("tree-sitter", x);
- for (d.ts_libs) |lib| m.linkLibrary(lib);
- if (d.ts_queries) |x| m.addOptions("ts_queries", x);
- if (d.mvzr) |x| m.addImport("mvzr", x);
- if (d.c_heap) |x| m.addImport("c_heap", x);
- if (d.vaxis) |x| m.addImport("vaxis", x);
- if (d.uucode) |x| m.addImport("uucode", x);
- if (d.xitdb) |x| m.addImport("xitdb", x);
+/// What every core module is made of: build.zig makes each once.
+pub const Parts = struct {
+ target: std.Build.ResolvedTarget,
+ optimize: std.lang.Optimize,
+ cloud9: *std.Build.Module,
+ /// -Dtracy's checkout, whose client a core that asks compiles in.
+ tracy: ?[]const u8,
+ zstd: *std.Build.Step.Compile,
+ /// The addons, for a core that has them compiled in (Addon.zig); the
+ /// pdf one only when it is built (-Dpdf=false leaves it out).
+ image: *std.Build.Module,
+ pdf: ?*std.Build.Module,
+ term: *std.Build.Module,
+ plain: *std.Build.Module,
+ /// The kinds' C ABI (src/kinds/pardes_addon.h), translated.
+ kind: *std.Build.Module,
+ themes: *std.Build.Module,
+ ts: TreeSitter,
+ mvzr: *std.Build.Module,
+ c_heap: *std.Build.Module,
+ vaxis: *std.Build.Module,
+ uucode: *std.Build.Module,
+ xitdb: *std.Build.Module,
+ doc_typ: *std.Build.Step.Options,
+ /// One options module for each value of `terminal`, `isolated` and
+ /// `on`, shared by every core.
+ term_on: *std.Build.Step.Options,
+ term_off: *std.Build.Step.Options,
+ iso_on: *std.Build.Step.Options,
+ iso_off: *std.Build.Step.Options,
+ builtin_on: *std.Build.Step.Options,
+ builtin_off: *std.Build.Step.Options,
+};
+
+/// Which core: its root and the few ways the products differ.
+pub const Core = struct {
+ /// src/main.zig for a shell, src/pardes.zig for the core, or a file
+ /// whose tests run on the core's imports.
+ root: []const u8,
+ /// The shell's options (`pardes_config`): this build's, or the window's
+ /// in the bare build.
+ config: *std.Build.Step.Options,
+ /// The terminal module; without it (core-test) a shell boot is a scratch pane.
+ terminal: bool = true,
+ /// pardes-isolate's: no host but the terminal.
+ isolated: bool = false,
+ /// The addons compiled in and registered at start (Addon.zig): the
+ /// static step's, and every core off Linux, whose loader has no memfd.
+ builtin_addons: bool = false,
+ /// Tracy's client with -Dtracy: the shell's and the core's.
+ tracy: bool = false,
+ /// libutil, for forkpty on the BSDs: the shell's.
+ util: bool = false,
+};
+
+/// A core module, everything it imports and links named here and nowhere else.
+pub fn module(b: *std.Build, p: Parts, c: Core) *std.Build.Module {
+ const m = b.createModule(.{ .target = p.target, .optimize = p.optimize, .root_source_file = b.path(c.root), .link_libc = true });
+ m.addImport("cloud9", p.cloud9);
+ // forkpty: in libc proper on glibc>=2.34 and darwin; the BSDs keep it in libutil
+ if (c.util and (p.target.result.os.tag == .freebsd or p.target.result.os.tag == .netbsd or p.target.result.os.tag == .openbsd))
+ m.linkSystemLibrary("util", .{});
+ if (c.tracy) if (p.tracy) |tracy_path| {
+ m.addIncludePath(.{ .cwd_relative = tracy_path });
+ m.addCSourceFile(.{
+ .file = .{ .cwd_relative = b.pathJoin(&.{ tracy_path, "public", "TracyClient.cpp" }) },
+ .flags = &.{
+ "-DTRACY_ENABLE=1",
+ "-DTRACY_NO_SAMPLING",
+ "-DTRACY_NO_CALLSTACK",
+ "-DTRACY_NO_SYSTEM_TRACING",
+ "-DTRACY_NO_CRASH_HANDLER",
+ "-DTRACY_NO_CODE_TRANSFER",
+ "-fno-sanitize=undefined",
+ },
+ });
+ m.link_libcpp = true;
+ };
+ if (c.builtin_addons) if (p.pdf) |pdf| m.addImport("pdf_addon", pdf);
+ m.linkLibrary(p.zstd);
+ if (c.builtin_addons) m.addImport("image_addon", p.image);
+ if (c.terminal) {
+ m.addImport("term", p.term);
+ m.addOptions("term_options", p.term_on);
+ } else m.addOptions("term_options", p.term_off);
+ m.addImport("plain", p.plain);
+ m.addImport("pardes_addon", p.kind);
+ m.addImport("generated_themes", p.themes);
+ p.ts.wire(m);
+ m.addImport("mvzr", p.mvzr);
+ m.addImport("c_heap", p.c_heap);
+ m.addImport("vaxis", p.vaxis);
+ m.addImport("uucode", p.uucode);
+ m.addImport("xitdb", p.xitdb);
+ // config.zig's test checks the words and keys docs/typ names exist.
+ m.addOptions("doc_typ", p.doc_typ);
+ m.addOptions("pardes_config", c.config);
+ m.addOptions("pardes_isolation", if (c.isolated) p.iso_on else p.iso_off);
+ m.addOptions("builtin_addons", if (c.builtin_addons) p.builtin_on else p.builtin_off);
+ return m;
}