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
16+ set -e
17+ cd build_dir/llvm-project
1918
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- }
19+ apt install -y libclang-19-dev
3020
3121CXX_FLAGS=" "
3222LDFLAGS=" "
3323ADDITIONAL_FLAGS=" "
3424if [ " $STDLIB " == " libcxx" ]; then
35- CXXFLAGS=" -stdlib=libc++ -std=c++23"
36- LDFLAGS=" -lc++"
25+ if [ " $ENABLE_SANITIZER " = " none" ]; then
26+ cmake -G Ninja -S runtimes -B build-libcxx -DLLVM_ENABLE_RUNTIMES=" libcxx;libcxxabi;libunwind" -DCMAKE_INSTALL_PREFIX=" /build_dir/libcxx"
27+ CXXFLAGS=" -std=c++23 -nostdinc++ -isystem /build_dir/libcxx/include/c++/v1"
28+ LDFLAGS=" -L/build_dir/libcxx/lib -lc++ -rpath /build_dir/libcxx/lib"
29+ elif [ " $ENABLE_SANITIZER " = " asan" ]; 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=" Address"
31+ CXXFLAGS=" -std=c++23 -nostdinc++ -isystem /build_dir/libcxx/include/c++/v1 -fsanitize=address"
32+ LDFLAGS=" -L/build_dir/libcxx/lib -lc++ -rpath /build_dir/libcxx/lib -fsanitize=address"
33+ elif [ " $ENABLE_SANITIZER " = " tsan" ]; then
34+ cmake -G Ninja -S runtimes -B build-libcxx -DLLVM_ENABLE_RUNTIMES=" libcxx;libcxxabi;libunwind" -DCMAKE_INSTALL_PREFIX=" /build_dir/libcxx" -DLLVM_USE_SANITIZER=" Thread"
35+ CXXFLAGS=" -std=c++23 -nostdinc++ -isystem /build_dir/libcxx/include/c++/v1 -fsanitize=thread"
36+ LDFLAGS=" -L/build_dir/libcxx/lib -lc++ -rpath /build_dir/libcxx/lib -fsanitize=thread"
37+ elif [ " $ENABLE_SANITIZER " = " ubsan" ]; then
38+ cmake -G Ninja -S runtimes -B build-libcxx -DLLVM_ENABLE_RUNTIMES=" libcxx;libcxxabi;libunwind" -DCMAKE_INSTALL_PREFIX=" /build_dir/libcxx" -DLLVM_USE_SANITIZER=" Undefined"
39+ CXXFLAGS=" -std=c++23 -nostdinc++ -isystem /build_dir/libcxx/include/c++/v1 -fsanitize=undefined"
40+ LDFLAGS=" -L/build_dir/libcxx/lib -lc++ -rpath /build_dir/libcxx/lib -fsanitize=undefined"
41+ else
42+ echo unexpected sanitizer: $SANITIZER ;
43+ exit 1
44+ fi
45+ ninja -C build-libcxx install-cxx install-cxxabi install-unwind
3746elif [ " $STDLIB " == " libstdcxx" ]; then
3847 CXXFLAGS=" -std=c++23"
3948 LDFLAGS=" "
4251 exit 1
4352fi
4453
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
54+ if [ " $ENABLE_SANITIZER " = " none" ]; then
55+ echo " Not using a sanitizer"
56+ elif [ " $ENABLE_SANITIZER " = " asan" ]; then
57+ ADDITIONAL_FLAGS=" ${ADDITIONAL_FLAGS} -DLLVM_USE_SANITIZER=Address"
58+ elif [ " $ENABLE_SANITIZER " = " tsan" ]; then
59+ ADDITIONAL_FLAGS=" ${ADDITIONAL_FLAGS} -DLLVM_USE_SANITIZER=Thread"
5460 export TSAN_OPTIONS=" report_bugs=0"
61+ elif [ " $ENABLE_SANITIZER " = " ubsan" ]; then
62+ ADDITIONAL_FLAGS=" ${ADDITIONAL_FLAGS} -DLLVM_ENABLE_RTTI=ON"
63+ ADDITIONAL_FLAGS=" ${ADDITIONAL_FLAGS} -DLLVM_USE_SANITIZER=Undefined"
64+ else
65+ echo unexpected sanitizer: $SANITIZER ;
66+ exit 1
5567fi
5668
5769if [ ! -z " ${CXXFLAGS} " ]; then
@@ -62,6 +74,7 @@ if [ ! -z "${LDFLAGS}" ]; then
6274 export LDFLAGS
6375fi
6476
77+
6578cmake -G Ninja -S llvm -B build -DCMAKE_BUILD_TYPE=Release \
6679 -DLLVM_ENABLE_PROJECTS=" mlir" \
6780 -DLLVM_TARGETS_TO_BUILD=Native \
0 commit comments