feat(ios): load ggml-metal.metal instead of prebuilt metallib#252
Merged
Conversation
418742f to
5ae8d4e
Compare
jhen0409
added a commit
to mybigday/whisper.rn
that referenced
this pull request
Dec 4, 2025
jhen0409
added a commit
that referenced
this pull request
May 25, 2026
* feat(ios): embed ggml-metal source into framework binary Fixes #348. Following the precompile-rollback rationale in #252, switch to upstream llama.cpp's GGML_METAL_EMBED_LIBRARY pattern: emit ggml-metal-embed.s during bootstrap, link it into the rnllama framework, and let ggml-metal-device.m's embedded code path supply the Metal source to newLibraryWithSource: directly. Removes the .metal resource shipping and the LM_GGML_METAL_PATH_RESOURCES fallback chain. ggml-metal-device.m itself is unchanged — its #if GGML_METAL_EMBED_LIBRARY branch already supports this path; we only define the macro, generate the asm wrapper, and link it. Cross-platform notes from porting: - scripts/bootstrap.sh: emit ggml-metal-embed.s right after the LM_ prefix sed pass. The od invocation intentionally omits -w16 because macOS BSD od rejects it ("illegal option -- w"); GNU od and BSD od both default to 16 bytes per line. - The Mach-O section name is __ggml_metallib (15 chars), not the LM_-prefixed variant, because Mach-O caps section specifiers at 16 characters. Only the exported symbols carry the LM_ prefix. - ios/CMakeLists.txt: project() needs LANGUAGES ASM so the Xcode generator emits a build rule for .s sources; without it, .s files are silently dropped from the build phase and the link step fails with undefined _lm_ggml_metallib_{start,end}. Tested on iPhone 13 mini (A15) with iOS 26.5 — initLlama succeeds and the native log reports "lm_ggml_metal_library_init: using embedded metal library" / "loaded in 9.690 sec" instead of the "default.metallib not found ... XPC_ERROR_CONNECTION_INTERRUPTED" chain from the #348 repro. nm confirms _lm_ggml_metallib_start / _lm_ggml_metallib_end are present as data section symbols (S) in all four xcframework slices (ios-arm64, ios-simulator arm64+x86_64, tvos-arm64, tvos-simulator arm64+x86_64). * chore: ignore ggml-metal-embed.s --------- Co-authored-by: Jhen-Jie Hong <developer@jhen.me>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Going back to using the ggml-metal source to compile it at runtime, in this way we will not need #244.