Skip to content

Commit 5fc0bbc

Browse files
committed
build: add -Demit-macos-app
1 parent 91ee75a commit 5fc0bbc

File tree

3 files changed

+95
-64
lines changed

3 files changed

+95
-64
lines changed

build.zig

Lines changed: 82 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,22 @@ pub fn build(b: *std.Build) !void {
2323

2424
// Ghostty docs
2525
const docs = try buildpkg.GhosttyDocs.init(b, &deps);
26-
if (config.emit_docs) docs.install();
26+
if (config.emit_docs) {
27+
docs.install();
28+
} else if (config.target.result.os.tag.isDarwin()) {
29+
// If we aren't emitting docs we need to emit a placeholder so
30+
// our macOS xcodeproject builds since it expects the `share/man`
31+
// directory to exist to copy into the app bundle.
32+
var wf = b.addWriteFiles();
33+
const path = "share/man/.placeholder";
34+
b.getInstallStep().dependOn(&b.addInstallFile(
35+
wf.add(
36+
path,
37+
"emit-docs not true so no man pages",
38+
),
39+
path,
40+
).step);
41+
}
2742

2843
// Ghostty webdata
2944
const webdata = try buildpkg.GhosttyWebdata.init(b, &deps);
@@ -43,15 +58,70 @@ pub fn build(b: *std.Build) !void {
4358
check_step.dependOn(dist.install_step);
4459
}
4560

46-
// If we're not building libghostty, then install the exe and resources.
61+
// libghostty
62+
const libghostty_shared = try buildpkg.GhosttyLib.initShared(
63+
b,
64+
&deps,
65+
);
66+
const libghostty_static = try buildpkg.GhosttyLib.initStatic(
67+
b,
68+
&deps,
69+
);
70+
71+
// Runtime "none" is libghostty, anything else is an executable.
4772
if (config.app_runtime != .none) {
4873
exe.install();
4974
resources.install();
5075
i18n.install();
76+
} else {
77+
// Libghostty
78+
//
79+
// Note: libghostty is not stable for general purpose use. It is used
80+
// heavily by Ghostty on macOS but it isn't built to be reusable yet.
81+
// As such, these build steps are lacking. For example, the Darwin
82+
// build only produces an xcframework.
83+
84+
// We shouldn't have this guard but we don't currently
85+
// build on macOS this way ironically so we need to fix that.
86+
if (!config.target.result.os.tag.isDarwin()) {
87+
libghostty_shared.installHeader(); // Only need one header
88+
libghostty_shared.install("libghostty.so");
89+
libghostty_static.install("libghostty.a");
90+
}
91+
}
5192

52-
// Run runs the Ghostty exe. We only do this if we are building
53-
// an apprt.
54-
{
93+
// macOS only artifacts. These will error if they're initialized for
94+
// other targets.
95+
if (config.target.result.os.tag.isDarwin()) {
96+
// Ghostty xcframework
97+
const xcframework = try buildpkg.GhosttyXCFramework.init(
98+
b,
99+
&deps,
100+
config.xcframework_target,
101+
);
102+
if (config.emit_xcframework) {
103+
xcframework.install();
104+
105+
// The xcframework build always installs resources because our
106+
// macOS xcode project contains references to them.
107+
resources.install();
108+
i18n.install();
109+
}
110+
111+
// Ghostty macOS app
112+
const macos_app = try buildpkg.GhosttyXcodebuild.init(
113+
b,
114+
&config,
115+
&xcframework,
116+
);
117+
if (config.emit_macos_app) {
118+
macos_app.install();
119+
}
120+
}
121+
122+
// Run step
123+
run: {
124+
if (config.app_runtime != .none) {
55125
const run_cmd = b.addRunArtifact(exe.exe);
56126
if (b.args) |args| run_cmd.addArgs(args);
57127

@@ -66,73 +136,27 @@ pub fn build(b: *std.Build) !void {
66136

67137
const run_step = b.step("run", "Run the app");
68138
run_step.dependOn(&run_cmd.step);
139+
break :run;
69140
}
70-
}
71141

72-
// Libghostty
73-
//
74-
// Note: libghostty is not stable for general purpose use. It is used
75-
// heavily by Ghostty on macOS but it isn't built to be reusable yet.
76-
// As such, these build steps are lacking. For example, the Darwin
77-
// build only produces an xcframework.
78-
if (config.app_runtime == .none) none: {
79-
if (!config.target.result.os.tag.isDarwin()) {
80-
const libghostty_shared = try buildpkg.GhosttyLib.initShared(
81-
b,
82-
&deps,
83-
);
84-
const libghostty_static = try buildpkg.GhosttyLib.initStatic(
85-
b,
86-
&deps,
87-
);
88-
libghostty_shared.installHeader(); // Only need one header
89-
libghostty_shared.install("libghostty.so");
90-
libghostty_static.install("libghostty.a");
91-
break :none;
92-
}
93-
94-
assert(config.target.result.os.tag.isDarwin());
95-
if (!config.emit_xcframework) break :none;
96-
97-
// Build the xcframework
98-
const xcframework = try buildpkg.GhosttyXCFramework.init(
99-
b,
100-
&deps,
101-
config.xcframework_target,
102-
);
103-
xcframework.install();
104-
105-
// The xcframework build always installs resources because our
106-
// macOS xcode project contains references to them.
107-
resources.install();
108-
i18n.install();
109-
110-
// If we aren't emitting docs we need to emit a placeholder so
111-
// our macOS xcodeproject builds.
112-
if (!config.emit_docs) {
113-
var wf = b.addWriteFiles();
114-
const path = "share/man/.placeholder";
115-
const placeholder = wf.add(path, "emit-docs not true so no man pages");
116-
b.getInstallStep().dependOn(&b.addInstallFile(placeholder, path).step);
117-
}
142+
assert(config.app_runtime == .none);
118143

119-
// Build our macOS app
120-
{
144+
// On macOS we can run the macOS app. For "run" we always force
145+
// a native-only build so that we can run as quickly as possible.
146+
if (config.target.result.os.tag.isDarwin()) {
121147
const xcframework_native = try buildpkg.GhosttyXCFramework.init(
122148
b,
123149
&deps,
124150
.native,
125151
);
126-
127-
const app = try buildpkg.GhosttyXcodebuild.init(
152+
const macos_app_native_only = try buildpkg.GhosttyXcodebuild.init(
128153
b,
129154
&config,
130155
&xcframework_native,
131156
);
132157

133-
// Add a run command that opens our mac app.
134158
const run_step = b.step("run", "Run the app");
135-
run_step.dependOn(&app.open.step);
159+
run_step.dependOn(&macos_app_native_only.open.step);
136160
}
137161
}
138162

src/build/Config.zig

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,15 @@ patch_rpath: ?[]const u8 = null,
5050

5151
/// Artifacts
5252
flatpak: bool = false,
53-
emit_test_exe: bool = false,
5453
emit_bench: bool = false,
55-
emit_helpgen: bool = false,
5654
emit_docs: bool = false,
57-
emit_webdata: bool = false,
58-
emit_xcframework: bool = false,
55+
emit_helpgen: bool = false,
56+
emit_macos_app: bool = false,
5957
emit_terminfo: bool = false,
6058
emit_termcap: bool = false,
59+
emit_test_exe: bool = false,
60+
emit_xcframework: bool = false,
61+
emit_webdata: bool = false,
6162

6263
/// Environmental properties
6364
env: std.process.EnvMap,
@@ -350,6 +351,12 @@ pub fn init(b: *std.Build) !Config {
350351
!config.emit_test_exe and
351352
!config.emit_helpgen);
352353

354+
config.emit_macos_app = b.option(
355+
bool,
356+
"emit-macos-app",
357+
"Build and install the macOS app bundle.",
358+
) orelse config.emit_xcframework;
359+
353360
//---------------------------------------------------------------
354361
// System Packages
355362

src/build/GhosttyXcodebuild.zig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@ pub fn init(
6565
build.expectExitCode(0);
6666

6767
// Capture stdout/stderr so we don't pollute our zig build
68-
_ = build.captureStdOut();
69-
_ = build.captureStdErr();
68+
// _ = build.captureStdOut();
69+
// _ = build.captureStdErr();
7070
break :build build;
7171
};
7272

0 commit comments

Comments
 (0)