From 55a5f91305df47cd56d7776f4193b6198208e891 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Thu, 19 Nov 2026 22:17:29 -0300 Subject: build: the dead and the doubled options go (the start design's step 1, pardes-build-options change 1): `ShellConfig.prebuilt_shaders`, set at build.zig:147 and read nowhere (the `-Dprebuilt-shaders` flag stays: gui.make hands it to sketchbook and the perf identity names it); `tools.add` and `core.assemble` handed the grammar set and -Dtracy beside the `shell_cfg` that holds them (`ShellConfig.tracy` is the checkout's path now, so Parts and the perf identity read it there); `syntax_zig_grammar`, always equal to `syntax_highlighting`; and the four `syntax_*` bools as the one enum they said four ways, `grammars` (`-Dtree-sitter`'s `TreeSitterGrammars`), read by syntax.zig, Output.zig's Build pane and three tests, with abi/wire.zig hashing it as the four words it was hashed as, so `pardes version`'s semantics line did not move on any product (38b5ae573b965550 on tui, gui, the bare build's two, both statics, FreeBSD; d41689a1f97605b8 with -Dtree-sitter=minimal, as on the base); build.zig and build/ 3,005 -> 2,992 lines; every shape configures (12 configurations) and builds as on the base (tui, gui, bare, the macOS library for Linux and aarch64-macos, static on musl and on the window, FreeBSD, -Dtree-sitter=minimal), and the two that fail on the base fail with the same errors (pardes-isolate: core/builtins.zig:510, core/ninep/ctl.zig:1298; -Dtree-sitter=disabled: core/indent.zig:48); tui core-test 848/991 (143 skipped), shell-test 1027/1030, pane-test 183/184, behaviour-test 275/275 (and -- --replay), term-test 15/15, kitty-test 45/45, lib-test, hxlib 538 cases 0 mismatches, process-test 3 of 144 failed (lspcomplete and lspcompletemoved, the base's, and headersweep-restored, on the flaky list: passed alone, 1364 ms), gui unit-test 1625/1629 (the perf check's BaselineHarnessMismatch, the base's); the test names of every suite equal the base's (ledger); load 15-45 on 16 cores Co-Authored-By: Claude Opus Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T --- build/core.zig | 17 ++++++----------- build/tools.zig | 7 ++----- 2 files changed, 8 insertions(+), 16 deletions(-) (limited to 'build') diff --git a/build/core.zig b/build/core.zig index 974d5c7e..b35c066b 100644 --- a/build/core.zig +++ b/build/core.zig @@ -60,11 +60,11 @@ pub fn command(b: *std.Build, argv: []const []const u8) ?[]const u8 { pub const ShellConfig = struct { tree_sitter_grammars: TreeSitterGrammars, - tracy: bool = false, + /// -Dtracy's checkout, whose client a core that asks compiles in. + tracy: ?[]const u8 = null, /// 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 = 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 @@ -79,11 +79,8 @@ pub const ShellConfig = struct { pub fn shellOptions(b: *std.Build, cfg: ShellConfig, platform: Platform) *std.Build.Step.Options { const o = b.addOptions(); o.addOption(Platform, "platform", platform); - o.addOption(bool, "syntax_highlighting", cfg.tree_sitter_grammars != .disabled); - o.addOption(bool, "syntax_zig_grammar", cfg.tree_sitter_grammars != .disabled); - o.addOption(bool, "syntax_minimal_grammars", cfg.tree_sitter_grammars == .minimal or cfg.tree_sitter_grammars == .full); - o.addOption(bool, "syntax_full_grammars", cfg.tree_sitter_grammars == .full); - o.addOption(bool, "enable_tracy", cfg.tracy); + o.addOption(TreeSitterGrammars, "grammars", cfg.tree_sitter_grammars); + o.addOption(bool, "enable_tracy", cfg.tracy != null); o.addOption(bool, "workspace_tag", cfg.workspace_tag orelse (platform != .macos)); o.addOption(bool, "embed_sources", cfg.embed_sources); o.addOption([]const u8, "version", display_version); @@ -429,8 +426,6 @@ 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, @@ -455,7 +450,7 @@ pub fn assemble(b: *std.Build, c: struct { // 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); + const ts = treeSitter(b, io, target, c_optimize, c.shell_cfg.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); @@ -623,7 +618,7 @@ pub fn assemble(b: *std.Build, c: struct { .target = target, .optimize = optimize, .cloud9 = cloud9, - .tracy = c.tracy, + .tracy = c.shell_cfg.tracy, .zstd = zstd, .image = image_addon.root_module, .pdf = pdf_built.module, diff --git a/build/tools.zig b/build/tools.zig index 1343fef9..62e9817a 100644 --- a/build/tools.zig +++ b/build/tools.zig @@ -2,7 +2,6 @@ const std = @import("std"); const builtin = @import("builtin"); const Platform = @import("../build.zig").Platform; const PerfBuild = @import("../build.zig").PerfBuild; -const TreeSitterGrammars = @import("../build.zig").TreeSitterGrammars; const core = @import("core.zig"); const testMatch = @import("tests.zig").testMatch; @@ -42,8 +41,6 @@ pub fn add(b: *std.Build, c: struct { shell_cfg: core.ShellConfig, target: std.Build.ResolvedTarget, test_filters: []const []const u8, - tracy: ?[]const u8, - tree_sitter_grammars: TreeSitterGrammars, unit_profile: *std.Build.Step.Compile, }) Tools { const image_harness = program(b, "pardes-image-harness", "test/image_harness.zig", c.target, c.optimize, &.{}); @@ -191,10 +188,10 @@ pub fn add(b: *std.Build, c: struct { .c_optimize = @tagName(c.c_optimize), .terminal_optimize = @tagName(c.ghostty_optimize), .platform = @tagName(c.platform), - .grammars = @tagName(c.tree_sitter_grammars), + .grammars = @tagName(c.shell_cfg.tree_sitter_grammars), .mupdf = c.pdf_addon != null, .jpx = c.enable_jpx, - .tracy = c.tracy != null, + .tracy = c.shell_cfg.tracy != null, .terminal_simd = c.ghostty_simd, .prebuilt_shaders = c.platform == .gui and c.prebuilt_shaders, }); -- cgit v1.3 From a481de9feea08de7b5b82c2471de70abd70d7462 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Thu, 19 Nov 2026 23:07:14 -0300 Subject: build: one options module a module set, `pardes_options`, and `build_info` beside it (the start design's step 2, pardes-build-options change 2): `core.module` makes the set's options from the build's `ShellConfig` and the set's `Core` (the platform, now a `Core` field in place of a module handed in; the grammar set; the terminal; pardes-isolate's `isolated`; the addons compiled in and the pdf one with them, `builtin_addons` and `builtin_pdf`; tracy; the workspace tag; embedded sources; the library's `lib`), one module shared by the set's five as `pardes_config` was, and `build_info` (version, commit, change, built, deps) made once in `assemble` and given to every set; the three one-value modules made in both values (`term_options`, `pardes_isolation`, `builtin_addons`), `shellOptions`, the six `Parts` fields that held them, `Parts.tracy` and `Parts.embed_sources` (the `ShellConfig` in `Parts` holds both) and the assembly's two options (`opts`, `gui_opts`) go; the library's `pardes-syntax` and the editor (the library's and hxlib's) get `pardes_options` with no terminal, the editor's with `lib` as before; the sources' imports follow, one identifier a line (abi/wire.zig and core/Output.zig import both, the hash's and the Build pane's lines reading the version, commit and dependencies from `build_info`); test programs see it as before, through the core module's import table (pane-test, behaviour-test); `pardes version`'s semantics line did not move on any product (38b5ae573b965550; d41689a1f97605b8 with -Dtree-sitter=minimal); build.zig and build/ 2,992 -> 2,960 lines (3,005 at the base); every shape configures and builds as on the base, pardes-isolate and -Dtree-sitter=disabled failing with the base's same errors (pardes-isolate reaching them through its own options module); tui core-test 848/991 (143 skipped), shell-test 1027/1030, pane-test 183/184, behaviour-test 275/275 (and -- --replay), term-test 15/15, kitty-test 45/45, lib-test (11/11 in the consumer), hxlib 538 cases 0 mismatches, process-test 2 of 144 failed (lspcomplete and lspcompletemoved, the base's), gui unit-test 1625/1629 (the perf check's BaselineHarnessMismatch, the base's); the test names of every suite equal the base's (ledger); the frame and perf gate (gpu/bo-s2 against tree1) PASS: 77/77 frames byte-identical in Debug, the alternated window corpus2x -0.104% (pictures identical in all 10 runs), the 97 per-operation counts within 0.1% (largest image-frame +0.0345%; against the coordinator's pardes-merge22 gate m22-g, 90 within 5 ppm, deep-sel 8-10 ppm, image-frame up to 85 ppm, its known noise); load 5-25 on 16 cores Co-Authored-By: Claude Opus Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T --- abi/wire.zig | 13 ++--- build.zig | 13 +++-- build/core.zig | 115 ++++++++++++++++---------------------------- build/library.zig | 2 +- build/tests.zig | 4 +- core/Addon.zig | 4 +- core/Editor.zig | 2 +- core/Output.zig | 15 +++--- core/Term.zig | 2 +- core/Text.zig | 2 +- core/config.zig | 2 +- core/lib_editor.zig | 2 +- core/memory.zig | 2 +- core/root.zig | 10 ++-- core/syntax.zig | 2 +- core/tracy.zig | 2 +- dev/root.zig | 6 +-- docs/next-editor.md | 2 +- docs/next-terminal.md | 4 +- runtime/macos.zig | 2 +- runtime/root.zig | 4 +- test/behaviour/panes.zig | 2 +- test/behaviour/settings.zig | 8 +-- test/output.zig | 2 +- 24 files changed, 96 insertions(+), 126 deletions(-) (limited to 'build') diff --git a/abi/wire.zig b/abi/wire.zig index 26a7131e..1f7d02d2 100644 --- a/abi/wire.zig +++ b/abi/wire.zig @@ -7,7 +7,8 @@ const std = @import("std"); const builtin = @import("builtin"); const pardes = @import("core"); -const config = @import("pardes_config"); +const config = @import("pardes_options"); +const build_info = @import("build_info"); /// 23: a pane of a kind's frame names its rasters by key, their pixels /// crossing before it as strips of 4 MiB at most over the rows it shows @@ -70,12 +71,12 @@ pub const semantics: u64 = blk: { break :blk std.hash.Wyhash.hash(0, std.fmt.comptimePrint( "wire {d}\npardes {s} {s}\n{s} grammars {} {} {} {} workspace_tag {} sources {}\nusize {d} {t}\n", .{ - version, config.version, config.commit orelse "unstamped", - family, g != .disabled, g != .disabled, - g == .minimal or g == .full, g == .full, config.workspace_tag, - config.embed_sources, @sizeOf(usize), builtin.cpu.arch.endian(), + version, build_info.version, build_info.commit orelse "unstamped", + family, g != .disabled, g != .disabled, + g == .minimal or g == .full, g == .full, config.workspace_tag, + config.embed_sources, @sizeOf(usize), builtin.cpu.arch.endian(), }, - ) ++ config.deps ++ "\n" ++ pardes.tape.shape); + ) ++ build_info.deps ++ "\n" ++ pardes.tape.shape); }; /// EndOfStream: the message ends early; WriteFailed: no room for it. diff --git a/build.zig b/build.zig index cf9a851f..fc0c5044 100644 --- a/build.zig +++ b/build.zig @@ -166,7 +166,6 @@ pub fn build(b: *std.Build) void { .pdf_scroll_bench_step = pdf_scroll_bench_step, }); 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; @@ -174,28 +173,28 @@ pub fn build(b: *std.Build) void { // its own flat C ABI instead of runtime/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_set = core.module(b, parts, .{ .root = if (platform == .macos) "runtime/macos.zig" else "runtime/main.zig", .config = opts, .builtin_addons = compiled_in, .tracy = true, .util = true }); + const root_set = core.module(b, parts, .{ .root = if (platform == .macos) "runtime/macos.zig" else "runtime/main.zig", .platform = platform, .builtin_addons = compiled_in, .tracy = true, .util = true }); const root_mod = root_set.root; // 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 = "core/root.zig", .config = opts, .builtin_addons = compiled_in, .tracy = true }; + const core_cfg: core.Core = .{ .root = "core/root.zig", .platform = platform, .builtin_addons = compiled_in, .tracy = true }; const core_set = core.module(b, parts, core_cfg); const core_module = core_set.root; // 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 = "core/root.zig", .config = opts, .builtin_addons = compiled_in, .terminal = false }; + const lean_cfg: core.Core = .{ .root = "core/root.zig", .platform = platform, .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 = "runtime/main.zig", .config = opts, .builtin_addons = compiled_in, .isolated = true }).root else null; + const isolated_mod: ?*std.Build.Module = if (platform == .tui) core.module(b, parts, .{ .root = "runtime/main.zig", .platform = platform, .builtin_addons = compiled_in, .isolated = true }).root 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_set: ?core.Modules = if ((platform == .tui and static_linkage != null) or platform == .gui) core.module(b, parts, .{ .root = "runtime/main.zig", .config = opts, .builtin_addons = true }) else null; + const static_set: ?core.Modules = if ((platform == .tui and static_linkage != null) or platform == .gui) core.module(b, parts, .{ .root = "runtime/main.zig", .platform = platform, .builtin_addons = true }) else null; const static_mod: ?*std.Build.Module = if (static_set) |s| s.root else null; - const gui_set: ?core.Modules = if (also_gui) core.module(b, parts, .{ .root = "runtime/main.zig", .config = a.gui_opts.?, .builtin_addons = compiled_in }) else null; + const gui_set: ?core.Modules = if (also_gui) core.module(b, parts, .{ .root = "runtime/main.zig", .platform = .gui, .builtin_addons = compiled_in }) else null; const gui_mod: ?*std.Build.Module = if (gui_set) |s| s.root else null; if (a.pdf.lib) |lib| tools.pdfBenches(b, target, optimize, core_module, lib, pdf_pointer_bench_step, pdf_scroll_bench_step); diff --git a/build/core.zig b/build/core.zig index b35c066b..4e4a748b 100644 --- a/build/core.zig +++ b/build/core.zig @@ -5,7 +5,7 @@ const grammar_manifest = @import("../core/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. +/// option in `buildInfo` for why that word is load-bearing. const zon = @import("../build.zig.zon"); /// Releases are numbered 0.N; the zon holds "0.N.0" because it must be semver, /// and what a user sees drops that ".0". @@ -76,21 +76,34 @@ pub const ShellConfig = struct { lib: bool = false, }; -pub fn shellOptions(b: *std.Build, cfg: ShellConfig, platform: Platform) *std.Build.Step.Options { +/// `pardes_options`: what a module set varies at compile time, one module +/// a configuration, which `module` makes and the set's modules share. +pub fn options(b: *std.Build, cfg: ShellConfig, c: Core, pdf: bool) *std.Build.Step.Options { const o = b.addOptions(); - o.addOption(Platform, "platform", platform); + o.addOption(Platform, "platform", c.platform); o.addOption(TreeSitterGrammars, "grammars", cfg.tree_sitter_grammars); + o.addOption(bool, "terminal", c.terminal); + o.addOption(bool, "isolated", c.isolated); + o.addOption(bool, "builtin_addons", c.builtin_addons); + // ...the pdf one only when it is built (-Dpdf=false leaves it out). + o.addOption(bool, "builtin_pdf", c.builtin_addons and pdf); o.addOption(bool, "enable_tracy", cfg.tracy != null); - o.addOption(bool, "workspace_tag", cfg.workspace_tag orelse (platform != .macos)); + o.addOption(bool, "workspace_tag", cfg.workspace_tag orelse (c.platform != .macos)); o.addOption(bool, "embed_sources", cfg.embed_sources); + o.addOption(bool, "lib", cfg.lib); + return o; +} + +/// `build_info`: the version, and the commit, change and time a stamped +/// build was made from (see `stamp_commit`, read at configure time), and +/// every dependency's hash. +pub fn buildInfo(b: *std.Build, cfg: ShellConfig) *std.Build.Step.Options { + const o = b.addOptions(); o.addOption([]const u8, "version", display_version); - // ...and the commit it was built from, when there is one and the build - // is stamped at all (see `stamp_commit`). Read at configure time. o.addOption(?[]const u8, "commit", cfg.commit); o.addOption(?[]const u8, "change", cfg.change); o.addOption(?[]const u8, "built", cfg.built); o.addOption([]const u8, "deps", deps_text); - o.addOption(bool, "lib", cfg.lib); return o; } @@ -237,16 +250,16 @@ pub fn editorModule(b: *std.Build, name: ?[]const u8, target: std.Build.Resolved /// cell's width for j and k's goal column. vaxis: *std.Build.Module, }) *std.Build.Module { - const options: std.Build.Module.CreateOptions = .{ + const create: std.Build.Module.CreateOptions = .{ .target = target, .optimize = optimize, .root_source_file = b.path("core/lib_editor.zig"), .link_libc = true, }; - const m = if (name) |n| b.addModule(n, options) else b.createModule(options); + const m = if (name) |n| b.addModule(n, create) else b.createModule(create); var lib_cfg = cfg; lib_cfg.lib = true; - m.addOptions("pardes_config", shellOptions(b, lib_cfg, .tui)); + m.addOptions("pardes_options", options(b, lib_cfg, .{ .root = "core/lib_editor.zig", .platform = .tui, .terminal = false }, false)); m.addImport("plain", b.createModule(.{ .target = target, .optimize = optimize, .root_source_file = b.path("abi/plain.zig") })); m.addImport("generated_themes", d.themes); d.ts.wire(m); @@ -262,8 +275,10 @@ 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, + /// The build's options (-Dtracy's checkout, -Dembed-sources...). + cfg: ShellConfig, + /// `build_info`, the same for every set. + info: *std.Build.Step.Options, 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). @@ -281,16 +296,6 @@ pub const Parts = struct { uucode: *std.Build.Module, xitdb: *std.Build.Module, doc_typ: *std.Build.Step.Options, - /// -Dembed-sources: the core embeds its sources for /src. - embed_sources: bool, - /// 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. @@ -299,9 +304,8 @@ pub const Core = struct { /// library), core/root.zig for the core, runtime/root.zig for the /// runtime, or a core 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, + /// This build's, or the window's in the bare build. + platform: Platform, /// 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. @@ -336,7 +340,7 @@ pub fn module(b: *std.Build, p: Parts, c: Core) Modules { // 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| { + if (c.tracy) if (p.cfg.tracy) |tracy_path| { m.addIncludePath(.{ .cwd_relative = tracy_path }); m.addCSourceFile(.{ .file = .{ .cwd_relative = b.pathJoin(&.{ tracy_path, "public", "TracyClient.cpp" }) }, @@ -356,7 +360,7 @@ pub fn module(b: *std.Build, p: Parts, c: Core) Modules { for (p.ts.libs.items) |lib| m.linkLibrary(lib); // The /src tree's files that live outside the core's directory // (fs.zig embeds them under the names they had there). - if (p.embed_sources) for ([_][]const u8{ "runtime/9p.zig", "runtime/9p_io.zig", "runtime/main.zig", "dev/host_io.zig" }) |f| + if (p.cfg.embed_sources) for ([_][]const u8{ "runtime/9p.zig", "runtime/9p_io.zig", "runtime/main.zig", "dev/host_io.zig" }) |f| m.addAnonymousImport(f, .{ .root_source_file = b.path(f) }); const runtime = b.createModule(.{ .target = p.target, .optimize = p.optimize, .root_source_file = b.path("runtime/root.zig"), .link_libc = true }); const dev = b.createModule(.{ .target = p.target, .optimize = p.optimize, .root_source_file = b.path("dev/root.zig"), .link_libc = true }); @@ -364,18 +368,15 @@ pub fn module(b: *std.Build, p: Parts, c: Core) Modules { const root = if (!in_runtime) m else if (std.mem.eql(u8, c.root, "runtime/root.zig")) runtime else b.createModule(.{ .target = p.target, .optimize = p.optimize, .root_source_file = b.path(c.root), .link_libc = true }); // Each options module once, so that the modules share it: a file is in // one module of a compilation. - const term_options = (if (c.terminal) p.term_on else p.term_off).createModule(); const ts_queries = if (p.ts.queries) |q| q.createModule() else null; const doc_typ = p.doc_typ.createModule(); - const pardes_config = c.config.createModule(); - const pardes_isolation = (if (c.isolated) p.iso_on else p.iso_off).createModule(); - const builtin_addons = (if (c.builtin_addons) p.builtin_on else p.builtin_off).createModule(); + const pardes_options = options(b, p.cfg, c, p.pdf != null).createModule(); + const build_info = p.info.createModule(); for ([_]*std.Build.Module{ m, dev, runtime, wire, root }) |x| { x.addImport("cloud9", p.cloud9); if (c.builtin_addons) if (p.pdf) |pdf| x.addImport("pdf_addon", pdf); if (c.builtin_addons) x.addImport("image_addon", p.image); if (c.terminal) x.addImport("term", p.term); - x.addImport("term_options", term_options); x.addImport("plain", p.plain); x.addImport("pardes_addon", p.kind); x.addImport("generated_themes", p.themes); @@ -388,9 +389,8 @@ pub fn module(b: *std.Build, p: Parts, c: Core) Modules { x.addImport("xitdb", p.xitdb); // config.zig's test checks the words and keys docs/typ names exist. x.addImport("doc_typ", doc_typ); - x.addImport("pardes_config", pardes_config); - x.addImport("pardes_isolation", pardes_isolation); - x.addImport("builtin_addons", builtin_addons); + x.addImport("pardes_options", pardes_options); + x.addImport("build_info", build_info); x.addImport("core", m); x.addImport("dev", dev); x.addImport("runtime", runtime); @@ -399,13 +399,9 @@ pub fn module(b: *std.Build, p: Parts, c: Core) Modules { return .{ .root = root, .core = m, .dev = dev, .runtime = runtime, .wire = wire }; } -/// What `assemble` makes besides the parts: the shells' options, the -/// addons, and the terminal's pieces the tests and harnesses name. +/// What `assemble` makes besides the parts: 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 (abi/addon.zig). addon_mod: *std.Build.Module, pdf: addons.Pdf, @@ -418,10 +414,10 @@ pub const Assembly = struct { 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. +/// Every core's parts 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. pub fn assemble(b: *std.Build, c: struct { target: std.Build.ResolvedTarget, optimize: std.lang.Optimize, @@ -463,9 +459,6 @@ pub fn assemble(b: *std.Build, c: struct { 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"); // vaxis, ghostty, mvzr and zstbi are patched as they are fetched @@ -597,28 +590,13 @@ pub fn assemble(b: *std.Build, c: struct { 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.shell_cfg.tracy, + .cfg = c.shell_cfg, + .info = buildInfo(b, c.shell_cfg), .zstd = zstd, .image = image_addon.root_module, .pdf = pdf_built.module, @@ -633,16 +611,7 @@ pub fn assemble(b: *std.Build, c: struct { .uucode = uucode_mod, .xitdb = xitdb_mod, .doc_typ = c.doc_typ, - .embed_sources = c.shell_cfg.embed_sources, - .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, .pdf = pdf_built, .image_addon = image_addon, diff --git a/build/library.zig b/build/library.zig index ebfd8596..8a23debc 100644 --- a/build/library.zig +++ b/build/library.zig @@ -24,7 +24,7 @@ pub fn build(b: *std.Build) void { }); // 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)); + mod.addOptions("pardes_options", core.options(b, cfg, .{ .root = "core/lib_syntax.zig", .platform = .tui, .terminal = false }, false)); const ts = core.treeSitter(b, io, target, if (optimize == .debug) .fast else optimize, tree_sitter_grammars); const themes = core.generatedThemes(b, io, target, optimize); mod.addImport("generated_themes", themes); diff --git a/build/tests.zig b/build/tests.zig index 50d3dd02..741eb24a 100644 --- a/build/tests.zig +++ b/build/tests.zig @@ -84,7 +84,7 @@ pub fn add(b: *std.Build, c: struct { if (c.ghostty_vt_for_tests) |x| pane_tests.root_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_tests.root_module.addImport("pardes_config", c.core_module.import_table.get("pardes_config").?); + pane_tests.root_module.addImport("pardes_options", c.core_module.import_table.get("pardes_options").?); const test_addons = b.addOptions(); test_addons.addOptionPath("image", c.image_addon.getEmittedBin()); test_addons.addOption(bool, "has_pdf", c.pdf_addon != null); @@ -129,7 +129,7 @@ pub fn add(b: *std.Build, c: struct { session_module.addOptions("session_options", session_options); // The build's options alone (platform), never the core: a test of a // window's word knows which build it runs in. - const behaviour_tests = units.root(b, "test/behaviour.zig", true, &.{ .{ .name = "session", .module = session_module }, .{ .name = "pardes_config", .module = c.core_module.import_table.get("pardes_config").? } }); + const behaviour_tests = units.root(b, "test/behaviour.zig", true, &.{ .{ .name = "session", .module = session_module }, .{ .name = "pardes_options", .module = c.core_module.import_table.get("pardes_options").? } }); const behaviour_test_step = b.step("behaviour-test", "run the behavioural tests, through the 9P tree alone (test/behaviour/), and the T1 runner (-- [--seed N]... | --monkey | --replay)"); _ = units.add(b, behaviour_tests, behaviour_test_step); // An addon's own test: `--addon-test` over the fake (the template) diff --git a/core/Addon.zig b/core/Addon.zig index ec2f796a..c542e1f1 100644 --- a/core/Addon.zig +++ b/core/Addon.zig @@ -236,9 +236,9 @@ fn fileOf(fd: c_int) ?[5]i64 { /// library exports. A static binary cannot dlopen, and the loader below /// is Linux's (a memfd): this is how either has image and PDF panes. /// A build with -Dpdf=false has the image addon alone. -const compiled_in: []const *const Kind.Ops = if (!@import("builtin_addons").on) +const compiled_in: []const *const Kind.Ops = if (!@import("pardes_options").builtin_addons) &.{} -else if (@import("builtin_addons").pdf) +else if (@import("pardes_options").builtin_pdf) &.{ &@import("image_addon").pardes_addon, &@import("pdf_addon").pardes_addon } else &.{&@import("image_addon").pardes_addon}; diff --git a/core/Editor.zig b/core/Editor.zig index 9781d857..aaf6ab05 100644 --- a/core/Editor.zig +++ b/core/Editor.zig @@ -10,7 +10,7 @@ const Registers = @import("Registers.zig"); /// The library's build (build.zig `library`): a text with no pane and no /// core, its characters its own. Where an edit reaches a pane it branches /// on this at compile time, so the library never compiles the core. -pub const lib = @import("pardes_config").lib; +pub const lib = @import("pardes_options").lib; const Pardes = if (lib) void else @import("Core.zig"); const Syntax = if (lib) @import("lib_editor.zig").Syntax else void; const modal = @import("modal.zig"); diff --git a/core/Output.zig b/core/Output.zig index 23409b68..08abc154 100644 --- a/core/Output.zig +++ b/core/Output.zig @@ -9,7 +9,8 @@ const Pardes = pardes.Pardes; const modal = @import("modal.zig"); const limits = @import("memory.zig").limits; const builtins = @import("builtins.zig"); -const build_options = @import("pardes_config"); +const build_options = @import("pardes_options"); +const build_info = @import("build_info"); const lsp = @import("lsp/lsp.zig"); const look = @import("look.zig"); const locations = @import("locations.zig"); @@ -896,9 +897,9 @@ pub fn openBuild(p: *Pardes, id: usize) !void { const w = &out.writer; try w.print("{s}\n", .{@import("runtime").upgrade.version_line}); try w.print("commit {s}\nchange {s}\nbuilt {s}\n", .{ - build_options.commit orelse "not stamped (a Debug build with -Dplatform or --prefix)", - build_options.change orelse "not stamped", - build_options.built orelse "not stamped", + build_info.commit orelse "not stamped (a Debug build with -Dplatform or --prefix)", + build_info.change orelse "not stamped", + build_info.built orelse "not stamped", }); try w.print("zig {s}\nmode {s}\ntarget {s}-{s}-{s}\nplatform {s}\n", .{ builtin.zig_version_string, @tagName(builtin.mode), @@ -907,9 +908,9 @@ pub fn openBuild(p: *Pardes, id: usize) !void { }); try w.print("grammars {s}\naddons {s}\nsemantics {x:0>16}\n\ndependencies\n{s}", .{ if (build_options.grammars == .full) "full" else if (build_options.grammars == .minimal) "minimal" else "none", - if (@import("builtin_addons").on) "compiled in" else "loaded from /lib/pardes/addons", + if (build_options.builtin_addons) "compiled in" else "loaded from /lib/pardes/addons", @import("wire").semantics, - build_options.deps, + build_info.deps, }); const content = try out.toOwnedSlice(); return openRead(p, id, .{ .cmd = .Build }, "", content); @@ -918,7 +919,7 @@ pub fn openBuild(p: *Pardes, id: usize) !void { pub fn openChangelog(p: *Pardes, id: usize) !void { var out: std.Io.Writer.Allocating = .init(p.gpa); errdefer out.deinit(); - try out.writer.print("pardes {s}\n\n", .{build_options.version}); + try out.writer.print("pardes {s}\n\n", .{build_info.version}); try out.writer.writeAll(@embedFile("CHANGELOG.md")); const content = try out.toOwnedSlice(); return openRead(p, id, .{ .cmd = .Changelog }, "", content); diff --git a/core/Term.zig b/core/Term.zig index fde36420..3f975df6 100644 --- a/core/Term.zig +++ b/core/Term.zig @@ -15,7 +15,7 @@ const File = @import("File.zig"); const iface = plain.term; /// The terminal module's entries; null in a core built without it. -pub const ops: ?*const iface.Ops = if (@import("term_options").terminal) &@import("term").ops else null; +pub const ops: ?*const iface.Ops = if (@import("pardes_options").terminal) &@import("term").ops else null; /// What a core without a terminal says, once, where one would have been. pub const none = "no terminal in this build"; diff --git a/core/Text.zig b/core/Text.zig index 51d660cf..1b3e6273 100644 --- a/core/Text.zig +++ b/core/Text.zig @@ -113,7 +113,7 @@ refused: bool = false, pub inline fn pane(t: *Text) ?*Pane { // the library's text has none (lib_editor.zig): known at compile time, // so what an edit does with a pane is not compiled there - if (comptime @import("pardes_config").lib) return null; + if (comptime @import("pardes_options").lib) return null; return switch (t.what) { .body => @alignCast(@fieldParentPtr("body", t)), .tag => @alignCast(@fieldParentPtr("tag", t)), diff --git a/core/config.zig b/core/config.zig index 792a7e62..bb04d24d 100644 --- a/core/config.zig +++ b/core/config.zig @@ -39,7 +39,7 @@ comptime { @setEvalBranchQuota(20_000); // A path here is a leaf: no builtin's path is it or runs past it, and // none of it is a builtin's whole path. The library has no builtins. - if (!@import("pardes_config").lib) for (leader_args) |la| for (std.enums.values(Builtin)) |b| if (leader_path.get(b)) |path| { + if (!@import("pardes_options").lib) for (leader_args) |la| for (std.enums.values(Builtin)) |b| if (leader_path.get(b)) |path| { if (std.mem.startsWith(u8, path, la.path) or std.mem.startsWith(u8, la.path, path)) @compileError("leader_args path collides with " ++ @tagName(b) ++ ": " ++ la.path); }; diff --git a/core/lib_editor.zig b/core/lib_editor.zig index c459241a..3fe631af 100644 --- a/core/lib_editor.zig +++ b/core/lib_editor.zig @@ -3,7 +3,7 @@ //! true`, docs/next-editor.md). In-memory editing with helix's keys: no //! files, commands, builtins, prompts or views, which come back to the //! caller as an `action`. Nothing is copied here: a key runs the editor's -//! own normal.zig and edit.zig, built with `pardes_config.lib`, where a +//! own normal.zig and edit.zig, built with `pardes_options.lib`, where a //! text has no pane and its characters are its own. //! //! The editor is a value of plain data (`Editor(capacity)`): no pointer, diff --git a/core/memory.zig b/core/memory.zig index c628ae49..0e0dba29 100644 --- a/core/memory.zig +++ b/core/memory.zig @@ -1,6 +1,6 @@ const std = @import("std"); const builtin = @import("builtin"); -const config = @import("pardes_config"); +const config = @import("pardes_options"); const KiB = 1024; const MiB = 1024 * KiB; diff --git a/core/root.zig b/core/root.zig index 69ec3ded..df273738 100644 --- a/core/root.zig +++ b/core/root.zig @@ -98,12 +98,12 @@ pub const Host = host_io.Host; pub const frameMark = tracy.frameMark; /// The shell this build is for (build.zig's `-Dplatform`). -pub const platform = @import("pardes_config").platform; +pub const platform = @import("pardes_options").platform; -pub const version = @import("pardes_config").version; -pub const commit: ?[]const u8 = @import("pardes_config").commit; +pub const version = @import("build_info").version; +pub const commit: ?[]const u8 = @import("build_info").commit; -pub const isolated = @import("pardes_isolation").isolated; +pub const isolated = @import("pardes_options").isolated; pub const font_picker = platform == .gui or platform == .macos; @@ -442,7 +442,7 @@ test { // A window's build links the window's C (font.c over FreeType and // HarfBuzz) into each of its programs, and their allocator (ui_malloc // and the rest) is gui.zig's. - if (comptime @import("term_options").terminal and platform == .gui) _ = @import("dev").gui; + if (comptime @import("pardes_options").terminal and platform == .gui) _ = @import("dev").gui; } /// The container-level `var`s core/ may hold (at the top of a file, in a diff --git a/core/syntax.zig b/core/syntax.zig index 36aa8c2b..ba3851ab 100644 --- a/core/syntax.zig +++ b/core/syntax.zig @@ -1,5 +1,5 @@ const std = @import("std"); -const config = @import("pardes_config"); +const config = @import("pardes_options"); const tracy = @import("tracy.zig"); const grammar_manifest = @import("grammar_manifest.zig"); const locations = @import("locations.zig"); diff --git a/core/tracy.zig b/core/tracy.zig index 3b0b8621..56429b1b 100644 --- a/core/tracy.zig +++ b/core/tracy.zig @@ -5,7 +5,7 @@ const std = @import("std"); const builtin = @import("builtin"); -pub const enable = if (builtin.is_test) false else @import("pardes_config").enable_tracy; +pub const enable = if (builtin.is_test) false else @import("pardes_options").enable_tracy; const SourceLocation = extern struct { name: ?[*:0]const u8, diff --git a/dev/root.zig b/dev/root.zig index 2c70783f..fc3ccfa8 100644 --- a/dev/root.zig +++ b/dev/root.zig @@ -26,9 +26,9 @@ test { _ = glide; // The frontends', which main.zig's test block collected: a shell's // build (shell-test); the core without a terminal never compiled them. - if (comptime @import("term_options").terminal) { - if (comptime @import("pardes_config").platform == .tui) _ = tui; - if (comptime @import("pardes_config").platform == .gui) _ = gui; + if (comptime @import("pardes_options").terminal) { + if (comptime @import("pardes_options").platform == .tui) _ = tui; + if (comptime @import("pardes_options").platform == .gui) _ = gui; _ = vaxis_input; } } diff --git a/docs/next-editor.md b/docs/next-editor.md index 120b4c09..e7168256 100644 --- a/docs/next-editor.md +++ b/docs/next-editor.md @@ -7,7 +7,7 @@ Decided 2026-11-17 on the coordinator's leans (survey: `.scratch/sketch/reports/editor-lib.md`); built the same day. One source of truth: the library runs the functions pardes runs, compiled from the -same files with `pardes_config.lib` set; nothing is copied for it. +same files with `pardes_options.lib` set; nothing is copied for it. ## The calls, as built diff --git a/docs/next-terminal.md b/docs/next-terminal.md index 26996897..c77ccd33 100644 --- a/docs/next-terminal.md +++ b/docs/next-terminal.md @@ -184,9 +184,9 @@ What differs from the plan above, and why: - **The ops are a compile-time constant, not handed over at start.** `Term.ops` (core/Term.zig:18) is `&@import("term").ops` when the build's - `term_options.terminal` says the core has a terminal, null otherwise. + `pardes_options.terminal` says the core has a terminal, null otherwise. Every core module but core-test's is given `term`; core-test's - (`core_lean` in build.zig) is not, and its `term_options` say so. A + (`core_lean` in build.zig) is not, and its `pardes_options` say so. A run-time `Pardes.Options.terminal` would have put the table in every test's options and every host's start for no gain: no build ever has two terminals, and a null known at compile time drops the dead code. diff --git a/runtime/macos.zig b/runtime/macos.zig index 408915da..24285c07 100644 --- a/runtime/macos.zig +++ b/runtime/macos.zig @@ -359,7 +359,7 @@ fn initCore(runtime: ?*const Runtime, cols_arg: u16, rows_arg: u16) !void { core.settings.workspace_tag = if (std.c.getenv("PARDES_WORKSPACE_TAG")) |v| std.mem.eql(u8, std.mem.span(v), "1") else - @import("pardes_config").workspace_tag; + @import("pardes_options").workspace_tag; core.view().frontend.native_images = true; var prompt_rcs = host_io.Shell.prepare(); diff --git a/runtime/root.zig b/runtime/root.zig index ec89e734..930f3389 100644 --- a/runtime/root.zig +++ b/runtime/root.zig @@ -22,9 +22,9 @@ test { _ = ninep; // main.zig's test block collected the crash file's: a shell's build // (shell-test); the core without a terminal (core-test) never compiled it. - if (comptime @import("term_options").terminal) _ = crash; + if (comptime @import("pardes_options").terminal) _ = crash; // A window's build links the window's C (font.c over FreeType and // HarfBuzz) into each of its programs, and their allocator (ui_malloc // and the rest) is gui.zig's. - if (comptime @import("term_options").terminal and @import("pardes_config").platform == .gui) _ = @import("dev").gui; + if (comptime @import("pardes_options").terminal and @import("pardes_options").platform == .gui) _ = @import("dev").gui; } diff --git a/test/behaviour/panes.zig b/test/behaviour/panes.zig index 8fb85cb7..dcde9c4d 100644 --- a/test/behaviour/panes.zig +++ b/test/behaviour/panes.zig @@ -888,7 +888,7 @@ test "panes: truncating body empties it, and a stat says the length after" { } test "panes: a rename colours a source its new name's language names, its text unchanged" { - if (@import("pardes_config").grammars == .disabled) return error.SkipZigTest; + if (@import("pardes_options").grammars == .disabled) return error.SkipZigTest; var s = try Session.initFile(std.testing.allocator, "fn check() void {}\n"); defer s.deinit(); const n = try s.focused(); diff --git a/test/behaviour/settings.zig b/test/behaviour/settings.zig index bd88b75e..cacee701 100644 --- a/test/behaviour/settings.zig +++ b/test/behaviour/settings.zig @@ -37,7 +37,7 @@ test "settings: Pet is the window's: a terminal's view refuses it; a window take defer s.deinit(); // Which build, from its options, not from the answer: a terminal's view // taking Pet must fail here, not pass as a window. - if (comptime @import("pardes_config").platform == .gui) { + if (comptime @import("pardes_options").platform == .gui) { try std.testing.expectEqualStrings("Pet off", try setting(&s, "Pet")); try s.write("/ctl", "Pet cat\n"); try std.testing.expectEqualStrings("Pet cat", try setting(&s, "Pet")); @@ -106,7 +106,7 @@ test "settings: a bad setting value is quoted, so two different bad values log a test "settings: a setting this frontend cannot show says GUI-only, never run as a command, and DumpDir reads back" { var s = try Session.initFile(std.testing.allocator, "x\n"); defer s.deinit(); - if (comptime @import("pardes_config").platform != .gui) { + if (comptime @import("pardes_options").platform != .gui) { _ = try s.refused("/ctl", "GripWidth 120\n"); try std.testing.expectEqualStrings("GripWidth is GUI-only, invalid here \"GripWidth\"", s.said); // A builtin the GUI alone has, written to a ctl or an exec, never @@ -158,7 +158,7 @@ test "settings: Back and Forward written to exec keep to the focused file" { }); } -const syntax = @import("pardes_config").grammars != .disabled; +const syntax = @import("pardes_options").grammars != .disabled; /// The style /screen draws the cell `into` cells into the first place /// `text` is drawn. @@ -314,7 +314,7 @@ test "settings: the user's startup file loads clean, every word of it known and const ctl = try s.read("/ctl"); for ([_][]const u8{ "Theme monokai_pro_classic\n", "CallstackDepth 64\n", "InactiveDim 5\n", "Shell fish\n", "JumpTrail on\n", "LocationsConfig context:4 tscontext:on tslocations:on layout:stacked\n" }) |line| try expectHas(ctl, line); // The window's words, which a terminal's view leaves to the window. - const window = @import("pardes_config").platform == .gui; + const window = @import("pardes_options").platform == .gui; for ([_][2][]const u8{ .{ "GripWidth", "110" }, .{ "CursorBlink", "off" }, .{ "WindowOpacity", "100" }, .{ "TaglineSize", "80" }, .{ "Pet", "frog" } }) |w| try expectHas(ctl, if (window) s.at("\n{s} {s}\n", .{ w[0], w[1] }) else s.at("\n# {s} unsupported\n", .{w[0]})); } diff --git a/test/output.zig b/test/output.zig index 17525616..dc99be8b 100644 --- a/test/output.zig +++ b/test/output.zig @@ -786,7 +786,7 @@ test "identical result refresh keeps warm content caches without allocation" { const index = try panes.File.lineIndex(p.gpa, file); const styles = try std.testing.allocator.dupe(u8, file.highlights); defer std.testing.allocator.free(styles); - if (@import("pardes_config").grammars != .disabled) try std.testing.expect(styles.len > 0); + if (@import("pardes_options").grammars != .disabled) try std.testing.expect(styles.len > 0); const revision = file.revision; const saved_revision = file.saved_revision; const body_ptr = file.content.ptr; -- cgit v1.3 From dcf6d58f8aacefd9a66817ef4589f68ce2d42e8a Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Thu, 19 Nov 2026 21:56:34 -0300 Subject: build: ghostty's terminal page sized in 4 KiB steps on every target (build/patches.zig `ghostty_page` and `ghostty_mem`, docs/ghostty-page-size.md), so the same pty bytes and resizes give the same emulator on Linux, FreeBSD and an Apple silicon Mac, as a client that replays its session's bytes needs, with Linux and FreeBSD unchanged: ghostty rounds a page to the OS page (src/terminal/page.zig:1770 at the pinned 1.4.0; 4 KiB here and on FreeBSD, 16 KiB on aarch64 macOS) and fills the rounding with rows and grown style room, so the 16 MiB scrollback kept other pages on the Mac: its digest differed from Linux's on every stream that filled the scrollback (source text, build logs, heavy colour, the torture stream: 59 to 1,177 history rows fewer) and its snapshot on the shell stream too (a style capacity hint, 388 against 397); now the layout rounds to 4 KiB and the three assertions that a page's length is a whole number of OS pages (page.zig:247, mem.zig:154 and :346) ask for 4 KiB, which on Linux and FreeBSD is what they were; a Mac maps whole 16 KiB pages under the shorter length (up to 12 KiB a page unused and never touched; 8 KiB for a standard page) and madvise and munmap act on its whole pages; the cross-check driver built from this tree (with the next change) gives on Linux and FreeBSD the lines it gave before the Edit, page counts and bytes included, and on the Mac the same lines, from a ReleaseFast and a ReleaseSafe build through all eight streams with no assertion (.scratch/sketch/reports/pardes-term-xcheck.md, "The reverse Edit"); in place of an earlier form of this change that rounded every target to 16 KiB and cost Linux +0.49% on pardes-perf's at-limit terminal cells and up to 13% of its history; the genizah's ghostty (main e8e7fea1, 2026-06-16) is older than the pin and rounds the same way, so no pin moves it; on both changes: tui term-test 15/15, kitty-test 45/45, core-test 848/991 (143 skipped), shell-test 1027/1030, image-harness and kitty-harness pass; gui unit-test 1625/1629 (4 skipped; the perf check's BaselineHarnessMismatch, the base's), image-harness and kitty-harness pass; the macOS library builds for Linux and aarch64-macos, the FreeBSD tui builds (load 11 to 37); the frame and perf gate (gpu/xcheck-c3, against tree1): 77/77 frames byte-identical, unit-test as the base, perfab corpus2x -0.076% (noise 0.091%), perfops 97 of 97 within 0.1% (terminal on all +0.0069%, the largest +0.0285%) (load 11 to 24) Co-Authored-By: Claude Opus Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T --- build/patches.zig | 32 +++++++++++- docs/ghostty-page-size.md | 128 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 159 insertions(+), 1 deletion(-) create mode 100644 docs/ghostty-page-size.md (limited to 'build') diff --git a/build/patches.zig b/build/patches.zig index d5ac7372..f58fb926 100644 --- a/build/patches.zig +++ b/build/patches.zig @@ -245,11 +245,41 @@ const ghostty_kitty = [_]Edit{ }, }; +/// ghostty's terminal page (src/terminal/page.zig): a page's size is +/// rounded to 4 KiB on every target, not to the OS page (4 KiB on Linux +/// and FreeBSD, 16 KiB on an Apple aarch64 Mac). The same bytes must give +/// the same emulator on every machine a client runs on, and the rounding +/// decides how many rows a page holds and how much room its style and link +/// tables grow to, so how many history rows the 16 MiB scrollback keeps: +/// a Mac had fewer than Linux once it was full, which the digest saw +/// (docs/ghostty-page-size.md). On Linux and FreeBSD this changes nothing; +/// a Mac maps whole 16 KiB pages under a length that is not one, up to +/// 12 KiB a page left unused, and ghostty's assertions that a page's +/// length is a whole number of OS pages (page.zig, mem.zig) ask for 4 KiB. +const ghostty_page = [_]Edit{ + .{ + .old = " const total_size = alignForward(usize, meta_end, std.heap.page_size_min);\n", + .new = " const total_size = alignForward(usize, meta_end, 4 << 10); // pardes (build/patches.zig)\n", + }, + .{ + .old = " assert(l.total_size % std.heap.page_size_min == 0);\n", + .new = " assert(l.total_size % (4 << 10) == 0); // pardes (build/patches.zig)\n", + }, +}; +const ghostty_mem = [_]Edit{.{ + .old = " assert(memory.len % std.heap.page_size_min == 0);\n", + .new = " assert(memory.len % (4 << 10) == 0); // pardes (build/patches.zig): a page's size\n", + .count = 2, +}}; + pub fn ghosttyKitty(b: *std.Build, patch: *std.Build.Step.Compile, dep: *std.Build.Dependency, vt: *std.Build.Module) void { const files = b.addWriteFiles(); // The rest of src as it is; fonts are the app's, not the library's. - _ = files.addCopyDirectory(dep.path("src"), "", .{ .exclude_extensions = &.{ "graphics_image.zig", ".ttf", ".otf" } }); + // ("terminal/page.zig" leaves terminal/snapshot/page.zig in.) + _ = files.addCopyDirectory(dep.path("src"), "", .{ .exclude_extensions = &.{ "graphics_image.zig", "terminal/page.zig", "terminal/mem.zig", ".ttf", ".otf" } }); _ = files.addCopyFile(apply(b, patch, dep, "src/terminal/kitty/graphics_image.zig", &ghostty_kitty, "ghostty_kitty.zig"), "terminal/kitty/graphics_image.zig"); + _ = files.addCopyFile(apply(b, patch, dep, "src/terminal/page.zig", &ghostty_page, null), "terminal/page.zig"); + _ = files.addCopyFile(apply(b, patch, dep, "src/terminal/mem.zig", &ghostty_mem, null), "terminal/mem.zig"); vt.root_source_file = files.getDirectory().path(b, "lib_vt.zig"); } diff --git a/docs/ghostty-page-size.md b/docs/ghostty-page-size.md new file mode 100644 index 00000000..6e65f36a --- /dev/null +++ b/docs/ghostty-page-size.md @@ -0,0 +1,128 @@ +# ghostty: a terminal's state depends on the OS page size + +A report for upstream (https://github.com/ghostty-org/ghostty), against +the commit pardes pins (83fb95624b04, 1.4.0, `build.zig.zon`). pardes +patches its fetched copy at build time (build/patches.zig, `ghostty_page` +and `ghostty_mem`) until it is fixed there, if upstream wants it fixed. + +## What happens + +A page's memory is rounded up to the OS page (`src/terminal/page.zig`, +`Page.layout`): + +```zig +const total_size = alignForward(usize, meta_end, std.heap.page_size_min); +``` + +`page_size_min` is 4 KiB on x86-64 and aarch64 Linux, FreeBSD and x86-64 +macOS, and 16 KiB on aarch64 macOS (Zig's `std/heap.zig`). The rounding is +not only slack: `Capacity.adjust` fills the rounded size with rows +(`availableBytesForGrid` is `total_size` less the metadata), and a style +table that grows is sized to fill it too. A standard page is 401,408 bytes +on Linux and 409,600 on an Apple silicon Mac. The scrollback limit +(`max_scrollback_bytes`) counts these bytes and prunes a whole page at a +time, so the same bytes fed to two terminals of the same size keep +different history on the two machines, and the snapshot of either +records its own capacity hints. + +pardes meets it because a client of a session runs its own emulator on +the pty's bytes: a Mac client of a Linux session must end with the +session's terminal, row for row. + +## Measured + +A driver fed eight streams through pardes's own wrapper +(`core/term/terminal.zig`), at 120x40, in reads of 4,096 and 65,536 bytes, +resized to 61x43 at a third and back at two thirds; then the hash of +pardes's per-unit digest (the active screen's text, the history's extent, +the view, the cursor) and of ghostty's full snapshot. Linux x86-64 (SIMD +on and off) and FreeBSD 15.1 amd64 gave the same lines; the Mac +(Darwin 25.6, arm64): + +| stream | digest | snapshot | history rows, Linux / Mac | +|---|---|---|---| +| shell, 90 KB | equal | differs (a style capacity hint, 388 / 397, and its record's CRC) | 0 / 0 | +| TUI, 31 KB | equal | equal | 0 / 0 | +| source text, 3.1 MB | differs | differs | 25,323 / 25,264 | +| build logs, 1.6 MB | differs | differs | 15,531 / 15,495 | +| heavy colour and links, 10 MB | differs | differs | 14,201 / 13,024 | +| a colour a cell, a link a word, stacked marks, 9 MB | differs | differs | 4,296 / 3,716 | +| kitty images, raw RGBA, 8.4 MB | equal | equal | 0 / 0 | + +The active screen's text, the cursor and the modes are the same on both; +what differs is how much history is kept and, on the last stream, which +links were dropped for lack of room in a page (19,002 `start_hyperlink +OutOfSpace` on Linux, 19,750 on the Mac). The smallest streams that show +it: the first 601,027 bytes of the source text (the first prune) for the +history, the first 11,690 bytes of the shell stream (its page's style +table grows) for the snapshot alone. + +The same driver built for Linux with `std.options.page_size_min = 16 KiB` +gives the Mac's lines exactly, digest and snapshot, on every stream: the +page size is the whole cause. + +## The fix + +Round a page's size to 4 KiB on every target, whatever the OS page is: + +```diff +--- a/src/terminal/page.zig ++++ b/src/terminal/page.zig +@@ Page.layout +- const total_size = alignForward(usize, meta_end, std.heap.page_size_min); ++ const total_size = alignForward(usize, meta_end, 4 << 10); +@@ Page.init +- assert(l.total_size % std.heap.page_size_min == 0); ++ assert(l.total_size % (4 << 10) == 0); +--- a/src/terminal/mem.zig ++++ b/src/terminal/mem.zig +@@ decommit, recommit +- assert(memory.len % std.heap.page_size_min == 0); ++ assert(memory.len % (4 << 10) == 0); +``` + +Why the Mac is the one that changes: on Linux and FreeBSD, where +`page_size_min` is 4 KiB, the three lines are what they were, so their +terminals are byte for byte what they were (the same history, the same +cost); only an Apple silicon Mac's pages shrink to Linux's sizes. + +Why a Mac can: the length of a page's memory need not be a whole number of +OS pages. A page's memory is `mmap`ed (`Page.init`, `AllocPosix`) or a +pool item allocated alone by the page allocator (`UntouchedPool`, ghostty's +tagged allocator on Darwin, which rounds the mapping up to whole pages and +unmaps it the same way); the pointer stays 16 KiB aligned, as its type +says; only the length is shorter than the mapping. `madvise` (`decommit`, +`recommit`: `FREE_REUSABLE`, `FREE_REUSE`) acts on whole pages, and the +last page of a mapping is that page's alone, the slack included. What +asked for whole OS pages were three assertions, which now ask for 4 KiB: +in a safe build they failed at once on a Mac; in a fast one they were +promises to the optimiser. Nothing else in ghostty's terminal, its page +pool, its compression or its snapshot loader reads the rounding. + +With it, the Mac gives Linux's lines on every stream (and with the PNG fix +of docs/zstbi-fp-contract.md, the PNG stream too). + +## What it costs + +Nothing on Linux and FreeBSD. On an Apple silicon Mac a page's mapping +keeps up to 12 KiB it does not use (8 KiB for a standard page: 401,408 +bytes in 409,600), never touched, so never resident; the scrollback's +16 MiB budget counts the 4 KiB-rounded size, so a Mac now keeps Linux's +history (above: 25,323 rows of source text, 14,201 of heavy colour, where +it kept 25,264 and 13,024). + +Measured with the Edit: on Linux and FreeBSD the cross-check driver's +eighteen lines are the lines it gave before, page counts and page bytes +included; pardes-perf's per-operation counts are within 0.03% of the +base's (its terminal cells +0.007%); on the Mac a ReleaseSafe build of +the driver runs all eight streams, the full scrollbacks' pruning and +page reuse included, with no assertion, and gives Linux's lines. + +## Upstream today + +Not read beyond what is on this machine (no network). The pin, 83fb956 +(1.4.0), has the rounding at `page.zig:1770`. The newest other copy here, +`~/05-genizah/ghostty` at its `main` (e8e7fea1, 2026-06-16, 1.3.2-dev), is +OLDER than the pin and has the same line (`page.zig:1753`). So moving the +pin is no fix as far as can be seen from here; whether upstream changed +it after 1.4.0 is not known. -- cgit v1.3 From 406f34120e3013c1900abfadb7a812dfd54ba89e Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Thu, 19 Nov 2026 22:31:10 -0300 Subject: build: no fused multiply-add in zstbi's resize (build/patches.zig `zstbi_cut`: `#pragma STDC FP_CONTRACT OFF`, docs/zstbi-fp-contract.md), so a kitty PNG over 1280 pixels downscales to the same pixels on an Apple silicon Mac as on Linux and FreeBSD, as a client that replays its session's bytes needs: clang contracts `a * b + c` where the CPU has a fused multiply-add, aarch64 always does (the Mac binary had 98 fmadd/fmla in stbir__resize_arbitrary and stbir__resample_horizontal_downsample; the x86-64 ones have none), a fused one rounds once, and the two downscaled pictures of the cross-check's PNG stream came out other pixels on the Mac (the snapshot differed; images are not in the digest) while the one under the bound and raw RGBA did not; with the pragma the Mac's are Linux's; the proof, the cross-check driver built from this tree (and the change before) with no patch of its own (only its step added to a scratch copy): its 18 lines (eight streams by two read sizes, two at 7 bytes: digest and full snapshot after two resizes) the same on Linux x86-64, FreeBSD 15.1 amd64 and the Mac (Darwin 25.6 arm64) (.scratch/sketch/reports/pardes-term-xcheck.md, "Landed"); no zstbi or stb upstream is on this machine to compare; tui term-test 15/15, kitty-test 45/45, core-test 848/991 (143 skipped), shell-test 1027/1030, image-harness and kitty-harness pass; gui unit-test 1625/1629 (4 skipped; the perf check's BaselineHarnessMismatch, the base's), image-harness and kitty-harness pass; the macOS library builds for Linux and aarch64-macos, the FreeBSD tui builds (load 19 to 47); the frame and perf gate (gpu/xcheck-c3, against tree1, with the change before): 77/77 frames byte-identical, perfab corpus2x -0.076%, perfops 97 of 97 within 0.1% Co-Authored-By: Claude Opus Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T --- build/patches.zig | 8 +++++- docs/zstbi-fp-contract.md | 66 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 73 insertions(+), 1 deletion(-) create mode 100644 docs/zstbi-fp-contract.md (limited to 'build') diff --git a/build/patches.zig b/build/patches.zig index f58fb926..3d956d26 100644 --- a/build/patches.zig +++ b/build/patches.zig @@ -175,8 +175,14 @@ pub fn vaxis(b: *std.Build, patch: *std.Build.Step.Compile, vaxis_dep: *std.Buil /// zstbi with stb_image and its writer cut out: of it only its resize is /// left, for a terminal PNG's downscale (build/core.zig, "One PNG /// decoder"). zstbi.deinit still resets the reader's and the writer's flip -/// flags, and Image.deinit frees the resize's output. +/// flags, and Image.deinit frees the resize's output. And no fused +/// multiply-add in the resize: clang contracts `a * b + c` where the CPU +/// has one (aarch64 always does), which rounds once, so a PNG downscaled +/// on an Apple silicon Mac came out pixels apart from Linux's, and the same +/// bytes must give the same terminal on every machine a client runs on +/// (docs/zstbi-fp-contract.md). const zstbi_cut = [_]Edit{ + .{ .old = "#include \n", .new = "#include \n#pragma STDC FP_CONTRACT OFF\n" }, .{ .old = "#define STB_IMAGE_IMPLEMENTATION\n#include \"stb_image.h\"\n", .new = "void stbi_set_flip_vertically_on_load(int flag) { (void)flag; }\nvoid stbi_image_free(void *p) { zstbiFreePtr(p); }\n" }, .{ .old = "#define STB_IMAGE_WRITE_IMPLEMENTATION\n#include \"stb_image_write.h\"\n", .new = "void stbi_flip_vertically_on_write(int flag) { (void)flag; }\n" }, }; diff --git a/docs/zstbi-fp-contract.md b/docs/zstbi-fp-contract.md new file mode 100644 index 00000000..95c067fd --- /dev/null +++ b/docs/zstbi-fp-contract.md @@ -0,0 +1,66 @@ +# stb_image_resize: a downscale's pixels depend on the CPU's fused multiply-add + +A report for upstream (https://github.com/zig-gamedev/zstbi, which vendors +nothings/stb's `stb_image_resize.h` v0.97), against the commit pardes pins +(6b9bea1f, `build.zig.zon`). pardes patches its fetched copy at build time +(build/patches.zig, `zstbi_cut`) until it is fixed there, if upstream wants +it fixed. + +## What happens + +pardes downscales a kitty graphics PNG over 1280 pixels with zstbi's +`stbir_resize_uint8` (core/term/TerminalImages.zig, `decodePng`). The +resize is plain C on floats, with no SIMD of its own, and clang compiles C +with `-ffp-contract=on`: where the target has a fused multiply-add, +`a * b + c` becomes one instruction that rounds once instead of twice. +aarch64 always has one; the x86-64 targets pardes builds for here do not +use one. The aarch64 macOS binary has 66 `fmadd`/`fmla` in +`stbir__resize_arbitrary` and 32 in `stbir__resample_horizontal_downsample`; +the x86-64 Linux and FreeBSD binaries have no `vfmadd` anywhere. So the same +PNG downscales to pixels a step apart on an Apple silicon Mac. + +pardes meets it because a client of a session runs its own emulator on the +pty's bytes: a Mac client of a Linux session must end with the session's +terminal, and a join compares the snapshot (which holds each image's +pixels) of the two. + +## Measured + +Three PNGs sent by direct data (`f=100`): 1601x1203 (downscaled to +1280x961), 700x2001 (to 447x1280) and 333x257 (not downscaled). On Linux +x86-64 (SIMD on and off) and FreeBSD 15.1 amd64 the three images' pixels +were the same; on the Mac (Darwin 25.6, arm64) the two downscaled ones +differed and the third was the same, as were two 1024x768 images sent as +raw RGBA (`f=32`). pardes's per-unit digest does not cover images, so only +the snapshot differed. + +## The fix + +Contraction off for the whole translation unit, at the top of zstbi's C file: + +```diff +--- a/src/zstbi.c ++++ b/src/zstbi.c +@@ -1,3 +1,4 @@ + #include ++#pragma STDC FP_CONTRACT OFF +``` + +(`-ffp-contract=off` in zstbi's build flags is the same.) With it the Mac +binary has no fused multiply-add in `stbir_*`, and the Mac's pixels are +Linux's: the three images, and the snapshot (with the page fix of +docs/ghostty-page-size.md, every stream's). + +## What it costs + +A multiply and an add where there was one instruction, in a resize made +once per image sent (a 1601x1203 picture's), on aarch64 only: not +measured, as nothing else of pardes runs it. + +## Upstream today + +Not read beyond what is on this machine (no network): no copy of zstbi or +stb is in `~/05-genizah`. The three zstbi copies in `zig-pkg/` (the pin and +two others) all vendor `stb_image_resize.h` v0.97 with no pragma. stb's own +successor, `stb_image_resize2.h`, has SIMD paths of its own; moving to it +would be another question of the same kind, not a fix of this one. -- cgit v1.3