build: zig build run only builds xcframework for current arch

This commit is contained in:
Mitchell Hashimoto
2025-07-04 14:56:21 -07:00
parent fb9c52ecf4
commit 3793dac313
3 changed files with 74 additions and 25 deletions

View File

@@ -7,11 +7,23 @@ const GhosttyLib = @import("GhosttyLib.zig");
const XCFrameworkStep = @import("XCFrameworkStep.zig");
xcframework: *XCFrameworkStep,
macos: GhosttyLib,
target: Target,
pub fn init(b: *std.Build, deps: *const SharedDeps) !GhosttyXCFramework {
// Create our universal macOS static library.
const macos = try GhosttyLib.initMacOSUniversal(b, deps);
pub const Target = enum { native, universal };
pub fn init(
b: *std.Build,
deps: *const SharedDeps,
target: Target,
) !GhosttyXCFramework {
// Universal macOS build
const macos_universal = try GhosttyLib.initMacOSUniversal(b, deps);
// Native macOS build
const macos_native = try GhosttyLib.initStatic(b, &try deps.retarget(
b,
Config.genericMacOSTarget(b, null),
));
// iOS
const ios = try GhosttyLib.initStatic(b, &try deps.retarget(
@@ -47,25 +59,32 @@ pub fn init(b: *std.Build, deps: *const SharedDeps) !GhosttyXCFramework {
const xcframework = XCFrameworkStep.create(b, .{
.name = "GhosttyKit",
.out_path = "macos/GhosttyKit.xcframework",
.libraries = &.{
.{
.library = macos.output,
.headers = b.path("include"),
.libraries = switch (target) {
.universal => &.{
.{
.library = macos_universal.output,
.headers = b.path("include"),
},
.{
.library = ios.output,
.headers = b.path("include"),
},
.{
.library = ios_sim.output,
.headers = b.path("include"),
},
},
.{
.library = ios.output,
.native => &.{.{
.library = macos_native.output,
.headers = b.path("include"),
},
.{
.library = ios_sim.output,
.headers = b.path("include"),
},
}},
},
});
return .{
.xcframework = xcframework,
.macos = macos,
.target = target,
};
}

View File

@@ -1,6 +1,7 @@
const Ghostty = @This();
const std = @import("std");
const builtin = @import("builtin");
const RunStep = std.Build.Step.Run;
const Config = @import("Config.zig");
const XCFramework = @import("GhosttyXCFramework.zig");
@@ -40,6 +41,23 @@ pub fn init(
xc_config,
});
switch (xcframework.target) {
// Universal is our default target, so we don't have to
// add anything.
.universal => {},
// Native we need to override the architecture in the Xcode
// project with the -arch flag.
.native => build.addArgs(&.{
"-arch",
switch (builtin.cpu.arch) {
.aarch64 => "arm64",
.x86_64 => "x86_64",
else => @panic("unsupported macOS arch"),
},
}),
}
// We need the xcframework
build.step.dependOn(xcframework.xcframework.step);