Path: blob/master/scripts/packaging/appimage/make-appimage.sh
7420 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.62"38"libavformat.so.62"39"libavutil.so.60"40"libswscale.so.9"41"libswresample.so.6"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_PLUGINS=(50"wayland-decoration-client"51"wayland-graphics-integration-client"52"wayland-shell-integration"53)5455declare -a REMOVE_LIBS=(56'libwayland-client.so*'57'libwayland-cursor.so*'58'libwayland-egl.so*'59)6061set -e6263LINUXDEPLOY=./linuxdeploy-x86_6464LINUXDEPLOY_PLUGIN_QT=./linuxdeploy-plugin-qt-x86_6465APPIMAGETOOL=./appimagetool-x86_6466APPIMAGERUNTIME=./runtime-x86_6467PATCHELF=patchelf6869if [ ! -f "$LINUXDEPLOY" ]; then70retry_command wget -O "$LINUXDEPLOY" https://github.com/stenzek/duckstation-ext-qt-minimal/releases/download/linux/linuxdeploy-x86_64.AppImage71chmod +x "$LINUXDEPLOY"72fi7374if [ ! -f "$LINUXDEPLOY_PLUGIN_QT" ]; then75retry_command wget -O "$LINUXDEPLOY_PLUGIN_QT" https://github.com/stenzek/duckstation-ext-qt-minimal/releases/download/linux/linuxdeploy-plugin-qt-x86_64.AppImage76chmod +x "$LINUXDEPLOY_PLUGIN_QT"77fi7879if [ ! -f "$APPIMAGETOOL" ]; then80retry_command wget -O "$APPIMAGETOOL" https://github.com/stenzek/duckstation-ext-qt-minimal/releases/download/linux/appimagetool-x86_64.AppImage81chmod +x "$APPIMAGETOOL"82fi8384if [ ! -f "$APPIMAGERUNTIME" ]; then85retry_command wget -O "$APPIMAGERUNTIME" https://github.com/stenzek/type2-runtime/releases/download/continuous/runtime-x86_6486fi8788OUTDIR=$(realpath "./$APPDIRNAME")89rm -fr "$OUTDIR"9091echo "Locating extra libraries..."92EXTRA_LIBS_ARGS=()93for lib in "${MANUAL_LIBS[@]}"; do94srcpath=$(find "$DEPSDIR" -name "$lib")95if [ ! -f "$srcpath" ]; then96echo "Missinge extra library $lib. Exiting."97exit 198fi99100echo "Found $lib at $srcpath."101EXTRA_LIBS_ARGS+=("--library=$srcpath")102done103104# Why the nastyness? linuxdeploy strips our main binary, and there's no option to turn it off.105# It also doesn't strip the Qt libs. We can't strip them after running linuxdeploy, because106# patchelf corrupts the libraries (but they still work), but patchelf+strip makes them crash107# on load. So, make a backup copy, strip the original (since that's where linuxdeploy finds108# the libs to copy), then swap them back after we're done.109# Isn't Linux packaging amazing?110111rm -fr "$DEPSDIR.bak"112cp -a "$DEPSDIR" "$DEPSDIR.bak"113IFS="114"115for i in $(find "$DEPSDIR" -iname '*.so'); do116echo "Stripping deps library ${i}"117strip "$i"118done119120echo "Running linuxdeploy to create AppDir..."121EXTRA_QT_PLUGINS="core;gui;svg;waylandclient;widgets;xcbqpa" \122EXTRA_PLATFORM_PLUGINS="libqwayland.so" \123DEPLOY_PLATFORM_THEMES="1" \124QMAKE="$DEPSDIR/bin/qmake" \125NO_STRIP="1" \126$LINUXDEPLOY --plugin qt --appdir="$OUTDIR" --executable="$BUILDDIR/bin/duckstation-qt" ${EXTRA_LIBS_ARGS[@]} \127--desktop-file="$ROOTDIR/scripts/packaging/org.duckstation.DuckStation.desktop" \128--icon-file="$ROOTDIR/scripts/packaging/org.duckstation.DuckStation.png" \129130echo "Copying resources into AppDir..."131cp -a "$BUILDDIR/bin/resources" "$OUTDIR/usr/bin"132133# LinuxDeploy's Qt plugin doesn't include Wayland support. So manually copy in the additional Wayland libraries.134echo "Copying Qt Wayland plugins..."135for GROUP in "${MANUAL_QT_PLUGINS[@]}"; do136srcpath="$DEPSDIR/plugins/$GROUP"137dstpath="$OUTDIR/usr/plugins/$GROUP"138echo " $srcpath -> $dstpath"139mkdir -p "$dstpath"140141for srcsopath in $(find "$DEPSDIR/plugins/$GROUP" -iname '*.so'); do142# This is ../../ because it's usually plugins/group/name.so143soname=$(basename "$srcsopath")144dstsopath="$dstpath/$soname"145echo " $srcsopath -> $dstsopath"146cp "$srcsopath" "$dstsopath"147$PATCHELF --set-rpath '$ORIGIN/../../lib:$ORIGIN' "$dstsopath"148done149done150151# Why do we have to manually remove these libs? Because the linuxdeploy Qt plugin152# copies them, not the "main" linuxdeploy binary, and plugins don't inherit the153# include list...154for lib in "${REMOVE_LIBS[@]}"; do155for libpath in $(find "$OUTDIR/usr/lib" -name "$lib"); do156echo " Removing problematic library ${libpath}."157rm -f "$libpath"158done159done160161# Restore unstripped deps (for cache).162rm -fr "$DEPSDIR"163mv "$DEPSDIR.bak" "$DEPSDIR"164165# Fix up translations.166rm -fr "$OUTDIR/usr/bin/translations"167mv "$OUTDIR/usr/translations" "$OUTDIR/usr/bin"168cp -a "$BUILDDIR/bin/translations" "$OUTDIR/usr/bin"169170# Generate AppStream meta-info.171echo "Generating AppStream metainfo..."172mkdir -p "$OUTDIR/usr/share/metainfo"173"$SCRIPTDIR/../generate-metainfo.sh" "$OUTDIR/usr/share/metainfo"174175echo "Generating AppImage..."176rm -f "$ASSETNAME"177"$APPIMAGETOOL" -v --runtime-file "$APPIMAGERUNTIME" "$OUTDIR" "$ASSETNAME"178179180