[CI] Add build and cache llvm build dir. #2086
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: test build process | |
on: | |
push: | |
branches: [ main, ci ] | |
pull_request: | |
branches: [ main, ci ] | |
jobs: | |
build: | |
runs-on: self-hosted | |
steps: | |
# 0. Install Ninja build system. | |
- name: Set up ninja | |
uses: seanmiddleditch/gha-setup-ninja@master | |
# 1. Checkout main repository, but do not fetch submodules immediately | |
- name: Checkout main repository | |
uses: actions/checkout@v4 | |
with: | |
submodules: 'false' | |
# 2. Get llvm submodule commit id | |
- name: Get LLVM submodule commit | |
id: llvm-submodule-commit | |
run: | | |
echo "commit=$(git submodule status llvm | awk '{print $1;}')" >> $GITHUB_OUTPUT | |
# 3. Cache llvm submodule source code | |
- name: Cache LLVM source | |
id: cache-llvm-source | |
uses: actions/cache@v4 | |
with: | |
path: llvm | |
key: llvm-source-${{ steps.llvm-submodule-commit.outputs.commit }} | |
restore-keys: | | |
llvm-source- | |
# 4. If cache miss,then pull LLVM submodule | |
- name: Checkout LLVM submodule | |
run: git submodule update --init --recursive llvm | |
if: steps.cache-llvm-source.outputs.cache-hit != 'true' | |
# 5. Cache llvm build directory | |
- name: Cache LLVM build directory | |
id: cache-llvm-build-dir | |
uses: actions/cache@v4 | |
with: | |
path: llvm/build | |
key: llvm-build-${{ steps.llvm-submodule-commit.outputs.commit }} | |
restore-keys: | | |
llvm-build- | |
# 6. If cache miss,then build LLVM | |
- name: Configure and Build LLVM | |
run: | | |
cd llvm | |
mkdir build | |
cd build | |
cmake -G Ninja ../llvm \ | |
-DLLVM_ENABLE_PROJECTS="mlir;clang;openmp" \ | |
-DLLVM_TARGETS_TO_BUILD="host;RISCV" \ | |
-DLLVM_ENABLE_ASSERTIONS=ON \ | |
-DCMAKE_BUILD_TYPE=RELEASE \ | |
-DMLIR_ENABLE_BINDINGS_PYTHON=ON \ | |
-DPython3_EXECUTABLE=$(which python3) | |
ninja check-clang check-mlir omp | |
if: steps.cache-llvm-build-dir.outputs.cache-hit != 'true' | |
# # 6. Cache LLVM build directory | |
# - name: Cache LLVM build directory | |
# uses: actions/cache@v4 | |
# with: | |
# path: llvm-build | |
# key: build-${{ steps.llvm-submodule-commit.outputs.commit }} | |
# restore-keys: | | |
# build- | |
# # Install Python 3.10 | |
# - name: Set up Python 3.10 | |
# uses: actions/setup-python@v4 | |
# with: | |
# python-version: '3.10' | |
# # Define cache key based on requirements.txt checksum | |
# - name: Cache Python virtual environment | |
# id: cache-pyenv | |
# uses: actions/cache@v4 | |
# with: | |
# path: buddy-mlir-venv-${{ hashFiles('requirements.txt') }} | |
# key: pyenv-${{ runner.os }}-${{ hashFiles('requirements.txt') }} | |
# # Create virtual environment if needed and install dependencies | |
# - name: Set up virtual environment | |
# run: | | |
# venv_path="buddy-mlir-venv-${{ hashFiles('requirements.txt') }}" | |
# if [ ! -d "$venv_path" ]; then | |
# python -m venv $venv_path | |
# source $venv_path/bin/activate | |
# pip install --upgrade pip | |
# pip install -r requirements.txt | |
# fi | |
# shell: bash | |
# # Activate virtual environment and verify installation | |
# - name: Activate virtual environment and verify installation | |
# run: | | |
# source buddy-mlir-venv-${{ hashFiles('requirements.txt') }}/bin/activate | |
# python --version | |
# pip list | |
# shell: bash | |
# # Use GitHub Actions caching to save the build directory for later use. | |
# # If the submodule's commit hash changes, a new cache will be created; | |
# # otherwise, the previous cache will be used to speed up builds. | |
# - name: Cache llvm build directory | |
# uses: actions/cache@v4 | |
# with: | |
# path: llvm | |
# key: build-${{ steps.llvm-build-dir.outputs.commit }} | |
# # Run a shell script 'TestBuild.sh' to test the build process. | |
# # The script is run with the path to the build directory that includes the commit ID, | |
# # ensuring the correct build version is tested. | |
# # This step executes the actual build verification after caching is set up. | |
# - name: Test build | |
# run: | | |
# source ~/miniconda3/bin/activate buddy | |
# bash ./tests/Actions/TestBuild.sh llvm/build-${{ steps.llvm-build-dir.outputs.commit }} | |
# shell: bash |