Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
stenzek
GitHub Repository: stenzek/duckstation
Path: blob/master/scripts/packaging/appimage/make-appimage.sh
7420 views
1
#!/usr/bin/env bash
2
3
# SPDX-FileCopyrightText: 2019-2025 Connor McLaughlin <[email protected]>
4
# SPDX-License-Identifier: CC-BY-NC-ND-4.0
5
6
SCRIPTDIR=$(dirname "${BASH_SOURCE[0]}")
7
8
function retry_command {
9
# Package servers tend to be unreliable at times..
10
# Retry a bunch of times.
11
local RETRIES=10
12
13
for i in $(seq 1 "$RETRIES"); do
14
"$@" && break
15
if [ "$i" == "$RETRIES" ]; then
16
echo "Command \"$@\" failed after ${RETRIES} retries."
17
exit 1
18
fi
19
done
20
}
21
22
if [ "$#" -ne 4 ]; then
23
echo "Syntax: $0 <path to duckstation directory> <path to build directory> <deps prefix> <output name>"
24
exit 1
25
fi
26
27
ROOTDIR=$1
28
BUILDDIR=$2
29
DEPSDIR=$3
30
ASSETNAME=$4
31
32
BINARY=duckstation-qt
33
APPDIRNAME=DuckStation.AppDir
34
STRIP=strip
35
36
declare -a MANUAL_LIBS=(
37
"libz.so.1"
38
"libavcodec.so.62"
39
"libavformat.so.62"
40
"libavutil.so.60"
41
"libswscale.so.9"
42
"libswresample.so.6"
43
"libdiscord-rpc.so"
44
"libharfbuzz.so"
45
"libfreetype.so.6"
46
"libshaderc_ds.so"
47
"libspirv-cross-c-shared.so.0"
48
)
49
50
declare -a MANUAL_QT_PLUGINS=(
51
"wayland-decoration-client"
52
"wayland-graphics-integration-client"
53
"wayland-shell-integration"
54
)
55
56
declare -a REMOVE_LIBS=(
57
'libwayland-client.so*'
58
'libwayland-cursor.so*'
59
'libwayland-egl.so*'
60
)
61
62
set -e
63
64
LINUXDEPLOY=./linuxdeploy-x86_64
65
LINUXDEPLOY_PLUGIN_QT=./linuxdeploy-plugin-qt-x86_64
66
APPIMAGETOOL=./appimagetool-x86_64
67
APPIMAGERUNTIME=./runtime-x86_64
68
PATCHELF=patchelf
69
70
if [ ! -f "$LINUXDEPLOY" ]; then
71
retry_command wget -O "$LINUXDEPLOY" https://github.com/stenzek/duckstation-ext-qt-minimal/releases/download/linux/linuxdeploy-x86_64.AppImage
72
chmod +x "$LINUXDEPLOY"
73
fi
74
75
if [ ! -f "$LINUXDEPLOY_PLUGIN_QT" ]; then
76
retry_command wget -O "$LINUXDEPLOY_PLUGIN_QT" https://github.com/stenzek/duckstation-ext-qt-minimal/releases/download/linux/linuxdeploy-plugin-qt-x86_64.AppImage
77
chmod +x "$LINUXDEPLOY_PLUGIN_QT"
78
fi
79
80
if [ ! -f "$APPIMAGETOOL" ]; then
81
retry_command wget -O "$APPIMAGETOOL" https://github.com/stenzek/duckstation-ext-qt-minimal/releases/download/linux/appimagetool-x86_64.AppImage
82
chmod +x "$APPIMAGETOOL"
83
fi
84
85
if [ ! -f "$APPIMAGERUNTIME" ]; then
86
retry_command wget -O "$APPIMAGERUNTIME" https://github.com/stenzek/type2-runtime/releases/download/continuous/runtime-x86_64
87
fi
88
89
OUTDIR=$(realpath "./$APPDIRNAME")
90
rm -fr "$OUTDIR"
91
92
echo "Locating extra libraries..."
93
EXTRA_LIBS_ARGS=()
94
for lib in "${MANUAL_LIBS[@]}"; do
95
srcpath=$(find "$DEPSDIR" -name "$lib")
96
if [ ! -f "$srcpath" ]; then
97
echo "Missinge extra library $lib. Exiting."
98
exit 1
99
fi
100
101
echo "Found $lib at $srcpath."
102
EXTRA_LIBS_ARGS+=("--library=$srcpath")
103
done
104
105
# Why the nastyness? linuxdeploy strips our main binary, and there's no option to turn it off.
106
# It also doesn't strip the Qt libs. We can't strip them after running linuxdeploy, because
107
# patchelf corrupts the libraries (but they still work), but patchelf+strip makes them crash
108
# on load. So, make a backup copy, strip the original (since that's where linuxdeploy finds
109
# the libs to copy), then swap them back after we're done.
110
# Isn't Linux packaging amazing?
111
112
rm -fr "$DEPSDIR.bak"
113
cp -a "$DEPSDIR" "$DEPSDIR.bak"
114
IFS="
115
"
116
for i in $(find "$DEPSDIR" -iname '*.so'); do
117
echo "Stripping deps library ${i}"
118
strip "$i"
119
done
120
121
echo "Running linuxdeploy to create AppDir..."
122
EXTRA_QT_PLUGINS="core;gui;svg;waylandclient;widgets;xcbqpa" \
123
EXTRA_PLATFORM_PLUGINS="libqwayland.so" \
124
DEPLOY_PLATFORM_THEMES="1" \
125
QMAKE="$DEPSDIR/bin/qmake" \
126
NO_STRIP="1" \
127
$LINUXDEPLOY --plugin qt --appdir="$OUTDIR" --executable="$BUILDDIR/bin/duckstation-qt" ${EXTRA_LIBS_ARGS[@]} \
128
--desktop-file="$ROOTDIR/scripts/packaging/org.duckstation.DuckStation.desktop" \
129
--icon-file="$ROOTDIR/scripts/packaging/org.duckstation.DuckStation.png" \
130
131
echo "Copying resources into AppDir..."
132
cp -a "$BUILDDIR/bin/resources" "$OUTDIR/usr/bin"
133
134
# LinuxDeploy's Qt plugin doesn't include Wayland support. So manually copy in the additional Wayland libraries.
135
echo "Copying Qt Wayland plugins..."
136
for GROUP in "${MANUAL_QT_PLUGINS[@]}"; do
137
srcpath="$DEPSDIR/plugins/$GROUP"
138
dstpath="$OUTDIR/usr/plugins/$GROUP"
139
echo " $srcpath -> $dstpath"
140
mkdir -p "$dstpath"
141
142
for srcsopath in $(find "$DEPSDIR/plugins/$GROUP" -iname '*.so'); do
143
# This is ../../ because it's usually plugins/group/name.so
144
soname=$(basename "$srcsopath")
145
dstsopath="$dstpath/$soname"
146
echo " $srcsopath -> $dstsopath"
147
cp "$srcsopath" "$dstsopath"
148
$PATCHELF --set-rpath '$ORIGIN/../../lib:$ORIGIN' "$dstsopath"
149
done
150
done
151
152
# Why do we have to manually remove these libs? Because the linuxdeploy Qt plugin
153
# copies them, not the "main" linuxdeploy binary, and plugins don't inherit the
154
# include list...
155
for lib in "${REMOVE_LIBS[@]}"; do
156
for libpath in $(find "$OUTDIR/usr/lib" -name "$lib"); do
157
echo " Removing problematic library ${libpath}."
158
rm -f "$libpath"
159
done
160
done
161
162
# Restore unstripped deps (for cache).
163
rm -fr "$DEPSDIR"
164
mv "$DEPSDIR.bak" "$DEPSDIR"
165
166
# Fix up translations.
167
rm -fr "$OUTDIR/usr/bin/translations"
168
mv "$OUTDIR/usr/translations" "$OUTDIR/usr/bin"
169
cp -a "$BUILDDIR/bin/translations" "$OUTDIR/usr/bin"
170
171
# Generate AppStream meta-info.
172
echo "Generating AppStream metainfo..."
173
mkdir -p "$OUTDIR/usr/share/metainfo"
174
"$SCRIPTDIR/../generate-metainfo.sh" "$OUTDIR/usr/share/metainfo"
175
176
echo "Generating AppImage..."
177
rm -f "$ASSETNAME"
178
"$APPIMAGETOOL" -v --runtime-file "$APPIMAGERUNTIME" "$OUTDIR" "$ASSETNAME"
179
180