From a75956bb3443aa8aac778d2ff12c42f5ef99e0e9 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Wed, 18 Nov 2026 20:52:50 -0300 Subject: runtime: main, daemon, upgrade, crash, addon_test, 9p_io, 9p and macos.zig into runtime/ (the reorganisation's tree, step 2a), skill.txt with main.zig, its one reader: module `runtime` (runtime/root.zig) and the core, each naming the other, a product's root (main.zig, macos.zig) a module of its own over both; the files name across by module (`@import("runtime").daemon`, `@import("core").look`), pardes.zig exporting what they name (ctl, edit_cmd, tracy, selection_pipe, and the frontends until they move); core-test and shell-test run each module's test program, so the same tests run (the ledger: every named test of every suite the base's, tui and gui); nothing else changes: frames byte-identical, the same counts (tui core-test 822/963, the one more an anonymous collector) Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T --- build/core.zig | 88 ++++++++++++++++++++++++++++++++++++++----------------- build/macos.zig | 2 ++ build/process.zig | 12 +++----- build/tests.zig | 31 ++++++++++++-------- build/tools.zig | 2 +- 5 files changed, 87 insertions(+), 48 deletions(-) (limited to 'build') diff --git a/build/core.zig b/build/core.zig index 3b9eefa8..8749d612 100644 --- a/build/core.zig +++ b/build/core.zig @@ -284,6 +284,8 @@ 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, @@ -296,8 +298,9 @@ pub const Parts = struct { /// Which core: its root and the few ways the products differ. pub const Core = struct { - /// src/main.zig for a shell, src/pardes.zig for the core, or a file - /// whose tests run on the core's imports. + /// runtime/main.zig for a shell (runtime/macos.zig for the macOS + /// library), src/pardes.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. @@ -315,10 +318,21 @@ pub const Core = struct { util: bool = false, }; -/// A core module, everything it imports and links named here and nowhere else. -pub fn module(b: *std.Build, p: Parts, c: Core) *std.Build.Module { - const m = b.createModule(.{ .target = p.target, .optimize = p.optimize, .root_source_file = b.path(c.root), .link_libc = true }); - m.addImport("cloud9", p.cloud9); +/// What `module` makes: the core and the runtime, each naming the other +/// (`core`, `runtime`), and the module a compile roots at. +pub const Modules = struct { + /// A product's own file (runtime/main.zig, runtime/macos.zig) naming + /// both, the runtime, or the core. + root: *std.Build.Module, + core: *std.Build.Module, + runtime: *std.Build.Module, +}; + +/// A core and the runtime beside it, everything they import and link +/// named here and nowhere else. +pub fn module(b: *std.Build, p: Parts, c: Core) Modules { + const in_runtime = std.mem.startsWith(u8, c.root, "runtime/"); + const m = b.createModule(.{ .target = p.target, .optimize = p.optimize, .root_source_file = b.path(if (in_runtime) "src/pardes.zig" else c.root), .link_libc = true }); // 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", .{}); @@ -338,28 +352,47 @@ pub fn module(b: *std.Build, p: Parts, c: Core) *std.Build.Module { }); m.link_libcpp = true; }; - if (c.builtin_addons) if (p.pdf) |pdf| m.addImport("pdf_addon", pdf); m.linkLibrary(p.zstd); - if (c.builtin_addons) m.addImport("image_addon", p.image); - if (c.terminal) { - m.addImport("term", p.term); - m.addOptions("term_options", p.term_on); - } else m.addOptions("term_options", p.term_off); - m.addImport("plain", p.plain); - m.addImport("pardes_addon", p.kind); - m.addImport("generated_themes", p.themes); - p.ts.wire(m); - m.addImport("mvzr", p.mvzr); - m.addImport("c_heap", p.c_heap); - m.addImport("vaxis", p.vaxis); - m.addImport("uucode", p.uucode); - m.addImport("xitdb", p.xitdb); - // config.zig's test checks the words and keys docs/typ names exist. - m.addOptions("doc_typ", p.doc_typ); - m.addOptions("pardes_config", c.config); - m.addOptions("pardes_isolation", if (c.isolated) p.iso_on else p.iso_off); - m.addOptions("builtin_addons", if (c.builtin_addons) p.builtin_on else p.builtin_off); - return m; + 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" }) |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 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(); + for ([_]*std.Build.Module{ m, runtime, 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); + if (p.ts.mod) |ts| x.addImport("tree-sitter", ts); + if (ts_queries) |q| x.addImport("ts_queries", q); + x.addImport("mvzr", p.mvzr); + x.addImport("c_heap", p.c_heap); + x.addImport("vaxis", p.vaxis); + x.addImport("uucode", p.uucode); + 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("core", m); + x.addImport("runtime", runtime); + } + return .{ .root = root, .core = m, .runtime = runtime }; } /// What `assemble` makes besides the parts: the shells' options, the @@ -598,6 +631,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, diff --git a/build/macos.zig b/build/macos.zig index bcaf4d4c..7289e70a 100644 --- a/build/macos.zig +++ b/build/macos.zig @@ -22,6 +22,8 @@ pub fn add(b: *std.Build, c: struct { .optimize = c.optimize, }); c.root_mod.addImport("pardes.h", header.createModule()); + // The app's watcher, which macos.zig's test reads beside its own. + c.root_mod.addAnonymousImport("macos/Sources/FileWatcher.swift", .{ .root_source_file = b.path("src/macos/Sources/FileWatcher.swift") }); const lib = b.addLibrary(.{ .name = "pardes", diff --git a/build/process.zig b/build/process.zig index 16f9b48b..d3ae9e68 100644 --- a/build/process.zig +++ b/build/process.zig @@ -15,16 +15,11 @@ pub fn add(b: *std.Build, opts: struct { optimize: std.builtin.OptimizeMode, ghostty_vt: ?*std.Build.Module, cloud9: *std.Build.Module, + /// The runtime whose 9P client the runner speaks (build/core.zig `module`). + runtime: *std.Build.Module, /// The build is the window's (-Dplatform=gui): the process tests drive it. gui: bool = false, }) void { - const ninep_client = b.createModule(.{ - .target = opts.target, - .optimize = opts.optimize, - .root_source_file = b.path("src/9p_io.zig"), - .link_libc = true, - }); - ninep_client.addImport("cloud9", opts.cloud9); const process_test = b.addExecutable(.{ .name = "pardes-process-test", .root_module = b.createModule(.{ @@ -35,7 +30,8 @@ pub fn add(b: *std.Build, opts: struct { }), }); if (opts.ghostty_vt) |vt| process_test.root_module.addImport("ghostty-vt", vt); - process_test.root_module.addImport("9p_io", ninep_client); + // The 9P client (runtime/9p_io.zig), through the runtime beside the core. + process_test.root_module.addImport("runtime", opts.runtime); process_test.root_module.addImport("cloud9", opts.cloud9); switch (opts.target.result.os.tag) { .freebsd, .netbsd, .openbsd => process_test.root_module.linkSystemLibrary("util", .{}), diff --git a/build/tests.zig b/build/tests.zig index e0b9235a..2d43d743 100644 --- a/build/tests.zig +++ b/build/tests.zig @@ -9,7 +9,10 @@ const program = tools.program; /// addon-test (and the addons it loads), kitty-test, the 9P roots. pub fn add(b: *std.Build, c: struct { addon_mod: *std.Build.Module, - core_lean: *std.Build.Module, + /// The core without a terminal and the runtime beside it: core-test. + core_lean: core.Modules, + /// The shell's root, core and runtime: shell-test. + root_set: core.Modules, core_module: *std.Build.Module, /// core_module's configuration, for the test roots that run on its imports. core_cfg: core.Core, @@ -60,12 +63,15 @@ pub fn add(b: *std.Build, c: struct { // The perf and fs bench programs' own tests: they compile no editor. _ = units.add(b, units.root(b, "test/perf.zig", true, &.{.{ .name = "perf_options", .module = c.tools.perf_options.createModule() }}), null); _ = units.add(b, units.root(b, "test/fs_bench.zig", null, &.{}), null); - const core_test = b.addTest(.{ .root_module = c.core_lean, .filters = c.test_filters }); - const run_core_test = b.addRunArtifact(core_test); - run_core_test.has_side_effects = true; - const core_test_step = b.step("core-test", "run core tests without native shell tests, on the core without a terminal (a test that needs one skips)"); - core_test_step.dependOn(&run_core_test.step); - if (testMatch(b, c.unit_profile, c.test_filters, core_test_step)) |check| check.addArtifactArg(core_test); + const core_test_step = b.step("core-test", "run core tests without native shell tests, on the core without a terminal (a test that needs one skips), and the runtime's beside it"); + const core_match = testMatch(b, c.unit_profile, c.test_filters, core_test_step); + for ([_]*std.Build.Module{ c.core_lean.core, c.core_lean.runtime }) |m| { + const core_test = b.addTest(.{ .root_module = m, .filters = c.test_filters }); + const run_core_test = b.addRunArtifact(core_test); + run_core_test.has_side_effects = true; + core_test_step.dependOn(&run_core_test.step); + if (core_match) |check| check.addArtifactArg(core_test); + } // The terminal module's own tests (src/term/): the emulator without a core. const run_term_test = units.add(b, b.addTest(.{ .root_module = c.parts.term, .filters = c.test_filters }), null); b.step("term-test", "run the terminal module's own tests (src/term/)").dependOn(&run_term_test.step); @@ -190,18 +196,18 @@ pub fn add(b: *std.Build, c: struct { // stays reachable even when Zig's filter leaves the core's // anonymous test-import block out. for ([_]struct { path: []const u8, step: []const u8, about: []const u8, filters: []const []const u8 }{ - .{ .path = "src/9p_io.zig", .step = "9p-io-test", .about = "run native 9P transport and client integration tests", .filters = &.{ "Unix and TCP", "one fetch", "expired sessions", "posts itself" } }, + .{ .path = "runtime/root.zig", .step = "9p-io-test", .about = "run native 9P transport and client integration tests", .filters = &.{ "Unix and TCP", "one fetch", "expired sessions", "posts itself" } }, .{ .path = "src/fs.zig", .step = "fs-unit-test", .about = "run filesystem unit tests", .filters = c.test_filters }, }) |t| { var cfg = c.core_cfg; cfg.root = t.path; - const m = core.module(b, c.parts, cfg); + const m = core.module(b, c.parts, cfg).root; b.step(t.step, t.about).dependOn(&b.addRunArtifact(b.addTest(.{ .root_module = m, .filters = t.filters })).step); } const cloud9: []const std.Build.Module.Import = &.{.{ .name = "cloud9", .module = c.parts.cloud9 }}; _ = units.add(b, units.root(b, "test/history.zig", false, cloud9), null); - const protocol_tests = units.root(b, "src/9p.zig", false, cloud9); + const protocol_tests = units.root(b, "runtime/9p.zig", false, cloud9); const protocol_step = b.step("9p-test", "run freestanding 9P protocol tests"); protocol_step.dependOn(&units.add(b, protocol_tests, null).step); if (testMatch(b, c.unit_profile, c.test_filters, protocol_step)) |check| check.addArtifactArg(protocol_tests); @@ -213,10 +219,11 @@ pub fn add(b: *std.Build, c: struct { _ = units.add(b, units.root(b, "test/deck/replay.zig", null, &.{.{ .name = "deck", .module = b.createModule(.{ .target = c.target, .optimize = c.optimize, .root_source_file = b.path("src/gui/deck.zig") }) }}), null); if (c.platform == .tui or c.platform == .gui) { - const run_shell_test = units.add(b, b.addTest(.{ .root_module = c.root_mod, .filters = c.test_filters }), null); // The native shell's tests alone, without the perf gate's // ReleaseFast build: what a -Dtest-filter iteration wants. - b.step("shell-test", "run the native shell's unit tests (src/main.zig's)").dependOn(&run_shell_test.step); + const shell_test_step = b.step("shell-test", "run the native shell's unit tests (runtime/main.zig's, and its core's and runtime's)"); + for ([_]*std.Build.Module{ c.root_set.root, c.root_set.core, c.root_set.runtime }) |m| + shell_test_step.dependOn(&units.add(b, b.addTest(.{ .root_module = m, .filters = c.test_filters }), null).step); const profile_test = b.addExecutable(.{ .name = "pardes-unit-profile-test", .root_module = b.createModule(.{ diff --git a/build/tools.zig b/build/tools.zig index 92217c4e..c6f25e6d 100644 --- a/build/tools.zig +++ b/build/tools.zig @@ -236,7 +236,7 @@ pub fn add(b: *std.Build, c: struct { // a terminal: its tests reach the editor's modes (modal.zig). var syntax_cfg = c.lean; syntax_cfg.root = "src/syntax.zig"; - const syntax_module = core.module(b, c.parts, syntax_cfg); + const syntax_module = core.module(b, c.parts, syntax_cfg).root; const syntax_runner = program(b, "pardes-syntax", "test/syntax.zig", c.target, c.optimize, &.{.{ .name = "syntax", .module = syntax_module }}); const run_syntax = b.addRunArtifact(syntax_runner); run_syntax.addPassthruArgs(); -- cgit v1.3