Update to Zig 0.17.0 (#1028)

Now compiles!
(Tested with Zig 0.17.0-dev.2375+d8aab4878)

## What are the changes about?

Updates dependencies & code for Zig 0.17.0 compatibility.

## What existing issue(s) does this resolve?

N/A

## Pre-requisites

- [x] I have tested & confirmed the changes work locally
- [x] I have read and fully adhere to the rules set in the contributing guidelines found in `CONTRIBUTING.md`

Reviewed-on: https://codeberg.org/fairyglade/ly/pulls/1028
This commit is contained in:
AnErrupTion authored and AnErrupTion committed 2026-10-03 17:53:36 +02:00
1 parent 55de3bc26c
commit f1fc335bb8
13 files changed
+91 -87

No files matched your search

+1 -3
View File
@@ -28,9 +28,7 @@ pub fn build(b: *std.Build) void {
});
mod.addImport("zlua", zlua.module("zlua"));
const translate_c = b.dependency("translate_c", .{
.target = target,
});
const translate_c = b.dependency("translate_c", .{});
addCImport(b, mod, translate_c, target, optimize, "pam", "#include <security/pam_appl.h>");
addCImport(b, mod, translate_c, target, optimize, "utmp", "#include <utmpx.h>");
+7 -7
View File
@@ -2,19 +2,19 @@
.name = .ly_core,
.version = "1.2.0",
.fingerprint = 0xddda7afda795472,
.minimum_zig_version = "0.16.0",
.minimum_zig_version = "0.17.0",
.dependencies = .{
.zigini = .{
.url = "git+https://github.com/AshAmetrine/zigini?ref=master#a665d081dda42664a96da2840ea09c5ccf9d0692",
.hash = "zigini-0.5.0-BSkB7e9WAACfyCBABNZiWL3gFMw18GKn3qBcPs8L1Ec1",
.url = "git+https://github.com/AshAmetrine/zigini?ref=main#085badbf90e25016f4609b5bde334689cdb41c5c",
.hash = "zigini-0.6.0-BSkB7UtYAAB6b6HEm3Pjj5WIy-uiuBYsNTNCUENVwL1t",
},
.translate_c = .{
.url = "git+https://codeberg.org/ziglang/translate-c?ref=zig-0.16.x#6fe0ffc4549f15c5f2d9432c2b4460ba90ff85ac",
.hash = "translate_c-1.0.0-Q_BUWo_5BgD4flHdUhA31zOz0XvZk9k7lQv1ouzyNXj2",
.url = "git+https://codeberg.org/ziglang/translate-c?ref=master#38d8339d9050eafe5dcf85b4fc9368576ca967e1",
.hash = "translate_c-0.0.0-Q_BUWoROBwAyokT5SJSw4YIrwdLd1w53i-pEYwBDqXZt",
},
.zlua = .{
.url = "git+https://github.com/natecraddock/ziglua?ref=zig-0.16#8f271c82baa5fc43aa02a72f6da020c2025d9436",
.hash = "zlua-0.1.0-hGRpC2aABQD4D9PBVH3wAW8k32-I4969MRQ0CpOwoley",
.url = "git+https://github.com/AnErrupTion/ziglua?ref=almost-there#5ff4bcc7b56661125dd93ad81addd473cebbcd14",
.hash = "zlua-0.1.0-hGRpC9eYBQDYOfd1aKlHG8hy8eTgKiaAdIyQEQgLREpI",
},
},
.paths = .{
+2 -2
View File
@@ -54,7 +54,7 @@ pub fn info(self: *LogFile, io: std.Io, category: []const u8, comptime message:
} else {
var buffer: [1024]u8 = undefined;
const slice = try std.fmt.bufPrint(&buffer, message, args);
const msg = try std.fmt.bufPrintZ(buffer[slice.len..], "[info/{s}] {s}", .{ category, slice });
const msg = try std.fmt.bufPrintSentinel(buffer[slice.len..], "[info/{s}] {s}", .{ category, slice }, 0);
std.posix.system.syslog(std.posix.LOG.INFO, msg.ptr);
}
@@ -72,7 +72,7 @@ pub fn err(self: *LogFile, io: std.Io, category: []const u8, comptime message: [
} else {
var buffer: [1024]u8 = undefined;
const slice = try std.fmt.bufPrint(&buffer, message, args);
const msg = try std.fmt.bufPrintZ(buffer[slice.len..], "[info/{s}] {s}", .{ category, slice });
const msg = try std.fmt.bufPrintSentinel(buffer[slice.len..], "[info/{s}] {s}", .{ category, slice }, 0);
std.posix.system.syslog(std.posix.LOG.ERR, msg.ptr);
}
+2 -2
View File
@@ -1,7 +1,7 @@
const std = @import("std");
const ErrInt = std.meta.Int(.unsigned, @bitSizeOf(anyerror));
const PaddingInt = std.meta.Int(.unsigned, 8 - (@bitSizeOf(ErrInt) + @bitSizeOf(bool)) % 8);
const ErrInt = @Int(.unsigned, @bitSizeOf(anyerror));
const PaddingInt = @Int(.unsigned, 8 - (@bitSizeOf(ErrInt) + @bitSizeOf(bool)) % 8);
const ErrorHandler = packed struct {
has_error: bool = false,
+4 -4
View File
@@ -376,7 +376,7 @@ pub fn setNumlock(val: bool) !void {
}
pub fn setUserContext(allocator: std.mem.Allocator, entry: UsernameEntry) !void {
const username_z = try allocator.dupeZ(u8, entry.username.?);
const username_z = try allocator.dupeSentinel(u8, entry.username.?, 0);
defer allocator.free(username_z);
return platform_struct.setUserContextImpl(username_z.ptr, entry);
@@ -392,10 +392,10 @@ pub fn setUserShell(entry: *UsernameEntry) void {
}
pub fn setEnvironmentVariable(allocator: std.mem.Allocator, name: []const u8, value: []const u8, replace: bool) !void {
const name_z = try allocator.dupeZ(u8, name);
const name_z = try allocator.dupeSentinel(u8, name, 0);
defer allocator.free(name_z);
const value_z = try allocator.dupeZ(u8, value);
const value_z = try allocator.dupeSentinel(u8, value, 0);
defer allocator.free(value_z);
const status = stdlib.setenv(name_z.ptr, value_z.ptr, @intFromBool(replace));
@@ -422,7 +422,7 @@ pub fn getNextUsernameEntry() ?UsernameEntry {
}
pub fn getUsernameEntry(allocator: std.mem.Allocator, username: []const u8) ?UsernameEntry {
const username_z = allocator.dupeZ(u8, username) catch return null;
const username_z = allocator.dupeSentinel(u8, username, 0) catch return null;
defer allocator.free(username_z);
const entry = pwd.getpwnam(username_z);
+43 -25
View File
@@ -131,13 +131,11 @@ pub fn LuaParser(comptime Struct: type) type {
var arena = std.heap.ArenaAllocator.init(allocator);
const arena_alloc = arena.allocator();
var maybe_load_error: ?anyerror = null;
errdefer |err| maybe_load_error = err;
const data = parseLua(arena_alloc, path) catch load_error: {
break :load_error Struct{};
};
var maybe_load_error: ?anyerror = null;
if (global_errors.items.len != 0) {
maybe_load_error = error.InvalidConfig;
}
@@ -176,8 +174,8 @@ pub fn LuaParser(comptime Struct: type) type {
defer lua.pop(1); // pop ly table
if (ly_type == .nil) return error.MissingLyTable;
inline for (struc.fields) |field| {
try setField(allocator, lua, field, &data);
inline for (struc.field_names, struc.field_types) |name, ftype| {
try setField(allocator, lua, name, ftype, &data);
}
},
else => @compileError("Expected a struct."),
@@ -188,21 +186,47 @@ pub fn LuaParser(comptime Struct: type) type {
return data;
}
pub fn setField(allocator: std.mem.Allocator, lua: *Lua, comptime field: std.builtin.Type.StructField, data: *Struct) !void {
const type_info = @typeInfo(field.type);
pub fn setField(
allocator: std.mem.Allocator,
lua: *Lua,
comptime field_name: [:0]const u8,
field_type: type,
data: *Struct,
) !void {
return setFieldInner(
allocator,
lua,
field_name,
field_type,
data,
) catch |err| {
const value = lua.toString(-1) catch "";
const duped = allocator.dupe(u8, value) catch "";
errorHandler(@typeName(field_type), field_name, duped, err);
};
}
fn setFieldInner(
allocator: std.mem.Allocator,
lua: *Lua,
comptime field_name: [:0]const u8,
field_type: type,
data: *Struct,
) !void {
const type_info = @typeInfo(field_type);
const actual_type, const is_optional = blk: {
if (type_info == .optional) {
break :blk .{ type_info.optional.child, true };
}
break :blk .{ field.type, false };
break :blk .{ field_type, false };
};
// push value to top of stack
_ = lua.getField(-1, field.name);
_ = lua.getField(-1, field_name);
defer lua.pop(1);
// handle null, i.e. undefined fields
if (is_optional and lua.isNil(-1)) {
@field(data, field.name) = null;
@field(data, field_name) = null;
return;
}
@@ -210,17 +234,11 @@ pub fn LuaParser(comptime Struct: type) type {
if (lua.isNil(-1)) return;
const actual_type_info = @typeInfo(actual_type);
errdefer |err| {
const value = lua.toString(-1) catch "";
const duped = allocator.dupe(u8, value) catch "";
errorHandler(@typeName(field.type), field.name, duped, err);
}
// dispatch depending on type
if (actual_type_info == .int and is_optional) {
if (lua.isNumber(-1)) {
const value = try lua.toNumber(-1);
@field(data, field.name) = @trunc(value);
@field(data, field_name) = @trunc(value);
} else {
const str = try lua.toString(-1);
@@ -231,13 +249,13 @@ pub fn LuaParser(comptime Struct: type) type {
if (iter.nextCodepoint() != null) return error.ExpectedSingleCharacter;
@field(data, field.name) = if (codepoint) |cp| @intCast(cp) else null;
@field(data, field_name) = if (codepoint) |cp| @intCast(cp) else null;
}
// non null integer
} else if (actual_type_info == .int) {
if (lua.isNumber(-1)) {
const value = try lua.toNumber(-1);
@field(data, field.name) = @trunc(value);
@field(data, field_name) = @trunc(value);
} else {
const str = try lua.toString(-1);
@@ -248,27 +266,27 @@ pub fn LuaParser(comptime Struct: type) type {
if (iter.nextCodepoint() != null) return error.ExpectedSingleCharacter;
@field(data, field.name) = @intCast(codepoint);
@field(data, field_name) = @intCast(codepoint);
}
} else if (actual_type_info == .float) { // all floats
const value = try lua.toNumber(-1);
@field(data, field.name) = @floatCast(value);
@field(data, field_name) = @floatCast(value);
} else if (actual_type_info == .bool) {
if (!lua.isBoolean(-1)) return error.ExpectedBoolean;
const value = lua.toBoolean(-1);
@field(data, field.name) = value;
@field(data, field_name) = value;
} else if (actual_type == []const u8) {
const value = try lua.toString(-1);
const duped = try allocator.dupe(u8, value);
@field(data, field.name) = duped;
@field(data, field_name) = duped;
} else if (actual_type == [:0]const u8) {
const value = try lua.toString(-1);
const duped = try allocator.dupeSentinel(u8, value, 0);
@field(data, field.name) = duped;
@field(data, field_name) = duped;
} else if (actual_type_info == .@"enum") {
const value = try lua.toString(-1);
const variant = std.meta.stringToEnum(actual_type, value) orelse return error.InvalidVariant;
@field(data, field.name) = variant;
@field(data, field_name) = variant;
} else unreachable;
}