Skip to content

Commit 75aa846

Browse files
stragerveprbl
authored andcommitted
kitty: support macOS (#56740)
Install the `kitty` command-line utility and the `kitty.app` macOS application. * Prefer libicns (png2icns) over Apple's non-free iconutil. * Work around warnings from Apple headers by disabling -pedantic-errors and -Werror. * Work around ld not support LLVM-LTO by disabling LTO. * Make Kitty and glfw compile for macOS 10.11 (and macOS 10.10).
1 parent f88d9c3 commit 75aa846

6 files changed

Lines changed: 223 additions & 7 deletions

File tree

pkgs/applications/misc/kitty/default.nix

Lines changed: 58 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,20 @@
22
harfbuzz, fontconfig, pkgconfig, ncurses, imagemagick, xsel,
33
libstartup_notification, libX11, libXrandr, libXinerama, libXcursor,
44
libxkbcommon, libXi, libXext, wayland-protocols, wayland,
5-
which, dbus
5+
which, dbus,
6+
Cocoa,
7+
CoreGraphics,
8+
Foundation,
9+
IOKit,
10+
Kernel,
11+
OpenGL,
12+
cf-private,
13+
libicns,
14+
libpng,
15+
librsvg,
16+
optipng,
17+
python3,
18+
zlib,
619
}:
720

821
with python3Packages;
@@ -19,12 +32,32 @@ buildPythonApplication rec {
1932
};
2033

2134
buildInputs = [
22-
fontconfig glfw ncurses libunistring harfbuzz libX11
35+
ncurses harfbuzz
36+
] ++ stdenv.lib.optionals stdenv.isDarwin [
37+
Cocoa
38+
CoreGraphics
39+
Foundation
40+
IOKit
41+
Kernel
42+
OpenGL
43+
cf-private
44+
libpng
45+
python3
46+
zlib
47+
] ++ stdenv.lib.optionals stdenv.isLinux [
48+
fontconfig glfw libunistring libX11
2349
libXrandr libXinerama libXcursor libxkbcommon libXi libXext
2450
wayland-protocols wayland dbus
2551
];
2652

27-
nativeBuildInputs = [ pkgconfig which sphinx ncurses ];
53+
nativeBuildInputs = [
54+
pkgconfig which sphinx ncurses
55+
] ++ stdenv.lib.optionals stdenv.isDarwin [
56+
imagemagick
57+
libicns # For the png2icns tool.
58+
librsvg
59+
optipng
60+
];
2861

2962
outputs = [ "out" "terminfo" ];
3063

@@ -33,16 +66,30 @@ buildPythonApplication rec {
3366
src = ./fix-paths.patch;
3467
libstartup_notification = "${libstartup_notification}/lib/libstartup-notification-1.so";
3568
})
69+
] ++ stdenv.lib.optionals stdenv.isDarwin [
70+
./macos-10.11.patch
71+
./no-lto.patch
72+
./no-werror.patch
73+
./png2icns.patch
3674
];
3775

38-
buildPhase = ''
76+
buildPhase = if stdenv.isDarwin then ''
77+
make app
78+
'' else ''
3979
${python.interpreter} setup.py linux-package
4080
'';
4181

