Skip to content

Commit

Permalink
Initial port to appimage-builder
Browse files Browse the repository at this point in the history
  • Loading branch information
HeavenVolkoff committed Nov 17, 2023
1 parent f3ad0d7 commit 68df347
Show file tree
Hide file tree
Showing 2 changed files with 238 additions and 0 deletions.
149 changes: 149 additions & 0 deletions scripts/AppImageBuilder.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
# Reference:
# https://appimage-builder.readthedocs.io/en/latest/reference/version_1.html

version: 1

script: |
set -eu
command -v mksquashfs >/dev/null 2>&1 || { apt-get update && apt-get install -yq squashfs-tools; }
# Clean up directories created by the recipe
rm "$TARGET_APPDIR" -rf || true
rm "$REPO_DIR" -rf || true
# Create a temporary Debian repository folder to put the generated Debian
# packages on, so we can install it like any other packages
mkdir -p "$REPO_DIR"
_deb="$(find "${TARGET_APPIMAGE_DIR}/../deb" -type f -name '*.deb' | sort -t '_' -k '2,2' -V | tail -n 1)"
cp -f "$_deb" "$REPO_DIR"
command -v apt-ftparchive >/dev/null 2>&1 || { apt-get update && apt-get install -yq apt-utils; }
CWD="$PWD" && cd "$REPO_DIR" && apt-ftparchive packages . > Packages && cd "$CWD"
# The following two commands are a workaround for the local APT package not
# being saved to the archives directory, as expected by appimage-builder
mkdir -p appimage-build/apt/archives
cp -f "$_deb" appimage-build/apt/archives
AppDir:
path: !ENV "${TARGET_APPDIR}"

app_info:
id: com.spacedrive
name: Spacedrive
icon: spacedrive
version: !ENV "${VERSION}"
exec: usr/bin/spacedrive
exec_args: $@

apt:
arch: !ENV ${TARGET_APPIMAGE_APT_ARCH}
sources:
- sourceline: !ENV 'deb [arch=${TARGET_APPIMAGE_APT_ARCH}] http://deb.debian.org/debian bookworm main'
key_url: 'https://keyserver.ubuntu.com/pks/lookup?op=get&search=0x1f89983e0081fde018f3cc9673a4f27b8dd47936'
- sourceline: !ENV 'deb [arch=${TARGET_APPIMAGE_APT_ARCH}] http://security.debian.org/debian-security bookworm-security main'
key_url: 'https://keyserver.ubuntu.com/pks/lookup?op=get&search=0x1f89983e0081fde018f3cc9673a4f27b8dd47936'
- sourceline: !ENV 'deb [arch=${TARGET_APPIMAGE_APT_ARCH}] http://deb.debian.org/debian bookworm-updates main'
key_url: 'https://keyserver.ubuntu.com/pks/lookup?op=get&search=0xac530d520f2f3269f5e98313a48449044aad5c5d'
- sourceline: !ENV 'deb [trusted=yes] file:${REPO_DIR}/ ./'

include:
- spacedrive
- gstreamer1.0-plugins-good
- gstreamer1.0-plugins-ugly
- gstreamer1.0-pipewire
# This package is necessary to avoid this: https://github.com/AppImageCrafters/appimage-builder/pull/191
- shared-mime-info

exclude:
- systemd
- systemd-sysv
- util-linux
- util-linux-extra
- xkb-data
- fdisk
- dmsetup
- mount
- dbus-daemon
- perl-base
- readline-common
- libpam-modules
- avahi-daemon
- bubblewrap
- adwaita-icon-theme
- humanity-icon-theme
- sensible-utils
- dconf-service
- ubuntu-mono
- fonts-*-core
- gstreamer1.0-plugins-bad

