summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--build.zig280
-rw-r--r--build/core.zig262
2 files changed, 308 insertions, 234 deletions
diff --git a/build.zig b/build.zig
index 0ef8c2f1..7ca241fb 100644
--- a/build.zig
+++ b/build.zig
@@ -1,8 +1,6 @@
const std = @import("std");
const builtin = @import("builtin");
const core = @import("build/core.zig");
-const patches = @import("build/patches.zig");
-const addons = @import("build/addons.zig");
const docs = @import("build/docs.zig");
const gui = @import("build/gui.zig");
const macos = @import("build/macos.zig");
@@ -108,34 +106,6 @@ pub fn build(b: *std.Build) void {
const macos_sdk = b.option([]const u8, "macos-sdk", "the macOS SDK a gui built for macOS from another system takes SDL's headers and frameworks from");
const macos_identity = b.option([]const u8, "macos-identity", "codesigning identity for pardes.app (default: ad-hoc)") orelse "-";
const prebuilt_shaders = b.option(bool, "prebuilt-shaders", "embed sketchbook's committed src/gpu/shaders/prebuilt/*.spv instead of running glslc over its GLSL (default: on for a bare `zig build`, off when -Dplatform names a shell)") orelse also_gui;
-
- const mupdf_check = b.step("mupdf-check", "the pdf addon's check: MuPDF compiles, links, renders and searches docs/design.pdf, and its script runs");
- const pdf_pointer_bench_step = b.step("pdf-pointer-bench", "time PDF hover and selection gestures and prove their pixels (-Doptimize=ReleaseFast -- [--label L] [--reps N] [--path FILE] [--cell WxH])");
- const pdf_scroll_bench_step = b.step("pdf-scroll-bench", "benchmark fast continuous-strip PDF scrolling in ReleaseFast (-Doptimize=ReleaseFast -- [--json] [--reps N] [--warmup N] [--path FILE])");
-
- // build-time IO: slurps the grammars' highlights.scm queries, and reads
- // vendor/themes to find the theme sources
- var threaded: std.Io.Threaded = .init(b.allocator, .{});
- defer threaded.deinit();
- const io = threaded.io();
-
- // 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
- // are asked for here in one round, the grammars with them, where each
- // `b.dependency` below would end the configure to fetch its own alone.
- const ts = core.treeSitter(b, io, target, c_optimize, tree_sitter_grammars);
- inline for (.{ "cloud9", "vaxis", "ghostty", "uucode", "zstbi", "mvzr", "zstd", "xitdb" }) |name| {
- // A dependency by path (none of these today) has no hash and is always there.
- const dep = @field(zon.dependencies, name);
- if (@hasField(@TypeOf(dep), "hash")) if (!std.Build.package_map.get(dep.hash).?.available) {
- _ = b.lazyDependency(name, .{});
- };
- }
- const cloud9 = b.dependency("cloud9", .{ .target = target, .optimize = optimize }).module("cloud9");
-
- const themes_mod = core.generatedThemes(b, io, target, optimize);
-
// 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)");
@@ -149,6 +119,20 @@ pub fn build(b: *std.Build) void {
// stamps one anyway.
const stamp_commit = b.option(bool, "stamp-commit", "embed the git commit in --version and crash records (default: release builds and the ~/.local install)") orelse
(optimize != .debug or home_install);
+ // MuPDF, and the FreeType and zlib it is built against, are lazy: a
+ // build asks for them only when it builds the pdf addon (or a window,
+ // FreeType). Zig 0.17's configure is told the -D options and never the
+ // steps asked for, so "the pdf step's" is an option, on once MuPDF is
+ // fetched (and off Linux, where the addons are compiled in): a fresh
+ // checkout's plain build fetches none of the three, and -Dpdf fetches
+ // MuPDF once.
+ const pdf = b.option(bool, "pdf", "build the pdf addon over MuPDF (default: on once MuPDF is fetched, as -Dpdf does)") orelse
+ (std.Build.package_map.get(zon.dependencies.mupdf.hash).?.available or target.result.os.tag != .linux);
+
+ const mupdf_check = b.step("mupdf-check", "the pdf addon's check: MuPDF compiles, links, renders and searches docs/design.pdf, and its script runs");
+ const pdf_pointer_bench_step = b.step("pdf-pointer-bench", "time PDF hover and selection gestures and prove their pixels (-Doptimize=ReleaseFast -- [--label L] [--reps N] [--path FILE] [--cell WxH])");
+ const pdf_scroll_bench_step = b.step("pdf-scroll-bench", "benchmark fast continuous-strip PDF scrolling in ReleaseFast (-Doptimize=ReleaseFast -- [--json] [--reps N] [--warmup N] [--path FILE])");
+
const shell_cfg: core.ShellConfig = .{
.tree_sitter_grammars = tree_sitter_grammars,
.tracy = tracy != null,
@@ -159,198 +143,26 @@ pub fn build(b: *std.Build) void {
.change = if (stamp_commit) core.jjChange(b) else null,
.built = if (stamp_commit) core.command(b, &.{ "date", "-u", "+%Y-%m-%d %H:%M UTC" }) else null,
};
- 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;
-
- 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
- // this test any longer": `a?` n times is 2^n steps), and pardes searches
- // with it holding the editor. Its matcher gets a step budget, patched into
- // the fetched source here at build time so that a fresh fetch keeps it:
- // each entry to matchPattern, which its backtracking recurses through,
- // spends a step, and with none left the match fails and says so
- // (src/regexp.zig). A bump that moves the anchor stops the build.
- const mvzr_mod = patches.mvzr(b, io, b.dependency("mvzr", .{ .target = target, .optimize = optimize }), target, optimize);
-
- // The C heap every C library with an allocator hook is handed: the core's
- // tree-sitter and fonts, and pdf.zig's MuPDF, which is a module of its own.
- const c_heap_mod = b.createModule(.{
+ // What every core is made of, the shells' options and the addons
+ // (build/core.zig).
+ const a = core.assemble(b, .{
.target = target,
.optimize = optimize,
- .root_source_file = b.path("src/c_heap.zig"),
- });
-
- // MuPDF, and the FreeType and zlib it is built against, are lazy: a
- // build asks for them only when it builds the pdf addon (or a window,
- // FreeType). Zig 0.17's configure is told the -D options and never the
- // steps asked for, so "the pdf step's" is an option, on once MuPDF is
- // fetched (and off Linux, where the addons are compiled in): a fresh
- // checkout's plain build fetches none of the three, and -Dpdf fetches
- // MuPDF once.
- const pdf = b.option(bool, "pdf", "build the pdf addon over MuPDF (default: on once MuPDF is fetched, as -Dpdf does)") orelse
- (std.Build.package_map.get(zon.dependencies.mupdf.hash).?.available or target.result.os.tag != .linux);
- const mupdf_dep = if (pdf) b.lazyDependency("mupdf", .{}) else null;
- // One FreeType in a binary: the gui's glyph atlas links it and MuPDF is
- // built against it (see build/mupdf.zig). At c_optimize with the rest of the
- // vendored C, since MuPDF rasterizes a PDF's text through it.
- const freetype_dep = if (pdf or also_gui or platform == .gui) b.lazyDependency("freetype", .{
- .target = target,
- .optimize = c_optimize,
- .@"enable-libpng" = false,
- }) else null;
- const freetype = if (freetype_dep) |d| d.artifact("freetype") else null;
-
- // The kinds' C ABI (src/kinds/pardes_addon.h), translated once: the core's
- // records are the header's, never a mirror of it.
- const kind_mod = b.addTranslateC(.{ .root_source_file = b.path("src/kinds/pardes_addon.h"), .target = target, .optimize = optimize }).createModule();
- // ...and what an addon in Zig imports over it (src/kinds/addon.zig).
- const addon_mod = b.createModule(.{ .root_source_file = b.path("src/kinds/addon.zig"), .target = target, .optimize = optimize, .imports = &.{.{ .name = "pardes_addon", .module = kind_mod }} });
- const snake_shader_lib = addons.gpu(b, target, optimize, addon_mod);
- const pdf_built = addons.pdf(b, .{
- .addon_mod = addon_mod,
.c_optimize = c_optimize,
+ .tree_sitter_grammars = tree_sitter_grammars,
+ .tracy = tracy,
+ .shell_cfg = shell_cfg,
+ .platform = platform,
+ .also_gui = also_gui,
+ .pdf = pdf,
.enable_jpx = enable_jpx,
- .freetype = freetype,
- .freetype_dep = freetype_dep,
- .io = io,
+ .doc_typ = doc_typ_opts,
.mupdf_check = mupdf_check,
- .mupdf_dep = mupdf_dep,
.pdf_pointer_bench_step = pdf_pointer_bench_step,
.pdf_scroll_bench_step = pdf_scroll_bench_step,
- .target = target,
- });
- const pdf_addon = pdf_built.lib;
- const no_pdf = pdf_built.no_pdf;
-
- const uucode_mod = core.uucodeModule(b, target, optimize).?;
-
- const vaxis_dep = b.dependency("vaxis", .{
- .target = target,
- .optimize = optimize,
- .external_uucode = true,
});
- const vaxis_mod = vaxis_dep.module("vaxis");
- patches.vaxis(b, io, vaxis_dep, vaxis_mod);
-
- var ghostty_vt_for_tests: ?*std.Build.Module = null;
- const ghostty_simd = !target.result.os.tag.isDarwin() or b.graph.host.result.os.tag.isDarwin();
- const ghostty_optimize: std.lang.Optimize = if (optimize == .debug) .safe else optimize;
- const ghostty_dep = b.lazyDependency("ghostty", .{ .target = target, .optimize = ghostty_optimize, .simd = ghostty_simd, .@"app-runtime" = .none, .@"emit-xcframework" = false });
- if (ghostty_dep) |dep| {
- const ghostty_vt = dep.module("ghostty-vt");
- ghostty_vt_for_tests = ghostty_vt;
- ghostty_vt.addImport("uucode", uucode_mod);
- patches.ghosttyKitty(b, io, dep, ghostty_vt);
- }
- // override uucode on vaxis LAST so it wins over ghostty's build() wiring.
- vaxis_mod.addImport("uucode", uucode_mod);
-
- // One PNG decoder (docs/shared-libs.md): ghostty's, wuffs, which
- // ghostty-vt links for kitty graphics whatever pardes does; a terminal's
- // PNG is decoded through it (TerminalImages.zig), and of zstbi only its
- // 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_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
- // its session and read by its client (src/replica.zig). The library's
- // compressor and decompressor alone, single-threaded and without its
- // x86 assembly, each context made with ZSTD_customMem over c_heap; of
- // 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 lib = b.addLibrary(.{
- .name = "zstd",
- .root_module = b.createModule(.{ .target = target, .optimize = c_optimize, .link_libc = true }),
- .linkage = .static,
- });
- lib.root_module.addCSourceFiles(.{
- .root = dep.path("lib"),
- .files = &.{
- "common/debug.c", "common/entropy_common.c", "common/error_private.c",
- "common/fse_decompress.c", "common/pool.c", "common/threading.c",
- "common/xxhash.c", "common/zstd_common.c", "compress/fse_compress.c",
- "compress/hist.c", "compress/huf_compress.c", "compress/zstd_compress.c",
- "compress/zstd_compress_literals.c", "compress/zstd_compress_sequences.c", "compress/zstd_compress_superblock.c",
- "compress/zstd_double_fast.c", "compress/zstd_fast.c", "compress/zstd_lazy.c",
- "compress/zstd_ldm.c", "compress/zstd_opt.c", "compress/zstd_preSplit.c",
- "decompress/huf_decompress.c", "decompress/zstd_ddict.c", "decompress/zstd_decompress.c",
- "decompress/zstd_decompress_block.c",
- },
- .flags = &.{
- "-DXXH_NAMESPACE=ZSTD_", "-DZSTD_DISABLE_ASM", "-DZSTD_LEGACY_SUPPORT=0",
- "-DDEBUGLEVEL=0", "-DZSTD_EXCLUDE_GREEDY_BLOCK_COMPRESSOR", "-DZSTD_EXCLUDE_LAZY2_BLOCK_COMPRESSOR",
- "-DZSTD_EXCLUDE_BTLAZY2_BLOCK_COMPRESSOR", "-DZSTD_EXCLUDE_BTOPT_BLOCK_COMPRESSOR", "-DZSTD_EXCLUDE_BTULTRA_BLOCK_COMPRESSOR",
- },
- });
- 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).
- const xitdb_mod = b.dependency("xitdb", .{ .target = target, .optimize = optimize }).module("xitdb");
-
- const image_addon = addons.image(b, target, c_optimize, addon_mod, zstbi_dep);
- const image_mod = image_addon.root_module;
- // 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_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);
- const iso_off = b.addOptions();
- iso_off.addOption(bool, "isolated", false);
- const iso_on = b.addOptions();
- iso_on.addOption(bool, "isolated", true);
- const builtin_off = b.addOptions();
- builtin_off.addOption(bool, "on", false);
- const builtin_on = b.addOptions();
- 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);
- 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,
- };
+ const parts = a.parts;
+ const opts = a.opts;
// Off Linux, whose memfd Addon.zig's loader needs, every core has the
// addons compiled in.
const compiled_in = target.result.os.tag != .linux;
@@ -376,8 +188,8 @@ pub fn build(b: *std.Build) void {
// 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 gui_mod: ?*std.Build.Module = if (also_gui) core.module(b, parts, .{ .root = "src/main.zig", .config = a.gui_opts.?, .builtin_addons = compiled_in }) else null;
+ if (a.pdf.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);
@@ -386,7 +198,7 @@ pub fn build(b: *std.Build) void {
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);
+ const window = gui.make(b, target, optimize, macos_sdk, prebuilt_shaders, a.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;
@@ -416,11 +228,11 @@ pub fn build(b: *std.Build) void {
// where the start scan finds them, <prefix>/lib/pardes/addons (and
// $XDG_DATA_HOME/pardes/addons unless -Dhome-install=false).
const addons_step = b.step("addons", "install the image and pdf addons");
- for ([_]?*std.Build.Step.Compile{ image_addon, pdf_addon }, [_][]const u8{ "image", "pdf" }) |lib, name| {
+ for ([_]?*std.Build.Step.Compile{ a.image_addon, a.pdf.lib }, [_][]const u8{ "image", "pdf" }) |lib, name| {
const step = b.step(name, b.fmt("install the {s} addon, <prefix>/lib/pardes/addons/{s}.so", .{ name, name }));
addons_step.dependOn(step);
const l = lib orelse {
- step.dependOn(no_pdf.?);
+ step.dependOn(a.pdf.no_pdf.?);
continue;
};
step.dependOn(&b.addInstallFileWithDir(l.getEmittedBin(), .lib, b.fmt("pardes/addons/{s}.so", .{name})).step);
@@ -445,7 +257,7 @@ pub fn build(b: *std.Build) void {
// also how a build for macOS, whose loader has no memfd, could have
// image and PDF panes.
const static_step = b.step("static", "a pardes with the image and pdf addons in it: the terminal's static (-Dplatform=tui -Dtarget=x86_64-linux-musl), the gui's dynamic (-Dplatform=gui)");
- if (no_pdf) |s| static_step.dependOn(s) else if (static_mod) |m|
+ if (a.pdf.no_pdf) |s| static_step.dependOn(s) else if (static_mod) |m|
static_step.dependOn(&b.addInstallArtifact(b.addExecutable(.{ .name = exe_name, .linkage = if (platform == .gui) null else static_linkage, .root_module = m }), .{}).step)
else
static_step.dependOn(&b.addFail("static is the terminal's on musl (-Dplatform=tui -Dtarget=x86_64-linux-musl) or the gui's (-Dplatform=gui)").step);
@@ -463,7 +275,7 @@ pub fn build(b: *std.Build) void {
iso_step.dependOn(&run_iso.step);
}
- 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};
+ const addon_libs: []const *std.Build.Step.Compile = if (a.pdf.lib) |l| b.allocator.dupe(*std.Build.Step.Compile, &.{ a.image_addon, l }) catch @panic("OOM") else &.{a.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, .{
@@ -472,8 +284,8 @@ pub fn build(b: *std.Build) void {
.addons = addon_libs,
.target = target,
.optimize = optimize,
- .ghostty_vt = ghostty_vt_for_tests,
- .cloud9 = cloud9,
+ .ghostty_vt = a.ghostty_vt,
+ .cloud9 = parts.cloud9,
.gui = platform == .gui,
});
@@ -482,15 +294,15 @@ pub fn build(b: *std.Build) void {
.core_module = core_module,
.enable_jpx = enable_jpx,
.exe = exe,
- .ghostty_optimize = ghostty_optimize,
- .ghostty_simd = ghostty_simd,
- .ghostty_vt_for_tests = ghostty_vt_for_tests,
- .image_addon = image_addon,
+ .ghostty_optimize = a.ghostty_optimize,
+ .ghostty_simd = a.ghostty_simd,
+ .ghostty_vt_for_tests = a.ghostty_vt,
+ .image_addon = a.image_addon,
.lean = lean_cfg,
- .no_pdf = no_pdf,
+ .no_pdf = a.pdf.no_pdf,
.optimize = optimize,
.parts = parts,
- .pdf_addon = pdf_addon,
+ .pdf_addon = a.pdf.lib,
.platform = platform,
.prebuilt_shaders = prebuilt_shaders,
.shell_cfg = shell_cfg,
@@ -501,23 +313,23 @@ pub fn build(b: *std.Build) void {
.unit_profile = unit_profile,
});
tests.add(b, .{
- .addon_mod = addon_mod,
+ .addon_mod = a.addon_mod,
.atlas_test = atlas_test,
.cells_test = cells_test,
.core_lean = core_lean,
.core_module = core_module,
.core_cfg = core_cfg,
.exe = exe,
- .ghostty_vt_for_tests = ghostty_vt_for_tests,
- .image_addon = image_addon,
+ .ghostty_vt_for_tests = a.ghostty_vt,
+ .image_addon = a.image_addon,
.lspmock = lspmock,
.mupdf_check = mupdf_check,
.optimize = optimize,
.parts = parts,
- .pdf_addon = pdf_addon,
+ .pdf_addon = a.pdf.lib,
.platform = platform,
.root_mod = root_mod,
- .snake_shader_lib = snake_shader_lib,
+ .snake_shader_lib = a.snake_shader_lib,
.target = target,
.test_build = test_build,
.test_filters = test_filters,
diff --git a/build/core.zig b/build/core.zig
index 2809ff46..8fced4ce 100644
--- a/build/core.zig
+++ b/build/core.zig
@@ -2,6 +2,8 @@ const std = @import("std");
const Platform = @import("../build.zig").Platform;
const TreeSitterGrammars = @import("../build.zig").TreeSitterGrammars;
const grammar_manifest = @import("../src/grammar_manifest.zig");
+const addons = @import("addons.zig");
+const patches = @import("patches.zig");
/// The package manifest, imported UNTYPED on purpose — see the `version`
/// option in `shellOptions` for why that word is load-bearing.
const zon = @import("../build.zig.zon");
@@ -357,3 +359,263 @@ pub fn module(b: *std.Build, p: Parts, c: Core) *std.Build.Module {
m.addOptions("builtin_addons", if (c.builtin_addons) p.builtin_on else p.builtin_off);
return m;
}
+
+/// What `assemble` makes besides the parts: the shells' options, the
+/// addons, and the terminal's pieces the tests and harnesses name.
+pub const Assembly = struct {
+ parts: Parts,
+ /// The shell's options (`pardes_config`), and the window's in the bare build.
+ opts: *std.Build.Step.Options,
+ gui_opts: ?*std.Build.Step.Options,
+ /// What an addon in Zig imports (src/kinds/addon.zig).
+ addon_mod: *std.Build.Module,
+ snake_shader_lib: ?*std.Build.Step.Compile,
+ pdf: addons.Pdf,
+ image_addon: *std.Build.Step.Compile,
+ /// The window's FreeType, which MuPDF is built against too.
+ freetype: ?*std.Build.Step.Compile,
+ /// ghostty's emulator, null while it is still to be fetched.
+ ghostty_vt: ?*std.Build.Module,
+ ghostty_optimize: std.lang.Optimize,
+ ghostty_simd: bool,
+};
+
+/// Every core's parts, the shells' options and the addons, made once and
+/// in this order (the configuration numbers what it generates by it): the
+/// one-round lazy fetch, tree-sitter and the themes, the patched packages,
+/// zstd, the terminal, and the options modules the cores choose between.
+pub fn assemble(b: *std.Build, c: struct {
+ target: std.Build.ResolvedTarget,
+ optimize: std.lang.Optimize,
+ c_optimize: std.lang.Optimize,
+ tree_sitter_grammars: TreeSitterGrammars,
+ tracy: ?[]const u8,
+ shell_cfg: ShellConfig,
+ platform: Platform,
+ also_gui: bool,
+ pdf: bool,
+ enable_jpx: bool,
+ doc_typ: *std.Build.Step.Options,
+ mupdf_check: *std.Build.Step,
+ pdf_pointer_bench_step: *std.Build.Step,
+ pdf_scroll_bench_step: *std.Build.Step,
+}) Assembly {
+ const target = c.target;
+ const optimize = c.optimize;
+ const c_optimize = c.c_optimize;
+ // build-time IO: slurps the grammars' highlights.scm queries, and reads
+ // vendor/themes to find the theme sources
+ var threaded: std.Io.Threaded = .init(b.allocator, .{});
+ defer threaded.deinit();
+ const io = threaded.io();
+
+ // 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
+ // are asked for here in one round, the grammars with them, where each
+ // `b.dependency` below would end the configure to fetch its own alone.
+ const ts = treeSitter(b, io, target, c_optimize, c.tree_sitter_grammars);
+ inline for (.{ "cloud9", "vaxis", "ghostty", "uucode", "zstbi", "mvzr", "zstd", "xitdb" }) |name| {
+ // A dependency by path (none of these today) has no hash and is always there.
+ const dep = @field(zon.dependencies, name);
+ if (@hasField(@TypeOf(dep), "hash")) if (!std.Build.package_map.get(dep.hash).?.available) {
+ _ = b.lazyDependency(name, .{});
+ };
+ }
+ const cloud9 = b.dependency("cloud9", .{ .target = target, .optimize = optimize }).module("cloud9");
+
+ const themes_mod = generatedThemes(b, io, target, optimize);
+
+ const opts = shellOptions(b, c.shell_cfg, c.platform);
+ const gui_opts: ?*std.Build.Step.Options = if (c.also_gui) shellOptions(b, c.shell_cfg, .gui) else null;
+
+ 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
+ // this test any longer": `a?` n times is 2^n steps), and pardes searches
+ // with it holding the editor. Its matcher gets a step budget, patched into
+ // the fetched source here at build time so that a fresh fetch keeps it:
+ // each entry to matchPattern, which its backtracking recurses through,
+ // spends a step, and with none left the match fails and says so
+ // (src/regexp.zig). A bump that moves the anchor stops the build.
+ const mvzr_mod = patches.mvzr(b, io, b.dependency("mvzr", .{ .target = target, .optimize = optimize }), target, optimize);
+
+ // The C heap every C library with an allocator hook is handed: the core's
+ // tree-sitter and fonts, and pdf.zig's MuPDF, which is a module of its own.
+ const c_heap_mod = b.createModule(.{
+ .target = target,
+ .optimize = optimize,
+ .root_source_file = b.path("src/c_heap.zig"),
+ });
+
+ // MuPDF and FreeType, lazy (build.zig's `pdf` option has why).
+ const mupdf_dep = if (c.pdf) b.lazyDependency("mupdf", .{}) else null;
+ // One FreeType in a binary: the gui's glyph atlas links it and MuPDF is
+ // built against it (see build/mupdf.zig). At c_optimize with the rest of the
+ // vendored C, since MuPDF rasterizes a PDF's text through it.
+ const freetype_dep = if (c.pdf or c.also_gui or c.platform == .gui) b.lazyDependency("freetype", .{
+ .target = target,
+ .optimize = c_optimize,
+ .@"enable-libpng" = false,
+ }) else null;
+ const freetype = if (freetype_dep) |d| d.artifact("freetype") else null;
+
+ // The kinds' C ABI (src/kinds/pardes_addon.h), translated once: the core's
+ // records are the header's, never a mirror of it.
+ const kind_mod = b.addTranslateC(.{ .root_source_file = b.path("src/kinds/pardes_addon.h"), .target = target, .optimize = optimize }).createModule();
+ // ...and what an addon in Zig imports over it (src/kinds/addon.zig).
+ const addon_mod = b.createModule(.{ .root_source_file = b.path("src/kinds/addon.zig"), .target = target, .optimize = optimize, .imports = &.{.{ .name = "pardes_addon", .module = kind_mod }} });
+ const snake_shader_lib = addons.gpu(b, target, optimize, addon_mod);
+ const pdf_built = addons.pdf(b, .{
+ .addon_mod = addon_mod,
+ .c_optimize = c_optimize,
+ .enable_jpx = c.enable_jpx,
+ .freetype = freetype,
+ .freetype_dep = freetype_dep,
+ .io = io,
+ .mupdf_check = c.mupdf_check,
+ .mupdf_dep = mupdf_dep,
+ .pdf_pointer_bench_step = c.pdf_pointer_bench_step,
+ .pdf_scroll_bench_step = c.pdf_scroll_bench_step,
+ .target = target,
+ });
+
+ const uucode_mod = uucodeModule(b, target, optimize).?;
+
+ const vaxis_dep = b.dependency("vaxis", .{
+ .target = target,
+ .optimize = optimize,
+ .external_uucode = true,
+ });
+ const vaxis_mod = vaxis_dep.module("vaxis");
+ patches.vaxis(b, io, vaxis_dep, vaxis_mod);
+
+ var ghostty_vt_for_tests: ?*std.Build.Module = null;
+ const ghostty_simd = !target.result.os.tag.isDarwin() or b.graph.host.result.os.tag.isDarwin();
+ const ghostty_optimize: std.lang.Optimize = if (optimize == .debug) .safe else optimize;
+ const ghostty_dep = b.lazyDependency("ghostty", .{ .target = target, .optimize = ghostty_optimize, .simd = ghostty_simd, .@"app-runtime" = .none, .@"emit-xcframework" = false });
+ if (ghostty_dep) |dep| {
+ const ghostty_vt = dep.module("ghostty-vt");
+ ghostty_vt_for_tests = ghostty_vt;
+ ghostty_vt.addImport("uucode", uucode_mod);
+ patches.ghosttyKitty(b, io, dep, ghostty_vt);
+ }
+ // override uucode on vaxis LAST so it wins over ghostty's build() wiring.
+ vaxis_mod.addImport("uucode", uucode_mod);
+
+ // One PNG decoder (docs/shared-libs.md): ghostty's, wuffs, which
+ // ghostty-vt links for kitty graphics whatever pardes does; a terminal's
+ // PNG is decoded through it (TerminalImages.zig), and of zstbi only its
+ // 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_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
+ // its session and read by its client (src/replica.zig). The library's
+ // compressor and decompressor alone, single-threaded and without its
+ // x86 assembly, each context made with ZSTD_customMem over c_heap; of
+ // 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 lib = b.addLibrary(.{
+ .name = "zstd",
+ .root_module = b.createModule(.{ .target = target, .optimize = c_optimize, .link_libc = true }),
+ .linkage = .static,
+ });
+ lib.root_module.addCSourceFiles(.{
+ .root = dep.path("lib"),
+ .files = &.{
+ "common/debug.c", "common/entropy_common.c", "common/error_private.c",
+ "common/fse_decompress.c", "common/pool.c", "common/threading.c",
+ "common/xxhash.c", "common/zstd_common.c", "compress/fse_compress.c",
+ "compress/hist.c", "compress/huf_compress.c", "compress/zstd_compress.c",
+ "compress/zstd_compress_literals.c", "compress/zstd_compress_sequences.c", "compress/zstd_compress_superblock.c",
+ "compress/zstd_double_fast.c", "compress/zstd_fast.c", "compress/zstd_lazy.c",
+ "compress/zstd_ldm.c", "compress/zstd_opt.c", "compress/zstd_preSplit.c",
+ "decompress/huf_decompress.c", "decompress/zstd_ddict.c", "decompress/zstd_decompress.c",
+ "decompress/zstd_decompress_block.c",
+ },
+ .flags = &.{
+ "-DXXH_NAMESPACE=ZSTD_", "-DZSTD_DISABLE_ASM", "-DZSTD_LEGACY_SUPPORT=0",
+ "-DDEBUGLEVEL=0", "-DZSTD_EXCLUDE_GREEDY_BLOCK_COMPRESSOR", "-DZSTD_EXCLUDE_LAZY2_BLOCK_COMPRESSOR",
+ "-DZSTD_EXCLUDE_BTLAZY2_BLOCK_COMPRESSOR", "-DZSTD_EXCLUDE_BTOPT_BLOCK_COMPRESSOR", "-DZSTD_EXCLUDE_BTULTRA_BLOCK_COMPRESSOR",
+ },
+ });
+ 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).
+ const xitdb_mod = b.dependency("xitdb", .{ .target = target, .optimize = optimize }).module("xitdb");
+
+ const image_addon = addons.image(b, target, c_optimize, addon_mod, zstbi_dep);
+ // 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_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);
+
+ // One options module for each value a core chooses (`module`).
+ const term_on = b.addOptions();
+ term_on.addOption(bool, "terminal", true);
+ const term_off = b.addOptions();
+ term_off.addOption(bool, "terminal", false);
+ const iso_off = b.addOptions();
+ iso_off.addOption(bool, "isolated", false);
+ const iso_on = b.addOptions();
+ iso_on.addOption(bool, "isolated", true);
+ const builtin_off = b.addOptions();
+ builtin_off.addOption(bool, "on", false);
+ const builtin_on = b.addOptions();
+ 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_built.lib != null);
+ return .{
+ .parts = .{
+ .target = target,
+ .optimize = optimize,
+ .cloud9 = cloud9,
+ .tracy = c.tracy,
+ .zstd = zstd,
+ .image = image_addon.root_module,
+ .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 = c.doc_typ,
+ .term_on = term_on,
+ .term_off = term_off,
+ .iso_on = iso_on,
+ .iso_off = iso_off,
+ .builtin_on = builtin_on,
+ .builtin_off = builtin_off,
+ },
+ .opts = opts,
+ .gui_opts = gui_opts,
+ .addon_mod = addon_mod,
+ .snake_shader_lib = snake_shader_lib,
+ .pdf = pdf_built,
+ .image_addon = image_addon,
+ .freetype = freetype,
+ .ghostty_vt = ghostty_vt_for_tests,
+ .ghostty_optimize = ghostty_optimize,
+ .ghostty_simd = ghostty_simd,
+ };
+}