Merge branch 'libretro-compat' into libretro

This commit is contained in:
刘皓 2025-03-07 21:01:48 -05:00
commit 9677ab899b
No known key found for this signature in database
GPG key ID: 7901753DB465B711
9 changed files with 105 additions and 23 deletions

View file

@ -727,22 +727,44 @@ jobs:
build-libretro-darwin: build-libretro-darwin:
needs: build-libretro-stage1 needs: build-libretro-stage1
name: LR Darwin ${{ matrix.arch_mkxpz }} name: LR ${{ matrix.system_name }} ${{ matrix.arch_mkxpz }}
runs-on: macos-latest runs-on: macos-latest
strategy: strategy:
fail-fast: false fail-fast: false
matrix: matrix:
include: include:
- arch_mkxpz: arm64 - system_name: macOS
arch_llvm: aarch64-apple-darwin system_mkxpz: macos
sdk: macosx
arch_mkxpz: arm64
arch_llvm: arm64
cpu_family: aarch64 cpu_family: aarch64
cpu: generic-armv8-a cpu: generic-armv8-a
endian: little endian: little
- arch_mkxpz: x86_64 - system_name: macOS
arch_llvm: x86_64-apple-darwin system_mkxpz: macos
sdk: macosx
arch_mkxpz: x86_64
arch_llvm: x86_64
cpu_family: x86_64 cpu_family: x86_64
cpu: x86_64 cpu: x86_64
endian: little 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: steps:
- name: Install dependencies - name: Install dependencies
run: | run: |
@ -766,8 +788,8 @@ jobs:
- name: Configure core - name: Configure core
run: | run: |
echo "[binaries]" | tee -a ${{ runner.temp }}/cross.ini echo "[binaries]" | tee -a ${{ runner.temp }}/cross.ini
echo "c = ['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 = ['clang++', '--target=${{ 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 "ar = 'ar'" | tee -a ${{ runner.temp }}/cross.ini
echo "strip = 'strip'" | tee -a ${{ runner.temp }}/cross.ini echo "strip = 'strip'" | tee -a ${{ runner.temp }}/cross.ini
echo "[host_machine]" | tee -a ${{ runner.temp }}/cross.ini echo "[host_machine]" | tee -a ${{ runner.temp }}/cross.ini
@ -775,6 +797,8 @@ jobs:
echo "cpu_family = '${{ matrix.cpu_family }}'" | tee -a ${{ runner.temp }}/cross.ini echo "cpu_family = '${{ matrix.cpu_family }}'" | tee -a ${{ runner.temp }}/cross.ini
echo "cpu = '${{ matrix.cpu }}'" | 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 "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 '--------------------------------------------------------------------------------' echo '--------------------------------------------------------------------------------'
CLICOLOR_FORCE=1 meson setup build --cross-file ${{ runner.temp }}/cross.ini --buildtype release -Db_lto=true -Dlibretro=true CLICOLOR_FORCE=1 meson setup build --cross-file ${{ runner.temp }}/cross.ini --buildtype release -Db_lto=true -Dlibretro=true
@ -789,7 +813,7 @@ jobs:
- name: Upload artifact - name: Upload artifact
uses: actions/upload-artifact@v4 uses: actions/upload-artifact@v4
with: 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 path: ${{ runner.temp }}/dist
build-libretro-emscripten: build-libretro-emscripten:
@ -903,7 +927,7 @@ jobs:
echo "endian = 'big'" | tee -a ~/cross.ini echo "endian = 'big'" | tee -a ~/cross.ini
echo '--------------------------------------------------------------------------------' echo '--------------------------------------------------------------------------------'
git config --global --add safe.directory "$(pwd)" 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 - name: Build core
run: | run: |

View file

