-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathbuild.sh
More file actions
executable file
·124 lines (90 loc) · 3.53 KB
/
build.sh
File metadata and controls
executable file
·124 lines (90 loc) · 3.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#!/bin/sh
set -e
export ARCH="$(uname -m)"
GHOSTTY_VERSION="1.0.1"
# Detect latest version numbers when jq is available.
if command -v jq >/dev/null 2>&1; then
if [ "$1" = "latest" ]; then
GHOSTTY_VERSION="$(
curl -s https://api.github.com/repos/ghostty-org/ghostty/tags |
jq '[.[] | select(.name != "tip") | .name | ltrimstr("v")] | sort_by(split(".") | map(tonumber)) | last'
)"
fi
fi
TMP_DIR="/tmp/ghostty-build"
APP_DIR="${TMP_DIR}/ghostty.AppDir"
PUB_KEY="RWQlAjJC23149WL2sEpT/l0QKy7hMIFhYdQOFy0Z7z7PbneUgvlsnYcV"
UPINFO="gh-releases-zsync|$(echo "${GITHUB_REPOSITORY:-no-user/no-repo}" | tr '/' '|')|latest|*$ARCH.AppImage.zsync"
APPDATA_FILE="${PWD}/assets/ghostty.appdata.xml"
DESKTOP_FILE="${PWD}/assets/ghostty.desktop"
rm -rf "${TMP_DIR}"
mkdir -p -- "${TMP_DIR}" "${APP_DIR}/usr" "${APP_DIR}/usr/lib" "${APP_DIR}/usr/share/metainfo"
cd "${TMP_DIR}"
wget -q "https://release.files.ghostty.org/${GHOSTTY_VERSION}/ghostty-${GHOSTTY_VERSION}.tar.gz"
wget -q "https://release.files.ghostty.org/${GHOSTTY_VERSION}/ghostty-${GHOSTTY_VERSION}.tar.gz.minisig"
minisign -V -m "ghostty-${GHOSTTY_VERSION}.tar.gz" -P "${PUB_KEY}" -s "ghostty-${GHOSTTY_VERSION}.tar.gz.minisig"
rm "ghostty-${GHOSTTY_VERSION}.tar.gz.minisig"
tar -xzmf "ghostty-${GHOSTTY_VERSION}.tar.gz"
rm "ghostty-${GHOSTTY_VERSION}.tar.gz"
cd "${TMP_DIR}/ghostty-${GHOSTTY_VERSION}"
sed -i 's/linkSystemLibrary2("bzip2", dynamic_link_opts)/linkSystemLibrary2("bz2", dynamic_link_opts)/' build.zig
# Fetch Zig Cache
ZIG_GLOBAL_CACHE_DIR=/tmp/offline-cache ./nix/build-support/fetch-zig-cache.sh
# Build Ghostty with zig
zig build \
--summary all \
--prefix "${APP_DIR}/usr" \
--system /tmp/offline-cache/p \
-Doptimize=ReleaseFast \
-Dcpu=baseline \
-Dpie=true \
-Demit-docs \
-Dversion-string="${GHOSTTY_VERSION}"
cd "${APP_DIR}"
# bundle all libs
ldd ./usr/bin/ghostty | awk -F"[> ]" '{print $4}' | xargs -I {} cp --update=none -v {} ./usr/lib
# ld-linux contains x86-64 instead of x86_64
case "${ARCH}" in
"x86_64")
ld_linux="ld-linux-x86-64.so.2"
;;
"aarch64")
ld_linux="ld-linux-aarch64.so.1"
;;
*)
echo "Unsupported ARCH: '${ARCH}'"
exit 1
;;
esac
cp -v /usr/lib/${ARCH}-linux-gnu/libpthread.so.0 ./usr/lib
if ! mv ./usr/lib/${ld_linux} ./ld-linux.so; then
cp -v /usr/lib/${ARCH}-linux-gnu/${ld_linux} ./ld-linux.so
fi
# Prepare AppImage -- Configure launcher script, metainfo and desktop file with icon.
cat <<'EOF' >./AppRun
#!/usr/bin/env sh
HERE="$(dirname "$(readlink -f "$0")")"
export TERM=xterm-256color
export GHOSTTY_RESOURCES_DIR="${HERE}/usr/share/ghostty"
exec "${HERE}"/ld-linux.so --library-path "${HERE}"/usr/lib "${HERE}"/usr/bin/ghostty "$@"
if [ "$?" -gt 0 ] && [ -n "$WAYLAND_DISPLAY" ]; then
export GDK_BACKEND=x11
exec "${HERE}"/ld-linux.so --library-path "${HERE}"/usr/lib "${HERE}"/usr/bin/ghostty "$@"
fi
EOF
chmod +x AppRun
export VERSION="$(./AppRun --version 2>/dev/null | awk 'FNR==1 {print $2}')"
if [ -z "$VERSION" ]; then
echo "ERROR: Could not get version from ghostty binary"
exit 1
fi
cp "${APPDATA_FILE}" "usr/share/metainfo/com.mitchellh.ghostty.appdata.xml"
# Fix Gnome dock issues -- StartupWMClass attribute needs to be present.
cp "${DESKTOP_FILE}" "usr/share/applications/com.mitchellh.ghostty.desktop"
# WezTerm has this, it might be useful.
ln -s "com.mitchellh.ghostty.desktop" "usr/share/applications/ghostty.desktop"
ln -s "usr/share/applications/com.mitchellh.ghostty.desktop" .
ln -s "usr/share/icons/hicolor/256x256/apps/com.mitchellh.ghostty.png" .
cd "${TMP_DIR}"
# create app image
appimagetool -u "${UPINFO}" "${APP_DIR}"