summaryrefslogtreecommitdiff
path: root/src/abi.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/abi.zig')
-rw-r--r--src/abi.zig17
1 files changed, 13 insertions, 4 deletions
diff --git a/src/abi.zig b/src/abi.zig
index 7177f14..33f7cd6 100644
--- a/src/abi.zig
+++ b/src/abi.zig
@@ -5,11 +5,13 @@
//! tagged unions, `std.mem.Allocator`. Two rules keep reloads safe:
//! - whatever outlives a call lives in host memory (host code is never
//! unloaded, so host allocators and function pointers stay valid);
-//! - `hash` covers the layout of every type here, and a host refuses a sketch
-//! built against different definitions instead of misreading its memory.
+//! - `hash` covers the layout of every type here and the compiler, backend
+//! and mode, and a host refuses a sketch built against different
+//! definitions or by another build instead of misreading its memory.
//!
//! Only `Event` and the reflected `Layout` are `extern`: they are written to disk.
const std = @import("std");
+const builtin = @import("builtin");
pub const layout = @import("layout.zig");
pub const Key = @import("keys.zig").Key;
@@ -813,16 +815,23 @@ pub const Sketch = struct {
};
};
-/// Layout hash of everything above. Changes whenever a shared type does.
+/// 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: {
@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 h;
+ break :blk std.hash.Wyhash.hash(h, build);
};
+/// The compiler, backend and mode of this build, exported by libraries as
+/// `sketch_build` so a host can say why it refuses one.
+pub const build = builtin.zig_version_string ++ " " ++ @tagName(builtin.zig_backend) ++ " " ++ @tagName(builtin.mode);
+
test "vertex attributes and std140 checks come from the types" {
const Vertex = extern struct { position: [2]f32, color: [4]u8, uv: [2]f32 };
const attrs = gpu.attributes(Vertex);