Skip to content

Commit

Permalink
Update build framework script to skip specifying buck executable. (py…
Browse files Browse the repository at this point in the history
…torch#5985)

Summary:
Pull Request resolved: pytorch#5985

.

Reviewed By: dbort

Differential Revision: D64053120

fbshipit-source-id: fc4149ee13130f913f96768a1370ea40ce8ed8b7
  • Loading branch information
shoumikhin authored and facebook-github-bot committed Oct 8, 2024
1 parent 2435364 commit f663ba6
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 30 deletions.
18 changes: 11 additions & 7 deletions build/build_apple_frameworks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ SOURCE_ROOT_DIR=""
OUTPUT="cmake-out"
MODE="Release"
TOOLCHAIN=""
BUCK2=$(which buck2)
PYTHON=$(which python3)
FLATC=$(which flatc)
COREML=OFF
Expand Down Expand Up @@ -80,7 +79,6 @@ usage() {
echo " --output=DIR Output directory. Default: 'cmake-out'"
echo " --Debug Use Debug build mode. Default: Uses Release build mode."
echo " --toolchain=FILE Cmake toolchain file. Default: '\$SOURCE_ROOT_DIR/third-party/ios-cmake/ios.toolchain.cmake'"
echo " --buck2=FILE Buck2 executable path. Default: Path of buck2 found in the current \$PATH"
echo " --python=FILE Python executable path. Default: Path of python3 found in the current \$PATH"
echo " --flatc=FILE FlatBuffers Compiler executable path. Default: Path of flatc found in the current \$PATH"
echo " --coreml Include this flag to build the Core ML backend."
Expand All @@ -92,7 +90,7 @@ usage() {
echo " --xnnpack Include this flag to build the XNNPACK backend."
echo
echo "Example:"
echo " $0 /path/to/source/root --output=cmake-out --toolchain=/path/to/cmake/toolchain --buck2=/path/to/buck2 --python=/path/to/python3 --coreml --mps --xnnpack"
echo " $0 /path/to/source/root --output=cmake-out --toolchain=/path/to/cmake/toolchain --python=/path/to/python3 --coreml --mps --xnnpack"
exit 0
}

Expand All @@ -102,7 +100,6 @@ for arg in "$@"; do
--output=*) OUTPUT="${arg#*=}" ;;
--Debug) MODE="Debug" ;;
--toolchain=*) TOOLCHAIN="${arg#*=}" ;;
--buck2=*) BUCK2="${arg#*=}" ;;
--python=*) PYTHON="${arg#*=}" ;;
--flatc=*) FLATC="${arg#*=}" ;;
--coreml) COREML=ON ;;
Expand Down Expand Up @@ -138,7 +135,6 @@ check_command() {

check_command cmake
check_command rsync
check_command "$BUCK2"
check_command "$PYTHON"
check_command "$FLATC"

Expand All @@ -158,7 +154,6 @@ cmake_build() {
-DCMAKE_TOOLCHAIN_FILE="$TOOLCHAIN" \
-DCMAKE_XCODE_ATTRIBUTE_CLANG_CXX_LANGUAGE_STANDARD="c++17" \
-DCMAKE_XCODE_ATTRIBUTE_CLANG_CXX_LIBRARY="libc++" \
-DBUCK2="$BUCK2" \
-DPYTHON_EXECUTABLE="$PYTHON" \
-DFLATC_EXECUTABLE="$FLATC" \
-DEXECUTORCH_BUILD_COREML=$COREML \
Expand Down Expand Up @@ -190,7 +185,16 @@ echo "Exporting headers"

mkdir -p "$HEADERS_PATH"

"$SOURCE_ROOT_DIR"/build/print_exported_headers.py --buck2="$BUCK2" --targets \
# Set BUCK2 to the path of the buck2 executable in $OUTPUT/*/buck2-bin/buck2-*
BUCK2=$(find . -type f -path '*/buck2-bin/buck2-*' | head -n 1)
if [[ -z "$BUCK2" ]]; then
echo "Could not find buck2 executable in any buck2-bin directory under $OUTPUT"
BUCK2=$(which buck2)
fi

check_command "$BUCK2"

"$SOURCE_ROOT_DIR"/build/print_exported_headers.py --buck2=$(realpath "$BUCK2") --targets \
//extension/module: \
//extension/tensor: \
| rsync -av --files-from=- "$SOURCE_ROOT_DIR" "$HEADERS_PATH/executorch"
Expand Down
9 changes: 1 addition & 8 deletions build/test_ios.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@ set -e

OUTPUT="${1:-executorch}"
EXIT_STATUS=0
BUCK2_RELEASE_DATE="2024-05-15"
BUCK2_ARCHIVE="buck2-aarch64-apple-darwin.zst"
BUCK2=".venv/bin/buck2"
APP_PATH="examples/demo-apps/apple_ios/ExecuTorchDemo/ExecuTorchDemo"
MODEL_NAME="mv3"
SIMULATOR_NAME="executorch"
Expand Down Expand Up @@ -66,10 +63,6 @@ say "Installing Requirements"

pip install --upgrade cmake pip setuptools wheel zstd

curl -LO "https://github.com/facebook/buck2/releases/download/$BUCK2_RELEASE_DATE/$BUCK2_ARCHIVE"
zstd -cdq "$BUCK2_ARCHIVE" > "$BUCK2" && chmod +x "$BUCK2"
rm "$BUCK2_ARCHIVE"

./install_requirements.sh --pybind coreml mps xnnpack
export PATH="$(realpath third-party/flatbuffers/cmake-out):$PATH"
./build/install_flatc.sh
Expand Down Expand Up @@ -99,7 +92,7 @@ curl https://raw.githubusercontent.com/pytorch/hub/master/imagenet_classes.txt \

say "Building Frameworks"

./build/build_apple_frameworks.sh --buck2="$(realpath $BUCK2)" --coreml --custom --mps --optimized --portable --quantized --xnnpack
./build/build_apple_frameworks.sh --coreml --custom --mps --optimized --portable --quantized --xnnpack
mv cmake-out "$APP_PATH/Frameworks"

say "Creating Simulator"
Expand Down
18 changes: 3 additions & 15 deletions docs/source/apple-runtime.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,19 +121,7 @@ source .venv/bin/activate
pip install --upgrade cmake pip zstd
```

5. Install a compatible version of [Buck2](https://buck.build):

```bash
BUCK2_RELEASE_DATE="2024-05-15"
BUCK2_ARCHIVE="buck2-aarch64-apple-darwin.zst"
BUCK2=".venv/bin/buck2"

curl -LO "https://github.com/facebook/buck2/releases/download/$BUCK2_RELEASE_DATE/$BUCK2_ARCHIVE"
zstd -cdq "$BUCK2_ARCHIVE" > "$BUCK2" && chmod +x "$BUCK2"
rm "$BUCK2_ARCHIVE"
```

6. Install the required dependencies, including those needed for the backends like [Core ML](build-run-coreml.md) or [MPS](build-run-mps.md), if you plan to build them as well:
5. Install the required dependencies, including those needed for the backends like [Core ML](build-run-coreml.md) or [MPS](build-run-mps.md), if you plan to build them as well:

```bash
./install_requirements.sh
Expand All @@ -145,7 +133,7 @@ rm "$BUCK2_ARCHIVE"
./backends/apple/mps/install_requirements.sh
```

7. Use the provided script to build .xcframeworks:
6. Use the provided script to build .xcframeworks:

```bash
./build/build_apple_frameworks.sh --help
Expand All @@ -154,7 +142,7 @@ rm "$BUCK2_ARCHIVE"
For example, the following invocation will build the ExecuTorch Runtime and all currently available kernels and backends for the Apple platform:

```bash
./build/build_apple_frameworks.sh --buck2="$(realpath $BUCK2)" --coreml --custom --mps --optimized --portable --quantized --xnnpack
./build/build_apple_frameworks.sh --coreml --custom --mps --optimized --portable --quantized --xnnpack
```

After the build finishes successfully, the resulting frameworks can be found in the `cmake-out` directory.
Expand Down

0 comments on commit f663ba6

Please sign in to comment.