-
Notifications
You must be signed in to change notification settings - Fork 0
197 lines (175 loc) · 6.67 KB
/
clang.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
192
193
194
195
196
197
on:
workflow_dispatch:
inputs:
clang_bootstrap_major_version:
description: "Major version of clang we'll use to build the clang toolchain."
type: number
required: true
clang_version:
description: "Version of clang we'll build."
type: string
required: true
runner:
description: "Type of runner to use/architecture to build for."
type: choice
options:
- toolchains-ubuntu-22.04-x86
- toolchains-ubuntu-22.04-arm
cpu_target:
description: "Type of CPU to optimize for. (-mcpu)"
type: string
required: false
arch_target:
description: "Type of micro architecture to optimize for. (-march)"
type: string
required: false
github_tag:
description: "Tag to upload the release to."
type: string
required: false
name: Linux Clang
jobs:
build_clang:
name: build clang ${{ inputs.runner }}
runs-on: ${{ inputs.runner }}
permissions:
contents: write
steps:
- name: Install required tools
run: sudo apt-get install -y zstd cmake gcc ninja-build
- name: Clone MaterializeInc/toolchains repo
uses: actions/checkout@v4
- name: Install bootstrap clang
run: sudo clang/llvm.sh ${{ inputs.clang_bootstrap_major_version }}
- name: Clone llvm-project at Version
uses: actions/checkout@v4
with:
repository: llvm/llvm-project
ref: 'llvmorg-${{ inputs.clang_version }}'
fetch-depth: 1 # llvm-project is quite large
path: llvm-project
- name: Get args
run: |
TARGET_CPU_ARG=""
if [ -n "${{ inputs.target_cpu }}" ]; then
TARGET_CPU_ARG="-mcpu=${{ inputs.target_cpu }}"
fi
echo "TARGET_CPU_ARG=$TARGET_CPU_ARG" >> $GITHUB_ENV
TARGET_ARCH_ARG=""
if [ -n "${{ inputs.target_arch }}" ]; then
TARGET_ARCH_ARG="-mcpu=${{ inputs.target_arch }}"
fi
echo "TARGET_ARCH_ARG=$TARGET_ARCH_ARG" >> $GITHUB_ENV
case ${{ inputs.runner }} in
toolchains-ubuntu-22.04-x86)
CLANG_ARCH=x86_64
;;
toolchains-ubuntu-22.04-arm)
CLANG_ARCH=aarch64
;;
*)
echo "Programming error, unknown runner"
exit 1
;;
esac
echo "CLANG_ARCH=$CLANG_ARCH" >> $GITHUB_ENV
echo "CLANG_TARGET=$CLANG_ARCH-unknown-linux-gnu" >> $GITHUB_ENV
CLANG_VERSION=${{ inputs.clang_version }}
CLANG_MAJOR_MINOR_VERSION=$(echo "$CLANG_VERSION" | cut -d. -f1-2)
echo "CLANG_VERSION=$CLANG_VERSION" >> $GITHUB_ENV
echo "CLANG_MAJOR_MINOR_VERSION=$CLANG_MAJOR_MINOR_VERSION" >> $GITHUB_ENV
C_BINARY="clang-${{ inputs.clang_bootstrap_major_version }}"
echo "C_BINARY=$C_BINARY" >> $GITHUB_ENV
CXX_BINARY="clang++-${{ inputs.clang_bootstrap_major_version }}"
echo "CXX_BINARY=$CXX_BINARY" >> $GITHUB_ENV
LLD_BINARY="lld-${{ inputs.clang_bootstrap_major_version }}"
echo "LLD_BINARY=$LLD_BINARY" >> $GITHUB_ENV
RELEASE_TAG="clang-${{ inputs.clang_version }}"
if [ -n "${{ inputs.github_tag }}" ]; then
RELEASE_TAG="${{ inputs.github_tag }}"
fi
echo "RELEASE_TAG=$RELEASE_TAG" >> $GITHUB_ENV
echo $GITHUB_ENV
- name: cmake configure
run: |
libs_dir="$CLANG_ARCH"-linux-gnu
echo $libs_dir
cd llvm-project
cmake -G Ninja -S llvm -B build \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_C_FLAGS="$TARGET_CPU_ARG $TARGET_ARCH_ARG -flto=thin -pthread -fPIC -O3 -DNDEBUG" \
-DCMAKE_CXX_FLAGS="$TARGET_CPU_ARG $TARGET_ARCH_ARG -flto=thin -pthread -fPIC -O3 -DNDEBUG" \
-DCMAKE_INTERPROCEDURAL_OPTIMIZATION="on" \
-DLLVM_ENABLE_PROJECTS="clang;lld" \
-DLLVM_ENABLE_RUNTIMES="libcxx;libcxxabi;libunwind;compiler-rt" \
-DLLVM_DISTRIBUTION_COMPONENTS="clang-resource-headers;libclang" \
-DCMAKE_C_COMPILER="$C_BINARY" \
-DCMAKE_CXX_COMPILER="$CXX_BINARY" \
-DCMAKE_CXX_STANDARD=17 \
-DLLVM_STATIC_LINK_CXX_STDLIB=ON \
-DLLVM_USE_LINKER="$LLD_BINARY" \
-DLLVM_ENABLE_LTO=Thin \
-DLLVM_ENABLE_PIC=ON \
-DLLVM_ENABLE_THREADS=ON \
-DLLVM_ENABLE_ZLIB=FORCE_ON \
-DBUILD_SHARED_LIBS=OFF \
-DLLVM_INCLUDE_UTILS=OFF \
-DLLVM_INCLUDE_TESTS=OFF \
-DLLVM_INCLUDE_EXAMPLES=OFF \
-DLLVM_INCLUDE_BENCHMARKS=OFF \
-DLLVM_INCLUDE_DOCS=OFF \
-DTerminfo_LIBRARIES=/usr/lib/$libs_dir/libtinfo.a \
-DZLIB_LIBRARY=/usr/lib/$libs_dir/libz.a
- name: build clang
run: |
cd llvm-project
CC="$C_BINARY" CXX="$CXX_BINARY" LD="$LLD_BINARY" cmake --build build --target \
clang \
lld \
llvm-ar \
llvm-as \
llvm-cov \
llvm-dwp \
llvm-libtool-darwin \
llvm-nm \
llvm-objcopy \
llvm-objdump \
llvm-profdata \
llvm-strip \
llvm-ranlib \
cxx \
cxxabi \
unwind \
builtins \
libclang
# Package the toolchain by copying everything listed from the following files:
#
# * bin.txt
# * include.txt
# * lib.txt
#
# Note: There is a header file `__config_site` that gets generated in a platform specific
# directory but to support cross compiling we move it into the normal `include` dir. This is
# bit hacky, but I've manually confirmed the file is the same for both architectures.
- name: package toolchain
run: |
mkdir package
mv llvm-project/build/include/$CLANG_TARGET/c++/v1/__config_site llvm-project/build/include/c++/v1/__config_site
for dir in bin include lib; do
mkdir package/$dir
cat clang/$dir.txt | while read -r val; do
val=${val#linux:}
if [[ $val != mac* && -n $val ]]; then
eval cp -rP llvm-project/build/$dir/$val package/$dir/
fi
done
done
cd package
tar -cf - * | zstd --ultra -22 -o "../linux_$CLANG_ARCH.tar.zst"
- name: Upload toolchain to release
uses: svenstaro/upload-release-action@v2
with:
file: "*.tar.zst"
file_glob: true
tag: ${{ env.RELEASE_TAG }}
overwrite: true