summaryrefslogtreecommitdiff
path: root/build.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-20 04:37:18 -0300
committerGabriel Schneider <[email protected]>2026-11-20 04:38:20 -0300
commita3634ab3dbf2fabd997f137c47eafd7bc6c442b0 (patch)
tree202a888c08f7d2620805445653156e81ce813cde /build.zig
parentfc9e2eaf5ad86719a3bc57d18ce4ad302461dfbd (diff)
downloadpardes-a3634ab3dbf2fabd997f137c47eafd7bc6c442b0.tar.gz
pardes-a3634ab3dbf2fabd997f137c47eafd7bc6c442b0.zip
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 <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T
Diffstat (limited to 'build.zig')
-rw-r--r--build.zig81
1 files changed, 75 insertions, 6 deletions
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(&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 });
+}