update to Zig 2024.10

This commit is contained in:
Carl Åstholm 2024-10-09 22:33:54 +02:00
parent fb4ae48540
commit ab97afcbe4
8 changed files with 43 additions and 31 deletions

View file

@ -18,7 +18,7 @@ jobs:
- name: Setup Zig - name: Setup Zig
run: | run: |
sudo apt install xz-utils sudo apt install xz-utils
sudo sh -c 'wget -c https://pkg.machengine.org/zig/zig-linux-x86_64-0.13.0-dev.351+64ef45eb0.tar.xz -O - | tar -xJ --strip-components=1 -C /usr/local/bin' sudo sh -c 'wget -c https://pkg.machengine.org/zig/zig-linux-x86_64-0.14.0-dev.1911+3bf89f55c.tar.xz -O - | tar -xJ --strip-components=1 -C /usr/local/bin'
- name: x86_64-linux -> x86_64-macos - name: x86_64-linux -> x86_64-macos
run: zig build -Dtarget=x86_64-macos run: zig build -Dtarget=x86_64-macos
- name: x86_64-linux -> aarch64-macos - name: x86_64-linux -> aarch64-macos
@ -48,10 +48,10 @@ jobs:
- name: Setup Zig - name: Setup Zig
run: | run: |
$ProgressPreference = 'SilentlyContinue' $ProgressPreference = 'SilentlyContinue'
Invoke-WebRequest -Uri "https://pkg.machengine.org/zig/zig-windows-x86_64-0.13.0-dev.351+64ef45eb0.zip" -OutFile "C:\zig.zip" Invoke-WebRequest -Uri "https://pkg.machengine.org/zig/zig-windows-x86_64-0.14.0-dev.1911+3bf89f55c.zip" -OutFile "C:\zig.zip"
cd C:\ cd C:\
7z x zig.zip 7z x zig.zip
Add-Content $env:GITHUB_PATH "C:\zig-windows-x86_64-0.13.0-dev.351+64ef45eb0\" Add-Content $env:GITHUB_PATH "C:\zig-windows-x86_64-0.14.0-dev.1911+3bf89f55c\"
- name: x86_64-windows -> x86_64-macos - name: x86_64-windows -> x86_64-macos
run: zig build -Dtarget=x86_64-macos run: zig build -Dtarget=x86_64-macos
- name: x86_64-windows -> aarch64-macos - name: x86_64-windows -> aarch64-macos
@ -76,7 +76,7 @@ jobs:
run: | run: |
brew uninstall --ignore-dependencies libx11 # https://github.com/ziglang/zig/issues/11066 brew uninstall --ignore-dependencies libx11 # https://github.com/ziglang/zig/issues/11066
brew install xz brew install xz
sudo sh -c 'wget -c https://pkg.machengine.org/zig/zig-macos-x86_64-0.13.0-dev.351+64ef45eb0.tar.xz -O - | tar -xJ --strip-components=1 -C /usr/local/bin' sudo sh -c 'wget -c https://pkg.machengine.org/zig/zig-macos-x86_64-0.14.0-dev.1911+3bf89f55c.tar.xz -O - | tar -xJ --strip-components=1 -C /usr/local/bin'
- name: x86_64-macos -> aarch64-macos - name: x86_64-macos -> aarch64-macos
run: zig build -Dtarget=aarch64-macos run: zig build -Dtarget=aarch64-macos
- name: x86_64-macos -> x86_64-windows - name: x86_64-macos -> x86_64-windows

View file

