Skip to content

build(macos): bundle libSDL3.dylib for sdl2-compat - #43

Merged
midwan merged 2 commits into
masterfrom
fix/macos-bundle-sdl3-compat
Sep 15, 2026
Merged

midwan merged 2 commits into
masterfrom
fix/macos-bundle-sdl3-compat

Conversation

@midwan

@midwan midwan commented Sep 15, 2026

Copy link
Copy Markdown
Contributor

Found while reproducing #3 on macOS.

Problem

Launching the macOS app bundle shows "Fatal error: failed loading SDL3 library" and never starts.

Homebrew's sdl2 formula now installs sdl2-compat (2.32.x), which implements the SDL2 API on top of SDL3 and dlopen()s libSDL3.dylib at runtime (first candidate: @loader_path/libSDL3.dylib). The bundle's gathering step (dylibbundler) only walks LC_LOAD_DYLIB entries, so SDL3 is a hidden dependency it cannot see — it never gets copied into Frameworks/, and the app dies on launch.

Fix

New post-build step (cmake/macos/BundleSDL3Compat.cmake), running after dylibbundler:

  • Detects sdl2-compat in the bundled libSDL2-2.0.0.dylib (it embeds the literal dlopen name libSDL3.dylib; real SDL2 does not).
  • Locates libSDL3.dylib (hints: the linked SDL2's directory, Homebrew prefixes) and copies it into Frameworks/, warning at build time if SDL3 is missing.
  • Ad-hoc signs the dylib and re-signs the app bundle, since the file is added after dylibbundler signed it.

Builds against real SDL2 are untouched (script exits early).

Verification

  • Fresh build on Homebrew sdl2-compat 2.32.72 + SDL3 3.4.16: bundle contains libSDL3.dylib, codesign -v --deep passes, app boots to emulation with no manual patching (previously required a hand-copied dylib).

Homebrew's sdl2 formula ships sdl2-compat (2.32+), which dlopens
libSDL3.dylib at runtime, trying @loader_path first. dylibbundler only
walks LC_LOAD_DYLIB entries, so SDL3 never landed in the app bundle and
launch died with "Failed loading SDL3 library.".

After dylibbundler runs, detect sdl2-compat in the bundled libSDL2
(it embeds the dlopen name libSDL3.dylib; real SDL2 does not), copy
libSDL3.dylib next to it from the Homebrew prefix, and re-sign the
bundle so the seal stays valid. Real-SDL2 builds are untouched.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 15, 2026

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review Completed 2026-09-15T20:20:52.629651Z 0360c91 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 0360c9193c

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread cmake/macos/BundleSDL3Compat.cmake Outdated
Per review: --deep on the executable does not regenerate the enclosing
bundle's resource seal. Sign nested code (libSDL3.dylib) first, then
the .app itself.
@midwan
midwan merged commit 181c95b into master Sep 15, 2026
10 checks passed
@midwan
midwan deleted the fix/macos-bundle-sdl3-compat branch September 15, 2026 20:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant