aboutsummaryrefslogtreecommitdiff
path: root/vendor/libghostty-vt/pkg/macos
diff options
context:
space:
mode:
authorCan Celik <ogulcancelik@gmail.com>2026-09-10 21:51:57 +0300
committerGitHub <noreply@github.com>2026-09-10 21:51:57 +0300
commit425c86179791cd32e2d4ce0ae7f269940b4b0663 (patch)
treee52c4383a6d69216cbe2a32638bf90841d7e2189 /vendor/libghostty-vt/pkg/macos
parent90e947a6e26e02f10ec7f1694c4eb5b78a86406b (diff)
chore: upgrade libghostty and preserve terminal behavior (#3906)
Diffstat (limited to 'vendor/libghostty-vt/pkg/macos')
-rw-r--r--vendor/libghostty-vt/pkg/macos/build.zig111
-rw-r--r--vendor/libghostty-vt/pkg/macos/build.zig.zon5
-rw-r--r--vendor/libghostty-vt/pkg/macos/foundation/string.zig6
-rw-r--r--vendor/libghostty-vt/pkg/macos/main.zig20
-rw-r--r--vendor/libghostty-vt/pkg/macos/text/font.zig13
-rw-r--r--vendor/libghostty-vt/pkg/macos/text/typesetter.zig6
-rw-r--r--vendor/libghostty-vt/pkg/macos/video/display_link.zig10
7 files changed, 117 insertions, 54 deletions
diff --git a/vendor/libghostty-vt/pkg/macos/build.zig b/vendor/libghostty-vt/pkg/macos/build.zig
index 0525e481..5569baad 100644
--- a/vendor/libghostty-vt/pkg/macos/build.zig
+++ b/vendor/libghostty-vt/pkg/macos/build.zig
@@ -2,6 +2,66 @@ const std = @import("std");
const builtin = @import("builtin");
const apple_sdk = @import("apple_sdk");
+const Framework = struct {
+ const Tag = enum { all, macos };
+
+ tag: Tag,
+ name: []const u8,
+ headers: []const []const u8,
+};
+
+const frameworks = [_]Framework{
+ .{ .tag = .all, .name = "CoreFoundation", .headers = &.{"CoreFoundation.h"} },
+ .{ .tag = .all, .name = "CoreGraphics", .headers = &.{"CoreGraphics.h"} },
+ .{ .tag = .all, .name = "CoreText", .headers = &.{"CoreText.h"} },
+ .{ .tag = .all, .name = "CoreVideo", .headers = &.{ "CoreVideo.h", "CVPixelBuffer.h" } },
+ .{ .tag = .all, .name = "QuartzCore", .headers = &.{"CALayer.h"} },
+ .{ .tag = .all, .name = "IOSurface", .headers = &.{"IOSurfaceRef.h"} },
+ .{ .tag = .macos, .name = "Carbon", .headers = &.{"Carbon.h"} },
+};
+
+const extra_headers = [_][]const u8{
+ "dispatch/dispatch.h",
+ "os/log.h",
+ "os/signpost.h",
+};
+
+const framework_header_fmt = "#include <{s}/{s}>\n";
+const extra_header_fmt = "#include <{s}>\n";
+
+fn cSourceLen(tag: Framework.Tag) usize {
+ var len: usize = 0;
+ for (frameworks) |framework| {
+ if (tag != .macos and framework.tag == .macos) continue;
+ for (framework.headers) |h| len += std.fmt.count(framework_header_fmt, .{ framework.name, h });
+ }
+ for (extra_headers) |h| len += std.fmt.count(extra_header_fmt, .{h});
+ return len;
+}
+
+fn genCSource(comptime tag: Framework.Tag) [cSourceLen(tag):0]u8 {
+ const len = cSourceLen(tag);
+ var buf: [len:0]u8 = undefined;
+ var writer: std.Io.Writer = .fixed(&buf);
+ for (frameworks) |framework| {
+ if (tag != .macos and framework.tag == .macos) continue;
+ for (framework.headers) |h| writer.print(framework_header_fmt, .{ framework.name, h }) catch unreachable;
+ }
+ for (extra_headers) |h| writer.print(extra_header_fmt, .{h}) catch unreachable;
+ buf[len] = 0;
+ return buf;
+}
+
+const c_source_macos = genCSource(.macos);
+const c_source_other = genCSource(.all);
+
+fn linkFrameworks(tag: Framework.Tag, module: *std.Build.Module) !void {
+ for (frameworks) |framework| {
+ if (tag != .macos and framework.tag == .macos) continue;
+ module.linkFramework(framework.name, .{});
+ }
+}
+
pub fn build(b: *std.Build) !void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
@@ -12,6 +72,29 @@ pub fn build(b: *std.Build) !void {
.optimize = optimize,
});
+ translate: {
+ const translate_c = b.lazyImport(@This(), "translate_c") orelse break :translate;
+ const translate_c_dep = b.lazyDependency("translate_c", .{}) orelse break :translate;
+ const macos_c: translate_c.Translator = .init(translate_c_dep, .{
+ .c_source_file = b.addWriteFiles().add(
+ "macos_c.h",
+ if (target.result.os.tag == .macos) &c_source_macos else &c_source_other,
+ ),
+ .target = target,
+ .optimize = optimize,
+ .libc_file = if (target.result.os.tag.isDarwin()) libc_file: {
+ switch (try apple_sdk.pathsForTarget(b, target.result)) {
+ inline else => |paths| break :libc_file paths.libc,
+ }
+ } else null,
+ });
+
+ // Blocks need to be enabled to use MacOS headers
+ macos_c.run.addArg("-fblocks");
+
+ module.addImport("macos_c", macos_c.mod);
+ }
+
const lib = b.addLibrary(.{
.name = "macos",
.root_module = b.createModule(.{
@@ -21,34 +104,18 @@ pub fn build(b: *std.Build) !void {
.linkage = .static,
});
- lib.addCSourceFile(.{
+ lib.root_module.addCSourceFile(.{
.file = b.path("os/zig_macos.c"),
.flags = &.{"-std=c99"},
});
- lib.addCSourceFile(.{
+ lib.root_module.addCSourceFile(.{
.file = b.path("text/ext.c"),
});
- lib.linkFramework("CoreFoundation");
- lib.linkFramework("CoreGraphics");
- lib.linkFramework("CoreText");
- lib.linkFramework("CoreVideo");
- lib.linkFramework("QuartzCore");
- lib.linkFramework("IOSurface");
- if (target.result.os.tag == .macos) {
- lib.linkFramework("Carbon");
- module.linkFramework("Carbon", .{});
- }
-
- if (target.result.os.tag.isDarwin()) {
- module.linkFramework("CoreFoundation", .{});
- module.linkFramework("CoreGraphics", .{});
- module.linkFramework("CoreText", .{});
- module.linkFramework("CoreVideo", .{});
- module.linkFramework("QuartzCore", .{});
- module.linkFramework("IOSurface", .{});
- try apple_sdk.addPaths(b, lib);
+ inline for (.{ lib.root_module, module }) |mod| {
+ try linkFrameworks(if (target.result.os.tag == .macos) .macos else .all, mod);
}
+ try apple_sdk.addPaths(b, lib);
b.installArtifact(lib);
{
@@ -63,7 +130,7 @@ pub fn build(b: *std.Build) !void {
if (target.result.os.tag.isDarwin()) {
try apple_sdk.addPaths(b, test_exe);
}
- test_exe.linkLibrary(lib);
+ test_exe.root_module.linkLibrary(lib);
var it = module.import_table.iterator();
while (it.next()) |entry| {
diff --git a/vendor/libghostty-vt/pkg/macos/build.zig.zon b/vendor/libghostty-vt/pkg/macos/build.zig.zon
index 4c22ad7c..f70cb802 100644
--- a/vendor/libghostty-vt/pkg/macos/build.zig.zon
+++ b/vendor/libghostty-vt/pkg/macos/build.zig.zon
@@ -5,5 +5,10 @@
.paths = .{""},
.dependencies = .{
.apple_sdk = .{ .path = "../apple-sdk" },
+ .translate_c = .{
+ .url = "https://codeberg.org/vancluever/translate-c/archive/4e879eb8aba615de112eabd1231ea6e01920cead.tar.gz",
+ .hash = "translate_c-0.0.0-Q_BUWhVNBwDOEcIqub4VFPJPB6D9dgwzUMHTX5KWr8Xr",
+ .lazy = true,
+ },
},
}
diff --git a/vendor/libghostty-vt/pkg/macos/foundation/string.zig b/vendor/libghostty-vt/pkg/macos/foundation/string.zig
index 2f679fef..3d1c5c05 100644
--- a/vendor/libghostty-vt/pkg/macos/foundation/string.zig
+++ b/vendor/libghostty-vt/pkg/macos/foundation/string.zig
@@ -21,13 +21,13 @@ pub const String = opaque {
pub fn createWithCharactersNoCopy(
unichars: []const u16,
- ) *String {
- return @as(*String, @ptrFromInt(@intFromPtr(c.CFStringCreateWithCharactersNoCopy(
+ ) Allocator.Error!*String {
+ return @ptrCast(@constCast(c.CFStringCreateWithCharactersNoCopy(
null,
@ptrCast(unichars.ptr),
@intCast(unichars.len),
foundation.c.kCFAllocatorNull,
- ))));
+ ) orelse return error.OutOfMemory));
}
pub fn release(self: *String) void {
diff --git a/vendor/libghostty-vt/pkg/macos/main.zig b/vendor/libghostty-vt/pkg/macos/main.zig
index e4f4b950..68d61567 100644
--- a/vendor/libghostty-vt/pkg/macos/main.zig
+++ b/vendor/libghostty-vt/pkg/macos/main.zig
@@ -10,25 +10,7 @@ pub const text = @import("text.zig");
pub const video = @import("video.zig");
pub const iosurface = @import("iosurface.zig");
-// All of our C imports consolidated into one place. We used to
-// import them one by one in each package but Zig 0.14 has some
-// kind of issue with that I wasn't able to minimize.
-pub const c = @cImport({
- @cInclude("CoreFoundation/CoreFoundation.h");
- @cInclude("CoreGraphics/CoreGraphics.h");
- @cInclude("CoreText/CoreText.h");
- @cInclude("CoreVideo/CoreVideo.h");
- @cInclude("CoreVideo/CVPixelBuffer.h");
- @cInclude("QuartzCore/CALayer.h");
- @cInclude("IOSurface/IOSurfaceRef.h");
- @cInclude("dispatch/dispatch.h");
- @cInclude("os/log.h");
- @cInclude("os/signpost.h");
-
- if (builtin.os.tag == .macos) {
- @cInclude("Carbon/Carbon.h");
- }
-});
+pub const c = @import("macos_c");
test {
@import("std").testing.refAllDecls(@This());
diff --git a/vendor/libghostty-vt/pkg/macos/text/font.zig b/vendor/libghostty-vt/pkg/macos/text/font.zig
index ea37891f..626b9089 100644
--- a/vendor/libghostty-vt/pkg/macos/text/font.zig
+++ b/vendor/libghostty-vt/pkg/macos/text/font.zig
@@ -18,6 +18,17 @@ pub const Font = opaque {
) orelse Allocator.Error.OutOfMemory;
}
+ pub fn createWithName(name: *foundation.String, size: f32) Allocator.Error!*Font {
+ return @as(
+ ?*Font,
+ @ptrFromInt(@intFromPtr(c.CTFontCreateWithName(
+ @ptrCast(name),
+ size,
+ null,
+ ))),
+ ) orelse Allocator.Error.OutOfMemory;
+ }
+
pub fn createForString(
self: *Font,
str: *foundation.String,
@@ -156,7 +167,7 @@ pub const Font = opaque {
return @ptrFromInt(@intFromPtr(c.CTFontCopyFamilyName(@ptrCast(self))));
}
- pub fn copyDisplayName(self: *Font) *foundation.String {
+ pub fn copyDisplayName(self: *Font) ?*foundation.String {
return @ptrFromInt(@intFromPtr(c.CTFontCopyDisplayName(@ptrCast(self))));
}
diff --git a/vendor/libghostty-vt/pkg/macos/text/typesetter.zig b/vendor/libghostty-vt/pkg/macos/text/typesetter.zig
index dc07df98..16cd7816 100644
--- a/vendor/libghostty-vt/pkg/macos/text/typesetter.zig
+++ b/vendor/libghostty-vt/pkg/macos/text/typesetter.zig
@@ -27,10 +27,10 @@ pub const Typesetter = opaque {
pub fn createLine(
self: *Typesetter,
range: foundation.c.CFRange,
- ) *text.Line {
- return @ptrFromInt(@intFromPtr(c.CTTypesetterCreateLine(
+ ) Allocator.Error!*text.Line {
+ return @ptrCast(@constCast(c.CTTypesetterCreateLine(
@ptrCast(self),
range,
- )));
+ ) orelse return error.OutOfMemory));
}
};
diff --git a/vendor/libghostty-vt/pkg/macos/video/display_link.zig b/vendor/libghostty-vt/pkg/macos/video/display_link.zig
index 7d6b437f..dc984422 100644
--- a/vendor/libghostty-vt/pkg/macos/video/display_link.zig
+++ b/vendor/libghostty-vt/pkg/macos/video/display_link.zig
@@ -1,21 +1,19 @@
-const std = @import("std");
-const assert = std.debug.assert;
-const Allocator = std.mem.Allocator;
const c = @import("c.zig").c;
pub const DisplayLink = opaque {
pub const Error = error{
+ CreationFailed,
InvalidOperation,
};
- pub fn createWithActiveCGDisplays() Allocator.Error!*DisplayLink {
+ pub fn createWithActiveCGDisplays() Error!*DisplayLink {
var result: ?*DisplayLink = null;
if (c.CVDisplayLinkCreateWithActiveCGDisplays(
@ptrCast(&result),
) != c.kCVReturnSuccess)
- return error.OutOfMemory;
+ return error.CreationFailed;
- return result orelse error.OutOfMemory;
+ return result orelse error.CreationFailed;
}
pub fn release(self: *DisplayLink) void {