Skip to content

macOS: build a self-contained Li-ri.app bundle - #126

Open
Gr33ndev wants to merge 2 commits into
petitlapin:mainfrom
Gr33ndev:macos-app-bundle
Open

Gr33ndev wants to merge 2 commits into
petitlapin:mainfrom
Gr33ndev:macos-app-bundle

Conversation

@Gr33ndev

Copy link
Copy Markdown

Problem

On macOS there is no usable .app bundle: the build produces a plain binary, and the macOS branch of Utils::GetPath() looks for data at Li-ri.app/Contents/Resources/... relative to the current working directory. When the game is started from Finder (or via open), the working directory is /, so the data is not found and the game exits with Unable to find '...'.

Fix

  • Data path: Utils::GetPath() on macOS now uses SDL_GetBasePath(), which returns <App>.app/Contents/Resources/ independent of the working directory. Falls back to LIRI_DATA_DIR (only if set at configure time) and the old relative path.
  • Bundle: Li-ri is built as MACOSX_BUNDLE with macos/Info.plist.in, an .icns icon generated from the existing PNGs via iconutil, and data/ + Sounds/ copied into Contents/Resources (post-build, so the .app in the build tree runs too).
  • Self-contained install/DMG: fixup_bundle copies non-system dylibs into Contents/Frameworks and rewrites their install names; the bundle is then re-signed ad hoc (required on Apple Silicon after install_name_tool). The install fails if codesign fails.
  • sdl2-compat: Homebrew's sdl2 is sdl2-compat, which dlopen()s SDL3 at runtime — invisible to fixup_bundle. When the sdl2-compat pkg-config module is found, SDL3 is installed as Contents/Frameworks/libSDL3.dylib (the first path sdl2-compat probes). No effect on the Conan build.
  • Linux desktop/appdata/icon installs and tools/Li-ri.sh are skipped on macOS.
  • CI (macOS job): verifies bundle contents and Info.plist (plutil -lint), and mounts the DMG to check data presence and codesign --verify --deep --strict.

CI fixes (separate commit; runner image drift, also affects main)

The macOS and Windows jobs no longer run on current GitHub runners, independent of this change:

  • macOS: macos-14 is retired (The configuration 'macos-14-arm64-us-default' is not supported) → moved to macos-15.
  • Windows / CMake: windows-latest now ships Visual Studio 2026; the sdl_mixer recipe pulls in cmake/3.31.12, which fails with Could not create named generator Visual Studio 18 2026. The Windows job now adds [replace_tool_requires] cmake/*: cmake/4.2.1 to the Conan profile (same version conanfile.py already uses).
  • Windows / NSIS: repolevedavaj/install-nsis downloads from a fixed SourceForge mirror that now serves a corrupted installer → install NSIS via Chocolatey instead.

Testing

Tested on an Apple M1, macOS 27.2.1, CMake 4.5.1, Homebrew SDL2 (sdl2-compat 2.32.74 / SDL3 3.4.20) + SDL2_mixer 2.8.2:

  • cmake -S . -B build -DCMAKE_BUILD_TYPE=Release && cmake --build build → open build/Li-ri.app starts with cwd /, graphics and sound work.
  • cmake --install build --prefix /tmp/liri → otool -L shows only @executable_path/../Frameworks/... and system libs (no /opt/homebrew references in the binary or any embedded dylib); codesign --verify --deep --strict passes; at runtime lsof shows SDL2, SDL2_mixer and SDL3 loaded from inside the bundle.
  • CI (Linux, macOS, Windows, clang-format) green on my fork; the macOS DMG from the artifacts mounts, passes codesign --verify, and the game runs from it (graphics and sound OK).

Note: with Homebrew, pkg-config may fail to resolve SDL2_mixer because fluidsynth requires the keg-only readline; PKG_CONFIG_PATH=$(brew --prefix readline)/lib/pkgconfig works around it (unrelated to this PR).

Notes

  • The CI DMG is arm64 only (as before), so it does not run on Intel Macs.

  • The app is signed ad hoc only. When downloaded via a browser, Gatekeeper blocks it until the user allows it (right-click → Open, or System Settings → Privacy & Security). Avoiding that would need a Developer ID certificate and notarization.

  • If the data ever moves (e.g. the Assets/ idea from Game data moved into Assets directory #114), only the two copy_directory lines in the APPLE block need adjusting.

  • Once the project moves to SDL3 (work/sdl3), the sdl2-compat special case can be dropped.

🤖 Generated with Claude Code

Gr33ndev and others added 2 commits November 26, 2026 09:27
- macOS: the macos-14 image is retired ("The configuration
  'macos-14-arm64-us-default' is not supported"); move to macos-15.
- Windows: windows-latest ships Visual Studio 2026. The sdl_mixer recipe
  pulls in cmake/3.31.12, which fails with "Could not create named
  generator Visual Studio 18 2026". Replace all cmake tool_requires with
  cmake/4.2.1 (the version conanfile.py already uses).
- Windows: repolevedavaj/install-nsis downloads from a fixed SourceForge
  mirror that now serves a corrupted installer; install NSIS via
  Chocolatey instead.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
When Li-ri is started from Finder the working directory is "/", so the
data path "Li-ri.app/Contents/Resources/..." (relative to the working
directory) is not found and the game exits.

- Locate game data via SDL_GetBasePath(), which points to
  Contents/Resources inside a bundle; keep LIRI_DATA_DIR (if set) and the
  old relative path as fallbacks
- Build as MACOSX_BUNDLE with Info.plist, an .icns icon generated from
  the existing PNGs, and data/ + Sounds/ copied into Contents/Resources
- On install, embed non-system dylibs with fixup_bundle and re-sign ad
  hoc (required on Apple Silicon); fail the install if codesign fails
- Homebrew's sdl2 is sdl2-compat, which dlopen()s SDL3 at runtime and is
  invisible to fixup_bundle: ship it as Contents/Frameworks/libSDL3.dylib
- Skip Linux desktop/icon/share installs and tools/Li-ri.sh on macOS
- CI: verify bundle contents, Info.plist and the dmg signature

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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