Use a better method of fixing the Emscripten OpenAL symbol conflict

This commit is contained in:
刘皓 2025-01-30 22:55:20 -05:00
parent e598114a73
commit 9f8d321c84
No known key found for this signature in database
GPG key ID: 7901753DB465B711
5 changed files with 126 additions and 45 deletions

View file

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

View file

@ -1,31 +0,0 @@
#!/bin/sh
#
# emscripten-patch.sh
#
# This file is part of mkxp.
#
# Copyright (C) 2013 - 2021 Amaryllis Kulla <ancurio@mapleshrine.eu>
#
# 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 <http://www.gnu.org/licenses/>.
# 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

View file

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

View file

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

View file

@ -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 */