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

@@ -1,24 +1,20 @@
const std = @import("std");
const ghostty_vt = @import("ghostty-vt");
pub fn main() !void {
var gpa: std.heap.DebugAllocator(.{}) = .init;
defer _ = gpa.deinit();
const alloc = gpa.allocator();
pub fn main(init: std.process.Init) !void {
// Create a terminal
var t: ghostty_vt.Terminal = try .init(alloc, .{ .cols = 150, .rows = 80 });
defer t.deinit(alloc);
var t: ghostty_vt.Terminal = try .init(init.io, init.gpa, .{ .cols = 150, .rows = 80 });
defer t.deinit(init.gpa);
// Create a read-only VT stream for parsing terminal sequences
var stream = t.vtStream();
defer stream.deinit();
// Read from stdin
const stdin = std.fs.File.stdin();
const stdin = std.Io.File.stdin();
var buf: [4096]u8 = undefined;
while (true) {
const n = try stdin.readAll(&buf);
const n = try stdin.readStreaming(init.io, &.{&buf});
if (n == 0) break;
// Replace \n with \r\n
@@ -35,7 +31,7 @@ pub fn main() !void {
});
// Write to stdout
var stdout_writer = std.fs.File.stdout().writer(&buf);
var stdout_writer = std.Io.File.stdout().writer(init.io, &buf);
const stdout = &stdout_writer.interface;
try stdout.print("{f}", .{formatter});
try stdout.flush();

View File

@@ -1,13 +1,9 @@
const std = @import("std");
const ghostty_vt = @import("ghostty-vt");
pub fn main() !void {
var gpa: std.heap.DebugAllocator(.{}) = .init;
defer _ = gpa.deinit();
const alloc = gpa.allocator();
var t: ghostty_vt.Terminal = try .init(alloc, .{ .cols = 80, .rows = 24 });
defer t.deinit(alloc);
pub fn main(init: std.process.Init) !void {
var t: ghostty_vt.Terminal = try .init(init.io, init.gpa, .{ .cols = 80, .rows = 24 });
defer t.deinit(init.gpa);
// Create a read-only VT stream for parsing terminal sequences
var stream = t.vtStream();
@@ -34,7 +30,7 @@ pub fn main() !void {
stream.nextSlice("Line A\r\nLine B\r\nLine C\r\n");
// Get the final terminal state as a plain string
const str = try t.plainString(alloc);
defer alloc.free(str);
const str = try t.plainString(init.gpa);
defer init.gpa.free(str);
std.debug.print("{s}\n", .{str});
}

View File

@@ -1,26 +1,20 @@
const std = @import("std");
const ghostty_vt = @import("ghostty-vt");
pub fn main() !void {
// Use a debug allocator so we get leak checking. You probably want
// to replace this for release builds.
var gpa: std.heap.DebugAllocator(.{}) = .init;
defer _ = gpa.deinit();
const alloc = gpa.allocator();
pub fn main(init: std.process.Init) !void {
// Initialize a terminal.
var t: ghostty_vt.Terminal = try .init(alloc, .{
var t: ghostty_vt.Terminal = try .init(init.io, init.gpa, .{
.cols = 6,
.rows = 40,
});
defer t.deinit(alloc);
defer t.deinit(init.gpa);
// Write some text. It'll wrap because this is too long for our
// columns size above (6).
try t.printString("Hello, World!");
// Get the plain string view of the terminal screen.
const str = try t.plainString(alloc);
defer alloc.free(str);
const str = try t.plainString(init.gpa);
defer init.gpa.free(str);
std.debug.print("{s}\n", .{str});
}