diff options
Diffstat (limited to 'build')
| -rw-r--r-- | build/core.zig | 115 | ||||
| -rw-r--r-- | build/library.zig | 2 | ||||
| -rw-r--r-- | build/tests.zig | 4 |
3 files changed, 45 insertions, 76 deletions
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 <seeds> | --replay)"); _ = units.add(b, behaviour_tests, behaviour_test_step); // An addon's own test: `--addon-test` over the fake (the template) |
