-
Notifications
You must be signed in to change notification settings - Fork 2
191 lines (164 loc) · 6.96 KB
/
build_llvm.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
name: "Build LLVM and MLIR"
on:
workflow_dispatch:
inputs:
force_debug_with_tmate:
type: boolean
description: 'Run the build with tmate session'
required: false
default: false
debug_with_tmate:
type: boolean
description: 'Run the build with a tmate session ONLY in case of failure'
required: false
default: false
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:
# either the PR number or `branch-N` where N always increments
CACHE_KEY: ${{ matrix.name }}_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: "Canonicalize workspace"
id: canonicalize-workspace
run: |
if [[ "${{ matrix.runs-on }}" == ubuntu* ]]; then
echo "workspace=$GITHUB_WORKSPACE" >> $GITHUB_OUTPUT
else
echo "workspace=${{ github.workspace }}" >> $GITHUB_OUTPUT
fi
- name: "Restore cache"
uses: actions/cache/restore@v3
with:
path: ${{ steps.canonicalize-workspace.outputs.workspace }}/.container-cache
key: ${{ env.CACHE_KEY }}
restore-keys: ${{ matrix.name }}_clang_llvm
- name: "Check out repository"
uses: actions/[email protected]
with:
submodules: true
- name: "Install OS deps"
run: |
if [[ "${{ matrix.runs-on }}" == ubuntu* ]]; then
dnf install -y epel-release
dnf install -y sudo ncurses-compat-libs tmate python3-pip
elif [[ "${{ matrix.runs-on }}" == macos* ]]; then
brew install ccache ninja
fi
- 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
vcvarsall: ${{ startsWith(matrix.runs-on, 'windows') }}
- name: "Set CC/CXX"
run: |
if [[ "${{ matrix.runs-on }}" == ubuntu* ]]; then
echo "CC=/github/home/llvm/bin/clang" >> $GITHUB_ENV
echo "CXX=/github/home/llvm/bin/clang++" >> $GITHUB_ENV
elif [[ "${{ matrix.runs-on }}" == windows* ]]; then
echo "CC=/C/Users/runneradmin/llvm/bin/clang-cl.exe" >> $GITHUB_ENV
echo "CXX=/C/Users/runneradmin/llvm/bin/clang-cl.exe" >> $GITHUB_ENV
elif [[ "${{ matrix.runs-on }}" == macos* ]]; then
echo "CC=/usr/bin/clang" >> $GITHUB_ENV
echo "CXX=/usr/bin/clang++" >> $GITHUB_ENV
fi
- 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
echo "Python3_EXECUTABLE=$(which $python3_command)" >> $GITHUB_ENV
- name: "Build LLVM and MLIR"
id: build
run: |
mkdir -p "${{ steps.canonicalize-workspace.outputs.workspace }}/.container-cache"
ccache --set-config=cache_dir="${{ steps.canonicalize-workspace.outputs.workspace }}/.container-cache"
ccache --set-config=max_size=700M
ccache --set-config=compiler_check="string:$($CC --version | head -n 1)"
ccache --set-config=sloppiness=include_file_ctime,include_file_mtime,time_macros
ccache --set-config=umask=002
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="$Python3_EXECUTABLE"
export LLVM_SOURCE_DIR="${{ steps.canonicalize-workspace.outputs.workspace }}/third_party/llvm-project"
export LLVM_BUILD_DIR="${{ steps.canonicalize-workspace.outputs.workspace }}/llvm-build"
export LLVM_INSTALL_DIR="${{ steps.canonicalize-workspace.outputs.workspace }}/llvm-install/llvm-install"
ccache -z
build_tools/cmake/build_llvm.sh
ccache -s
pushd $LLVM_SOURCE_DIR && echo "llvm_sha_short=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT && popd
rm -rf $LLVM_BUILD_DIR $LLVM_SOURCE_DIR
- name: "Upload dist"
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.name }}_llvm_${{ steps.build.outputs.llvm_sha_short }}
path: ${{ steps.canonicalize-workspace.outputs.workspace }}/llvm-install
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: ${{ steps.canonicalize-workspace.outputs.workspace }}/.container-cache
key: ${{ env.CACHE_KEY }}
- name: "Setup tmate session"
if: ${{ (failure() && inputs.debug_with_tmate) || inputs.force_debug_with_tmate }}
uses: mxschmitt/[email protected]
with:
limit-access-to-actor: true
install-dependencies: ${{ startsWith(matrix.runs-on, 'macos') || startsWith(matrix.runs-on, 'windows') }}