From 9aa9a26a3c233d440335a0c3153a541c2b7c921a Mon Sep 17 00:00:00 2001 From: Farid Zakaria Date: Thu, 18 Jan 2024 13:05:38 -0800 Subject: [PATCH] Make building Python bindings optional (#1926) Many developers are using the ci_build_* scripts to build LLVM and StableHLO. A previous PR #1923 made the CI system by default building python bindings however there is an undocumented step of installing Python dependencies such as pybind. To simplify local development, make the option configurable with the default to OFF so that the ci_build_* actions work without any additional setup. The CI system itself (GitHub actions) set the appropriate variables to build the Python bindings. --- .github/workflows/buildAndTestCMake.yml | 8 +++++++- build_tools/github_actions/ci_build_cmake.sh | 10 +++++++--- build_tools/github_actions/ci_build_cmake_llvm.sh | 8 ++++++-- 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/.github/workflows/buildAndTestCMake.yml b/.github/workflows/buildAndTestCMake.yml index 3b258a007fc..75816a9b889 100644 --- a/.github/workflows/buildAndTestCMake.yml +++ b/.github/workflows/buildAndTestCMake.yml @@ -70,8 +70,14 @@ jobs: shell: bash run: | ./build_tools/github_actions/ci_build_cmake_llvm.sh "$LLVM_PROJECT_DIR" "$LLVM_BUILD_DIR" + env: + CMAKE_BUILD_TYPE: Release + MLIR_ENABLE_BINDINGS_PYTHON: ON - name: Build and Test StableHLO (with Python bindings) shell: bash run: | - ./build_tools/github_actions/ci_build_cmake.sh "$LLVM_BUILD_DIR" "$STABLEHLO_BUILD_DIR" \ No newline at end of file + ./build_tools/github_actions/ci_build_cmake.sh "$LLVM_BUILD_DIR" "$STABLEHLO_BUILD_DIR" + env: + CMAKE_BUILD_TYPE: Release + STABLEHLO_ENABLE_BINDINGS_PYTHON: ON \ No newline at end of file diff --git a/build_tools/github_actions/ci_build_cmake.sh b/build_tools/github_actions/ci_build_cmake.sh index b6e03eaac66..43c664c2389 100755 --- a/build_tools/github_actions/ci_build_cmake.sh +++ b/build_tools/github_actions/ci_build_cmake.sh @@ -27,12 +27,16 @@ fi LLVM_BUILD_DIR="$1" STABLEHLO_BUILD_DIR="$2" +CMAKE_BUILD_TYPE="${CMAKE_BUILD_TYPE:-RelWithDebInfo}" + +# Turn on building Python bindings +STABLEHLO_ENABLE_BINDINGS_PYTHON="${STABLEHLO_ENABLE_BINDINGS_PYTHON:-OFF}" # Configure StableHLO cmake -GNinja \ -B"$STABLEHLO_BUILD_DIR" \ -DLLVM_ENABLE_LLD=ON \ - -DCMAKE_BUILD_TYPE=Release \ + -DCMAKE_BUILD_TYPE="${CMAKE_BUILD_TYPE}" \ -DLLVM_ENABLE_ASSERTIONS=ON \ -DMLIR_DIR="$LLVM_BUILD_DIR/lib/cmake/mlir" \ -DCMAKE_CXX_COMPILER=clang++ \ @@ -40,8 +44,8 @@ cmake -GNinja \ -DCMAKE_C_COMPILER=clang \ -DCMAKE_C_COMPILER_LAUNCHER=ccache \ -DSTABLEHLO_ENABLE_STRICT_BUILD=ON \ - -DSTABLEHLO_ENABLE_BINDINGS_PYTHON=ON + -DSTABLEHLO_ENABLE_BINDINGS_PYTHON="${STABLEHLO_ENABLE_BINDINGS_PYTHON}" # Build and Test StableHLO -cd "$STABLEHLO_BUILD_DIR" +cd "$STABLEHLO_BUILD_DIR" || exit ninja check-stablehlo-ci diff --git a/build_tools/github_actions/ci_build_cmake_llvm.sh b/build_tools/github_actions/ci_build_cmake_llvm.sh index 6cb285a69e1..fdc4b0bb322 100755 --- a/build_tools/github_actions/ci_build_cmake_llvm.sh +++ b/build_tools/github_actions/ci_build_cmake_llvm.sh @@ -25,6 +25,10 @@ fi LLVM_SRC_DIR="$1" LLVM_BUILD_DIR="$2" +CMAKE_BUILD_TYPE="${CMAKE_BUILD_TYPE:-RelWithDebInfo}" +# Turn on building Python bindings +MLIR_ENABLE_BINDINGS_PYTHON="${MLIR_ENABLE_BINDINGS_PYTHON:-OFF}" + # Configure LLVM cmake -GNinja \ "-H$LLVM_SRC_DIR/llvm" \ @@ -34,11 +38,11 @@ cmake -GNinja \ -DLLVM_ENABLE_PROJECTS=mlir \ -DLLVM_TARGETS_TO_BUILD=host \ -DLLVM_INCLUDE_TOOLS=ON \ - -DMLIR_ENABLE_BINDINGS_PYTHON=ON \ + -DMLIR_ENABLE_BINDINGS_PYTHON="${MLIR_ENABLE_BINDINGS_PYTHON}" \ -DLLVM_ENABLE_BINDINGS=OFF \ -DLLVM_BUILD_TOOLS=OFF \ -DLLVM_INCLUDE_TESTS=OFF \ - -DCMAKE_BUILD_TYPE=RelWithDebInfo \ + -DCMAKE_BUILD_TYPE="${CMAKE_BUILD_TYPE}" \ -DLLVM_ENABLE_ASSERTIONS=On \ -DCMAKE_CXX_COMPILER=clang++ \ -DCMAKE_CXX_COMPILER_LAUNCHER=ccache \