summaryrefslogtreecommitdiff
path: root/src/abi.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-16 23:00:19 -0300
committerGabriel Schneider <[email protected]>2026-11-17 12:15:01 -0300
commit5b8cf6f66e367192090350c9129fa341edfc9343 (patch)
tree48a5e6229aca31c4a44473343d47fb7fcc63a32f /src/abi.zig
parent88c04dd6c392c6d8fc3a02408506e85d86f476d5 (diff)
downloadsketchbook-5b8cf6f66e367192090350c9129fa341edfc9343.tar.gz
sketchbook-5b8cf6f66e367192090350c9129fa341edfc9343.zip
Compute abi.hash's layout half once per abi change, not in every compile
The comptime walk over the shared types cost about half a second of every sketch library's compile. abi_hash.zig runs it at build time, once per change of the abi sources (watched like any input), and build.zig hands the number to host and sketches as the module abi_hash; abi.hash folds in the build as before. The value is the walk's own, computed for the build machine in Debug.
Diffstat (limited to 'src/abi.zig')
-rw-r--r--src/abi.zig17
1 files changed, 11 insertions, 6 deletions
diff --git a/src/abi.zig b/src/abi.zig
index 33f7cd6..9154539 100644
--- a/src/abi.zig
+++ b/src/abi.zig
@@ -815,17 +815,22 @@ pub const Sketch = struct {
};
};
-/// Layout hash of everything above, and of `build`. Changes whenever a shared
-/// type does, or the compiler, backend or optimize mode: Zig's own calling
-/// convention, which `Host.VTable` and every `std.mem.Allocator` use, differs
-/// between backends and modes.
-pub const hash: u64 = blk: {
+/// `layout_hash` and `build`: changes whenever a shared type does, or the
+/// compiler, backend or optimize mode, since Zig's own calling convention
+/// (`Host.VTable`, every `std.mem.Allocator`) differs between them.
+/// `layout_hash` costs half a second of comptime, so build.zig has
+/// `abi_hash.zig` compute it once per change of these files and hands it
+/// over as the module `abi_hash`, instead of every sketch's compile doing it.
+pub const hash: u64 = std.hash.Wyhash.hash(@import("abi_hash").layout, build);
+
+/// Hash of every shared type's name and layout.
+pub const layout_hash: u64 = blk: {
@setEvalBranchQuota(1_000_000);
var h: u64 = 0;
for (.{ Rect, Color, BlendMode, Corners, Event, Mode, Stream, Input, Image, Audio, Cursor, Voice, Command, gpu.Pass, gpu.Pipeline, gpu.Draw, gpu.Dispatch, gpu.PostProcess, Host, Host.VTable, Context, Field, Layout, Info, Memory, Sketch }) |T| {
h = std.hash.Wyhash.hash(h, @typeName(T) ++ layout.signature(T));
}
- break :blk std.hash.Wyhash.hash(h, build);
+ break :blk h;
};
/// The compiler, backend and mode of this build, exported by libraries as