Skip to content

Commit f3c6af0

Browse files
committed
fix(macos): bundle SDL3 for sdl2-compat at install time
Homebrew replaced its `sdl2` formula with `sdl2-compat`, a compatibility layer that provides the SDL2 API by `dlopen`-ing the real SDL3 library at runtime. The macOS CI build (`build-macos.yml`) pulls this via `brew install mpv`, so the app now links `libSDL2-2.0.0.dylib` which is actually `sdl2-compat`, and every nightly ships it in `Contents/Frameworks`. SDL3 is not a linker dependency, so it never shows up in `otool -L` output and the `CompleteBundleMac` fixup loop never copies it into the app bundle. At runtime `sdl2-compat` looks for `libSDL3.dylib` relative to its own loader path, cannot find it, prints "Failed loading SDL3 library." and aborts during dyld initialization, since the library is missing. This regression appeared once Homebrew's SDL2 became the `sdl2-compat` shim, so older nightly builds (built against genuine SDL2) are unaffected. This detects `sdl2-compat` inside the bundle (it is the only `libSDL2-2.0.0.dylib` containing the `libSDL3.dylib` loader string) and explicitly copies libSDL3 from the Homebrew prefix into `Contents/Frameworks/libSDL3.dylib`, using the same `install-id` convention as the other bundled dylibs so `codesign` and the existing fixup steps keep working. If SDL3 cannot be found at install time a warning is printed instead of failing silently. Fixes #1225
1 parent 9fad78e commit f3c6af0

1 file changed

Lines changed: 39 additions & 0 deletions

File tree

CMakeModules/CompleteBundleMac.cmake.in

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,45 @@ endwhile()
230230

231231
message(STATUS "Library path fixing complete")
232232

233+
#
234+
# sdl2-compat: Homebrew's sdl2 formula is now a compatibility layer that loads
235+
# the real SDL3 library at runtime via dlopen. Since SDL3 is not a linker
236+
# dependency, it is invisible to otool and is never picked up by the fixup loop
237+
# above. Detect sdl2-compat and bundle libSDL3 explicitly.
238+
#
239+
set(sdl2_compat_lib "${framework_path}/libSDL2-2.0.0.dylib")
240+
if(EXISTS "${sdl2_compat_lib}")
241+
execute_process(
242+
COMMAND strings -a "${sdl2_compat_lib}"
243+
OUTPUT_VARIABLE sdl2_compat_strings
244+
ERROR_QUIET
245+
OUTPUT_STRIP_TRAILING_WHITESPACE
246+
)
247+
if(sdl2_compat_strings MATCHES "libSDL3\\.dylib")
248+
set(sdl3_target "${framework_path}/libSDL3.dylib")
249+
if(NOT EXISTS "${sdl3_target}")
250+
set(sdl3_source "")
251+
foreach(candidate "${brew_lib}/libSDL3.dylib" "${brew_lib}/libSDL3.0.dylib")
252+
if(EXISTS "${candidate}")
253+
get_filename_component(sdl3_source "${candidate}" REALPATH)
254+
break()
255+
endif()
256+
endforeach()
257+
if(sdl3_source)
258+
message(STATUS "sdl2-compat detected, bundling SDL3 into ${framework_path}")
259+
file(COPY "${sdl3_source}" DESTINATION "${framework_path}")
260+
get_filename_component(sdl3_source_name "${sdl3_source}" NAME)
261+
if(NOT "${sdl3_source_name}" STREQUAL "libSDL3.dylib")
262+
file(RENAME "${framework_path}/${sdl3_source_name}" "${sdl3_target}")
263+
endif()
264+
execute_process(COMMAND install_name_tool -id "@executable_path/../Frameworks/libSDL3.dylib" "${sdl3_target}" ERROR_QUIET)
265+
else()
266+
message(WARNING "sdl2-compat detected but libSDL3 was not found in ${brew_lib}; the app will fail at runtime with 'Failed loading SDL3 library.'")
267+
endif()
268+
endif()
269+
endif()
270+
endif()
271+
233272
# List all bundled libraries for verification
234273
file(GLOB final_dylibs "${framework_path}/*.dylib")
235274
message(STATUS "=== Bundled libraries in Frameworks ===")

0 commit comments

Comments
 (0)