From f663ba6621ea5588c11d2f764e4bc21d340c6190 Mon Sep 17 00:00:00 2001 From: Anthony Shoumikhin Date: Tue, 8 Oct 2024 14:43:13 -0700 Subject: [PATCH] Update build framework script to skip specifying buck executable. (#5985) Summary: Pull Request resolved: https://github.com/pytorch/executorch/pull/5985 . Reviewed By: dbort Differential Revision: D64053120 fbshipit-source-id: fc4149ee13130f913f96768a1370ea40ce8ed8b7 --- build/build_apple_frameworks.sh | 18 +++++++++++------- build/test_ios.sh | 9 +-------- docs/source/apple-runtime.md | 18 +++--------------- 3 files changed, 15 insertions(+), 30 deletions(-) diff --git a/build/build_apple_frameworks.sh b/build/build_apple_frameworks.sh index acd98583b8..0d5df75050 100755 --- a/build/build_apple_frameworks.sh +++ b/build/build_apple_frameworks.sh @@ -11,7 +11,6 @@ SOURCE_ROOT_DIR="" OUTPUT="cmake-out" MODE="Release" TOOLCHAIN="" -BUCK2=$(which buck2) PYTHON=$(which python3) FLATC=$(which flatc) COREML=OFF @@ -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." @@ -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 } @@ -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 ;; @@ -138,7 +135,6 @@ check_command() { check_command cmake check_command rsync -check_command "$BUCK2" check_command "$PYTHON" check_command "$FLATC" @@ -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 \ @@ -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" diff --git a/build/test_ios.sh b/build/test_ios.sh index 67b71e02ef..150a974cc1 100755 --- a/build/test_ios.sh +++ b/build/test_ios.sh @@ -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" @@ -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 @@ -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" diff --git a/docs/source/apple-runtime.md b/docs/source/apple-runtime.md index 023903db3b..e17ee3ea2f 100644 --- a/docs/source/apple-runtime.md +++ b/docs/source/apple-runtime.md @@ -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 @@ -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 @@ -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.