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:
Chris Marchesi
2026-05-07 09:11:14 -07:00
parent 74d0c72fd9
commit e8525c0fd9
357 changed files with 8958 additions and 6098 deletions

View File

@@ -36,13 +36,14 @@ all: std.EnumMap(Key, *Screen),
generations: std.EnumMap(Key, usize),
pub fn init(
io: std.Io,
alloc: Allocator,
opts: Screen.Options,
) Allocator.Error!ScreenSet {
// We need to initialize our initial primary screen
const screen = try alloc.create(Screen);
errdefer alloc.destroy(screen);
screen.* = try .init(alloc, opts);
screen.* = try .init(io, alloc, opts);
return .{
.active_key = .primary,
.active = screen,
@@ -73,6 +74,7 @@ pub fn generation(self: *const ScreenSet, key: Key) usize {
/// Get the screen for the given key, initializing it if necessary.
pub fn getInit(
self: *ScreenSet,
io: std.Io,
alloc: Allocator,
key: Key,
opts: Screen.Options,
@@ -80,7 +82,7 @@ pub fn getInit(
if (self.get(key)) |screen| return screen;
const screen = try alloc.create(Screen);
errdefer alloc.destroy(screen);
screen.* = try .init(alloc, opts);
screen.* = try .init(io, alloc, opts);
self.all.put(key, screen);
return screen;
}
@@ -108,14 +110,15 @@ pub fn switchTo(self: *ScreenSet, key: Key) void {
test ScreenSet {
const alloc = testing.allocator;
var set: ScreenSet = try .init(alloc, .default);
const io = testing.io;
var set: ScreenSet = try .init(io, alloc, .default);
defer set.deinit(alloc);
try testing.expectEqual(.primary, set.active_key);
try testing.expectEqual(@as(usize, 0), set.generation(.primary));
try testing.expectEqual(@as(usize, 0), set.generation(.alternate));
// Initialize a secondary screen
_ = try set.getInit(alloc, .alternate, .default);
_ = try set.getInit(io, alloc, .alternate, .default);
try testing.expectEqual(@as(usize, 0), set.generation(.alternate));
set.switchTo(.alternate);
@@ -124,7 +127,8 @@ test ScreenSet {
test "ScreenSet generations" {
const alloc = testing.allocator;
var set: ScreenSet = try .init(alloc, .default);
const io = testing.io;
var set: ScreenSet = try .init(io, alloc, .default);
defer set.deinit(alloc);
try testing.expectEqual(@as(usize, 0), set.generation(.primary));
@@ -135,7 +139,7 @@ test "ScreenSet generations" {
try testing.expectEqual(@as(usize, 0), set.generation(.alternate));
// Initializing a screen doesn't change the generation.
_ = try set.getInit(alloc, .alternate, .default);
_ = try set.getInit(io, alloc, .alternate, .default);
try testing.expectEqual(@as(usize, 0), set.generation(.alternate));
const alternate_generation = set.generation(.alternate);
@@ -144,7 +148,7 @@ test "ScreenSet generations" {
// Reinitializing keeps the generation from the last removal, so stale
// handles can distinguish the new screen from the destroyed screen.
_ = try set.getInit(alloc, .alternate, .default);
_ = try set.getInit(io, alloc, .alternate, .default);
try testing.expectEqual(alternate_generation +% 1, set.generation(.alternate));
try testing.expectEqual(@as(usize, 0), set.generation(.primary));
}