| 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 ubuntu:noble on Jan 8 2025. |
| 5 |
# Found by running |
| 6 |
# docker pull ubuntu:noble && docker images --digests | grep ubuntu |
| 7 |
FROM ubuntu@sha256:80dd3c3b9c6cecb9f1667e9290b3bc61b78c2678c02cbdae5f0fea92cc6734ab |
| 8 |
|
| 9 |
# Install build dependencies of llvm. |
| 10 |
# First, Update the apt's source list and include the sources of the packages. |
| 11 |
RUN sed -i 's/^Types: deb$/Types: deb deb-src/g' /etc/apt/sources.list.d/ubuntu.sources |
| 12 |
# Install compiler, python, etc. We need clang and lld because otherwise we have issues compiling |
| 13 |
# compiler-rt (it fails using the built-in ld). |
| 14 |
# |
| 15 |
# The versions were added after seeing what was available when this image was created on Jan 8 2025. |
| 16 |
# Specifying the versions makes this Docker container comply with SLSA level 1. |
| 17 |
RUN apt-get update && \ |
| 18 |
apt-get install -y --no-install-recommends \ |
| 19 |
ca-certificates=20240203 \ |
| 20 |
gnupg=2.4.4-2ubuntu17 \ |
| 21 |
build-essential=12.10ubuntu1 \ |
| 22 |
cmake=3.28.3-1build7 \ |
| 23 |
make=4.3-4.1build2 \ |
| 24 |
python3=3.12.3-0ubuntu2 \ |
| 25 |
zlib1g=1:1.3.dfsg-3.1ubuntu2.1 \ |
| 26 |
wget=1.21.4-1ubuntu4 \ |
| 27 |
unzip=6.0-28ubuntu4 \ |
| 28 |
git=1:2.43.0-1ubuntu7 \ |
| 29 |
clang=1:18.0-59~exp2 \ |
| 30 |
lld=1:18.0-59~exp2 \ |
| 31 |
ninja-build=1.11.1-2 && \ |
| 32 |
rm -rf /var/lib/apt/lists/* |
| 33 |
|
| 34 |
ENV TARGET_DIR=/tmp/clang_output |
| 35 |
ENV CLANG_RELEASE=llvmorg-19.1.6 |
| 36 |
|
| 37 |
RUN mkdir -p /tmp/clang && cd /tmp/clang && \ |
| 38 |
git clone --depth 1 -b ${CLANG_RELEASE} https://llvm.googlesource.com/llvm-project |
| 39 |
|
| 40 |
# Check out the IWYU branch corresponding to our CLANG_RELEASE. |
| 41 |
RUN git clone https://github.com/include-what-you-use/include-what-you-use.git /tmp/iwyu && \ |
| 42 |
cd /tmp/iwyu && \ |
| 43 |
git checkout clang_19 |
| 44 |
|
| 45 |
WORKDIR /tmp/clang/llvm-project |
| 46 |
|
| 47 |
ENV CC=/usr/bin/clang |
| 48 |
ENV 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. |
| 54 |
RUN 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="libcxx;libcxxabi;libunwind;compiler-rt" \ |
| 60 |
-DLLVM_ENABLE_ZLIB=ON \ |
| 61 |
-DLLVM_INSTALL_TOOLCHAIN_ONLY=ON \ |
| 62 |
-DLLVM_USE_LINKER=lld \ |
| 63 |
-DLLVM_ENABLE_UNWIND_TABLES=OFF \ |
| 64 |
-DLLVM_EXTERNAL_PROJECTS=iwyu \ |
| 65 |
-DLLVM_EXTERNAL_IWYU_SOURCE_DIR=/tmp/iwyu |
| 66 |
|
| 67 |
RUN ninja -C out install |
| 68 |
RUN cp out/bin/llvm-symbolizer out/bin/llvm-profdata out/bin/llvm-cov ${TARGET_DIR}/bin |
| 69 |
RUN cp `c++ -print-file-name=libstdc++.so.6` ${TARGET_DIR}/lib |
| 70 |
|
| 71 |
# Use the newly compiled clang to build TSAN and MSAN libraries. |
| 72 |
ENV CC=${TARGET_DIR}/bin/clang |
| 73 |
ENV 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 |
| 78 |
RUN mkdir tsan_out && \ |
| 79 |
cmake -G Ninja -S runtimes -B tsan_out \ |
| 80 |
-DCMAKE_BUILD_TYPE=Release \ |
| 81 |
-DLLVM_ENABLE_RUNTIMES="libcxx;libcxxabi;libunwind;compiler-rt" \ |
| 82 |
-DLLVM_USE_SANITIZER=Thread |
| 83 |
|
| 84 |
RUN ninja -C tsan_out cxx cxxabi |
| 85 |
RUN 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) |
| 90 |
RUN 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 |
-DLIBCXXABI_USE_LLVM_UNWINDER=OFF |
| 96 |
|
| 97 |
RUN ninja -C msan_out cxx cxxabi |
| 98 |
|
| 99 |
RUN cp -r msan_out/lib ${TARGET_DIR}/msan |