Skip to content

Commit a53b0a4

Browse files
cccclaifacebook-github-bot
authored andcommitted
Update instruction to install flatc (#447)
Summary: See context in D49487908, the `flatc` from `brew install flatbuffers` seems good. config change is in D49780588 Reviewed By: dbort Differential Revision: D49530021
1 parent d3ccc62 commit a53b0a4

File tree

4 files changed

+97
-18
lines changed

4 files changed

+97
-18
lines changed

build/install_flatc.sh

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
#!/bin/bash
2+
# Copyright (c) Meta Platforms, Inc. and affiliates.
3+
# All rights reserved.
4+
#
5+
# This source code is licensed under the BSD-style license found in the
6+
# LICENSE file in the root directory of this source tree.
7+
8+
# This file is meant to build flatc from the `third-party/flatbuffers` folder and help
9+
# users to ensure it's installed correctly
10+
11+
ROOT=$(cd -- "$(dirname "$(dirname -- "${BASH_SOURCE[0]}")")" &> /dev/null && pwd)
12+
FLATBUFFERS_PATH="$ROOT/third-party/flatbuffers"
13+
14+
# Get the flatbuffers version from the git submodule
15+
get_flatbuffers_version(){
16+
pushd "$FLATBUFFERS_PATH" || exit
17+
FLATBUFFERS_VERSION=$(git describe --tags "$(git rev-list --tags --max-count=1)" | sed 's/^v//')
18+
popd || exit
19+
}
20+
21+
FLATC_PATH="$(which flatc 2>&1)"
22+
23+
GREEN='\033[0;32m' # GREEN Color
24+
RED='\033[0;31m' # Red Color
25+
NC='\033[0m' # No Color
26+
27+
get_flatbuffers_version
28+
echo "flatbuffers version in $FLATBUFFERS_PATH is: $FLATBUFFERS_VERSION"
29+
30+
# Warn the users to uninstall flatc from conda
31+
if [[ "$FLATC_PATH" == *miniconda3* ]]; then
32+
echo "${RED}From the flatc path: $FLATC_PATH, it seems it's installed with conda. The flatc from conda is problematic and please avoid using it."
33+
echo "Please run the following lines to remove it: "
34+
echo " conda uninstall flatbuffers"
35+
exit
36+
fi
37+
38+
# Check the following:
39+
# 1. the path to the flatc command if it exists in the system's PATH
40+
# 2. execute the flatc command and check the version
41+
if { command -v flatc; } && { flatc --version | grep "$FLATBUFFERS_VERSION" &> /dev/null; }; then
42+
echo "${GREEN}flatc is installed successfully and ready to use. ${NC}"
43+
else
44+
# Check the existence of flatc in flatbuffers path, if it exists, instruct users to export it to path
45+
if [[ -f "$FLATBUFFERS_PATH/flatc" ]]; then
46+
echo "${RED}flatc is built in $FLATBUFFERS_PATH/flatc but hasn't added to path, run following lines: "
47+
echo " export PATH=$FLATBUFFERS_PATH:\$PATH ${NC}"
48+
else
49+
# flatc is not in flatbuffers path, build it and instruct users to export it to path
50+
pushd "$FLATBUFFERS_PATH" || exit
51+
cmake --build . --target flatc
52+
echo "flatc path: $FLATBUFFERS_PATH/flatc"
53+
popd || exit
54+
echo "${RED}Finished building flatc. Run the following lines to add it to PATH, then re-run this script:"
55+
echo " export PATH=\"$FLATBUFFERS_PATH:\$PATH\" "
56+
echo " bash build/install_flatc.sh${NC}"
57+
fi
58+
fi

docs/source/getting-started-setup.md

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,6 @@ the steps in the [conda installation guide](https://conda.io/projects/conda/en/l
6565
conda activate executorch
6666
```
6767

68-
1. Install the flatbuffers `flatc` command line tool if you do not already have it:
69-
70-
```bash
71-
conda install -c conda-forge flatbuffers
72-
```
73-
7468
1. Clone the `executorch` repository:
7569

7670
```bash

docs/website/docs/tutorials/cmake_build_system.md

Lines changed: 36 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -122,12 +122,22 @@ Assuming NDK is available on installed, run
122122
# Run the following lines from executorch folder
123123
rm -rf cmake-android-out && mkdir cmake-android-out && cd cmake-android-out
124124

125-
# point -DCMAKE_TOOLCHAIN_FILE to the location where ndk is installed
126-
# 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
127-
cmake -DCMAKE_TOOLCHAIN_FILE=/Users/{user_name}/Library/Android/sdk/ndk/25.2.9519653/build/cmake/android.toolchain.cmake -DANDROID_ABI=arm64-v8a ..
128-
129-
cd ..
130-
cmake --build cmake-android-out -j9
125+
BUCK2=/path/to/buck2
126+
FLATC=/path/to/flatc
127+
NDK_ROOT=${HOME}/Library/Android/sdk/ndk/25.2.9519653
128+
129+
# Point -DCMAKE_TOOLCHAIN_FILE to the location where ndk is installed.
130+
# If BUCK2 or FLATC aren't specified, fall back to using
131+
# the commands on the PATH.
132+
cmake \
133+
-DCMAKE_TOOLCHAIN_FILE=${NDK_ROOT}/build/cmake/android.toolchain.cmake \
134+
-DANDROID_ABI=arm64-v8a \
135+
-DBUCK2="${BUCK2:-$(which buck2)}" \
136+
-DFLATC_EXECUTABLE="${FLATC:-$(which flatc)}" \
137+
..
138+
139+
# Move to the executorch folder and build
140+
cd .. && cmake --build cmake-android-out -j9
131141

132142
# push the binary to an Android device
133143
adb push cmake-android-out/executor_runner /data/local/tmp/executorch
@@ -162,14 +172,28 @@ git clone https://github.com/leetal/ios-cmake.git
162172
```bash
163173
rm -rf cmake-ios-out && mkdir cmake-ios-out && cd cmake-ios-out
164174

165-
# change the platform accordingly, please refer to the table listed in Readme
166-
cmake . -G Xcode -DCMAKE_TOOLCHAIN_FILE=~/ios-cmake/ios.toolchain.cmake -DPLATFORM=SIMULATOR
175+
BUCK2=/path/to/buck2
176+
FLATC=/path/to/flatc
177+
PYTHON=/path/to/miniconda/envs/executorch/bin/python3
178+
# The path to the cloned ios-cmake repo
179+
IOS_CMAKE=/path/to/ios-cmake
180+
181+
# Change the PLATFORM accordingly; please refer to the table listed in https://github.com/leetal/ios-cmake#readme
182+
cmake \
183+
-G Xcode \
184+
-DCMAKE_TOOLCHAIN_FILE=${IOS_CMAKE}/ios.toolchain.cmake \
185+
-DPLATFORM=SIMULATOR \
186+
-DBUCK2="${BUCK2:-$(which buck2)}" \
187+
-DFLATC_EXECUTABLE="${FLATC:-$(which flatc)}" \
188+
-DPYTHON_EXECUTABLE="${PYTHON:-$(which python3)}" \
189+
..
190+
191+
# Move to the executorch folder and build
192+
cd .. && cmake --build cmake-ios-out -j9
167193

168194
# Create an include folder in cmake-ios-out to include all header files
169-
mkdir include
170-
cp -r ../runtime include
171-
cp -r ../extension include
172-
cp -r ../utils include
195+
(cd cmake-ios-out && mkdir include && cd include && \
196+
ln -s ../../runtime ../../util ../../extension .)
173197
```
174198

175199

install_requirements.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,6 @@ pip install --pre transformers==${TRANSFORMERS_VERSION}
3636

3737
TORCHSR_VERSION=1.0.4
3838
pip install --pre torchsr==${TORCHSR_VERSION}
39+
40+
# Install flatc dependency
41+
bash build/install_flatc.sh

0 commit comments

Comments
 (0)