4282
installPhase = ''
4383
runHook preInstall
4484
mkdir -p $out
85+
${if stdenv.isDarwin then ''
86+
mkdir "$out/bin"
87+
ln -s ../Applications/kitty.app/Contents/MacOS/kitty "$out/bin/kitty"
88+
mkdir "$out/Applications"
89+
cp -r kitty.app "$out/Applications/kitty.app"
90+
'' else ''
4591
cp -r linux-package/{bin,share,lib} $out
92+
''}
4693
wrapProgram "$out/bin/kitty" --prefix PATH : "$out/bin:${stdenv.lib.makeBinPath [ imagemagick xsel ]}"
4794
runHook postInstall
4895
@@ -54,8 +101,13 @@ buildPythonApplication rec {
54101
'';
55102

56103
postInstall = ''
104+
terminfo_src=${if stdenv.isDarwin then
105+
''"$out/Applications/kitty.app/Contents/Resources/terminfo"''
106+
else
107+
"$out/share/terminfo"}
108+
57109
mkdir -p $terminfo/share
58-
mv $out/share/terminfo $terminfo/share/terminfo
110+
mv "$terminfo_src" $terminfo/share/terminfo
59111
60112
mkdir -p $out/nix-support
61113
echo "$terminfo" >> $out/nix-support/propagated-user-env-packages
@@ -65,7 +117,7 @@ buildPythonApplication rec {
65117
homepage = https://github.com/kovidgoyal/kitty;
66118
description = "A modern, hackable, featureful, OpenGL based terminal emulator";
67119
license = licenses.gpl3;
68-
platforms = platforms.linux;
120+
platforms = platforms.darwin ++ platforms.linux;
69121
maintainers = with maintainers; [ tex rvolosatovs ];
70122
};
71123
}
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
commit 749772b8b8179eb3b71e542fd9ed5621feb578f5
2+
Author: Matthew Glazar <strager.nds@gmail.com>
3+
Date: Thu Feb 28 22:01:32 2019 -0800
4+
5+
Support macOS 10.11
6+
7+
Allow Kitty to run on macOS 10.11 El Capitan.
8+
9+
diff --git a/glfw/cocoa_init.m b/glfw/cocoa_init.m
10+
index 1e719d2e..05a680e4 100644
11+
--- a/glfw/cocoa_init.m
12+
+++ b/glfw/cocoa_init.m
13+
@@ -30,6 +30,10 @@
14+
#define NSEventMaskKeyUp NSKeyUpMask
15+
#define NSEventMaskKeyDown NSKeyDownMask
16+
#define NSEventModifierFlagCommand NSCommandKeyMask
17+
+ #define NSEventModifierFlagControl NSControlKeyMask
18+
+ #define NSEventModifierFlagDeviceIndependentFlagsMask NSDeviceIndependentModifierFlagsMask
19+
+ #define NSEventModifierFlagShift NSShiftKeyMask
20+
+ #define NSEventTypeApplicationDefined NSApplicationDefined
21+
#endif
22+
23+
// Change to our application bundle's resources directory, if present
24+
diff --git a/glfw/cocoa_window.m b/glfw/cocoa_window.m
25+
index 1ce79b56..fd2255fc 100644
26+
--- a/glfw/cocoa_window.m
27+
+++ b/glfw/cocoa_window.m
28+
@@ -41,6 +41,7 @@
29+
#define NSWindowStyleMaskTitled NSTitledWindowMask
30+
#define NSEventModifierFlagCommand NSCommandKeyMask
31+
#define NSEventModifierFlagControl NSControlKeyMask
32+
+ #define NSEventModifierFlagNumericPad NSNumericPadKeyMask
33+
#define NSEventModifierFlagOption NSAlternateKeyMask
34+
#define NSEventModifierFlagShift NSShiftKeyMask
35+
#define NSEventModifierFlagCapsLock NSAlphaShiftKeyMask
36+
diff --git a/kitty/cocoa_window.m b/kitty/cocoa_window.m
37+
index 5e9252ba..99eb3352 100644
38+
--- a/kitty/cocoa_window.m
39+
+++ b/kitty/cocoa_window.m
40+
@@ -15,6 +15,9 @@
41+
#include <objc/runtime.h>
42+
43+
#if (MAC_OS_X_VERSION_MAX_ALLOWED < 101200)
44+
+typedef NSUInteger NSWindowStyleMask;
45+
+#define NSWindowStyleMaskBorderless NSBorderlessWindowMask
46+
+#define NSWindowStyleMaskFullScreen NSFullScreenWindowMask
47+
#define NSWindowStyleMaskResizable NSResizableWindowMask
48+
#define NSEventModifierFlagOption NSAlternateKeyMask
49+
#define NSEventModifierFlagCommand NSCommandKeyMask
50+
diff --git a/kitty/logging.c b/kitty/logging.c
51+
index 45c88174..1ec9f1b0 100644
52+
--- a/kitty/logging.c
53+
+++ b/kitty/logging.c
54+
@@ -5,12 +5,21 @@
55+
* Distributed under terms of the GPL3 license.
56+
*/
57+
58+
+#ifdef __APPLE__
59+
+#include <AvailabilityMacros.h>
60+
+#endif
61+
+#if defined(__APPLE__) && defined(MAC_OS_X_VERSION_10_12) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_12
62+
+#define USE_APPLE_OS_LOG 1
63+
+#else
64+
+#define USE_APPLE_OS_LOG 0
65+
+#endif
66+
+
67+
#include "data-types.h"
68+
#include <stdlib.h>
69+
#include <stdarg.h>
70+
#include <time.h>
71+
#include <sys/time.h>
72+
-#ifdef __APPLE__
73+
+#if USE_APPLE_OS_LOG
74+
#include <os/log.h>
75+
#endif
76+
77+
@@ -21,7 +30,7 @@ void
78+
log_error(const char *fmt, ...) {
79+
va_list ar;
80+
struct timeval tv;
81+
-#ifdef __APPLE__
82+
+#if USE_APPLE_OS_LOG
83+
// Apple does not provide a varargs style os_logv
84+
char logbuf[16 * 1024] = {0};
85+
#else
86+
@@ -44,7 +53,7 @@ log_error(const char *fmt, ...) {
87+
if (use_os_log) { bufprint(vsnprintf, fmt, ar); }
88+
else vfprintf(stderr, fmt, ar);
89+
va_end(ar);
90+
-#ifdef __APPLE__
91+
+#if USE_APPLE_OS_LOG
92+
if (use_os_log) os_log(OS_LOG_DEFAULT, "%{public}s", logbuf);
93+
#endif
94+
if (!use_os_log) fprintf(stderr, "\n");
95+
@@ -66,7 +75,7 @@ static PyMethodDef module_methods[] = {
96+
bool
97+
init_logging(PyObject *module) {
98+
if (PyModule_AddFunctions(module, module_methods) != 0) return false;
99+
-#ifdef __APPLE__
100+
+#if USE_APPLE_OS_LOG
101+
if (getenv("KITTY_LAUNCHED_BY_LAUNCH_SERVICES") != NULL) use_os_log = true;
102+
#endif
103+
return true;
104+
diff --git a/setup.py b/setup.py
105+
index f8643fce..55a96e73 100755
106+
--- a/setup.py
107+
+++ b/setup.py
108+
@@ -711,7 +711,7 @@ Categories=System;TerminalEmulator;
109+
CFBundlePackageType='APPL',
110+
CFBundleSignature='????',
111+
CFBundleExecutable=appname,
112+
- LSMinimumSystemVersion='10.12.0',
113+
+ LSMinimumSystemVersion='10.11.0',
114+
LSRequiresNativeExecution=True,
115+
NSAppleScriptEnabled=False,
116+
# Needed for dark mode in Mojave when linking against older SDKs
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
--- a/setup.py
2+
+++ b/setup.py
3+
@@ -223,9 +223,6 @@ def init_env(
4+
cppflags += shlex.split(os.environ.get('CPPFLAGS', ''))
5+
cflags += shlex.split(os.environ.get('CFLAGS', ''))
6+
ldflags += shlex.split(os.environ.get('LDFLAGS', ''))
7+
- if not debug and not sanitize:
8+
- # See https://github.com/google/sanitizers/issues/647
9+
- cflags.append('-flto'), ldflags.append('-flto')
10+
11+
if profile:
12+
cppflags.append('-DWITH_PROFILER')
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
--- a/setup.py
2+
+++ b/setup.py
3+
@@ -202,7 +202,7 @@ def init_env(
4+
cflags = os.environ.get(
5+
'OVERRIDE_CFLAGS', (
6+
'-Wextra -Wno-missing-field-initializers -Wall -std=c11'
7+
- ' -pedantic-errors -Werror {} {} -fwrapv {} {} -pipe {} -fvisibility=hidden'
8+
+ ' {} {} -fwrapv {} {} -pipe {} -fvisibility=hidden'
9+
).format(
10+
optimize,
11+
' '.join(sanitize_args),
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
--- a/setup.py
2+
+++ b/setup.py
3+
@@ -744,9 +744,15 @@ Categories=System;TerminalEmulator;
4+
if not os.path.exists(logo_dir):
5+
raise SystemExit('The kitty logo has not been generated, you need to run logo/make.py')
6+
subprocess.check_call([
7+
- 'iconutil', '-c', 'icns', logo_dir, '-o',
8+
+ 'png2icns',
9+
os.path.join('Resources', os.path.basename(logo_dir).partition('.')[0] + '.icns')
10+
- ])
11+
+ ] + [os.path.join(logo_dir, logo) for logo in (
12+
+ 'icon_128x128.png',
13+
+ 'icon_16x16.png',
14+
+ 'icon_256x256.png',
15+
+ 'icon_32x32.png',
16+
+ 'icon_512x512.png',
17+
+ )])
18+
# }}}
19+
# }}}

pkgs/top-level/all-packages.nix

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18192,7 +18192,13 @@ in
1819218192

1819318193
kipi-plugins = libsForQt5.callPackage ../applications/graphics/kipi-plugins { };
1819418194

18195-
kitty = callPackage ../applications/misc/kitty { };
18195+
kitty = callPackage ../applications/misc/kitty {
18196+
harfbuzz = if stdenv.isDarwin then harfbuzz.override {
18197+
withCoreText = true;
18198+
} else harfbuzz;
18199+
inherit (darwin) cf-private;
18200+
inherit (darwin.apple_sdk.frameworks) Cocoa CoreGraphics Foundation IOKit Kernel OpenGL;
18201+
};
1819618202

1819718203
kiwix = callPackage ../applications/misc/kiwix { };
1819818204

0 commit comments

Comments
 (0)