From 9f8d321c84c0f97f82ebe9e13339843e1439d7dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E7=9A=93?= Date: Thu, 30 Jan 2025 22:55:20 -0500 Subject: [PATCH] Use a better method of fixing the Emscripten OpenAL symbol conflict --- .github/workflows/autobuild.yml | 1 - retro/emscripten-patch.sh | 31 ----- src/core.cpp | 22 ++-- subprojects/openal-soft.wrap | 2 +- .../packagefiles/openal-soft-emscripten.patch | 115 ++++++++++++++++++ 5 files changed, 126 insertions(+), 45 deletions(-) delete mode 100755 retro/emscripten-patch.sh create mode 100644 subprojects/packagefiles/openal-soft-emscripten.patch diff --git a/.github/workflows/autobuild.yml b/.github/workflows/autobuild.yml index 453e27f9..e4766b08 100644 --- a/.github/workflows/autobuild.yml +++ b/.github/workflows/autobuild.yml @@ -800,7 +800,6 @@ jobs: cd .. done find ./ -type f -name '*.o' -print0 | xargs -0 emcc -r -o ${{ runner.temp }}/libretro-mkxp-z.bc - ../../retro/emscripten-patch.sh ${{ runner.temp }}/libretro-mkxp-z.bc - name: Build RetroArch run: | diff --git a/retro/emscripten-patch.sh b/retro/emscripten-patch.sh deleted file mode 100755 index 2b8dbc0b..00000000 --- a/retro/emscripten-patch.sh +++ /dev/null @@ -1,31 +0,0 @@ -#!/bin/sh -# -# emscripten-patch.sh -# -# This file is part of mkxp. -# -# Copyright (C) 2013 - 2021 Amaryllis Kulla -# -# mkxp is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 2 of the License, or -# (at your option) any later version. -# -# mkxp is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with mkxp. If not, see . - -# This file looks for all the symbols in the input file that begin with "al" or "alc" (i.e. OpenAL functions) and changes the "a" at the beginning of each symbol into "A". -# This is to work around a symbol conflict with Emscripten's OpenAL implementation by renaming all the symbols in the OpenAL implementation we use. - -set -e -for symbol in $(emnm "$1" | cut -d ' ' -f 3 | grep '^alc\?[A-Z]' | awk '{ print length, $0 }' | sort -n -r | cut -d ' ' -f 2) -do - new_symbol="A$(echo $symbol | cut -c 2-)" - echo "[emscripten-patch.sh] Replacing '$symbol' with '$new_symbol'" - sed -i "s/$symbol/$new_symbol/g" "$1" -done diff --git a/src/core.cpp b/src/core.cpp index 9083ac71..46c1d1ae 100644 --- a/src/core.cpp +++ b/src/core.cpp @@ -168,22 +168,16 @@ static bool init_sandbox() { log_printf(RETRO_LOG_INFO, "Initializing audio\n"); - alcLoopbackOpenDeviceSOFT = (LPALCLOOPBACKOPENDEVICESOFT)alcGetProcAddress(NULL, "AlcLoopbackOpenDeviceSOFT"); + alcLoopbackOpenDeviceSOFT = (LPALCLOOPBACKOPENDEVICESOFT)alcGetProcAddress(NULL, "alcLoopbackOpenDeviceSOFT"); if (alcLoopbackOpenDeviceSOFT == NULL) { - alcLoopbackOpenDeviceSOFT = (LPALCLOOPBACKOPENDEVICESOFT)alcGetProcAddress(NULL, "alcLoopbackOpenDeviceSOFT"); - if (alcLoopbackOpenDeviceSOFT == NULL) { - log_printf(RETRO_LOG_ERROR, "OpenAL implementation does not support `alcLoopbackOpenDeviceSOFT`\n"); - return false; - } + log_printf(RETRO_LOG_ERROR, "OpenAL implementation does not support `alcLoopbackOpenDeviceSOFT`\n"); + return false; } - alcRenderSamplesSOFT = (LPALCRENDERSAMPLESSOFT)alcGetProcAddress(NULL, "AlcRenderSamplesSOFT"); + alcRenderSamplesSOFT = (LPALCRENDERSAMPLESSOFT)alcGetProcAddress(NULL, "alcRenderSamplesSOFT"); if (alcRenderSamplesSOFT == NULL) { - alcRenderSamplesSOFT = (LPALCRENDERSAMPLESSOFT)alcGetProcAddress(NULL, "alcRenderSamplesSOFT"); - if (alcRenderSamplesSOFT == NULL) { - log_printf(RETRO_LOG_ERROR, "OpenAL implementation does not support `alcRenderSamplesSOFT`\n"); - return false; - } + log_printf(RETRO_LOG_ERROR, "OpenAL implementation does not support `alcRenderSamplesSOFT`\n"); + return false; } al_device = alcLoopbackOpenDeviceSOFT(NULL); @@ -274,11 +268,15 @@ extern "C" RETRO_API void retro_set_environment(retro_environment_t cb) { environment = cb; struct retro_log_callback log; +#ifndef __EMSCRIPTEN__ if (cb(RETRO_ENVIRONMENT_GET_LOG_INTERFACE, &log)) { log_printf = log.log; } else { +#endif // __EMSCRIPTEN__ log_printf = fallback_log; +#ifndef __EMSCRIPTEN__ } +#endif // __EMSCRIPTEN__ perf = { .get_time_usec = nullptr, diff --git a/subprojects/openal-soft.wrap b/subprojects/openal-soft.wrap index f983089e..2c8ea6a9 100644 --- a/subprojects/openal-soft.wrap +++ b/subprojects/openal-soft.wrap @@ -2,4 +2,4 @@ url = https://github.com/kcat/openal-soft revision = openal-soft-1.21.0 depth = 1 -diff_files = openal-soft.patch, openal-soft-devkitarm.patch, openal-soft-devkitppc.patch +diff_files = openal-soft.patch, openal-soft-devkitarm.patch, openal-soft-devkitppc.patch, openal-soft-emscripten.patch diff --git a/subprojects/packagefiles/openal-soft-emscripten.patch b/subprojects/packagefiles/openal-soft-emscripten.patch new file mode 100644 index 00000000..6d528971 --- /dev/null +++ b/subprojects/packagefiles/openal-soft-emscripten.patch @@ -0,0 +1,115 @@ +# This patch applies C++ name mangling to all of OpenAL Soft's functions so that they don't conflict with the functions in Emscripten's OpenAL implementation. +# Otherwise, the Emscripten build crashes on startup because the Emscripten version of RetroArch also depends on OpenAL, and it will incorrectly try to use our OpenAL implementation instead of Emscripten's. + +diff --git a/include/AL/al.h b/include/AL/al.h +--- a/include/AL/al.h ++++ b/include/AL/al.h +@@ -1,9 +1,9 @@ + #ifndef AL_AL_H + #define AL_AL_H + +-#if defined(__cplusplus) +-extern "C" { +-#endif ++ ++ ++ + + #ifndef AL_API + #if defined(AL_LIBTYPE_STATIC) +@@ -648,8 +648,8 @@ typedef void (AL_APIENTRY *LPALDOPPLERVELOCITY)(ALfloat value); + typedef void (AL_APIENTRY *LPALSPEEDOFSOUND)(ALfloat value); + typedef void (AL_APIENTRY *LPALDISTANCEMODEL)(ALenum distanceModel); + +-#if defined(__cplusplus) +-} /* extern "C" */ +-#endif ++ ++ ++ + + #endif /* AL_AL_H */ +diff --git a/include/AL/alc.h b/include/AL/alc.h +--- a/include/AL/alc.h ++++ b/include/AL/alc.h +@@ -1,9 +1,9 @@ + #ifndef AL_ALC_H + #define AL_ALC_H + +-#if defined(__cplusplus) +-extern "C" { +-#endif ++ ++ ++ + + #ifndef ALC_API + #if defined(AL_LIBTYPE_STATIC) +@@ -263,8 +263,8 @@ typedef void (ALC_APIENTRY *LPALCCAPTURESTART)(ALCdevice *device); + typedef void (ALC_APIENTRY *LPALCCAPTURESTOP)(ALCdevice *device); + typedef void (ALC_APIENTRY *LPALCCAPTURESAMPLES)(ALCdevice *device, ALCvoid *buffer, ALCsizei samples); + +-#if defined(__cplusplus) +-} +-#endif ++ ++ ++ + + #endif /* AL_ALC_H */ +diff --git a/include/AL/alext.h b/include/AL/alext.h +--- a/include/AL/alext.h ++++ b/include/AL/alext.h +@@ -40,9 +40,9 @@ typedef unsigned __int64 uint64_t; + #include "alc.h" + #include "al.h" + +-#ifdef __cplusplus +-extern "C" { +-#endif ++ ++ ++ + + #ifndef AL_LOKI_IMA_ADPCM_format + #define AL_LOKI_IMA_ADPCM_format 1 +@@ -578,8 +578,8 @@ AL_API void AL_APIENTRY alGetPointervSOFT(ALenum pname, void **values); + #endif + #endif + +-#ifdef __cplusplus +-} +-#endif ++ ++ ++ + + #endif +diff --git a/include/AL/efx.h b/include/AL/efx.h +--- a/include/AL/efx.h ++++ b/include/AL/efx.h +@@ -6,9 +6,9 @@ + #include "alc.h" + #include "al.h" + +-#ifdef __cplusplus +-extern "C" { +-#endif ++ ++ ++ + + #define ALC_EXT_EFX_NAME "ALC_EXT_EFX" + +@@ -755,8 +755,8 @@ AL_API void AL_APIENTRY alGetAuxiliaryEffectSlotfv(ALuint effectslot, ALenum par + #define AL_DEFAULT_METERS_PER_UNIT (1.0f) + + +-#ifdef __cplusplus +-} /* extern "C" */ +-#endif ++ ++ ++ + + #endif /* AL_EFX_H */