This is an automated email from the ASF dual-hosted git repository.

chaokunyang pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/fory.git


The following commit(s) were added to refs/heads/main by this push:
     new 847087a1d refactor(ci): install Bazel using setup-bazel (#3494)
847087a1d is described below

commit 847087a1d18443aba4a9ccf36f8ff2bc831185d0
Author: Peiyang He <[email protected]>
AuthorDate: Thu Mar 19 01:29:46 2026 -0400

    refactor(ci): install Bazel using setup-bazel (#3494)
    
    ## Why?
    
    - Setting up Bazel manually cannot handle network issues properly.
    - old `rules_cc` version will cause one job failure on the latest macOS
    runner.
    
    ## What does this PR do?
    
    
    
    - Setting up Bazel using GitHub action across CI.
    - Bump `rules_cc` version.
    
    ## Related issues
    
    No.
    
    ## AI Contribution Checklist
    
    No.
    
    ## Does this PR introduce any user-facing change?
    
    No.
    
    ## Benchmark
    
    No.
---
 .github/workflows/build-containerized-pr.yml      |   7 +-
 .github/workflows/build-containerized-release.yml |   7 +-
 .github/workflows/build-native-pr.yml             |  38 ++---
 .github/workflows/build-native-release.yml        |  38 ++---
 .github/workflows/ci.yml                          |  86 +++---------
 MODULE.bazel                                      |   2 +-
 ci/build_linux_wheels.py                          |  29 +++-
 ci/run_ci.py                                      |   7 +-
 ci/run_ci.sh                                      |  87 ------------
 ci/tasks/common.py                                | 162 +---------------------
 ci/tasks/python_container_build_script.sh         |   7 +-
 11 files changed, 92 insertions(+), 378 deletions(-)

diff --git a/.github/workflows/build-containerized-pr.yml 
b/.github/workflows/build-containerized-pr.yml
index 837a50811..149b1f2a4 100644
--- a/.github/workflows/build-containerized-pr.yml
+++ b/.github/workflows/build-containerized-pr.yml
@@ -32,8 +32,13 @@ jobs:
         python: [cp313-cp313]
     steps:
       - uses: actions/checkout@v5
+      - name: Set up Bazel
+        uses: bazel-contrib/[email protected]
+        with:
+          bazelisk-cache: true
+          bazelisk-version: '1.x'
       - name: Build and test wheels
-        run: ./ci/build_linux_wheels.py --arch ${{ runner.arch }} --python ${{ 
matrix.python }}
+        run: ./ci/build_linux_wheels.py --arch ${{ runner.arch }} --python ${{ 
matrix.python }} --bazel-bin "$(command -v bazel)"
       - name: Upload wheels as artifacts
         uses: actions/upload-artifact@v4
         with:
diff --git a/.github/workflows/build-containerized-release.yml 
b/.github/workflows/build-containerized-release.yml
index 513a1cd99..23ac5d0c8 100644
--- a/.github/workflows/build-containerized-release.yml
+++ b/.github/workflows/build-containerized-release.yml
@@ -35,11 +35,16 @@ jobs:
           - cp313-cp313
     steps:
       - uses: actions/checkout@v5
+      - name: Set up Bazel
+        uses: bazel-contrib/[email protected]
+        with:
+          bazelisk-cache: true
+          bazelisk-version: '1.x'
       - name: Bump version
         # Pass the tag name from the push (e.g. "v0.12.1b1"); deploy.sh will 
strip leading "v".
         run: ./ci/deploy.sh bump_py_version "${{ github.ref_name }}"
       - name: Build and test wheels
-        run: ./ci/build_linux_wheels.py --arch ${{ runner.arch }} --python ${{ 
matrix.python }} --release
+        run: ./ci/build_linux_wheels.py --arch ${{ runner.arch }} --python ${{ 
matrix.python }} --release --bazel-bin "$(command -v bazel)"
       - name: Upload wheels as artifacts
         uses: actions/upload-artifact@v4
         with:
diff --git a/.github/workflows/build-native-pr.yml 
b/.github/workflows/build-native-pr.yml
index ad1a34b37..74a84e9ea 100644
--- a/.github/workflows/build-native-pr.yml
+++ b/.github/workflows/build-native-pr.yml
@@ -35,17 +35,11 @@ jobs:
         with:
           python-version: ${{ matrix.python-version }}
           cache: 'pip'
-      - name: Cache Bazel binary
-        uses: actions/cache@v4
+      - name: Set up Bazel
+        uses: bazel-contrib/[email protected]
         with:
-          path: |
-            ~/bin/bazel
-            ~/.local/bin/bazel
-            C:\bazel\bazel.exe
-          key: bazel-binary-${{ runner.os }}-${{ runner.arch }}-${{ 
hashFiles('.bazelversion') }}
-      - name: Install bazel (Windows)
-        run: ./ci/run_ci.sh install_bazel_windows
-        shell: bash
+          bazelisk-cache: true
+          bazelisk-version: '1.x'
       - name: Build wheel
         run: ./ci/deploy.sh build_pyfory
         shell: bash
@@ -72,15 +66,11 @@ jobs:
         with:
           python-version: ${{ matrix.python-version }}
           cache: 'pip'
-      - name: Cache Bazel binary
-        uses: actions/cache@v4
+      - name: Set up Bazel
+        uses: bazel-contrib/[email protected]
         with:
-          path: |
-            ~/bin/bazel
-            ~/.local/bin/bazel
-          key: bazel-binary-${{ runner.os }}-${{ runner.arch }}-${{ 
hashFiles('.bazelversion') }}
-      - name: Install bazel
-        run: ./ci/run_ci.sh install_bazel
+          bazelisk-cache: true
+          bazelisk-version: '1.x'
       - name: Build wheel
         run: ./ci/deploy.sh build_pyfory
         shell: bash
@@ -110,15 +100,11 @@ jobs:
         with:
           python-version: ${{ matrix.python-version }}
           cache: 'pip'
-      - name: Cache Bazel binary
-        uses: actions/cache@v4
+      - name: Set up Bazel
+        uses: bazel-contrib/[email protected]
         with:
-          path: |
-            ~/bin/bazel
-            ~/.local/bin/bazel
-          key: bazel-binary-${{ runner.os }}-${{ runner.arch }}-${{ 
hashFiles('.bazelversion') }}
-      - name: Install bazel
-        run: ./ci/run_ci.sh install_bazel
+          bazelisk-cache: true
+          bazelisk-version: '1.x'
       - name: Build wheel
         run: ./ci/deploy.sh build_pyfory
         shell: bash
diff --git a/.github/workflows/build-native-release.yml 
b/.github/workflows/build-native-release.yml
index 087674549..d3f302db3 100644
--- a/.github/workflows/build-native-release.yml
+++ b/.github/workflows/build-native-release.yml
@@ -36,17 +36,11 @@ jobs:
         with:
           python-version: ${{ matrix.python-version }}
           cache: 'pip'
-      - name: Cache Bazel binary
-        uses: actions/cache@v4
+      - name: Set up Bazel
+        uses: bazel-contrib/[email protected]
         with:
-          path: |
-            ~/bin/bazel
-            ~/.local/bin/bazel
-            C:\bazel\bazel.exe
-          key: bazel-binary-${{ runner.os }}-${{ runner.arch }}-${{ 
hashFiles('.bazelversion') }}
-      - name: Install bazel (Windows)
-        run: ./ci/run_ci.sh install_bazel_windows
-        shell: bash
+          bazelisk-cache: true
+          bazelisk-version: '1.x'
       - name: Build wheel
         shell: bash
         run: ./ci/deploy.sh build_pyfory
@@ -87,15 +81,11 @@ jobs:
         with:
           python-version: ${{ matrix.python-version }}
           cache: 'pip'
-      - name: Cache Bazel binary
-        uses: actions/cache@v4
+      - name: Set up Bazel
+        uses: bazel-contrib/[email protected]
         with:
-          path: |
-            ~/bin/bazel
-            ~/.local/bin/bazel
-          key: bazel-binary-${{ runner.os }}-${{ runner.arch }}-${{ 
hashFiles('.bazelversion') }}
-      - name: Install bazel
-        run: ./ci/run_ci.sh install_bazel
+          bazelisk-cache: true
+          bazelisk-version: '1.x'
       - name: Build wheel
         shell: bash
         run: ./ci/deploy.sh build_pyfory
@@ -138,15 +128,11 @@ jobs:
         with:
           python-version: ${{ matrix.python-version }}
           cache: 'pip'
-      - name: Cache Bazel binary
-        uses: actions/cache@v4
+      - name: Set up Bazel
+        uses: bazel-contrib/[email protected]
         with:
-          path: |
-            ~/bin/bazel
-            ~/.local/bin/bazel
-          key: bazel-binary-${{ runner.os }}-${{ runner.arch }}-${{ 
hashFiles('.bazelversion') }}
-      - name: Install bazel
-        run: ./ci/run_ci.sh install_bazel
+          bazelisk-cache: true
+          bazelisk-version: '1.x'
       - name: Build wheel
         shell: bash
         run: ./ci/deploy.sh build_pyfory
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 2fbeaaa97..00b8c3d04 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -569,16 +569,11 @@ jobs:
         with:
           python-version: 3.11
           cache: 'pip'
-      - name: Cache Bazel binary
-        uses: actions/cache@v4
+      - name: Set up Bazel
+        uses: bazel-contrib/[email protected]
         with:
-          path: |
-            ~/bin/bazel
-            ~/.local/bin/bazel
-            C:\bazel\bazel.exe
-          key: bazel-binary-${{ runner.os }}-${{ runner.arch }}-${{ 
hashFiles('.bazelversion') }}
-          restore-keys: |
-            bazel-binary-${{ runner.os }}-${{ runner.arch }}-
+          bazelisk-cache: true
+          bazelisk-version: '1.x'
       - name: Cache Bazel repository cache
         uses: actions/cache@v4
         with:
@@ -631,17 +626,11 @@ jobs:
           key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
           restore-keys: |
             ${{ runner.os }}-maven-
-      - name: Cache Bazel binary
-        uses: actions/cache@v4
+      - name: Set up Bazel
+        uses: bazel-contrib/[email protected]
         with:
-          path: |
-            ~/bin/bazel
-            ~/.local/bin/bazel
-          key: bazel-binary-${{ runner.os }}-${{ runner.arch }}-${{ 
hashFiles('.bazelversion') }}
-          restore-keys: |
-            bazel-binary-${{ runner.os }}-${{ runner.arch }}-
-      - name: Install bazel
-        run: python ./ci/run_ci.py cpp --install-deps-only
+          bazelisk-cache: true
+          bazelisk-version: '1.x'
       - name: Run CPP Xlang Test
         env:
           FORY_CPP_JAVA_CI: "1"
@@ -663,17 +652,11 @@ jobs:
         uses: actions/setup-python@v5
         with:
           python-version: '3.11'
-      - name: Cache Bazel binary
-        uses: actions/cache@v4
+      - name: Set up Bazel
+        uses: bazel-contrib/[email protected]
         with:
-          path: |
-            ~/bin/bazel
-            ~/.local/bin/bazel
-          key: bazel-binary-${{ runner.os }}-${{ runner.arch }}-${{ 
hashFiles('.bazelversion') }}
-          restore-keys: |
-            bazel-binary-${{ runner.os }}-${{ runner.arch }}-
-      - name: Install bazel
-        run: python ./ci/run_ci.py cpp --install-deps-only
+          bazelisk-cache: true
+          bazelisk-version: '1.x'
       - name: Build and run C++ hello_world example (CMake)
         run: |
           cd examples/cpp/hello_world
@@ -713,33 +696,11 @@ jobs:
         with:
           python-version: ${{ matrix.python-version }}
           cache: 'pip'
-      - name: Cache Bazel binary (Unix)
-        if: runner.os != 'Windows'
-        uses: actions/cache@v4
-        with:
-          path: |
-            ~/bin/bazel
-            ~/.local/bin/bazel
-          key: bazel-binary-v2-${{ runner.os }}-${{ runner.arch }}-${{ 
hashFiles('.bazelversion') }}
-          restore-keys: |
-            bazel-binary-v2-${{ runner.os }}-${{ runner.arch }}-
-          enableCrossOsArchive: false
-      - name: Cache Bazel binary (Windows)
-        if: runner.os == 'Windows'
-        uses: actions/cache@v4
+      - name: Set up Bazel
+        uses: bazel-contrib/[email protected]
         with:
-          path: C:\bazel\bazel.exe
-          key: bazel-binary-v2-${{ runner.os }}-${{ runner.arch }}-${{ 
hashFiles('.bazelversion') }}
-          restore-keys: |
-            bazel-binary-v2-${{ runner.os }}-${{ runner.arch }}-
-      - name: Install bazel (Unix)
-        if: runner.os != 'Windows'
-        shell: bash
-        run: python ./ci/run_ci.py cpp --install-deps-only
-      - name: Install bazel (Windows)
-        if: runner.os == 'Windows'
-        shell: bash
-        run: ./ci/run_ci.sh install_bazel_windows
+          bazelisk-cache: true
+          bazelisk-version: '1.x'
       - name: Clean Bazel cache (Windows)
         if: runner.os == 'Windows'
         shell: bash
@@ -810,18 +771,11 @@ jobs:
         with:
           python-version: 3.8
           cache: 'pip'
-      - name: Cache Bazel binary
-        uses: actions/cache@v4
+      - name: Set up Bazel
+        uses: bazel-contrib/[email protected]
         with:
-          path: |
-            ~/bin/bazel
-            ~/.local/bin/bazel
-          key: bazel-binary-v2-${{ runner.os }}-${{ runner.arch }}-${{ 
hashFiles('.bazelversion') }}
-          restore-keys: |
-            bazel-binary-v2-${{ runner.os }}-${{ runner.arch }}-
-          enableCrossOsArchive: false
-      - name: Install bazel
-        run: python ./ci/run_ci.py cpp --install-deps-only
+          bazelisk-cache: true
+          bazelisk-version: '1.x'
       - name: Install python dependencies
         run: pip install pyarrow cython wheel pytest setuptools -U
       - name: Install pyfory for xlang tests
diff --git a/MODULE.bazel b/MODULE.bazel
index f47b3719b..5a6712054 100644
--- a/MODULE.bazel
+++ b/MODULE.bazel
@@ -27,7 +27,7 @@ bazel_dep(name = "platforms", version = "0.0.11")
 bazel_dep(name = "bazel_skylib", version = "1.7.1")
 
 # Rules CC (C++ rules)
-bazel_dep(name = "rules_cc", version = "0.1.1")
+bazel_dep(name = "rules_cc", version = "0.2.17")
 
 # Rules Python - standard Python rules
 bazel_dep(name = "rules_python", version = "1.4.1")
diff --git a/ci/build_linux_wheels.py b/ci/build_linux_wheels.py
index 54fdc2ed3..9150d5a0e 100755
--- a/ci/build_linux_wheels.py
+++ b/ci/build_linux_wheels.py
@@ -33,6 +33,7 @@ from __future__ import annotations
 import argparse
 import os
 import shlex
+import shutil
 import subprocess
 import sys
 from typing import List
@@ -67,6 +68,11 @@ def parse_args():
     p.add_argument(
         "--python", required=True, help="Python version (e.g. cp38-cp38, 
cp313-cp313)"
     )
+    p.add_argument(
+        "--bazel-bin",
+        default="",
+        help="Path to host bazel executable to mount into the container",
+    )
     p.add_argument("--release", action="store_true", help="Run in release 
mode")
     p.add_argument(
         "--dry-run", action="store_true", help="Print docker command without 
running"
@@ -89,9 +95,14 @@ def get_image_for_arch(arch_normalized: str) -> str:
 
 
 def build_docker_cmd(
-    workspace: str, image: str, python_version: str, release: bool = False
+    workspace: str,
+    image: str,
+    python_version: str,
+    bazel_bin: str,
+    release: bool = False,
 ) -> List[str]:
     workspace = os.path.abspath(workspace)
+    bazel_bin = os.path.abspath(bazel_bin)
     github_ref_name = os.environ.get("GITHUB_REF_NAME", "")
 
     cmd = [
@@ -107,6 +118,8 @@ def build_docker_cmd(
         f"PYTHON_VERSIONS={python_version}",
         "-e",
         f"RELEASE_BUILD={'1' if release else '0'}",
+        "-v",
+        f"{bazel_bin}:/usr/local/bin/bazel:ro",
     ]
 
     if github_ref_name:
@@ -121,13 +134,25 @@ def main() -> int:
     arch = normalize_arch(args.arch)
     image = get_image_for_arch(arch)
     workspace = os.environ.get("GITHUB_WORKSPACE", os.getcwd())
+    bazel_bin = args.bazel_bin or shutil.which("bazel")
 
     script_path = os.path.join(workspace, CONTAINER_SCRIPT_PATH)
     if not os.path.exists(script_path):
         print(f"Container script not found at {script_path}", file=sys.stderr)
         return 2
+    if not bazel_bin:
+        print(
+            "Unable to locate bazel on host. Please provide --bazel-bin.",
+            file=sys.stderr,
+        )
+        return 2
+    if not os.path.exists(bazel_bin):
+        print(f"Host bazel binary does not exist: {bazel_bin}", 
file=sys.stderr)
+        return 2
 
-    docker_cmd = build_docker_cmd(workspace, image, args.python, 
release=args.release)
+    docker_cmd = build_docker_cmd(
+        workspace, image, args.python, bazel_bin, release=args.release
+    )
     printable = " ".join(shlex.quote(c) for c in docker_cmd)
     print(f"+ {printable}")
 
diff --git a/ci/run_ci.py b/ci/run_ci.py
index 38e426a4d..66af37f68 100644
--- a/ci/run_ci.py
+++ b/ci/run_ci.py
@@ -262,13 +262,10 @@ def parse_args():
             else:
                 run_shell_script(f"java{version}")
     elif command == "cpp":
-        if USE_PYTHON_CPP:
+        if USE_PYTHON_CPP or arg_dict.get("install_deps_only", False):
             func(arg_dict.get("install_deps_only", False))
         else:
-            if arg_dict.get("install_deps_only", False):
-                run_shell_script("install_bazel")
-            else:
-                run_shell_script("cpp")
+            run_shell_script("cpp")
     elif command == "rust":
         if USE_PYTHON_RUST:
             func()
diff --git a/ci/run_ci.sh b/ci/run_ci.sh
index 875df9b0a..d64cfab3e 100755
--- a/ci/run_ci.sh
+++ b/ci/run_ci.sh
@@ -60,93 +60,6 @@ install_pyfory() {
   popd
 }
 
-get_bazel_version() {
-    cat "$ROOT/.bazelversion"
-}
-
-install_bazel() {
-  REQUIRED_VERSION=$(get_bazel_version)
-
-  if command -v bazel >/dev/null; then
-    echo "existing bazel location $(which bazel)"
-    INSTALLED_VERSION=$(bazel --version 2>/dev/null | sed 's/bazel //')
-    echo "existing bazel version: $INSTALLED_VERSION, required: 
$REQUIRED_VERSION"
-    if [ "$INSTALLED_VERSION" = "$REQUIRED_VERSION" ]; then
-      echo "Bazel version matches, using cached binary"
-      return
-    else
-      echo "Bazel version mismatch, re-downloading..."
-      # Remove old bazel binary
-      rm -f "$(which bazel)" 2>/dev/null || true
-    fi
-  fi
-
-  ARCH="$(uname -m)"
-  OPERATING_SYSTEM="$(uname -s)"
-
-  # Normalize architecture names
-  case "${ARCH}" in
-    x86_64|amd64)  ARCH="x86_64" ;;
-    aarch64|arm64) ARCH="arm64" ;;
-    *)             echo "Unsupported architecture: $ARCH"; exit 1 ;;
-  esac
-
-  # Handle OS-specific logic. Windows handled elsewhere
-  case "${OPERATING_SYSTEM}" in
-    Linux*)     OS="linux" ;;
-    Darwin*)    OS="darwin" ;;
-    *)          echo "Unsupported OS: $OPERATING_SYSTEM"; exit 1 ;;
-  esac
-
-  BAZEL_DIR="$HOME/.local/bin"
-  mkdir -p "$BAZEL_DIR"
-
-  # Construct platform-specific URL (use REQUIRED_VERSION defined at function 
start)
-  
BINARY_URL="https://github.com/bazelbuild/bazel/releases/download/${REQUIRED_VERSION}/bazel-${REQUIRED_VERSION}-${OS}-${ARCH}";
-
-  echo "Downloading bazel from: $BINARY_URL"
-  # Retry download with exponential backoff to avoid transient network errors 
in CI
-  MAX_ATTEMPTS=5
-  SLEEP_SECONDS=2
-  attempt=1
-  while [ $attempt -le $MAX_ATTEMPTS ]; do
-    if curl -L -sSf -o "$BAZEL_DIR/bazel" "$BINARY_URL"; then
-      break
-    fi
-    echo "Attempt $attempt to download bazel failed."
-    if [ $attempt -eq $MAX_ATTEMPTS ]; then
-      echo "Failed to download bazel after $MAX_ATTEMPTS attempts"
-      exit 1
-    fi
-    sleep $SLEEP_SECONDS
-    SLEEP_SECONDS=$((SLEEP_SECONDS * 2))
-    attempt=$((attempt + 1))
-  done
-  chmod +x "$BAZEL_DIR/bazel"
-
-  # Add to current shell's PATH
-  export PATH="$BAZEL_DIR:$PATH"
-
-  # Verify installation
-  echo "Checking bazel installation..."
-  bazel version || { echo "Bazel installation verification failed"; exit 1; }
-
-  # Configure number of jobs based on memory
-  if [[ "$OS" == linux ]]; then
-    MEM=$(grep MemTotal < /proc/meminfo | awk '{print $2}')
-    JOBS=$(( MEM / 1024 / 1024 / 3 ))
-    echo "build --jobs=$JOBS" >> ~/.bazelrc
-    grep "jobs" ~/.bazelrc
-  fi
-}
-
-install_bazel_windows() {
-  BAZEL_VERSION=$(get_bazel_version)
-  choco install bazel --version="${BAZEL_VERSION}" --force
-  VERSION=$(bazel version)
-  echo "bazel version: $VERSION"
-}
-
 JDKS=(
 "zulu21.28.85-ca-jdk21.0.0-linux_x64"
 "zulu17.44.17-ca-crac-jdk17.0.8-linux_x64"
diff --git a/ci/tasks/common.py b/ci/tasks/common.py
index 40b5ac4cf..fd1bc80c4 100644
--- a/ci/tasks/common.py
+++ b/ci/tasks/common.py
@@ -17,10 +17,8 @@
 
 import subprocess
 import platform
-import urllib.request as ulib
 import os
 import logging
-import importlib
 
 # Constants
 PYARROW_VERSION = "15.0.0"
@@ -34,12 +32,6 @@ logging.basicConfig(
 )
 
 
-def get_bazel_version():
-    """Get the bazel version from the .bazelversion file."""
-    with open(os.path.join(PROJECT_ROOT_DIR, ".bazelversion")) as f:
-        return f.read().strip()
-
-
 def exec_cmd(cmd: str):
     """Execute a shell command and return its output."""
     logging.info(f"running command: {cmd}")
@@ -74,49 +66,6 @@ def get_os_machine():
     return machine
 
 
-def get_bazel_download_url():
-    """Construct the URL to download bazel."""
-    bazel_version = get_bazel_version()
-    download_url_base = (
-        
f"https://github.com/bazelbuild/bazel/releases/download/{bazel_version}";
-    )
-
-    # For Windows, use the .exe installer
-    if is_windows():
-        return f"{download_url_base}/bazel-{bazel_version}-windows-x86_64.exe"
-
-    # For Unix-like systems, use the binary directly (not the installer)
-    return 
f"{download_url_base}/bazel-{bazel_version}-{get_os_name_lower()}-{get_os_machine()}"
-
-
-def urlretrieve_with_retries(url, filename, max_attempts=5, initial_delay=2):
-    """Download a URL to filename with retries and exponential backoff.
-
-    Raises the last exception if all attempts fail.
-    """
-    attempt = 1
-    delay = initial_delay
-    last_exc = None
-    while attempt <= max_attempts:
-        try:
-            logging.info(f"Downloading (attempt {attempt}) {url} -> 
{filename}")
-            ulib.urlretrieve(url, filename)
-            return
-        except Exception as e:
-            logging.error(f"Download attempt {attempt} failed: {e}")
-            last_exc = e
-            if attempt == max_attempts:
-                break
-            logging.info(f"Retrying in {delay} seconds...")
-            import time
-
-            time.sleep(delay)
-            delay *= 2
-            attempt += 1
-    logging.error(f"All {max_attempts} download attempts failed for URL: 
{url}")
-    raise last_exc
-
-
 def cd_project_subdir(subdir):
     """Change to a subdirectory of the project."""
     os.chdir(os.path.join(PROJECT_ROOT_DIR, subdir))
@@ -128,119 +77,11 @@ def bazel(cmd: str):
     original_dir = os.getcwd()
     os.chdir(PROJECT_ROOT_DIR)
     try:
-        bazel_cmd = "bazel" if is_windows() else "~/bin/bazel"
-        return exec_cmd(f"{bazel_cmd} {cmd}")
+        return exec_cmd(f"bazel {cmd}")
     finally:
         os.chdir(original_dir)
 
 
-def update_shell_profile():
-    """Update shell profile to include bazel in PATH."""
-    home = os.path.expanduser("~")
-    profiles = [".bashrc", ".bash_profile", ".zshrc"]
-    path_export = 'export PATH="$PATH:$HOME/bin" # Add Bazel to PATH\n'
-    for profile in profiles:
-        profile_path = os.path.join(home, profile)
-        if os.path.exists(profile_path):
-            with open(profile_path, "a") as f:
-                f.write(path_export)
-            logging.info(f"Updated {profile} to include Bazel PATH.")
-            break
-    else:
-        logging.info("No shell profile found. Please add Bazel to PATH 
manually.")
-
-
-def install_bazel():
-    """Download and install bazel."""
-    required_version = get_bazel_version()
-
-    # Check if bazel is already cached (from GitHub Actions cache)
-    if not is_windows():
-        home_bin = os.path.expanduser("~/bin")
-        bazel_path = os.path.join(home_bin, "bazel")
-
-        # Also check ~/.local/bin for some systems
-        alt_bin = os.path.expanduser("~/.local/bin")
-        alt_bazel_path = os.path.join(alt_bin, "bazel")
-
-        for path in [bazel_path, alt_bazel_path]:
-            if os.path.exists(path) and os.access(path, os.X_OK):
-                logging.info(f"Bazel already exists at {path}, verifying...")
-                try:
-                    # Verify it works and has the correct version
-                    result = exec_cmd(f"{path} --version")
-                    installed_version = result.strip().replace("bazel ", "")
-                    if installed_version == required_version:
-                        logging.info(f"Cached Bazel binary is valid: 
{result.strip()}")
-                        logging.info("Skipping Bazel download, using cached 
binary")
-                        return
-                    else:
-                        logging.warning(
-                            f"Cached Bazel version {installed_version} does 
not match "
-                            f"required version {required_version}"
-                        )
-                        logging.info("Re-downloading Bazel with correct 
version...")
-                        try:
-                            os.remove(path)
-                        except Exception:
-                            pass
-                except Exception as e:
-                    logging.warning(f"Cached Bazel binary at {path} is 
invalid: {e}")
-                    logging.info("Re-downloading Bazel...")
-                    try:
-                        os.remove(path)
-                    except Exception:
-                        pass
-
-    bazel_download_url = get_bazel_download_url()
-    logging.info(f"Downloading bazel from: {bazel_download_url}")
-
-    if is_windows():
-        # For Windows, download the installer and add it to PATH
-        local_name = "bazel.exe"
-        try:
-            urlretrieve_with_retries(bazel_download_url, local_name)
-        except Exception as e:
-            logging.error(f"Failed to download bazel: {e}")
-            logging.error(f"URL: {bazel_download_url}")
-            logging.error(
-                f"OS: {get_os_name_lower()}, Machine: {get_os_machine()}, 
Original Machine: {platform.machine().lower()}"
-            )
-            raise
-        os.chmod(local_name, 0o777)
-        bazel_path = os.path.join(os.getcwd(), local_name)
-        exec_cmd(f'setx path "%PATH%;{bazel_path}"')
-    else:
-        # For Unix-like systems, download the binary directly to ~/bin/bazel
-        home_bin = os.path.expanduser("~/bin")
-        os.makedirs(home_bin, exist_ok=True)
-        bazel_path = os.path.join(home_bin, "bazel")
-
-        try:
-            urlretrieve_with_retries(bazel_download_url, bazel_path)
-        except Exception as e:
-            logging.error(f"Failed to download bazel: {e}")
-            logging.error(f"URL: {bazel_download_url}")
-            logging.error(
-                f"OS: {get_os_name_lower()}, Machine: {get_os_machine()}, 
Original Machine: {platform.machine().lower()}"
-            )
-            raise
-
-        os.chmod(bazel_path, 0o755)
-        update_shell_profile()
-
-    # bazel install status check
-    bazel("--version")
-
-    # default is byte
-    psutil = importlib.import_module("psutil")
-    total_mem = psutil.virtual_memory().total
-    limit_jobs = int(total_mem / 1024 / 1024 / 1024 / 3)
-    bazelrc_path = os.path.join(PROJECT_ROOT_DIR, ".bazelrc")
-    with open(bazelrc_path, "a") as file:
-        file.write(f"\nbuild --jobs={limit_jobs}")
-
-
 def install_cpp_deps():
     """Install dependencies for C++ development."""
     # Check the Python version and install the appropriate pyarrow version
@@ -252,4 +93,3 @@ def install_cpp_deps():
         exec_cmd(f"pip install pyarrow=={PYARROW_VERSION}")
         # Automatically install numpy
     exec_cmd("pip install psutil")
-    install_bazel()
diff --git a/ci/tasks/python_container_build_script.sh 
b/ci/tasks/python_container_build_script.sh
index 6ba1f7d80..46e4007ac 100644
--- a/ci/tasks/python_container_build_script.sh
+++ b/ci/tasks/python_container_build_script.sh
@@ -21,8 +21,11 @@ yum install -y git sudo wget || true
 
 git config --global --add safe.directory /work
 
-ci/run_ci.sh install_bazel
-export PATH="$HOME/.local/bin:$PATH"
+if ! command -v bazel >/dev/null 2>&1; then
+    echo "bazel is required in container PATH"
+    exit 1
+fi
+echo "Using bazel: $(bazel --version)"
 
 # Function to verify the installed version against expected version
 verify_version() {


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to