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

@ -95,7 +95,11 @@ pub fn build(b: *std.Build) !void {
if (!config.emit_xcframework) break :none; if (!config.emit_xcframework) break :none;
// Build the xcframework // Build the xcframework
const xcframework = try buildpkg.GhosttyXCFramework.init(b, &deps); const xcframework = try buildpkg.GhosttyXCFramework.init(
b,
&deps,
.universal,
);
xcframework.install(); xcframework.install();
// The xcframework build always installs resources because our // The xcframework build always installs resources because our
@ -113,16 +117,24 @@ pub fn build(b: *std.Build) !void {
} }
// Build our macOS app // Build our macOS app
{
const xcframework_native = try buildpkg.GhosttyXCFramework.init(
b,
&deps,
.native,
);
const app = try buildpkg.GhosttyXcodebuild.init( const app = try buildpkg.GhosttyXcodebuild.init(
b, b,
&config, &config,
&xcframework, &xcframework_native,
); );
// Add a run command that opens our mac app. // Add a run command that opens our mac app.
const run_step = b.step("run", "Run the app"); const run_step = b.step("run", "Run the app");
run_step.dependOn(&app.open.step); run_step.dependOn(&app.open.step);
} }
}
// Tests // Tests
{ {

View File

@ -7,11 +7,23 @@ const GhosttyLib = @import("GhosttyLib.zig");
const XCFrameworkStep = @import("XCFrameworkStep.zig"); const XCFrameworkStep = @import("XCFrameworkStep.zig");
xcframework: *XCFrameworkStep, xcframework: *XCFrameworkStep,
macos: GhosttyLib, target: Target,
pub fn init(b: *std.Build, deps: *const SharedDeps) !GhosttyXCFramework { pub const Target = enum { native, universal };
// Create our universal macOS static library.
const macos = try GhosttyLib.initMacOSUniversal(b, deps); 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 // iOS
const ios = try GhosttyLib.initStatic(b, &try deps.retarget( const ios = try GhosttyLib.initStatic(b, &try deps.retarget(
@ -47,9 +59,10 @@ pub fn init(b: *std.Build, deps: *const SharedDeps) !GhosttyXCFramework {
const xcframework = XCFrameworkStep.create(b, .{ const xcframework = XCFrameworkStep.create(b, .{
.name = "GhosttyKit", .name = "GhosttyKit",
.out_path = "macos/GhosttyKit.xcframework", .out_path = "macos/GhosttyKit.xcframework",
.libraries = &.{ .libraries = switch (target) {
.universal => &.{
.{ .{
.library = macos.output, .library = macos_universal.output,
.headers = b.path("include"), .headers = b.path("include"),
}, },
.{ .{
@ -61,11 +74,17 @@ pub fn init(b: *std.Build, deps: *const SharedDeps) !GhosttyXCFramework {
.headers = b.path("include"), .headers = b.path("include"),
}, },
}, },
.native => &.{.{
.library = macos_native.output,
.headers = b.path("include"),
}},
},
}); });
return .{ return .{
.xcframework = xcframework, .xcframework = xcframework,
.macos = macos, .target = target,
}; };
} }

View File

@ -1,6 +1,7 @@
const Ghostty = @This(); const Ghostty = @This();
const std = @import("std"); const std = @import("std");
const builtin = @import("builtin");
const RunStep = std.Build.Step.Run; const RunStep = std.Build.Step.Run;
const Config = @import("Config.zig"); const Config = @import("Config.zig");
const XCFramework = @import("GhosttyXCFramework.zig"); const XCFramework = @import("GhosttyXCFramework.zig");
@ -40,6 +41,23 @@ pub fn init(
xc_config, 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 // We need the xcframework
build.step.dependOn(xcframework.xcframework.step); build.step.dependOn(xcframework.xcframework.step);