summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-17 14:07:18 -0300
committerGabriel Schneider <[email protected]>2026-11-17 14:25:10 -0300
commit73e324a8dc89837b5de35b5cedee3a112fad5ec4 (patch)
tree04ba2c85a092fe4d01721013a3b4245b0bf093e6 /tools
parent20f75e147d720a6a4c98c4c3b4db067bbf55ee32 (diff)
downloadpardes-73e324a8dc89837b5de35b5cedee3a112fad5ec4.tar.gz
pardes-73e324a8dc89837b5de35b5cedee3a112fad5ec4.zip
build: the upstream patches as data, applied at make time by tools/patch.zig
Each of the four upstream patches (vaxis's parser, render and queue, zstbi, ghostty's kitty loader, mvzr) is a table of edits in build/patches.zig: the text to find, how many times it occurs, its replacement. tools/patch.zig (39 lines, the shape of sketchbook's reload_edit) applies one file's table at make time, and appends what the patch adds as a real Zig file of build/patches/ (vaxis_parser.zig, vaxis_render.zig, ghostty_kitty.zig, mvzr_budget.zig); an edit whose text moved or doubled writes nothing and fails that file's step. The configure no longer reads or carries ~300 KB of patched sources: the binary configuration halves (tui 607,524 -> 302,049 bytes, gui 643,248 -> 337,769). build/patches.zig 386 -> 338 lines, plus 57 in its four appended files. Gates: zig build -l and -h byte-identical, whole matrix and test/lib. The patched files byte-identical to the base's (Parser.zig, Vaxis.zig, queue.zig, graphics_image.zig, mvzr.zig, zstbi.c), and the four module directories the compiles read (vaxis 53 files, ghostty 1,009, mvzr, zstbi) identical file for file (sha256). The warm rebuild cannot be all cached: a module root in another directory is another compile, though its bytes are the same (a 10-line experiment shows it), so this was built from a wiped cache: install addons, core-test shell-test unit-test process-test on tui and gui give the base's counts (tui 2339/2486, gui 2398/2545, the same failures). pardes and pardes-gui differ from the base's in layout only: section sizes equal, every named symbol the same name, size and kind (tui 37,228; gui 79,507 against the base tree relinked cold), anonymous symbols the same sizes; image.so and pdf.so identical once their debug info is stripped. (A cold relink of the base tree itself takes operator new from libc++abi.a rather than libc++.a, as this one does: the base's binary was linked in another order.) A second build is all cached, the patch runs too. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T
Diffstat (limited to 'tools')
-rw-r--r--tools/patch.zig39
1 files changed, 39 insertions, 0 deletions
diff --git a/tools/patch.zig b/tools/patch.zig
new file mode 100644
index 00000000..a72624ff
--- /dev/null
+++ b/tools/patch.zig
@@ -0,0 +1,39 @@
+//! One upstream file patched at make time, for build/patches.zig:
+//! `patch <in> <out> [--append <file>] [<count> <old> <new>]...`.
+//! Each `old` must occur exactly `count` times, and every occurrence is
+//! replaced by `new`, in order; then `file` follows after an empty line.
+//! An `old` that moved or doubled writes nothing and fails the step.
+const std = @import("std");
+
+pub fn main(init: std.process.Init) !void {
+ const io = init.io;
+ const arena = init.arena.allocator();
+ var args = init.minimal.args.iterate();
+ _ = args.skip();
+ const in_path = args.next() orelse return error.Usage;
+ const out_path = args.next() orelse return error.Usage;
+ const cwd = std.Io.Dir.cwd();
+
+ var source = try cwd.readFileAlloc(io, in_path, arena, .limited(4 << 20));
+ var append: []const u8 = "";
+ var failed = false;
+ while (args.next()) |arg| {
+ if (std.mem.eql(u8, arg, "--append")) {
+ append = try cwd.readFileAlloc(io, args.next() orelse return error.Usage, arena, .limited(1 << 20));
+ continue;
+ }
+ const count = try std.fmt.parseInt(usize, arg, 10);
+ const old = args.next() orelse return error.Usage;
+ const new = args.next() orelse return error.Usage;
+ const found = std.mem.count(u8, source, old);
+ if (found != count) {
+ std.log.err("{s} changed: the text to replace occurs {d} times, not {d} (redo its patch in build/patches.zig):\n{s}", .{ in_path, found, count, old });
+ failed = true;
+ continue;
+ }
+ source = try std.mem.replaceOwned(u8, arena, source, old, new);
+ }
+ if (failed) std.process.exit(1);
+ const out = if (append.len == 0) source else try std.mem.concat(arena, u8, &.{ source, "\n", append });
+ try cwd.writeFile(io, .{ .sub_path = out_path, .data = out });
+}