summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--build.zig30
-rw-r--r--src/build/GhosttyXCFramework.zig51
-rw-r--r--src/build/GhosttyXcodebuild.zig18
3 files changed, 74 insertions, 25 deletions
diff --git a/build.zig b/build.zig
index 4bd6e0b46..d72bdc28c 100644
--- a/build.zig
+++ b/build.zig
@@ -95,7 +95,11 @@ pub fn build(b: *std.Build) !void {
if (!config.emit_xcframework) break :none;
// Build the xcframework
- const xcframework = try buildpkg.GhosttyXCFramework.init(b, &deps);
+ const xcframework = try buildpkg.GhosttyXCFramework.init(
+ b,
+ &deps,
+ .universal,
+ );
xcframework.install();
// The xcframework build always installs resources because our
@@ -113,15 +117,23 @@ pub fn build(b: *std.Build) !void {
}
// Build our macOS app
- const app = try buildpkg.GhosttyXcodebuild.init(
- b,
- &config,
- &xcframework,
- );
+ {
+ const xcframework_native = try buildpkg.GhosttyXCFramework.init(
+ b,
+ &deps,
+ .native,
+ );
+
+ const app = try buildpkg.GhosttyXcodebuild.init(
+ b,
+ &config,
+ &xcframework_native,
+ );
- // Add a run command that opens our mac app.
- const run_step = b.step("run", "Run the app");
- run_step.dependOn(&app.open.step);
+ // Add a run command that opens our mac app.
+ const run_step = b.step("run", "Run the app");
+ run_step.dependOn(&app.open.step);
+ }
}
// Tests
diff --git a/src/build/GhosttyXCFramework.zig b/src/build/GhosttyXCFramework.zig
index 0dc4f5762..707d5e4e2 100644
--- a/src/build/GhosttyXCFramework.zig
+++ b/src/build/GhosttyXCFramework.zig
@@ -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,
- .headers = b.path("include"),
- },
- .{
- .library = ios_sim.output,
+
+ .native => &.{.{
+ .library = macos_native.output,
.headers = b.path("include"),
- },
+ }},
},
});
return .{
.xcframework = xcframework,
- .macos = macos,
+ .target = target,
};
}
diff --git a/src/build/GhosttyXcodebuild.zig b/src/build/GhosttyXcodebuild.zig
index 83ab0aed3..8ed067b6b 100644
--- a/src/build/GhosttyXcodebuild.zig
+++ b/src/build/GhosttyXcodebuild.zig
@@ -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);