zig-window
zig-window copied to clipboard
Can't build with zig 0.8.0 ?
Tried to built it with zig 0.8.0 but compiler complain:
❯ zig build -Dtarget=x86_64-linux
./src/main.zig:252:34: error: container 'builtin' has no member called 'endian'
.byte_order = if (builtin.endian == builtin.Endian.Big) 0x42 else 0x6c,
^
./src/main.zig:218:5: note: referenced here
try writeSetup(sock, auth);
^
./src/main.zig:179:51: note: referenced here
return connectToStream(allocator, sock, auth) catch |err| switch (err) {
^
./src/main.zig:91:12: note: referenced here
return try connectToDisplay(allocator, parsed, null);
^
nox...The following command exited with error code 1:
/usr/bin/zig build-exe /home/naia/zig-window/example/nox.zig --cache-dir /home/naia/zig-window/zig-cache --global-cache-dir /home/naia/.cache/zig --name nox --pkg-begin window /home/naia/zig-window/src/main.zig --pkg-end --enable-cache
error: the following build command failed with exit code 1:
/home/naia/zig-window/zig-cache/o/ccbd26785dce871b5dfe91bcf48914cf/build /usr/bin/zig /home/naia/zig-window /home/naia/zig-window/zig-cache /home/naia/.cache/zig
❯ zig version
0.8.0
Yeah, I think this is just an issue with the progressive nature of the std api. I've got it compiling against 0.8.1 but alas, the linking is borked for me (probably because i'm unfamiliar with the build args/targets (but as noted in the readme its best to use a generic profile -Dtarget=x86_64-linux
(which links but doesn't run for me) Anyways YMMV:
diff --git a/src/main.zig b/src/main.zig
index 91b0a10..504e04e 100644
--- a/src/main.zig
+++ b/src/main.zig
@@ -249,7 +249,7 @@ fn writeSetup(sock: net.Stream, auth: ?Auth) !void {
var parts: [6]os.iovec_const = undefined;
var parts_index: usize = 0;
var setup_req = xcb_setup_request_t{
- .byte_order = if (builtin.endian == builtin.Endian.Big) 0x42 else 0x6c,
+ .byte_order = if (builtin.target.cpu.arch.endian() == std.builtin.Endian.Big) 0x42 else 0x6c,
.pad0 = 0,
.protocol_major_version = X_PROTOCOL,
.protocol_minor_version = X_PROTOCOL_REVISION,
diff --git a/src/static-window.zig b/src/static-window.zig
index 2571820..749e5cb 100644
--- a/src/static-window.zig
+++ b/src/static-window.zig
@@ -1534,8 +1534,7 @@ fn checkDeviceExtensionSupport(allocator: *Allocator, device: c.VkPhysicalDevice
const CStrHashMap = std.HashMap(
[*:0]const u8,
void,
- hash_cstr,
- eql_cstr,
+ CStringContext,
std.hash_map.DefaultMaxLoadPercentage,
);
var requiredExtensions = CStrHashMap.init(allocator);
@@ -1655,17 +1654,21 @@ fn drawFrame() !void {
currentFrame = (currentFrame + 1) % MAX_FRAMES_IN_FLIGHT;
}
-fn hash_cstr(a: [*:0]const u8) u64 {
- // FNV 32-bit hash
- var h: u32 = 2166136261;
- var i: usize = 0;
- while (a[i] != 0) : (i += 1) {
- h ^= a[i];
- h *%= 16777619;
+const CStringContext = struct {
+ pub fn hash(self: @This(), a: [*:0]const u8) u64 {
+ _ = self;
+ // FNV 32-bit hash
+ var h: u32 = 2166136261;
+ var i: usize = 0;
+ while (a[i] != 0) : (i += 1) {
+ h ^= a[i];
+ h *%= 16777619;
+ }
+ return h;
}
- return h;
-}
+ pub fn eql(self: @This(), a: [*:0]const u8, b: [*:0]const u8) bool {
+ _ = self;
+ return std.cstr.cmp(a, b) == 0;
+ }
+};
-fn eql_cstr(a: [*:0]const u8, b: [*:0]const u8) bool {
- return std.cstr.cmp(a, b) == 0;
-}