#!/usr/bin/env bash # Runs INSIDE a debian:trixie container on an x86-64 runner. Cross-builds the ARM64 shadPS4 core # (tools/shadps4/source.env) with its own scripts - FEXCore first, then shadPS4 linked against it - # after applying ./patches, and packs the binary as shadps4.AppImage for /opt/appimages. # Built against trixie's glibc 2.41; the runtime's Arch rootfs is newer, so its own X11, Vulkan # loader, udev and C++ libraries are used and nothing is bundled. set -euxo pipefail WORK=/work cd "$WORK" . tools/shadps4/source.env export DEBIAN_FRONTEND=noninteractive # Downloaded packages are kept in the workspace (.apt-cache), which the workflow caches between # runs; the image's docker-clean hook would otherwise delete them after every install. rm -f /etc/apt/apt.conf.d/docker-clean mkdir -p "$WORK/.apt-cache/archives/partial" cat > /etc/apt/apt.conf.d/99droiddeck-cache <<'APT' Dir::Cache::archives "/work/.apt-cache/archives"; Binary::apt::APT::Keep-Downloaded-Packages "true"; APT dpkg --add-architecture arm64 apt-get update # The Bachata runtime's cross set, plus PulseAudio and ALSA headers so SDL3 builds its audio # drivers (it loads them at run time; the runtime plays through PulseAudio), and the Wayland, EGL # and xkbcommon headers with the host's wayland-scanner so it builds its Wayland video driver. apt-get install -y --no-install-recommends \ ca-certificates git curl xz-utils zstd file pkg-config dpkg-dev squashfs-tools ccache \ cmake ninja-build clang llvm lld gcc g++ make \ gcc-aarch64-linux-gnu g++-aarch64-linux-gnu binutils-aarch64-linux-gnu \ python3 nodejs \ libvulkan-dev libc6-dev \ libx11-dev:arm64 libxext-dev:arm64 libudev-dev:arm64 uuid-dev:arm64 \ libpulse-dev:arm64 libasound2-dev:arm64 \ libwayland-dev:arm64 libegl-dev:arm64 libxkbcommon-dev:arm64 libwayland-bin \ libc6:arm64 libgcc-s1:arm64 libstdc++6:arm64 libvulkan1:arm64 libudev1:arm64 libuuid1:arm64 \ libx11-6:arm64 libxext6:arm64 git config --global --add safe.directory '*' SRC=$WORK/build/shadps4-arm64-src rm -rf "$SRC" git init -q "$SRC" git -C "$SRC" remote add origin "$SHADPS4_REPO" git -C "$SRC" fetch -q --depth 1 origin "$SHADPS4_REV" git -C "$SRC" checkout -q --detach FETCH_HEAD test "$(git -C "$SRC" rev-parse HEAD)" = "$SHADPS4_REV" git -C "$SRC" submodule update --init --recursive --depth 1 --jobs 8 for p in $(ls tools/shadps4/patches/*.patch | sort); do echo "applying $(basename "$p")" git -C "$SRC" apply --whitespace=nowarn "$WORK/$p" done # pkg-config answers for the arm64 target, not the x86-64 host: SDL3 finds PulseAudio (libpulse) # only through it, and without it builds ALSA alone. export PKG_CONFIG_LIBDIR=/usr/lib/aarch64-linux-gnu/pkgconfig:/usr/share/pkgconfig pkg-config --modversion libpulse # FEXCore compiles through ccache on its own once it is installed, and patches/0005 hands # shadPS4's configure the same launcher; the cache lives in the workspace (.ccache) and the # workflow keeps it between runs. export CCACHE_DIR=$WORK/.ccache CCACHE_BASEDIR=$WORK CCACHE_NOHASHDIR=1 \ CCACHE_COMPILERCHECK=content CCACHE_MAXSIZE=4G ccache -z bash "$SRC/runtime/scripts/build-shadps4-arm64.sh" ccache -s BIN=$SRC/runtime/build/shadps4-arm64-stage/bin/shadps4-arm64 test -x "$BIN" cat "$SRC/runtime/build/shadps4-arm64-stage/needed.txt" # SDL3 found the audio drivers the runtime needs. grep -E 'SDL_AUDIO_DRIVER_(PULSEAUDIO|ALSA)' "$SRC"/runtime/build/shadps4-arm64/externals/sdl3/include-config-release/build_config/SDL_build_config.h grep -q '#define SDL_AUDIO_DRIVER_PULSEAUDIO 1' "$SRC"/runtime/build/shadps4-arm64/externals/sdl3/include-config-release/build_config/SDL_build_config.h # ... and both video drivers: X11 under gamescope, Wayland on the desktop. grep -q '#define SDL_VIDEO_DRIVER_WAYLAND 1' "$SRC"/runtime/build/shadps4-arm64/externals/sdl3/include-config-release/build_config/SDL_build_config.h grep -q '#define SDL_VIDEO_DRIVER_X11 1' "$SRC"/runtime/build/shadps4-arm64/externals/sdl3/include-config-release/build_config/SDL_build_config.h # The patch is in. grep -aq 'BACHATA_MANAGED' "$BIN" APPDIR=$WORK/build/shadPS4.AppDir rm -rf "$APPDIR" install -Dm755 "$BIN" "$APPDIR/usr/bin/shadps4" cat > "$APPDIR/AppRun" <<'RUN' #!/bin/sh # shadPS4 is a command-line emulator; opened from a menu with nothing to run, it shows its own # Big Picture game list instead of a usage box. # The first time, the ROMs folder's ps4 folder (any case) is added to its game folders so the # list is not empty; a folder the player removes later stays removed. # Under gamescope (a game session) it stays on gamescope's X server; on the desktop it draws # through the compositor's Wayland directly. An SDL_VIDEODRIVER already set wins. HERE=$(dirname "$(readlink -f "$0")") if [ -z "$SDL_VIDEODRIVER" ]; then if [ -n "$GAMESCOPE_WAYLAND_DISPLAY" ]; then export SDL_VIDEODRIVER=x11 elif [ -n "$WAYLAND_DISPLAY" ]; then export SDL_VIDEODRIVER=wayland fi fi if [ $# -eq 0 ]; then MARK="${XDG_DATA_HOME:-$HOME/.local/share}/shadPS4/.droiddeck-games-folder" if [ ! -e "$MARK" ]; then for d in /root/ROMs/*; do case "$(basename "$d" | tr 'A-Z' 'a-z')" in ps4) [ -d "$d" ] && "$HERE/usr/bin/shadps4" --add-game-folder "$d" && mkdir -p "$(dirname "$MARK")" && : > "$MARK" ;; esac done fi set -- --big-picture fi exec "$HERE/usr/bin/shadps4" "$@" RUN chmod 755 "$APPDIR/AppRun" cat > "$APPDIR/shadps4.desktop" <<'DESK' [Desktop Entry] Type=Application Name=shadPS4 Exec=shadps4 Icon=shadps4 Categories=Game;Emulator; DESK cp "$SRC/src/resources/shadps4.png" "$APPDIR/shadps4.png" ln -sf shadps4.png "$APPDIR/.DirIcon" curl -fsSL -o runtime-aarch64 "$APPIMAGE_RUNTIME_URL" file runtime-aarch64 | grep -q 'ARM aarch64' mksquashfs "$APPDIR" shadps4.squashfs -root-owned -noappend -comp zstd -Xcompression-level 19 cat runtime-aarch64 shadps4.squashfs > shadps4.AppImage chmod 755 shadps4.AppImage rm -f shadps4.squashfs runtime-aarch64 sha256sum shadps4.AppImage | tee shadps4.AppImage.sha256 ls -l shadps4.AppImage