mirror of
https://github.com/ghostty-org/ghostty.git
synced 2026-08-04 06:38:37 +00:00
Update to Zig 0.16.0
This commit represents the majority of the work necessary to upgrade Ghostty to use Zig 0.16.0. Key parts: * In addition to its previous responsibilities, the global state now houses state for global I/O implementations and the process environment. It is now also utilized in the main application along with the C library. Where necessary, global state is isolated from key parts of the implementation (e.g., in libghostty subsystems), and it's expected that this list will grow. * We currently manage our own C translation layer where necessary. In these cases, cImport has been removed in favor of the new external translate-c package. Due to fixes that have needed be made to properly translate the dependencies that were swapped out, as mentioned, we have had to backport fixes from the current translate-c package (and the upstream Arocc dependency). We will host this ourselves until Zig 0.17.0 is released with these fixes. * Where necessary (only a small number of cases), some stdlib code from 0.15.2 (and even from 0.17.0) has been taken, adopted, and vendored in lib/compat. Co-authored-by: Leah Amelia Chen <hi@pluie.me>
This commit is contained in:
@@ -1439,30 +1439,35 @@ pub const Action = union(enum) {
|
||||
const all_fields = @typeInfo(Action).@"union".fields;
|
||||
|
||||
// Find all fields that are app-scoped
|
||||
var i: usize = 0;
|
||||
var union_fields: [all_fields.len]std.builtin.Type.UnionField = undefined;
|
||||
var enum_fields: [all_fields.len]std.builtin.Type.EnumField = undefined;
|
||||
var i: comptime_int = 0;
|
||||
var names: [all_fields.len][]const u8 = undefined;
|
||||
var types: [all_fields.len]type = undefined;
|
||||
var attrs: [all_fields.len]std.builtin.Type.UnionField.Attributes = undefined;
|
||||
var raw_values: [all_fields.len]comptime_int = undefined;
|
||||
|
||||
for (all_fields) |field| {
|
||||
const action = @unionInit(Action, field.name, undefined);
|
||||
if (action.scope() == s) {
|
||||
union_fields[i] = field;
|
||||
enum_fields[i] = .{ .name = field.name, .value = i };
|
||||
names[i] = field.name;
|
||||
types[i] = field.type;
|
||||
attrs[i] = .{ .@"align" = field.alignment };
|
||||
raw_values[i] = i;
|
||||
i += 1;
|
||||
}
|
||||
}
|
||||
|
||||
const TagInt = std.math.IntFittingRange(0, i);
|
||||
var values: [i]TagInt = undefined;
|
||||
for (raw_values[0..i], &values) |raw, *v| v.* = raw;
|
||||
|
||||
// Build our union
|
||||
return @Type(.{ .@"union" = .{
|
||||
.layout = .auto,
|
||||
.tag_type = @Type(.{ .@"enum" = .{
|
||||
.tag_type = std.math.IntFittingRange(0, i),
|
||||
.fields = enum_fields[0..i],
|
||||
.decls = &.{},
|
||||
.is_exhaustive = true,
|
||||
} }),
|
||||
.fields = union_fields[0..i],
|
||||
.decls = &.{},
|
||||
} });
|
||||
return @Union(
|
||||
.auto,
|
||||
@Enum(TagInt, .exhaustive, names[0..i], &values),
|
||||
names[0..i],
|
||||
types[0..i],
|
||||
attrs[0..i],
|
||||
);
|
||||
}
|
||||
|
||||
/// Returns the scoped version of this action. If the action is not
|
||||
|
||||
@@ -352,8 +352,7 @@ pub const Key = enum(c_int) {
|
||||
)) |key| return key;
|
||||
|
||||
// We need to convert FooBar to foo_bar
|
||||
var fbs = std.io.fixedBufferStream(&result);
|
||||
const w = fbs.writer();
|
||||
var w: std.Io.Writer = .fixed(&result);
|
||||
for (code, 0..) |ch, i| switch (ch) {
|
||||
'a'...'z' => w.writeByte(ch) catch return null,
|
||||
|
||||
@@ -367,7 +366,7 @@ pub const Key = enum(c_int) {
|
||||
else => return null,
|
||||
};
|
||||
|
||||
return std.meta.stringToEnum(Key, fbs.getWritten());
|
||||
return std.meta.stringToEnum(Key, w.buffered());
|
||||
}
|
||||
|
||||
/// Converts a Ghostty key enum value to a W3C key code.
|
||||
@@ -379,8 +378,7 @@ pub const Key = enum(c_int) {
|
||||
const name = @tagName(tag);
|
||||
|
||||
var buf: [128]u8 = undefined;
|
||||
var fbs = std.io.fixedBufferStream(&buf);
|
||||
const w = fbs.writer();
|
||||
var w: std.Io.Writer = .fixed(&buf);
|
||||
var i: usize = 0;
|
||||
while (i < name.len) {
|
||||
if (i == 0) {
|
||||
@@ -396,7 +394,7 @@ pub const Key = enum(c_int) {
|
||||
}
|
||||
|
||||
const written = buf;
|
||||
const result = written[0..fbs.getWritten().len];
|
||||
const result = written[0..w.end];
|
||||
break :w3c result;
|
||||
},
|
||||
};
|
||||
|
||||
@@ -368,12 +368,11 @@ pub const RemapSet = struct {
|
||||
const to = entry.value_ptr.*;
|
||||
|
||||
var buf: [64]u8 = undefined;
|
||||
var fbs = std.io.fixedBufferStream(&buf);
|
||||
const writer = fbs.writer();
|
||||
formatMod(writer, from) catch return error.OutOfMemory;
|
||||
var writer: std.Io.Writer = .fixed(&buf);
|
||||
formatMod(&writer, from) catch return error.OutOfMemory;
|
||||
writer.writeByte('=') catch return error.OutOfMemory;
|
||||
formatMod(writer, to) catch return error.OutOfMemory;
|
||||
try formatter.formatEntry([]const u8, fbs.getWritten());
|
||||
formatMod(&writer, to) catch return error.OutOfMemory;
|
||||
try formatter.formatEntry([]const u8, writer.buffered());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user