summaryrefslogtreecommitdiff
path: root/build/patches.zig
diff options
context:
space:
mode:
Diffstat (limited to 'build/patches.zig')
-rw-r--r--build/patches.zig40
1 files changed, 38 insertions, 2 deletions
diff --git a/build/patches.zig b/build/patches.zig
index d5ac7372..3d956d26 100644
--- a/build/patches.zig
+++ b/build/patches.zig
@@ -175,8 +175,14 @@ pub fn vaxis(b: *std.Build, patch: *std.Build.Step.Compile, vaxis_dep: *std.Buil
/// zstbi with stb_image and its writer cut out: of it only its resize is
/// left, for a terminal PNG's downscale (build/core.zig, "One PNG
/// decoder"). zstbi.deinit still resets the reader's and the writer's flip
-/// flags, and Image.deinit frees the resize's output.
+/// flags, and Image.deinit frees the resize's output. And no fused
+/// multiply-add in the resize: clang contracts `a * b + c` where the CPU
+/// has one (aarch64 always does), which rounds once, so a PNG downscaled
+/// on an Apple silicon Mac came out pixels apart from Linux's, and the same
+/// bytes must give the same terminal on every machine a client runs on
+/// (docs/zstbi-fp-contract.md).
const zstbi_cut = [_]Edit{
+ .{ .old = "#include <stdlib.h>\n", .new = "#include <stdlib.h>\n#pragma STDC FP_CONTRACT OFF\n" },
.{ .old = "#define STB_IMAGE_IMPLEMENTATION\n#include \"stb_image.h\"\n", .new = "void stbi_set_flip_vertically_on_load(int flag) { (void)flag; }\nvoid stbi_image_free(void *p) { zstbiFreePtr(p); }\n" },
.{ .old = "#define STB_IMAGE_WRITE_IMPLEMENTATION\n#include \"stb_image_write.h\"\n", .new = "void stbi_flip_vertically_on_write(int flag) { (void)flag; }\n" },
};
@@ -245,11 +251,41 @@ const ghostty_kitty = [_]Edit{
},
};
+/// ghostty's terminal page (src/terminal/page.zig): a page's size is
+/// rounded to 4 KiB on every target, not to the OS page (4 KiB on Linux
+/// and FreeBSD, 16 KiB on an Apple aarch64 Mac). The same bytes must give
+/// the same emulator on every machine a client runs on, and the rounding
+/// decides how many rows a page holds and how much room its style and link
+/// tables grow to, so how many history rows the 16 MiB scrollback keeps:
+/// a Mac had fewer than Linux once it was full, which the digest saw
+/// (docs/ghostty-page-size.md). On Linux and FreeBSD this changes nothing;
+/// a Mac maps whole 16 KiB pages under a length that is not one, up to
+/// 12 KiB a page left unused, and ghostty's assertions that a page's
+/// length is a whole number of OS pages (page.zig, mem.zig) ask for 4 KiB.
+const ghostty_page = [_]Edit{
+ .{
+ .old = " const total_size = alignForward(usize, meta_end, std.heap.page_size_min);\n",
+ .new = " const total_size = alignForward(usize, meta_end, 4 << 10); // pardes (build/patches.zig)\n",
+ },
+ .{
+ .old = " assert(l.total_size % std.heap.page_size_min == 0);\n",
+ .new = " assert(l.total_size % (4 << 10) == 0); // pardes (build/patches.zig)\n",
+ },
+};
+const ghostty_mem = [_]Edit{.{
+ .old = " assert(memory.len % std.heap.page_size_min == 0);\n",
+ .new = " assert(memory.len % (4 << 10) == 0); // pardes (build/patches.zig): a page's size\n",
+ .count = 2,
+}};
+
pub fn ghosttyKitty(b: *std.Build, patch: *std.Build.Step.Compile, dep: *std.Build.Dependency, vt: *std.Build.Module) void {
const files = b.addWriteFiles();
// The rest of src as it is; fonts are the app's, not the library's.
- _ = files.addCopyDirectory(dep.path("src"), "", .{ .exclude_extensions = &.{ "graphics_image.zig", ".ttf", ".otf" } });
+ // ("terminal/page.zig" leaves terminal/snapshot/page.zig in.)
+ _ = files.addCopyDirectory(dep.path("src"), "", .{ .exclude_extensions = &.{ "graphics_image.zig", "terminal/page.zig", "terminal/mem.zig", ".ttf", ".otf" } });
_ = files.addCopyFile(apply(b, patch, dep, "src/terminal/kitty/graphics_image.zig", &ghostty_kitty, "ghostty_kitty.zig"), "terminal/kitty/graphics_image.zig");
+ _ = files.addCopyFile(apply(b, patch, dep, "src/terminal/page.zig", &ghostty_page, null), "terminal/page.zig");
+ _ = files.addCopyFile(apply(b, patch, dep, "src/terminal/mem.zig", &ghostty_mem, null), "terminal/mem.zig");
vt.root_source_file = files.getDirectory().path(b, "lib_vt.zig");
}