diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-18 20:52:50 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-18 21:22:58 -0300 |
| commit | a75956bb3443aa8aac778d2ff12c42f5ef99e0e9 (patch) | |
| tree | 17547cbf6606c8bd05be313cd8f835cb85d13e57 /build/core.zig | |
| parent | 5b33c88476054fffc1044fff0526f7f0b28563cf (diff) | |
| download | pardes-a75956bb3443aa8aac778d2ff12c42f5ef99e0e9.tar.gz pardes-a75956bb3443aa8aac778d2ff12c42f5ef99e0e9.zip | |
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 <[email protected]>
Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T
Diffstat (limited to 'build/core.zig')
| -rw-r--r-- | build/core.zig | 88 |
1 files changed, 61 insertions, 27 deletions
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, |
