Skip to content

Add macOS arm64 runtime support and release artifacts#1174

Open
kkorenn wants to merge 4 commits into
LavaGang:masterfrom
kkorenn:codex/macos-arm64-ci
Open

Add macOS arm64 runtime support and release artifacts#1174
kkorenn wants to merge 4 commits into
LavaGang:masterfrom
kkorenn:codex/macos-arm64-ci

Conversation

@kkorenn

@kkorenn kkorenn commented Jun 7, 2026

Copy link
Copy Markdown

What changed

This PR contains the macOS arm64 runtime fixes plus the CI/release packaging needed to ship separate macOS x64 and arm64 archives.

Runtime and bootstrap fixes

  • Adds arm64 / osx-arm64 to the shared build properties and solution configurations.
  • Adds macOS arm64 native bootstrap dependencies (libdobby.a, libplthook.a) and updates the macOS x64 libplthook.a.
  • Adds native macOS dlsym interpose support in osxentry.cpp because plthook cannot reliably patch modern macOS chained fixups in UnityPlayer.dylib.
  • Exposes MLRegisterDlsymHook, MLRealDlsym, and MLMacOSJitCopy from the native bootstrap and keeps those symbols through the AOT/native link.
  • Updates ModuleSymbolRedirect so macOS uses the native dlsym interpose path, while still using the real un-interposed dlsym when resolving genuine runtime symbols.
  • Adds MLMacOSJitCopy support for arm64 JIT writes using pthread_jit_write_protect_np plus instruction-cache invalidation.
  • Vendors an arm64-safe macOS native detour platform inside MelonLoader so the arm64 build actually uses MLMacOSJitCopy instead of falling back to MonoMod legacy mprotect / MonoPosix writes.

macOS launch/path fixes

  • Ships a macOS launch helper that opens Terminal tailing the MelonLoader log for visibility.
  • Improves .app path detection on macOS so MelonLoader can resolve the game bundle correctly.
  • Improves Mono framework detection by falling back to a single .app bundle in the game directory when the process path is not already the bundle path.

CI/release fixes

  • Builds both osx-x64 and osx-arm64 in the macOS GitHub workflow matrix.
  • Uploads debug/release artifacts for both architectures.
  • Packages MelonLoader.macOS.arm64.zip alongside the existing MelonLoader.macOS.x64.zip in GitHub releases.
  • Updates softprops/action-gh-release@v3 inputs to tag_name / name, enables overwrite_files, and grants the nested release upload workflow contents: write so an existing tag release can be updated.

Why

Apple Silicon native macOS installs need both the runtime/bootstrap changes and a release artifact. The existing x64-only macOS release path forced Rosetta and did not handle the arm64 detour/JIT/dlsym path correctly.

Validation

  • dotnet restore -p:Platform="arm64" -p:ForceRID="osx-arm64"
  • dotnet build --no-restore -c Release -p:Platform="arm64" -p:ForceRID="osx-arm64" -p:Version="0.7.3"
  • dotnet restore -p:Platform="x64" -p:ForceRID="osx-x64"
  • dotnet build --no-restore -c Release -p:Platform="x64" -p:ForceRID="osx-x64" -p:Version="0.7.3"
  • Fork tag release workflow v0.7.3 | Release: https://github.com/kkorenn/MelonLoader/actions/runs/27083213838
  • Downloaded MelonLoader.macOS.arm64.zip from kkorenn/MelonLoader@v0.7.3 and verified:
    • MelonLoader.Bootstrap.dylib is Mach-O arm64.
    • Native symbols include MLMacOSJitCopy, MLRegisterDlsymHook, and MLRealDlsym.
    • MelonLoader.dll for net35, net472, and net6 contains MacOSArm64NativeDetourPlatform and MLMacOSJitCopy.

Both architecture builds succeeded with existing project warnings. The fork release workflow completed successfully and updated the existing v0.7.3 release assets.

kkorenn added 2 commits June 7, 2026 12:02
Add support for osx-arm64: add ARM64 platform and runtime identifier in Directory.Build.props and define an ARM64 build constant. Include osx-arm64 native libraries (libdobby.a and libplthook.a) and update the osx-x64 plthook. Implement a DYLD dlsym interpose flow because plthook cannot patch modern macOS GOTs: export MLRegisterDlsymHook, MLRealDlsym and MLMacOSJitCopy from native osxentry.cpp, register the managed detour from ModuleSymbolRedirect, and use RealDlsym to resolve genuine runtime symbols. Update the bootstrap project file to keep additional linker symbols and append native exports before native linking. Improve macOS-specific behavior: add JIT copy support for arm64, open a Terminal tailing the MelonLoader log from the macOS launcher script, better resolve the game .app path and frameworks path, and select the appropriate DetourNative platform for macOS ARM64. Also update osxexports.def with the new native exports.
@kkorenn kkorenn marked this pull request as ready for review June 7, 2026 03:33
@kkorenn kkorenn changed the title [codex] Build macOS x64 and arm64 artifacts [codex] Add macOS arm64 support and release artifacts Jun 7, 2026
@kkorenn kkorenn changed the title [codex] Add macOS arm64 support and release artifacts macOS runtime fixes + macOS x64 and arm64 seperate build Jun 7, 2026
@kkorenn kkorenn changed the title macOS runtime fixes + macOS x64 and arm64 seperate build Add macOS arm64 runtime support and release artifacts Jun 7, 2026
datariot added a commit to datariot/MelonLoader that referenced this pull request Jun 26, 2026
Builds on PR LavaGang#1174 (arm64 macOS native-detour platform / dobby) to get
MelonLoader fully loading il2cpp games on Apple Silicon. Validated on
Bloons TD 6 (Unity 6000.0.58f2) with native-arm64 class injection working.

- MelonLoader/Core.cs: wire MacOSArm64NativeDetourPlatform for net6/il2cpp, not
  just Mono. LavaGang#1174 selected it only under `!NET6`; without this, HarmonyX/MonoMod
  (DetourHelper.Native) has no arm64 platform -> IL compile error / NullRef in
  MonoMod ILHook ctor when the Il2Cpp support module applies its hooks. (keystone)
- Dependencies/Il2CppAssemblyGenerator/.../ExecutablePackage.cs: strip
  DYLD_INSERT_LIBRARIES when spawning the Cpp2IL subprocess, else the x86_64
  Cpp2IL inherits the arm64 bootstrap insert -> dyld arch-mismatch crash.
- MelonLoader/SupportModule/SupportModule.cs: surface support-module init failures
  via MelonLogger.Error (was MelonDebug.Error, debug-only) so swallowed exceptions
  are visible.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NNJ7xPHAVYU6JAMioxnFs8
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