1# This is based off the official LLVM docker container 2# https://github.com/llvm/llvm-project/blob/76fd4bf675b5ceeeca0e4e15cf15d89c7acf4947/llvm/utils/docker/debian10/Dockerfile 3# 4# This was launcher.gcr.io/google/debian10:latest on Sep 22 2022 5# Found by running 6# docker pull launcher.gcr.io/google/debian10:latest && docker images --digests | grep debian10 7FROM launcher.gcr.io/google/debian10@sha256:3242ff21417c7722482c2085f86f28ed4f76cde00bf880f15fc1795975bc2a81 8 9# Install build dependencies of llvm. 10# First, Update the apt's source list and include the sources of the packages. 11RUN grep deb /etc/apt/sources.list | \ 12 sed 's/^deb/deb-src /g' >> /etc/apt/sources.list 13# Install compiler, python, etc. We need clang and lld because otherwise we have issues compiling 14# compiler-rt (it fails using the built-in ld). 15# 16# The versions were added after seeing what was available when this image was created on Sep 22 2022 17# Specifying the versions makes this Docker container comply with SLSA level 1. 18RUN apt-get update && \ 19 apt-get install -y --no-install-recommends \ 20 ca-certificates=20200601~deb10u2 gnupg=2.2.12-1+deb10u2 \ 21 build-essential=12.6 cmake=3.13.4-1 make=4.2.1-1.2 python3=3.7.3-1 \ 22 zlib1g=1:1.2.11.dfsg-1+deb10u2 wget=1.20.1-1.1 unzip=6.0-23+deb10u3 \ 23 git=1:2.20.1-2+deb10u3 clang=1:7.0-47 lld=1:7.0-47 && \ 24 rm -rf /var/lib/apt/lists/* 25# Install a newer ninja release. It seems the older version in the debian repos 26# randomly crashes when compiling llvm. 27RUN wget "https://github.com/ninja-build/ninja/releases/download/v1.8.2/ninja-linux.zip" && \ 28 echo "d2fea9ff33b3ef353161ed906f260d565ca55b8ca0568fa07b1d2cab90a84a07 ninja-linux.zip" \ 29 | sha256sum -c && \ 30 unzip ninja-linux.zip -d /usr/local/bin && \ 31 rm ninja-linux.zip 32 33ENV TARGET_DIR=/tmp/clang_output 34ENV CLANG_RELEASE=llvmorg-15.0.1 35 36RUN mkdir -p /tmp/clang && cd /tmp/clang && \ 37 git clone --depth 1 -b ${CLANG_RELEASE} https://llvm.googlesource.com/llvm-project 38 39# As of October 21, 2022, iwyu 0.19 (for clang 15) was not yet a branch, so we just checkout 40# tip of tree at that time 41RUN git clone https://github.com/include-what-you-use/include-what-you-use.git /tmp/iwyu && \ 42 cd /tmp/iwyu && \ 43 git checkout 6d416d5f90755dd76d55c0f33f9ac0de6dd27b5f 44 45WORKDIR /tmp/clang/llvm-project 46 47ENV CC=/usr/bin/clang 48ENV CXX=/usr/bin/clang++ 49 50# https://libcxx.llvm.org/BuildingLibcxx.html#bootstrapping-build 51# https://github.com/include-what-you-use/include-what-you-use#how-to-build-as-part-of-llvm 52# This will build clang first and then use that new clang to build the runtimes and the 53# iwyu probject. 54RUN mkdir ${TARGET_DIR} out && \ 55 cmake -G Ninja -S llvm -B out \ 56 -DCMAKE_BUILD_TYPE=Release \ 57 -DCMAKE_INSTALL_PREFIX=${TARGET_DIR} \ 58 -DLLVM_ENABLE_PROJECTS="clang;lld;clang-tools-extra" \ 59 -DLLVM_ENABLE_RUNTIMES="all" \ 60 -DLLVM_INSTALL_TOOLCHAIN_ONLY=ON \ 61 -DLLVM_USE_LINKER=lld \ 62 -DLLVM_ENABLE_UNWIND_TABLES=OFF \ 63 -DLLVM_ENABLE_TERMINFO=OFF \ 64 -DLLVM_EXTERNAL_PROJECTS=iwyu \ 65 -DLLVM_EXTERNAL_IWYU_SOURCE_DIR=/tmp/iwyu 66 67RUN ninja -C out install 68RUN cp out/bin/llvm-symbolizer out/bin/llvm-profdata out/bin/llvm-cov ${TARGET_DIR}/bin 69RUN cp `c++ -print-file-name=libstdc++.so.6` ${TARGET_DIR}/lib 70 71# Use the newly compiled clang to build TSAN and MSAN libraries. 72ENV CC=${TARGET_DIR}/bin/clang 73ENV CXX=${TARGET_DIR}/bin/clang++ 74 75# It is very important to start the build from the runtimes subfolder and not the llvm subfolder 76# like we did above when following the bootstrapping-build instructions. 77# https://stackoverflow.com/a/73827100/1447621 78RUN mkdir tsan_out && \ 79 cmake -G Ninja -S runtimes -B tsan_out \ 80 -DCMAKE_BUILD_TYPE=Release \ 81 -DLLVM_ENABLE_RUNTIMES="libcxx;libcxxabi" \ 82 -DLLVM_USE_SANITIZER=Thread 83 84RUN ninja -C tsan_out cxx cxxabi 85RUN cp -r tsan_out/lib ${TARGET_DIR}/tsan 86 87# We would be following the instructions from 88# https://github.com/google/sanitizers/wiki/MemorySanitizerLibcxxHowTo 89# but those are currently out of date (https://github.com/google/sanitizers/issues/1574) 90RUN mkdir msan_out && \ 91 cmake -GNinja -S runtimes -B msan_out \ 92 -DCMAKE_BUILD_TYPE=Release \ 93 -DLLVM_ENABLE_RUNTIMES="libcxx;libcxxabi" \ 94 -DLLVM_USE_SANITIZER=MemoryWithOrigins 95 96RUN ninja -C msan_out cxx cxxabi 97 98RUN cp -r msan_out/lib ${TARGET_DIR}/msan