From b1131c1a7bb6d2fc6e7e4a279007cc49d97d2b0e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E7=9A=93?= Date: Tue, 14 Jan 2025 18:51:56 -0500 Subject: [PATCH] Fix Android libretro builds --- .github/workflows/autobuild.yml | 14 ++++++++++---- meson.build | 12 +++++++++--- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/.github/workflows/autobuild.yml b/.github/workflows/autobuild.yml index 30170d73..a7894b93 100644 --- a/.github/workflows/autobuild.yml +++ b/.github/workflows/autobuild.yml @@ -531,7 +531,7 @@ jobs: endian: little - arch_mkxpz: riscv64 arch_alpine: riscv64 - arch_llvm: riscv64gc-alpine-linux-musl + arch_llvm: riscv64-alpine-linux-musl cpu_family: riscv64 cpu: rv64gc endian: little @@ -604,7 +604,7 @@ jobs: - uses: actions/upload-artifact@v4 with: - name: libretro-mkxp-z.linux-musl.${{ matrix.arch_mkxpz }} + name: libretro-mkxp-z.linux-musl.${{ 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 }}/retro-phase2 build-retro-phase2-android: @@ -617,21 +617,25 @@ jobs: include: - arch_mkxpz: armv7 arch_llvm: armv7a-linux-androideabi21 + arch_cmake: armv7-a cpu_family: arm cpu: generic-armv7-a endian: little - arch_mkxpz: arm64 arch_llvm: aarch64-linux-android21 + arch_cmake: aarch64 cpu_family: aarch64 cpu: generic-armv8-a endian: little - arch_mkxpz: x86 arch_llvm: i686-linux-android21 + arch_cmake: i686 cpu_family: x86 cpu: i686 endian: little - arch_mkxpz: x86_64 arch_llvm: x86_64-linux-android21 + arch_cmake: x86_64 cpu_family: x86_64 cpu: x86_64 endian: little @@ -672,10 +676,12 @@ 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_SYSTEM_PROCESSOR = '${{ matrix.arch_cmake }}'" | tee -a ${{ runner.temp }}/cross.ini mkdir ${{ runner.temp }}/retro-phase2 cp retro/core.info ${{ runner.temp }}/retro-phase2/libretro-mkxp-z.info - meson setup build --cross-file ${{ runner.temp }}/cross.ini --buildtype release -Db_lto=true -Dretro=true -Dretro_phase1_path=retro/build/retro-phase1 + ANDROID_NDK=${{ steps.ndk.outputs.ndk-path }} meson setup build --cross-file ${{ runner.temp }}/cross.ini --buildtype release -Db_lto=true -Dretro=true -Dretro_phase1_path=retro/build/retro-phase1 cd build ninja -v llvm-strip libretro-mkxp-z.so @@ -683,7 +689,7 @@ jobs: - uses: actions/upload-artifact@v4 with: - name: libretro-mkxp-z.android.${{ matrix.arch_mkxpz }} + name: libretro-mkxp-z.android.${{ 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 }}/retro-phase2 build-retro-phase2-darwin: diff --git a/meson.build b/meson.build index 64358f9c..2cd77575 100644 --- a/meson.build +++ b/meson.build @@ -1,4 +1,4 @@ -project('mkxp-z', 'c', 'cpp', version: '2.4.2', meson_version: '>=0.63.0', default_options: ['cpp_std=c++14', 'buildtype=release']) +project('mkxp-z', 'c', 'cpp', version: '2.4.2', meson_version: '>=1.3.0', default_options: ['cpp_std=c++14', 'buildtype=release']) host_system = host_machine.system() host_endian = host_machine.endian() @@ -106,11 +106,17 @@ if get_option('retro') == true retro_link_args = [] - # We need to statically link the C++ standard library (libstdc++/libc++), the compiler runtime library (libgcc/compiler-rt) and libpthread in MSYS2 builds for Windows - if host_system == 'windows' or host_system == 'cygwin' + # We need to statically link the C++ standard library (libstdc++/libc++), the compiler runtime library (libgcc/compiler-rt) and libpthread in MSYS2 builds for Windows because those are not part of the operating system + if (host_system == 'windows' or host_system == 'cygwin') and compilers['cpp'].has_link_argument('-static') retro_link_args += '-static' endif + # Android doesn't have a built-in C++ standard library, so we need to statically link against the C++ standard library + if host_system == 'android' + compilers['cpp'].has_link_argument('-static-libstdc++', required: true) + retro_link_args += '-static-libstdc++' + endif + # If possible, stop the linker from reexporting the symbols from the static libraries we use (e.g. zlib) if compilers['cpp'].has_link_argument('-Wl,--version-script,' + join_paths(meson.current_source_dir(), 'retro/link.T')) # Only works with GNU linker and LLVM linker retro_link_args += '-Wl,--version-script,' + join_paths(meson.current_source_dir(), 'retro/link.T')