Cross-compilation for iOS consists of the two steps below.
For cross-compilation, you need Xcode. It comes with the SDKs for iOS devices and the simulator, as well as the simctl
tool for controlling the simulator from the command line.
On your host platform, you should already be able to build IREE from source. Please make sure you've gone through the steps in getting started.
Build and install on your macOS host:
cmake -S . -B ../iree-build/ -GNinja \ -DCMAKE_BUILD_TYPE=RelWithDebInfo \ -DCMAKE_INSTALL_PREFIX=../iree-build/install cmake --build ../iree-build/ --target install
Build the runtime for the iOS Simulator.
cmake -S . -B ../build-ios-sim -GNinja \ -DCMAKE_SYSTEM_NAME=iOS \ -DCMAKE_OSX_SYSROOT=$(xcodebuild -version -sdk iphonesimulator Path) \ -DCMAKE_OSX_ARCHITECTURES=arm64 \ -DCMAKE_SYSTEM_PROCESSOR=arm64 \ -DCMAKE_OSX_DEPLOYMENT_TARGET=11.0 \ -DCMAKE_IOS_INSTALL_COMBINED=YES \ -DIREE_HOST_BIN_DIR="$PWD/../iree-build/install/bin" \ -DCMAKE_INSTALL_PREFIX=../build-ios-sim/install \ -DIREE_BUILD_COMPILER=OFF cmake --build ../build-ios-sim --config Release --target install
Or, we can build the runtime for iOS devices it by changing the value of the -DCMAKE OSX SYSROOT
option to:
-DCMAKE_OSX_SYSROOT=$(xcodebuild -version -sdk iphoneos Path)
Run the IREE compiler on the host to generate a module.
../iree-build/install/bin/iree-compile \ --iree-hal-target-backends=vmvx \ samples/models/simple_abs.mlir \ -o /tmp/simple_abs_vmvx.vmfb
We could test the generated module by running the macOS version of iree-run-module
on the host.
../iree-build/install/bin/iree-run-module \ --module=/tmp/simple_abs_vmvx.vmfb \ --device=local-task \ --function=abs \ --input="f32=-5"
To run it on the iOS simulator, we need to copy the vmfb file into the iree-run-module
iOS app bundle.
cp /tmp/simple_abs_vmvx.vmfb \ ../build-ios-sim/install/bin/iree-run-module.app/
Open the iOS Simulator Manager on the host.
open -a Simulator
After creating and booting a simulator in this app, you can list it from the command-line.
xcrun simctl list devices | grep Booted
This is what should come out of the command:
iPhone 14 Pro (12341234-ABCD-ABCD-ABCD-123412341234) (Booted)
where iPhone 14 Pro
is the device being simulated and 12341234-ABCD-ABCD-ABCD-123412341234
is the simulator's unique device ID (UDID).
Install the app iree-run-module
on the simulator, given its UDID.
xcrun simctl install <UDID> ../build-ios-sim/install/bin/iree-run-module.app
Check the path to the installed bundle, where the simple_abs_vmvx.vmfb
module should be found.
ls $(xcrun simctl get_app_container <UDID> dev.iree.iree-run-module)
The string dev.iree.iree-run-module
is the bundle identifier of the iOS app. The CMake building process generates it and saves it in the property list (plist) file ../build-ios-sim/install/bin/iree-run-module.app/Info.plist
.
Launch the iree-run-module
app on the simulator to run the IREE module simple_abs_vmvx.vmfb
.
xcrun simctl launch --console \ <UDID> \ dev.iree.runmodule \ --device=local-task \ --function=abs \ --input="f32=-5" \ --module=$(xcrun simctl get_app_container <UDID> dev.iree.iree-run-module)/simple_abs_vmvx.vmfb