Skip to content

switch to brew install flatc #447

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions build/install_flatc.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#!/bin/bash
# Copyright (c) Meta Platforms, Inc. and affiliates.
# All rights reserved.
#
# This source code is licensed under the BSD-style license found in the
# LICENSE file in the root directory of this source tree.

# This file is meant to build flatc from the `third-party/flatbuffers` folder and help
# users to ensure it's installed correctly

ROOT=$(cd -- "$(dirname "$(dirname -- "${BASH_SOURCE[0]}")")" &> /dev/null && pwd)
FLATBUFFERS_PATH="$ROOT/third-party/flatbuffers"

# Get the flatbuffers version from the git submodule
get_flatbuffers_version(){
pushd "$FLATBUFFERS_PATH" || exit
FLATBUFFERS_VERSION=$(git describe --tags "$(git rev-list --tags --max-count=1)" | sed 's/^v//')
popd || exit
}

FLATC_PATH="$(which flatc 2>&1)"

GREEN='\033[0;32m' # GREEN Color
RED='\033[0;31m' # Red Color
NC='\033[0m' # No Color

get_flatbuffers_version
echo "flatbuffers version in $FLATBUFFERS_PATH is: $FLATBUFFERS_VERSION"

# Warn the users to uninstall flatc from conda
if [[ "$FLATC_PATH" == *miniconda3* ]]; then
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."
echo "Please run the following lines to remove it: "
echo " conda uninstall flatbuffers"
exit
fi

# Check the following:
# 1. the path to the flatc command if it exists in the system's PATH
# 2. execute the flatc command and check the version
if { command -v flatc; } && { flatc --version | grep "$FLATBUFFERS_VERSION" &> /dev/null; }; then
echo "${GREEN}flatc is installed successfully and ready to use. ${NC}"
else
# Check the existence of flatc in flatbuffers path, if it exists, instruct users to export it to path
if [[ -f "$FLATBUFFERS_PATH/flatc" ]]; then
echo "${RED}flatc is built in $FLATBUFFERS_PATH/flatc but hasn't added to path, run following lines: "
echo " export PATH=$FLATBUFFERS_PATH:\$PATH ${NC}"
else
# flatc is not in flatbuffers path, build it and instruct users to export it to path
pushd "$FLATBUFFERS_PATH" || exit
cmake --build . --target flatc
echo "flatc path: $FLATBUFFERS_PATH/flatc"
popd || exit
echo "${RED}Finished building flatc. Run the following lines to add it to PATH, then re-run this script:"
echo " export PATH=\"$FLATBUFFERS_PATH:\$PATH\" "
echo " bash build/install_flatc.sh${NC}"
fi
fi
6 changes: 0 additions & 6 deletions docs/source/getting-started-setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,6 @@ the steps in the [conda installation guide](https://conda.io/projects/conda/en/l
conda activate executorch
```

1. Install the flatbuffers `flatc` command line tool if you do not already have it:

```bash
conda install -c conda-forge flatbuffers
```

1. Clone the `executorch` repository:

```bash
Expand Down
48 changes: 36 additions & 12 deletions docs/website/docs/tutorials/cmake_build_system.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,12 +122,22 @@ Assuming NDK is available on installed, run
# Run the following lines from executorch folder
rm -rf cmake-android-out && mkdir cmake-android-out && cd cmake-android-out

# point -DCMAKE_TOOLCHAIN_FILE to the location where ndk is installed
# 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
cmake -DCMAKE_TOOLCHAIN_FILE=/Users/{user_name}/Library/Android/sdk/ndk/25.2.9519653/build/cmake/android.toolchain.cmake -DANDROID_ABI=arm64-v8a ..

cd ..
cmake --build cmake-android-out -j9
BUCK2=/path/to/buck2
FLATC=/path/to/flatc
NDK_ROOT=${HOME}/Library/Android/sdk/ndk/25.2.9519653

# Point -DCMAKE_TOOLCHAIN_FILE to the location where ndk is installed.
# If BUCK2 or FLATC aren't specified, fall back to using
# the commands on the PATH.
cmake \
-DCMAKE_TOOLCHAIN_FILE=${NDK_ROOT}/build/cmake/android.toolchain.cmake \
-DANDROID_ABI=arm64-v8a \
-DBUCK2="${BUCK2:-$(which buck2)}" \
-DFLATC_EXECUTABLE="${FLATC:-$(which flatc)}" \
..

# Move to the executorch folder and build
cd .. && cmake --build cmake-android-out -j9

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

# change the platform accordingly, please refer to the table listed in Readme
cmake . -G Xcode -DCMAKE_TOOLCHAIN_FILE=~/ios-cmake/ios.toolchain.cmake -DPLATFORM=SIMULATOR
BUCK2=/path/to/buck2
FLATC=/path/to/flatc
PYTHON=/path/to/miniconda/envs/executorch/bin/python3
# The path to the cloned ios-cmake repo
IOS_CMAKE=/path/to/ios-cmake

# Change the PLATFORM accordingly; please refer to the table listed in https://github.com/leetal/ios-cmake#readme
cmake \
-G Xcode \
-DCMAKE_TOOLCHAIN_FILE=${IOS_CMAKE}/ios.toolchain.cmake \
-DPLATFORM=SIMULATOR \
-DBUCK2="${BUCK2:-$(which buck2)}" \
-DFLATC_EXECUTABLE="${FLATC:-$(which flatc)}" \
-DPYTHON_EXECUTABLE="${PYTHON:-$(which python3)}" \
..

# Move to the executorch folder and build
cd .. && cmake --build cmake-ios-out -j9

# Create an include folder in cmake-ios-out to include all header files
mkdir include
cp -r ../runtime include
cp -r ../extension include
cp -r ../utils include
(cd cmake-ios-out && mkdir include && cd include && \
ln -s ../../runtime ../../util ../../extension .)
```


Expand Down
3 changes: 3 additions & 0 deletions install_requirements.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,6 @@ pip install --pre transformers==${TRANSFORMERS_VERSION}

TORCHSR_VERSION=1.0.4
pip install --pre torchsr==${TORCHSR_VERSION}

# Install flatc dependency
bash build/install_flatc.sh