From 24a4ae575978bc3e547f5d23d6d806d1f7ed3eda Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E7=9A=93?= Date: Thu, 6 Mar 2025 20:07:58 -0500 Subject: [PATCH 1/7] Fix missing symbol errors in libretro PlayStation Vita build Somehow, enabling LTO prevents these linker errors from showing up, which is why they don't show up in GitHub Actions, but that doesn't mean the errors can be ignored! --- subprojects/packagefiles/openal-soft-flockfile.patch | 11 ++++------- subprojects/packagefiles/physfs-dir.patch | 11 +++++++++++ 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/subprojects/packagefiles/openal-soft-flockfile.patch b/subprojects/packagefiles/openal-soft-flockfile.patch index f43ea028..8181785d 100644 --- a/subprojects/packagefiles/openal-soft-flockfile.patch +++ b/subprojects/packagefiles/openal-soft-flockfile.patch @@ -1,17 +1,14 @@ -# devkitPro platforms don't have usable flockfile and funlockfile functions. -# This patch disables the use of those functions when using devkitPro. +# Disables OpenAL Soft's use of flockfile and funlockfile since not every platform we support has those functions. +# Besides, OpenAL Soft shouldn't even be using the filesystem or the standard streams. --- a/fmt-11.1.1/include/fmt/format-inl.h +++ b/fmt-11.1.1/include/fmt/format-inl.h -@@ -1479,7 +1479,11 @@ struct has_flockfile : std::false_type {}; +@@ -1479,7 +1479,7 @@ struct has_flockfile : std::false_type {}; template struct has_flockfile()))>> -+#if defined(__DEVKITPRO__) +- : std::true_type {}; + : std::false_type {}; -+#else - : std::true_type {}; -+#endif // A FILE wrapper. F is FILE defined as a template parameter to make system API // detection work. diff --git a/subprojects/packagefiles/physfs-dir.patch b/subprojects/packagefiles/physfs-dir.patch index f74f24d9..4f076630 100644 --- a/subprojects/packagefiles/physfs-dir.patch +++ b/subprojects/packagefiles/physfs-dir.patch @@ -42,3 +42,14 @@ return retval; } /* __PHYSFS_platformCalcUserDir */ +--- a/src/physfs_platform_unix.c ++++ b/src/physfs_platform_unix.c +@@ -227,7 +227,7 @@ static char *readSymLink(const char *path) + break; /* out of memory. */ + retval = ptr; + +- rc = readlink(path, retval, len); ++ rc = -1; + if (rc == -1) + break; /* not a symlink, i/o error, etc. */ + From 516c706a669917de5d091ce18c51a6049001fe09 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E7=9A=93?= Date: Thu, 6 Mar 2025 22:55:26 -0500 Subject: [PATCH 2/7] Convert all CMake subprojects' object libraries into static libraries CMake object libraries keep building with position-independent code enabled even when it's explicitly disabled! We do, in fact, have to build with position-independent code disabled on some targets, such as PlayStation Vita, since some targets support position-independent code. CMake static libraries don't seem to forcibly enable position-independent code, so I've converted all the object libraries into static libraries and added the new static libraries as dependencies in Meson. --- meson.build | 2 ++ subprojects/packagefiles/mpg123-pic.patch | 9 ++++++--- subprojects/packagefiles/openal-soft-pic.patch | 9 +++++++++ 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/meson.build b/meson.build index cdd790c5..65f067a3 100644 --- a/meson.build +++ b/meson.build @@ -461,6 +461,7 @@ if is_libretro cmake.subproject('libzip', options: libzip_options).dependency('zip'), cmake.subproject('physfs', options: physfs_options).dependency('physfs-static'), cmake.subproject('openal-soft', options: openal_options).dependency('OpenAL'), + cmake.subproject('openal-soft', options: openal_options).dependency('alsoft.fmt'), cmake.subproject('fluidlite', options: fluidlite_options).dependency('fluidlite-static'), cmake.subproject('ogg', options: ogg_options).dependency('ogg'), cmake.subproject('vorbis', options: vorbis_options).dependency('vorbis'), @@ -468,6 +469,7 @@ if is_libretro cmake.subproject('flac', options: flac_options).dependency('FLAC'), cmake.subproject('opus', options: opus_options).dependency('opus'), cmake.subproject('mpg123', options: mpg123_options).dependency('libmpg123'), + cmake.subproject('mpg123', options: mpg123_options).dependency('compat'), cmake.subproject('libsndfile', options: libsndfile_options).dependency('sndfile'), declare_dependency( link_with: static_library( diff --git a/subprojects/packagefiles/mpg123-pic.patch b/subprojects/packagefiles/mpg123-pic.patch index df08f1ba..92f685ed 100644 --- a/subprojects/packagefiles/mpg123-pic.patch +++ b/subprojects/packagefiles/mpg123-pic.patch @@ -3,13 +3,16 @@ --- a/ports/cmake/src/compat/CMakeLists.txt +++ b/ports/cmake/src/compat/CMakeLists.txt -@@ -2,12 +2,6 @@ set(TARGET compat) - add_library(${TARGET} OBJECT +@@ -1,13 +1,7 @@ + set(TARGET compat) +-add_library(${TARGET} OBJECT ++add_library(${TARGET} STATIC "${CMAKE_CURRENT_SOURCE_DIR}/../../../../src/compat/compat.c" "${CMAKE_CURRENT_SOURCE_DIR}/../../../../src/compat/compat_str.c") -set_target_properties(${TARGET} PROPERTIES POSITION_INDEPENDENT_CODE ON) - add_library(${TARGET}_dl OBJECT +-add_library(${TARGET}_dl OBJECT ++add_library(${TARGET}_dl STATIC "${CMAKE_CURRENT_SOURCE_DIR}/../../../../src/compat/compat_dl.c") -set_target_properties(${TARGET}_dl PROPERTIES POSITION_INDEPENDENT_CODE ON) - diff --git a/subprojects/packagefiles/openal-soft-pic.patch b/subprojects/packagefiles/openal-soft-pic.patch index abd4b2c3..d99e2e67 100644 --- a/subprojects/packagefiles/openal-soft-pic.patch +++ b/subprojects/packagefiles/openal-soft-pic.patch @@ -13,6 +13,15 @@ unset(HAS_ROUTER) --- a/fmt-11.1.1/CMakeLists.txt +++ b/fmt-11.1.1/CMakeLists.txt +@@ -58,7 +58,7 @@ add_headers(FMT_HEADERS args.h base.h chrono.h color.h compile.h core.h format.h + xchar.h) + set(FMT_SOURCES src/format.cc src/os.cc) + +-add_library(alsoft.fmt OBJECT ${FMT_SOURCES} ${FMT_HEADERS} README.md ChangeLog.md) ++add_library(alsoft.fmt STATIC ${FMT_SOURCES} ${FMT_HEADERS} README.md ChangeLog.md) + add_library(alsoft::fmt ALIAS alsoft.fmt) + + if (cxx_std_11 IN_LIST CMAKE_CXX_COMPILE_FEATURES) @@ -73,7 +73,7 @@ target_include_directories(alsoft.fmt PUBLIC set_target_properties(alsoft.fmt PROPERTIES ${ALSOFT_STD_VERSION_PROPS} VERSION ${FMT_VERSION} SOVERSION ${CPACK_PACKAGE_VERSION_MAJOR} From e5c092660db32f110e64fb499aa07875f7fdf923 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E7=9A=93?= Date: Fri, 7 Mar 2025 00:10:25 -0500 Subject: [PATCH 3/7] Switch the libretro PS3 build back to ScummVM's toolchain image --- .github/workflows/autobuild.yml | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/.github/workflows/autobuild.yml b/.github/workflows/autobuild.yml index a44094c2..88d8f9e0 100644 --- a/.github/workflows/autobuild.yml +++ b/.github/workflows/autobuild.yml @@ -864,16 +864,14 @@ jobs: needs: build-libretro-stage1 name: LR PlayStation 3 runs-on: ubuntu-latest - container: - image: git.libretro.com:5050/libretro-infrastructure/libretro-build-psl1ght:latest - options: -u root + container: scummvm/dockerized-toolchains:ps3 steps: - name: Install dependencies run: | apt update apt install -y git build-essential pip ninja-build jq apt remove -y meson cmake - pip install meson cmake + pip install --break-system-packages meson cmake - id: short-sha name: Get Git commit hash From 31494e40e7462c7a087cba674379bdfe0d3590f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E7=9A=93?= Date: Fri, 7 Mar 2025 00:59:00 -0500 Subject: [PATCH 4/7] Add libretro builds for iOS and tvOS --- .github/workflows/autobuild.yml | 46 +++++++++++++++++++++++++++------ 1 file changed, 38 insertions(+), 8 deletions(-) diff --git a/.github/workflows/autobuild.yml b/.github/workflows/autobuild.yml index 88d8f9e0..c33f5060 100644 --- a/.github/workflows/autobuild.yml +++ b/.github/workflows/autobuild.yml @@ -727,22 +727,52 @@ jobs: build-libretro-darwin: needs: build-libretro-stage1 - name: LR Darwin ${{ matrix.arch_mkxpz }} + name: LR ${{ matrix.system_name }} ${{ matrix.arch_mkxpz }} runs-on: macos-latest strategy: fail-fast: false matrix: include: - - arch_mkxpz: arm64 - arch_llvm: aarch64-apple-darwin + - system_name: macOS + system_mkxpz: macos + sdk: macosx + arch_mkxpz: arm64 + arch_llvm: arm64 cpu_family: aarch64 cpu: generic-armv8-a endian: little - - arch_mkxpz: x86_64 - arch_llvm: x86_64-apple-darwin + - system_name: macOS + system_mkxpz: macos + sdk: macosx + arch_mkxpz: x86_64 + arch_llvm: x86_64 cpu_family: x86_64 cpu: x86_64 endian: little + - system_name: iOS + system_mkxpz: ios + sdk: iphoneos + arch_mkxpz: armv7 + arch_llvm: armv7 + cpu_family: arm + cpu: generic-armv7-a + endian: little + - system_name: iOS + system_mkxpz: ios + sdk: iphoneos + arch_mkxpz: arm64 + arch_llvm: arm64 + cpu_family: aarch64 + cpu: generic-armv8-a + endian: little + - system_name: tvOS + system_mkxpz: tvos + sdk: appletvos + arch_mkxpz: arm64 + arch_llvm: arm64 + cpu_family: aarch64 + cpu: generic-armv8-a + endian: little steps: - name: Install dependencies run: | @@ -766,8 +796,8 @@ jobs: - name: Configure core run: | echo "[binaries]" | tee -a ${{ runner.temp }}/cross.ini - echo "c = ['clang', '--target=${{ matrix.arch_llvm }}']" | tee -a ${{ runner.temp }}/cross.ini - echo "cpp = ['clang++', '--target=${{ matrix.arch_llvm }}']" | tee -a ${{ runner.temp }}/cross.ini + echo "c = ['xcrun', '--sdk', '${{ matrix.sdk }}', 'clang', '-arch', '${{ matrix.arch_llvm }}']" | tee -a ${{ runner.temp }}/cross.ini + echo "cpp = ['xcrun', '--sdk', '${{ matrix.sdk }}', 'clang++', '-arch', '${{ matrix.arch_llvm }}']" | tee -a ${{ runner.temp }}/cross.ini echo "ar = 'ar'" | tee -a ${{ runner.temp }}/cross.ini echo "strip = 'strip'" | tee -a ${{ runner.temp }}/cross.ini echo "[host_machine]" | tee -a ${{ runner.temp }}/cross.ini @@ -789,7 +819,7 @@ jobs: - name: Upload artifact uses: actions/upload-artifact@v4 with: - name: mkxp-z_libretro.darwin.${{ matrix.arch_mkxpz }}.${{ github.event_name == 'pull_request' && format('PR{0}', github.event.number) || github.ref_name }}-${{ steps.short-sha.outputs.sha }} + name: mkxp-z_libretro.${{ matrix.system_mkxpz }}.${{ matrix.arch_mkxpz }}.${{ github.event_name == 'pull_request' && format('PR{0}', github.event.number) || github.ref_name }}-${{ steps.short-sha.outputs.sha }} path: ${{ runner.temp }}/dist build-libretro-emscripten: From dfa9645958d94cb4e8ced237b535a5eca25e5b50 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E7=9A=93?= Date: Fri, 7 Mar 2025 10:11:07 -0500 Subject: [PATCH 5/7] Prevent CMake from manually setting sysroot in libretro Darwin builds --- .github/workflows/autobuild.yml | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/.github/workflows/autobuild.yml b/.github/workflows/autobuild.yml index c33f5060..a940962d 100644 --- a/.github/workflows/autobuild.yml +++ b/.github/workflows/autobuild.yml @@ -749,14 +749,6 @@ jobs: cpu_family: x86_64 cpu: x86_64 endian: little - - system_name: iOS - system_mkxpz: ios - sdk: iphoneos - arch_mkxpz: armv7 - arch_llvm: armv7 - cpu_family: arm - cpu: generic-armv7-a - endian: little - system_name: iOS system_mkxpz: ios sdk: iphoneos @@ -805,6 +797,8 @@ jobs: echo "cpu_family = '${{ matrix.cpu_family }}'" | tee -a ${{ runner.temp }}/cross.ini echo "cpu = '${{ matrix.cpu }}'" | tee -a ${{ runner.temp }}/cross.ini echo "endian = '${{ matrix.endian }}'" | tee -a ${{ runner.temp }}/cross.ini + echo "[cmake]" | tee -a ${{ runner.temp }}/cross.ini + echo "CMAKE_OSX_SYSROOT = '/nonexistent'" | tee -a ${{ runner.temp }}/cross.ini echo '--------------------------------------------------------------------------------' CLICOLOR_FORCE=1 meson setup build --cross-file ${{ runner.temp }}/cross.ini --buildtype release -Db_lto=true -Dlibretro=true From f810489a15b2abc87f5a3a4fcd0b60f7aef3ec09 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E7=9A=93?= Date: Fri, 7 Mar 2025 11:27:27 -0500 Subject: [PATCH 6/7] Enable LTO only for libruby in libretro PlayStation 3 build --- .github/workflows/autobuild.yml | 8 +++++--- meson.build | 14 +++++++++++--- meson_options.txt | 1 + 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/.github/workflows/autobuild.yml b/.github/workflows/autobuild.yml index a940962d..01c91793 100644 --- a/.github/workflows/autobuild.yml +++ b/.github/workflows/autobuild.yml @@ -888,14 +888,16 @@ jobs: needs: build-libretro-stage1 name: LR PlayStation 3 runs-on: ubuntu-latest - container: scummvm/dockerized-toolchains:ps3 + container: + image: git.libretro.com:5050/libretro-infrastructure/libretro-build-psl1ght:latest + options: -u root steps: - name: Install dependencies run: | apt update apt install -y git build-essential pip ninja-build jq apt remove -y meson cmake - pip install --break-system-packages meson cmake + pip install meson cmake - id: short-sha name: Get Git commit hash @@ -925,7 +927,7 @@ jobs: echo "endian = 'big'" | tee -a ~/cross.ini echo '--------------------------------------------------------------------------------' git config --global --add safe.directory "$(pwd)" - CLICOLOR_FORCE=1 meson setup build --cross-file ~/cross.ini --buildtype release -Db_lto=true -Dlibretro=true + CLICOLOR_FORCE=1 meson setup build --cross-file ~/cross.ini --buildtype release -Db_lto=false -Druby_lto=true -Dlibretro=true - name: Build core run: | diff --git a/meson.build b/meson.build index 65f067a3..7c9bcc64 100644 --- a/meson.build +++ b/meson.build @@ -40,6 +40,7 @@ if is_libretro libretro_link_args = [] libretro_cflags = ['-Wno-unused-command-line-argument'] libretro_cppflags = ['-Wno-unused-command-line-argument'] + libretro_ruby_cflags = [] if core_is_static and not is_emscripten and get_option('b_lto') compilers['c'].has_argument('-ffat-lto-objects', required: true) @@ -48,9 +49,16 @@ if is_libretro libretro_cppflags += '-ffat-lto-objects' endif - if (host_cpu_family == 'ppc' or host_cpu_family == 'ppc64') and not get_option('b_lto') + if get_option('ruby_lto') and not get_option('b_lto') + compilers['c'].has_argument('-flto', required: true) + compilers['c'].has_argument('-ffat-lto-objects', required: true) + libretro_ruby_cflags += '-flto' + libretro_ruby_cflags += '-ffat-lto-objects' + endif + + if (host_cpu_family == 'ppc' or host_cpu_family == 'ppc64') and not get_option('b_lto') and not get_option('ruby_lto') # We get a bunch of "relocation truncated to fit" when linking if LTO isn't enabled. - error('LTO is required when building for PowerPC architectures.') + error('LTO is required when building for PowerPC architectures. Please pass either `-Db_lto=true` or `-Druby_lto=true` to Meson.') endif if host_cpu_family == 'ppc64' @@ -474,7 +482,7 @@ if is_libretro declare_dependency( link_with: static_library( 'ruby', - c_args: libretro_cflags + libretro_defines + [ + c_args: libretro_cflags + libretro_ruby_cflags + libretro_defines + [ '-fno-optimize-sibling-calls', '-frounding-math', '-fsignaling-nans', diff --git a/meson_options.txt b/meson_options.txt index ba6884d9..04b8e59c 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -24,3 +24,4 @@ option('gfx_backend', type: 'combo', value: 'gl', choices: ['gl', 'gles'], descr option('libretro', type: 'boolean', value: false, description: 'Build a libretro core instead of an executable') option('libretro_stage1_path', type: 'string', value: 'libretro/build/libretro-stage1', description: 'Path to libretro-stage1 for libretro builds') +option('ruby_lto', type: 'boolean', value: false, description: 'Enable link-time optimization for libruby in libretro builds, even if link-time optimization is disabled for everything else') From c25175778e4196a118787a10397078eeabb3aea8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E7=9A=93?= Date: Fri, 7 Mar 2025 12:10:26 -0500 Subject: [PATCH 7/7] Prevent PhysFS from using `lstat()` on platforms where it's not supported --- meson.build | 11 +++++++++++ subprojects/packagefiles/physfs-lstat.patch | 16 ++++++++++++++++ subprojects/physfs.wrap | 2 +- 3 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 subprojects/packagefiles/physfs-lstat.patch diff --git a/meson.build b/meson.build index 7c9bcc64..1febf702 100644 --- a/meson.build +++ b/meson.build @@ -243,6 +243,17 @@ if is_libretro libretro_defines += '-DMKXPZ_HAVE_ALIGNED_ALLOC' endif + if compilers['cpp'].has_header('sys/stat.h') and (not compilers['cpp'].has_header_symbol('sys/stat.h', 'lstat') or not compilers['cpp'].links(''' + #include + int main() { + struct stat stat; + lstat("/", &stat); + return 0; + } + ''', name: 'lstat sanity check')) + libretro_defines += '-DMKXPZ_NO_LSTAT' + endif + # Enable integer-only mode in FLAC when building with Vita SDK. Otherwise, we get an internal compiler error in FLAC__window_triangle: # # ../subprojects/flac/src/libFLAC/window.c: In function 'FLAC__window_triangle': diff --git a/subprojects/packagefiles/physfs-lstat.patch b/subprojects/packagefiles/physfs-lstat.patch new file mode 100644 index 00000000..31cb7609 --- /dev/null +++ b/subprojects/packagefiles/physfs-lstat.patch @@ -0,0 +1,16 @@ +# Prevents PhysFS from using lstat if the lstat sanity check in our meson.build failed. + +--- a/src/physfs_platform_posix.c ++++ b/src/physfs_platform_posix.c +@@ -331,7 +331,11 @@ int __PHYSFS_platformDelete(const char *path) + int __PHYSFS_platformStat(const char *fname, PHYSFS_Stat *st, const int follow) + { + struct stat statbuf; ++#ifdef MKXPZ_NO_LSTAT ++ const int rc = stat(fname, &statbuf); ++#else + const int rc = follow ? stat(fname, &statbuf) : lstat(fname, &statbuf); ++#endif + BAIL_IF(rc == -1, errcodeFromErrno(), 0); + + if (S_ISREG(statbuf.st_mode)) diff --git a/subprojects/physfs.wrap b/subprojects/physfs.wrap index ff3d2b70..1ed88223 100644 --- a/subprojects/physfs.wrap +++ b/subprojects/physfs.wrap @@ -2,4 +2,4 @@ url = https://github.com/icculus/physfs revision = release-3.2.0 depth = 1 -diff_files = physfs-darwin.patch, physfs-dir.patch, physfs-mkxp-threads.patch, physfs-unknown-platform.patch +diff_files = physfs-darwin.patch, physfs-dir.patch, physfs-lstat.patch, physfs-mkxp-threads.patch, physfs-unknown-platform.patch