Debian Codegraph @

infra/bots/assets/clang_linux/Dockerfile

raw
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
7 FROM 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.
11 RUN 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.
18 RUN 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 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
26 # Install a newer ninja release.
27 RUN wget "https://github.com/ninja-build/ninja/releases/download/v1.12.1/ninja-linux.zip" && \
28 echo "6f98805688d19672bd699fbbfa2c2cf0fc054ac3df1f0e6a47664d963d530255 ninja-linux.zip" \
29 | sha256sum -c && \
30 unzip ninja-linux.zip -d /usr/local/bin && \
31 rm ninja-linux.zip
32
33 # Install a newer CMake release
34 RUN wget "https://github.com/Kitware/CMake/releases/download/v3.30.3/cmake-3.30.3-linux-x86_64.tar.gz" && \
35 echo "4a5864e9ff0d7945731fe6d14afb61490bf0ec154527bc3af0456bd8fa90decb cmake-3.30.3-linux-x86_64.tar.gz" \
36 | sha256sum -c && \
37 tar --strip-components=1 -xvzf cmake-3.30.3-linux-x86_64.tar.gz -C /usr/local && \
38 rm cmake-3.30.3-linux-x86_64.tar.gz
39
40 ENV TARGET_DIR=/tmp/clang_output
41 ENV CLANG_RELEASE=llvmorg-18.1.8
42
43 RUN mkdir -p /tmp/clang && cd /tmp/clang && \
44 git clone --depth 1 -b ${CLANG_RELEASE} https://llvm.googlesource.com/llvm-project
45
46 # As of August 30, 2024, iwyu 0.22 (for clang 18) is a branch. Unfortunately, this branch requires
47 # python 3.9. Commit "Loosen Python version requirements for functools.cache" [0] restored support
48 # for python 3.2+. However, clang internally made an incompatable change, which iwyu picked up with
49 # "[clang compat] Update InclusionDirective override" [1] which came before it. So we must
50 # checkout 0.22 and cherry-pick the python fix.
51 # [0] https://github.com/include-what-you-use/include-what-you-use/commit/88e414728702390ed8eebf11d14b992a01df1ee0
52 # [1] https://github.com/include-what-you-use/include-what-you-use/commit/f27fafa378a70b975aeaa9a1428b275a1edcfe5a
53 RUN git clone https://github.com/include-what-you-use/include-what-you-use.git /tmp/iwyu && \
54 cd /tmp/iwyu && \
55 git checkout 377eaef70cdda47368939f4d9beabfabe3f628f0 && \
56 git config user.email "[email protected]" && \
57 git config user.name "SkAsset Create" && \
58 git cherry-pick 88e414728702390ed8eebf11d14b992a01df1ee0
59
60 WORKDIR /tmp/clang/llvm-project
61
62 ENV CC=/usr/bin/clang
63 ENV CXX=/usr/bin/clang++
64
65 # https://libcxx.llvm.org/BuildingLibcxx.html#bootstrapping-build
66 # https://github.com/include-what-you-use/include-what-you-use#how-to-build-as-part-of-llvm
67 # This will build clang first and then use that new clang to build the runtimes and the
68 # iwyu probject.
69 RUN mkdir ${TARGET_DIR} out && \
70 cmake -G Ninja -S llvm -B out \
71 -DCMAKE_BUILD_TYPE=Release \
72 -DCMAKE_INSTALL_PREFIX=${TARGET_DIR} \
73 -DLLVM_ENABLE_PROJECTS="clang;lld;clang-tools-extra" \
74 -DLLVM_ENABLE_RUNTIMES="libcxx;libcxxabi;libunwind;compiler-rt" \
75 -DLLVM_INSTALL_TOOLCHAIN_ONLY=ON \
76 -DLLVM_USE_LINKER=lld \
77 -DLLVM_ENABLE_UNWIND_TABLES=OFF \
78 -DLLVM_ENABLE_TERMINFO=OFF \
79 -DLLVM_EXTERNAL_PROJECTS=iwyu \
80 -DLLVM_EXTERNAL_IWYU_SOURCE_DIR=/tmp/iwyu
81
82 RUN ninja -C out install
83 RUN cp out/bin/llvm-symbolizer out/bin/llvm-profdata out/bin/llvm-cov ${TARGET_DIR}/bin
84 RUN cp `c++ -print-file-name=libstdc++.so.6` ${TARGET_DIR}/lib
85
86 # Use the newly compiled clang to build TSAN and MSAN libraries.
87 ENV CC=${TARGET_DIR}/bin/clang
88 ENV CXX=${TARGET_DIR}/bin/clang++
89
90 # It is very important to start the build from the runtimes subfolder and not the llvm subfolder
91 # like we did above when following the bootstrapping-build instructions.
92 # https://stackoverflow.com/a/73827100/1447621
93 RUN mkdir tsan_out && \
94 cmake -G Ninja -S runtimes -B tsan_out \
95 -DCMAKE_BUILD_TYPE=Release \
96 -DLLVM_ENABLE_RUNTIMES="libcxx;libcxxabi;libunwind;compiler-rt" \
97 -DLLVM_USE_SANITIZER=Thread
98
99 RUN ninja -C tsan_out cxx cxxabi
100 RUN cp -r tsan_out/lib ${TARGET_DIR}/tsan
101
102 # We would be following the instructions from
103 # https://github.com/google/sanitizers/wiki/MemorySanitizerLibcxxHowTo
104 # but those are currently out of date (https://github.com/google/sanitizers/issues/1574)
105 RUN mkdir msan_out && \
106 cmake -GNinja -S runtimes -B msan_out \
107 -DCMAKE_BUILD_TYPE=Release \
108 -DLLVM_ENABLE_RUNTIMES="libcxx;libcxxabi;libunwind;compiler-rt" \
109 -DLLVM_USE_SANITIZER=MemoryWithOrigins
110
111 RUN ninja -C msan_out cxx cxxabi
112
113 RUN cp -r msan_out/lib ${TARGET_DIR}/msan