all: upgrade to zig 0.17

This commit is contained in:
Loïc Grégoire
2026-10-03 17:00:13 -04:00
parent a49a738d69
commit 10c6c3d27f
6 changed files with 126 additions and 38 deletions
+2 -2
View File
@@ -13,8 +13,8 @@
.hash = "N-V-__8AAAAAjAwsopZIlbp4U6NN1Eh573uVdLTwl1mkFUug", .hash = "N-V-__8AAAAAjAwsopZIlbp4U6NN1Eh573uVdLTwl1mkFUug",
}, },
.zonfig = .{ .zonfig = .{
.url = "git+https://github.com/rdmsr/zonfig?ref=HEAD#ee612592ba79d99da3ddf715ffec1414f72609ca", .url = "git+https://github.com/rdmsr/zonfig?ref=HEAD#7cb4e030077acbef88458aef2d3fec4331b3b6da",
.hash = "zonfig-0.1.0-V0D8-WQ4AQAW5RNFJPxDNIpI7KB7eGPx0MlzGDM6HFbK", .hash = "zonfig-0.1.0-V0D8-aRMFAAQ3Yb-0u8JNpdceK6lUOWUP7EY5BRXz12C",
}, },
}, },
+1 -1
View File
@@ -3,7 +3,7 @@ const std = @import("std");
const Arch = std.Target.Cpu.Arch; const Arch = std.Target.Cpu.Arch;
fn addLimineTool(b: *std.Build, limine: *std.Build.Dependency) *std.Build.Step.Compile { fn addLimineTool(b: *std.Build, limine: *std.Build.Dependency) *std.Build.Step.Compile {
const tool = b.addExecutable(.{ .name = "limine", .root_module = b.addModule("limine", .{ const tool = b.addExecutable(.{ .name = "limine", .root_module = b.createModule(.{
.target = b.graph.host, .target = b.graph.host,
.link_libc = true, .link_libc = true,
}) }); }) });
+4 -2
View File
@@ -711,8 +711,10 @@ pub const Idtr = extern struct {
pub fn sidtr() Idtr { pub fn sidtr() Idtr {
var idtr: Idtr = undefined; var idtr: Idtr = undefined;
asm volatile ("sidt %[idtr]"
: [idtr] "={memory}" (idtr), asm volatile ("sidt %[p]"
:
: [p] "*p" (&idtr.limit),
); );
return idtr; return idtr;
} }
+4 -4
View File
@@ -71,10 +71,10 @@ fn apply_num(
const sign = @typeInfo(ValueT).int.signedness; const sign = @typeInfo(ValueT).int.signedness;
_ = switch (info.bits) { _ = switch (info.bits) {
8 => store_int(std.meta.Int(sign, 8), entry.address, value), 8 => store_int(@Int(sign, 8), entry.address, value),
16 => store_int(std.meta.Int(sign, 16), entry.address, value), 16 => store_int(@Int(sign, 16), entry.address, value),
32 => store_int(std.meta.Int(sign, 32), entry.address, value), 32 => store_int(@Int(sign, 32), entry.address, value),
64 => store_int(std.meta.Int(sign, 64), entry.address, value), 64 => store_int(@Int(sign, 64), entry.address, value),
else => unreachable, else => unreachable,
}; };
} }
+2 -2
View File
@@ -23,7 +23,7 @@ fn reclaim_state(obj: *anyopaque, _: ?*anyopaque) void {
const state: *ke.ShootdownState = @fieldParentPtr("link", link); const state: *ke.ShootdownState = @fieldParentPtr("link", link);
const space: *mm.Space = @ptrFromInt(state.payload[0]); const space: *mm.Space = @ptrFromInt(state.payload[0]);
const pfn_list: mmp.PfnList = @bitCast(state.payload[1]); const pfn_list: *mmp.PfnList = @ptrCast(&state.payload[1]);
const base = state.base; const base = state.base;
const npages = state.npages; const npages = state.npages;
@@ -70,7 +70,7 @@ pub fn reclaim_range(space: *mm.Space, va: r.VAddr, size: usize) void {
.state = .init(0), .state = .init(0),
.payload = .{ .payload = .{
@intFromPtr(space), @intFromPtr(space),
@bitCast(list), @as(*const usize, @ptrCast(@alignCast(&list))).*,
}, },
}; };
+113 -27
View File
@@ -18,30 +18,60 @@ pub const HandoffList = @import("handoff.zig").HandoffList;
pub const LinkerSet = @import("linker_set.zig").LinkerSet; pub const LinkerSet = @import("linker_set.zig").LinkerSet;
pub const CachePadded = @import("cache_padded.zig").CachePadded; pub const CachePadded = @import("cache_padded.zig").CachePadded;
pub fn comptime_error(comptime msg: []const u8, args: anytype) void {
@compileError(std.fmt.comptimePrint(msg, args));
}
/// Asserts that a given type `T` matches the schema declared by `I`. /// Asserts that a given type `T` matches the schema declared by `I`.
/// This includes public methods and fields. /// This includes public methods and fields.
pub fn assert_interface(T: type, I: type) void { pub fn assert_interface(T: type, I: type) void {
const tinfo = @typeInfo(I); const tinfo = @typeInfo(I);
inline for (tinfo.@"struct".fields) |f| { const info = tinfo.@"struct";
if (!@hasField(T, f.name)) {
@compileError(std.fmt.comptimePrint("Expected field '{s}' of type '{s}' in type '{s}' required by '{s}'", .{ f.name, @typeName(f.type), @typeName(T), @typeName(I) })); inline for (info.field_names, info.field_types) |name, t| {
if (!@hasField(T, name)) {
comptime_error(
"Expected field '{s}' of type '{s}' in type '{s}' required by '{s}'",
.{
name,
@typeName(t),
@typeName(T),
@typeName(I),
},
);
} else { } else {
if (@FieldType(T, f.name) != f.type) { if (@FieldType(T, name) != t) {
@compileError(std.fmt.comptimePrint("Expected field '{s}' of type '{s}' in type '{s}' required by '{s}', got '{s}'", .{ f.name, @typeName(f.type), @typeName(T), @typeName(I), @typeName(@FieldType(T, f.name)) })); comptime_error(
"Expected field '{s}' of type '{s}' in type '{s}' required by '{s}', got '{s}'",
.{
name,
@typeName(t),
@typeName(T),
@typeName(I),
@typeName(@FieldType(T, name)),
},
);
} }
} }
} }
inline for (tinfo.@"struct".decls) |decl| { inline for (tinfo.@"struct".decl_names) |decl| {
const member = @field(I, decl.name); const member = @field(I, decl);
if (@typeInfo(@TypeOf(member)) == .@"fn") { if (@typeInfo(@TypeOf(member)) == .@"fn") {
if (!@hasDecl(T, decl.name)) { if (!@hasDecl(T, decl)) {
@compileError(std.fmt.comptimePrint("Expected method '{s}' in type '{s}' required by '{s}'", .{ decl.name, @typeName(T), @typeName(I) })); comptime_error(
"Expected method '{s}' in type '{s}' required by '{s}'",
.{
decl,
@typeName(T),
@typeName(I),
},
);
} }
const impl_member = @field(T, decl.name); const impl_member = @field(T, decl);
const IfaceFnType = @TypeOf(member); const IfaceFnType = @TypeOf(member);
const ImplFnType = @TypeOf(impl_member); const ImplFnType = @TypeOf(impl_member);
@@ -49,36 +79,88 @@ pub fn assert_interface(T: type, I: type) void {
const iface_fn = @typeInfo(IfaceFnType).@"fn"; const iface_fn = @typeInfo(IfaceFnType).@"fn";
const impl_fn = @typeInfo(ImplFnType).@"fn"; const impl_fn = @typeInfo(ImplFnType).@"fn";
if (iface_fn.params.len != impl_fn.params.len) { if (iface_fn.param_types.len != impl_fn.param_types.len) {
@compileError(std.fmt.comptimePrint("Parameter count mismatch in method '{s}' in type '{s}' required by '{s}'", .{ decl.name, @typeName(T), @typeName(I) })); comptime_error(
"Parameter count mismatch in method '{s}' in type '{s}' required by '{s}'",
.{
decl,
@typeName(T),
@typeName(I),
},
);
} }
if (iface_fn.return_type != impl_fn.return_type) { if (iface_fn.return_type != impl_fn.return_type) {
@compileError(std.fmt.comptimePrint("Return type mismatch in method '{s}' in type '{s}' required by '{s}'", .{ decl.name, @typeName(T), @typeName(I) })); comptime_error(
"Return type mismatch in method '{s}' in type '{s}' required by '{s}'",
.{
decl,
@typeName(T),
@typeName(I),
},
);
} }
for (0..iface_fn.params.len) |i| { for (iface_fn.param_types, impl_fn.param_types) |a, b| {
if (iface_fn.params[i].type != impl_fn.params[i].type) { if (a != b) {
@compileError(std.fmt.comptimePrint("Parameter type mismatch in method '{s}' in type '{s}' required by '{s}'", .{ decl.name, @typeName(T), @typeName(I) })); comptime_error(
"Parameter type mismatch in method '{s}' in type '{s}' required by '{s}'",
.{
decl,
@typeName(T),
@typeName(I),
},
);
} }
} }
} }
} else if (@TypeOf(member) == type) { } else if (@TypeOf(member) == type) {
if (!@hasDecl(T, decl.name)) { if (!@hasDecl(T, decl)) {
@compileError(std.fmt.comptimePrint("Expected type declaration '{s}' in type '{s}' required by '{s}'", .{ decl.name, @typeName(T), @typeName(I) })); comptime_error(
"Expected type declaration '{s}' in type '{s}' required by '{s}'",
.{
decl,
@typeName(T),
@typeName(I),
},
);
} }
const impl_member = @field(T, decl.name); const impl_member = @field(T, decl);
if (@TypeOf(impl_member) != type) { if (@TypeOf(impl_member) != type) {
@compileError(std.fmt.comptimePrint("Declaration '{s}' in type '{s}' is required to be a type by '{s}', but got '{s}'", .{ decl.name, @typeName(T), @typeName(I), @typeName(@TypeOf(impl_member)) })); comptime_error(
"Declaration '{s}' in type '{s}' is required to be a type by '{s}', but got '{s}'",
.{
decl,
@typeName(T),
@typeName(I),
@typeName(@TypeOf(impl_member)),
},
);
} }
} else { } else {
if (!@hasDecl(T, decl.name)) { if (!@hasDecl(T, decl)) {
@compileError(std.fmt.comptimePrint("Expected variable declaration '{s}' in type '{s}' required by '{s}'", .{ decl.name, @typeName(T), @typeName(I) })); comptime_error(
"Expected variable declaration '{s}' in type '{s}' required by '{s}'",
.{
decl,
@typeName(T),
@typeName(I),
},
);
} }
const impl_member = @field(T, decl.name); const impl_member = @field(T, decl);
if (@TypeOf(impl_member) != @TypeOf(member)) { if (@TypeOf(impl_member) != @TypeOf(member)) {
@compileError(std.fmt.comptimePrint("Declaration '{s}' in type '{s}' is required to be a variable of type '{s}' by '{s}', but got '{s}'", .{ decl.name, @typeName(T), @typeName(@TypeOf(member)), @typeName(I), @typeName(@TypeOf(impl_member)) })); comptime_error(
"Declaration '{s}' in type '{s}' is required to be a variable of type '{s}' by '{s}', but got '{s}'",
.{
decl,
@typeName(T),
@typeName(@TypeOf(member)),
@typeName(I),
@typeName(@TypeOf(impl_member)),
},
);
} }
} }
} }
@@ -89,9 +171,13 @@ pub fn assert(condition: bool, comptime msg: []const u8, args: anytype) void {
@branchHint(.unlikely); @branchHint(.unlikely);
switch (@import("builtin").mode) { switch (@import("builtin").mode) {
.ReleaseFast, .ReleaseSmall => unreachable, .fast, .small => unreachable,
.Debug, .ReleaseSafe => { .debug, .safe => {
std.debug.panicExtra(@returnAddress(), "Assertion failed: " ++ msg, args); std.debug.panicExtra(
@returnAddress(),
"Assertion failed: " ++ msg,
args,
);
}, },
} }
} }