@ -5,11 +5,17 @@ pub fn build(b: *std.Build) !void {
const optimize = b.standardOptimizeOption(.{}); const optimize = b.standardOptimizeOption(.{});
const target = b.standardTargetOptions(.{}); const target = b.standardTargetOptions(.{});
const glfw_dep = b.dependency("glfw", .{
.target = target,
.optimize = optimize,
});
var module = b.addModule("mach-glfw", .{ var module = b.addModule("mach-glfw", .{
.target = target, .target = target,
.optimize = optimize, .optimize = optimize,
.root_source_file = b.path("src/main.zig"), .root_source_file = b.path("src/main.zig"),
}); });
module.linkLibrary(glfw_dep.artifact("glfw"));
const test_step = b.step("test", "Run library tests"); const test_step = b.step("test", "Run library tests");
const main_tests = b.addTest(.{ const main_tests = b.addTest(.{
@ -18,23 +24,29 @@ pub fn build(b: *std.Build) !void {
.target = target, .target = target,
.optimize = optimize, .optimize = optimize,
}); });
main_tests.linkLibrary(glfw_dep.artifact("glfw"));
b.installArtifact(main_tests); b.installArtifact(main_tests);
test_step.dependOn(&b.addRunArtifact(main_tests).step); test_step.dependOn(&b.addRunArtifact(main_tests).step);
if (b.lazyDependency("glfw", .{ if (target.result.isDarwin()) {
if (glfw_dep.builder.lazyDependency("xcode_frameworks", .{
.target = target, .target = target,
.optimize = optimize, .optimize = optimize,
})) |dep| { })) |dep| {
module.linkLibrary(dep.artifact("glfw")); module.addSystemFrameworkPath(dep.path("Frameworks"));
@import("glfw").addPaths(module); module.addSystemIncludePath(dep.path("include"));
main_tests.linkLibrary(dep.artifact("glfw")); module.addLibraryPath(dep.path("lib"));
@import("glfw").addPaths(&main_tests.root_module);
main_tests.root_module.addSystemFrameworkPath(dep.path("Frameworks"));
main_tests.root_module.addSystemIncludePath(dep.path("include"));
main_tests.root_module.addLibraryPath(dep.path("lib"));
}
} }
} }
comptime { comptime {
const supported_zig = std.SemanticVersion.parse("0.13.0-dev.351+64ef45eb0") catch unreachable; const supported_zig = std.SemanticVersion.parse("0.14.0-dev.1911+3bf89f55c") catch unreachable;
if (builtin.zig_version.order(supported_zig) != .eq) { if (builtin.zig_version.order(supported_zig) != .eq) {
@compileError(std.fmt.comptimePrint("unsupported Zig version ({}). Required Zig version 2024.5.0-mach: https://machengine.org/about/nominated-zig/#202450-mach", .{builtin.zig_version})); @compileError(std.fmt.comptimePrint("unsupported Zig version ({}). Required Zig version 2024.10.0-mach: https://machengine.org/docs/nominated-zig/#2024100-mach", .{builtin.zig_version}));
} }
} }

View file

@ -12,8 +12,8 @@
}, },
.dependencies = .{ .dependencies = .{
.glfw = .{ .glfw = .{
.url = "https://pkg.machengine.org/glfw/e6f377baed70a7bef9fa08d808f40b64c5136bf6.tar.gz", .url = "https://pkg.machengine.org/glfw/db0e7acc8e1685393df582871b64a0ea2b3a0938.tar.gz",
.hash = "1220c15e66c13f9633fcfd50b5ed265f74f2950c98b1f1defd66298fa027765e0190", .hash = "122050d9df82e40d86b35a641afe615a1b4145e78bb57a4ba3844ba2a338e3ee11e5",
}, },
}, },
} }

View file

