1313# See the License for the specific language governing permissions and
1414# limitations under the License.
1515set -o xtrace
16- cd /build_dir/llvm-project
17- rm -rf ./build
18- mkdir build
19-
20- capitalize () {
21- if [ -z " $1 " ]; then
22- return 1
23- fi
24-
25- local first_char rest
26- first_char=$( echo " ${1: 0: 1} " | tr ' [:lower:]' ' [:upper:]' )
27- rest=" ${1: 1} "
28- echo " ${first_char}${rest} "
29- }
16+ set -e
17+ cd build_dir/llvm-project
3018
3119CXX_FLAGS=" "
3220LDFLAGS=" "
3321ADDITIONAL_FLAGS=" "
3422if [ " $STDLIB " == " libcxx" ]; then
35- CXXFLAGS=" -stdlib=libc++ -std=c++23"
36- LDFLAGS=" -lc++"
23+ if [ " $ENABLE_SANITIZER " = " none" ]; then
24+ cmake -G Ninja -S runtimes -B build-libcxx -DLLVM_ENABLE_RUNTIMES=" libcxx;libcxxabi;libunwind" -DCMAKE_INSTALL_PREFIX=" /build_dir/libcxx" ;
25+ elif [ " $ENABLE_SANITIZER " = " asan" ]; then
26+ cmake -G Ninja -S runtimes -B build-libcxx -DLLVM_ENABLE_RUNTIMES=" libcxx;libcxxabi;libunwind" -DCMAKE_INSTALL_PREFIX=" /build_dir/libcxx" -DLLVM_USE_SANITIZER=" Address" ;
27+ elif [ " $ENABLE_SANITIZER " = " tsan" ]; then
28+ cmake -G Ninja -S runtimes -B build-libcxx -DLLVM_ENABLE_RUNTIMES=" libcxx;libcxxabi;libunwind" -DCMAKE_INSTALL_PREFIX=" /build_dir/libcxx" -DLLVM_USE_SANITIZER=" Thread" ;
29+ elif [ " $ENABLE_SANITIZER " = " ubsan" ]; then
30+ cmake -G Ninja -S runtimes -B build-libcxx -DLLVM_ENABLE_RUNTIMES=" libcxx;libcxxabi;libunwind" -DCMAKE_INSTALL_PREFIX=" /build_dir/libcxx" -DLLVM_USE_SANITIZER=" Undefined" ;
31+ else
32+ echo unexpected sanitizer: $SANITIZER ;
33+ exit 1
34+ fi
35+ ninja -C build-libcxx install-cxx install-cxxabi install-unwind
36+ CXXFLAGS=" -std=c++23 -nostdinc++ -isystem /build_dir/libcxx/include/c++/v1"
37+ LDFLAGS=" -L/build_dir/libcxx/lib -lc++ -rpath /build_dir/libcxx/lib"
3738elif [ " $STDLIB " == " libstdcxx" ]; then
3839 CXXFLAGS=" -std=c++23"
3940 LDFLAGS=" "
4243 exit 1
4344fi
4445
45- if [ ! " ${ENABLE_SANITIZER} " = " none" ]; then
46- ADDITIONAL_FLAGS=" ${ADDITIONAL_FLAGS} -DLLVM_USE_SANITIZER=$( capitalize ${ENABLE_SANITIZER} ) "
47- fi
48-
49- if [ " ${ENABLE_SANITIZER} " = " undefined" ]; then
50- ADDITIONAL_FLAGS=" ${ADDITIONAL_FLAGS} -DLLVM_ENABLE_RTTI=ON"
51- fi
52-
53- if [ " ${ENABLE_SANITIZER} " = " thread" ]; then
46+ if [ " $ENABLE_SANITIZER " = " none" ]; then
47+ echo " Not using a sanitizer"
48+ elif [ " $ENABLE_SANITIZER " = " asan" ]; then
49+ ADDITIONAL_FLAGS=" ${ADDITIONAL_FLAGS} -DLLVM_USE_SANITIZER=Address"
50+ elif [ " $ENABLE_SANITIZER " = " tsan" ]; then
51+ ADDITIONAL_FLAGS=" ${ADDITIONAL_FLAGS} -DLLVM_USE_SANITIZER=Thread"
5452 export TSAN_OPTIONS=" report_bugs=0"
53+ elif [ " $ENABLE_SANITIZER " = " ubsan" ]; then
54+ ADDITIONAL_FLAGS=" ${ADDITIONAL_FLAGS} -DLLVM_ENABLE_RTTI=ON"
55+ ADDITIONAL_FLAGS=" ${ADDITIONAL_FLAGS} -DLLVM_USE_SANITIZER=Undefined"
56+ else
57+ echo unexpected sanitizer: $SANITIZER ;
58+ exit 1
5559fi
5660
5761if [ ! -z " ${CXXFLAGS} " ]; then
@@ -62,6 +66,7 @@ if [ ! -z "${LDFLAGS}" ]; then
6266 export LDFLAGS
6367fi
6468
69+
6570cmake -G Ninja -S llvm -B build -DCMAKE_BUILD_TYPE=Release \
6671 -DLLVM_ENABLE_PROJECTS=" mlir" \
6772 -DLLVM_TARGETS_TO_BUILD=Native \
0 commit comments