-
Notifications
You must be signed in to change notification settings - Fork 1
/
build_git.sh
executable file
·217 lines (157 loc) · 5.98 KB
/
build_git.sh
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
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
#!/bin/bash
#set -x
# This script bootstraps llvm, clang and friends in optimized way
# requires gold linker (for lto) http://llvm.org/docs/GoldPlugin.html
# and ninja https://ninja-build.org/
procs=6 #number of jobs to run at a time
export CCACHE_DISABLE=1 #disable ccache
rootDir=`pwd` #cwd
echo "Latest builds of buildslave http://lab.llvm.org:8011/builders/clang-with-lto-ubuntu"
python3 ~/llvm_bootstrap/BB_status.py
mkdir -p stage_1
cd stage_1
# exclude llgo
all_projects="clang;clang-tools-extra;compiler-rt;debuginfo-tests;libc;libclc;libcxx;libcxxabi;libunwind;lld;lldb;openmp;parallel-libs;polly;pstl"
export stageBase=`pwd`
# build dir
export LLVMBuild=${stageBase}/build
#compilers to use for stage 1
export CXX=clang++
export CC=clang
echo -e "\e[95mCloning/updating repo...\e[39m"
repoSrcStr="llvm-project"
if ! test -d ${repoSrcStr}; then
git clone https://github.com/llvm/llvm-project ${repoSrcStr}
else
cd ${repoSrcStr}
git pull
fi
# start building
mkdir -p ${LLVMBuild}
cd ${LLVMBuild}
cmake ../${repoSrcStr}/llvm -G "Ninja" \
-DCMAKE_BUILD_TYPE=Release \
-DLLVM_BINUTILS_INCDIR=/usr/include \
-DCMAKE_C_FLAGS="-march=native -O3 -g0 -DNDEBUG -DNLLVM_DEBUG" \
-DCMAKE_CXX_FLAGS="-march=native -O3 -g0 -DNDEBUG -DNLLVM_DEBUG" \
-DLLVM_PARALLEL_LINK_JOBS=1 \
-DLLVM_TARGETS_TO_BUILD="X86" \
-DLLVM_OPTIMIZED_TABLEGEN=1 \
-DLLVM_BUILD_TOOLS=0 \
-DLLVM_ENABLE_PROJECTS="llvm;clang;lld" \
-DLLVM_LIT_ARGS="--timeout 300 -sv"
echo -e "\e[95mbuilding stage 1\e[39m"
nice -n 15 ninja -l $procs -j $procs clang LLVMgold llvm-ar llvm-ranlib lld || exit
echo -e "\e[95mrunning stage 1 tests\e[39m"
nice -n 15 ninja -l $procs -j $procs check-llvm check-clang check-lld || exit
echo -e "\e[95mstage 1 done\e[39m"
# clang compiled with system clang is done
# now, compile clang again with the newly built version
cd ${rootDir}
export cloneRoot=${rootDir}/stage_1/${repoSrcStr}
mkdir -p stage_2
cd stage_2
export stageBase=`pwd`
export LLVMObjects=${stageBase}/objects # build in here
export LLVMBuild=${stageBase}/build # make install into here
export LLVMTest=${stageBase}/test # compile and exec tests here
# we can simply clone from local to local repo, no need to pull everything from the net again
if ! test -d ${repoSrcStr}; then
git clone ${cloneRoot} ${repoSrcStr}
else
cd ${repoSrcStr}
git pull
fi
# use new clang++
export CXX="${rootDir}/stage_1/build/bin/clang++"
export CC="${rootDir}/stage_1/build/bin/clang"
mkdir -p ${LLVMObjects}
cd ${LLVMObjects}
cmake ../${repoSrcStr}/llvm -G "Ninja" \
-DCMAKE_BUILD_TYPE=Release \
-DLLVM_BINUTILS_INCDIR=/usr/include \
-DCMAKE_C_FLAGS="-march=native -O3 -g0 -DNDEBUG -DNLLVM_DEBUG" \
-DCMAKE_CXX_FLAGS="-march=native -O3 -g0 -DNDEBUG -DNLLVM_DEBUG" \
-DLLVM_PARALLEL_LINK_JOBS=1 \
-DLLVM_OPTIMIZED_TABLEGEN=1 \
-DLLVM_TARGETS_TO_BUILD="X86" \
-DLLVM_ENABLE_LTO="Thin" \
-DCMAKE_AR="${rootDir}/stage_1/build/bin/llvm-ar" \
-DCMAKE_RANLIB="${rootDir}/stage_1/build/bin/llvm-ranlib" \
-DLLVM_USE_LINKER="${rootDir}/stage_1/build/bin/ld.lld" \
-DCMAKE_INSTALL_PREFIX="${stageBase}/build/" \
-DLLVM_LIBDIR_SUFFIX="" \
-DLLVM_ENABLE_PROJECTS=${all_projects} \
-DLLVM_TOOL_LLGO_BUILD=0 \
-DCMAKE_EXE_LINKER_FLAGS="-Wl,-thinlto-jobs=4 -Wl,-thinlto-cache-policy,cache_size_bytes=6g -Wl,-thinlto-cache-dir='${stageBase}/objects/thinlto_cache'"
export stage2_install_dir=${LLVMBuild}
echo -e "\e[95mBuilding stage 2\e[39m"
nice -n 15 ninja -l $procs -j $procs all || exit
echo -e "\e[95mCompiling done.\e[39m"
echo -e "\e[95mInstalling...\e[39m"
rm -rf ${LLVMBuild}
nice -n 15 ninja -l $procs -j $procs install || exit
echo -e "\e[95mInstalling done.\e[39m"
# building this will take ages with lto, also take care having automatic core dumps disabled before running
# to do this, find your /etc/systemd/coredump.conf
# and add
#
# [Coredump]
# Storage=none
#
# see https://wiki.archlinux.org/index.php/Core_dump for more details
# stage 2 is done.
# we can run tests now (stage 3)
# stage 3 has additional debug options and verification enabled
cd ${rootDir}
export cloneRoot=${rootDir}/stage_2/${repoSrcStr}
mkdir -p stage_3_tests
cd stage_3_tests
export stageBase=`pwd`
export LLVMSrc=${stageBase}/${repoSrcStr}
export LLVMObjects=${stageBase}/objects # build in here
echo -e "\e[95mllvm\e[39m"
if ! test -d ${LLVMSrc}; then
git clone ${cloneRoot} ${repoSrcStr}
else
cd ${LLVMSrc}
git pull
fi
export LLVMTestSuite=${LLVMSrc}/test-suite
echo -e "\e[95mllvm tests-suite\e[39m"
if ! test -d ${LLVMTestSuite}; then
git clone https://github.com/llvm/llvm-test-suite/ ${LLVMTestSuite}
else
cd ${LLVMTestSuite}
git pull
fi
# use optimized stage 2 clang++
export CXX="${rootDir}/stage_2/build/bin/clang++"
export CC="${rootDir}/stage_2/build/bin/clang"
mkdir -p ${LLVMObjects}
cd ${LLVMObjects}
echo -e "\e[95mConfiguring tests\e[39m"
cmake ../${repoSrcStr}/llvm -G "Ninja" \
-DCMAKE_BUILD_TYPE=Release \
-DLLVM_BINUTILS_INCDIR=/usr/include \
-DCMAKE_C_FLAGS="-O3 -D_GLIBCXX_DEBUG -g0" \
-DCMAKE_CXX_FLAGS="-O3 -D_GLIBCXX_DEBUG -g0" \
-DLLVM_PARALLEL_LINK_JOBS=1 \
-DLLVM_OPTIMIZED_TABLEGEN=1 \
-DLLVM_ENABLE_LTO="Thin" \
-DCMAKE_AR="${rootDir}/stage_2/build/bin/llvm-ar" \
-DCMAKE_RANLIB="${rootDir}/stage_2/build/bin/llvm-ranlib" \
-DLLVM_USE_LINKER="${rootDir}/stage_2/build/bin/ld.lld" \
-DLLVM_ENABLE_EXPENSIVE_CHECKS=1 \
-DLLDB_TEST_C_COMPILER="${rootDir}/stage_3_tests/objects/bin/clang" \
-DLLDB_TEST_CXX_COMPILER="${rootDir}/stage_3_tests/objects/bin/clang++" \
-DLLVM_ENABLE_ASSERTIONS=1 \
-DLLVM_ENABLE_PROJECTS=${all_projects} \
-DLLVM_TOOL_LLGO_BUILD=0 \
-DLLVM_LIT_ARGS="--timeout 300 -sv" \
-DCMAKE_EXE_LINKER_FLAGS="-Wl,-thinlto-jobs=4 -Wl,-thinlto-cache-policy,cache_size_bytes=6g -Wl,-thinlto-cache-dir='${stageBase}/objects/thinlto_cache'"
echo -e "\e[95mBuilding and running stage 3 tests.\e[39m"
# build and run tests now
# export ASAN_OPTIONS=detect_odr_violation=0
nice -n 15 ninja -l $procs -j $procs check-all || exit
echo -e "\e[95mstage 3 testing done, tests passed\e[39m"