update to Zig 2024.05

Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
This commit is contained in:
Stephen Gutekanst 2024-06-02 16:16:03 -07:00 committed by Stephen Gutekanst
parent c64bc513b9
commit 707e5cc756
16 changed files with 102 additions and 93 deletions

View file

@ -13,7 +13,7 @@ pub inline fn printUnhandledErrorCallback(_: void, ty: gpu.ErrorType, message: [
.unknown => std.log.err("gpu: unknown error: {s}\n", .{message}),
else => unreachable,
}
std.os.exit(1);
std.process.exit(1);
}
pub fn detectBackendType(allocator: std.mem.Allocator) !gpu.BackendType {

View file

@ -1308,7 +1308,7 @@ inline fn printUnhandledErrorCallback(_: void, ty: gpu.ErrorType, message: [*:0]
.unknown => std.log.err("gpu: unknown error: {s}\n", .{message}),
else => unreachable,
}
std.os.exit(1);
std.process.exit(1);
}
fn detectBackendType(allocator: std.mem.Allocator) !gpu.BackendType {

View file

@ -24,7 +24,7 @@ pub fn main() !void {
// Run from the directory where the executable is located so relative assets can be found.
var buffer: [1024]u8 = undefined;
const path = std.fs.selfExeDirPath(buffer[0..]) catch ".";
std.os.chdir(path) catch {};
std.posix.chdir(path) catch {};
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
defer _ = gpa.deinit();

View file

@ -87,9 +87,9 @@ const linux_impl = struct {
real_gamemode_request_end: *const fn () callconv(.C) c_int,
real_gamemode_query_status: *const fn () callconv(.C) c_int,
real_gamemode_request_start_for: *const fn (std.os.pid_t) callconv(.C) c_int,
real_gamemode_request_end_for: *const fn (std.os.pid_t) callconv(.C) c_int,
real_gamemode_query_status_for: *const fn (std.os.pid_t) callconv(.C) c_int,
real_gamemode_request_start_for: *const fn (std.c.pid_t) callconv(.C) c_int,
real_gamemode_request_end_for: *const fn (std.c.pid_t) callconv(.C) c_int,
real_gamemode_query_status_for: *const fn (std.c.pid_t) callconv(.C) c_int,
};
/// Try to load libgamemode, returning an error when loading fails.
@ -169,7 +169,7 @@ const linux_impl = struct {
/// Query the status of gamemode for a given PID.
/// This does blocking IO!
pub fn queryStatusFor(pid: std.os.pid_t) Error!Status {
pub fn queryStatusFor(pid: std.c.pid_t) Error!Status {
if (!init()) return .inactive;
const ret = state.init.syms.real_gamemode_query_status_for(pid);
@ -192,7 +192,7 @@ const linux_impl = struct {
/// Request starting gamemode for a given PID.
/// This does blocking IO!
pub fn requestStartFor(pid: std.os.pid_t) Error!void {
pub fn requestStartFor(pid: std.c.pid_t) Error!void {
if (!init()) return;
const ret = state.init.syms.real_gamemode_request_start_for(pid);
@ -215,7 +215,7 @@ const linux_impl = struct {
/// Request stopping gamemode for a given PID.
/// This does blocking IO!
pub fn requestEndFor(pid: std.os.pid_t) Error!void {
pub fn requestEndFor(pid: std.c.pid_t) Error!void {
if (!init()) return;
const ret = state.init.syms.real_gamemode_request_end_for(pid);
@ -244,20 +244,20 @@ const noop_impl = struct {
return .inactive;
}
pub fn queryStatusFor(pid: std.os.pid_t) Error!Status {
pub fn queryStatusFor(pid: std.c.pid_t) Error!Status {
_ = pid;
return .inactive;
}
pub fn requestStart() Error!void {}
pub fn requestStartFor(pid: std.os.pid_t) Error!void {
pub fn requestStartFor(pid: std.c.pid_t) Error!void {
_ = pid;
}
pub fn requestEnd() Error!void {}
pub fn requestEndFor(pid: std.os.pid_t) Error!void {
pub fn requestEndFor(pid: std.c.pid_t) Error!void {
_ = pid;
}
};

View file

@ -12,7 +12,7 @@ pub inline fn printUnhandledErrorCallback(_: void, typ: gpu.ErrorType, message:
.unknown => std.log.err("gpu: unknown error: {s}\n", .{message}),
else => unreachable,
}
std.os.exit(1);
std.process.exit(1);
}
fn getEnvVarOwned(allocator: std.mem.Allocator, key: []const u8) error{ OutOfMemory, InvalidUtf8, InvalidWtf8 }!?[]u8 {

View file

@ -1013,7 +1013,7 @@ test "projection2D_model_to_clip_space" {
try testing.expect(math.Vec4, math.vec4(0, 0, 1.0, 1)).eql(mvp.mulVec(&math.vec4(0, 0, 0, 1)));
try testing.expect(math.Vec4, math.vec4(0, 0, 0.5, 1)).eql(mvp.mulVec(&math.vec4(0, 0, 50, 1)));
try testing.expect(math.Vec4, math.vec4(0, -1, 1, 1)).eql(mvp.mul(&math.Mat4x4.rotateX(math.degreesToRadians(f32, 90))).mulVec(&math.vec4(0, 0, 50, 1)));
try testing.expect(math.Vec4, math.vec4(1, 0, 1, 1)).eql(mvp.mul(&math.Mat4x4.rotateY(math.degreesToRadians(f32, 90))).mulVec(&math.vec4(0, 0, 50, 1)));
try testing.expect(math.Vec4, math.vec4(0, 0, 0.5, 1)).eql(mvp.mul(&math.Mat4x4.rotateZ(math.degreesToRadians(f32, 90))).mulVec(&math.vec4(0, 0, 50, 1)));
try testing.expect(math.Vec4, math.vec4(0, -1, 1, 1)).eql(mvp.mul(&math.Mat4x4.rotateX(math.degreesToRadians(90))).mulVec(&math.vec4(0, 0, 50, 1)));
try testing.expect(math.Vec4, math.vec4(1, 0, 1, 1)).eql(mvp.mul(&math.Mat4x4.rotateY(math.degreesToRadians(90))).mulVec(&math.vec4(0, 0, 50, 1)));
try testing.expect(math.Vec4, math.vec4(0, 0, 0.5, 1)).eql(mvp.mul(&math.Mat4x4.rotateZ(math.degreesToRadians(90))).mulVec(&math.vec4(0, 0, 50, 1)));
}

View file

@ -785,7 +785,7 @@ pub fn Database(comptime modules: anytype) type {
}
break :blk @Type(.{
.Struct = .{
.layout = .Auto,
.layout = .auto,
.is_tuple = false,
.fields = fields,
.decls = &[_]std.builtin.Type.Declaration{},

View file

@ -87,7 +87,7 @@ pub fn Merge(comptime tuple: anytype) type {
return @Type(.{
.Struct = .{
.is_tuple = true,
.layout = .Auto,
.layout = .auto,
.decls = &.{},
.fields = tuple_fields,
},
@ -439,7 +439,7 @@ pub fn ModsByName(comptime modules: anytype) type {
}
return @Type(.{
.Struct = .{
.layout = .Auto,
.layout = .auto,
.is_tuple = false,
.fields = fields,
.decls = &[_]std.builtin.Type.Declaration{},
@ -619,8 +619,8 @@ pub fn ModSet(comptime modules: anytype) type {
pub inline fn scheduleWithArgs(m: *@This(), comptime system_name: SystemEnumM(M), args: SystemArgsM(M, system_name)) void {
const ModulesT = Modules(modules);
const MByName = ModsByName(modules);
const mod_ptr: *MByName = @alignCast(@fieldParentPtr(MByName, @tagName(module_tag), m));
const mods = @fieldParentPtr(ModulesT, "mod", mod_ptr);
const mod_ptr: *MByName = @alignCast(@fieldParentPtr(@tagName(module_tag), m));
const mods: *ModulesT = @fieldParentPtr("mod", mod_ptr);
mods.scheduleWithArgs(module_tag, system_name, args);
}
@ -641,8 +641,8 @@ pub fn ModSet(comptime modules: anytype) type {
pub inline fn scheduleAny(m: *@This(), sys: AnySystem) void {
const ModulesT = Modules(modules);
const MByName = ModsByName(modules);
const mod_ptr: *MByName = @alignCast(@fieldParentPtr(MByName, @tagName(module_tag), m));
const mods = @fieldParentPtr(ModulesT, "mod", mod_ptr);
const mod_ptr: *MByName = @alignCast(@fieldParentPtr(@tagName(module_tag), m));
const mods: *ModulesT = @fieldParentPtr("mod", mod_ptr);
mods.scheduleDynamic(sys.module_id, sys.system_id);
}
};
@ -867,7 +867,7 @@ fn NamespacedModules(comptime modules: anytype) type {
}
return @Type(.{
.Struct = .{
.layout = .Auto,
.layout = .auto,
.is_tuple = false,
.fields = fields,
.decls = &[_]std.builtin.Type.Declaration{},
@ -942,7 +942,7 @@ pub fn ComponentTypesByName(comptime modules: anytype) type {
}
return @Type(.{
.Struct = .{
.layout = .Auto,
.layout = .auto,
.is_tuple = false,
.fields = fields,
.decls = &[_]std.builtin.Type.Declaration{},
@ -1012,7 +1012,7 @@ fn ComponentTypesM(comptime M: anytype) type {
}
return @Type(.{
.Struct = .{
.layout = .Auto,
.layout = .auto,
.is_tuple = false,
.fields = fields,
.decls = &[_]std.builtin.Type.Declaration{},

View file

@ -117,31 +117,31 @@ pub const Context = struct {
}
fn onDeviceStateChangedCB(ctx: *const win32.IMMNotificationClient, _: ?[*:0]const u16, _: u32) callconv(std.os.windows.WINAPI) win32.HRESULT {
var watcher = @fieldParentPtr(Watcher, "notif_client", ctx);
var watcher: *Watcher = @fieldParentPtr("notif_client", ctx);
watcher.deviceChangeFn(watcher.user_data);
return win32.S_OK;
}
fn onDeviceAddedCB(ctx: *const win32.IMMNotificationClient, _: ?[*:0]const u16) callconv(std.os.windows.WINAPI) win32.HRESULT {
var watcher = @fieldParentPtr(Watcher, "notif_client", ctx);
var watcher: *Watcher = @fieldParentPtr("notif_client", ctx);
watcher.deviceChangeFn(watcher.user_data);
return win32.S_OK;
}
fn onDeviceRemovedCB(ctx: *const win32.IMMNotificationClient, _: ?[*:0]const u16) callconv(std.os.windows.WINAPI) win32.HRESULT {
var watcher = @fieldParentPtr(Watcher, "notif_client", ctx);
var watcher: *Watcher = @fieldParentPtr("notif_client", ctx);
watcher.deviceChangeFn(watcher.user_data);
return win32.S_OK;
}
fn onDefaultDeviceChangedCB(ctx: *const win32.IMMNotificationClient, _: win32.DataFlow, _: win32.Role, _: ?[*:0]const u16) callconv(std.os.windows.WINAPI) win32.HRESULT {
var watcher = @fieldParentPtr(Watcher, "notif_client", ctx);
var watcher: *Watcher = @fieldParentPtr("notif_client", ctx);
watcher.deviceChangeFn(watcher.user_data);
return win32.S_OK;
}
fn onPropertyValueChangedCB(ctx: *const win32.IMMNotificationClient, _: ?[*:0]const u16, _: win32.PROPERTYKEY) callconv(std.os.windows.WINAPI) win32.HRESULT {
var watcher = @fieldParentPtr(Watcher, "notif_client", ctx);
var watcher: *Watcher = @fieldParentPtr("notif_client", ctx);
watcher.deviceChangeFn(watcher.user_data);
return win32.S_OK;
}

View file

@ -288,7 +288,7 @@ pub const Device = struct {
pub fn processQueuedOperations(device: *Device) void {
// Reference trackers
if (device.queue) |queue| {
const completed_value = queue.completed_value.load(.Acquire);
const completed_value = queue.completed_value.load(.acquire);
var i: usize = 0;
while (i < device.reference_trackers.items.len) {
@ -2191,7 +2191,7 @@ pub const Queue = struct {
// Internal
pub fn waitUntil(queue: *Queue, fence_value: u64) void {
// TODO - avoid spin loop
while (queue.completed_value.load(.Acquire) < fence_value) {}
while (queue.completed_value.load(.acquire) < fence_value) {}
}
// Private
@ -2220,7 +2220,7 @@ pub const Queue = struct {
fn completedHandler(ctx: CompletedContext, mtl_command_buffer: *mtl.CommandBuffer) void {
_ = mtl_command_buffer;
ctx.queue.completed_value.store(ctx.fence_value, .Release);
ctx.queue.completed_value.store(ctx.fence_value, .release);
}
};

View file

@ -298,7 +298,7 @@ pub const Tag = enum {
}
};
pub const keywords = std.ComptimeStringMap(Tag, .{
pub const keywords = std.StaticStringMap(Tag).initComptime(.{
.{ "enable", .k_enable },
.{ "requires", .k_requires },
.{ "fn", .k_fn },
@ -368,7 +368,7 @@ pub const keywords = std.ComptimeStringMap(Tag, .{
pub const reserved = blk: {
@setEvalBranchQuota(3000);
break :blk std.ComptimeStringMap(void, .{
break :blk std.StaticStringMap(void).initComptime(.{
.{ "NULL", {} },
.{ "Self", {} },
.{ "abstract", {} },

View file

@ -130,7 +130,7 @@ pub fn writeOperand(section: *Section, comptime Operand: type, operand: Operand)
}
},
.Struct => |info| {
if (info.layout == .Packed) {
if (info.layout == .@"packed") {
section.writeWord(@bitCast(operand));
} else {
section.writeExtendedMask(Operand, operand);
@ -262,7 +262,7 @@ fn operandSize(comptime Operand: type, operand: Operand) usize {
}
break :blk total;
},
.Struct => |info| if (info.layout == .Packed) 1 else extendedMaskSize(Operand, operand),
.Struct => |info| if (info.layout == .@"packed") 1 else extendedMaskSize(Operand, operand),
.Union => extendedUnionSize(Operand, operand),
else => unreachable,
},

View file

@ -290,5 +290,5 @@ fn expectCodegen(
defer allocator.free(out);
try std.fs.cwd().makePath("zig-out/shader/");
try std.fs.cwd().writeFile("zig-out/shader/" ++ file_name, out);
try std.fs.cwd().writeFile(.{ .sub_path = "zig-out/shader/" ++ file_name, .data = out });
}

View file

@ -8,13 +8,13 @@ pub fn Manager(comptime T: type) type {
count: u32 = 1,
pub fn reference(manager: *@This()) void {
_ = @atomicRmw(u32, &manager.count, .Add, 1, .Monotonic);
_ = @atomicRmw(u32, &manager.count, .Add, 1, .monotonic);
}
pub fn release(manager: *@This()) void {
if (@atomicRmw(u32, &manager.count, .Sub, 1, .Release) == 1) {
@fence(.Acquire);
const parent = @fieldParentPtr(T, "manager", manager);
if (@atomicRmw(u32, &manager.count, .Sub, 1, .release) == 1) {
@fence(.acquire);
const parent: *T = @alignCast(@fieldParentPtr("manager", manager));
parent.deinit();
}
}