Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit be3d229

Browse files
committedNov 9, 2024·
Add LLVM as submodule (and add GHA build scripts)
1 parent cac2b21 commit be3d229

File tree

7 files changed

+469
-0
lines changed

7 files changed

+469
-0
lines changed
 
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
name: CI - manylinux x86_64 clang LLVM
2+
3+
on:
4+
workflow_call:
5+
workflow_dispatch:
6+
pull_request:
7+
merge_group:
8+
push:
9+
branches:
10+
- main
11+
12+
concurrency:
13+
# A PR number if a pull request and otherwise the commit hash. This cancels
14+
# queued and in-progress runs for the same PR (presubmit) or commit
15+
# (postsubmit). The workflow name is prepended to avoid conflicts between
16+
# different workflows.
17+
group: ${{ github.workflow }}-${{ github.event.number || github.sha }}
18+
cancel-in-progress: true
19+
20+
jobs:
21+
manylinux_x64_clang_llvm:
22+
name: Build LLVM and MLIR (linux)
23+
24+
runs-on: ubuntu-22.04
25+
26+
env:
27+
CACHE_DIR: ${{ github.workspace }}/.container-cache
28+
# either the PR number or `branch-N` where N always increments
29+
CACHE_KEY: manylinux_x64_clang_llvm_${{ format('{0}-{1}', github.ref_name, github.run_number) }}
30+
31+
container:
32+
image: quay.io/pypa/manylinux_2_28_x86_64
33+
34+
steps:
35+
36+
- name: "Set unified TZ"
37+
uses: szenius/set-timezone@v2.0
38+
with:
39+
# this is an arbitrary choice
40+
timezoneLinux: "Asia/Singapore"
41+
timezoneMacos: "Asia/Singapore"
42+
timezoneWindows: "Singapore Standard Time"
43+
44+
- name: Enable cache
45+
uses: actions/cache/restore@v3
46+
with:
47+
path: ${{ env.CACHE_DIR }}
48+
key: ${{ env.CACHE_KEY }}
49+
restore-keys: manylinux_x64_clang_llvm_
50+
51+
- name: "Check out repository"
52+
uses: actions/checkout@v4.2.2
53+
with:
54+
submodules: true
55+
56+
- name: "Install OS deps"
57+
run: |
58+
dnf install -y epel-release
59+
dnf install -y sudo ncurses-compat-libs tmate
60+
61+
- name: "Setup compiler/toolchain"
62+
uses: aminya/setup-cpp@v1
63+
with:
64+
compiler: llvm-18
65+
cmake: true
66+
ninja: true
67+
ccache: true
68+
69+
- name: "Setup ccache"
70+
run: |
71+
echo "CCACHE_DIR=${{ env.CACHE_DIR }}" >> $GITHUB_ENV
72+
echo "CCACHE_MAXSIZE=700M" >> $GITHUB_ENV
73+
echo "CCACHE_COMPILERCHECK=string:$(clang --version)" >> $GITHUB_ENV
74+
echo "CCACHE_SLOPPINESS=include_file_ctime,include_file_mtime,time_macros" >> $GITHUB_ENV
75+
76+
- name: "Setup Python"
77+
uses: actions/setup-python@v4
78+
with:
79+
python-version: '3.12'
80+
81+
- name: "Python deps"
82+
run: |
83+
pip install -r third_party/llvm-project/mlir/python/requirements.txt
84+
85+
- name: "Build LLVM and MLIR"
86+
run: |
87+
export LLVM_BUILD_DIR="$PWD/llvm-build"
88+
export LLVM_INSTALL_DIR="$PWD/llvm-install"
89+
build_tools/cmake/build_llvm.sh build_llvm
90+
build_tools/cmake/build_llvm.sh build_mlir
91+
92+
- name: "Tar dist"
93+
if: ${{ !cancelled() }}
94+
run: |
95+
pushd third_party/llvm-project && llvm_sha_short=$(git rev-parse --short HEAD) && popd
96+
tar cf llvm-dist-linux-$llvm_sha_short.tar llvm-install
97+
98+
- name: "Upload dist"
99+
uses: actions/upload-artifact@v4
100+
if: ${{ !cancelled() }}
101+
with:
102+
name: linux_x86_64_llvm_packages
103+
path: llvm-dist-*.tar
104+
if-no-files-found: error
105+
106+
- name: "Save cache"
107+
uses: actions/cache/save@v3
108+
# if: ${{ !cancelled() && github.event_name == 'push' && github.ref_name == 'main' }}
109+
if: ${{ !cancelled() }}
110+
with:
111+
path: ${{ env.CACHE_DIR }}
112+
key: ${{ env.CACHE_KEY }}
113+
114+
- name: Setup tmate session
115+
if: ${{ failure() }}
116+
uses: mxschmitt/action-tmate@v3.18
117+
with:
118+
limit-access-to-actor: true
119+
install-dependencies: false

