Files
spacedrive/scripts/appimage/build_appimage.sh
Vítor Vasconcellos 556ddbd4f8 Port AppImage build to use appimage-builder (#1785)
* Initial port to appimage-builder

* Almost

* Fix appimage build on arm64

* Custom patch for external binaries run under appimage
 - Disable bubblewrap sandbox when running under appimage
 - Change cwd to APPDIR when running under appimage

* AppImage Works (for the first lunch, then it crashes with Stack Smash 😭)

* Fix stack smashing, now AppImage almos fully works \o/ (gstreamer is still broken)
 - Temporarily disable the volume watcher when running under appimage (Workaround for the stack smash error)
 - Wrap gnu lic version check for appimage under conditional compile for glibc targets
 - Add error handling for the justUpdatedCheck
 - Fix VITE_LANDING_ORIGIN being undefined

* On non glibc systems default to runtime/compat

* Use glibc version 2.8 instead of 0 for non-gnu systems

* Fix video playback not working due to broken GstRegistry

* Build and publish new AppImage release artifact
 - Fix model location when building deb
 - Improve model path resolution logic
 - Remove patchelf dependency from setup script
 - Fix incorrectly ignore gstreamer dependency in AppImage recipe

* Fix clippy complaining about `get_path_relative_to_exe`
 - Read GLIBC_FAKE_VERSION or use 2.8 for musl in appimage (while the code is there, this is not really supported for now)

* Remove appimage tauri target from release CI

* Remove setup-buildx-action, not relly needed

* typo fix

* Fix git describe command running on cwd instead of the repo root dir

* Attempt fix weird git permissions errors in CI+docker

* Pass CI env to docker appimage

* Only use git after installing it

* Pass target to appimage build script

* Fix permission after creating appimage

* -_-

* Swap envvar with github ci var

* Format

* Add instruction on how to manually build an AppImage

* Fix typos

* docs: add note about running podman with `--privileged` if there's a permission denied error

* docs: fix typo and link directly to appimage-building `README.md`

* refactor: streamline code and make it a bit cleaner

---------

Co-authored-by: jake <77554505+brxken128@users.noreply.github.com>
2024-01-22 10:52:26 +00:00

93 lines
3.1 KiB
Bash
Executable File

#!/usr/bin/env bash
# Creates an AppImage with the specified Rust package binary and its dependencies.
# AppImage is an universal Linux application distribution format, similar
# to macOS bundles, which packs an application and its dependencies to
# allow running it across a wide variety of distros with no system changes
# and little user hassle.
#
# Relevant documentation:
# https://docs.appimage.org/packaging-guide/index.html
# https://appimage-builder.readthedocs.io/en/latest/index.html
set -eEuo pipefail
if [ "${CI:-}" = "true" ]; then
set -x
fi
_root="$(CDPATH='' cd "$(dirname -- "$0")" && pwd -P)"
readonly _root
# The appimage-builder recipe to use to generate the AppImage.
readonly RECIPE="${_root}/AppImageBuilder.yml"
# The directory where the generated AppImage bundles will be stored.
readonly TARGET_APPIMAGE_DIR="${_root}/../../target/${TARGET:-.}/release/bundle/appimage"
export TARGET_APPIMAGE_DIR
alias wget='wget -nc -nv --show-progress -P "$APPIMAGE_WORKDIR"'
# Create a temporary working directory for this AppImage script
APPIMAGE_WORKDIR=$(mktemp -d -t spacedrive-appimagebuild.XXX)
readonly APPIMAGE_WORKDIR
trap '{ rm -rf "$APPIMAGE_WORKDIR" || true; } && { rm -rf appimage-build AppDir || true; }' EXIT INT TERM
# Install required system dependencies
echo 'Installind required system dependencies...'
apt-get update && apt-get install -yq \
git \
zsync \
dpkg-dev \
apt-utils \
libffi-dev \
squashfs-tools \
libglib2.0-bin \
gstreamer1.0-tools \
libgdk-pixbuf2.0-bin \
gtk-update-icon-cache
if [ "${CI:-}" = "true" ]; then
git config --global --add safe.directory '*'
fi
# gdk-pixbuf-query-loaders is not in PATH by default
ln -fs /usr/lib/x86_64-linux-gnu/gdk-pixbuf-2.0/gdk-pixbuf-query-loaders /usr/local/bin/gdk-pixbuf-query-loaders
export TARGET_APPIMAGE_ARCH="${TARGET_APPIMAGE_ARCH:-$(uname -m)}"
if ! command -v appimage-builder >/dev/null 2>&1; then
apt-get install -yq python3 python3-dev python3-venv
# Set up a virtual environment so that we do not pollute the global Python
# packages list with the packages we need to install
echo 'Setting up temporary Python virtual environment...'
python3 -m venv "$APPIMAGE_WORKDIR/.venv"
. "$APPIMAGE_WORKDIR/.venv/bin/activate"
export MAKEFLAGS="-j$(nproc)"
pip3 install wheel setuptools --upgrade
echo 'Install appimage-build in temporary Python virtual environment...'
pip3 install git+https://github.com/AppImageCrafters/appimage-builder.git
fi
echo 'Running appimage-builder...'
export TARGET_APPIMAGE_APT_ARCH="${TARGET_APPIMAGE_APT_ARCH:-$(dpkg-architecture -q DEB_HOST_ARCH)}"
export TARGET_APPDIR="${APPIMAGE_WORKDIR}/AppDir"
export REPO_DIR="$APPIMAGE_WORKDIR/pkgs"
XDG_DATA_DIRS="$(pwd)/AppDir/usr/share:/usr/share:/usr/local/share:/var/lib/flatpak/exports/share"
export XDG_DATA_DIRS
VERSION="$(CDPATH='' cd "${_root}/../.." && git describe --tags --dirty=-custom --always)"
export VERSION
mkdir -p "$TARGET_APPIMAGE_DIR"
appimage-builder --recipe "$RECIPE" --skip-test
echo "> Moving generated AppImage to $TARGET_APPIMAGE_DIR"
mv -f ./*.AppImage* "$TARGET_APPIMAGE_DIR"