Skip to content

darwin/arm64

darwin/arm64 #10

name: "darwin/arm64"
# This allows the workflow to be triggered manually from the
# GitHub UI (Actions tab > "Build XLA PJRT CPU Plugin" > Run workflow)
on:
workflow_dispatch:
permissions:
contents: write
jobs:
build:
name: "Build PJRT"
# We use macos-14, which is the GitHub-hosted runner for Apple Silicon (arm64)
runs-on: macos-latest
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
steps:
- uses: actions/checkout@v4
- name: "Clone and checkout XLA"
run: |
git clone https://github.com/openxla/xla xla
cd xla
# This is the command to checkout the specific hash from the file
XLA_HASH=$(cat ../XLA_COMMIT_HASH.txt)
echo "Checking out XLA at commit: $XLA_HASH"
git checkout $XLA_HASH
echo "XLA_HASH=$XLA_HASH" >> $GITHUB_ENV
- name: "Set up Python 3.11"
uses: actions/setup-python@v5
with:
python-version: "3.11"
# Optional: cache pip dependencies to speed up subsequent runs
cache: "pip"
cache-dependency-path: "xla/requirements_lock_3_11.txt"
- name: "Install Python dependencies"
run: |
pip install --upgrade pip
pip install six numpy
- name: "Install latest LLVM (Clang)"
run: |
brew install llvm
- name: "Setup Bazelisk (for Bazel)"
# This action installs and caches the correct Bazel version
# specified by the .bazelversion file in the XLA repo.
uses: bazelbuild/setup-bazelisk@v3
- run: |
# Extract version numbers
BUILDER_VERSION="$(cat BUILDER_VERSION.txt)"
PJRT_C_API_HEADER="./xla/xla/pjrt/c/pjrt_c_api.h"
MAJOR=$(grep -E '#define PJRT_API_MAJOR' "${PJRT_C_API_HEADER}" | awk '{print $3}')
MINOR=$(grep -E '#define PJRT_API_MINOR' "${PJRT_C_API_HEADER}" | awk '{print $3}')
echo "Building PJRT CPU plugin for version ${MAJOR}.${MINOR} (to be used in go-xla as v${MAJOR}.${MINOR}.${BUILDER_VERSION})"
echo "RELEASE_VERSION=v${MAJOR}.${MINOR}.${BUILDER_VERSION}" >> $GITHUB_ENV
- name: "Build PJRT C API CPU plugin"
run: |
# Point Bazel to the Homebrew-installed LLVM/Clang
# This is the standard path for Homebrew on Apple Silicon runners
export PATH="/opt/homebrew/opt/llvm/bin:$PATH"
export LDFLAGS="-L/opt/homebrew/opt/llvm/lib"
export CPPFLAGS="-I/opt/homebrew/opt/llvm/include"
export LLVM_PATH="/opt/homebrew/opt/llvm"
export PATH="$LLVM_PATH/bin:$PATH"
export CC="$LLVM_PATH/bin/clang"
export CXX="$LLVM_PATH/bin/clang++"
export HERMETIC_PYTHON_VERSION=3.11
cd xla
printf "\nConfiguring XLA build:\n"
./configure.py --backend CPU --os DARWIN --host_compiler CLANG --clang_path "$LLVM_PATH/bin/clang"
printf "\nStarting XLA bazel build:\n"
bazel build -c opt //xla/service/cpu:runtime_matmul
bazel build -c opt //xla/pjrt/c:pjrt_c_api_cpu_plugin.so
- name: "Package the binary"
run: |
# Create the tarball.
TARBALL_NAME="pjrt_cpu_darwin_arm64.tar.gz"
BINARY_DIR="xla/bazel-bin/xla/pjrt/c"
BINARY_NAME="pjrt_c_api_cpu_plugin.so"
NEW_BINARY_NAME="pjrt_c_api_cpu_${RELEASE_VERSION}_plugin.so"
# Create tarball
mv "${BINARY_DIR}/${BINARY_NAME}" "${NEW_BINARY_NAME}"
tar -czvf ${TARBALL_NAME} ${NEW_BINARY_NAME}
echo "Successfully created ${TARBALL_NAME} containing ${NEW_BINARY_NAME}"
echo "TARBALL_NAME=${TARBALL_NAME}" >> $GITHUB_ENV
- name: Upload release asset
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ env.RELEASE_VERSION }}
files: |
${{ env.TARBALL_NAME }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}