From 030dc4e7b14d656cdcc4aa733f5be2434bea004f Mon Sep 17 00:00:00 2001 From: Seth Flynn Date: Thu, 27 Nov 2025 16:48:16 -0500 Subject: [PATCH 1/4] ci(setup-dependencies/linux): use deps from system Signed-off-by: Seth Flynn --- .github/actions/setup-dependencies/linux/action.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/actions/setup-dependencies/linux/action.yml b/.github/actions/setup-dependencies/linux/action.yml index 610126442..877b8aa6e 100644 --- a/.github/actions/setup-dependencies/linux/action.yml +++ b/.github/actions/setup-dependencies/linux/action.yml @@ -9,9 +9,9 @@ runs: run: | sudo apt-get -y update sudo apt-get -y install \ - dpkg-dev libarchive-dev \ - ninja-build extra-cmake-modules scdoc \ - libqrencode-dev \ + dpkg-dev \ + ninja-build extra-cmake-modules pkg-config scdoc \ + cmark-dev libarchive-dev libqrencode-dev tomlplusplus-dev zlib-dev \ appstream libxcb-cursor-dev - name: Setup AppImage tooling From dc774aa424033d692ff4f1cf3f80dc24f3e510e7 Mon Sep 17 00:00:00 2001 From: Seth Flynn Date: Thu, 27 Nov 2025 16:04:39 -0500 Subject: [PATCH 2/4] build(cmake): remove `Launcher_FORCE_BUNDLED_LIBS` option As we won't be providing "bundled" libraries anymore, this option is basically pointless Signed-off-by: Seth Flynn --- CMakeLists.txt | 39 ++++++++++++++------------------------- 1 file changed, 14 insertions(+), 25 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 27d5108ba..3fbf33554 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -244,7 +244,6 @@ set(Launcher_DISCORD_URL "https://prismlauncher.org/discord" CACHE STRING "URL f set(Launcher_SUBREDDIT_URL "https://prismlauncher.org/reddit" CACHE STRING "URL for the subreddit.") # Builds -set(Launcher_FORCE_BUNDLED_LIBS OFF CACHE BOOL "Prevent using system libraries, if they are available as submodules") set(Launcher_QT_VERSION_MAJOR "6" CACHE STRING "Major Qt version to build against") # Java downloader @@ -309,16 +308,6 @@ set(Launcher_BUILD_TIMESTAMP "${TODAY}") ################################ 3rd Party Libs ################################ -# Successive configurations of cmake without cleaning the build dir will cause zlib fallback to fail due to cached values -# Record when fallback triggered and skip this find_package -if(NOT Launcher_FORCE_BUNDLED_LIBS AND NOT FORCE_BUNDLED_ZLIB) - find_package(ZLIB QUIET) -endif() -if(NOT ZLIB_FOUND) - set(FORCE_BUNDLED_ZLIB TRUE CACHE BOOL "") - mark_as_advanced(FORCE_BUNDLED_ZLIB) -endif() - # Find the required Qt parts include(QtVersionlessBackport) if(Launcher_QT_VERSION_MAJOR EQUAL 6) @@ -357,22 +346,20 @@ if(NOT LibArchive_FOUND) pkg_check_modules(libarchive REQUIRED IMPORTED_TARGET libarchive) endif() -if(NOT Launcher_FORCE_BUNDLED_LIBS) - # Find toml++ - find_package(tomlplusplus 3.2.0 QUIET) - # Fallback to pkg-config (if available) if CMake files aren't found - if(NOT tomlplusplus_FOUND) - find_package(PkgConfig QUIET) - if(PkgConfig_FOUND) - pkg_check_modules(tomlplusplus IMPORTED_TARGET tomlplusplus>=3.2.0) - endif() +# Find toml++ +find_package(tomlplusplus 3.2.0 QUIET) +# Fallback to pkg-config (if available) if CMake files aren't found +if(NOT tomlplusplus_FOUND) + find_package(PkgConfig QUIET) + if(PkgConfig_FOUND) + pkg_check_modules(tomlplusplus IMPORTED_TARGET tomlplusplus>=3.2.0) endif() - - - # Find cmark - find_package(cmark QUIET) endif() + +# Find cmark +find_package(cmark QUIET) + include(ECMQtDeclareLoggingCategory) ####################################### Program Info ####################################### @@ -479,7 +466,9 @@ add_subdirectory(libraries/libnbtplusplus) add_subdirectory(libraries/systeminfo) # system information library add_subdirectory(libraries/launcher) # java based launcher part for Minecraft add_subdirectory(libraries/javacheck) # java compatibility checker -if(FORCE_BUNDLED_ZLIB) + +find_package(ZLIB QUIET) +if(NOT ZLIB_FOUND) message(STATUS "Using bundled zlib") set(CMAKE_POLICY_DEFAULT_CMP0069 NEW) # Suppress cmake warnings and allow INTERPROCEDURAL_OPTIMIZATION for zlib From e2c31569dc827247076c7c138ecbe43309522207 Mon Sep 17 00:00:00 2001 From: Seth Flynn Date: Thu, 27 Nov 2025 16:09:52 -0500 Subject: [PATCH 3/4] build: remove third party submodules Most of these are extremely common in distributions now, so packagers don't have much need for our in-tree versions - most don't even use them as is With our move to vcpkg for Windows/macOS, we also don't have a need for them. So time to say goodbye! Signed-off-by: Seth Flynn --- .../setup-dependencies/linux/action.yml | 24 +++++- .gitmodules | 12 --- CMakeLists.txt | 82 ++----------------- flatpak/cmark.yml | 14 ++++ flatpak/org.prismlauncher.PrismLauncher.yml | 3 + flatpak/tomlplusplus.yml | 6 ++ libraries/README.md | 32 -------- libraries/cmark | 1 - libraries/extra-cmake-modules | 1 - libraries/tomlplusplus | 1 - libraries/zlib | 1 - 11 files changed, 54 insertions(+), 123 deletions(-) create mode 100644 flatpak/cmark.yml create mode 100644 flatpak/tomlplusplus.yml delete mode 160000 libraries/cmark delete mode 160000 libraries/extra-cmake-modules delete mode 160000 libraries/tomlplusplus delete mode 160000 libraries/zlib diff --git a/.github/actions/setup-dependencies/linux/action.yml b/.github/actions/setup-dependencies/linux/action.yml index 877b8aa6e..e47941ce3 100644 --- a/.github/actions/setup-dependencies/linux/action.yml +++ b/.github/actions/setup-dependencies/linux/action.yml @@ -11,9 +11,31 @@ runs: sudo apt-get -y install \ dpkg-dev \ ninja-build extra-cmake-modules pkg-config scdoc \ - cmark-dev libarchive-dev libqrencode-dev tomlplusplus-dev zlib-dev \ + cmark libarchive-dev libcmark-dev libqrencode-dev zlib1g-dev \ appstream libxcb-cursor-dev + # TODO(@getchoo): Install with the above when all targets use Ubuntu 24.04 + - name: Install tomlplusplus + if: ${{ runner.arch == 'ARM64' }} + shell: bash + run: | + sudo apt-get -y install libtomlplusplus-dev + + # FIXME(@getchoo): THIS IS HORRIBLE TO DO! + # Install tomlplusplus from Ubuntu 24.04, since it never got backported to 22.04 + # I've done too much to continue keeping this as a submodule.... + - name: Install tomlplusplus from 24.04 + if: ${{ runner.arch != 'ARM64' }} + shell: bash + run: | + deb_arch="$(dpkg-architecture -q DEB_HOST_ARCH)" + curl -Lo libtomlplusplus-dev.deb http://mirrors.kernel.org/ubuntu/pool/universe/t/tomlplusplus/libtomlplusplus-dev_3.4.0+ds-0.2build1_"$deb_arch".deb + curl -Lo libtomlplusplus3t64.deb http://mirrors.kernel.org/ubuntu/pool/universe/t/tomlplusplus/libtomlplusplus3t64_3.4.0+ds-0.2build1_"$deb_arch".deb + sudo dpkg -i libtomlplusplus3t64.deb + sudo dpkg -i libtomlplusplus-dev.deb + rm *.deb + sudo apt-get install -f + - name: Setup AppImage tooling shell: bash run: | diff --git a/.gitmodules b/.gitmodules index 246d9d791..f2d71ef29 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,18 +1,6 @@ -[submodule "libraries/tomlplusplus"] - path = libraries/tomlplusplus - url = https://github.com/marzer/tomlplusplus.git [submodule "libraries/libnbtplusplus"] path = libraries/libnbtplusplus url = https://github.com/PrismLauncher/libnbtplusplus.git -[submodule "libraries/zlib"] - path = libraries/zlib - url = https://github.com/madler/zlib.git -[submodule "libraries/extra-cmake-modules"] - path = libraries/extra-cmake-modules - url = https://github.com/KDE/extra-cmake-modules -[submodule "libraries/cmark"] - path = libraries/cmark - url = https://github.com/commonmark/cmark.git [submodule "flatpak/shared-modules"] path = flatpak/shared-modules url = https://github.com/flathub/shared-modules.git diff --git a/CMakeLists.txt b/CMakeLists.txt index 3fbf33554..0cefd727a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -104,9 +104,6 @@ endif() set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DQT_WARN_DEPRECATED_UP_TO=0x060200") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DQT_DISABLE_DEPRECATED_UP_TO=0x060000") -# Fix aarch64 build for toml++ -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DTOML_ENABLE_FLOAT16=0") - # set CXXFLAGS for build targets set(CMAKE_CXX_FLAGS_RELEASE "-O2 -D_FORTIFY_SOURCE=2 ${CMAKE_CXX_FLAGS_RELEASE}") @@ -174,20 +171,9 @@ endif() option(BUILD_TESTING "Build the testing tree." ON) -find_package(ECM QUIET NO_MODULE) -if(NOT ECM_FOUND) - if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/libraries/extra-cmake-modules/CMakeLists.txt") - message(STATUS "Using bundled ECM") - set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/libraries/extra-cmake-modules/modules;${CMAKE_MODULE_PATH}") - else() - message(FATAL_ERROR - " Could not find ECM\n \n" - " Either install ECM using the system package manager or clone submodules\n" - " Submodules can be cloned with 'git submodule update --init --recursive'") - endif() -else() - set(CMAKE_MODULE_PATH "${ECM_MODULE_PATH};${CMAKE_MODULE_PATH}") -endif() +find_package(ECM NO_MODULE REQUIRED) +set(CMAKE_MODULE_PATH "${ECM_MODULE_PATH};${CMAKE_MODULE_PATH}") + include(CTest) include(ECMAddTests) if(BUILD_TESTING) @@ -326,6 +312,8 @@ if(Launcher_QT_VERSION_MAJOR EQUAL 6) set(QT_LIBEXECS_DIR ${QT${QT_VERSION_MAJOR}_INSTALL_PREFIX}/${QT${QT_VERSION_MAJOR}_INSTALL_LIBEXECS}) endif() +find_package(cmark REQUIRED) + # Find libqrencode ## NOTE(@getchoo): Never use pkg-config with MSVC since the vcpkg port makes our install bundle fail to find the dll if(MSVC) @@ -339,27 +327,17 @@ else() endif() # Find libarchive through CMake packages, mainly for vcpkg -find_package(LibArchive QUIET) +find_package(LibArchive) # CMake packages aren't available in most distributions of libarchive, so fallback to pkg-config if(NOT LibArchive_FOUND) find_package(PkgConfig REQUIRED) pkg_check_modules(libarchive REQUIRED IMPORTED_TARGET libarchive) endif() -# Find toml++ -find_package(tomlplusplus 3.2.0 QUIET) -# Fallback to pkg-config (if available) if CMake files aren't found -if(NOT tomlplusplus_FOUND) - find_package(PkgConfig QUIET) - if(PkgConfig_FOUND) - pkg_check_modules(tomlplusplus IMPORTED_TARGET tomlplusplus>=3.2.0) - endif() -endif() +find_package(tomlplusplus 3.2.0 REQUIRED) +find_package(ZLIB REQUIRED) -# Find cmark -find_package(cmark QUIET) - include(ECMQtDeclareLoggingCategory) ####################################### Program Info ####################################### @@ -467,52 +445,8 @@ add_subdirectory(libraries/systeminfo) # system information library add_subdirectory(libraries/launcher) # java based launcher part for Minecraft add_subdirectory(libraries/javacheck) # java compatibility checker -find_package(ZLIB QUIET) -if(NOT ZLIB_FOUND) - message(STATUS "Using bundled zlib") - - set(CMAKE_POLICY_DEFAULT_CMP0069 NEW) # Suppress cmake warnings and allow INTERPROCEDURAL_OPTIMIZATION for zlib - set(SKIP_INSTALL_ALL ON) - add_subdirectory(libraries/zlib EXCLUDE_FROM_ALL) - - # On OS where unistd.h exists, zlib's generated header defines `Z_HAVE_UNISTD_H`, while the included header does not. - # We cannot safely undo the rename on those systems, and they generally have packages for zlib anyway. - check_include_file(unistd.h NEED_GENERATED_ZCONF) - if (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/libraries/zlib/zconf.h.included" AND NOT NEED_GENERATED_ZCONF) - # zlib's cmake script renames a file, dirtying the submodule, see https://github.com/madler/zlib/issues/162 - message(STATUS "Undoing Rename") - message(STATUS " ${CMAKE_CURRENT_SOURCE_DIR}/libraries/zlib/zconf.h") - file(RENAME "${CMAKE_CURRENT_SOURCE_DIR}/libraries/zlib/zconf.h.included" "${CMAKE_CURRENT_SOURCE_DIR}/libraries/zlib/zconf.h") - endif() - - set(ZLIB_INCLUDE_DIR "${CMAKE_CURRENT_BINARY_DIR}/libraries/zlib" "${CMAKE_CURRENT_SOURCE_DIR}/libraries/zlib" CACHE STRING "" FORCE) - set_target_properties(zlibstatic PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${ZLIB_INCLUDE_DIR}") - add_library(ZLIB::ZLIB ALIAS zlibstatic) - set(ZLIB_LIBRARY ZLIB::ZLIB CACHE STRING "zlib library name") - - find_package(ZLIB REQUIRED) -else() - message(STATUS "Using system zlib") -endif() add_subdirectory(libraries/rainbow) # Qt extension for colors add_subdirectory(libraries/LocalPeer) # fork of a library from Qt solutions -if(NOT tomlplusplus_FOUND) - message(STATUS "Using bundled tomlplusplus") - add_subdirectory(libraries/tomlplusplus) # toml parser -else() - message(STATUS "Using system tomlplusplus") -endif() -if(NOT cmark_FOUND) - message(STATUS "Using bundled cmark") - set(ORIGINAL_BUILD_TESTING ${BUILD_TESTING}) - set(BUILD_TESTING 0) - set(BUILD_SHARED_LIBS 0) - add_subdirectory(libraries/cmark EXCLUDE_FROM_ALL) # Markdown parser - add_library(cmark::cmark ALIAS cmark) - set(BUILD_TESTING ${ORIGINAL_BUILD_TESTING}) -else() - message(STATUS "Using system cmark") -endif() add_subdirectory(libraries/gamemode) add_subdirectory(libraries/murmur2) # Hash for usage with the CurseForge API add_subdirectory(libraries/qdcss) # css parser diff --git a/flatpak/cmark.yml b/flatpak/cmark.yml new file mode 100644 index 000000000..d5078baab --- /dev/null +++ b/flatpak/cmark.yml @@ -0,0 +1,14 @@ +name: cmark +buildsystem: cmake-ninja +builddir: true +config-opts: + - -DCMAKE_TESTS=OFF +sources: + - type: archive + url: https://github.com/commonmark/cmark/archive/0.31.1.tar.gz + sha256: 3da93db5469c30588cfeb283d9d62edfc6ded9eb0edc10a4f5bbfb7d722ea802 + x-checker-data: + type: anitya + project-id: 9159 + stable-only: true + url-template: https://github.com/commonmark/cmark/archive/$version.tar.gz diff --git a/flatpak/org.prismlauncher.PrismLauncher.yml b/flatpak/org.prismlauncher.PrismLauncher.yml index 136aef91a..80ed8158d 100644 --- a/flatpak/org.prismlauncher.PrismLauncher.yml +++ b/flatpak/org.prismlauncher.PrismLauncher.yml @@ -27,6 +27,9 @@ finish-args: - --filesystem=/sys/kernel/mm/transparent_hugepage:ro modules: + - cmark.yml + - tomlplusplus.yml + # Might be needed by some Controller mods (see https://github.com/isXander/Controlify/issues/31) - shared-modules/libusb/libusb.json diff --git a/flatpak/tomlplusplus.yml b/flatpak/tomlplusplus.yml new file mode 100644 index 000000000..0afaf6678 --- /dev/null +++ b/flatpak/tomlplusplus.yml @@ -0,0 +1,6 @@ +name: tomlplusplus +buildsystem: cmake-ninja +sources: + - type: archive + url: https://github.com/marzer/tomlplusplus/archive/v3.4.0.tar.gz + sha256: 8517f65938a4faae9ccf8ebb36631a38c1cadfb5efa85d9a72e15b9e97d25155 diff --git a/libraries/README.md b/libraries/README.md index 2ebb80515..8cd49d24b 100644 --- a/libraries/README.md +++ b/libraries/README.md @@ -10,14 +10,6 @@ See [github repo](https://github.com/FeralInteractive/gamemode). BSD-3-Clause licensed -## cmark - -The C reference implementation of CommonMark, a standardized Markdown spec. - -See [github_repo](https://github.com/commonmark/cmark). - -BSD2 licensed. - ## javacheck Simple Java tool that prints the JVM details - version and platform bitness. @@ -99,22 +91,6 @@ Canonical implementation of the murmur2 hash, taken from [SMHasher](https://gith Public domain (the author disclaimed the copyright). -## QR-Code-generator - -A simple library for generating QR codes - -See [github repo](https://github.com/nayuki/QR-Code-generator). - -MIT - -## libarchive - -Multi-format archive and compression library. - -See [github repo](https://github.com/libarchive/libarchive). - -BSD 2-Clause license with some exception. - ## rainbow Color functions extracted from [KGuiAddons](https://inqlude.org/libraries/kguiaddons.html). Used for adaptive text coloring. @@ -127,14 +103,6 @@ A Prism Launcher-specific library for probing system information. Apache 2.0 -## tomlplusplus - -A TOML language parser. Used by Forge 1.14+ to store mod metadata. - -See [github repo](https://github.com/marzer/tomlplusplus). - -Licenced under the MIT licence. - ## qdcss A quick and dirty css parser, used by NilLoader to store mod metadata. diff --git a/libraries/cmark b/libraries/cmark deleted file mode 160000 index 3460cd809..000000000 --- a/libraries/cmark +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 3460cd809b6dd311b58e92733ece2fc956224fd2 diff --git a/libraries/extra-cmake-modules b/libraries/extra-cmake-modules deleted file mode 160000 index 1f820dc98..000000000 --- a/libraries/extra-cmake-modules +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 1f820dc98d0a520c175433bcbb0098327d82aac6 diff --git a/libraries/tomlplusplus b/libraries/tomlplusplus deleted file mode 160000 index c4369ae1d..000000000 --- a/libraries/tomlplusplus +++ /dev/null @@ -1 +0,0 @@ -Subproject commit c4369ae1d8955cae20c4ab40b9813ef4b60e48be diff --git a/libraries/zlib b/libraries/zlib deleted file mode 160000 index 51b7f2abd..000000000 --- a/libraries/zlib +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 51b7f2abdade71cd9bb0e7a373ef2610ec6f9daf From 38afa3a94c12a73de83b38d9cba948f7490e8e65 Mon Sep 17 00:00:00 2001 From: Seth Flynn Date: Thu, 27 Nov 2025 16:19:51 -0500 Subject: [PATCH 4/4] build: remove vendored gamemode code Signed-off-by: Seth Flynn --- .../setup-dependencies/linux/action.yml | 2 +- CMakeLists.txt | 6 +- launcher/CMakeLists.txt | 2 +- libraries/README.md | 8 - libraries/gamemode/CMakeLists.txt | 7 - libraries/gamemode/include/gamemode_client.h | 337 ------------------ nix/unwrapped.nix | 6 +- nix/wrapper.nix | 2 +- 8 files changed, 9 insertions(+), 361 deletions(-) delete mode 100644 libraries/gamemode/CMakeLists.txt delete mode 100644 libraries/gamemode/include/gamemode_client.h diff --git a/.github/actions/setup-dependencies/linux/action.yml b/.github/actions/setup-dependencies/linux/action.yml index e47941ce3..c1cc517a3 100644 --- a/.github/actions/setup-dependencies/linux/action.yml +++ b/.github/actions/setup-dependencies/linux/action.yml @@ -11,7 +11,7 @@ runs: sudo apt-get -y install \ dpkg-dev \ ninja-build extra-cmake-modules pkg-config scdoc \ - cmark libarchive-dev libcmark-dev libqrencode-dev zlib1g-dev \ + cmark gamemode-dev libarchive-dev libcmark-dev libqrencode-dev zlib1g-dev \ appstream libxcb-cursor-dev # TODO(@getchoo): Install with the above when all targets use Ubuntu 24.04 diff --git a/CMakeLists.txt b/CMakeLists.txt index 0cefd727a..323ef58d4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -314,6 +314,11 @@ endif() find_package(cmark REQUIRED) +if(CMAKE_SYSTEM_NAME STREQUAL "Linux") + find_package(PkgConfig REQUIRED) + pkg_check_modules(gamemode REQUIRED IMPORTED_TARGET gamemode) +endif() + # Find libqrencode ## NOTE(@getchoo): Never use pkg-config with MSVC since the vcpkg port makes our install bundle fail to find the dll if(MSVC) @@ -447,7 +452,6 @@ add_subdirectory(libraries/javacheck) # java compatibility checker add_subdirectory(libraries/rainbow) # Qt extension for colors add_subdirectory(libraries/LocalPeer) # fork of a library from Qt solutions -add_subdirectory(libraries/gamemode) add_subdirectory(libraries/murmur2) # Hash for usage with the CurseForge API add_subdirectory(libraries/qdcss) # css parser diff --git a/launcher/CMakeLists.txt b/launcher/CMakeLists.txt index 37e1ebbdb..02fc1321a 100644 --- a/launcher/CMakeLists.txt +++ b/launcher/CMakeLists.txt @@ -1336,7 +1336,7 @@ else() target_link_libraries(Launcher_logic LibArchive::LibArchive) endif() -if (UNIX AND NOT CYGWIN AND NOT APPLE) +if (CMAKE_SYSTEM_NAME STREQUAL "Linux") target_link_libraries(Launcher_logic gamemode ) diff --git a/libraries/README.md b/libraries/README.md index 8cd49d24b..df4d251f7 100644 --- a/libraries/README.md +++ b/libraries/README.md @@ -2,14 +2,6 @@ This folder has third-party or otherwise external libraries needed for other parts to work. -## gamemode - -A performance optimization daemon. - -See [github repo](https://github.com/FeralInteractive/gamemode). - -BSD-3-Clause licensed - ## javacheck Simple Java tool that prints the JVM details - version and platform bitness. diff --git a/libraries/gamemode/CMakeLists.txt b/libraries/gamemode/CMakeLists.txt deleted file mode 100644 index 61195ac21..000000000 --- a/libraries/gamemode/CMakeLists.txt +++ /dev/null @@ -1,7 +0,0 @@ -cmake_minimum_required(VERSION 3.15) -project(gamemode - VERSION 1.6.1) - -add_library(gamemode) -target_include_directories(gamemode PUBLIC include) -target_link_libraries(gamemode PUBLIC ${CMAKE_DL_LIBS}) diff --git a/libraries/gamemode/include/gamemode_client.h b/libraries/gamemode/include/gamemode_client.h deleted file mode 100644 index b186cd489..000000000 --- a/libraries/gamemode/include/gamemode_client.h +++ /dev/null @@ -1,337 +0,0 @@ -/* - -Copyright (c) 2017-2019, Feral Interactive -All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: - - * Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - * Neither the name of Feral Interactive nor the names of its contributors - may be used to endorse or promote products derived from this software - without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE -LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -POSSIBILITY OF SUCH DAMAGE. - - */ -#ifndef CLIENT_GAMEMODE_H -#define CLIENT_GAMEMODE_H -/* - * GameMode supports the following client functions - * Requests are refcounted in the daemon - * - * int gamemode_request_start() - Request gamemode starts - * 0 if the request was sent successfully - * -1 if the request failed - * - * int gamemode_request_end() - Request gamemode ends - * 0 if the request was sent successfully - * -1 if the request failed - * - * GAMEMODE_AUTO can be defined to make the above two functions apply during static init and - * destruction, as appropriate. In this configuration, errors will be printed to stderr - * - * int gamemode_query_status() - Query the current status of gamemode - * 0 if gamemode is inactive - * 1 if gamemode is active - * 2 if gamemode is active and this client is registered - * -1 if the query failed - * - * int gamemode_request_start_for(pid_t pid) - Request gamemode starts for another process - * 0 if the request was sent successfully - * -1 if the request failed - * -2 if the request was rejected - * - * int gamemode_request_end_for(pid_t pid) - Request gamemode ends for another process - * 0 if the request was sent successfully - * -1 if the request failed - * -2 if the request was rejected - * - * int gamemode_query_status_for(pid_t pid) - Query status of gamemode for another process - * 0 if gamemode is inactive - * 1 if gamemode is active - * 2 if gamemode is active and this client is registered - * -1 if the query failed - * - * const char* gamemode_error_string() - Get an error string - * returns a string describing any of the above errors - * - * Note: All the above requests can be blocking - dbus requests can and will block while the daemon - * handles the request. It is not recommended to make these calls in performance critical code - */ - -#include -#include - -#include -#include - -#include - -static char internal_gamemode_client_error_string[512] = { 0 }; - -/** - * Load libgamemode dynamically to dislodge us from most dependencies. - * This allows clients to link and/or use this regardless of runtime. - * See SDL2 for an example of the reasoning behind this in terms of - * dynamic versioning as well. - */ -static volatile int internal_libgamemode_loaded = 1; - -/* Typedefs for the functions to load */ -typedef int (*api_call_return_int)(void); -typedef const char* (*api_call_return_cstring)(void); -typedef int (*api_call_pid_return_int)(pid_t); - -/* Storage for functors */ -static api_call_return_int REAL_internal_gamemode_request_start = NULL; -static api_call_return_int REAL_internal_gamemode_request_end = NULL; -static api_call_return_int REAL_internal_gamemode_query_status = NULL; -static api_call_return_cstring REAL_internal_gamemode_error_string = NULL; -static api_call_pid_return_int REAL_internal_gamemode_request_start_for = NULL; -static api_call_pid_return_int REAL_internal_gamemode_request_end_for = NULL; -static api_call_pid_return_int REAL_internal_gamemode_query_status_for = NULL; - -/** - * Internal helper to perform the symbol binding safely. - * - * Returns 0 on success and -1 on failure - */ -__attribute__((always_inline)) static inline int internal_bind_libgamemode_symbol(void* handle, - const char* name, - void** out_func, - size_t func_size, - bool required) -{ - void* symbol_lookup = NULL; - char* dl_error = NULL; - - /* Safely look up the symbol */ - symbol_lookup = dlsym(handle, name); - dl_error = dlerror(); - if (required && (dl_error || !symbol_lookup)) { - snprintf(internal_gamemode_client_error_string, sizeof(internal_gamemode_client_error_string), "dlsym failed - %s", dl_error); - return -1; - } - - /* Have the symbol correctly, copy it to make it usable */ - memcpy(out_func, &symbol_lookup, func_size); - return 0; -} - -/** - * Loads libgamemode and needed functions - * - * Returns 0 on success and -1 on failure - */ -__attribute__((always_inline)) static inline int internal_load_libgamemode(void) -{ - /* We start at 1, 0 is a success and -1 is a fail */ - if (internal_libgamemode_loaded != 1) { - return internal_libgamemode_loaded; - } - - /* Anonymous struct type to define our bindings */ - struct binding { - const char* name; - void** functor; - size_t func_size; - bool required; - } bindings[] = { - { "real_gamemode_request_start", (void**)&REAL_internal_gamemode_request_start, sizeof(REAL_internal_gamemode_request_start), - true }, - { "real_gamemode_request_end", (void**)&REAL_internal_gamemode_request_end, sizeof(REAL_internal_gamemode_request_end), true }, - { "real_gamemode_query_status", (void**)&REAL_internal_gamemode_query_status, sizeof(REAL_internal_gamemode_query_status), false }, - { "real_gamemode_error_string", (void**)&REAL_internal_gamemode_error_string, sizeof(REAL_internal_gamemode_error_string), true }, - { "real_gamemode_request_start_for", (void**)&REAL_internal_gamemode_request_start_for, - sizeof(REAL_internal_gamemode_request_start_for), false }, - { "real_gamemode_request_end_for", (void**)&REAL_internal_gamemode_request_end_for, sizeof(REAL_internal_gamemode_request_end_for), - false }, - { "real_gamemode_query_status_for", (void**)&REAL_internal_gamemode_query_status_for, - sizeof(REAL_internal_gamemode_query_status_for), false }, - }; - - void* libgamemode = NULL; - - /* Try and load libgamemode */ - libgamemode = dlopen("libgamemode.so.0", RTLD_NOW); - if (!libgamemode) { - /* Attempt to load unversioned library for compatibility with older - * versions (as of writing, there are no ABI changes between the two - - * this may need to change if ever ABI-breaking changes are made) */ - libgamemode = dlopen("libgamemode.so", RTLD_NOW); - if (!libgamemode) { - snprintf(internal_gamemode_client_error_string, sizeof(internal_gamemode_client_error_string), "dlopen failed - %s", dlerror()); - internal_libgamemode_loaded = -1; - return -1; - } - } - - /* Attempt to bind all symbols */ - for (size_t i = 0; i < sizeof(bindings) / sizeof(bindings[0]); i++) { - struct binding* binder = &bindings[i]; - - if (internal_bind_libgamemode_symbol(libgamemode, binder->name, binder->functor, binder->func_size, binder->required)) { - internal_libgamemode_loaded = -1; - return -1; - }; - } - - /* Success */ - internal_libgamemode_loaded = 0; - return 0; -} - -/** - * Redirect to the real libgamemode - */ -__attribute__((always_inline)) static inline const char* gamemode_error_string(void) -{ - /* If we fail to load the system gamemode, or we have an error string already, return our error - * string instead of diverting to the system version */ - if (internal_load_libgamemode() < 0 || internal_gamemode_client_error_string[0] != '\0') { - return internal_gamemode_client_error_string; - } - - return REAL_internal_gamemode_error_string(); -} - -/** - * Redirect to the real libgamemode - * Allow automatically requesting game mode - * Also prints errors as they happen. - */ -#ifdef GAMEMODE_AUTO -__attribute__((constructor)) -#else -__attribute__((always_inline)) static inline -#endif -int gamemode_request_start(void) -{ - /* Need to load gamemode */ - if (internal_load_libgamemode() < 0) { -#ifdef GAMEMODE_AUTO - fprintf(stderr, "gamemodeauto: %s\n", gamemode_error_string()); -#endif - return -1; - } - - if (REAL_internal_gamemode_request_start() < 0) { -#ifdef GAMEMODE_AUTO - fprintf(stderr, "gamemodeauto: %s\n", gamemode_error_string()); -#endif - return -1; - } - - return 0; -} - -/* Redirect to the real libgamemode */ -#ifdef GAMEMODE_AUTO -__attribute__((destructor)) -#else -__attribute__((always_inline)) static inline -#endif -int gamemode_request_end(void) -{ - /* Need to load gamemode */ - if (internal_load_libgamemode() < 0) { -#ifdef GAMEMODE_AUTO - fprintf(stderr, "gamemodeauto: %s\n", gamemode_error_string()); -#endif - return -1; - } - - if (REAL_internal_gamemode_request_end() < 0) { -#ifdef GAMEMODE_AUTO - fprintf(stderr, "gamemodeauto: %s\n", gamemode_error_string()); -#endif - return -1; - } - - return 0; -} - -/* Redirect to the real libgamemode */ -__attribute__((always_inline)) static inline int gamemode_query_status(void) -{ - /* Need to load gamemode */ - if (internal_load_libgamemode() < 0) { - return -1; - } - - if (REAL_internal_gamemode_query_status == NULL) { - snprintf(internal_gamemode_client_error_string, sizeof(internal_gamemode_client_error_string), - "gamemode_query_status missing (older host?)"); - return -1; - } - - return REAL_internal_gamemode_query_status(); -} - -/* Redirect to the real libgamemode */ -__attribute__((always_inline)) static inline int gamemode_request_start_for(pid_t pid) -{ - /* Need to load gamemode */ - if (internal_load_libgamemode() < 0) { - return -1; - } - - if (REAL_internal_gamemode_request_start_for == NULL) { - snprintf(internal_gamemode_client_error_string, sizeof(internal_gamemode_client_error_string), - "gamemode_request_start_for missing (older host?)"); - return -1; - } - - return REAL_internal_gamemode_request_start_for(pid); -} - -/* Redirect to the real libgamemode */ -__attribute__((always_inline)) static inline int gamemode_request_end_for(pid_t pid) -{ - /* Need to load gamemode */ - if (internal_load_libgamemode() < 0) { - return -1; - } - - if (REAL_internal_gamemode_request_end_for == NULL) { - snprintf(internal_gamemode_client_error_string, sizeof(internal_gamemode_client_error_string), - "gamemode_request_end_for missing (older host?)"); - return -1; - } - - return REAL_internal_gamemode_request_end_for(pid); -} - -/* Redirect to the real libgamemode */ -__attribute__((always_inline)) static inline int gamemode_query_status_for(pid_t pid) -{ - /* Need to load gamemode */ - if (internal_load_libgamemode() < 0) { - return -1; - } - - if (REAL_internal_gamemode_query_status_for == NULL) { - snprintf(internal_gamemode_client_error_string, sizeof(internal_gamemode_client_error_string), - "gamemode_query_status_for missing (older host?)"); - return -1; - } - - return REAL_internal_gamemode_query_status_for(pid); -} - -#endif // CLIENT_GAMEMODE_H diff --git a/nix/unwrapped.nix b/nix/unwrapped.nix index 7d461a072..e5fc0bad4 100644 --- a/nix/unwrapped.nix +++ b/nix/unwrapped.nix @@ -15,12 +15,8 @@ tomlplusplus, zlib, msaClientID ? null, - gamemodeSupport ? stdenv.hostPlatform.isLinux, libarchive, }: -assert lib.assertMsg ( - gamemodeSupport -> stdenv.hostPlatform.isLinux -) "gamemodeSupport is only available on Linux."; let date = @@ -83,7 +79,7 @@ stdenv.mkDerivation { tomlplusplus zlib ] - ++ lib.optional gamemodeSupport gamemode; + ++ lib.optional stdenv.hostPlatform.isLinux gamemode; cmakeFlags = [ # downstream branding diff --git a/nix/wrapper.nix b/nix/wrapper.nix index 01edd0d9a..4ca2d7b3b 100644 --- a/nix/wrapper.nix +++ b/nix/wrapper.nix @@ -51,7 +51,7 @@ assert lib.assertMsg ( ) "textToSpeechSupport only has an effect on Linux."; let - prismlauncher' = prismlauncher-unwrapped.override { inherit msaClientID gamemodeSupport; }; + prismlauncher' = prismlauncher-unwrapped.override { inherit msaClientID; }; in symlinkJoin {