blob: b569a7be9f9ab801f7c5c19cecfb080bc8cf6dfd [file] [log] [blame]
mtklein@google.com9f3b0e42013-10-08 15:16:36 +00001#!/bin/bash
2
3# Build Skia with one of Clang's many sanitizers.
4#
commit-bot@chromium.org7eb529f2014-04-24 18:16:13 +00005# $ tools/xsan_build {address,thread,undefined,etc.} [any other flags to pass to make...]
mtklein@google.com9f3b0e42013-10-08 15:16:36 +00006#
7# This script assumes the use of Clang >=3.2.
8#
9# For more information, see:
10# http://clang.llvm.org/docs/UsersManual.html#controlling-code-generation
11
12set -e
mtklein8ca88e42016-02-03 09:21:44 -080013set -x
mtklein@google.com9f3b0e42013-10-08 15:16:36 +000014
mtklein013475a2016-02-12 12:15:23 -080015here=$(cd `dirname $0`; echo `pwd`)
16cores=48
17
18echo "Bootstrapping CMake"
19pushd $here/../third_party/externals/cmake
20./bootstrap --parallel=$cores
21make -j $cores cmake
22popd
23
mtklein0da85372016-02-16 14:03:14 -080024cmake=$here/../third_party/externals/cmake/bin/cmake
25
mtklein013475a2016-02-12 12:15:23 -080026echo "Building Clang"
27pushd $here/../third_party/externals/llvm
28mkdir -p out/
29cd out/
mtklein0da85372016-02-16 14:03:14 -080030rm -f CMakeCache.txt # Force CMake to re-configure, in case DEPS has changed.
31$cmake -DCMAKE_BUILD_TYPE=Release -G Ninja ..
mtklein013475a2016-02-12 12:15:23 -080032ninja
33popd
34
35export CC=$here/../third_party/externals/llvm/out/bin/clang
36export CXX=$here/../third_party/externals/llvm/out/bin/clang++
commit-bot@chromium.org7eb529f2014-04-24 18:16:13 +000037$CC --version
mtklein@google.com9f3b0e42013-10-08 15:16:36 +000038
mtklein8ca88e42016-02-03 09:21:44 -080039if [[ "$1" == "memory" ]]; then
mtklein0da85372016-02-16 14:03:14 -080040 echo "Building libc++ with MSAN"
41 pushd $here/../third_party/externals/llvm
42 mkdir -p msan_out/
43 cd msan_out/
44 rm -f CMakeCache.txt # Force CMake to re-configure, in case DEPS has changed.
45 $cmake -DLLVM_USE_SANITIZER=MemoryWithOrigins -DCMAKE_BUILD_TYPE=Release -G Ninja ..
46 ninja cxx cxxabi # No need to build all of LLVM+Clang with MSAN, just libc++.
47 popd
48
49 msan_out=$here/../third_party/externals/llvm/msan_out
50
mtklein8ca88e42016-02-03 09:21:44 -080051 export GYP_DEFINES="skia_gpu=0 skia_no_fontconfig=1 skia_freetype_static=1 ${GYP_DEFINES}"
mtklein0da85372016-02-16 14:03:14 -080052 export CXXFLAGS="-stdlib=libc++ -I$msan_out/include ${CXX_FLAGS}"
53 export LDFLAGS="-stdlib=libc++ -L$msan_out/lib -Wl,-rpath,$msan_out/lib ${LDFLAGS}"
mtklein8ca88e42016-02-03 09:21:44 -080054fi
55export GYP_DEFINES="skia_sanitizer=$1 ${GYP_DEFINES}"
56
57shift
58make $@