Skip to content

Commit cc09fd3

Browse files
authored
Build ccache from source (#91)
The change modifies the Debian, RHEL, and Ubuntu images to build from source. As suggested in #90 (review), I first explored using the GCC image as a base to build ccache, and then copy it into the final GCC and Clang images. However, this resulted in two issues: 1. The Clang images would need to build the GCC base image first, which would result in additional work. 2. The Clang images would need to be provided with a GCC version to use. I considered building a wholly separate image, e.g. a `tools-rippled-ccache`, to use as base image in which GCC would be installed and then ccache built from source, upon which it could be copied into the distro images. However, this has its own drawbacks: 1. The CI pipeline currently runs all builds in parallel, so it is not set up to handle dependencies between images. This would then result in failures until the ccache image is built and pushed. 2. Future updates to the ccache image would lead to unexpected issues. Namely, if you were to change the ccache version, the old image would still used due to issue 1. above, so you'd need to first merge the change, and then rerun the pipelines afterwards so the distro images actually use the new ccache image. (Note that we already have this issue with the GCC base image in the `docker/gcc` directory, used by Debian, so I prefer to not add more such cases.) So, to keep things simple at the expense of duplication (of which there already is a bit; unfortunately Docker doesn't support importing a bunch of instructions from another Dockerfile), I build ccache from source in both the GCC and Clang final images. Note that the gold linker in RHEL 8 is so old that it doesn't support a compiler flag used by ccache, so I've configured it to use the default linker instead.
1 parent f07de7f commit cc09fd3

File tree

6 files changed

+151
-57
lines changed

6 files changed

+151
-57
lines changed

docker/debian/Dockerfile

Lines changed: 42 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -79,27 +79,6 @@ RUN pip install --no-cache \
7979
gcovr==${GCOVR_VERSION} \
8080
cmake==${CMAKE_VERSION}
8181

82-
# Install ccache. Note that the ccache version from the package manager is
83-
# installed for Debian Bullseye, as the latest version requires a newer GLIBC
84-
# version, and older compatible releases are x86-64 only.
85-
ARG CCACHE_VERSION
86-
87-
RUN <<EOF
88-
if [[ "${DEBIAN_VERSION}" == "bullseye" ]]; then
89-
apt-get update
90-
apt-get install -y --no-install-recommends ccache
91-
apt-get clean
92-
rm -rf /var/lib/apt/lists/*
93-
else
94-
ARCH=$(uname -m)
95-
wget -O ccache.tar.xz https://github.com/ccache/ccache/releases/download/v${CCACHE_VERSION}/ccache-${CCACHE_VERSION}-linux-${ARCH}.tar.xz
96-
tar -xf ccache.tar.xz
97-
cp ccache-${CCACHE_VERSION}-linux-${ARCH}/ccache /usr/local/bin
98-
rm -r ccache-${CCACHE_VERSION}-linux-${ARCH}
99-
rm ccache.tar.xz
100-
fi
101-
EOF
102-
10382
# Install mold.
10483
ARG MOLD_VERSION
10584

@@ -119,7 +98,6 @@ ENV PATH="$CARGO_HOME/bin:$PATH"
11998

12099
# Print versions.
121100
RUN <<EOF
122-
ccache --version
123101
cmake --version
124102
conan --version
125103
gcovr --version
@@ -192,6 +170,27 @@ if [[ "${CXX_VER}" != "${GCC_VERSION}" ]]; then
192170
fi
193171
EOF
194172

173+
# Build ccache from source to avoid incompatible GLIBC versions.
174+
ARG CCACHE_VERSION
175+
176+
RUN <<EOF
177+
wget -O ccache.tar.gz https://github.com/ccache/ccache/releases/download/v${CCACHE_VERSION}/ccache-${CCACHE_VERSION}.tar.gz
178+
tar -xzf ccache.tar.gz
179+
rm ccache.tar.gz
180+
cd ccache-${CCACHE_VERSION}
181+
182+
# Build, install, and clean up.
183+
mkdir build
184+
cd build
185+
cmake -DCMAKE_BUILD_TYPE=Release -DENABLE_TESTING=OFF ..
186+
make -j install
187+
cd ../..
188+
rm -rf ccache-${CCACHE_VERSION}
189+
190+
# Verify the installation.
191+
ccache --version
192+
EOF
193+
195194
# Set the Conan home directory, so the users of this image can find the default
196195
# profile.
197196
ENV HOME=/root
@@ -285,6 +284,27 @@ if [[ "${CXX_VER}" != "${CLANG_VERSION}" ]]; then
285284
fi
286285
EOF
287286

287+
# Build ccache from source to avoid incompatible GLIBC versions.
288+
ARG CCACHE_VERSION
289+
290+
RUN <<EOF
291+
wget -O ccache.tar.gz https://github.com/ccache/ccache/releases/download/v${CCACHE_VERSION}/ccache-${CCACHE_VERSION}.tar.gz
292+
tar -xzf ccache.tar.gz
293+
rm ccache.tar.gz
294+
cd ccache-${CCACHE_VERSION}
295+
296+
# Build, install, and clean up.
297+
mkdir build
298+
cd build
299+
cmake -DCMAKE_BUILD_TYPE=Release -DENABLE_TESTING=OFF ..
300+
make -j install
301+
cd ../..
302+
rm -rf ccache-${CCACHE_VERSION}
303+
304+
# Verify the installation.
305+
ccache --version
306+
EOF
307+
288308
# Set the Conan home directory, so the users of this image can find the default
289309
# profile.
290310
ENV HOME=/root

docker/debian/README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,12 @@ In order to build a GCC image for Bullseye, you also need to explicitly set
6666
`BASE_IMAGE` build argument, e.g.
6767

6868
```shell
69+
# The version of the distro to use.
6970
DEBIAN_VERSION=bullseye
71+
# The version of GCC to use, including corresponding base image.
7072
GCC_VERSION=12
7173
BASE_IMAGE=ghcr.io/xrplf/ci/gcc:${GCC_VERSION}-bullseye
74+
# The versions of the tools to use.
7275
CCACHE_VERSION=4.12.2
7376
CMAKE_VERSION=4.1.0
7477
CONAN_VERSION=2.22.2
@@ -100,8 +103,11 @@ In order to build an image for Clang, run the commands below from the root
100103
directory of the repository.
101104

102105
```shell
106+
# The version of the distro to use.
103107
DEBIAN_VERSION=bookworm
108+
# The version of Clang to use.
104109
CLANG_VERSION=17
110+
# The versions of the tools to use.
105111
CCACHE_VERSION=4.12.2
106112
CMAKE_VERSION=4.1.0
107113
CONAN_VERSION=2.22.2

docker/rhel/Dockerfile

Lines changed: 48 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -90,27 +90,6 @@ RUN pip install --no-cache \
9090
gcovr==${GCOVR_VERSION} \
9191
cmake==${CMAKE_VERSION}
9292

93-
# Install ccache. Note that the ccache version from the package manager is
94-
# installed for RHEL 8, as the latest version requires a newer GLIBC version,
95-
# and older compatible releases are x86-64 only.
96-
ARG CCACHE_VERSION
97-
98-
RUN <<EOF
99-
if [[ "${RHEL_VERSION}" == "8" ]]; then
100-
dnf update -y
101-
dnf install -y --allowerasing --setopt=tsflags=nodocs ccache
102-
dnf clean -y all
103-
rm -rf /var/cache/dnf/*
104-
else
105-
ARCH=$(uname -m)
106-
wget -O ccache.tar.xz https://github.com/ccache/ccache/releases/download/v${CCACHE_VERSION}/ccache-${CCACHE_VERSION}-linux-${ARCH}.tar.xz
107-
tar -xf ccache.tar.xz
108-
cp ccache-${CCACHE_VERSION}-linux-${ARCH}/ccache /usr/local/bin
109-
rm -r ccache-${CCACHE_VERSION}-linux-${ARCH}
110-
rm ccache.tar.xz
111-
fi
112-
EOF
113-
11493
# Install mold.
11594
ARG MOLD_VERSION
11695

@@ -130,7 +109,6 @@ ENV PATH="$CARGO_HOME/bin:$PATH"
130109

131110
# Print versions.
132111
RUN <<EOF
133-
ccache --version
134112
cmake --version
135113
conan --version
136114
gcovr --version
@@ -204,6 +182,30 @@ if [[ "${CXX_VER}" != "${GCC_VERSION}" ]]; then
204182
fi
205183
EOF
206184

185+
# Build ccache from source to avoid incompatible GLIBC versions.
186+
ARG CCACHE_VERSION
187+
188+
RUN <<EOF
189+
wget -O ccache.tar.gz https://github.com/ccache/ccache/releases/download/v${CCACHE_VERSION}/ccache-${CCACHE_VERSION}.tar.gz
190+
tar -xzf ccache.tar.gz
191+
rm ccache.tar.gz
192+
cd ccache-${CCACHE_VERSION}
193+
194+
# Build, install, and clean up.
195+
mkdir build
196+
cd build
197+
if [[ "${RHEL_VERSION}" -eq "8" ]]; then
198+
LINKER_OPTION='-D USE_FASTER_LINKER=OFF'
199+
fi
200+
cmake -DCMAKE_BUILD_TYPE=Release -DENABLE_TESTING=OFF ${LINKER_OPTION} ..
201+
make -j install
202+
cd ../..
203+
rm -rf ccache-${CCACHE_VERSION}
204+
205+
# Verify the installation.
206+
ccache --version
207+
EOF
208+
207209
# Set the Conan home directory, so the users of this image can find the default
208210
# profile.
209211
ENV HOME=/root
@@ -280,6 +282,30 @@ if [[ ${CXX_VER} -lt ${MINIMUM_CLANG_VERSION} ]]; then
280282
fi
281283
EOF
282284

285+
# Build ccache from source to avoid incompatible GLIBC versions.
286+
ARG CCACHE_VERSION
287+
288+
RUN <<EOF
289+
wget -O ccache.tar.gz https://github.com/ccache/ccache/releases/download/v${CCACHE_VERSION}/ccache-${CCACHE_VERSION}.tar.gz
290+
tar -xzf ccache.tar.gz
291+
rm ccache.tar.gz
292+
cd ccache-${CCACHE_VERSION}
293+
294+
# Build, install, and clean up.
295+
mkdir build
296+
cd build
297+
if [[ "${RHEL_VERSION}" -eq "8" ]]; then
298+
LINKER_OPTION='-D USE_FASTER_LINKER=OFF'
299+
fi
300+
cmake -DCMAKE_BUILD_TYPE=Release -DENABLE_TESTING=OFF ${LINKER_OPTION} ..
301+
make -j install
302+
cd ../..
303+
rm -rf ccache-${CCACHE_VERSION}
304+
305+
# Verify the installation.
306+
ccache --version
307+
EOF
308+
283309
# Set the Conan home directory, so the users of this image can find the default
284310
# profile.
285311
ENV HOME=/root

docker/rhel/README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,11 @@ In order to build the image for GCC, run the commands below from the root
2323
directory of the repository.
2424

2525
```shell
26+
# The version of the distro to use.
2627
RHEL_VERSION=9
28+
# The version of GCC to use.
2729
GCC_VERSION=12
30+
# The versions of the tools to use.
2831
CCACHE_VERSION=4.12.2
2932
CMAKE_VERSION=4.1.0
3033
CONAN_VERSION=2.22.2
@@ -55,7 +58,9 @@ In order to build the image for Clang, run the commands below from the root
5558
directory of the repository.
5659

5760
```shell
61+
# The version of the distro to use.
5862
RHEL_VERSION=10
63+
# The versions of the tools to use.
5964
CCACHE_VERSION=4.12.2
6065
CMAKE_VERSION=4.1.0
6166
CONAN_VERSION=2.22.2

docker/ubuntu/Dockerfile

Lines changed: 42 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -62,18 +62,6 @@ RUN pip install --no-cache \
6262
gcovr==${GCOVR_VERSION} \
6363
cmake==${CMAKE_VERSION}
6464

65-
# Install ccache.
66-
ARG CCACHE_VERSION
67-
68-
RUN <<EOF
69-
ARCH=$(uname -m)
70-
wget -O ccache.tar.xz https://github.com/ccache/ccache/releases/download/v${CCACHE_VERSION}/ccache-${CCACHE_VERSION}-linux-${ARCH}.tar.xz
71-
tar -xf ccache.tar.xz
72-
cp ccache-${CCACHE_VERSION}-linux-${ARCH}/ccache /usr/local/bin
73-
rm -r ccache-${CCACHE_VERSION}-linux-${ARCH}
74-
rm ccache.tar.xz
75-
EOF
76-
7765
# Install mold.
7866
ARG MOLD_VERSION
7967

@@ -93,7 +81,6 @@ ENV PATH="$CARGO_HOME/bin:$PATH"
9381

9482
# Print versions.
9583
RUN <<EOF
96-
ccache --version
9784
cmake --version
9885
conan --version
9986
gcovr --version
@@ -156,6 +143,27 @@ if [[ "${CXX_VER}" != "${GCC_VERSION}" ]]; then
156143
fi
157144
EOF
158145

146+
# Build ccache from source to avoid incompatible GLIBC versions.
147+
ARG CCACHE_VERSION
148+
149+
RUN <<EOF
150+
wget -O ccache.tar.gz https://github.com/ccache/ccache/releases/download/v${CCACHE_VERSION}/ccache-${CCACHE_VERSION}.tar.gz
151+
tar -xzf ccache.tar.gz
152+
rm ccache.tar.gz
153+
cd ccache-${CCACHE_VERSION}
154+
155+
# Build, install, and clean up.
156+
mkdir build
157+
cd build
158+
cmake -DCMAKE_BUILD_TYPE=Release -DENABLE_TESTING=OFF ..
159+
make -j install
160+
cd ../..
161+
rm -rf ccache-${CCACHE_VERSION}
162+
163+
# Verify the installation.
164+
ccache --version
165+
EOF
166+
159167
# Set the Conan home directory, so the users of this image can find the default
160168
# profile.
161169
ENV HOME=/root
@@ -244,6 +252,27 @@ if [[ "${CXX_VER}" != "${CLANG_VERSION}" ]]; then
244252
fi
245253
EOF
246254

255+
# Build ccache from source to avoid incompatible GLIBC versions.
256+
ARG CCACHE_VERSION
257+
258+
RUN <<EOF
259+
wget -O ccache.tar.gz https://github.com/ccache/ccache/releases/download/v${CCACHE_VERSION}/ccache-${CCACHE_VERSION}.tar.gz
260+
tar -xzf ccache.tar.gz
261+
rm ccache.tar.gz
262+
cd ccache-${CCACHE_VERSION}
263+
264+
# Build, install, and clean up.
265+
mkdir build
266+
cd build
267+
cmake -DCMAKE_BUILD_TYPE=Release -DENABLE_TESTING=OFF ..
268+
make -j install
269+
cd ../..
270+
rm -rf ccache-${CCACHE_VERSION}
271+
272+
# Verify the installation.
273+
ccache --version
274+
EOF
275+
247276
# Set the Conan home directory, so the users of this image can find the default
248277
# profile.
249278
ENV HOME=/root

docker/ubuntu/README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,18 @@ In order to build the image for GCC, run the commands below from the root
2222
directory of the repository.
2323

2424
```shell
25+
# The version of the distro to use.
2526
UBUNTU_VERSION=noble
27+
# The version of GCC to use.
2628
GCC_VERSION=14
29+
# The versions of the tools to use.
2730
CCACHE_VERSION=4.12.2
2831
CMAKE_VERSION=4.1.0
2932
CONAN_VERSION=2.22.2
3033
GCOVR_VERSION=8.3
3134
MOLD_VERSION=2.40.4
3235
RUST_VERSION=1.91.1
36+
# The name of the image to build.
3337
CONTAINER_IMAGE=ghcr.io/xrplf/ci/ubuntu-${UBUNTU_VERSION}:gcc-${GCC_VERSION}
3438

3539
docker buildx build . \
@@ -54,14 +58,18 @@ In order to build the image for Clang, run the commands below from the root
5458
directory of the repository.
5559

5660
```shell
61+
# The version of the distro to use.
5762
UBUNTU_VERSION=noble
63+
# The version of Clang to use.
5864
CLANG_VERSION=18
65+
# The versions of the tools to use.
5966
CCACHE_VERSION=4.12.2
6067
CMAKE_VERSION=4.1.0
6168
CONAN_VERSION=2.22.2
6269
GCOVR_VERSION=8.3
6370
MOLD_VERSION=2.40.4
6471
RUST_VERSION=1.91.1
72+
# The name of the image to build.
6573
CONTAINER_IMAGE=ghcr.io/xrplf/ci/ubuntu-${UBUNTU_VERSION}:clang-${CLANG_VERSION}
6674

6775
docker buildx build . \

0 commit comments

Comments
 (0)