@ -40,6 +40,7 @@ if is_libretro
libretro_link_args = [] libretro_link_args = []
libretro_cflags = ['-Wno-unused-command-line-argument'] libretro_cflags = ['-Wno-unused-command-line-argument']
libretro_cppflags = ['-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') if core_is_static and not is_emscripten and get_option('b_lto')
compilers['c'].has_argument('-ffat-lto-objects', required: true) compilers['c'].has_argument('-ffat-lto-objects', required: true)
@ -48,9 +49,16 @@ if is_libretro
libretro_cppflags += '-ffat-lto-objects' libretro_cppflags += '-ffat-lto-objects'
endif 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. # 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 endif
if host_cpu_family == 'ppc64' if host_cpu_family == 'ppc64'
@ -235,6 +243,17 @@ if is_libretro
libretro_defines += '-DMKXPZ_HAVE_ALIGNED_ALLOC' libretro_defines += '-DMKXPZ_HAVE_ALIGNED_ALLOC'
endif 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 <sys/stat.h>
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: # 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': # ../subprojects/flac/src/libFLAC/window.c: In function 'FLAC__window_triangle':
@ -483,6 +502,7 @@ if is_libretro
cmake.subproject('libzip', options: libzip_options).dependency('zip'), cmake.subproject('libzip', options: libzip_options).dependency('zip'),
cmake.subproject('physfs', options: physfs_options).dependency('physfs-static'), 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('OpenAL'),
cmake.subproject('openal-soft', options: openal_options).dependency('alsoft.fmt'),
cmake.subproject('fluidlite', options: fluidlite_options).dependency('fluidlite-static'), cmake.subproject('fluidlite', options: fluidlite_options).dependency('fluidlite-static'),
cmake.subproject('ogg', options: ogg_options).dependency('ogg'), cmake.subproject('ogg', options: ogg_options).dependency('ogg'),
cmake.subproject('vorbis', options: vorbis_options).dependency('vorbis'), cmake.subproject('vorbis', options: vorbis_options).dependency('vorbis'),
@ -490,6 +510,7 @@ if is_libretro
cmake.subproject('flac', options: flac_options).dependency('FLAC'), cmake.subproject('flac', options: flac_options).dependency('FLAC'),
cmake.subproject('opus', options: opus_options).dependency('opus'), cmake.subproject('opus', options: opus_options).dependency('opus'),
cmake.subproject('mpg123', options: mpg123_options).dependency('libmpg123'), cmake.subproject('mpg123', options: mpg123_options).dependency('libmpg123'),
cmake.subproject('mpg123', options: mpg123_options).dependency('compat'),
cmake.subproject('libsndfile', options: libsndfile_options).dependency('sndfile'), cmake.subproject('libsndfile', options: libsndfile_options).dependency('sndfile'),
cmake.subproject('pixman-region', options: pixman_region_options).dependency('pixman-region'), cmake.subproject('pixman-region', options: pixman_region_options).dependency('pixman-region'),
subproject('stb').get_variable('stb'), subproject('stb').get_variable('stb'),
@ -498,7 +519,7 @@ if is_libretro
declare_dependency( declare_dependency(
link_with: static_library( link_with: static_library(
'ruby', 'ruby',
c_args: libretro_cflags + libretro_defines + [ c_args: libretro_cflags + libretro_ruby_cflags + libretro_defines + [
'-fno-optimize-sibling-calls', '-fno-optimize-sibling-calls',
'-frounding-math', '-frounding-math',
'-fsignaling-nans', '-fsignaling-nans',

View file

@ -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', 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('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')

View file

@ -3,13 +3,16 @@
--- a/ports/cmake/src/compat/CMakeLists.txt --- a/ports/cmake/src/compat/CMakeLists.txt
+++ b/ports/cmake/src/compat/CMakeLists.txt +++ b/ports/cmake/src/compat/CMakeLists.txt
@@ -2,12 +2,6 @@ set(TARGET compat) @@ -1,13 +1,7 @@
add_library(${TARGET} OBJECT 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.c"
"${CMAKE_CURRENT_SOURCE_DIR}/../../../../src/compat/compat_str.c") "${CMAKE_CURRENT_SOURCE_DIR}/../../../../src/compat/compat_str.c")
-set_target_properties(${TARGET} PROPERTIES POSITION_INDEPENDENT_CODE ON) -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") "${CMAKE_CURRENT_SOURCE_DIR}/../../../../src/compat/compat_dl.c")
-set_target_properties(${TARGET}_dl PROPERTIES POSITION_INDEPENDENT_CODE ON) -set_target_properties(${TARGET}_dl PROPERTIES POSITION_INDEPENDENT_CODE ON)
- -

View file

@ -1,17 +1,14 @@
# devkitPro platforms don't have usable flockfile and funlockfile functions. # Disables OpenAL Soft's use of flockfile and funlockfile since not every platform we support has those functions.
# This patch disables the use of those functions when using devkitPro. # Besides, OpenAL Soft shouldn't even be using the filesystem or the standard streams.
--- a/fmt-11.1.1/include/fmt/format-inl.h --- a/fmt-11.1.1/include/fmt/format-inl.h
+++ b/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 <typename F> template <typename F>
struct has_flockfile<F, void_t<decltype(flockfile(&std::declval<F&>()))>> struct has_flockfile<F, void_t<decltype(flockfile(&std::declval<F&>()))>>
+#if defined(__DEVKITPRO__) - : std::true_type {};
+ : std::false_type {}; + : std::false_type {};
+#else
: std::true_type {};
+#endif
// A FILE wrapper. F is FILE defined as a template parameter to make system API // A FILE wrapper. F is FILE defined as a template parameter to make system API
// detection work. // detection work.

View file

@ -13,6 +13,15 @@
unset(HAS_ROUTER) unset(HAS_ROUTER)
--- a/fmt-11.1.1/CMakeLists.txt --- a/fmt-11.1.1/CMakeLists.txt
+++ b/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 @@ -73,7 +73,7 @@ target_include_directories(alsoft.fmt PUBLIC
set_target_properties(alsoft.fmt PROPERTIES ${ALSOFT_STD_VERSION_PROPS} set_target_properties(alsoft.fmt PROPERTIES ${ALSOFT_STD_VERSION_PROPS}
VERSION ${FMT_VERSION} SOVERSION ${CPACK_PACKAGE_VERSION_MAJOR} VERSION ${FMT_VERSION} SOVERSION ${CPACK_PACKAGE_VERSION_MAJOR}

View file

@ -42,3 +42,14 @@
return retval; return retval;
} /* __PHYSFS_platformCalcUserDir */ } /* __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. */

View file

@ -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))

View file

@ -2,4 +2,4 @@
url = https://github.com/icculus/physfs url = https://github.com/icculus/physfs
revision = release-3.2.0 revision = release-3.2.0
depth = 1 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