From 852299dd8d056b90446508757d8c6dacf8975abe Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Fri, 20 Nov 2026 03:57:20 -0300 Subject: build: the `-Dtree-sitter=disabled` tier is deleted (pardes-build-2 item 2; P31's Q5, decided on the evidence 2026-11-20): a pardes with no tree-sitter at all, whose syntax.zig stubbed `ts` with four opaque types and answered every call empty; it did not compile on the base (`zig build install -Dplatform=tui -Dtree-sitter=disabled`: core/indent.zig:48 `struct 'syntax.ts__struct_3541' has no member named 'Tree'`, since indent.zig reads the parse tree the stub never had) and nobody set it; out with it: the `disabled` value of `TreeSitterGrammars`, build/core.zig's `treeSitter` made always (its module and its queries no longer optional, so `TreeSitter.wire` and `core.module` add them plainly), the stub `ts` and `ts_queries`, `syntax.enabled` and every branch that was for it: 32 guard lines and 16 terms of a condition in core/syntax.zig (its `start` and `stop` unwrapped), whole test guards in core/draw.zig, Stream.zig, File.zig, Query.zig, Core.zig (2), mouse.zig, replica.zig (2), test/output.zig (7), test/panes.zig (11) and test/behaviour/{panes,settings}.zig, a term in Stream.zig's two worker tests, `TreeContext.enabled` (builtins.zig) and the config table's condition on it (config.zig), test/output.zig's two conditions on the grammars; abi/wire.zig hashes the grammar set as the same four words (`true true` for highlighting and the Zig grammar, which every set has now), so `pardes version`'s semantics line did not move: 8b6382fddba7b382 on tui, gui, the bare build's two, both statics and FreeBSD, 0520895ac88d25ad with -Dtree-sitter=minimal, as at item 1; the manual's option table and the changelog say it; build.zig and build/ 2,981 -> 2,974 lines; every shape configures (11) and builds (tui, gui, bare, static musl and gui, FreeBSD, -Dtree-sitter=minimal, the macOS library for Linux and aarch64-macos); tui core-test 856/1006 (150 skipped), shell-test 1046/1049, pane-test 183/184, behaviour-test 275/275 and -- --replay 275/275, term-test 17/17, kitty-test 45/45, addon-test 5/5, lib-test, hxlib 538 cases 0 mismatches, process-test 0 of 144 failed (diffstack failed once and passed on the runner's own retry), gui unit-test 1643/1647 (the perf check's BaselineHarnessMismatch, the base's); load 5-26 on 16 cores Co-Authored-By: Claude Opus Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T --- build/library.zig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'build/library.zig') diff --git a/build/library.zig b/build/library.zig index 8a23debc..cabb175b 100644 --- a/build/library.zig +++ b/build/library.zig @@ -12,7 +12,7 @@ const patches = @import("patches.zig"); pub fn build(b: *std.Build) void { const target = b.standardTargetOptions(.{}); const optimize = b.standardOptimizeOption(.{}); - const tree_sitter_grammars = b.option(TreeSitterGrammars, "tree-sitter", "tree-sitter grammar set: disabled, zig, minimal (c/c++/zig), full") orelse .full; + const tree_sitter_grammars = b.option(TreeSitterGrammars, "tree-sitter", "tree-sitter grammar set: zig, minimal (c/c++/zig), full") orelse .full; var threaded: std.Io.Threaded = .init(b.allocator, .{}); defer threaded.deinit(); const io = threaded.io(); -- cgit v1.3 From fc9e2eaf5ad86719a3bc57d18ce4ad302461dfbd Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Fri, 20 Nov 2026 04:36:44 -0300 Subject: build: the grammar set is one option, `grammars`, with `none | minimal | full` (pardes-build-2 item 3; the start design's step 3, P31's lean): for a package that depends on pardes `.grammars = .minimal` where it wrote `.@"tree-sitter" = .minimal`, and for pardes's own products `-Dgrammars=minimal` where `-Dtree-sitter=minimal` was (one option, not two spellings of one: no live gate script passes -Dtree-sitter, only two configure-matrix scripts of an earlier agent's and the first build pass's shapes script, which also name test/lib and the deleted `disabled` and change anyway; the three consumers' lines change for `.grammars` anyway); `none` is tree-sitter's runtime with no grammar, for a program that hands in its own at run time (sketchbook's examples/live, which set `zig` only because it was the smallest set that kept syntax on: `zig`, its one setter, goes, and the Zig grammar is a minimal one: grammar_manifest's tiers are minimal and full); syntax.zig's sets read `none` (`minimal_grammars` is `!= .none`, four tests' doubled condition one), the Build pane prints the set's own name (`none` was what it printed for the zig set), and abi/wire.zig hashes the set as the four words it was hashed as, so a minimal or a full set's semantics did not move (8b6382fddba7b382 full, 0520895ac88d25ad minimal, as at items 1 and 2) and `none` hashes as highlighting with no grammar (794d23e0255281f8; the old zig set's hash is gone with it); test/lib asks with `.grammars`; the manual's table, its library section's two lines and the changelog say it; build.zig and build/ 2,974 -> 2,971 lines; -Dgrammars=full, minimal and none each install and pass lib-test, and the old spelling is refused (`invalid option: "tree-sitter"`); the suites run on the stack's top (item 5) Co-Authored-By: Claude Opus Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T --- abi/wire.zig | 14 +++++++------- build.zig | 4 ++-- build/core.zig | 5 +---- build/library.zig | 4 ++-- core/CHANGELOG.md | 8 ++++++-- core/Output.zig | 2 +- core/grammar_manifest.zig | 4 ++-- core/lib_syntax.zig | 2 +- core/syntax.zig | 11 +++++------ docs/typ/building.typ | 10 +++++----- test/lib/build.zig | 2 +- 11 files changed, 33 insertions(+), 33 deletions(-) (limited to 'build/library.zig') diff --git a/abi/wire.zig b/abi/wire.zig index 4f6e199b..a36e746b 100644 --- a/abi/wire.zig +++ b/abi/wire.zig @@ -63,19 +63,19 @@ const family = switch (config.platform) { pub const semantics: u64 = blk: { @setEvalBranchQuota(1_000_000); // The grammar set as the four words it was hashed as when it was four - // options (highlighting, zig, minimal, full), so the hash stays: - // highlighting and the Zig grammar are in every set. + // options (highlighting, zig, minimal, full), so the hash of a minimal + // or a full set stays: every set has highlighting, `none` no grammar. const g = config.grammars; // The two long ones (the dependencies, 2.5 KB, and the tape's shape, // 11 KB) joined on, not formatted: formatting them at comptime was 5 % // of a compile of the core. break :blk std.hash.Wyhash.hash(0, std.fmt.comptimePrint( - "wire {d}\npardes {s} {s}\n{s} grammars true true {} {} workspace_tag {} sources {}\nusize {d} {t}\n", + "wire {d}\npardes {s} {s}\n{s} grammars true {} {} {} workspace_tag {} sources {}\nusize {d} {t}\n", .{ - version, build_info.version, build_info.commit orelse "unstamped", - family, g != .zig, 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 != .none, g != .none, + g == .full, config.workspace_tag, config.embed_sources, + @sizeOf(usize), builtin.cpu.arch.endian(), }, ) ++ build_info.deps ++ "\n" ++ pardes.tape.shape); }; diff --git a/build.zig b/build.zig index 2a20f5b9..e31464f7 100644 --- a/build.zig +++ b/build.zig @@ -32,7 +32,7 @@ pub const PerfBuild = struct { pub const macos_min_version: std.SemanticVersion = .{ .major = 13, .minor = 0, .patch = 0 }; -pub const TreeSitterGrammars = enum { zig, minimal, full }; +pub const TreeSitterGrammars = enum { none, minimal, full }; pub fn build(b: *std.Build) void { // A package that depends on pardes takes its library; nothing of the @@ -108,7 +108,7 @@ pub fn build(b: *std.Build) void { }), }); const c_optimize: std.lang.Optimize = if (optimize == .debug) .fast else optimize; - const tree_sitter_grammars = b.option(TreeSitterGrammars, "tree-sitter", "tree-sitter grammar set: zig, minimal (c/c++/zig), full") orelse .full; + const tree_sitter_grammars = b.option(TreeSitterGrammars, "grammars", "the tree-sitter grammars compiled in: none (the runtime alone), minimal (C, C++ and Zig) or full (all of them; the default)") orelse .full; const tracy = b.option([]const u8, "tracy", "enable Tracy profiling; supply the path to a Tracy source checkout"); const macos_sdk = b.option([]const u8, "macos-sdk", "the macOS SDK a gui built for macOS from another system takes SDL's headers and frameworks from"); const macos_identity = b.option([]const u8, "macos-identity", "codesigning identity for pardes.app (default: ad-hoc)") orelse "-"; diff --git a/build/core.zig b/build/core.zig index 903b5602..b668211d 100644 --- a/build/core.zig +++ b/build/core.zig @@ -166,10 +166,7 @@ pub fn treeSitter(b: *std.Build, io: std.Io, target: std.Build.ResolvedTarget, c var ts_libs: std.ArrayList(*std.Build.Step.Compile) = .empty; const ts_queries = b.addOptions(); inline for (grammar_manifest.all) |g| { - if (tree_sitter_grammars == .full or - (tree_sitter_grammars == .minimal and g.tier != .full) or - (tree_sitter_grammars == .zig and g.tier == .zig)) - grammar: { + if (tree_sitter_grammars == .full or (tree_sitter_grammars == .minimal and g.tier == .minimal)) grammar: { const dep = b.dependencyLazy(g.dep, .{}) catch break :grammar; const upstream = configureRead(b, io, dep.builder.root, g.query, 0x100000) catch @panic("read " ++ g.name ++ " highlights"); // the patterns that colour, filtered here once and not in diff --git a/build/library.zig b/build/library.zig index cabb175b..9a1bfb67 100644 --- a/build/library.zig +++ b/build/library.zig @@ -6,13 +6,13 @@ const patches = @import("patches.zig"); /// pardes as a library, all a package that depends on it is given: the /// `pardes-syntax` module (core/lib_syntax.zig), the grammars, highlighting /// and themes for a program that draws source text itself. It takes -/// tree-sitter and the grammars of its `tree-sitter` option and no other +/// tree-sitter and the grammars of its `grammars` option and no other /// dependency, so nothing else is fetched (build.zig.zon). test/lib is such /// a package, which `lib-test` builds. pub fn build(b: *std.Build) void { const target = b.standardTargetOptions(.{}); const optimize = b.standardOptimizeOption(.{}); - const tree_sitter_grammars = b.option(TreeSitterGrammars, "tree-sitter", "tree-sitter grammar set: zig, minimal (c/c++/zig), full") orelse .full; + const tree_sitter_grammars = b.option(TreeSitterGrammars, "grammars", "the tree-sitter grammars compiled in: none (the runtime alone), minimal (C, C++ and Zig) or full (all of them; the default)") orelse .full; var threaded: std.Io.Threaded = .init(b.allocator, .{}); defer threaded.deinit(); const io = threaded.io(); diff --git a/core/CHANGELOG.md b/core/CHANGELOG.md index b1875877..813f24e6 100644 --- a/core/CHANGELOG.md +++ b/core/CHANGELOG.md @@ -212,7 +212,7 @@ grammars, highlighting, declarations, syntax tree and themes as the editor has them, for a program that draws source text itself. Every dependency but tree-sitter's runtime is lazy in the manifest, so such a - package fetches the runtime and the grammars of its `tree-sitter` set + package fetches the runtime and the grammars of its `grammars` set and nothing else; `zig build lib-test`, which `unit-test` runs, builds one (`test/lib`). The markdown grammar is pinned by its commit: its branch has moved, and a fresh checkout could not fetch it. @@ -574,7 +574,11 @@ terminal's pardes with no host but the terminal and no filesystem had not compiled for some releases, and nothing ran it. So is `-Dtree-sitter=disabled`, a pardes with no tree-sitter, which did not - compile either: every build has the runtime and the Zig grammar. + compile either; every build has tree-sitter's runtime. The grammar set + is `-Dgrammars` (`.grammars` for a package that depends on pardes, no + longer `.@"tree-sitter"`): `none`, the runtime alone, where a program + hands in a grammar of its own at run time, `minimal` or `full`; the + `zig` set, which `none` replaces, is gone. ## 0.24 diff --git a/core/Output.zig b/core/Output.zig index 759bada9..c7bfde14 100644 --- a/core/Output.zig +++ b/core/Output.zig @@ -907,7 +907,7 @@ pub fn openBuild(p: *Pardes, id: usize) !void { @tagName(builtin.abi), @tagName(build_options.platform), }); 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", + @tagName(build_options.grammars), if (build_options.builtin_addons) "compiled in" else "loaded from /lib/pardes/addons", @import("wire").semantics, build_info.deps, diff --git a/core/grammar_manifest.zig b/core/grammar_manifest.zig index 711c31a4..b4ff30b9 100644 --- a/core/grammar_manifest.zig +++ b/core/grammar_manifest.zig @@ -5,7 +5,7 @@ const std = @import("std"); -pub const Tier = enum { zig, minimal, full }; +pub const Tier = enum { minimal, full }; pub const Grammar = struct { name: []const u8, @@ -58,7 +58,7 @@ pub const all = [_]Grammar{ \\"#" @keyword \\ }, - .{ .name = "zig", .dep = "ts_zig", .exts = &.{ ".zig", ".zon" }, .tier = .zig }, + .{ .name = "zig", .dep = "ts_zig", .exts = &.{ ".zig", ".zon" }, .tier = .minimal }, }; /// The names a language goes by besides its grammar's: a fence's `py`, diff --git a/core/lib_syntax.zig b/core/lib_syntax.zig index a25af884..f10f88a5 100644 --- a/core/lib_syntax.zig +++ b/core/lib_syntax.zig @@ -15,7 +15,7 @@ const colors = @import("colors.zig"); const modal = @import("modal.zig"); /// Every grammar pardes knows (`all`), by name or alias (`byName`) and by -/// path (`byPath`). The build's `tree-sitter` option says which of them are +/// path (`byPath`). The build's `grammars` option says which of them are /// compiled in, and `supportsPath` answers for this build. pub const grammars = @import("grammar_manifest.zig"); pub const supportsPath = syntax.supportsPath; diff --git a/core/syntax.zig b/core/syntax.zig index 1147b6b9..19831ec2 100644 --- a/core/syntax.zig +++ b/core/syntax.zig @@ -7,7 +7,7 @@ const regexp = @import("regexp.zig"); const c_heap = @import("c_heap"); const diff = @import("diff.zig"); -const minimal_grammars = config.grammars == .minimal or config.grammars == .full; +const minimal_grammars = config.grammars != .none; const full_grammars = config.grammars == .full; pub const ts = @import("tree-sitter"); @@ -37,7 +37,6 @@ const Spec = struct { fn grammarSelected(comptime g: grammar_manifest.Grammar) bool { return switch (g.tier) { - .zig => true, .minimal => minimal_grammars, .full => full_grammars, }; @@ -1314,7 +1313,7 @@ test "syntax context multiline bindings and C++ namespaces preserve declaration try std.testing.expectEqual(@as(usize, 1), zig_declarations.len); try std.testing.expectEqual(@as(usize, 0), zig_declarations[0].start_line); try std.testing.expectEqual(@as(usize, 1), zig_declarations[0].header_end_line); - if (!minimal_grammars and !full_grammars) return; + if (!minimal_grammars) return; const cpp_source = "namespace example {\nstruct Outer {\n int run() {\n return 1;\n }\n};\n}\n"; const cpp_declarations = try contextDeclarations(gpa, "nested.cpp", cpp_source); defer gpa.free(cpp_declarations); @@ -1342,7 +1341,7 @@ test "syntax context Rust modules impls and methods remain nested" { } test "syntax formatted locations color hidden context and preserve multiline source" { - if (!minimal_grammars and !full_grammars) return; + if (!minimal_grammars) return; const gpa = std.testing.allocator; start(gpa); defer stop(); @@ -1889,7 +1888,7 @@ test "syntax allocator switching clears default-runtime caches" { } test "syntax location context snapshots retain omitted multiline comment scope" { - if (!minimal_grammars and !full_grammars) return; + if (!minimal_grammars) return; const gpa = std.testing.allocator; start(gpa); defer stop(); @@ -1934,7 +1933,7 @@ test "syntax declaration locations clear snapshots without muting ordinary conte } test "syntax stacked addresses do not split multiline source groups" { - if (!minimal_grammars and !full_grammars) return; + if (!minimal_grammars) return; const gpa = std.testing.allocator; start(gpa); defer stop(); diff --git a/docs/typ/building.typ b/docs/typ/building.typ index 901f2ca2..8403df9a 100644 --- a/docs/typ/building.typ +++ b/docs/typ/building.typ @@ -60,7 +60,7 @@ must share with its session; `pardes --help` lists every flag. [`-Dplatform`], [`tui`, `gui`, `macos`; absent: the tui and SDL shells together, installed into `~/.local`], [`-Dpdf`], [bool: build the pdf addon, fetching MuPDF the first time; default on once MuPDF is fetched, and off Linux], [`-Djpx`], [bool, `true`: JPEG 2000, and with it scanned PDFs], - [`-Dtree-sitter`], [`zig`, `minimal`, `full`; `full`], + [`-Dgrammars`], [the tree-sitter grammars compiled in: `none` (the runtime alone), `minimal` (C, C++ and Zig) or `full` (all of them; the default)], [`-Dembed-sources`], [bool, `false`: serve the sources under #file("/src")], [`-Dhome-install`], [bool: a bare `zig build` also copies the binaries into `~/.local/bin` and the addon steps theirs into `$XDG_DATA_HOME/pardes/addons`, default true; with `-Dplatform` only `true` copies, and the addons alone], [`-Dstamp-commit`], [bool: the git commit in `--version` and crash records; on for release builds and the `~/.local` install], @@ -104,7 +104,7 @@ it. const pardes = b.dependency("pardes", .{ .target = target, .optimize = optimize, - .@"tree-sitter" = .minimal, + .grammars = .minimal, }); exe.root_module.addImport("pardes-syntax", pardes.module("pardes-syntax")); ``` @@ -122,8 +122,8 @@ for a language's name. [`start`, `stop`], [tree-sitter's allocator, and the end of the parsers kept per language], ) -The `tree-sitter` option is the build's own: `zig`, `minimal` (C, C++ -and Zig) or `full`, the default. Every dependency but tree-sitter's +The `grammars` option is the build's own: `none` (the runtime alone), +`minimal` (C, C++ and Zig) or `full` (all of them; the default). Every dependency but tree-sitter's runtime is lazy in the manifest, so the package fetches the runtime and its set's grammars and compiles those alone; pardes's own build asks for what it is missing in one round. Zig still unpacks a lazy package whose @@ -146,7 +146,7 @@ a package imports one of the two. const pardes = b.dependency("pardes", .{ .target = target, .optimize = optimize, - .@"tree-sitter" = .minimal, + .grammars = .minimal, .editor = true, }); exe.root_module.addImport("pardes-editor", pardes.module("pardes-editor")); diff --git a/test/lib/build.zig b/test/lib/build.zig index 436517d4..171812e9 100644 --- a/test/lib/build.zig +++ b/test/lib/build.zig @@ -8,7 +8,7 @@ const std = @import("std"); pub fn build(b: *std.Build) void { const target = b.standardTargetOptions(.{}); const optimize = b.standardOptimizeOption(.{}); - const pardes = b.dependency("pardes", .{ .target = target, .optimize = optimize, .@"tree-sitter" = .minimal, .editor = true }); + const pardes = b.dependency("pardes", .{ .target = target, .optimize = optimize, .grammars = .minimal, .editor = true }); const step = b.step("test", "colour, outline and walk a C and a Zig source through pardes's library, and edit a text with its editor"); // A file belongs to one module: the syntax alone, and the editor (which // has it as `.syntax`), each a test of its own. -- cgit v1.3 From a3634ab3dbf2fabd997f137c47eafd7bc6c442b0 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Fri, 20 Nov 2026 04:37:18 -0300 Subject: build: build.zig reads like sketchbook's (pardes-build-2 item 4; the start design's 4.3 and 4.4): its head comment is a consumer's lines, both shapes (`pardes-syntax` with `.grammars = .minimal`, as computeranim's anim takes it; `pardes-editor` with `.grammars = .none, .editor = true` and a grammar of its own, as sketchbook's examples/live does) and what each option selects, and `build()` begins with what such a package may ask for, the mode and `grammars` (pardes's own build takes both too), then `if (!b.isRoot()) return library(...)` with the target and `editor`, which only a dependency declares: the root's target is not read there, since its default comes from -Dplatform (x86_64-linux-gnu.2.38, or the Mac's) and a package that passes none keeps the native one; build/library.zig is `library` at the foot of build.zig, the editor option read with the others and handed in (its body otherwise as it was); `-Deditor` stays a dependency's alone and the root's -Dgrammars help text is the head comment's words; lines: build.zig 361 -> 430 (26 of them the head comment), build/library.zig 49 -> 0, build.zig and build/ 2,971 -> 2,991; tui install, lib-test (the package still asks for `.grammars = .minimal, .editor = true`) and hxlib (538 cases, 0 mismatches) as before Co-Authored-By: Claude Opus Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T --- build.zig | 81 ++++++++++++++++++++++++++++++++++++++++++++++++++----- build/library.zig | 49 --------------------------------- 2 files changed, 75 insertions(+), 55 deletions(-) delete mode 100644 build/library.zig (limited to 'build/library.zig') diff --git a/build.zig b/build.zig index e31464f7..3498b331 100644 --- a/build.zig +++ b/build.zig @@ -1,3 +1,29 @@ +//! pardes: the editor, and the library it is for a program that draws +//! source text itself. `zig build -Dplatform=tui` (or `gui`, `macos`) +//! builds the editor; docs/typ/building.typ has the rest. +//! +//! A package that depends on pardes is given its syntax, `pardes-syntax` +//! (core/lib_syntax.zig): +//! +//! const pardes = b.dependency("pardes", .{ .target = target, .optimize = optimize, .grammars = .minimal }); +//! exe.root_module.addImport("pardes-syntax", pardes.module("pardes-syntax")); +//! +//! and, when it asks, the text pane, `pardes-editor` (core/lib_editor.zig), +//! here with a grammar of its own handed in at run time: +//! +//! const pardes = b.dependency("pardes", .{ .target = target, .optimize = optimize, .grammars = .none, .editor = true }); +//! exe.root_module.addImport("pardes-editor", pardes.module("pardes-editor")); +//! +//! `.grammars`: the tree-sitter grammars compiled in: `none` (the runtime +//! alone), `minimal` (C, C++ and Zig) or `full` (all of them; the default). +//! `.editor`: exports `pardes-editor` besides `pardes-syntax`, and with it +//! fetches uucode, mvzr and vaxis. +//! +//! Every dependency but tree-sitter's runtime is lazy in the manifest, so +//! such a package fetches what it asked for and nothing else. +//! `pardes-editor` has `pardes-syntax` in it as `.syntax`: a file belongs +//! to one module, so a package imports one of the two. test/lib is such a +//! package; `lib-test`, which `unit-test` runs, builds and runs it. const std = @import("std"); const builtin = @import("builtin"); const core = @import("build/core.zig"); @@ -8,6 +34,7 @@ const macos = @import("build/macos.zig"); const tools = @import("build/tools.zig"); const tests = @import("build/tests.zig"); const process_build = @import("build/process.zig"); +const patches = @import("build/patches.zig"); /// The package manifest, imported untyped (build/core.zig has the reason). const zon = @import("build.zig.zon"); @@ -35,9 +62,14 @@ pub const macos_min_version: std.SemanticVersion = .{ .major = 13, .minor = 0, . pub const TreeSitterGrammars = enum { none, minimal, full }; pub fn build(b: *std.Build) void { - // A package that depends on pardes takes its library; nothing of the - // editor is configured for it. - if (!b.isRoot()) return @import("build/library.zig").build(b); + // What a package that depends on pardes may ask for (the head comment). + // pardes's own build takes the mode and the grammars too, and its target + // below, whose default -Dplatform says. + const optimize = b.standardOptimizeOption(.{}); + const grammars = b.option(TreeSitterGrammars, "grammars", "the tree-sitter grammars compiled in: none (the runtime alone), minimal (C, C++ and Zig) or full (all of them; the default)") orelse .full; + if (!b.isRoot()) return library(b, b.standardTargetOptions(.{}), optimize, grammars, b.option(bool, "editor", "exports pardes-editor besides pardes-syntax, and with it fetches uucode, mvzr and vaxis") orelse false); + + // Everything below is pardes's own: the editor, its tests and tools. // This configure reads the environment (HOME, XDG_DATA_HOME, // HX_HARNESS), the clock (-Dtest-rebuild) and vendor/themes and // vendor/queries without telling the configure cache, so it is never @@ -79,7 +111,6 @@ pub fn build(b: *std.Build) void { }, }, }); - const optimize = b.standardOptimizeOption(.{}); // one substring, because that is what a dev loop needs: see the unit-test // step for why the whole-binary run is worth narrowing const test_filters: []const []const u8 = if (b.option([]const u8, "test-filter", "run only tests whose name contains this")) |f| @@ -108,7 +139,6 @@ pub fn build(b: *std.Build) void { }), }); const c_optimize: std.lang.Optimize = if (optimize == .debug) .fast else optimize; - const tree_sitter_grammars = b.option(TreeSitterGrammars, "grammars", "the tree-sitter grammars compiled in: none (the runtime alone), minimal (C, C++ and Zig) or full (all of them; the default)") orelse .full; const tracy = b.option([]const u8, "tracy", "enable Tracy profiling; supply the path to a Tracy source checkout"); const macos_sdk = b.option([]const u8, "macos-sdk", "the macOS SDK a gui built for macOS from another system takes SDL's headers and frameworks from"); const macos_identity = b.option([]const u8, "macos-identity", "codesigning identity for pardes.app (default: ad-hoc)") orelse "-"; @@ -141,7 +171,7 @@ pub fn build(b: *std.Build) void { const pdf_scroll_bench_step = b.step("pdf-scroll-bench", "benchmark fast continuous-strip PDF scrolling in ReleaseFast (-Doptimize=ReleaseFast -- [--json] [--reps N] [--warmup N] [--path FILE])"); const shell_cfg: core.ShellConfig = .{ - .tree_sitter_grammars = tree_sitter_grammars, + .tree_sitter_grammars = grammars, .tracy = tracy, .workspace_tag = workspace_tag, .embed_sources = embed_sources, @@ -359,3 +389,42 @@ fn installHome(b: *std.Build, artifact: *std.Build.Step.Compile, home_bin: ?[]co copy.has_side_effects = true; b.getInstallStep().dependOn(©.step); } + +/// What a package that depends on pardes is given (the head comment): +/// `pardes-syntax`, the grammars, highlighting and themes, over tree-sitter +/// and the grammars of its set alone; and with `editor`, `pardes-editor`, +/// whose uucode, mvzr and vaxis (with what its build names) are fetched +/// then and only then. Of vaxis it takes the grapheme width, which uucode +/// alone feeds. +fn library(b: *std.Build, target: std.Build.ResolvedTarget, optimize: std.lang.Optimize, grammars: TreeSitterGrammars, editor: bool) void { + var threaded: std.Io.Threaded = .init(b.allocator, .{}); + defer threaded.deinit(); + const io = threaded.io(); + const mod = b.addModule("pardes-syntax", .{ + .target = target, + .optimize = optimize, + .root_source_file = b.path("core/lib_syntax.zig"), + .link_libc = true, + }); + // A library's options: its grammars, nothing stamped, no window. + const cfg: core.ShellConfig = .{ .tree_sitter_grammars = grammars }; + 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, grammars); + const themes = core.generatedThemes(b, io, target, optimize); + mod.addImport("generated_themes", themes); + ts.wire(mod); + mod.addImport("c_heap", b.createModule(.{ .target = target, .optimize = optimize, .root_source_file = b.path("core/c_heap.zig") })); + if (!editor) return; + const uucode = core.uucodeModule(b, target, optimize) orelse return; + const mvzr = patches.mvzr(b, patches.tool(b), b.dependencyLazy("mvzr", .{ .target = target, .optimize = optimize }) catch return, target, optimize); + const vaxis_dep = b.dependencyLazy("vaxis", .{ .target = target, .optimize = optimize, .external_uucode = true }) catch return; + const width = b.addWriteFiles(); + _ = width.addCopyFile(vaxis_dep.path("src/gwidth.zig"), "gwidth.zig"); + const vaxis = b.createModule(.{ + .target = target, + .optimize = optimize, + .root_source_file = width.add("vaxis.zig", "pub const gwidth = @import(\"gwidth.zig\");\n"), + .imports = &.{.{ .name = "uucode", .module = uucode }}, + }); + _ = core.editorModule(b, "pardes-editor", target, optimize, cfg, .{ .themes = themes, .ts = ts, .uucode = uucode, .mvzr = mvzr, .vaxis = vaxis }); +} diff --git a/build/library.zig b/build/library.zig deleted file mode 100644 index 9a1bfb67..00000000 --- a/build/library.zig +++ /dev/null @@ -1,49 +0,0 @@ -const std = @import("std"); -const TreeSitterGrammars = @import("../build.zig").TreeSitterGrammars; -const core = @import("core.zig"); -const patches = @import("patches.zig"); - -/// pardes as a library, all a package that depends on it is given: the -/// `pardes-syntax` module (core/lib_syntax.zig), the grammars, highlighting -/// and themes for a program that draws source text itself. It takes -/// tree-sitter and the grammars of its `grammars` option and no other -/// dependency, so nothing else is fetched (build.zig.zon). test/lib is such -/// a package, which `lib-test` builds. -pub fn build(b: *std.Build) void { - const target = b.standardTargetOptions(.{}); - const optimize = b.standardOptimizeOption(.{}); - const tree_sitter_grammars = b.option(TreeSitterGrammars, "grammars", "the tree-sitter grammars compiled in: none (the runtime alone), minimal (C, C++ and Zig) or full (all of them; the default)") orelse .full; - var threaded: std.Io.Threaded = .init(b.allocator, .{}); - defer threaded.deinit(); - const io = threaded.io(); - const mod = b.addModule("pardes-syntax", .{ - .target = target, - .optimize = optimize, - .root_source_file = b.path("core/lib_syntax.zig"), - .link_libc = true, - }); - // A library's options: its grammars, nothing stamped, no window. - const cfg: core.ShellConfig = .{ .tree_sitter_grammars = tree_sitter_grammars }; - 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); - ts.wire(mod); - mod.addImport("c_heap", b.createModule(.{ .target = target, .optimize = optimize, .root_source_file = b.path("core/c_heap.zig") })); - // The editor, `pardes-editor`, to a package that asks for it: uucode, - // mvzr and vaxis (with what its build names) are fetched then and only - // then. Of vaxis it takes the grapheme width, which uucode alone feeds. - if (!(b.option(bool, "editor", "also export `pardes-editor`, the text pane as a library (fetches uucode, mvzr and vaxis)") orelse false)) return; - const uucode = core.uucodeModule(b, target, optimize) orelse return; - const mvzr = patches.mvzr(b, patches.tool(b), b.dependencyLazy("mvzr", .{ .target = target, .optimize = optimize }) catch return, target, optimize); - const vaxis_dep = b.dependencyLazy("vaxis", .{ .target = target, .optimize = optimize, .external_uucode = true }) catch return; - const width = b.addWriteFiles(); - _ = width.addCopyFile(vaxis_dep.path("src/gwidth.zig"), "gwidth.zig"); - const vaxis = b.createModule(.{ - .target = target, - .optimize = optimize, - .root_source_file = width.add("vaxis.zig", "pub const gwidth = @import(\"gwidth.zig\");\n"), - .imports = &.{.{ .name = "uucode", .module = uucode }}, - }); - _ = core.editorModule(b, "pardes-editor", target, optimize, cfg, .{ .themes = themes, .ts = ts, .uucode = uucode, .mvzr = mvzr, .vaxis = vaxis }); -} -- cgit v1.3