summaryrefslogtreecommitdiff
path: root/build.zig
diff options
context:
space:
mode:
Diffstat (limited to 'build.zig')
-rw-r--r--build.zig70
1 files changed, 52 insertions, 18 deletions
diff --git a/build.zig b/build.zig
index a78cd442..e63b7f4b 100644
--- a/build.zig
+++ b/build.zig
@@ -60,7 +60,8 @@ pub fn build(b: *std.Build) void {
const requested_platform = b.option(Platform, "platform", "which shell to build (tty, gui, web, macos, esp32p4); absent builds the tty cli and the SDL gui together");
const platform = requested_platform orelse .tty;
const also_gui = requested_platform == null;
- if (also_gui and prefixIsUntouched(b)) {
+ const home_install = also_gui and prefixIsUntouched(b);
+ if (home_install) {
if (b.graph.environ_map.get("HOME")) |home| {
b.resolveInstallPrefix(b.pathJoin(&.{ home, ".local" }), .{});
std.debug.print("pardes: installing into {s} (override with --prefix)\n", .{b.install_prefix});
@@ -108,7 +109,9 @@ pub fn build(b: *std.Build) void {
ninep_options.addOption(bool, "quic", enable_quic);
const enable_mupdf = b.option(bool, "mupdf", "native PDF rendering with MuPDF (AGPL/commercial; native default on, web/esp32p4 off; -Dmupdf=false disables)") orelse !freestanding_core;
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; on for -Dplatform=esp32p4, whose only source is the device)") orelse is_esp32p4;
+ // Off on the board too: the sources are ~1.8 MB, more than the whole
+ // 1.5 MiB app partition, and with them the image does not link.
+ const embed_sources = b.option(bool, "embed-sources", "serve the editor's own sources under /src of its 9P tree (default off; the esp32p4 image has no room for them)") orelse false;
const is_web_target = target.result.cpu.arch == .wasm32 and target.result.os.tag == .freestanding;
const is_esp32p4_target = target.result.cpu.arch == .riscv32 and target.result.os.tag == .freestanding;
const optimize = if (is_web)
@@ -311,6 +314,16 @@ pub fn build(b: *std.Build) void {
// 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 <version>` 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);
const shell_cfg: ShellConfig = .{
.tree_sitter_grammars = tree_sitter_grammars,
.tracy = tracy != null,
@@ -323,7 +336,7 @@ pub fn build(b: *std.Build) void {
.prebuilt_shaders = prebuilt_shaders,
.embed_sources = embed_sources,
.zig_lib_dir = b.graph.zig_lib_directory.path orelse "",
- .commit = gitCommit(b),
+ .commit = if (stamp_commit) gitCommit(b) else null,
};
const opts = shellOptions(b, shell_cfg, platform);
const gui_opts: ?*std.Build.Step.Options = if (also_gui) shellOptions(b, shell_cfg, .gui) else null;
@@ -454,7 +467,40 @@ pub fn build(b: *std.Build) void {
\\pub threadlocal var exhausted: bool = false;
\\
;
- const patched = b.fmt("{s}{s}{s}{s}", .{ src[0..at], spend, src[at..], budget });
+ const budgeted = b.fmt("{s}{s}{s}{s}", .{ src[0..at], spend, src[at..], budget });
+ // A group's greedy match never gave back to what follows the group:
+ // on `aab`, `(a+)ab` missed where `a+ab` matched. hasAlt counts the
+ // group's own `)` as an alternative, so every group with pattern
+ // after it takes matchGroup's alternatives branch, which tries each
+ // alternative's one (greedy) match and gives up. When the rest fails
+ // after it, try that alternative's shorter matches, longest first
+ // (docs/mvzr-group-backtrack.md is the report for upstream).
+ const group_anchor =
+ \\ const next_match = matchPattern(next_patt, sets, haystack, m1.i);
+ \\ if (next_match) |m2| {
+ \\ // Whole group matches, and we can use m2.j
+ \\ return m2;
+ \\ } else { // Try our next pattern, if any.
+ \\
+ ;
+ const group_backoff =
+ \\ const next_match = matchPattern(next_patt, sets, haystack, m1.i);
+ \\ if (next_match) |m2| {
+ \\ // Whole group matches, and we can use m2.j
+ \\ return m2;
+ \\ } else { // Try our next pattern, if any.
+ \\ // pardes's patch (its build.zig): back the group off.
+ \\ var e = m1.i;
+ \\ while (e > i) {
+ \\ e -= 1;
+ \\ const shorter = matchAlt(remaining_patt, sets, haystack[0..e], i) orelse continue;
+ \\ if (shorter.i != e) continue;
+ \\ if (matchPattern(next_patt, sets, haystack, e)) |whole| return whole;
+ \\ }
+ \\
+ ;
+ if (std.mem.count(u8, budgeted, group_anchor) != 1) @panic("mvzr's matchGroup changed: redo its group backtracking in build.zig");
+ const patched = std.mem.replaceOwned(u8, b.allocator, budgeted, group_anchor, group_backoff) catch @panic("OOM");
break :mvzr b.createModule(.{ .root_source_file = b.addWriteFiles().add("mvzr.zig", patched), .target = target, .optimize = optimize });
};
@@ -1364,18 +1410,6 @@ pub fn build(b: *std.Build) void {
lspbench_test_step.dependOn(&run_lspbench_tests.step);
lspbench_check_step.dependOn(&run_lspbench_tests.step);
if (testMatch(b, unit_profile, test_filters, lspbench_test_step)) |check| check.addArtifactArg(lspbench_tests);
- const config_module = b.createModule(.{
- .target = target,
- .optimize = optimize,
- .root_source_file = b.path("src/config.zig"),
- });
- config_module.addImport("pardes_config", core_module.import_table.get("pardes_config").?);
- const config_tests = b.addTest(.{ .root_module = config_module, .filters = test_filters });
- const run_config_tests = b.addRunArtifact(config_tests);
- run_config_tests.has_side_effects = true;
- const config_test_step = b.step("config-test", "run configuration tests without compiling the editor");
- config_test_step.dependOn(&run_config_tests.step);
- if (testMatch(b, unit_profile, test_filters, config_test_step)) |check| check.addArtifactArg(config_tests);
const diff_tests = b.addTest(.{ .root_module = hxdiff.root_module, .filters = test_filters });
const run_diff_tests = b.addRunArtifact(diff_tests);
run_diff_tests.has_side_effects = true;
@@ -1607,8 +1641,8 @@ fn shellOptions(b: *std.Build, cfg: ShellConfig, platform: Platform) *std.Build.
o.addOption([]const u8, "zls_version", if (cfg.zls_backend) zls_version else "none");
o.addOption(bool, "embed_sources", cfg.embed_sources);
o.addOption([]const u8, "version", zon.version);
- // ...and the commit it was built from, when there is one. See `gitCommit`
- // for why this is optional and why it is read at configure time.
+ // ...and the commit it was built from, when there is one and the build
+ // is stamped at all (see `stamp_commit`). Read at configure time.
o.addOption(?[]const u8, "commit", cfg.commit);
o.addOption([]const u8, "zig_lib_dir", cfg.zig_lib_dir);
return o;