summaryrefslogtreecommitdiff
path: root/build.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.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.zig')
-rw-r--r--build.zig272
1 files changed, 84 insertions, 188 deletions
diff --git a/build.zig b/build.zig
index 6a44d44c..0ef8c2f1 100644
--- a/build.zig
+++ b/build.zig
@@ -119,79 +119,6 @@ pub fn build(b: *std.Build) void {
defer threaded.deinit();
const io = threaded.io();
- const root_mod = b.createModule(.{
- .target = target,
- .optimize = optimize,
- // The macOS shell is a library whose host owns main(): it roots at
- // its own flat C ABI instead of src/main.zig.
- .root_source_file = b.path(switch (platform) {
- .macos => "src/macos.zig",
- .tui, .gui => "src/main.zig",
- }),
- .link_libc = true,
- });
- const core_module = b.createModule(.{
- .target = target,
- .optimize = optimize,
- .root_source_file = b.path("src/pardes.zig"),
- .link_libc = true,
- });
- // The core without the terminal module (docs/next-terminal.md, Phase 1):
- // what core-test is compiled from. No ghostty-vt, wuffs, zstbi or C++;
- // a shell boot is a scratch pane, a test that needs a terminal skips,
- // and shell-test runs them all with one.
- const core_lean = b.createModule(.{
- .target = target,
- .optimize = optimize,
- .root_source_file = b.path("src/pardes.zig"),
- .link_libc = true,
- });
-
- const isolated_mod: ?*std.Build.Module = if (platform == .tui) b.createModule(.{
- .target = target,
- .optimize = optimize,
- .root_source_file = b.path("src/main.zig"),
- .link_libc = true,
- }) else null;
-
- // `zig build static`'s: the addons compiled in (Addon.zig). Linked
- // statically on musl alone, as glibc links only dynamically; the gui's
- // is dynamic (SDL and the GPU need the display's libraries) with the
- // addons in it all the same.
- const static_linkage: ?std.builtin.LinkMode = if (target.result.isMuslLibC()) .static else null;
- const static_mod: ?*std.Build.Module = if ((platform == .tui and static_linkage != null) or platform == .gui) b.createModule(.{
- .target = target,
- .optimize = optimize,
- .root_source_file = b.path("src/main.zig"),
- .link_libc = true,
- }) else null;
-
- const gui_mod: ?*std.Build.Module = if (also_gui) b.createModule(.{
- .target = target,
- .optimize = optimize,
- .root_source_file = b.path("src/main.zig"),
- .link_libc = true,
- }) else null;
-
- const CoreMod = struct { mod: ?*std.Build.Module, shell: Platform };
- var core_mods_buf: [6]*std.Build.Module = undefined;
- var core_shells_buf: [6]Platform = undefined;
- var core_mods_len: usize = 0;
- for ([_]CoreMod{
- .{ .mod = root_mod, .shell = platform },
- // hxdiff's headless core and pardes-isolate are the primary shell's
- // configuration compiled two more ways, not two more frontends.
- .{ .mod = core_module, .shell = platform },
- .{ .mod = core_lean, .shell = platform },
- .{ .mod = isolated_mod, .shell = platform },
- .{ .mod = static_mod, .shell = platform },
- .{ .mod = gui_mod, .shell = .gui },
- }) |entry| if (entry.mod) |m| {
- core_mods_buf[core_mods_len] = m;
- core_shells_buf[core_mods_len] = entry.shell;
- core_mods_len += 1;
- };
- const core_mods = core_mods_buf[0..core_mods_len];
// The manifest marks every dependency lazy but tree-sitter's runtime, so
// that a package depending on pardes fetches what `library` takes and
// nothing else. pardes takes these whatever it builds: the missing ones
@@ -206,26 +133,9 @@ pub fn build(b: *std.Build) void {
};
}
const cloud9 = b.dependency("cloud9", .{ .target = target, .optimize = optimize }).module("cloud9");
- for (core_mods) |mod| mod.addImport("cloud9", cloud9);
- const core_shells = core_shells_buf[0..core_mods_len];
- // The modules the addons are compiled into (Addon.zig reads their
- // `pardes_addon`): the static step's, and every one for a system
- // Addon.zig's loader, over a Linux memfd, does not run on.
- const builtin_mods: []const *std.Build.Module = if (target.result.os.tag != .linux) core_mods else if (static_mod) |m| b.allocator.dupe(*std.Build.Module, &.{m}) catch @panic("OOM") else &.{};
-
- // The conditional dependencies, hoisted so one `wireCore` call at the end
- // can name them all. The unconditional ones are ordinary consts below.
- const ts_mod = ts.mod;
- const ts_queries_opts = ts.queries;
- var ghostty_core_vt: ?*std.Build.Module = null;
- const ts_libs = ts.libs;
const themes_mod = core.generatedThemes(b, io, target, optimize);
- // forkpty: in libc proper on glibc>=2.34 and darwin; the BSDs keep it in libutil
- if (target.result.os.tag == .freebsd or target.result.os.tag == .netbsd or target.result.os.tag == .openbsd)
- root_mod.linkSystemLibrary("util", .{});
-
// The macOS shell carries the workspace tag row's commands in its native
// menu bar; the row itself goes away. `-Dworkspace-tag=true` puts it back.
const workspace_tag = b.option(bool, "workspace-tag", "draw the workspace tag row (default: on except on macOS, whose menu bar carries its commands)");
@@ -252,25 +162,6 @@ pub fn build(b: *std.Build) void {
const opts = core.shellOptions(b, shell_cfg, platform);
const gui_opts: ?*std.Build.Step.Options = if (also_gui) core.shellOptions(b, shell_cfg, .gui) else null;
- if (tracy) |tracy_path| {
- for ([_]*std.Build.Module{ root_mod, core_module }) |mod| {
- mod.addIncludePath(.{ .cwd_relative = tracy_path });
- mod.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",
- },
- });
- mod.link_libcpp = true;
- }
- }
-
const zstbi_dep = b.dependency("zstbi", .{ .target = target, .optimize = c_optimize });
const zstbi_mod = zstbi_dep.module("root");
// mvzr backtracks with no bound on its work (its own test "do not make
@@ -318,16 +209,13 @@ pub fn build(b: *std.Build) void {
const snake_shader_lib = addons.gpu(b, target, optimize, addon_mod);
const pdf_built = addons.pdf(b, .{
.addon_mod = addon_mod,
- .builtin_mods = builtin_mods,
.c_optimize = c_optimize,
- .core_module = core_module,
.enable_jpx = enable_jpx,
.freetype = freetype,
.freetype_dep = freetype_dep,
.io = io,
.mupdf_check = mupdf_check,
.mupdf_dep = mupdf_dep,
- .optimize = optimize,
.pdf_pointer_bench_step = pdf_pointer_bench_step,
.pdf_scroll_bench_step = pdf_scroll_bench_step,
.target = target,
@@ -354,7 +242,6 @@ pub fn build(b: *std.Build) void {
ghostty_vt_for_tests = ghostty_vt;
ghostty_vt.addImport("uucode", uucode_mod);
patches.ghosttyKitty(b, io, dep, ghostty_vt);
- ghostty_core_vt = ghostty_vt;
}
// override uucode on vaxis LAST so it wins over ghostty's build() wiring.
vaxis_mod.addImport("uucode", uucode_mod);
@@ -365,7 +252,7 @@ pub fn build(b: *std.Build) void {
// resize is left, for the PNG's downscale: stb_image and its writer
// (with the deflate it carries) are patched out, here at build time so
// a fresh fetch keeps it. The image addon has its own (addons/image).
- const wuffs_mod: ?*std.Build.Module = if (ghostty_core_vt) |vt| vt.import_table.get("wuffs") else null;
+ const wuffs_mod: ?*std.Build.Module = if (ghostty_vt_for_tests) |vt| vt.import_table.get("wuffs") else null;
patches.zstbi(b, io, zstbi_dep, zstbi_mod);
// One zstd (docs/shared-libs.md): a far replica's stream, compressed by
@@ -375,14 +262,14 @@ pub fn build(b: *std.Build) void {
// its block compressors only those of levels 3 (dfast) and 6 (lazy),
// the two replica.zig asks for, and its unused functions dropped at
// link. Zig's std has a decompressor, but no compressor.
- {
+ const zstd = zstd: {
const dep = b.dependency("zstd", .{});
- const zstd = b.addLibrary(.{
+ const lib = b.addLibrary(.{
.name = "zstd",
.root_module = b.createModule(.{ .target = target, .optimize = c_optimize, .link_libc = true }),
.linkage = .static,
});
- zstd.root_module.addCSourceFiles(.{
+ lib.root_module.addCSourceFiles(.{
.root = dep.path("lib"),
.files = &.{
"common/debug.c", "common/entropy_common.c", "common/error_private.c",
@@ -401,10 +288,10 @@ pub fn build(b: *std.Build) void {
"-DZSTD_EXCLUDE_BTLAZY2_BLOCK_COMPRESSOR", "-DZSTD_EXCLUDE_BTOPT_BLOCK_COMPRESSOR", "-DZSTD_EXCLUDE_BTULTRA_BLOCK_COMPRESSOR",
},
});
- zstd.link_function_sections = true;
- zstd.link_data_sections = true;
- for (core_mods) |m| m.linkLibrary(zstd);
- }
+ lib.link_function_sections = true;
+ lib.link_data_sections = true;
+ break :zstd lib;
+ };
// xitdb keeps what pardes writes to disk (src/Db.zig): pure Zig, no C
// library and no allocator hook of its own (it takes Zig allocators).
@@ -412,40 +299,22 @@ pub fn build(b: *std.Build) void {
const image_addon = addons.image(b, target, c_optimize, addon_mod, zstbi_dep);
const image_mod = image_addon.root_module;
- for (builtin_mods) |m| m.addImport("image_addon", image_mod);
// The records the core and the terminal both name (src/plain/plain.zig).
const plain_mod = b.createModule(.{ .root_source_file = b.path("src/plain/plain.zig"), .target = target, .optimize = optimize });
// The terminal, a module of its own (src/term/term.zig): the emulator and
// what it brings are its, and every core but core-test's is given it.
const term_mod = b.createModule(.{ .root_source_file = b.path("src/term/term.zig"), .target = target, .optimize = optimize, .link_libc = true });
term_mod.addImport("plain", plain_mod);
- if (ghostty_core_vt) |x| term_mod.addImport("ghostty-vt", x);
+ if (ghostty_vt_for_tests) |x| term_mod.addImport("ghostty-vt", x);
if (wuffs_mod) |x| term_mod.addImport("wuffs", x);
term_mod.addImport("zstbi", zstbi_mod);
+
+ // The core, made by core.module for each product: every import and
+ // library it takes is named there, once.
const term_on = b.addOptions();
term_on.addOption(bool, "terminal", true);
const term_off = b.addOptions();
term_off.addOption(bool, "terminal", false);
- for (core_mods) |m| if (m == core_lean) {
- m.addOptions("term_options", term_off);
- } else {
- m.addImport("term", term_mod);
- m.addOptions("term_options", term_on);
- };
- for (core_mods) |m| core.wireCore(m, .{
- .plain = plain_mod,
- .kind = kind_mod,
- .themes = themes_mod,
- .tree_sitter = ts_mod,
- .ts_libs = ts_libs.items,
- .ts_queries = ts_queries_opts,
- .mvzr = mvzr_mod,
- .c_heap = c_heap_mod,
- .vaxis = vaxis_mod,
- .uucode = uucode_mod,
- .xitdb = xitdb_mod,
- });
-
const iso_off = b.addOptions();
iso_off.addOption(bool, "isolated", false);
const iso_on = b.addOptions();
@@ -456,31 +325,72 @@ pub fn build(b: *std.Build) void {
builtin_on.addOption(bool, "on", true);
// ...the pdf one only when it is built (-Dpdf=false leaves it out).
builtin_on.addOption(bool, "pdf", pdf_addon != null);
-
- for (core_mods, core_shells) |mod, shell| {
- // config.zig's test checks the words and keys docs/typ names exist.
- mod.addOptions("doc_typ", doc_typ_opts);
- mod.addOptions("pardes_config", if (also_gui and shell == .gui) gui_opts.? else opts);
- mod.addOptions("pardes_isolation", if (isolated_mod == mod) iso_on else iso_off);
- mod.addOptions("builtin_addons", if (std.mem.indexOfScalar(*std.Build.Module, builtin_mods, mod) != null) builtin_on else builtin_off);
- }
+ const parts: core.Parts = .{
+ .target = target,
+ .optimize = optimize,
+ .cloud9 = cloud9,
+ .tracy = tracy,
+ .zstd = zstd,
+ .image = image_mod,
+ .pdf = pdf_built.module,
+ .term = term_mod,
+ .plain = plain_mod,
+ .kind = kind_mod,
+ .themes = themes_mod,
+ .ts = ts,
+ .mvzr = mvzr_mod,
+ .c_heap = c_heap_mod,
+ .vaxis = vaxis_mod,
+ .uucode = uucode_mod,
+ .xitdb = xitdb_mod,
+ .doc_typ = doc_typ_opts,
+ .term_on = term_on,
+ .term_off = term_off,
+ .iso_on = iso_on,
+ .iso_off = iso_off,
+ .builtin_on = builtin_on,
+ .builtin_off = builtin_off,
+ };
+ // Off Linux, whose memfd Addon.zig's loader needs, every core has the
+ // addons compiled in.
+ const compiled_in = target.result.os.tag != .linux;
+ // The macOS shell is a library whose host owns main(): it roots at
+ // its own flat C ABI instead of src/main.zig. Tracy's client and BSD
+ // libutil go to the shell (and Tracy's to the core) alone, as before
+ // core.module.
+ const root_mod = core.module(b, parts, .{ .root = if (platform == .macos) "src/macos.zig" else "src/main.zig", .config = opts, .builtin_addons = compiled_in, .tracy = true, .util = true });
+ // hxdiff's headless core and pardes-isolate are the primary shell's
+ // configuration compiled two more ways, not two more frontends.
+ const core_cfg: core.Core = .{ .root = "src/pardes.zig", .config = opts, .builtin_addons = compiled_in, .tracy = true };
+ const core_module = core.module(b, parts, core_cfg);
+ // The core without the terminal module (docs/next-terminal.md, Phase 1):
+ // what core-test is compiled from. No ghostty-vt, wuffs, zstbi or C++;
+ // a shell boot is a scratch pane, a test that needs a terminal skips,
+ // and shell-test runs them all with one.
+ const lean_cfg: core.Core = .{ .root = "src/pardes.zig", .config = opts, .builtin_addons = compiled_in, .terminal = false };
+ const core_lean = core.module(b, parts, lean_cfg);
+ const isolated_mod: ?*std.Build.Module = if (platform == .tui) core.module(b, parts, .{ .root = "src/main.zig", .config = opts, .builtin_addons = compiled_in, .isolated = true }) else null;
+ // `zig build static`'s: the addons compiled in (Addon.zig). Linked
+ // statically on musl alone, as glibc links only dynamically; the gui's
+ // is dynamic (SDL and the GPU need the display's libraries) with the
+ // addons in it all the same.
+ const static_linkage: ?std.builtin.LinkMode = if (target.result.isMuslLibC()) .static else null;
+ const static_mod: ?*std.Build.Module = if ((platform == .tui and static_linkage != null) or platform == .gui) core.module(b, parts, .{ .root = "src/main.zig", .config = opts, .builtin_addons = true }) else null;
+ const gui_mod: ?*std.Build.Module = if (also_gui) core.module(b, parts, .{ .root = "src/main.zig", .config = gui_opts.?, .builtin_addons = compiled_in }) else null;
+ if (pdf_built.lib) |lib| tools.pdfBenches(b, target, optimize, core_module, lib, pdf_pointer_bench_step, pdf_scroll_bench_step);
const builtins_json_step = docs.builtinsJson(b, requested_platform, platform, target, optimize, core_module, doc_renders);
- const gui_tests = gui.add(b, .{
- .freetype = freetype,
- .gui_mod = gui_mod,
- .macos_sdk = macos_sdk,
- .optimize = optimize,
- .platform = platform,
- .prebuilt_shaders = prebuilt_shaders,
- .root_mod = root_mod,
- .static_mod = static_mod,
- .target = target,
- .test_filters = test_filters,
- });
- const cells_test = gui_tests.cells_test;
- const atlas_test = gui_tests.atlas_test;
+ // The window's shells: the bare build's pardes-gui; -Dplatform=gui's
+ // pardes-gui and its static.
+ var cells_test: ?*std.Build.Step.Compile = null;
+ var atlas_test: ?*std.Build.Step.Compile = null;
+ if (also_gui or platform == .gui) {
+ const window = gui.make(b, target, optimize, macos_sdk, prebuilt_shaders, freetype, test_filters);
+ for ([_]?*std.Build.Module{ gui_mod, if (platform == .gui) root_mod else null, if (platform == .gui) static_mod else null }) |m| if (m) |gm| window.wire(gm);
+ cells_test = window.cells_test;
+ atlas_test = window.atlas_test;
+ }
if (platform == .macos) macos.add(b, .{
.macos_identity = macos_identity,
@@ -554,8 +464,11 @@ pub fn build(b: *std.Build) void {
}
const addon_libs: []const *std.Build.Step.Compile = if (pdf_addon) |l| b.allocator.dupe(*std.Build.Step.Compile, &.{ image_addon, l }) catch @panic("OOM") else &.{image_addon};
+ // The scripted language server the tests' sessions and the tty cases ask.
+ const lspmock = tools.program(b, "pardes-lspmock", "test/lspmock.zig", target, optimize, &.{});
process_build.add(b, .{
.exe = exe,
+ .lspmock = lspmock,
.addons = addon_libs,
.target = target,
.optimize = optimize,
@@ -565,7 +478,6 @@ pub fn build(b: *std.Build) void {
});
const t = tools.add(b, .{
- .c_heap_mod = c_heap_mod,
.c_optimize = c_optimize,
.core_module = core_module,
.enable_jpx = enable_jpx,
@@ -574,59 +486,43 @@ pub fn build(b: *std.Build) void {
.ghostty_simd = ghostty_simd,
.ghostty_vt_for_tests = ghostty_vt_for_tests,
.image_addon = image_addon,
- .mvzr_mod = mvzr_mod,
+ .lean = lean_cfg,
.no_pdf = no_pdf,
.optimize = optimize,
- .opts = opts,
+ .parts = parts,
.pdf_addon = pdf_addon,
.platform = platform,
.prebuilt_shaders = prebuilt_shaders,
.shell_cfg = shell_cfg,
.target = target,
- .term_mod = term_mod,
.test_filters = test_filters,
- .themes_mod = themes_mod,
.tracy = tracy,
.tree_sitter_grammars = tree_sitter_grammars,
- .ts_libs = ts_libs,
- .ts_mod = ts_mod,
- .ts_queries_opts = ts_queries_opts,
.unit_profile = unit_profile,
- .uucode_mod = uucode_mod,
- .vaxis_mod = vaxis_mod,
});
- const perf_gate_step = t.perf_gate_step;
- const perf_tests = t.perf_tests;
- const fs_bench_test = t.fs_bench_test;
- const lib_test_step = t.lib_test_step;
-
tests.add(b, .{
.addon_mod = addon_mod,
.atlas_test = atlas_test,
.cells_test = cells_test,
- .cloud9 = cloud9,
.core_lean = core_lean,
.core_module = core_module,
+ .core_cfg = core_cfg,
.exe = exe,
- .fs_bench_test = fs_bench_test,
.ghostty_vt_for_tests = ghostty_vt_for_tests,
.image_addon = image_addon,
- .image_mod = image_mod,
- .lib_test_step = lib_test_step,
+ .lspmock = lspmock,
.mupdf_check = mupdf_check,
.optimize = optimize,
+ .parts = parts,
.pdf_addon = pdf_addon,
- .perf_gate_step = perf_gate_step,
- .perf_tests = perf_tests,
- .plain_mod = plain_mod,
.platform = platform,
.root_mod = root_mod,
.snake_shader_lib = snake_shader_lib,
.target = target,
- .term_mod = term_mod,
.test_build = test_build,
.test_filters = test_filters,
.test_nonce = test_nonce,
+ .tools = t,
.unit_profile = unit_profile,
});
}