‎.gitignore

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Prerequisites
2+
*.d
3+
4+
# Compiled Object files
5+
*.slo
6+
*.lo
7+
*.o
8+
*.obj
9+
10+
# Precompiled Headers
11+
*.gch
12+
*.pch
13+
14+
# Compiled Dynamic libraries
15+
*.so
16+
*.dylib
17+
*.dll
18+
19+
# Fortran module files
20+
*.mod
21+
*.smod
22+
23+
# Compiled Static libraries
24+
*.lai
25+
*.la
26+
*.a
27+
*.lib
28+
29+
# Executables
30+
*.exe
31+
*.out
32+
*.app
33+
34+
.idea

‎.gitmodules

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[submodule "third_party/llvm-project"]
2+
path = third_party/llvm-project
3+
url = https://github.com/llvm/llvm-project.git
4+
ignore = dirty
5+
shallow = true

‎build_tools/cmake/build_llvm.sh

+121
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
#!/usr/bin/env bash
2+
3+
TD="$(cd $(dirname $0) && pwd)"
4+
REPO_ROOT="$(cd $TD/../.. && pwd)"
5+
6+
LLVM_SOURCE_DIR="${LLVM_SOURCE_DIR:-${REPO_ROOT}/third_party/llvm-project}"
7+
LLVM_BUILD_DIR="${LLVM_BUILD_DIR:-${REPO_ROOT}/../llvm-build}"
8+
LLVM_INSTALL_DIR="${LLVM_INSTALL_DIR:-${REPO_ROOT}/../llvm-install}"
9+
10+
LLVM_SOURCE_DIR="$(realpath -m "${LLVM_SOURCE_DIR}")"
11+
LLVM_BUILD_DIR="$(realpath -m "${LLVM_BUILD_DIR}")"
12+
LLVM_INSTALL_DIR="$(realpath -m "${LLVM_INSTALL_DIR}")"
13+
14+
echo "Paths canonicalized as:"
15+
echo "LLVM_SOURCE_DIR=${LLVM_SOURCE_DIR}"
16+
echo "LLVM_BUILD_DIR=${LLVM_BUILD_DIR}"
17+
echo "LLVM_INSTALL_DIR=${LLVM_INSTALL_DIR}"
18+
19+
command="$1"
20+
shift
21+
22+
has_ccache=false
23+
if (command -v ccache &> /dev/null); then
24+
has_ccache=true
25+
fi
26+
27+
has_clang=false
28+
if (command -v clang &> /dev/null) && (command -v clang++ &> /dev/null); then
29+
has_clang=true
30+
fi
31+
32+
has_lld=false
33+
if (command -v lld &> /dev/null); then
34+
has_lld=true
35+
fi
36+
37+
python3_command=""
38+
if (command -v python3 &> /dev/null); then
39+
python3_command="python3"
40+
elif (command -v python &> /dev/null); then
41+
python3_command="python"
42+
fi
43+
44+
set -euo pipefail
45+
46+
print_toolchain_config() {
47+
if $has_ccache; then
48+
echo -n "-DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache "
49+
fi
50+
if $has_clang; then
51+
echo "-DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++"
52+
fi
53+
}
54+
55+
do_build_llvm() {
56+
echo "*********************** BUILDING LLVM *********************************"
57+
main_build_dir="${LLVM_BUILD_DIR}/llvm"
58+
main_install_dir="${LLVM_INSTALL_DIR}/llvm"
59+
targets_to_build="${LLVM_TARGETS_TO_BUILD:-X86}"
60+
61+
cmake_options="-DLLVM_TARGETS_TO_BUILD='${targets_to_build}'"
62+
cmake_options="${cmake_options} -DCMAKE_BUILD_TYPE=Release"
63+
cmake_options="${cmake_options} -C $TD/llvm_config.cmake"
64+
cmake_options="${cmake_options} -DCMAKE_INSTALL_PREFIX=${main_install_dir}"
65+
cmake_options="${cmake_options} $(print_toolchain_config)"
66+
if $has_lld; then
67+
cmake_options="${cmake_options} -DLLVM_ENABLE_LLD=ON"
68+
fi
69+
70+
echo "Source Directory: ${LLVM_SOURCE_DIR}"
71+
echo "Build Directory: ${main_build_dir}"
72+
echo "CMake Options: ${cmake_options}"
73+
cmake -GNinja -S "${LLVM_SOURCE_DIR}/llvm" -B "${main_build_dir}" \
74+
$cmake_options
75+
cmake --build "${main_build_dir}" \
76+
--target install-toolchain-distribution \
77+
--target install-development-distribution
78+
}
79+
80+
do_build_mlir() {
81+
echo "*********************** BUILDING MLIR *********************************"
82+
main_install_dir="${LLVM_INSTALL_DIR}/llvm"
83+
mlir_build_dir="${LLVM_BUILD_DIR}/mlir"
84+
mlir_install_dir="${LLVM_INSTALL_DIR}/mlir"
85+
86+
cmake_options="-DLLVM_DIR='${main_install_dir}/lib/cmake/llvm'"
87+
cmake_options="${cmake_options} -DPython3_EXECUTABLE='$(which $python3_command)'"
88+
# Note: Building the MLIR Python bindings requires the installation of
89+
# dependencies as specified in `mlir/python/requirements.txt`, which among
90+
# others include pybind11.
91+
cmake_options="${cmake_options} -DMLIR_ENABLE_BINDINGS_PYTHON=ON"
92+
cmake_options="${cmake_options} -DCMAKE_INSTALL_PREFIX=${mlir_install_dir}"
93+
cmake_options="${cmake_options} -C $TD/mlir_config.cmake"
94+
cmake_options="${cmake_options} $(print_toolchain_config)"
95+
if $has_lld; then
96+
cmake_options="${cmake_options} -DLLVM_ENABLE_LLD=ON"
97+
fi
98+
99+
echo "Source Directory: ${LLVM_SOURCE_DIR}"
100+
echo "Build Directory: ${mlir_build_dir}"
101+
echo "CMake Options: ${cmake_options}"
102+
cmake -GNinja -S "${LLVM_SOURCE_DIR}/mlir" -B "${mlir_build_dir}" \
103+
$cmake_options
104+
cmake --build "${mlir_build_dir}" \
105+
--target install-mlirdevelopment-distribution
106+
}
107+
108+
case "${command}" in
109+
build_llvm)
110+
do_build_llvm
111+
;;
112+
113+
build_mlir)
114+
do_build_mlir
115+
;;
116+
117+
*)
118+
echo "ERROR: Expected command of 'build_llvm', 'build_mlir' (got '${command}')"
119+
exit 1
120+
;;
121+
esac

0 commit comments

Comments
 (0)
Please sign in to comment.