Skip to content

Commit 49ef23c

Browse files
cccclaifacebook-github-bot
authored andcommitted
Update instruction for cross compilation
Summary: As title, instructions for cross compilation Reviewed By: tarun292 Differential Revision: D48165575 fbshipit-source-id: 4d3dadb00083e14151172064d7694434d03c228d
1 parent f61b600 commit 49ef23c

File tree

1 file changed

+77
-0
lines changed

1 file changed

+77
-0
lines changed

docs/website/docs/tutorials/cmake_build_system.md

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,3 +106,80 @@ I 00:00:00.002159 executorch:executor_runner.cpp:186] Inputs prepared.
106106
I 00:00:00.011684 executorch:executor_runner.cpp:195] Model executed successfully.
107107
I 00:00:00.011709 executorch:executor_runner.cpp:210] 8.000000
108108
```
109+
110+
111+
## Cross compilation
112+
113+
114+
### Android
115+
- Prerequisite: [Android NDK](https://developer.android.com/ndk), choose one of the following:
116+
- Option 1: Download Android Studio, [follow instruction here to install ndk](https://developer.android.com/studio/projects/install-ndk)
117+
- Option 2: Download NDK directly from [here](https://developer.android.com/ndk/downloads)
118+
119+
Assuming NDK is available on installed, run
120+
```bash
121+
# Run the following lines from executorch folder
122+
rm -r cmake-android-out
123+
mkdir cmake-android-out
124+
cd cmake-android-out
125+
126+
# point -DCMAKE_TOOLCHAIN_FILE to the location where ndk is installed
127+
# Run `which buck2`, if it returns empty (meaning the system doesn't know where buck2 is installed), pass in pass in this flag `-DBUCK2=/path/to/buck2` pointing to buck2
128+
cmake -DCMAKE_TOOLCHAIN_FILE=/Users/{user_name}/Library/Android/sdk/ndk/25.2.9519653/build/cmake/android.toolchain.cmake -DANDROID_ABI=arm64-v8a ..
129+
130+
cd ..
131+
cmake --build cmake-android-out -j9
132+
133+
# push the binary to an Android device
134+
adb push cmake-android-out/executor_runner /data/local/tmp/executorch
135+
136+
adb shell "/data/local/tmp/executorch/executor_runner --model_path /data/local/tmp/executorch/add.ff"
137+
```
138+
139+
### IOS
140+
```
141+
---
142+
**NOTE**
143+
While we're working on making it a smoother experience, here is an early workflow to try out cross compilation for iOS.
144+
---
145+
146+
```
147+
Only supported in mac
148+
149+
Prerequisites:
150+
- XCode
151+
152+
After XCode is installed,
153+
154+
1. Get the iOS cmake toolchain, options are
155+
- Option 1 [recommended] : use the `ios.toolchain.cmake` from the following github repo
156+
```bash
157+
git clone https://github.com/leetal/ios-cmake.git
158+
```
159+
- Option2 [wip], use the `iOS.cmake` from pytorch, the tool chain is located in `executorch/third-party/pytorch/pytorch/blob/main/cmake/iOS.cmake`
160+
161+
162+
2. Use the tool chain provided in the repro to build the executorch library.
163+
```bash
164+
rm -r cmake-ios-out
165+
mkdir cmake-ios-out
166+
cd cmake-ios-out
167+
168+
# change the platform accordingly, please refer to the table listed in Readme
169+
cmake . -G Xcode -DCMAKE_TOOLCHAIN_FILE=~/ios-cmake/ios.toolchain.cmake -DPLATFORM=SIMULATOR
170+
171+
# Create an include folder in cmake-ios-out to include all header files
172+
mkdir include
173+
cp -r ../runtime include
174+
cp -r ../extension include
175+
cp -r ../utils include
176+
```
177+
178+
179+
3. XCode setup
180+
181+
If using ios cmake tool chain from `https://github.com/leetal/ios-cmake.git`, after build:
182+
183+
- Open the project in XCode, drag the `executorch.xcodeproj` generated from Step 2 to `Frameworks`,
184+
- Go to project Target’s `Build Phases` - `Link Binaries With Libraries`, click the + sign and add all the library files located in `cmake-ios-out/build`.
185+
- Navigate to the project `Build Settings`, set the value **Header Search Paths** to `cmake-ios-out/include` and **Library Search Paths** to `cmake-ios-out/build`

0 commit comments

Comments
 (0)