From 59b70b6adb773b88b81d6a317cd4b3f578cfea9c Mon Sep 17 00:00:00 2001 From: Stenzek Date: Sat, 2 Sep 2023 16:54:51 +1000 Subject: [PATCH] Build: Add Flatpak manifest and scripts --- CMakeLists.txt | 7 +- scripts/flatpak/.gitignore | 5 ++ scripts/flatpak/duckstation-qt.desktop | 9 +++ scripts/flatpak/generate-metainfo.sh | 31 +++++++++ scripts/flatpak/install-packages.sh | 67 +++++++++++++++++++ scripts/flatpak/modules/20-sdl2.json | 45 +++++++++++++ scripts/flatpak/modules/21-libbacktrace.json | 22 ++++++ .../flatpak/org.duckstation.duckstation.json | 57 ++++++++++++++++ ...rg.duckstation.duckstation.metainfo.xml.in | 34 ++++++++++ src/CMakeLists.txt | 11 +-- 10 files changed, 281 insertions(+), 7 deletions(-) create mode 100644 scripts/flatpak/.gitignore create mode 100644 scripts/flatpak/duckstation-qt.desktop create mode 100755 scripts/flatpak/generate-metainfo.sh create mode 100755 scripts/flatpak/install-packages.sh create mode 100644 scripts/flatpak/modules/20-sdl2.json create mode 100644 scripts/flatpak/modules/21-libbacktrace.json create mode 100644 scripts/flatpak/org.duckstation.duckstation.json create mode 100644 scripts/flatpak/org.duckstation.duckstation.metainfo.xml.in diff --git a/CMakeLists.txt b/CMakeLists.txt index 0d921a36d..8d0cc1bcb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -26,6 +26,7 @@ endif() option(BUILD_NOGUI_FRONTEND "Build the NoGUI frontend" OFF) option(BUILD_QT_FRONTEND "Build the Qt frontend" ON) option(BUILD_REGTEST "Build regression test runner" OFF) +option(BUILD_TESTS "Build unit tests" OFF) option(ENABLE_CUBEB "Build with Cubeb audio output" ON) option(ENABLE_OPENGL "Build with OpenGL renderer" ON) option(ENABLE_VULKAN "Build with Vulkan renderer" ON) @@ -77,7 +78,7 @@ if(NOT WIN32 AND NOT ANDROID) find_package(CURL REQUIRED) endif() if(BUILD_QT_FRONTEND) - find_package(Qt6 6.5.2 COMPONENTS Core Gui Widgets Network LinguistTools REQUIRED) + find_package(Qt6 6.5.1 COMPONENTS Core Gui Widgets Network LinguistTools REQUIRED) endif() @@ -221,9 +222,11 @@ if((LINUX OR FREEBSD) AND (${CPU_ARCH} STREQUAL "x86" OR ${CPU_ARCH} STREQUAL "a add_definitions("-D_FILE_OFFSET_BITS=64") endif() +if(BUILD_TESTS) + enable_testing() +endif() # Recursively include the source tree. -enable_testing() add_subdirectory(dep) add_subdirectory(src) diff --git a/scripts/flatpak/.gitignore b/scripts/flatpak/.gitignore new file mode 100644 index 000000000..006124b0c --- /dev/null +++ b/scripts/flatpak/.gitignore @@ -0,0 +1,5 @@ +.flatpak-builder/ +build/ +repo/ +org.duckstation.duckstation.metainfo.xml +*.flatpak diff --git a/scripts/flatpak/duckstation-qt.desktop b/scripts/flatpak/duckstation-qt.desktop new file mode 100644 index 000000000..d6adb9f6c --- /dev/null +++ b/scripts/flatpak/duckstation-qt.desktop @@ -0,0 +1,9 @@ +[Desktop Entry] +Type=Application +Name=DuckStation +GenericName=PlayStation 1 Emulator +Comment=Fast PlayStation 1 emulator +Icon=duckstation-qt +TryExec=duckstation-qt +Exec=duckstation-qt %f +Categories=Game;Emulator;Qt; diff --git a/scripts/flatpak/generate-metainfo.sh b/scripts/flatpak/generate-metainfo.sh new file mode 100755 index 000000000..c3b65d311 --- /dev/null +++ b/scripts/flatpak/generate-metainfo.sh @@ -0,0 +1,31 @@ +#!/usr/bin/env bash + +SCRIPTDIR=$(dirname "${BASH_SOURCE[0]}") + +if [[ $# -lt 1 ]]; then + echo "Output file must be provided as a parameter" + exit 1 +fi + +OUTFILE=$1 +GIT_DATE=$(git log -1 --pretty=%cd --date=short) +GIT_VERSION=$(git tag --points-at HEAD) +GIT_HASH=$(git rev-parse HEAD) + +if [[ "${GIT_VERSION}" == "" ]]; then + GIT_VERSION=$(git describe --tags --dirty --exclude latest --exclude preview --exclude legacy --exclude previous-latest | tr -d '\r\n') + if [[ "${GIT_VERSION}" == "" ]]; then + GIT_VERSION=$(git rev-parse HEAD) + fi +fi + +echo "GIT_DATE: ${GIT_DATE}" +echo "GIT_VERSION: ${GIT_VERSION}" +echo "GIT_HASH: ${GIT_HASH}" + +cp "${SCRIPTDIR}"/org.duckstation.duckstation.metainfo.xml.in "${OUTFILE}" + +sed -i -e "s/@GIT_VERSION@/${GIT_VERSION}/" "${OUTFILE}" +sed -i -e "s/@GIT_DATE@/${GIT_DATE}/" "${OUTFILE}" +sed -i -e "s/@GIT_HASH@/${GIT_HASH}/" "${OUTFILE}" + diff --git a/scripts/flatpak/install-packages.sh b/scripts/flatpak/install-packages.sh new file mode 100755 index 000000000..cf6428dd9 --- /dev/null +++ b/scripts/flatpak/install-packages.sh @@ -0,0 +1,67 @@ +#!/bin/bash + +set -e + +SCRIPTDIR=$(dirname "${BASH_SOURCE[0]}") + +function retry_command { + # Package servers tend to be unreliable at times.. + # Retry a bunch of times. + local RETRIES=10 + + for i in $(seq 1 "$RETRIES"); do + "$@" && break + if [ "$i" == "$RETRIES" ]; then + echo "Command \"$@\" failed after ${RETRIES} retries." + exit 1 + fi + done +} + +ARCH=x86_64 +KDE_BRANCH=6.5 +BRANCH=22.08 +FLAT_MANAGER_CLIENT_DIR="$HOME/.local/bin" + +# Build packages. Mostly needed for flat-manager-client. +declare -a BUILD_PACKAGES=( + "flatpak" + "flatpak-builder" + "appstream-util" + "python3-aiohttp" + "python3-tenacity" + "python3-gi" + "gobject-introspection" + "libappstream-glib8" + "libappstream-glib-dev" + "libappstream-dev" + "gir1.2-ostree-1.0" +) + +# Flatpak runtimes and SDKs. +declare -a FLATPAK_PACKAGES=( + "org.kde.Platform/${ARCH}/${KDE_BRANCH}" + "org.kde.Sdk/${ARCH}/${KDE_BRANCH}" + "org.freedesktop.Sdk.Extension.llvm16/${ARCH}/${BRANCH}" + "org.freedesktop.appstream-glib/${ARCH}/stable" +) + +retry_command sudo apt-get -qq update + +# Install packages needed for building +echo "Will install the following packages for building - ${BUILD_PACKAGES[*]}" +retry_command sudo apt-get -y install "${BUILD_PACKAGES[@]}" + +sudo flatpak remote-add --if-not-exists flathub https://flathub.org/repo/flathub.flatpakrepo + +# Install packages needed for building +echo "Will install the following packages for building - ${FLATPAK_PACKAGES[*]}" +retry_command sudo flatpak -y install "${FLATPAK_PACKAGES[@]}" + +echo "Downloading flat-manager-client" +mkdir -p "$FLAT_MANAGER_CLIENT_DIR" +pushd "$FLAT_MANAGER_CLIENT_DIR" +aria2c -Z "https://raw.githubusercontent.com/flatpak/flat-manager/9401efbdc0d6bd489507d8401c567ba219d735d5/flat-manager-client" +chmod +x flat-manager-client +echo "$FLAT_MANAGER_CLIENT_DIR" >> $GITHUB_PATH +popd diff --git a/scripts/flatpak/modules/20-sdl2.json b/scripts/flatpak/modules/20-sdl2.json new file mode 100644 index 000000000..1f65c07ec --- /dev/null +++ b/scripts/flatpak/modules/20-sdl2.json @@ -0,0 +1,45 @@ +{ + "name": "sdl2", + "buildsystem": "autotools", + "no-autogen": true, + "config-opts": [ + "--disable-dbus", + "--without-x", + "--disable-video-opengl", + "--disable-video-opengles", + "--disable-video-vulkan", + "--disable-wayland-shared", + "--disable-ime", + "--disable-oss", + "--disable-alsa", + "--disable-jack", + "--disable-esd", + "--disable-pipewire", + "--disable-pulseaudio", + "--disable-arts", + "--disable-nas", + "--disable-sndio", + "--disable-fusionsound", + "--disable-diskaudio" + ], + "build-options": { + "strip": true + }, + "sources": [ + { + "type": "archive", + "url": "https://libsdl.org/release/SDL2-2.28.2.tar.gz", + "sha256": "64b1102fa22093515b02ef33dd8739dee1ba57e9dbba6a092942b8bbed1a1c5e" + } + ], + "cleanup": [ + "/bin", + "/include", + "/lib/*.a", + "/lib/*.la", + "/lib/cmake", + "/lib/pkgconfig", + "/share/aclocal" + ] +} + diff --git a/scripts/flatpak/modules/21-libbacktrace.json b/scripts/flatpak/modules/21-libbacktrace.json new file mode 100644 index 000000000..96b3a4203 --- /dev/null +++ b/scripts/flatpak/modules/21-libbacktrace.json @@ -0,0 +1,22 @@ +{ + "name": "libbacktrace", + "buildsystem": "autotools", + "no-autogen": true, + "build-options": { + "strip": false, + "no-debuginfo": true + }, + "sources": [ + { + "type": "git", + "url": "https://github.com/ianlancetaylor/libbacktrace.git", + "commit": "ad106d5fdd5d960bd33fae1c48a351af567fd075" + } + ], + "cleanup": [ + "/include", + "/lib/*.a", + "/lib/*.la" + ] + } + diff --git a/scripts/flatpak/org.duckstation.duckstation.json b/scripts/flatpak/org.duckstation.duckstation.json new file mode 100644 index 000000000..b95a29821 --- /dev/null +++ b/scripts/flatpak/org.duckstation.duckstation.json @@ -0,0 +1,57 @@ +{ + "app-id": "org.duckstation.duckstation", + "runtime": "org.kde.Platform", + "runtime-version": "6.5", + "sdk": "org.kde.Sdk", + "sdk-extensions": [ + "org.freedesktop.Sdk.Extension.llvm16" + ], + "command": "duckstation-qt", + "finish-args": [ + "--device=all", + "--share=network", + "--share=ipc", + "--socket=fallback-x11", + "--socket=wayland", + "--socket=pulseaudio", + "--filesystem=host:ro", + "--talk-name=org.freedesktop.ScreenSaver" + ], + "modules": [ + "modules/20-sdl2.json", + "modules/21-libbacktrace.json", + { + "name": "duckstation", + "buildsystem": "cmake", + "build-options": { + "strip": false, + "no-debuginfo": true, + "config-opts": [ + "-DCMAKE_BUILD_TYPE=Release", + "-DCMAKE_INTERPROCEDURAL_OPTIMIZATION=ON", + "-DBUILD_NOGUI_FRONTEND=OFF", + "-DBUILD_QT_FRONTEND=ON", + "-DBUILD_TESTS=OFF", + "-DCMAKE_C_COMPILER=/usr/lib/sdk/llvm16/bin/clang", + "-DCMAKE_CXX_COMPILER=/usr/lib/sdk/llvm16/bin/clang++", + "-DCMAKE_EXE_LINKER_FLAGS_INIT=-fuse-ld=lld", + "-DCMAKE_MODULE_LINKER_FLAGS_INIT=-fuse-ld=lld", + "-DCMAKE_SHARED_LINKER_FLAGS_INIT=-fuse-ld=lld" + ] + }, + "sources": [ + { + "type": "dir", + "path": "../.." + } + ], + "post-install": [ + "cp -a \"${FLATPAK_BUILDER_BUILDDIR}/bin\" ${FLATPAK_DEST}", + "install -Dm644 data/resources/images/duck.png ${FLATPAK_DEST}/share/icons/hicolor/512x512/apps/org.duckstation.duckstation.png", + "install -Dm644 scripts/flatpak/duckstation-qt.desktop ${FLATPAK_DEST}/share/applications/org.duckstation.duckstation.desktop", + "desktop-file-edit --set-key=Icon --set-value=org.duckstation.duckstation ${FLATPAK_DEST}/share/applications/org.duckstation.duckstation.desktop", + "install -Dm644 scripts/flatpak/org.duckstation.duckstation.metainfo.xml ${FLATPAK_DEST}/share/metainfo/org.duckstation.duckstation.metainfo.xml" + ] + } + ] +} diff --git a/scripts/flatpak/org.duckstation.duckstation.metainfo.xml.in b/scripts/flatpak/org.duckstation.duckstation.metainfo.xml.in new file mode 100644 index 000000000..a3f52b933 --- /dev/null +++ b/scripts/flatpak/org.duckstation.duckstation.metainfo.xml.in @@ -0,0 +1,34 @@ + + + org.duckstation.duckstation + org.duckstation.duckstation.desktop + CC0-1.0 + GPL-3.0 + DuckStation + DuckStation + PlayStation Emulator + +

DuckStation is an simulator/emulator of the Sony PlayStation(TM) console, focusing on playability, speed, and long-term maintainability. The goal is to be as accurate as possible while maintaining performance suitable for low-end devices.

+

"Hack" options are discouraged, the default configuration should support all playable games with only some of the enhancements having compatibility issues.

+

"PlayStation" and "PSX" are registered trademarks of Sony Interactive Entertainment Europe Limited. This project is not affiliated in any way with Sony Interactive Entertainment.

+
+ https://www.duckstation.org/ + https://github.com/stenzek/duckstation + https://github.com/stenzek/duckstation + + + https://raw.githubusercontent.com/stenzek/duckstation/md-images/main-qt.png + + + https://raw.githubusercontent.com/stenzek/duckstation/md-images/bigduck.png + + + + stenzek_AT_gmail.com + + + + + https://raw.githubusercontent.com/stenzek/duckstation/@GIT_HASH@/scripts/flatpak/org.duckstation.duckstation.json + +
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index c8a8d755a..d8d693ddd 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -3,11 +3,8 @@ add_subdirectory(util) add_subdirectory(core) add_subdirectory(scmversion) -if(NOT ANDROID) - add_subdirectory(common-tests) - if(WIN32) - add_subdirectory(updater) - endif() +if(WIN32) + add_subdirectory(updater) endif() if(BUILD_NOGUI_FRONTEND) @@ -21,3 +18,7 @@ endif() if(BUILD_REGTEST) add_subdirectory(duckstation-regtest) endif() + +if(BUILD_TESTS) + add_subdirectory(common-tests) +endif()