summaryrefslogtreecommitdiff
path: root/build.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-20 06:33:52 -0300
committerGabriel Schneider <[email protected]>2026-11-20 06:33:53 -0300
commitffe05cceb897b3ae6a6d36491f9318a8aa3426e7 (patch)
tree352414579559060b3e8486af34e29d49fd5df781 /build.zig
parent5b7124d10f9b2db8d1c5e99eacb9b6d2fffff0cc (diff)
parenta403340ec5c90238b136ca85fc64d65809b29a65 (diff)
downloadpardes-ffe05cceb897b3ae6a6d36491f9318a8aa3426e7.tar.gz
pardes-ffe05cceb897b3ae6a6d36491f9318a8aa3426e7.zip
integration: the build's second pass on the handle and the devices once: pardes-build-pass2 (pardes-isolate and the tree-sitter=disabled tier deleted; one option, grammars = none | minimal | full; build.zig with the consumer's lines as its head comment; test/lib -> test/consumer; the manual's library section) and pardes-merge31, merged without a textual conflict; one line follows a deletion: dev/file_watch.zig's end-to-end test of a session's watches (written since on the base) guarded on fs.platform_has_fs, which the first of these changes deleted: the guard reads as the file's other tests' (comptime !supported); tui core-test 857/1008 (151 skipped), shell-test 1048/1051, the window builds; the coordinator's gate in the ledger (reorg/merge32)
Co-Authored-By: Claude Fable 5.2 <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T
Diffstat (limited to 'build.zig')
-rw-r--r--build.zig110
1 files changed, 89 insertions, 21 deletions
diff --git a/build.zig b/build.zig
index fc0c5044..125f4dcc 100644
--- a/build.zig
+++ b/build.zig
@@ -1,3 +1,40 @@
+//! 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/consumer` is
+//! such a package, with both shapes; `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 +45,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");
@@ -32,12 +70,17 @@ pub const PerfBuild = struct {
pub const macos_min_version: std.SemanticVersion = .{ .major = 13, .minor = 0, .patch = 0 };
-pub const TreeSitterGrammars = enum { disabled, 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
- // 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 +122,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 +150,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, "tree-sitter", "tree-sitter grammar set: disabled, zig, minimal (c/c++/zig), full") 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 +182,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,
@@ -175,8 +216,8 @@ pub fn build(b: *std.Build) void {
// core.module.
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.
+ // hxdiff's headless core is the primary shell's configuration compiled
+ // another way, not another frontend.
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;
@@ -186,7 +227,6 @@ pub fn build(b: *std.Build) void {
// and shell-test runs them all with one.
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", .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
@@ -270,17 +310,6 @@ pub fn build(b: *std.Build) void {
static_step.dependOn(&b.addFail("static is the terminal's on musl (-Dplatform=tui -Dtarget=x86_64-linux-musl) or the gui's (-Dplatform=gui)").step);
const run = b.addRunArtifact(exe);
b.step("run", "descend to the pardes").dependOn(&run.step);
- if (isolated_mod) |iso| {
- const iso_exe = b.addExecutable(.{
- .name = "pardes-isolate",
- .root_module = iso,
- });
- const run_iso = b.addRunArtifact(iso_exe);
- // Something to look at on arrival, read out of the binary itself.
- run_iso.addPassthruArgs();
- const iso_step = b.step("run-isolated", "descend to a pardes with no host but the terminal");
- iso_step.dependOn(&run_iso.step);
- }
const addon_libs: []const *std.Build.Step.Compile = if (a.pdf.lib) |l| b.allocator.dupe(*std.Build.Step.Compile, &.{ a.image_addon, l }) catch @panic("OOM") else &.{a.image_addon};
// The scripted language server the tests' sessions and the tty cases ask.
@@ -371,3 +400,42 @@ fn installHome(b: *std.Build, artifact: *std.Build.Step.Compile, home_bin: ?[]co
copy.has_side_effects = true;
b.getInstallStep().dependOn(&copy.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 });
+}