build: gate lib-vt xcframework on emit-xcframework with xcodebuild detection

This commit is contained in:
0xDVC
2026-04-23 17:07:40 +00:00
committed by Mitchell Hashimoto
parent caad13e232
commit 44a2d8740a
3 changed files with 25 additions and 48 deletions

View File

@@ -154,14 +154,8 @@ pub fn build(b: *std.Build) !void {
// libghostty-vt xcframework (Apple only, universal binary).
// Only when building on macOS (not cross-compiling) since
// optional: requires full xcodebuild. keep lib-vt usable on command-line tools
const emit_lib_vt_xcframework = b.option(
bool,
"emit-lib-vt-xcframework",
"Emit libghostty-vt XCFramework (requires xcodebuild/full Xcode).",
) orelse false;
if (config.emit_lib_vt and emit_lib_vt_xcframework and builtin.os.tag.isDarwin() and config.target.result.os.tag.isDarwin()) {
// xcodebuild is required.
if (config.emit_lib_vt and config.emit_xcframework and builtin.os.tag.isDarwin() and config.target.result.os.tag.isDarwin()) {
const apple_libs = try buildpkg.GhosttyLibVt.initStaticAppleUniversal(
b,
&config,
@@ -206,8 +200,9 @@ pub fn build(b: *std.Build) !void {
}
// macOS only artifacts. These will error if they're initialized for
// other targets.
if (config.target.result.os.tag.isDarwin() and
// other targets. In lib-vt mode emit_xcframework controls the lib-vt
// xcframework above, not this one.
if (!config.emit_lib_vt and config.target.result.os.tag.isDarwin() and
(config.emit_xcframework or config.emit_macos_app))
{
// Ghostty xcframework

View File

@@ -1,35 +1,6 @@
// swift-tools-version: 5.9
import Foundation
import PackageDescription
func existingXCFrameworkPath() -> String {
let fm = FileManager.default
let candidates = [
"../../zig-out/lib/ghostty-vt.xcframework",
"../../zig-out/xcframeworks/ghostty-vt.xcframework",
"../../zig-out/ghostty-vt.xcframework",
]
for rel in candidates {
let plist = "\(rel)/Info.plist"
var isDir: ObjCBool = false
if fm.fileExists(atPath: rel, isDirectory: &isDir),
isDir.boolValue,
fm.fileExists(atPath: plist)
{
return rel // important to return relative path
}
}
fatalError(
"""
GhosttyVt XCFramework not found.
Build it first (must produce a valid *.xcframework with Info.plist).
Tried:
\(candidates.joined(separator: "\n"))
""")
}
let package = Package(
name: "swift-vt-xcframework",
platforms: [.macOS(.v13)],
@@ -38,11 +9,13 @@ let package = Package(
name: "swift-vt-xcframework",
dependencies: ["GhosttyVt"],
path: "Sources",
linkerSettings: [.linkedLibrary("c++")]
linkerSettings: [
.linkedLibrary("c++"),
]
),
.binaryTarget(
name: "GhosttyVt",
path: existingXCFrameworkPath()
path: "../../zig-out/lib/ghostty-vt.xcframework"
),
]
)

View File

@@ -444,13 +444,22 @@ pub fn init(b: *std.Build, appVersion: []const u8, libVersion: []const u8) !Conf
bool,
"emit-xcframework",
"Build and install the xcframework for the macOS library.",
) orelse !config.emit_lib_vt and
builtin.target.os.tag.isDarwin() and
target.result.os.tag == .macos and
config.app_runtime == .none and
(!config.emit_bench and
!config.emit_test_exe and
!config.emit_helpgen);
) orelse emit_xcfw: {
if (!builtin.target.os.tag.isDarwin() or target.result.os.tag != .macos)
break :emit_xcfw false;
if (config.emit_lib_vt) {
// In lib-vt mode default to whether xcodebuild is available,
// since xcodebuild is required to produce the XCFramework.
const path = expandPath(b.allocator, "xcodebuild") catch
break :emit_xcfw false;
defer if (path) |p| b.allocator.free(p);
break :emit_xcfw path != null;
}
break :emit_xcfw config.app_runtime == .none and
(!config.emit_bench and
!config.emit_test_exe and
!config.emit_helpgen);
};
config.emit_macos_app = b.option(
bool,