@ -1678,8 +1678,8 @@ pub inline fn setInputMode(self: Window, mode: InputMode, value: anytype) void {
const T = @TypeOf(value); const T = @TypeOf(value);
std.debug.assert(switch (mode) { std.debug.assert(switch (mode) {
.cursor => switch (@typeInfo(T)) { .cursor => switch (@typeInfo(T)) {
.Enum => T == InputModeCursor, .@"enum" => T == InputModeCursor,
.EnumLiteral => @hasField(InputModeCursor, @tagName(value)), .enum_literal => @hasField(InputModeCursor, @tagName(value)),
else => false, else => false,
}, },
.sticky_keys => T == bool, .sticky_keys => T == bool,
@ -1688,8 +1688,8 @@ pub inline fn setInputMode(self: Window, mode: InputMode, value: anytype) void {
.raw_mouse_motion => T == bool, .raw_mouse_motion => T == bool,
}); });
const int_value: c_int = switch (@typeInfo(T)) { const int_value: c_int = switch (@typeInfo(T)) {
.Enum, .@"enum",
.EnumLiteral, .enum_literal,
=> @intFromEnum(@as(InputModeCursor, value)), => @intFromEnum(@as(InputModeCursor, value)),
else => @intFromBool(value), else => @intFromBool(value),
}; };
@ -2155,27 +2155,27 @@ inline fn hint(h: Hint, value: anytype) void {
const value_type_info: std.builtin.Type = @typeInfo(value_type); const value_type_info: std.builtin.Type = @typeInfo(value_type);
switch (value_type_info) { switch (value_type_info) {
.Int, .ComptimeInt => { .int, .comptime_int => {
c.glfwWindowHint(@intFromEnum(h), @as(c_int, @intCast(value))); c.glfwWindowHint(@intFromEnum(h), @as(c_int, @intCast(value)));
}, },
.Bool => { .bool => {
const int_value = @intFromBool(value); const int_value = @intFromBool(value);
c.glfwWindowHint(@intFromEnum(h), @as(c_int, @intCast(int_value))); c.glfwWindowHint(@intFromEnum(h), @as(c_int, @intCast(int_value)));
}, },
.Enum => { .@"enum" => {
const int_value = @intFromEnum(value); const int_value = @intFromEnum(value);
c.glfwWindowHint(@intFromEnum(h), @as(c_int, @intCast(int_value))); c.glfwWindowHint(@intFromEnum(h), @as(c_int, @intCast(int_value)));
}, },
.Array => |arr_type| { .array => |arr_type| {
if (arr_type.child != u8) { if (arr_type.child != u8) {
@compileError("expected array of u8, got " ++ @typeName(arr_type)); @compileError("expected array of u8, got " ++ @typeName(arr_type));
} }
c.glfwWindowHintString(@intFromEnum(h), &value[0]); c.glfwWindowHintString(@intFromEnum(h), &value[0]);
}, },
.Pointer => |pointer_info| { .pointer => |pointer_info| {
const pointed_type = @typeInfo(pointer_info.child); const pointed_type = @typeInfo(pointer_info.child);
switch (pointed_type) { switch (pointed_type) {
.Array => |arr_type| { .array => |arr_type| {
if (arr_type.child != u8) { if (arr_type.child != u8) {
@compileError("expected pointer to array of u8, got " ++ @typeName(arr_type)); @compileError("expected pointer to array of u8, got " ++ @typeName(arr_type));
} }

View file

@ -18,7 +18,7 @@ pub const Hat = packed struct(u8) {
inline fn verifyIntType(comptime IntType: type) void { inline fn verifyIntType(comptime IntType: type) void {
comptime { comptime {
switch (@typeInfo(IntType)) { switch (@typeInfo(IntType)) {
.Int => {}, .int => {},
else => @compileError("Int was not of int type"), else => @compileError("Int was not of int type"),
} }
} }

View file

@ -304,10 +304,10 @@ pub const PlatformType = enum(c_int) {
/// @thread_safety This function must only be called from the main thread. /// @thread_safety This function must only be called from the main thread.
fn initHint(hint: InitHint, value: anytype) void { fn initHint(hint: InitHint, value: anytype) void {
switch (@typeInfo(@TypeOf(value))) { switch (@typeInfo(@TypeOf(value))) {
.Int, .ComptimeInt => { .int, .comptime_int => {
c.glfwInitHint(@intFromEnum(hint), @as(c_int, @intCast(value))); c.glfwInitHint(@intFromEnum(hint), @as(c_int, @intCast(value)));
}, },
.Bool => c.glfwInitHint(@intFromEnum(hint), @as(c_int, @intCast(@intFromBool(value)))), .bool => c.glfwInitHint(@intFromEnum(hint), @as(c_int, @intCast(@intFromBool(value)))),
else => @compileError("expected a int or bool, got " ++ @typeName(@TypeOf(value))), else => @compileError("expected a int or bool, got " ++ @typeName(@TypeOf(value))),
} }
} }

View file

@ -18,7 +18,7 @@ pub const Mods = packed struct(u8) {
inline fn verifyIntType(comptime IntType: type) void { inline fn verifyIntType(comptime IntType: type) void {
comptime { comptime {
switch (@typeInfo(IntType)) { switch (@typeInfo(IntType)) {
.Int => {}, .int => {},
else => @compileError("Int was not of int type"), else => @compileError("Int was not of int type"),
} }
} }

View file

@ -232,7 +232,7 @@ pub inline fn createWindowSurface(vk_instance: anytype, window: Window, vk_alloc
// zig-vulkan uses enums to represent opaque pointers: // zig-vulkan uses enums to represent opaque pointers:
// pub const Instance = enum(usize) { null_handle = 0, _ }; // pub const Instance = enum(usize) { null_handle = 0, _ };
const instance: c.VkInstance = switch (@typeInfo(@TypeOf(vk_instance))) { const instance: c.VkInstance = switch (@typeInfo(@TypeOf(vk_instance))) {
.Enum => @as(c.VkInstance, @ptrFromInt(@intFromEnum(vk_instance))), .@"enum" => @as(c.VkInstance, @ptrFromInt(@intFromEnum(vk_instance))),
else => @as(c.VkInstance, @ptrCast(vk_instance)), else => @as(c.VkInstance, @ptrCast(vk_instance)),
}; };