diff options
| -rw-r--r-- | build.zig | 81 | ||||
| -rw-r--r-- | build/library.zig | 49 |
2 files changed, 75 insertions, 55 deletions
@@ -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 }); -} |
