diff --git a/frontend/.gitignore b/frontend/.gitignore index ea8c4bf7..f1d16cd5 100644 --- a/frontend/.gitignore +++ b/frontend/.gitignore @@ -1 +1,3 @@ /target +/dist/ +/packaging/tools/ diff --git a/frontend/README.md b/frontend/README.md index 3365cc7d..a7d7f850 100644 --- a/frontend/README.md +++ b/frontend/README.md @@ -64,6 +64,56 @@ config file controls the duration. The FPS/status overlay is hidden by default. Toggle it in-game with `F3`, from the pause menu, or with the “Show FPS/status overlay” checkbox in the launcher. +## AppImage (AMD64) + +A local AppImage build script is included: + +```sh +./packaging/build-appimage.sh +``` + +It builds the core and frontend, downloads the AppImage tools into +`packaging/tools/`, creates `dist/AppDir`, and produces: + +- `dist/TsundereStation--x86_64.AppImage` +- `dist/TsundereStation-x86_64.AppImage` (stable symlink) + +The AppImage bundles `swanstation_libretro.so`, the desktop file, the icon, the +license, and a source note, so no separate core installation is needed. + +Current builds target **Debian 13 / glibc 2.41 or newer**. Build on an older +distribution if you need a wider glibc baseline. This is a local-only build for +now; a future Debian 13 Forgejo Runner can reuse the script with +`--skip-build` after performing its own core/frontend build. + +Useful options: + +```sh +# Reuse already-built binaries +./packaging/build-appimage.sh --skip-build + +# Build without running the AppImage selftest +./packaging/build-appimage.sh --no-test +``` + +Run the result: + +```sh +chmod +x dist/TsundereStation-x86_64.AppImage +./dist/TsundereStation-x86_64.AppImage +``` + +AppImage type 2 requires FUSE2 on some systems. If FUSE is unavailable, run: + +```sh +./dist/TsundereStation-x86_64.AppImage --appimage-extract-and-run +``` + +Optional desktop integration is provided by tools such as AppImageLauncher; the +AppImage itself runs standalone. The app’s config, BIOS, saves and states still +live under the usual `~/.config/tsunderestation` and +`~/.local/share/tsunderestation` paths. + ## Data locations Following the XDG base directory spec: diff --git a/frontend/packaging/build-appimage.sh b/frontend/packaging/build-appimage.sh new file mode 100755 index 00000000..eca6017b --- /dev/null +++ b/frontend/packaging/build-appimage.sh @@ -0,0 +1,181 @@ +#!/usr/bin/env bash +# +# Build a local AMD64 AppImage for TsundereStation. +# +# The resulting AppImage uses the build host's glibc as its minimum. On +# Debian 13 / glibc 2.41, it targets Debian 13 or newer. Build on an older +# distro if you need wider compatibility. +# +# Usage: +# ./packaging/build-appimage.sh [--skip-build] [--no-test] +# +# Tools are cached in packaging/tools unless TSUNDERESTATION_APPIMAGE_TOOLS +# points elsewhere. +# +set -euo pipefail + +say() { printf '%s\n' "$*"; } +die() { printf 'error: %s\n' "$*" >&2; exit 1; } + +for cmd in curl make cargo install strip readelf; do + command -v "$cmd" >/dev/null 2>&1 || die "missing required command: $cmd" +done + +[[ "$(uname -m)" == "x86_64" ]] || die "this script builds AMD64/x86_64 AppImages only" + +here="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +frontend="$(cd "$here/.." && pwd)" +repo="$(cd "$frontend/.." && pwd)" +dist="$frontend/dist" +appdir="$dist/AppDir" +bin="$frontend/target/release/tsunderestation" +core="$repo/swanstation_libretro.so" +tools="${TSUNDERESTATION_APPIMAGE_TOOLS:-$here/tools}" +desktop="$here/tsunderestation.desktop" +icon="$frontend/assets/tsunderestation.png" +version="$(sed -n 's/^version = "\([^"]*\)"/\1/p' "$frontend/Cargo.toml" | head -n1)" +[[ -n "$version" ]] || die "could not read version from frontend/Cargo.toml" + +skip_build=0 +run_test=1 +for arg in "$@"; do + case "$arg" in + --skip-build) skip_build=1 ;; + --no-test) run_test=0 ;; + -h|--help) + cat <<'EOF' +Usage: ./packaging/build-appimage.sh [--skip-build] [--no-test] + +Build a local AMD64 AppImage for TsundereStation. + +Options: + --skip-build Reuse existing core and frontend binaries. + --no-test Do not run the AppImage selftest after building. + -h, --help Show this help. + +The AppImage tools are cached in packaging/tools. Set +TSUNDERESTATION_APPIMAGE_TOOLS to use a different cache directory. +The resulting AppImage requires the build host's glibc or newer. +EOF + exit 0 + ;; + *) + die "unknown argument: $arg (try --help)" + ;; + esac +done + +say "TsundereStation AppImage build" +say " repo: $repo" +say " version: $version" +if [[ -f /etc/os-release ]]; then + # shellcheck disable=SC1091 + . /etc/os-release + say " host: ${PRETTY_NAME:-unknown}" +fi +if command -v ldd >/dev/null 2>&1; then + say " glibc: $(ldd --version 2>/dev/null | head -n1 || true)" +fi + +if [[ "$skip_build" -eq 0 ]]; then + say "Building core..." + (cd "$repo" && make -f Makefile.libretro platform=unix -j"$(nproc)") + say "Building frontend..." + (cd "$frontend" && cargo build --release) +fi + +[[ -x "$bin" ]] || die "missing frontend binary: $bin (run without --skip-build first)" +[[ -f "$core" ]] || die "missing core library: $core (run without --skip-build first)" +readelf -h "$bin" | grep -q "X86-64" || die "frontend binary is not x86_64" +readelf -h "$core" | grep -q "X86-64" || die "core library is not x86_64" +[[ -f "$desktop" ]] || die "missing desktop file: $desktop" +[[ -f "$icon" ]] || die "missing icon: $icon" + +mkdir -p "$tools" +fetch_tool() { + local url="$1" output="$2" + if [[ ! -s "$output" ]]; then + say "Downloading $(basename "$output")..." + curl -fL --retry 3 -o "$output.tmp" "$url" + mv "$output.tmp" "$output" + fi + chmod +x "$output" +} +fetch_tool \ + "https://github.com/linuxdeploy/linuxdeploy/releases/download/1-alpha-20251107-1/linuxdeploy-x86_64.AppImage" \ + "$tools/linuxdeploy-x86_64.AppImage" +fetch_tool \ + "https://github.com/AppImage/appimagetool/releases/download/continuous/appimagetool-x86_64.AppImage" \ + "$tools/appimagetool-x86_64.AppImage" + +rm -rf "$appdir" +mkdir -p "$appdir" + +say "Deploying frontend and libraries with linuxdeploy..." +"$tools/linuxdeploy-x86_64.AppImage" --appimage-extract-and-run \ + --appdir "$appdir" \ + --executable "$bin" \ + --desktop-file "$desktop" \ + --icon-file "$icon" + +say "Adding bundled core, license and source note..." +install -Dm644 "$core" "$appdir/usr/lib/libretro/swanstation_libretro.so" +install -Dm644 "$repo/LICENSE" "$appdir/usr/share/doc/tsunderestation/LICENSE" +source_url="$(git -C "$repo" remote get-url origin 2>/dev/null || true)" +[[ -n "$source_url" ]] || source_url="https://github.com/libretro/swanstation" +cat > "$appdir/usr/share/doc/tsunderestation/SOURCE" </dev/null || true +strip --strip-unneeded "$appdir/usr/lib/libretro/swanstation_libretro.so" 2>/dev/null || true + +out="$dist/TsundereStation-${version}-x86_64.AppImage" +stable="$dist/TsundereStation-x86_64.AppImage" +mkdir -p "$dist" +rm -f "$out" "$stable" + +say "Creating AppImage..." +ARCH=x86_64 VERSION="$version" \ + "$tools/appimagetool-x86_64.AppImage" --appimage-extract-and-run --no-appstream \ + "$appdir" "$out" + +ln -sfn "$(basename "$out")" "$stable" + +if [[ "$run_test" -eq 1 ]]; then + say "Running AppImage selftest..." + tmp="$(mktemp -d)" + cleanup() { + rm -rf "$tmp" + rm -rf /tmp/tsunderestation-selftest + rm -f /tmp/tsunderestation-selftest.ppm + rm -f /tmp/tsunderestation-selftest.state + } + trap cleanup EXIT + if ! XDG_CONFIG_HOME="$tmp/config" XDG_DATA_HOME="$tmp/data" \ + "$out" --appimage-extract-and-run --selftest 2>&1 | tee "$tmp/selftest.log"; then + die "AppImage selftest failed" + fi + grep -q "selftest ok" "$tmp/selftest.log" || die "AppImage selftest did not report success" + say "AppImage selftest passed." +fi + +say "" +say "Built:" +say " $out" +say " $stable -> $(basename "$out")" +say " size: $(du -h "$out" | cut -f1)" +say "" +say "Run it with:" +say " $stable" +say "" +say "The AppImage requires glibc >= the build host's glibc. If it is not" +say "executable directly, install FUSE2 or run:" +say " $out --appimage-extract-and-run"