summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/abi.zig17
-rw-r--r--src/abi_hash.zig9
2 files changed, 20 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
diff --git a/src/abi_hash.zig b/src/abi_hash.zig
new file mode 100644
index 0000000..9cd01cf
--- /dev/null
+++ b/src/abi_hash.zig
@@ -0,0 +1,9 @@
+//! Prints `abi.layout_hash` as Zig source: build.zig runs this once per change
+//! of the abi sources and hands the result to host and sketches as the module
+//! `abi_hash`.
+const std = @import("std");
+const abi = @import("abi");
+
+pub fn main(init: std.process.Init) !void {
+ try std.Io.File.stdout().writeStreamingAll(init.io, std.fmt.comptimePrint("pub const layout: u64 = 0x{x};\n", .{abi.layout_hash}));
+}