summaryrefslogtreecommitdiff
path: root/build.zig
diff options
context:
space:
mode:
Diffstat (limited to 'build.zig')
-rw-r--r--build.zig56
1 files changed, 48 insertions, 8 deletions
diff --git a/build.zig b/build.zig
index 470d8600..cae96193 100644
--- a/build.zig
+++ b/build.zig
@@ -26,8 +26,15 @@
//!
//! `.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.
+//! `.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`.
//!
//! Every dependency but tree-sitter's runtime is lazy in the manifest, so
//! such a package fetches what it asked for and nothing else.
@@ -72,13 +79,20 @@ pub const macos_min_version: std.SemanticVersion = .{ .major = 13, .minor = 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 = 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);
+ 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,
@@ -401,13 +415,38 @@ fn installHome(b: *std.Build, artifact: *std.Build.Step.Compile, home_bin: ?[]co
b.getInstallStep().dependOn(&copy.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, grammars: TreeSitterGrammars, editor: bool) void {
+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();
@@ -417,10 +456,11 @@ fn library(b: *std.Build, target: std.Build.ResolvedTarget, optimize: std.lang.O
.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 };
+ // 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, grammars);
+ 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);