- Added BUILD_FROM_SOURCE.md with detailed error analysis - Documented SDK version issues and miniaudio cross-compilation problems - Provided alternative approaches and recommendations
4.6 KiB
Building LiteRT-LM for iOS from Source
Status: Build Issues Encountered
We attempted to build LiteRT-LM iOS binaries from source but encountered significant cross-compilation challenges with Bazel.
Build Attempt Summary
Environment
- Machine: Mac Mini (Apple Silicon)
- OS: macOS 15.x
- Xcode: CommandLineTools SDK 15.5
- Bazel: 7.6.1 (via Bazelisk)
Commands Attempted
# Clone repository
git clone https://github.com/google-ai-edge/LiteRT-LM.git
cd LiteRT-LM
# Build for iOS device (arm64)
bazel build --config=ios_arm64 //c:engine
# Build for iOS simulator (arm64)
bazel build --config=ios_sim_arm64 //c:engine
Issues Encountered
1. SDK Version Mismatch
ERROR: SDK version [10.11] for platform [MacOSX] is unsupported
xcrun: error: SDK "macosx10.11" cannot be located
Attempted Fix: Created .bazelrc.user with --macos_sdk_version=15.5
2. OpenGLES Header Missing
fatal error: 'OpenGLES/EAGL.h' file not found
#import <OpenGLES/EAGL.h>
Root Cause: The miniaudio library uses AVFoundation framework which on macOS includes CoreImage, which requires OpenGLES headers. When cross-compiling for iOS from macOS, Bazel incorrectly uses the host macOS SDK for some compilation steps.
Attempted Fixes:
- Patched
BUILD.miniaudioto use different SDK frameworks - Patched
runtime/components/preprocessor/BUILDto use C version instead of ObjC version - Neither fully resolved the issue
3. Objective-C Syntax Errors
error: expected identifier or '('
@class NSInvocation, NSMethodSignature, NSCoder, NSString, NSEnumerator;
Root Cause: After switching to C version of miniaudio, the C compiler tried to parse Objective-C headers.
Patches Applied
.bazelrc.user- SDK version override:
build --macos_sdk_version=15.5
build --ios_sdk_version=18.0
-
BUILD.miniaudio- Added more SDK frameworks -
runtime/components/preprocessor/BUILD- Changed miniaudio selection to use C version
Why These Issues Occur
-
Complex Cross-Compilation: LiteRT-LM uses Bazel with rules_apple for iOS builds, which requires precise toolchain configuration.
-
Audio Dependencies: The miniaudio library needs platform-specific audio backends (AVFoundation on iOS/macOS), which creates complications during cross-compilation.
-
Host vs Target Toolchains: Bazel is mixing host (macOS) and target (iOS) toolchains, causing SDK mismatches.
Alternative Approaches
Option 1: Use Full Xcode (Not CommandLineTools)
The build may work better with full Xcode installation which has proper iOS SDKs:
sudo xcode-select -s /Applications/Xcode.app/Contents/Developer
Option 2: Build on Linux with iOS Cross-Compilation
Use a Linux machine with proper iOS cross-compilation toolchain setup.
Option 3: Wait for Official Binaries
Google may provide prebuilt iOS binaries in future releases.
Option 4: Use MediaPipe Tasks (Working Alternative)
While deprecated, MediaPipe Tasks LLM Inference has a working Swift API:
pod 'MediaPipeTasksGenAI', '~> 0.10.0'
Option 5: Use LiteRT C API with Custom Bridge
Build only the core LiteRT runtime (without LLM features) and implement the conversation handling in Swift.
Recommendation
For immediate use: Use the Objective-C++ bridge pattern with stub implementation (already provided in the project) and wait for:
- Official LiteRT-LM iOS binaries from Google
- LiteRT-LM Swift API release (marked as "coming soon")
For production: Consider building on a CI service like GitHub Actions with proper macOS/iOS build environment.
Build Scripts
The following scripts were created during the build attempt:
/tmp/build_litert_lm_ios.sh
Main build script that attempts to build both device and simulator libraries.
/tmp/patch_miniaudio_build.py
Patches the miniaudio BUILD file to add additional SDK frameworks.
/tmp/patch_preprocessor_build.py
Patches the preprocessor BUILD file to use C version of miniaudio.
Next Steps
To successfully build from source, you would need to:
- Install full Xcode (not just CommandLineTools)
- Set up proper iOS signing certificates
- Modify the Bazel build configuration to handle audio dependencies correctly
- Potentially disable audio features entirely for a text-only build
- Build in a clean environment with sufficient disk space (20GB+)