summaryrefslogtreecommitdiff
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
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
-rw-r--r--build.zig272
-rw-r--r--build/addons.zig31
-rw-r--r--build/core.zig175
-rw-r--r--build/gui.zig305
-rw-r--r--build/library.zig34
-rw-r--r--build/process.zig14
-rw-r--r--build/tests.zig65
-rw-r--r--build/tools.zig170
8 files changed, 456 insertions, 610 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,
});
}
diff --git a/build/addons.zig b/build/addons.zig
index d22abc7a..a3a23825 100644
--- a/build/addons.zig
+++ b/build/addons.zig
@@ -30,6 +30,9 @@ pub fn gpu(b: *std.Build, target: std.Build.ResolvedTarget, optimize: std.lang.O
pub const Pdf = struct {
lib: ?*std.Build.Step.Compile,
+ /// The same module, for a core with the addons compiled in, which
+ /// exports nothing there (addon.exportLib).
+ module: ?*std.Build.Module,
/// What a step that needs the addon depends on when it is not built.
no_pdf: ?*std.Build.Step,
};
@@ -43,21 +46,19 @@ pub const Pdf = struct {
/// `pardes_addon` alone.
pub fn pdf(b: *std.Build, c: struct {
addon_mod: *std.Build.Module,
- builtin_mods: []const *std.Build.Module,
c_optimize: std.lang.Optimize,
- core_module: *std.Build.Module,
enable_jpx: bool,
freetype: ?*std.Build.Step.Compile,
freetype_dep: ?*std.Build.Dependency,
io: std.Io,
mupdf_check: *std.Build.Step,
mupdf_dep: ?*std.Build.Dependency,
- optimize: std.lang.Optimize,
pdf_pointer_bench_step: *std.Build.Step,
pdf_scroll_bench_step: *std.Build.Step,
target: std.Build.ResolvedTarget,
}) Pdf {
var pdf_addon: ?*std.Build.Step.Compile = null;
+ var pdf_module: ?*std.Build.Module = null;
if (c.mupdf_dep) |md| if (c.freetype_dep) |fd| {
// ...and one zlib, the one FreeType links for its gzip module. Asked
// of FreeType's build with the options it asks with, the dependency
@@ -83,36 +84,16 @@ pub fn pdf(b: *std.Build, c: struct {
const lib = b.addLibrary(.{ .name = "pdf", .linkage = .dynamic, .root_module = pdf_mod });
lib.setVersionScript(b.addWriteFiles().add("pdf.map", "{ global: pardes_addon; local: *; };\n"));
pdf_addon = lib;
- // ...and the same module compiled into a pardes, which exports
- // nothing there (addon.exportLib).
- for (c.builtin_mods) |m| m.addImport("pdf_addon", pdf_mod);
+ pdf_module = pdf_mod;
c.mupdf_check.dependOn(mupdf_build.addProbe(b, mupdf, .{
.target = c.target,
.pdf = b.path("docs/design.pdf"),
}));
-
- // The PDF benches: the core over the addon, a pane of it.
- const config = b.addOptions();
- config.addOption(bool, "release_fast_core", c.optimize == .fast);
- config.addOption([]const u8, "core_optimize", @tagName(c.optimize));
- config.addOptionPath("pdf_addon", lib.getEmittedBin());
- for ([_]struct { step: *std.Build.Step, exe: []const u8, file: []const u8, optimize: std.lang.Optimize }{
- .{ .step = c.pdf_pointer_bench_step, .exe = "pardes-pdf-pointer-bench", .file = "test/pdf_pointer_bench.zig", .optimize = .fast },
- .{ .step = c.pdf_scroll_bench_step, .exe = "pardes-pdf-scroll-bench", .file = "test/pdf_scroll_bench.zig", .optimize = c.optimize },
- }) |bench| {
- const exe = b.addExecutable(.{ .name = bench.exe, .root_module = b.createModule(.{ .target = c.target, .optimize = bench.optimize, .root_source_file = b.path(bench.file), .link_libc = true }) });
- exe.root_module.addImport("pardes", c.core_module);
- exe.root_module.addOptions("pdf_bench_config", config);
- const run = b.addRunArtifact(exe);
- run.addPassthruArgs();
- run.setCwd(b.path("."));
- bench.step.dependOn(&run.step);
- }
};
// Without it, what needs it says how to have it.
const no_pdf: ?*std.Build.Step = if (pdf_addon == null) &b.addFail("this step needs the pdf addon, over MuPDF: add -Dpdf (it is fetched once, and on from then)").step else null;
if (no_pdf) |s| for ([_]*std.Build.Step{ c.mupdf_check, c.pdf_pointer_bench_step, c.pdf_scroll_bench_step }) |step| step.dependOn(s);
- return .{ .lib = pdf_addon, .no_pdf = no_pdf };
+ return .{ .lib = pdf_addon, .module = pdf_module, .no_pdf = no_pdf };
}
/// The image addon (addons/image/image.zig over stb_image, stb.c),
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;
}
diff --git a/build/gui.zig b/build/gui.zig
index aaf64707..9b46f6c5 100644
--- a/build/gui.zig
+++ b/build/gui.zig
@@ -1,5 +1,4 @@
const std = @import("std");
-const Platform = @import("../build.zig").Platform;
const gui_shaders = [_][]const u8{
"ui.vert",
@@ -11,163 +10,177 @@ const gui_shaders = [_][]const u8{
"image.frag",
};
-/// The window's shells (the bare build's pardes-gui, -Dplatform=gui's
-/// pardes-gui and its static): SDL, gui.zig's `c`, sketchbook's renderer and
-/// glyph atlas, FreeType and HarfBuzz; and the renderer's and atlas's own
-/// tests, for unit-test.
-pub fn add(b: *std.Build, c: struct {
+/// The window's pieces, made once and wired into each of its shells (the
+/// bare build's pardes-gui; -Dplatform=gui's pardes-gui and its static):
+/// SDL, gui.zig's `c`, sketchbook's renderer and glyph atlas, FreeType and
+/// HarfBuzz; and the renderer's and atlas's own tests, for unit-test. A
+/// piece whose lazy package is not fetched yet is null.
+pub const Window = struct {
+ sdl: ?Sdl = null,
+ sketchbook: ?*std.Build.Dependency,
freetype: ?*std.Build.Step.Compile,
- gui_mod: ?*std.Build.Module,
- macos_sdk: ?[]const u8,
- optimize: std.lang.Optimize,
- platform: Platform,
- prebuilt_shaders: bool,
- root_mod: *std.Build.Module,
- static_mod: ?*std.Build.Module,
- target: std.Build.ResolvedTarget,
- test_filters: []const []const u8,
-}) struct { cells_test: ?*std.Build.Step.Compile, atlas_test: ?*std.Build.Step.Compile } {
- const gui_shell_mod: ?*std.Build.Module = c.gui_mod orelse
- if (c.platform == .gui) c.root_mod else null;
- // The static step's gui module is a gui shell too.
- const gui_shell_mods: [2]?*std.Build.Module = .{ gui_shell_mod, if (c.platform == .gui) c.static_mod else null };
- // SDL's headers, for the macOS trackpad adapter's test after the loop.
- var sdl_include: ?std.Build.LazyPath = null;
- // sketchbook's Cells.zig's own tests (the instance ABI), for unit-test.
- var cells_test: ?*std.Build.Step.Compile = null;
- // sketchbook's Atlas.zig's own tests, for unit-test.
- var atlas_test: ?*std.Build.Step.Compile = null;
- for (gui_shell_mods) |gui_shell_entry| if (gui_shell_entry) |gm| {
- // This shell's `c`, for the Atlas's tests below.
- var font_c: ?*std.Build.Module = null;
- // SDL's build asks a cross build for macOS for the SDK's paths.
- const sdk: ?std.Build.LazyPath = if (c.macos_sdk) |p| .{ .cwd_relative = p } else null;
- const sdl_dep = b.lazyDependency("sdl", .{ .target = c.target, .optimize = c.optimize, .sanitize_c = .off, .preferred_linkage = .static, .system_include_path = if (sdk) |p| p.path(b, "usr/include") else null, .system_framework_path = if (sdk) |p| p.path(b, "System/Library/Frameworks") else null, .library_path = if (sdk) |p| p.path(b, "usr/lib") else null });
- if (sdl_dep) |dep| {
- const sdl_lib = dep.artifact("SDL3");
- // SDL's own stb_image (SDL_stb.c, for SDL_LoadPNG and a camera's
- // MJPEG, neither of which pardes calls) is a second PNG and JPEG
- // decoder beside the build's: off (docs/shared-libs.md).
- sdl_lib.root_module.addCMacro("SDL_DISABLE_STB", "1");
- gm.linkLibrary(sdl_lib);
- gm.addIncludePath(dep.path("include"));
- // gui.zig's `c`: SDL and the font shim, which @cImport gave it before Zig 0.17.
- const header = b.addWriteFiles().add("gui_c.h",
- \\#define SDL_DISABLE_OLD_NAMES 1
- \\#include <SDL3/SDL.h>
- \\#include "font.h"
- \\#include "macos_trackpad.h"
- \\
- );
- const gui_c = b.addTranslateC(.{ .root_source_file = header, .target = c.target, .optimize = c.optimize });
- gui_c.addIncludePath(dep.path("include"));
- gui_c.addIncludePath(b.path("src/gui"));
- const gui_c_mod = gui_c.createModule();
- font_c = gui_c_mod;
- gm.addImport("gui_c", gui_c_mod);
- if (b.lazyDependency("sketchbook", .{ .@"gpu-only" = true })) |sb| {
- const gpu = b.createModule(.{ .root_source_file = sb.path("src/gpu/Executor.zig"), .imports = &.{ .{ .name = "abi", .module = sb.module("abi") }, .{ .name = "c", .module = gui_c_mod } } });
- gm.addImport("sketch_gpu", gpu);
- // The glyph atlas (src/font/Atlas.zig) over the font shim
- // (vendor/font.{c,h}), compiled below against pardes's
- // FreeType and HarfBuzz.
- const atlas_mod = b.createModule(.{ .root_source_file = sb.path("src/font/Atlas.zig"), .imports = &.{.{ .name = "c", .module = gui_c_mod }} });
- gm.addImport("font_atlas", atlas_mod);
- // pardes's renderer, moved to sketchbook (src/gpu/), compiled
- // against pardes's SDL; its tests run with unit-test. Its
- // SPIR-V is sketchbook's GLSL through glslc, or the prebuilt
- // copies with -Dprebuilt-shaders.
- const cells_mod = b.createModule(.{ .root_source_file = sb.path("src/gpu/Cells.zig"), .imports = &.{ .{ .name = "c", .module = gui_c_mod }, .{ .name = "font_atlas", .module = atlas_mod } } });
- for (gui_shaders) |name| cells_mod.addAnonymousImport(b.fmt("{s}.spv", .{name}), .{
- .root_source_file = if (c.prebuilt_shaders)
- sb.path(b.fmt("src/gpu/shaders/prebuilt/{s}.spv", .{name}))
- else
- compileGlsl(b, sb.path(b.fmt("src/gpu/shaders/{s}.glsl", .{name})), name),
- });
- gm.addImport("gpu_cells", cells_mod);
- gm.addImport("gpu_present", b.createModule(.{ .root_source_file = sb.path("src/gpu/Present.zig"), .imports = &.{ .{ .name = "c", .module = gui_c_mod }, .{ .name = "gpu_cells", .module = cells_mod } } }));
- if (cells_test == null) cells_test = b.addTest(.{ .root_module = b.createModule(.{ .root_source_file = sb.path("src/gpu/Cells.zig"), .target = c.target, .optimize = c.optimize, .imports = &.{ .{ .name = "c", .module = gui_c_mod }, .{ .name = "font_atlas", .module = atlas_mod } } }), .filters = c.test_filters });
- gui_c.addIncludePath(sb.path("vendor"));
- gm.addImport("gpu_scene", sb.module("gpu_scene"));
- }
- sdl_include = dep.path("include");
- if (c.target.result.os.tag == .macos) {
- const arch = if (c.target.result.cpu.arch == .aarch64) "arm64" else @tagName(c.target.result.cpu.arch);
- const shim = b.addSystemCommand(&.{ "xcrun", "clang", "-fobjc-arc", "-O2", "-target", b.fmt("{s}-apple-macos13.0", .{arch}), "-I" });
- shim.addDirectoryArg(dep.path("include"));
- shim.addArg("-c");
- shim.addFileArg(b.path("src/gui/macos_trackpad.m"));
- // Header changes invalidate the independently compiled adapter.
- shim.addFileInput(b.path("src/gui/macos_trackpad.h"));
- shim.addArg("-o");
- gm.addObjectFile(shim.addOutputFileArg("macos_trackpad.o"));
+ harfbuzz: ?HarfBuzz = null,
+ darwin: bool,
+ /// sketchbook's Cells.zig's own tests (the instance ABI).
+ cells_test: ?*std.Build.Step.Compile = null,
+ /// sketchbook's Atlas.zig's own tests.
+ atlas_test: ?*std.Build.Step.Compile = null,
+
+ const Sdl = struct {
+ lib: *std.Build.Step.Compile,
+ include: std.Build.LazyPath,
+ gui_c: *std.Build.Module,
+ /// sketchbook's renderer by file, over gui_c: sketch_gpu,
+ /// font_atlas, gpu_cells, gpu_present, gpu_scene.
+ renderer: ?[5]std.Build.Module.Import = null,
+ /// The macOS trackpad adapter, compiled apart.
+ trackpad: ?std.Build.LazyPath = null,
+ };
+ const HarfBuzz = struct { lib: *std.Build.Step.Compile, include: std.Build.LazyPath };
+
+ /// `gm`, a window shell, given the pieces, in the order it links them.
+ pub fn wire(w: Window, gm: *std.Build.Module) void {
+ const b = gm.owner;
+ if (w.sdl) |sdl| {
+ gm.linkLibrary(sdl.lib);
+ gm.addIncludePath(sdl.include);
+ gm.addImport("gui_c", sdl.gui_c);
+ if (sdl.renderer) |imports| for (imports) |i| gm.addImport(i.name, i.module);
+ if (sdl.trackpad) |object| {
+ gm.addObjectFile(object);
gm.linkFramework("Cocoa", .{});
}
}
- const ft = c.freetype orelse continue;
+ const ft = w.freetype orelse return;
gm.linkLibrary(ft);
- // HarfBuzz from source, like FreeType: its FreeType integration
- // (HAVE_FREETYPE, hb-ft) links the freetype artifact above, so the two
- // share one FreeType. The flags are the ones Ghostty builds it with,
- // plus its allocator: gui.zig's ui_malloc and friends, over a Zig
- // allocator, as FreeType's is.
- if (b.lazyDependency("harfbuzz", .{})) |upstream| {
- const harfbuzz = b.addLibrary(.{
- .name = "harfbuzz",
- .linkage = .static,
- .root_module = b.createModule(.{
- .target = c.target,
- .optimize = c.optimize,
- .link_libc = true,
- .link_libcpp = true,
- }),
- });
- harfbuzz.root_module.linkLibrary(ft);
- harfbuzz.root_module.addIncludePath(upstream.path("src"));
- harfbuzz.root_module.addCSourceFile(.{
- .file = upstream.path("src/harfbuzz.cc"),
- .flags = &.{
- "-DHAVE_STDBOOL_H",
- "-DHAVE_UNISTD_H",
- "-DHAVE_SYS_MMAN_H",
- "-DHAVE_PTHREAD=1",
- "-DHAVE_FREETYPE=1",
- "-DHAVE_FT_GET_VAR_BLEND_COORDINATES=1",
- "-DHAVE_FT_SET_VAR_BLEND_COORDINATES=1",
- "-DHAVE_FT_DONE_MM_VAR=1",
- "-DHAVE_FT_GET_TRANSFORM=1",
- "-Dhb_malloc_impl=ui_malloc",
- "-Dhb_calloc_impl=ui_calloc",
- "-Dhb_realloc_impl=ui_realloc",
- "-Dhb_free_impl=ui_free",
- },
- });
- gm.linkLibrary(harfbuzz);
- gm.addIncludePath(upstream.path("src"));
- // The Atlas's own tests, over the same FreeType, HarfBuzz and
- // shim, the embedded face theirs to draw.
- if (atlas_test == null) if (font_c) |fc| if (b.lazyDependency("sketchbook", .{ .@"gpu-only" = true })) |sb| {
- const atlas_mod = b.createModule(.{ .root_source_file = sb.path("src/font/Atlas.zig"), .target = c.target, .optimize = c.optimize, .link_libc = true, .imports = &.{.{ .name = "c", .module = fc }} });
- atlas_mod.linkLibrary(ft);
- atlas_mod.linkLibrary(harfbuzz);
- atlas_mod.addIncludePath(upstream.path("src"));
- atlas_mod.addCSourceFile(.{ .file = sb.path("vendor/font.c") });
- atlas_mod.addAnonymousImport("AdwaitaMono-Regular.ttf", .{ .root_source_file = b.path("assets/AdwaitaMono-Regular.ttf") });
- atlas_test = b.addTest(.{ .root_module = atlas_mod, .filters = c.test_filters });
- };
+ if (w.harfbuzz) |hb| {
+ gm.linkLibrary(hb.lib);
+ gm.addIncludePath(hb.include);
}
- if (c.target.result.os.tag.isDarwin())
+ if (w.darwin)
gm.addRPath(.{ .cwd_relative = "/usr/local/lib" });
- if (b.lazyDependency("sketchbook", .{ .@"gpu-only" = true })) |sb| gm.addCSourceFile(.{ .file = sb.path("vendor/font.c") });
+ if (w.sketchbook) |sb| gm.addCSourceFile(.{ .file = sb.path("vendor/font.c") });
// the embedded UI font: provided as a build import since assets/ lives
// outside the src/ module root (@embedFile can't escape it)
gm.addAnonymousImport("AdwaitaMono-Regular.ttf", .{
.root_source_file = b.path("assets/AdwaitaMono-Regular.ttf"),
});
- };
- if (c.target.result.os.tag == .macos) if (sdl_include) |include| {
+ }
+};
+
+pub fn make(b: *std.Build, target: std.Build.ResolvedTarget, optimize: std.lang.Optimize, macos_sdk: ?[]const u8, prebuilt_shaders: bool, freetype: ?*std.Build.Step.Compile, test_filters: []const []const u8) Window {
+ const sketchbook = b.lazyDependency("sketchbook", .{ .@"gpu-only" = true });
+ var w: Window = .{ .sketchbook = sketchbook, .freetype = freetype, .darwin = target.result.os.tag.isDarwin() };
+ // SDL's build asks a cross build for macOS for the SDK's paths.
+ const sdk: ?std.Build.LazyPath = if (macos_sdk) |p| .{ .cwd_relative = p } else null;
+ const sdl_dep = b.lazyDependency("sdl", .{ .target = target, .optimize = optimize, .sanitize_c = .off, .preferred_linkage = .static, .system_include_path = if (sdk) |p| p.path(b, "usr/include") else null, .system_framework_path = if (sdk) |p| p.path(b, "System/Library/Frameworks") else null, .library_path = if (sdk) |p| p.path(b, "usr/lib") else null });
+ if (sdl_dep) |dep| {
+ const sdl_lib = dep.artifact("SDL3");
+ // SDL's own stb_image (SDL_stb.c, for SDL_LoadPNG and a camera's
+ // MJPEG, neither of which pardes calls) is a second PNG and JPEG
+ // decoder beside the build's: off (docs/shared-libs.md).
+ sdl_lib.root_module.addCMacro("SDL_DISABLE_STB", "1");
+ // gui.zig's `c`: SDL and the font shim, which @cImport gave it before Zig 0.17.
+ const header = b.addWriteFiles().add("gui_c.h",
+ \\#define SDL_DISABLE_OLD_NAMES 1
+ \\#include <SDL3/SDL.h>
+ \\#include "font.h"
+ \\#include "macos_trackpad.h"
+ \\
+ );
+ const gui_c = b.addTranslateC(.{ .root_source_file = header, .target = target, .optimize = optimize });
+ gui_c.addIncludePath(dep.path("include"));
+ gui_c.addIncludePath(b.path("src/gui"));
+ const gui_c_mod = gui_c.createModule();
+ var sdl: Window.Sdl = .{ .lib = sdl_lib, .include = dep.path("include"), .gui_c = gui_c_mod };
+ if (sketchbook) |sb| {
+ const gpu = b.createModule(.{ .root_source_file = sb.path("src/gpu/Executor.zig"), .imports = &.{ .{ .name = "abi", .module = sb.module("abi") }, .{ .name = "c", .module = gui_c_mod } } });
+ // The glyph atlas (src/font/Atlas.zig) over the font shim
+ // (vendor/font.{c,h}), compiled below against pardes's
+ // FreeType and HarfBuzz.
+ const atlas_mod = b.createModule(.{ .root_source_file = sb.path("src/font/Atlas.zig"), .imports = &.{.{ .name = "c", .module = gui_c_mod }} });
+ // pardes's renderer, moved to sketchbook (src/gpu/), compiled
+ // against pardes's SDL; its tests run with unit-test. Its
+ // SPIR-V is sketchbook's GLSL through glslc, or the prebuilt
+ // copies with -Dprebuilt-shaders.
+ const cells_mod = b.createModule(.{ .root_source_file = sb.path("src/gpu/Cells.zig"), .imports = &.{ .{ .name = "c", .module = gui_c_mod }, .{ .name = "font_atlas", .module = atlas_mod } } });
+ for (gui_shaders) |name| cells_mod.addAnonymousImport(b.fmt("{s}.spv", .{name}), .{
+ .root_source_file = if (prebuilt_shaders)
+ sb.path(b.fmt("src/gpu/shaders/prebuilt/{s}.spv", .{name}))
+ else
+ compileGlsl(b, sb.path(b.fmt("src/gpu/shaders/{s}.glsl", .{name})), name),
+ });
+ const present = b.createModule(.{ .root_source_file = sb.path("src/gpu/Present.zig"), .imports = &.{ .{ .name = "c", .module = gui_c_mod }, .{ .name = "gpu_cells", .module = cells_mod } } });
+ sdl.renderer = .{ .{ .name = "sketch_gpu", .module = gpu }, .{ .name = "font_atlas", .module = atlas_mod }, .{ .name = "gpu_cells", .module = cells_mod }, .{ .name = "gpu_present", .module = present }, .{ .name = "gpu_scene", .module = sb.module("gpu_scene") } };
+ w.cells_test = b.addTest(.{ .root_module = b.createModule(.{ .root_source_file = sb.path("src/gpu/Cells.zig"), .target = target, .optimize = optimize, .imports = &.{ .{ .name = "c", .module = gui_c_mod }, .{ .name = "font_atlas", .module = atlas_mod } } }), .filters = test_filters });
+ gui_c.addIncludePath(sb.path("vendor"));
+ }
+ if (target.result.os.tag == .macos) {
+ const arch = if (target.result.cpu.arch == .aarch64) "arm64" else @tagName(target.result.cpu.arch);
+ const shim = b.addSystemCommand(&.{ "xcrun", "clang", "-fobjc-arc", "-O2", "-target", b.fmt("{s}-apple-macos13.0", .{arch}), "-I" });
+ shim.addDirectoryArg(dep.path("include"));
+ shim.addArg("-c");
+ shim.addFileArg(b.path("src/gui/macos_trackpad.m"));
+ // Header changes invalidate the independently compiled adapter.
+ shim.addFileInput(b.path("src/gui/macos_trackpad.h"));
+ shim.addArg("-o");
+ sdl.trackpad = shim.addOutputFileArg("macos_trackpad.o");
+ }
+ w.sdl = sdl;
+ }
+ const ft = freetype orelse return w;
+ // HarfBuzz from source, like FreeType: its FreeType integration
+ // (HAVE_FREETYPE, hb-ft) links the freetype artifact above, so the two
+ // share one FreeType. The flags are the ones Ghostty builds it with,
+ // plus its allocator: gui.zig's ui_malloc and friends, over a Zig
+ // allocator, as FreeType's is.
+ if (b.lazyDependency("harfbuzz", .{})) |upstream| {
+ const harfbuzz = b.addLibrary(.{
+ .name = "harfbuzz",
+ .linkage = .static,
+ .root_module = b.createModule(.{
+ .target = target,
+ .optimize = optimize,
+ .link_libc = true,
+ .link_libcpp = true,
+ }),
+ });
+ harfbuzz.root_module.linkLibrary(ft);
+ harfbuzz.root_module.addIncludePath(upstream.path("src"));
+ harfbuzz.root_module.addCSourceFile(.{
+ .file = upstream.path("src/harfbuzz.cc"),
+ .flags = &.{
+ "-DHAVE_STDBOOL_H",
+ "-DHAVE_UNISTD_H",
+ "-DHAVE_SYS_MMAN_H",
+ "-DHAVE_PTHREAD=1",
+ "-DHAVE_FREETYPE=1",
+ "-DHAVE_FT_GET_VAR_BLEND_COORDINATES=1",
+ "-DHAVE_FT_SET_VAR_BLEND_COORDINATES=1",
+ "-DHAVE_FT_DONE_MM_VAR=1",
+ "-DHAVE_FT_GET_TRANSFORM=1",
+ "-Dhb_malloc_impl=ui_malloc",
+ "-Dhb_calloc_impl=ui_calloc",
+ "-Dhb_realloc_impl=ui_realloc",
+ "-Dhb_free_impl=ui_free",
+ },
+ });
+ w.harfbuzz = .{ .lib = harfbuzz, .include = upstream.path("src") };
+ // The Atlas's own tests, over the same FreeType, HarfBuzz and
+ // shim, the embedded face theirs to draw.
+ if (w.sdl) |sdl| if (sketchbook) |sb| {
+ const atlas_mod = b.createModule(.{ .root_source_file = sb.path("src/font/Atlas.zig"), .target = target, .optimize = optimize, .link_libc = true, .imports = &.{.{ .name = "c", .module = sdl.gui_c }} });
+ atlas_mod.linkLibrary(ft);
+ atlas_mod.linkLibrary(harfbuzz);
+ atlas_mod.addIncludePath(upstream.path("src"));
+ atlas_mod.addCSourceFile(.{ .file = sb.path("vendor/font.c") });
+ atlas_mod.addAnonymousImport("AdwaitaMono-Regular.ttf", .{ .root_source_file = b.path("assets/AdwaitaMono-Regular.ttf") });
+ w.atlas_test = b.addTest(.{ .root_module = atlas_mod, .filters = test_filters });
+ };
+ }
+ if (target.result.os.tag == .macos) if (w.sdl) |sdl| {
const adapter_test = b.addSystemCommand(&.{ "xcrun", "clang", "-fobjc-arc", "-O1", "-framework", "Cocoa", "-I" });
- adapter_test.addDirectoryArg(include);
+ adapter_test.addDirectoryArg(sdl.include);
adapter_test.addFileArg(b.path("test/macos_trackpad.m"));
adapter_test.addFileInput(b.path("src/gui/macos_trackpad.m"));
adapter_test.addFileInput(b.path("src/gui/macos_trackpad.h"));
@@ -178,7 +191,7 @@ pub fn add(b: *std.Build, c: struct {
run_adapter.has_side_effects = true;
b.step("macos-trackpad-test", "test native SDL trackpad decoding and haptics without hardware").dependOn(&run_adapter.step);
};
- return .{ .cells_test = cells_test, .atlas_test = atlas_test };
+ return w;
}
/// glslc <glsl> -fshader-stage=<vertex|fragment> -o <name>.spv, returned as
diff --git a/build/library.zig b/build/library.zig
index dcbb8938..7bcd6c5c 100644
--- a/build/library.zig
+++ b/build/library.zig
@@ -22,25 +22,14 @@ pub fn build(b: *std.Build) void {
.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));
+ // A library's options: its grammars, nothing stamped, no window.
+ const cfg: core.ShellConfig = .{ .tree_sitter_grammars = tree_sitter_grammars };
+ mod.addOptions("pardes_config", core.shellOptions(b, cfg, .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") }),
- });
+ mod.addImport("generated_themes", themes);
+ ts.wire(mod);
+ mod.addImport("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.
@@ -56,14 +45,5 @@ pub fn build(b: *std.Build) void {
.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 });
+ _ = core.editorModule(b, "pardes-editor", target, optimize, cfg, .{ .themes = themes, .ts = ts, .uucode = uucode, .mvzr = mvzr, .vaxis = vaxis });
}
diff --git a/build/process.zig b/build/process.zig
index 1968aaab..16f9b48b 100644
--- a/build/process.zig
+++ b/build/process.zig
@@ -6,6 +6,8 @@ const std = @import("std");
/// window's own, run in full when asked.
pub fn add(b: *std.Build, opts: struct {
exe: *std.Build.Step.Compile,
+ /// The language server a tty case's `.rs` files speak to (test/lspmock.zig).
+ lspmock: *std.Build.Step.Compile,
/// The addons the build made (image, pdf), which every session loads:
/// each `--addon=<lib>`, linked into its data directory's addons.
addons: []const *std.Build.Step.Compile,
@@ -23,16 +25,6 @@ pub fn add(b: *std.Build, opts: struct {
.link_libc = true,
});
ninep_client.addImport("cloud9", opts.cloud9);
- // The language server a tty case's `.rs` files speak to.
- const lspmock = b.addExecutable(.{
- .name = "pardes-lspmock",
- .root_module = b.createModule(.{
- .target = opts.target,
- .optimize = opts.optimize,
- .root_source_file = b.path("test/lspmock.zig"),
- .link_libc = true,
- }),
- });
const process_test = b.addExecutable(.{
.name = "pardes-process-test",
.root_module = b.createModule(.{
@@ -52,7 +44,7 @@ pub fn add(b: *std.Build, opts: struct {
const run_process_test = b.addRunArtifact(process_test);
run_process_test.addArtifactArg(opts.exe);
for (opts.addons) |a| run_process_test.addPrefixedFileArg("--addon=", a.getEmittedBin());
- run_process_test.addPrefixedFileArg("--lspmock=", lspmock.getEmittedBin());
+ run_process_test.addPrefixedFileArg("--lspmock=", opts.lspmock.getEmittedBin());
run_process_test.addArg(if (opts.gui) "--backend=gui" else "--backend=tui");
run_process_test.addPassthruArgs();
// The tty cases' goldens are test/snapshots/'s, from the build root.
diff --git a/build/tests.zig b/build/tests.zig
index 9d4399f8..efb3515f 100644
--- a/build/tests.zig
+++ b/build/tests.zig
@@ -1,5 +1,8 @@
const std = @import("std");
const Platform = @import("../build.zig").Platform;
+const core = @import("core.zig");
+const tools = @import("tools.zig");
+const program = tools.program;
/// unit-test and the test roots it runs, each with its own step where it
/// has one: core-test, shell-test, term-test, pane-test, behaviour-test,
@@ -8,29 +11,27 @@ pub fn add(b: *std.Build, c: struct {
addon_mod: *std.Build.Module,
atlas_test: ?*std.Build.Step.Compile,
cells_test: ?*std.Build.Step.Compile,
- cloud9: *std.Build.Module,
core_lean: *std.Build.Module,
core_module: *std.Build.Module,
+ /// core_module's configuration, for the test roots that run on its imports.
+ core_cfg: core.Core,
exe: *std.Build.Step.Compile,
- fs_bench_test: *std.Build.Step.Compile,
ghostty_vt_for_tests: ?*std.Build.Module,
image_addon: *std.Build.Step.Compile,
- image_mod: *std.Build.Module,
- lib_test_step: *std.Build.Step,
+ /// The scripted language server the sessions' language words ask.
+ lspmock: *std.Build.Step.Compile,
mupdf_check: *std.Build.Step,
optimize: std.lang.Optimize,
+ parts: core.Parts,
pdf_addon: ?*std.Build.Step.Compile,
- perf_gate_step: *std.Build.Step,
- perf_tests: *std.Build.Step.Compile,
- plain_mod: *std.Build.Module,
platform: Platform,
root_mod: *std.Build.Module,
snake_shader_lib: ?*std.Build.Step.Compile,
target: std.Build.ResolvedTarget,
- term_mod: *std.Build.Module,
test_build: *std.Build.Step,
test_filters: []const []const u8,
test_nonce: ?*std.Build.Module,
+ tools: tools.Tools,
unit_profile: *std.Build.Step.Compile,
}) void {
const unit_step = b.step("unit-test", "run native shell and module unit tests");
@@ -55,12 +56,12 @@ pub fn add(b: *std.Build, c: struct {
}
// The perf gate runs with every unit-test (a regression like a
// contrast search per grapheme costs 100x, far past the gate).
- unit_step.dependOn(c.perf_gate_step);
- unit_step.dependOn(c.lib_test_step);
+ unit_step.dependOn(c.tools.perf_gate_step);
+ unit_step.dependOn(c.tools.lib_test_step);
const units: Units = .{ .nonce = c.test_nonce, .build = c.test_build, .unit = unit_step, .match = testMatch(b, c.unit_profile, c.test_filters, unit_step), .profiler = c.unit_profile, .filters = c.test_filters };
// The perf and fs bench programs' own tests: they compile no editor.
- _ = units.add(b, c.perf_tests, null);
- _ = units.add(b, c.fs_bench_test, null);
+ _ = units.add(b, c.tools.perf_tests, null);
+ _ = units.add(b, c.tools.fs_bench_test, null);
if (c.cells_test) |t| _ = units.add(b, t, null);
if (c.atlas_test) |t| _ = units.add(b, t, null);
const core_test = b.addTest(.{ .root_module = c.core_lean, .filters = c.test_filters });
@@ -70,7 +71,7 @@ pub fn add(b: *std.Build, c: struct {
core_test_step.dependOn(&run_core_test.step);
if (testMatch(b, c.unit_profile, c.test_filters, core_test_step)) |check| check.addArtifactArg(core_test);
// The terminal module's own tests (src/term/): the emulator without a core.
- const run_term_test = units.add(b, b.addTest(.{ .root_module = c.term_mod, .filters = c.test_filters }), null);
+ const run_term_test = units.add(b, b.addTest(.{ .root_module = c.parts.term, .filters = c.test_filters }), null);
b.step("term-test", "run the terminal module's own tests (src/term/)").dependOn(&run_term_test.step);
const pane_module = b.createModule(.{
.target = c.target,
@@ -80,9 +81,11 @@ pub fn add(b: *std.Build, c: struct {
});
pane_module.addImport("pardes", c.core_module);
// test/terminal.zig reads the emulator behind a core's terminal.
- pane_module.addImport("term", c.term_mod);
- pane_module.addImport("plain", c.plain_mod);
+ pane_module.addImport("term", c.parts.term);
+ pane_module.addImport("plain", c.parts.plain);
if (c.ghostty_vt_for_tests) |x| pane_module.addImport("ghostty-vt", x);
+ // The core's own options module, not another over the same file:
+ // a file is in one module of a compilation.
pane_module.addImport("pardes_config", c.core_module.import_table.get("pardes_config").?);
const test_addons = b.addOptions();
test_addons.addOptionPath("image", c.image_addon.getEmittedBin());
@@ -104,15 +107,7 @@ pub fn add(b: *std.Build, c: struct {
// The scripted language server its language words ask
// (Session.initLanguage), as the tty cases do.
const session_options = b.addOptions();
- session_options.addOptionPath("lspmock", b.addExecutable(.{
- .name = "pardes-lspmock",
- .root_module = b.createModule(.{
- .target = c.target,
- .optimize = c.optimize,
- .root_source_file = b.path("test/lspmock.zig"),
- .link_libc = true,
- }),
- }).getEmittedBin());
+ session_options.addOptionPath("lspmock", c.lspmock.getEmittedBin());
var fake_addon_lib: ?*std.Build.Step.Compile = null;
// The fake addon (addons/fake/fake.c) and three copies of it built
// wrong, which the loader must refuse (test/behaviour/addons.zig).
@@ -156,7 +151,7 @@ pub fn add(b: *std.Build, c: struct {
const snake_lib = b.addLibrary(.{ .name = "snake", .linkage = .dynamic, .root_module = snake_mod });
const life_mod = b.createModule(.{ .root_source_file = b.path("addons/life/life.zig"), .target = c.target, .optimize = c.optimize, .imports = &.{.{ .name = "addon", .module = c.addon_mod }} });
const life_lib = b.addLibrary(.{ .name = "life", .linkage = .dynamic, .root_module = life_mod });
- for ([_]*std.Build.Module{ snake_mod, life_mod, c.image_mod }) |m| addon_test_step.dependOn(&b.addRunArtifact(b.addTest(.{ .root_module = m })).step);
+ for ([_]*std.Build.Module{ snake_mod, life_mod, c.parts.image }) |m| addon_test_step.dependOn(&b.addRunArtifact(b.addTest(.{ .root_module = m })).step);
// ...and the pdf addon's, which mupdf-check runs too (its script
// opens docs/design.pdf, from the build root).
const libs = [_]struct { ?*std.Build.Step.Compile, []const u8 }{ .{ fake_addon_lib.?, "addons/fake/fake" }, .{ snake_lib, "addons/snake/snake" }, .{ c.snake_shader_lib, "addons/snake_shader/snake_shader" }, .{ life_lib, "addons/life/life" }, .{ c.pdf_addon, "addons/pdf/pdf" } };
@@ -178,16 +173,7 @@ pub fn add(b: *std.Build, c: struct {
// after each, random input hunting panics (`-- --monkey <seeds>`),
// and its seeds' tapes replayed (`-- --replay`). Bare, a short
// fixed-seed run of the first, part of behaviour-test.
- const t1_runner = b.addExecutable(.{
- .name = "pardes-monkey-session",
- .root_module = b.createModule(.{
- .target = c.target,
- .optimize = c.optimize,
- .root_source_file = b.path("test/monkey9p.zig"),
- .link_libc = true,
- }),
- });
- t1_runner.root_module.addImport("session", session_module);
+ const t1_runner = program(b, "pardes-monkey-session", "test/monkey9p.zig", c.target, c.optimize, &.{.{ .name = "session", .module = session_module }});
const run_t1_runner = b.addRunArtifact(t1_runner);
run_t1_runner.addPassthruArgs();
run_t1_runner.has_side_effects = true;
@@ -215,10 +201,9 @@ pub fn add(b: *std.Build, c: struct {
.{ .path = "src/9p_io.zig", .step = "9p-io-test", .about = "run native 9P transport and client integration tests", .filters = &.{ "Unix and TCP", "one fetch", "expired sessions", "posts itself" } },
.{ .path = "src/fs.zig", .step = "fs-unit-test", .about = "run filesystem unit tests", .filters = c.test_filters },
}) |t| {
- const m = b.createModule(.{ .root_source_file = b.path(t.path), .target = c.target, .optimize = c.optimize, .link_libc = true });
- m.link_objects.appendSlice(b.allocator, c.core_module.link_objects.items) catch @panic("OOM");
- var imports = c.core_module.import_table.iterator();
- while (imports.next()) |entry| m.addImport(entry.key_ptr.*, entry.value_ptr.*);
+ var cfg = c.core_cfg;
+ cfg.root = t.path;
+ const m = core.module(b, c.parts, cfg);
b.step(t.step, t.about).dependOn(&b.addRunArtifact(b.addTest(.{ .root_module = m, .filters = t.filters })).step);
}
@@ -241,7 +226,7 @@ pub fn add(b: *std.Build, c: struct {
}),
.filters = c.test_filters,
});
- tests.root_module.addImport("cloud9", c.cloud9);
+ tests.root_module.addImport("cloud9", c.parts.cloud9);
const run_tests = units.add(b, tests, null);
if (std.mem.eql(u8, entry.path, "src/9p.zig")) {
protocol_step.dependOn(&run_tests.step);
diff --git a/build/tools.zig b/build/tools.zig
index 0819401c..4393e088 100644
--- a/build/tools.zig
+++ b/build/tools.zig
@@ -6,6 +6,12 @@ const TreeSitterGrammars = @import("../build.zig").TreeSitterGrammars;
const core = @import("core.zig");
const testMatch = @import("tests.zig").testMatch;
+/// A program of this build's, from `root`, with libc and `imports`: the
+/// harnesses, benches and runners below and in tests.zig.
+pub fn program(b: *std.Build, name: []const u8, root: []const u8, target: std.Build.ResolvedTarget, optimize: std.lang.Optimize, imports: []const std.Build.Module.Import) *std.Build.Step.Compile {
+ return b.addExecutable(.{ .name = name, .root_module = b.createModule(.{ .target = target, .optimize = optimize, .root_source_file = b.path(root), .link_libc = true, .imports = imports }) });
+}
+
/// What unit-test runs of what these make.
pub const Tools = struct {
perf_gate_step: *std.Build.Step,
@@ -17,7 +23,6 @@ pub const Tools = struct {
/// The harnesses, the helix comparisons, the benches and the perf gate, the
/// syntax snapshots and their tests, the library's package test and history.
pub fn add(b: *std.Build, c: struct {
- c_heap_mod: *std.Build.Module,
c_optimize: std.lang.Optimize,
core_module: *std.Build.Module,
enable_jpx: bool,
@@ -26,36 +31,22 @@ pub fn add(b: *std.Build, c: struct {
ghostty_simd: bool,
ghostty_vt_for_tests: ?*std.Build.Module,
image_addon: *std.Build.Step.Compile,
- mvzr_mod: *std.Build.Module,
+ /// core-test's core: the syntax module's tests run on it.
+ lean: core.Core,
no_pdf: ?*std.Build.Step,
optimize: std.lang.Optimize,
- opts: *std.Build.Step.Options,
+ parts: core.Parts,
pdf_addon: ?*std.Build.Step.Compile,
platform: Platform,
prebuilt_shaders: bool,
shell_cfg: core.ShellConfig,
target: std.Build.ResolvedTarget,
- term_mod: *std.Build.Module,
test_filters: []const []const u8,
- themes_mod: *std.Build.Module,
tracy: ?[]const u8,
tree_sitter_grammars: TreeSitterGrammars,
- ts_libs: std.ArrayList(*std.Build.Step.Compile),
- ts_mod: ?*std.Build.Module,
- ts_queries_opts: ?*std.Build.Step.Options,
unit_profile: *std.Build.Step.Compile,
- uucode_mod: *std.Build.Module,
- vaxis_mod: *std.Build.Module,
}) Tools {
- const image_harness = b.addExecutable(.{
- .name = "pardes-image-harness",
- .root_module = b.createModule(.{
- .target = c.target,
- .optimize = c.optimize,
- .root_source_file = b.path("test/image_harness.zig"),
- .link_libc = true,
- }),
- });
+ const image_harness = program(b, "pardes-image-harness", "test/image_harness.zig", c.target, c.optimize, &.{});
if (c.ghostty_vt_for_tests) |vt| image_harness.root_module.addImport("ghostty-vt", vt);
switch (c.target.result.os.tag) {
.freebsd, .netbsd, .openbsd => image_harness.root_module.linkSystemLibrary("util", .{}),
@@ -72,24 +63,8 @@ pub fn add(b: *std.Build, c: struct {
// the pane's bash (and kitten icat, chafa when installed), a kitty
// terminal outside (tui) or the GPU capture (gui). test/kitty.zig
// is the same protocol at the core.
- const kitty_client = b.addExecutable(.{
- .name = "pardes-kitty-client",
- .root_module = b.createModule(.{
- .target = c.target,
- .optimize = c.optimize,
- .root_source_file = b.path("test/kitty_client.zig"),
- .link_libc = true,
- }),
- });
- const kitty_harness = b.addExecutable(.{
- .name = "pardes-kitty-harness",
- .root_module = b.createModule(.{
- .target = c.target,
- .optimize = c.optimize,
- .root_source_file = b.path("test/kitty_harness.zig"),
- .link_libc = true,
- }),
- });
+ const kitty_client = program(b, "pardes-kitty-client", "test/kitty_client.zig", c.target, c.optimize, &.{});
+ const kitty_harness = program(b, "pardes-kitty-harness", "test/kitty_harness.zig", c.target, c.optimize, &.{});
if (c.ghostty_vt_for_tests) |vt| kitty_harness.root_module.addImport("ghostty-vt", vt);
switch (c.target.result.os.tag) {
.freebsd, .netbsd, .openbsd => kitty_harness.root_module.linkSystemLibrary("util", .{}),
@@ -114,16 +89,7 @@ pub fn add(b: *std.Build, c: struct {
pdf_harness_step.dependOn(&run_pdf_harness.step);
}
- const hxdiff = b.addExecutable(.{
- .name = "pardes-hxdiff",
- .root_module = b.createModule(.{
- .target = c.target,
- .optimize = c.optimize,
- .root_source_file = b.path("test/hxdiff.zig"),
- .link_libc = true,
- }),
- });
- hxdiff.root_module.addImport("pardes", c.core_module);
+ const hxdiff = program(b, "pardes-hxdiff", "test/hxdiff.zig", c.target, c.optimize, &.{.{ .name = "pardes", .module = c.core_module }});
const run_hxdiff = b.addRunArtifact(hxdiff);
run_hxdiff.has_side_effects = true;
// Bare, it runs the checked-in suite (test/hxdiff.zig); `-- --parity`
@@ -145,24 +111,8 @@ pub fn add(b: *std.Build, c: struct {
// types them into an editor value and prints its results, which
// hxdiff holds against helix's goldens, or with `-- --parity`
// against the file pane, so the library cannot drift from either.
- const hxlib = b.addExecutable(.{
- .name = "pardes-hxlib",
- .root_module = b.createModule(.{
- .target = c.target,
- .optimize = c.optimize,
- .root_source_file = b.path("test/hxlib.zig"),
- .link_libc = true,
- }),
- });
- hxlib.root_module.addImport("pardes-editor", core.editorModule(b, null, c.target, c.optimize, c.shell_cfg, .{
- .themes = c.themes_mod,
- .tree_sitter = c.ts_mod,
- .ts_libs = c.ts_libs.items,
- .ts_queries = c.ts_queries_opts,
- .uucode = c.uucode_mod,
- .mvzr = c.mvzr_mod,
- .vaxis = c.vaxis_mod,
- }));
+ const hxlib = program(b, "pardes-hxlib", "test/hxlib.zig", c.target, c.optimize, &.{});
+ hxlib.root_module.addImport("pardes-editor", core.editorModule(b, null, c.target, c.optimize, c.shell_cfg, .{ .themes = c.parts.themes, .ts = c.parts.ts, .uucode = c.parts.uucode, .mvzr = c.parts.mvzr, .vaxis = c.parts.vaxis }));
const run_hxlib = b.addRunArtifact(hxlib);
run_hxlib.addArgs(&.{ "test/hxcases/cases.jsonl", "test/hxcases/parity.jsonl" });
run_hxlib.setCwd(b.path("."));
@@ -199,16 +149,7 @@ pub fn add(b: *std.Build, c: struct {
run_hxgolf.setCwd(b.path("."));
b.step("hxgolf", "compare the helix-golf examples against their Helix results").dependOn(&run_hxgolf.step);
- const lspbench = b.addExecutable(.{
- .name = "pardes-lspbench",
- .root_module = b.createModule(.{
- .target = c.target,
- .optimize = .fast,
- .root_source_file = b.path("test/lspbench.zig"),
- .link_libc = true,
- }),
- });
- lspbench.root_module.addImport("pardes", c.core_module);
+ const lspbench = program(b, "pardes-lspbench", "test/lspbench.zig", c.target, .fast, &.{.{ .name = "pardes", .module = c.core_module }});
const run_lspbench = b.addRunArtifact(lspbench);
run_lspbench.addPassthruArgs();
run_lspbench.setCwd(b.path("."));
@@ -216,21 +157,12 @@ pub fn add(b: *std.Build, c: struct {
const lspbench_step = b.step("lspbench", "language-backend latency + feature matrix (-- [--json] [--check] [repo-root]), or one query (-- probe <kind> <file> <line>:<col> [arg] [--reps N])");
lspbench_step.dependOn(&run_lspbench.step);
- const rollback_bench = b.addExecutable(.{
- .name = "pardes-rollback-bench",
- .root_module = b.createModule(.{ .target = c.target, .optimize = c.optimize, .root_source_file = b.path("test/rollback_bench.zig"), .link_libc = true }),
- });
- rollback_bench.root_module.addImport("pardes", c.core_module);
+ const rollback_bench = program(b, "pardes-rollback-bench", "test/rollback_bench.zig", c.target, c.optimize, &.{.{ .name = "pardes", .module = c.core_module }});
const run_rollback_bench = b.addRunArtifact(rollback_bench);
run_rollback_bench.has_side_effects = true;
b.step("rollback-bench", "a replica's rollback copy (walked state, pinned blobs, walk time) for a typical and a big session, and a fork of the big one (-Doptimize=ReleaseFast)").dependOn(&run_rollback_bench.step);
- const replicas = b.addExecutable(.{
- .name = "pardes-replicas",
- .root_module = b.createModule(.{ .target = c.target, .optimize = c.optimize, .root_source_file = b.path("test/replicas.zig"), .link_libc = true }),
- });
- replicas.root_module.addImport("pardes", c.core_module);
- replicas.root_module.addImport("term", c.term_mod);
+ const replicas = program(b, "pardes-replicas", "test/replicas.zig", c.target, c.optimize, &.{ .{ .name = "pardes", .module = c.core_module }, .{ .name = "term", .module = c.parts.term } });
const run_replicas = b.addRunArtifact(replicas);
run_replicas.addPassthruArgs();
run_replicas.has_side_effects = true;
@@ -275,16 +207,7 @@ pub fn add(b: *std.Build, c: struct {
perf_options.addOptionPath("image_addon", c.image_addon.getEmittedBin());
perf_options.addOption(bool, "has_pdf_addon", c.pdf_addon != null);
if (c.pdf_addon) |l| perf_options.addOptionPath("pdf_addon", l.getEmittedBin());
- const perf = b.addExecutable(.{
- .name = "pardes-perf",
- .root_module = b.createModule(.{
- .target = c.target,
- .optimize = perf_optimize,
- .root_source_file = b.path("test/perf.zig"),
- .link_libc = true,
- }),
- });
- perf.root_module.addImport("pardes", c.core_module);
+ const perf = program(b, "pardes-perf", "test/perf.zig", c.target, perf_optimize, &.{.{ .name = "pardes", .module = c.core_module }});
// --live drives the real binary through a pty (test/e2e_harness.zig).
if (c.ghostty_vt_for_tests) |vt| perf.root_module.addImport("ghostty-vt", vt);
perf.root_module.addOptions("perf_options", perf_options);
@@ -317,16 +240,7 @@ pub fn add(b: *std.Build, c: struct {
});
perf_tests.root_module.addOptions("perf_options", perf_options);
- const fs_bench = b.addExecutable(.{
- .name = "pardes-fs-bench",
- .root_module = b.createModule(.{
- .target = c.target,
- .optimize = .fast,
- .root_source_file = b.path("test/fs_bench.zig"),
- .link_libc = true,
- }),
- });
- fs_bench.root_module.addImport("pardes", c.core_module);
+ const fs_bench = program(b, "pardes-fs-bench", "test/fs_bench.zig", c.target, .fast, &.{.{ .name = "pardes", .module = c.core_module }});
const run_fs_bench = b.addRunArtifact(fs_bench);
run_fs_bench.has_side_effects = true;
run_fs_bench.addPassthruArgs();
@@ -342,24 +256,12 @@ pub fn add(b: *std.Build, c: struct {
.filters = c.test_filters,
});
- const syntax_module = b.createModule(.{
- .target = c.target,
- .optimize = c.optimize,
- .root_source_file = b.path("src/syntax.zig"),
- .link_libc = true,
- });
- syntax_module.addOptions("pardes_config", c.opts);
- core.wireCore(syntax_module, .{ .tree_sitter = c.ts_mod, .ts_libs = c.ts_libs.items, .ts_queries = c.ts_queries_opts, .c_heap = c.c_heap_mod });
- const syntax_runner = b.addExecutable(.{
- .name = "pardes-syntax",
- .root_module = b.createModule(.{
- .target = c.target,
- .optimize = c.optimize,
- .root_source_file = b.path("test/syntax.zig"),
- .link_libc = true,
- }),
- });
- syntax_runner.root_module.addImport("syntax", syntax_module);
+ // The syntax module's own tests and snapshots, on the core without
+ // a terminal: its tests reach the editor's modes (modal.zig).
+ var syntax_cfg = c.lean;
+ syntax_cfg.root = "src/syntax.zig";
+ const syntax_module = core.module(b, c.parts, syntax_cfg);
+ const syntax_runner = program(b, "pardes-syntax", "test/syntax.zig", c.target, c.optimize, &.{.{ .name = "syntax", .module = syntax_module }});
const run_syntax = b.addRunArtifact(syntax_runner);
run_syntax.addPassthruArgs();
run_syntax.has_side_effects = true;
@@ -397,3 +299,23 @@ pub fn add(b: *std.Build, c: struct {
b.step("history", "compare command output and test/build runtime across jj revisions").dependOn(&run_history.step);
return .{ .perf_gate_step = perf_gate_step, .perf_tests = perf_tests, .fs_bench_test = fs_bench_test, .lib_test_step = lib_test_step };
}
+
+/// The PDF benches: the core over the pdf addon, a pane of it.
+pub fn pdfBenches(b: *std.Build, target: std.Build.ResolvedTarget, optimize: std.lang.Optimize, core_module: *std.Build.Module, lib: *std.Build.Step.Compile, pointer_step: *std.Build.Step, scroll_step: *std.Build.Step) void {
+ const config = b.addOptions();
+ config.addOption(bool, "release_fast_core", optimize == .fast);
+ config.addOption([]const u8, "core_optimize", @tagName(optimize));
+ config.addOptionPath("pdf_addon", lib.getEmittedBin());
+ for ([_]struct { step: *std.Build.Step, exe: []const u8, file: []const u8, optimize: std.lang.Optimize }{
+ .{ .step = pointer_step, .exe = "pardes-pdf-pointer-bench", .file = "test/pdf_pointer_bench.zig", .optimize = .fast },
+ .{ .step = scroll_step, .exe = "pardes-pdf-scroll-bench", .file = "test/pdf_scroll_bench.zig", .optimize = optimize },
+ }) |bench| {
+ const exe = b.addExecutable(.{ .name = bench.exe, .root_module = b.createModule(.{ .target = target, .optimize = bench.optimize, .root_source_file = b.path(bench.file), .link_libc = true }) });
+ exe.root_module.addImport("pardes", core_module);
+ exe.root_module.addOptions("pdf_bench_config", config);
+ const run = b.addRunArtifact(exe);
+ run.addPassthruArgs();
+ run.setCwd(b.path("."));
+ bench.step.dependOn(&run.step);
+ }
+}