//! 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). //! `.languages`: instead of `.grammars`, the languages compiled in by name //! (`"rust"`, or `&.{ "rust", "go" }`), each with what it needs (markdown //! its inline grammar); a name the manifest does not have fails the //! configure. `.editor`: exports `pardes-editor` besides `pardes-syntax`, //! and with it fetches uucode, mvzr and vaxis. //! //! The manifest, for a package's build script to read at configure time //! (`@import("pardes").grammar_manifest.all`: each grammar's name, its //! extensions and what it needs), is `grammar_manifest`. //! //! A browser's module, one call a language (`wasmModule`): //! //! const pardes = @import("pardes"); //! b.installArtifact(pardes.wasmModule(b, .{ .language = "rust" })); //! b.installArtifact(pardes.wasmModule(b, .{})); // the patch view alone //! //! 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; `consumer-test`, which `unit-test` runs, //! builds and runs it. const std = @import("std"); const builtin = @import("builtin"); const core = @import("build/core.zig"); const docs = @import("build/docs.zig"); const gui = @import("build/gui.zig"); const addons = @import("build/addons.zig"); 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"); pub const Platform = enum { tui, gui, macos }; pub const PerfBuild = struct { compiler: []const u8, target: []const u8, cpu: []const u8, driver_optimize: []const u8, core_optimize: []const u8, c_optimize: []const u8, terminal_optimize: []const u8, platform: []const u8, grammars: []const u8, mupdf: bool, jpx: bool, tracy: bool, terminal_simd: bool, prebuilt_shaders: bool, }; pub const macos_min_version: std.SemanticVersion = .{ .major = 13, .minor = 0, .patch = 0 }; pub const TreeSitterGrammars = enum { none, minimal, full }; /// Every grammar pardes knows (the head comment). pub const grammar_manifest = @import("core/grammar_manifest.zig"); pub fn build(b: *std.Build) void { // 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_option = 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)"); const grammars = grammars_option orelse .full; if (!b.isRoot()) return library(b, b.standardTargetOptions(.{}), optimize, librarySet( grammars_option, b.option([]const []const u8, "languages", "instead of grammars, the languages compiled in by name, each with what it needs"), ), 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 // cached (REORG decision 20; typst's lookup did this before it moved to // make time). b.graph.poisonCache(); const requested_platform = b.option(Platform, "platform", "which shell to build (tui, gui, macos); absent builds the tui cli and the SDL gui together"); const platform = requested_platform orelse .tui; const also_gui = requested_platform == null; // A bare `zig build` also copies the binaries into ~/.local/bin, and the // addon steps theirs into the user's data directory. Zig 0.17 keeps the // prefix in the maker process, out of this script's reach, so `--prefix` // no longer turns it off: -Dhome-install=false does. With -Dplatform // neither is copied, but the addons with -Dhome-install=true. const home_option = b.option(bool, "home-install", "copy into the user directories: a bare `zig build` the binaries and addons, -Dplatform the addons only when true (default: true for a bare `zig build`)"); const home_bin: ?[]const u8 = if (also_gui and (home_option orelse true)) if (b.graph.environ_map.get("HOME")) |home| b.pathJoin(&.{ home, ".local", "bin" }) else null else null; const home_addons: ?[]const u8 = if (!(home_option orelse also_gui)) null else if (b.graph.environ_map.get("XDG_DATA_HOME")) |data| b.pathJoin(&.{ data, "pardes", "addons" }) else if (b.graph.environ_map.get("HOME")) |home| b.pathJoin(&.{ home, ".local", "share", "pardes", "addons" }) else null; const home_install = home_bin != null; const target = b.standardTargetOptions(.{ .default_target = switch (platform) { .macos => if (builtin.os.tag.isDarwin()) .{ .cpu_arch = builtin.target.cpu.arch, .os_tag = .macos, .os_version_min = .{ .semver = macos_min_version }, } else .{}, .tui, .gui => .{ .cpu_arch = .x86_64, .os_tag = .linux, .abi = .gnu, .glibc_version = .{ .major = 2, .minor = 38, .patch = 0 }, }, }, }); // 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| &.{f} else &.{}; const enable_jpx = b.option(bool, "jpx", "JPEG 2000 in PDFs, for scanned documents (default on; -Djpx=false drops openjpeg)") orelse true; const embed_sources = b.option(bool, "embed-sources", "serve the editor's own sources under /src of its 9P tree (default off)") orelse false; const test_build = b.step("test-build", "compile unit-test programs without running them"); const doc_typ_opts = b.addOptions(); doc_typ_opts.addOptionPathUntracked("dir", b.path("docs/typ")); // The words the shipped addons bring (PdfFit...), which the docs name too. doc_typ_opts.addOptionPathUntracked("addons", b.path("addons")); const doc_renders = docs.add(b); const test_nonce: ?*std.Build.Module = if (b.option(bool, "test-rebuild", "force fresh Zig test compilation while retaining cached C dependencies") orelse false) blk: { const files = b.addTempFiles(); const source = files.add("test_nonce.zig", b.fmt("pub const nonce = {d};\n", .{std.Io.Clock.awake.now(b.graph.io).nanoseconds})); break :blk b.createModule(.{ .root_source_file = source, .target = target, .optimize = optimize }); } else null; const unit_profile = b.addExecutable(.{ .name = "pardes-unit-profile", .root_module = b.createModule(.{ .target = target, .optimize = optimize, .root_source_file = b.path("test/unit_profile.zig"), }), }); const c_optimize: std.lang.Optimize = if (optimize == .debug) .fast else optimize; 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 "-"; const prebuilt_shaders = b.option(bool, "prebuilt-shaders", "embed sketchbook's committed dev/draw/shaders/prebuilt/*.spv instead of running glslc over its GLSL (default: on for a bare `zig build`, off when -Dplatform names a shell)") orelse also_gui; // The macOS shell carries the workspace tag row's commands in its native // menu bar; the row itself goes away. `-Dworkspace-tag=true` puts it back. const workspace_tag = b.option(bool, "workspace-tag", "draw the workspace tag row (default: on except on macOS, whose menu bar carries its commands)"); // The commit is a build input: every `jj new` or `jj commit` moves HEAD, // changes the options module and so recompiles every binary that imports // it, which is all of them (~0.6 GB of fresh test objects per move). Only // builds someone keeps are stamped: release builds and the bare // `zig build` that installs into ~/.local. Every other Debug build (any // -Dplatform or --prefix, so every test and snapshot run) prints // `pardes ` alone, like a tarball build; -Dstamp-commit=true // stamps one anyway. const stamp_commit = b.option(bool, "stamp-commit", "embed the git commit in --version and crash records (default: release builds and the ~/.local install)") orelse (optimize != .debug or home_install); // MuPDF, and the FreeType and zlib it is built against, are lazy: a // build asks for them only when it builds the pdf addon (or a window, // FreeType). Zig 0.17's configure is told the -D options and never the // steps asked for, so "the pdf step's" is an option, on once MuPDF is // fetched (and off Linux, where the addons are compiled in): a fresh // checkout's plain build fetches none of the three, and -Dpdf fetches // MuPDF once. const pdf = b.option(bool, "pdf", "build the pdf addon over MuPDF (default: on once MuPDF is fetched, as -Dpdf does)") orelse (std.Build.package_map.get(zon.dependencies.mupdf.hash).?.available or target.result.os.tag != .linux); const mupdf_check = b.step("mupdf-check", "the pdf addon's check: MuPDF compiles, links, renders and searches docs/design.pdf, and its script runs"); const pdf_pointer_bench_step = b.step("pdf-pointer-bench", "time PDF hover and selection gestures and prove their pixels (-Doptimize=ReleaseFast -- [--label L] [--reps N] [--path FILE] [--cell WxH])"); 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 = grammars, .tracy = tracy, .workspace_tag = workspace_tag, .embed_sources = embed_sources, .commit = if (stamp_commit) core.gitCommit(b) else null, .change = if (stamp_commit) core.jjChange(b) else null, .built = if (stamp_commit) core.command(b, &.{ "date", "-u", "+%Y-%m-%d %H:%M UTC" }) else null, }; // What every core is made of, the shells' options and the addons // (build/core.zig). const a = core.assemble(b, .{ .target = target, .optimize = optimize, .c_optimize = c_optimize, .shell_cfg = shell_cfg, .platform = platform, .also_gui = also_gui, .pdf = pdf, .enable_jpx = enable_jpx, .doc_typ = doc_typ_opts, .mupdf_check = mupdf_check, .pdf_pointer_bench_step = pdf_pointer_bench_step, .pdf_scroll_bench_step = pdf_scroll_bench_step, }); const parts = a.parts; // Off Linux, whose memfd Addon.zig's loader needs, every core has the // addons compiled in. const compiled_in = target.result.os.tag != .linux; // The macOS shell is a library whose host owns main(): it roots at // its own flat C ABI instead of runtime/main.zig. Tracy's client and BSD // libutil go to the shell (and Tracy's to the core) alone, as before // 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 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; // The core without the terminal module (docs/next-terminal.md, Phase 1): // what core-test is compiled from. No ghostty-vt, wuffs, zstbi or C++; // a shell boot is a scratch pane, a test that needs a terminal skips, // 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); // `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 // addons in it all the same. const static_linkage: ?std.builtin.LinkMode = if (target.result.isMuslLibC()) .static else null; const static_set: ?core.Modules = if ((platform == .tui and static_linkage != null) or platform == .gui) core.module(b, parts, .{ .root = "runtime/main.zig", .platform = platform, .builtin_addons = true }) else null; const static_mod: ?*std.Build.Module = if (static_set) |s| s.root else null; const gui_set: ?core.Modules = if (also_gui) core.module(b, parts, .{ .root = "runtime/main.zig", .platform = .gui, .builtin_addons = compiled_in }) else null; const gui_mod: ?*std.Build.Module = if (gui_set) |s| s.root else null; if (a.pdf.lib) |lib| tools.pdfBenches(b, target, optimize, core_module, lib, pdf_pointer_bench_step, pdf_scroll_bench_step); const builtins_json_step = docs.builtinsJson(b, requested_platform, platform, target, optimize, core_module, doc_renders); // The window's shells: the bare build's pardes-gui; -Dplatform=gui's // pardes-gui and its static. var sketchbook: ?*std.Build.Dependency = null; if (also_gui or platform == .gui) { const window = gui.make(b, target, optimize, macos_sdk, prebuilt_shaders, a.freetype); // ...into the devices, whose gui/gui.zig names the window. for ([_]?core.Modules{ gui_set, if (platform == .gui) root_set else null, if (platform == .gui) static_set else null }) |m| if (m) |s| window.wire(s.dev); sketchbook = window.sketchbook; } const snake_shader_lib = addons.gpu(b, target, optimize, a.addon_mod, sketchbook); if (platform == .macos) macos.add(b, .{ .macos_identity = macos_identity, .optimize = optimize, .root_mod = root_mod, .target = target, .test_build = test_build, .test_filters = test_filters, .test_nonce = test_nonce, .unit_profile = unit_profile, }) else { var exe_name: []const u8 = if (platform == .gui) "pardes-gui" else "pardes"; if (target.result.os.tag != .linux or target.result.cpu.arch != .x86_64) exe_name = b.fmt("{s}-{s}-{s}", .{ exe_name, @tagName(target.result.os.tag), @tagName(target.result.cpu.arch) }); const exe = b.addExecutable(.{ .name = exe_name, .root_module = root_mod, }); installHome(b, exe, home_bin); if (requested_platform == .tui) docs.commandLine(b, exe, builtins_json_step, doc_renders); // The addons, a step each: the default install is the binaries // alone, and `zig build image pdf` (or `addons`) puts the libraries // where the start scan finds them, /lib/pardes/addons (and // $XDG_DATA_HOME/pardes/addons as home_addons says). const addons_step = b.step("addons", "install the image and pdf addons"); for ([_]?*std.Build.Step.Compile{ a.image_addon, a.pdf.lib }, [_][]const u8{ "image", "pdf" }) |lib, name| { const step = b.step(name, b.fmt("install the {s} addon, /lib/pardes/addons/{s}.so", .{ name, name })); addons_step.dependOn(step); const l = lib orelse { step.dependOn(a.pdf.no_pdf.?); continue; }; step.dependOn(&b.addInstallFileWithDir(l.getEmittedBin(), .lib, b.fmt("pardes/addons/{s}.so", .{name})).step); if (home_addons) |dir| { const copy = b.addUpdateSourceFiles(); copy.addCopyFileToSource(l.getEmittedBin(), b.pathJoin(&.{ dir, b.fmt("{s}.so", .{name}) })); step.dependOn(©.step); } } if (gui_mod) |gm| { var gui_name: []const u8 = "pardes-gui"; if (target.result.os.tag != .linux or target.result.cpu.arch != .x86_64) gui_name = b.fmt("{s}-{s}-{s}", .{ gui_name, @tagName(target.result.os.tag), @tagName(target.result.cpu.arch) }); const gui_exe = b.addExecutable(.{ .name = gui_name, .root_module = gm, }); installHome(b, gui_exe, home_bin); } // One static pardes, never the default: the terminal's, both // addons compiled in and registered at start as if loaded. It is // also how a build for macOS, whose loader has no memfd, could have // image and PDF panes. const static_step = b.step("static", "a pardes with the image and pdf addons in it: the terminal's static (-Dplatform=tui -Dtarget=x86_64-linux-musl), the gui's dynamic (-Dplatform=gui)"); if (a.pdf.no_pdf) |s| static_step.dependOn(s) else if (static_mod) |m| static_step.dependOn(&b.addInstallArtifact(b.addExecutable(.{ .name = exe_name, .linkage = if (platform == .gui) null else static_linkage, .root_module = m }), .{}).step) else 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); 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. const lspmock = tools.program(b, "pardes-lspmock", "test/lspmock.zig", target, optimize, &.{}); process_build.add(b, .{ .exe = exe, .lspmock = lspmock, .addons = addon_libs, .target = target, .optimize = optimize, .ghostty_vt = a.ghostty_vt, .cloud9 = parts.cloud9, .runtime = core_set.runtime, .gui = platform == .gui, }); const t = tools.add(b, .{ .c_optimize = c_optimize, .core_module = core_module, .enable_jpx = enable_jpx, .exe = exe, .ghostty_optimize = a.ghostty_optimize, .ghostty_simd = a.ghostty_simd, .ghostty_vt_for_tests = a.ghostty_vt, .image_addon = a.image_addon, .lean = lean_cfg, .no_pdf = a.pdf.no_pdf, .optimize = optimize, .parts = parts, .pdf_addon = a.pdf.lib, .platform = platform, .prebuilt_shaders = prebuilt_shaders, .shell_cfg = shell_cfg, .target = target, .test_filters = test_filters, .unit_profile = unit_profile, }); tests.add(b, .{ .addon_mod = a.addon_mod, .core_lean = core_lean, .root_set = root_set, .core_wire = core_set.wire, .core_module = core_module, .core_runtime = core_set.runtime, .core_cfg = core_cfg, .exe = exe, .ghostty_vt_for_tests = a.ghostty_vt, .image_addon = a.image_addon, .lspmock = lspmock, .mupdf_check = mupdf_check, .optimize = optimize, .parts = parts, .pdf_addon = a.pdf.lib, .platform = platform, .root_mod = root_mod, .snake_shader_lib = snake_shader_lib, .target = target, .test_build = test_build, .test_filters = test_filters, .test_nonce = test_nonce, .tools = t, .unit_profile = unit_profile, }); } // The test-build programs installed rather than run, for a machine the // build cannot run them on (`-Dtarget=x86_64-freebsd.15.0`): each into // /test, named for its root file. const test_install = b.step("test-install", "install the test-build programs into /test, to run elsewhere"); for (test_build.dependencies.items) |dep| { const t = dep.cast(std.Build.Step.Compile) orelse continue; const name = switch (t.root_module.root_source_file orelse continue) { .src_path => |p| if (std.mem.eql(u8, std.fs.path.basename(p.sub_path), "root.zig")) std.fs.path.basename(std.fs.path.dirname(p.sub_path).?) else std.fs.path.stem(p.sub_path), else => t.name, }; test_install.dependOn(&b.addInstallArtifact(t, .{ .dest_dir = .{ .override = .{ .custom = "test" } }, .dest_sub_path = name }).step); } } /// A browser's module, one call a language (the head comment): wasm32-wasi /// as a reactor (no `main`; `_initialize`, then any export), with /// `language`'s grammar and what it needs, tree-sitter's runtime and /// pardes's highlighter; or, with no language, the patch view alone, with /// no tree-sitter in it. Its exports are abi/wasm.zig's (`memory`, /// `_initialize`, `reserve`, `release`, `patch`, and with a language /// `highlight` and `patchFile`), the same in every module; docs/typ/building.typ has their /// layouts and the WASI imports a page stubs. The package's dependency on /// pardes is named "pardes". A name the manifest does not have fails the /// configure, as `.languages` does. pub fn wasmModule(b: *std.Build, options: struct { language: ?[]const u8 = null, optimize: std.lang.Optimize = .ReleaseSmall, }) *std.Build.Step.Compile { const target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .wasi }); const pardes = if (options.language) |name| b.dependency("pardes", .{ .target = target, .optimize = options.optimize, .languages = name }) else b.dependency("pardes", .{ .target = target, .optimize = options.optimize, .grammars = .none }); const exports = b.addOptions(); exports.addOption(bool, "language", options.language != null); const module = b.addExecutable(.{ .name = b.fmt("pardes-{s}", .{options.language orelse "patch"}), .root_module = b.createModule(.{ .target = target, .optimize = options.optimize, .root_source_file = pardes.path("abi/wasm.zig"), .imports = &.{ .{ .name = "pardes-syntax", .module = pardes.module("pardes-syntax") }, .{ .name = "wasm_options", .module = exports.createModule() }, }, }), }); module.entry = .disabled; module.wasi_exec_model = .reactor; // Its own functions alone: tree-sitter's and libc's stay inside. module.root_module.export_symbol_names = if (options.language != null) &.{ "reserve", "release", "patch", "highlight", "patchFile" } else &.{ "reserve", "release", "patch" }; return module; } /// Installs `artifact` in the prefix and, given `home_bin`, copies it there /// too (`install` unlinks first, so a running binary is replaced). fn installHome(b: *std.Build, artifact: *std.Build.Step.Compile, home_bin: ?[]const u8) void { b.installArtifact(artifact); const dir = home_bin orelse return; const copy = b.addSystemCommand(&.{ "install", "-Dm755" }); copy.addArtifactArg(artifact); copy.addArg(b.pathJoin(&.{ dir, artifact.name })); copy.has_side_effects = true; b.getInstallStep().dependOn(©.step); } /// The grammars a dependent package asked for: the languages it named and /// what each needs (the manifest's), or its tier's. A language the manifest /// does not have, or a tier beside languages, ends the configure: Zig /// reports an option it cannot read and builds on (exit code 0). fn librarySet(grammars: ?TreeSitterGrammars, languages: ?[]const []const u8) core.GrammarSet { const names = languages orelse return core.tierSet(grammars orelse .full); if (grammars) |tier| fatal("pardes: `.languages` replaces `.grammars` (here .{t}): give one of them", .{tier}); var set: core.GrammarSet = @splat(false); for (names) |name| { const i = grammar_manifest.byName(name) orelse fatal("pardes: no language \"{s}\" in its manifest (`.languages`); it has:{s}", .{ name, comptime known: { var all: []const u8 = ""; for (grammar_manifest.all) |g| all = all ++ " " ++ g.name; break :known all; } }); set[i] = true; for (grammar_manifest.all[i].needs) |need| set[grammar_manifest.byName(need).?] = true; } return set; } fn fatal(comptime format: []const u8, args: anytype) noreturn { std.log.err(format, args); std.process.exit(1); } /// 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, set: core.GrammarSet, 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: nothing stamped, no window, and a tier only // pardes's own tests read (syntax.zig knows the set by its queries). const cfg: core.ShellConfig = .{ .tree_sitter_grammars = if (std.mem.eql(bool, &set, &core.tierSet(.full))) .full else if (std.mem.eql(bool, &set, &core.tierSet(.minimal))) .minimal else .none }; 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, set); 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 }); }