Add make-appimage.sh
This commit is contained in:
commit
42052916f2
1 file changed
+175
@@ -0,0 +1,175 @@
|
||||
#!/bin/sh
|
||||
# Builds the Linux app as an AppImage, from the standalone web app built beforehand:
|
||||
# pnpm -F web build:standalone && packages/desktop/scripts/make-appimage.sh
|
||||
#
|
||||
# Meant for a recent Debian/Ubuntu or Arch-like host (CI uses ubuntu-24.04); the
|
||||
# desktop workflow lists the packages. Prints the AppImage's path.
|
||||
set -e
|
||||
desktop=$(cd "$(dirname "$0")/.." && pwd)
|
||||
repo=$(cd "$desktop/../.." && pwd)
|
||||
work=${APPIMAGE_WORK:-$desktop/appimage}
|
||||
id=io.github.viren070.aiostreams
|
||||
|
||||
if [ ! -f "$repo/packages/web/dist-standalone/index.html" ]; then
|
||||
echo "Build the web app first: pnpm -F web build:standalone" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
case $(uname -m) in
|
||||
x86_64) image_arch=x86_64 ;;
|
||||
aarch64) image_arch=aarch64 ;;
|
||||
*) echo "No AppImage tooling for $(uname -m)" >&2; exit 1 ;;
|
||||
esac
|
||||
|
||||
prefix="$work/prefix"
|
||||
appdir="$work/AppDir"
|
||||
tools="$work/tools"
|
||||
rm -rf "$appdir"
|
||||
mkdir -p "$prefix" "$appdir/usr/bin" "$appdir/usr/lib" "$tools"
|
||||
|
||||
# mpv 0.41 needs libplacebo 6.338.2, a patch above Ubuntu 24.04's 6.338.0, so it is
|
||||
# built at the commit the Flatpak manifest pins. Vulkan stays off: the app plays
|
||||
# through libmpv's OpenGL render API, and that keeps shaderc out of the AppImage.
|
||||
if [ ! -f "$prefix/lib/libplacebo.so" ]; then
|
||||
rm -rf "$work/libplacebo" "$work/libplacebo-build"
|
||||
git clone --quiet --depth 1 --branch v7.360.1 https://github.com/haasn/libplacebo.git "$work/libplacebo"
|
||||
# The OpenGL component builds glad from this submodule, as the Flatpak's git source does.
|
||||
git -C "$work/libplacebo" submodule update --init --quiet --depth 1
|
||||
[ "$(git -C "$work/libplacebo" rev-parse HEAD)" = cee9b076f2c63104ccfd497fa79c39a867293ec4 ] ||
|
||||
{ echo "Unexpected libplacebo checkout" >&2; exit 1; }
|
||||
meson setup "$work/libplacebo-build" "$work/libplacebo" --prefix="$prefix" --buildtype=release \
|
||||
-Dvulkan=disabled -Ddemos=false
|
||||
meson install -C "$work/libplacebo-build"
|
||||
fi
|
||||
|
||||
if [ ! -f "$prefix/lib/libmpv.so.2" ]; then
|
||||
mpv_tar="$work/mpv-v0.41.0.tar.gz"
|
||||
[ -f "$mpv_tar" ] || curl -fsSL -o "$mpv_tar" https://github.com/mpv-player/mpv/archive/v0.41.0.tar.gz
|
||||
# The checksum the Flatpak manifest pins.
|
||||
echo "ee21092a5ee427353392360929dc64645c54479aefdb5babc5cfbb5fad626209 $mpv_tar" | sha256sum -c - >/dev/null
|
||||
rm -rf "$work/mpv-src" "$work/mpv-build"
|
||||
mkdir "$work/mpv-src" && tar -xzf "$mpv_tar" -C "$work/mpv-src" --strip-components=1
|
||||
PKG_CONFIG_PATH="$prefix/lib/pkgconfig${PKG_CONFIG_PATH:+:$PKG_CONFIG_PATH}" \
|
||||
meson setup "$work/mpv-build" "$work/mpv-src" --prefix="$prefix" --buildtype=release \
|
||||
-Dlibmpv=true -Dcplayer=false -Dmanpage-build=disabled -Dbuild-date=false \
|
||||
-Dlua=luajit -Duchardet=enabled -Dvulkan=disabled
|
||||
meson install -C "$work/mpv-build"
|
||||
fi
|
||||
|
||||
# The app itself; the workflow sets the workspace version before this.
|
||||
cargo build --release --manifest-path "$desktop/Cargo.toml" -p aiostreams-desktop
|
||||
install -m755 "$desktop/target/release/aiostreams-desktop" "$appdir/usr/bin/aiostreams-desktop"
|
||||
mkdir -p "$appdir/usr/lib/aiostreams-desktop"
|
||||
cp -r "$repo/packages/web/dist-standalone" "$appdir/usr/lib/aiostreams-desktop/web"
|
||||
|
||||
# WebKitGTK launches its web and network processes and its injected bundle through
|
||||
# paths compiled into the library. The copies below sit at the same paths, which a
|
||||
# rewrite in the library turns into relative ones the AppRun can satisfy.
|
||||
for file in $(find /usr/lib /usr/libexec -type f \( \
|
||||
-path '*webkitgtk-6.0/WebKitWebProcess' -o \
|
||||
-path '*webkitgtk-6.0/WebKitNetworkProcess' -o \
|
||||
-path '*webkitgtk-6.0/WebKitGPUProcess' -o \
|
||||
-path '*webkitgtk-6.0/injected-bundle/*' \) 2>/dev/null); do
|
||||
install -Dm755 "$file" "$appdir/usr${file#/usr}"
|
||||
done
|
||||
find "$appdir/usr" -type f -name WebKitWebProcess | grep -q . || {
|
||||
echo "WebKitGTK 6's helper processes were not found; install libwebkitgtk-6.0-4" >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
# The modules, loaders and schemas GTK looks for beside its libraries. Some
|
||||
# distributions build its modules in, so a missing module directory is fine.
|
||||
gtk_libdir=$(pkg-config --variable=libdir gtk4)
|
||||
if [ -d "$gtk_libdir/gtk-4.0" ]; then
|
||||
cp -r "$gtk_libdir/gtk-4.0" "$appdir/usr/lib/gtk-4.0"
|
||||
fi
|
||||
|
||||
pixbuf_binarydir=$(pkg-config --variable=gdk_pixbuf_binarydir gdk-pixbuf-2.0)
|
||||
mkdir -p "$appdir/usr/lib/gdk-pixbuf-2.0"
|
||||
pixbuf_dir="$appdir/usr/lib/gdk-pixbuf-2.0/${pixbuf_binarydir##*gdk-pixbuf-2.0/}"
|
||||
cp -r "$pixbuf_binarydir" "$pixbuf_dir"
|
||||
gdk-pixbuf-query-loaders > "$pixbuf_dir/loaders.cache"
|
||||
sed -i "s|$(pkg-config --variable=gdk_pixbuf_moduledir gdk-pixbuf-2.0)/||g" "$pixbuf_dir/loaders.cache"
|
||||
|
||||
mkdir -p "$appdir/usr/lib/gio"
|
||||
cp -r "$(pkg-config --variable=giomoduledir gio-2.0)" "$appdir/usr/lib/gio/modules"
|
||||
gio-querymodules "$appdir/usr/lib/gio/modules"
|
||||
|
||||
mkdir -p "$appdir/usr/share/glib-2.0"
|
||||
cp -r "$(pkg-config --variable=schemasdir gio-2.0)" "$appdir/usr/share/glib-2.0/schemas"
|
||||
glib-compile-schemas "$appdir/usr/share/glib-2.0/schemas"
|
||||
|
||||
install -Dm644 "$desktop/linux/$id.desktop" "$appdir/usr/share/applications/$id.desktop"
|
||||
cp "$desktop/app/icons/aiostreams.png" "$work/$id.png"
|
||||
install -Dm644 "$repo/LICENSE" "$desktop/THIRD-PARTY.md" -t "$appdir/usr/share/licenses/$id"
|
||||
|
||||
# Written before linuxdeploy runs, so its deploy pass finds one in place and
|
||||
# leaves it; it would otherwise link AppRun at the executable.
|
||||
cat > "$appdir/AppRun" <<'EOF'
|
||||
#!/bin/sh
|
||||
# WebKit's rewritten paths resolve from usr/, so the session runs from there.
|
||||
APPDIR=$(dirname "$(readlink -f "$0")")
|
||||
export APPDIR
|
||||
cd "$APPDIR/usr" || exit 1
|
||||
export LD_LIBRARY_PATH="$APPDIR/usr/lib${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}"
|
||||
export XDG_DATA_DIRS="$APPDIR/usr/share:${XDG_DATA_DIRS:-/usr/local/share:/usr/share}"
|
||||
export GTK_PATH="$APPDIR/usr/lib/gtk-4.0"
|
||||
export GTK_EXE_PREFIX="$APPDIR/usr"
|
||||
export GDK_PIXBUF_MODULE_FILE="$APPDIR/usr/lib/gdk-pixbuf-2.0/2.10.0/loaders.cache"
|
||||
export GIO_MODULE_DIR="$APPDIR/usr/lib/gio/modules"
|
||||
# The app looks beside the executable and in system folders for libmpv.
|
||||
export AIOSTREAMS_LIBMPV="${AIOSTREAMS_LIBMPV:-$APPDIR/usr/lib/libmpv.so.2}"
|
||||
export AIOSTREAMS_WEB_DIR="${AIOSTREAMS_WEB_DIR:-$APPDIR/usr/lib/aiostreams-desktop/web}"
|
||||
# WebKit's bubblewrap sandbox mounts a fresh /tmp, which would hide the AppImage's
|
||||
# mount from its helper processes, so they run unsandboxed.
|
||||
export WEBKIT_DISABLE_SANDBOX_THIS_IS_DANGEROUS=1
|
||||
# VA-API drivers sit wherever the host puts them, not always on the build host's path.
|
||||
export LIBVA_DRIVERS_PATH="${LIBVA_DRIVERS_PATH:+$LIBVA_DRIVERS_PATH:}/usr/lib/x86_64-linux-gnu/dri:/usr/lib64/dri:/usr/lib/dri"
|
||||
exec "$APPDIR/usr/bin/aiostreams-desktop" "$@"
|
||||
EOF
|
||||
chmod +x "$appdir/AppRun"
|
||||
|
||||
linuxdeploy="$tools/linuxdeploy-$image_arch"
|
||||
[ -f "$linuxdeploy" ] || {
|
||||
curl -fsSL -o "$linuxdeploy" \
|
||||
"https://github.com/linuxdeploy/linuxdeploy/releases/download/continuous/linuxdeploy-$image_arch.AppImage"
|
||||
chmod +x "$linuxdeploy"
|
||||
}
|
||||
|
||||
# The modern appimagetool, which reads zstd, ships inside the AppImage output
|
||||
# plugin; extracting it avoids running another linuxdeploy deploy pass.
|
||||
appimagetool="$tools/appimagetool-$image_arch/usr/bin/appimagetool"
|
||||
[ -x "$appimagetool" ] || {
|
||||
plugin="$tools/linuxdeploy-plugin-appimage-$image_arch"
|
||||
[ -f "$plugin" ] || curl -fsSL -o "$plugin" \
|
||||
"https://github.com/linuxdeploy/linuxdeploy-plugin-appimage/releases/download/continuous/linuxdeploy-plugin-appimage-$image_arch.AppImage"
|
||||
chmod +x "$plugin"
|
||||
rm -rf "$tools/squashfs-root"
|
||||
(cd "$tools" && "$plugin" --appimage-extract) >/dev/null
|
||||
mv "$tools/squashfs-root" "$tools/appimagetool-$image_arch"
|
||||
}
|
||||
|
||||
# GL and everything that talks to the GPU driver belongs to the host, whose mesa
|
||||
# and proprietary drivers the AppImage cannot know.
|
||||
export APPIMAGE_EXTRACT_AND_RUN=1 ARCH=$image_arch
|
||||
LD_LIBRARY_PATH="$prefix/lib${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}" \
|
||||
"$linuxdeploy" --appdir "$appdir" \
|
||||
--executable "$appdir/usr/bin/aiostreams-desktop" \
|
||||
--library "$prefix/lib/libmpv.so.2" \
|
||||
--desktop-file "$appdir/usr/share/applications/$id.desktop" \
|
||||
--icon-file "$work/$id.png" \
|
||||
--exclude-library libEGL.so.1 --exclude-library libGL.so.1 --exclude-library libGLESv2.so.2 \
|
||||
--exclude-library libOpenGL.so.0 --exclude-library libGLX.so.0 --exclude-library libGLdispatch.so.0 \
|
||||
--exclude-library libgbm.so.1
|
||||
|
||||
# The rewrite is the same length as what it replaces, so the library stays loadable,
|
||||
# and it resolves from the working directory the AppRun runs from.
|
||||
find "$appdir/usr/lib" -name 'libwebkit*' -type f -exec sed -i 's|/usr|././|g' {} +
|
||||
|
||||
# The AppRun is in place from before the deploy pass, so the AppDir is packed
|
||||
# exactly as staged:
|
||||
ln -sf usr/share/icons/hicolor/512x512/apps/$id.png "$appdir/.DirIcon"
|
||||
|
||||
APPIMAGE_EXTRACT_AND_RUN=1 ARCH=$image_arch \
|
||||
"$appimagetool" --comp zstd "$appdir" "$work/$id.AppImage"
|
||||
echo "$work/$id.AppImage"
|
||||
Reference in new issue
Block a user