Add macos and windows builds #10
Workflow file for this run
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: "Build LLVM and MLIR" | |
on: | |
workflow_dispatch: | |
pull_request: | |
paths: | |
- ".github/workflows/build_llvm.yml" | |
- "third_party/llvm-project" | |
concurrency: | |
# A PR number if a pull request and otherwise the commit hash. This cancels | |
# queued and in-progress runs for the same PR (presubmit) or commit | |
# (postsubmit). The workflow name is prepended to avoid conflicts between | |
# different workflows. | |
group: ${{ github.workflow }}-${{ github.event.number || github.sha }} | |
cancel-in-progress: true | |
jobs: | |
build: | |
strategy: | |
fail-fast: false | |
matrix: | |
include: | |
- name: "manylinux_x86_64" | |
runs-on: "ubuntu-22.04" | |
container: "quay.io/pypa/manylinux_2_28_x86_64" | |
- name: "windows_x86_64" | |
runs-on: "windows-2019" | |
- name: "macos_arm64" | |
runs-on: "macos-latest" | |
# - name: "macos_x86_64" | |
# os: "macos-13" | |
runs-on: ${{ matrix.runs-on }} | |
name: ${{ matrix.name }} | |
defaults: | |
run: | |
shell: bash | |
env: | |
CACHE_DIR: /.container-cache | |
# either the PR number or `branch-N` where N always increments | |
CACHE_KEY: ${{ matrix.name }}_x64_clang_llvm_${{ format('{0}-{1}', github.ref_name, github.run_number) }} | |
container: | |
image: ${{ matrix.container }} | |
steps: | |
- name: "Set unified TZ" | |
uses: szenius/[email protected] | |
with: | |
# this is an arbitrary choice | |
timezoneLinux: "Asia/Singapore" | |
timezoneMacos: "Asia/Singapore" | |
timezoneWindows: "Singapore Standard Time" | |
- name: Restore cache | |
uses: actions/cache/restore@v3 | |
with: | |
path: ${{ env.CACHE_DIR }} | |
key: ${{ env.CACHE_KEY }} | |
restore-keys: ${{ matrix.name }}_x64_clang_llvm | |
- name: "Check out repository" | |
uses: actions/[email protected] | |
with: | |
submodules: true | |
- name: "Install OS deps" | |
if: ${{ matrix.name == 'manylinux_x86_64' }} | |
run: | | |
dnf install -y epel-release | |
dnf install -y sudo ncurses-compat-libs tmate python3-pip | |
- name: "Install OS deps" | |
if: ${{ startsWith(matrix.runs-on, 'macos') }} | |
run: | | |
brew install ccache ninja | |
- name: "Install Python" | |
uses: actions/setup-python@v4 | |
if: ${{ startsWith(matrix.runs-on, 'macos') || startsWith(matrix.runs-on, 'windows') }} | |
with: | |
python-version: '3.12' | |
- name: "Setup compiler/toolchain" | |
uses: aminya/setup-cpp@v1 | |
if: ${{ startsWith(matrix.runs-on, 'ubuntu') || startsWith(matrix.runs-on, 'windows') }} | |
with: | |
compiler: llvm-18 | |
cmake: true | |
ninja: true | |
ccache: true | |
- name: "Fix CC/CXX on Windows" | |
if: ${{ startsWith(matrix.runs-on, 'windows') }} | |
run: | | |
echo "CC=/C/Users/runneradmin/llvm/bin/clang-cl.exe" >> $GITHUB_ENV | |
echo "CXX=/C/Users/runneradmin/llvm/bin/clang-cl.exe" >> $GITHUB_ENV | |
- name: "Python deps" | |
run: | | |
python3_command="" | |
if (command -v python3.12 &> /dev/null); then | |
python3_command="python3.12" | |
elif (command -v python3 &> /dev/null); then | |
python3_command="python3" | |
elif (command -v python &> /dev/null); then | |
python3_command="python" | |
fi | |
$python3_command -m pip install -r third_party/llvm-project/mlir/python/requirements.txt | |
- name: "Build LLVM and MLIR" | |
run: | | |
export CCACHE_DIR="${{ env.CACHE_DIR }}" | |
export CCACHE_MAXSIZE=700M | |
export CCACHE_COMPILERCHECK="string:$(clang --version)" | |
export CCACHE_SLOPPINESS=include_file_ctime,include_file_mtime,time_macros | |
export CMAKE_C_COMPILER_LAUNCHER=ccache | |
export CMAKE_CXX_COMPILER_LAUNCHER=ccache | |
export CMAKE_EXE_LINKER_FLAGS_INIT="-fuse-ld=lld" | |
export CMAKE_SHARED_LINKER_FLAGS_INIT="-fuse-ld=lld" | |
export CMAKE_MODULE_LINKER_FLAGS_INIT="-fuse-ld=lld" | |
export Python3_EXECUTABLE="$(which python3.12)" | |
export LLVM_SOURCE_DIR="$PWD/third_party/llvm-project" | |
export LLVM_BUILD_DIR="$PWD/llvm-build" | |
export LLVM_INSTALL_DIR="$PWD/llvm-install" | |
pushd $LLVM_SOURCE_DIR && llvm_sha_short=$(git rev-parse --short HEAD) && popd | |
build_tools/cmake/build_llvm.sh | |
rm -rf $LLVM_BUILD_DIR $LLVM_SOURCE_DIR | |
tar cf llvm-dist-linux-$llvm_sha_short.tar $LLVM_INSTALL_DIR | |
rm -rf $LLVM_INSTALL_DIR | |
- name: "Upload dist" | |
uses: actions/upload-artifact@v4 | |
with: | |
name: linux_x86_64_llvm_packages | |
path: llvm-dist-*.tar | |
if-no-files-found: error | |
- name: "Save cache" | |
uses: actions/cache/save@v3 | |
# if: ${{ !cancelled() && github.event_name == 'push' && github.ref_name == 'main' }} | |
if: ${{ !cancelled() }} | |
with: | |
path: ${{ env.CACHE_DIR }} | |
key: ${{ env.CACHE_KEY }} | |
- name: Setup tmate session | |
if: ${{ failure() }} | |
uses: mxschmitt/[email protected] | |
with: | |
limit-access-to-actor: true | |
install-dependencies: ${{ startsWith(matrix.runs-on, 'macos') || startsWith(matrix.runs-on, 'windows') }} |