From da1248d9738f02d0c35d2a18677a19cadbf556ad Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Sat, 24 Jun 2023 11:41:16 -0700 Subject: [PATCH] build: copy terminfo data into Mac app bundle --- build.zig | 30 ++++++++++++++++++++++++++---- src/os/exe.zig | 2 ++ 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/build.zig b/build.zig index cd62d5a64..85f6fbb90 100644 --- a/build.zig +++ b/build.zig @@ -286,11 +286,18 @@ pub fn build(b: *std.Build) !void { const src_source = wf.add("share/terminfo/ghostty.terminfo", str.items); const src_install = b.addInstallFile(src_source, "share/terminfo/ghostty.terminfo"); b.getInstallStep().dependOn(&src_install.step); + if (target.isDarwin()) { + const mac_src_install = b.addInstallFile( + src_source, + "Ghostty.app/Contents/Resources/terminfo/ghostty.terminfo", + ); + b.getInstallStep().dependOn(&mac_src_install.step); + } // Convert to termcap source format if thats helpful to people and // install it. The resulting value here is the termcap source in case // that is used for other commands. - const cap_source = cap_source: { + { const run_step = RunStep.create(b, "infotocap"); run_step.addArg("infotocap"); run_step.addFileSourceArg(src_source); @@ -300,9 +307,14 @@ pub fn build(b: *std.Build) !void { const cap_install = b.addInstallFile(out_source, "share/terminfo/ghostty.termcap"); b.getInstallStep().dependOn(&cap_install.step); - break :cap_source out_source; - }; - _ = cap_source; + if (target.isDarwin()) { + const mac_cap_install = b.addInstallFile( + out_source, + "Ghostty.app/Contents/Resources/terminfo/ghostty.termcap", + ); + b.getInstallStep().dependOn(&mac_cap_install.step); + } + } // Compile the terminfo source into a terminfo database { @@ -321,6 +333,16 @@ pub fn build(b: *std.Build) !void { }); install.step.dependOn(&run_step.step); b.getInstallStep().dependOn(&install.step); + + if (target.isDarwin()) { + const mac_install = b.addInstallDirectory(.{ + .source_dir = path, + .install_dir = .prefix, + .install_subdir = "Ghostty.app/Contents/Resources/terminfo", + }); + mac_install.step.dependOn(&run_step.step); + b.getInstallStep().dependOn(&mac_install.step); + } } } diff --git a/src/os/exe.zig b/src/os/exe.zig index 55c8a6fe2..a2889a3ef 100644 --- a/src/os/exe.zig +++ b/src/os/exe.zig @@ -6,6 +6,8 @@ const builtin = @import("builtin"); /// /// This function can be very slow. The caller can choose to cache the value /// if they want but this function itself doesn't handle caching. +/// +/// From: https://unix.stackexchange.com/questions/317211/absolute-path-to-currently-executing-program pub fn exePath(buf: []u8) !?[]const u8 { if (comptime builtin.target.isDarwin()) { // We put the path into a temporary buffer first because we need