files:
exclude:
# Development, localization, documentation and configuration files
- usr/include
- usr/share/bug
- usr/share/man
- usr/share/doc
- usr/share/doc-base
- usr/share/lintian
- usr/share/sounds
- usr/share/bash-completion
- usr/share/zsh
- usr/share/applications
- usr/share/pkgconfig
- usr/share/pam
- usr/share/pam-configs
- usr/share/polkit-1
- usr/share/util-linux
- usr/share/initramfs-tools
- usr/share/locale
- usr/share/systemd
- usr/lib/systemd
- usr/lib/*-linux-gnu/systemd
- usr/lib/udev
- usr/lib/*.d
- usr/lib/kernel
- usr/lib/tmpfiles.d
# using our own ALSA can cause issues, and the API is pretty stable anyway
- usr/lib/*/libasound.so.*
# produced by library compilation
- usr/lib/*.a
# produced by library compilation
- usr/lib/cmake
# produced by library compilation
- usr/lib/pkgconfig
- etc
- var
# systemd, pam, lsb, modprobe.d, udev and misc daemon files
- lib/systemd
- lib/*-linux-gnu/security
- lib/udev
- lib/lsb
- lib/modprobe.d
# Unneeded utility programs and libraries
- usr/sbin
# Remove any binary but spacedrive
- usr/bin/[!s]*
- usr/bin/s[!p]*
- usr/bin/sp[!a]*
- sbin
- bin

# Incorporate Tauri patch to relocate hardcoded system WebKitGTK binary paths to the AppDir:
# https://github.com/tauri-apps/linuxdeploy-plugin-gtk/blob/c017fa2962008635d201889a721373077dd299e4/linuxdeploy-plugin-gtk.sh#L325-L326
# /usr/lib/x86_64-linux-gnu/webkit2gtk-4.0/WebKitNetworkProcess
# .././lib/x86_64-linux-gnu/webkit2gtk-4.0/WebKitNetworkProcess
# ../../usr/lib/x86_64-linux-gnu/webkit2gtk-4.0/WebKitNetworkProcess
after_runtime: |
set -eu
ln -sf ../usr/lib "${TARGET_APPDIR}/runtime/lib"
find "$TARGET_APPDIR"/usr/lib* -name 'libwebkit*' -exec sed -i -e "s|/usr/lib|.././lib|g" '{}' \;
# Tests don't work due to Tauri security checks we can't work around:
# https://github.com/tauri-apps/tauri/blob/35264b4c1801b381e0b867c1c35540f0fbb43365/core/tauri-utils/src/lib.rs#L202
#test:
# debian-stretch:
# image: debian:stretch-slim
# command: ./AppRun

AppImage:
arch: !ENV "${TARGET_APPIMAGE_ARCH}"
sign-key: None
update-information: None
89 changes: 89 additions & 0 deletions scripts/build_appimage.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
#!/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 -xeEuo 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

if ! command -v appimage-builder >/dev/null 2>&1; then
if ! command -v python3 >/dev/null 2>&1; then
echo "! Python 3 was not found. Please make sure it is installed and in the PATH variable." >&2
false
fi

# 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"

echo '> Install appimage-build in temporary Python virtual environment'
pip3 install -r /proc/self/fd/0 <<'REQUIREMENTS'
appimage-builder==1.1.0
certifi==2022.6.15
charset-normalizer==2.1.0
contextlib2==21.6.0
decorator==5.1.1
docker==5.0.3
emrichen==0.2.3
idna==3.3
jsonpath-rw==1.4.0
lief==0.12.1
packaging==21.3
ply==3.11
prompt-toolkit==3.0.30
pyaml==21.10.1
pyparsing==3.0.9
python-gnupg==0.4.9>
ruamel.yaml==0.17.21
ruamel.yaml.clib==0.2.6
schema==0.7.5
six==1.16.0
urllib3==1.26.11
wcwidth==0.2.5
websocket-client==1.3.3
REQUIREMENTS

echo '> Running appimage-builder'
fi

export TARGET_APPIMAGE_ARCH="${TARGET_APPIMAGE_ARCH:-$(uname -m)}"
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"
VERSION="$(git describe --tags --dirty=-custom --always)"
export VERSION

appimage-builder --recipe "$RECIPE" --skip-test

echo "> Moving generated AppImage to $TARGET_APPIMAGE_DIR"
mkdir -p "$TARGET_APPIMAGE_DIR"
mv -f ./*.AppImage* "$TARGET_APPIMAGE_DIR"

0 comments on commit 68df347

Please sign in to comment.