Path: blob/master/scripts/packaging/appimage/make-appimage.sh
4804 views
#!/usr/bin/env bash12# SPDX-FileCopyrightText: 2019-2025 Connor McLaughlin <[email protected]>3# SPDX-License-Identifier: CC-BY-NC-ND-4.045SCRIPTDIR=$(dirname "${BASH_SOURCE[0]}")67function retry_command {8# Package servers tend to be unreliable at times..9# Retry a bunch of times.10local RETRIES=101112for i in $(seq 1 "$RETRIES"); do13"$@" && break14if [ "$i" == "$RETRIES" ]; then15echo "Command \"$@\" failed after ${RETRIES} retries."16exit 117fi18done19}2021if [ "$#" -ne 4 ]; then22echo "Syntax: $0 <path to duckstation directory> <path to build directory> <deps prefix> <output name>"23exit 124fi2526ROOTDIR=$127BUILDDIR=$228DEPSDIR=$329ASSETNAME=$43031BINARY=duckstation-qt32APPDIRNAME=DuckStation.AppDir33STRIP=strip3435declare -a MANUAL_LIBS=(36"libz.so.1"37"libavcodec.so.61"38"libavformat.so.61"39"libavutil.so.59"40"libswscale.so.8"41"libswresample.so.5"42"libdiscord-rpc.so"43"libharfbuzz.so"44"libfreetype.so.6"45"libshaderc_ds.so"46"libspirv-cross-c-shared.so.0"47)4849declare -a MANUAL_QT_LIBS=(50"libQt6WaylandEglClientHwIntegration.so.6"51)5253declare -a MANUAL_QT_PLUGINS=(54"wayland-decoration-client"55"wayland-graphics-integration-client"56"wayland-shell-integration"57)5859declare -a REMOVE_LIBS=(60'libwayland-client.so*'61'libwayland-cursor.so*'62'libwayland-egl.so*'63)6465set -e6667LINUXDEPLOY=./linuxdeploy-x86_6468LINUXDEPLOY_PLUGIN_QT=./linuxdeploy-plugin-qt-x86_6469APPIMAGETOOL=./appimagetool-x86_6470APPIMAGERUNTIME=./runtime-x86_6471PATCHELF=patchelf7273if [ ! -f "$LINUXDEPLOY" ]; then74retry_command wget -O "$LINUXDEPLOY" https://github.com/stenzek/duckstation-ext-qt-minimal/releases/download/linux/linuxdeploy-x86_64.AppImage75chmod +x "$LINUXDEPLOY"76fi7778if [ ! -f "$LINUXDEPLOY_PLUGIN_QT" ]; then79retry_command wget -O "$LINUXDEPLOY_PLUGIN_QT" https://github.com/stenzek/duckstation-ext-qt-minimal/releases/download/linux/linuxdeploy-plugin-qt-x86_64.AppImage80chmod +x "$LINUXDEPLOY_PLUGIN_QT"81fi8283if [ ! -f "$APPIMAGETOOL" ]; then84retry_command wget -O "$APPIMAGETOOL" https://github.com/stenzek/duckstation-ext-qt-minimal/releases/download/linux/appimagetool-x86_64.AppImage85chmod +x "$APPIMAGETOOL"86fi8788if [ ! -f "$APPIMAGERUNTIME" ]; then89retry_command wget -O "$APPIMAGERUNTIME" https://github.com/stenzek/type2-runtime/releases/download/continuous/runtime-x86_6490fi9192OUTDIR=$(realpath "./$APPDIRNAME")93rm -fr "$OUTDIR"9495echo "Locating extra libraries..."96EXTRA_LIBS_ARGS=()97for lib in "${MANUAL_LIBS[@]}"; do98srcpath=$(find "$DEPSDIR" -name "$lib")99if [ ! -f "$srcpath" ]; then100echo "Missinge extra library $lib. Exiting."101exit 1102fi103104echo "Found $lib at $srcpath."105EXTRA_LIBS_ARGS+=("--library=$srcpath")106done107108# Why the nastyness? linuxdeploy strips our main binary, and there's no option to turn it off.109# It also doesn't strip the Qt libs. We can't strip them after running linuxdeploy, because110# patchelf corrupts the libraries (but they still work), but patchelf+strip makes them crash111# on load. So, make a backup copy, strip the original (since that's where linuxdeploy finds112# the libs to copy), then swap them back after we're done.113# Isn't Linux packaging amazing?114115rm -fr "$DEPSDIR.bak"116cp -a "$DEPSDIR" "$DEPSDIR.bak"117IFS="118"119for i in $(find "$DEPSDIR" -iname '*.so'); do120echo "Stripping deps library ${i}"121strip "$i"122done123124echo "Running linuxdeploy to create AppDir..."125EXTRA_QT_PLUGINS="core;gui;svg;waylandclient;widgets;xcbqpa" \126EXTRA_PLATFORM_PLUGINS="libqwayland-egl.so;libqwayland-generic.so" \127DEPLOY_PLATFORM_THEMES="1" \128QMAKE="$DEPSDIR/bin/qmake" \129NO_STRIP="1" \130$LINUXDEPLOY --plugin qt --appdir="$OUTDIR" --executable="$BUILDDIR/bin/duckstation-qt" ${EXTRA_LIBS_ARGS[@]} \131--desktop-file="$ROOTDIR/scripts/packaging/org.duckstation.DuckStation.desktop" \132--icon-file="$ROOTDIR/scripts/packaging/org.duckstation.DuckStation.png" \133134echo "Copying resources into AppDir..."135cp -a "$BUILDDIR/bin/resources" "$OUTDIR/usr/bin"136137# LinuxDeploy's Qt plugin doesn't include Wayland support. So manually copy in the additional Wayland libraries.138echo "Copying Qt Wayland libraries..."139for lib in "${MANUAL_QT_LIBS[@]}"; do140srcpath="$DEPSDIR/lib/$lib"141dstpath="$OUTDIR/usr/lib/$lib"142echo " $srcpath -> $dstpath"143cp "$srcpath" "$dstpath"144$PATCHELF --set-rpath '$ORIGIN' "$dstpath"145done146147# .. and plugins.148echo "Copying Qt Wayland plugins..."149for GROUP in "${MANUAL_QT_PLUGINS[@]}"; do150srcpath="$DEPSDIR/plugins/$GROUP"151dstpath="$OUTDIR/usr/plugins/$GROUP"152echo " $srcpath -> $dstpath"153mkdir -p "$dstpath"154155for srcsopath in $(find "$DEPSDIR/plugins/$GROUP" -iname '*.so'); do156# This is ../../ because it's usually plugins/group/name.so157soname=$(basename "$srcsopath")158dstsopath="$dstpath/$soname"159echo " $srcsopath -> $dstsopath"160cp "$srcsopath" "$dstsopath"161$PATCHELF --set-rpath '$ORIGIN/../../lib:$ORIGIN' "$dstsopath"162done163done164165# Why do we have to manually remove these libs? Because the linuxdeploy Qt plugin166# copies them, not the "main" linuxdeploy binary, and plugins don't inherit the167# include list...168for lib in "${REMOVE_LIBS[@]}"; do169for libpath in $(find "$OUTDIR/usr/lib" -name "$lib"); do170echo " Removing problematic library ${libpath}."171rm -f "$libpath"172done173done174175# Restore unstripped deps (for cache).176rm -fr "$DEPSDIR"177mv "$DEPSDIR.bak" "$DEPSDIR"178179# Fix up translations.180rm -fr "$OUTDIR/usr/bin/translations"181mv "$OUTDIR/usr/translations" "$OUTDIR/usr/bin"182cp -a "$BUILDDIR/bin/translations" "$OUTDIR/usr/bin"183184# Generate AppStream meta-info.185echo "Generating AppStream metainfo..."186mkdir -p "$OUTDIR/usr/share/metainfo"187"$SCRIPTDIR/../generate-metainfo.sh" "$OUTDIR/usr/share/metainfo"188189echo "Generating AppImage..."190rm -f "$ASSETNAME"191"$APPIMAGETOOL" -v --runtime-file "$APPIMAGERUNTIME" "$OUTDIR" "$ASSETNAME"192193194