Skip to content

Commit 3547bb3

Browse files
bthomeeBronek
andauthored
Add gcc and g++ to the Debian and Ubuntu clang images (#21)
This PR adds gcc and g++ to the Debian and Ubuntu clang images as some build dependencies (e.g. `b2`) require them. RHEL already include these compilers by default. --------- Co-authored-by: Bart Thomee <11445373+bthomee@users.noreply.github.com> Co-authored-by: Bronek Kozicki <brok@incorrekt.com>
1 parent 922b62f commit 3547bb3

File tree

5 files changed

+84
-45
lines changed

5 files changed

+84
-45
lines changed

docker/debian/Dockerfile

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,12 @@ ldconfig -v
8181
dpkg-divert --divert /usr/bin/gcc.orig --rename /usr/bin/gcc
8282
dpkg-divert --divert /usr/bin/g++.orig --rename /usr/bin/g++
8383
dpkg-divert --divert /usr/bin/gfortran.orig --rename /usr/bin/gfortran
84-
update-alternatives --install /usr/bin/cc cc /usr/local/bin/gcc 999
85-
update-alternatives --install \
86-
/usr/bin/gcc gcc /usr/local/bin/gcc 100 \
84+
update-alternatives \
85+
--install /usr/bin/cc cc /usr/local/bin/gcc 999
86+
update-alternatives \
87+
--install /usr/bin/c++ c++ /usr/local/bin/g++ 999
88+
update-alternatives \
89+
--install /usr/bin/gcc gcc /usr/local/bin/gcc 100 \
8790
--slave /usr/bin/g++ g++ /usr/local/bin/g++ \
8891
--slave /usr/bin/gcc-ar gcc-ar /usr/local/bin/gcc-ar \
8992
--slave /usr/bin/gcc-nm gcc-nm /usr/local/bin/gcc-nm \
@@ -93,6 +96,7 @@ update-alternatives --install \
9396
--slave /usr/bin/gcov-dump gcov-dump /usr/local/bin/gcov-dump \
9497
--slave /usr/bin/lto-dump lto-dump /usr/local/bin/lto-dump
9598
update-alternatives --auto cc
99+
update-alternatives --auto c++
96100
update-alternatives --auto gcc
97101
EOF
98102
# Set the compiler environment variables to point to the GCC binaries.
@@ -144,7 +148,7 @@ RUN conan profile show
144148
# Test the image by compiling a simple C++ program.
145149
RUN --mount=type=bind,source=test,target=/test,readonly <<EOF
146150
cp -r /test test
147-
cd test && ./run.sh
151+
cd test && ./run.sh gcc
148152
cd ..
149153
rm -rf test
150154
EOF
@@ -157,10 +161,12 @@ ARG DEBIAN_FRONTEND=noninteractive
157161

158162
# Install Clang. Use the LLVM apt repository to access the latest versions. We
159163
# must repeat the DEBIAN_VERSION argument here, as it is not inherited from the
160-
# base or source images.
164+
# base or source images. Some build dependencies require GCC to be also available.
161165
ARG DEBIAN_VERSION
162166
ARG CLANG_VERSION
163167
RUN <<EOF
168+
apt-get update
169+
apt-get install -y --no-install-recommends gcc g++
164170
curl --no-progress-meter https://apt.llvm.org/llvm-snapshot.gpg.key | gpg --dearmor -o /etc/apt/keyrings/llvm.gpg
165171
printf "%s\n%s\n" \
166172
"deb [signed-by=/etc/apt/keyrings/llvm.gpg] https://apt.llvm.org/${DEBIAN_VERSION}/ llvm-toolchain-${DEBIAN_VERSION}-${CLANG_VERSION} main" \
@@ -169,13 +175,17 @@ apt-get update
169175
apt-get install -t llvm-toolchain-${DEBIAN_VERSION}-${CLANG_VERSION} -y --no-install-recommends clang-${CLANG_VERSION} llvm-${CLANG_VERSION}
170176
apt-get clean
171177
rm -rf /var/lib/apt/lists/*
172-
update-alternatives --install /usr/bin/cc cc /usr/bin/clang-${CLANG_VERSION} 999
173-
update-alternatives --install \
174-
/usr/bin/clang clang /usr/bin/clang-${CLANG_VERSION} 100 \
175-
--slave /usr/bin/clang++ clang++ /usr/bin/clang++-${CLANG_VERSION}
176-
update-alternatives --install \
177-
/usr/bin/llvm-cov llvm-cov /usr/bin/llvm-cov-${CLANG_VERSION} 100
178+
update-alternatives \
179+
--install /usr/bin/cc cc /usr/bin/clang-${CLANG_VERSION} 999
180+
update-alternatives \
181+
--install /usr/bin/c++ c++ /usr/bin/clang++-${CLANG_VERSION} 999
182+
update-alternatives \
183+
--install /usr/bin/clang clang /usr/bin/clang-${CLANG_VERSION} 100 \
184+
--slave /usr/bin/clang++ clang++ /usr/bin/clang++-${CLANG_VERSION}
185+
update-alternatives \
186+
--install /usr/bin/llvm-cov llvm-cov /usr/bin/llvm-cov-${CLANG_VERSION} 100
178187
update-alternatives --auto cc
188+
update-alternatives --auto c++
179189
update-alternatives --auto clang
180190
update-alternatives --auto llvm-cov
181191
EOF
@@ -225,7 +235,7 @@ RUN conan profile show
225235
# Test the image by compiling a simple C++ program.
226236
RUN --mount=type=bind,source=test,target=/test,readonly <<EOF
227237
cp -r /test test
228-
cd test && ./run.sh
238+
cd test && ./run.sh clang
229239
cd ..
230240
rm -rf test
231241
EOF

docker/rhel/Dockerfile

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -53,15 +53,19 @@ dnf remove -y gcc gcc-c++
5353
dnf install -y --setopt=tsflags=nodocs gcc-toolset-${GCC_VERSION}-gcc gcc-toolset-${GCC_VERSION}-gcc-c++
5454
dnf clean -y all
5555
rm -rf /var/cache/dnf/*
56-
update-alternatives --install /usr/bin/cc cc /opt/rh/gcc-toolset-${GCC_VERSION}/root/usr/bin/gcc 999
5756
update-alternatives \
58-
--install /usr/bin/gcc gcc /opt/rh/gcc-toolset-${GCC_VERSION}/root/usr/bin/gcc 100 \
59-
--slave /usr/bin/g++ g++ /opt/rh/gcc-toolset-${GCC_VERSION}/root/usr/bin/g++ \
60-
--slave /usr/bin/cpp cpp /opt/rh/gcc-toolset-${GCC_VERSION}/root/usr/bin/cpp \
61-
--slave /usr/bin/gcov gcov /opt/rh/gcc-toolset-${GCC_VERSION}/root/usr/bin/gcov \
62-
--slave /usr/bin/gcov-dump gcov-dump /opt/rh/gcc-toolset-${GCC_VERSION}/root/usr/bin/gcov-dump-${GCC_VERSION} \
63-
--slave /usr/bin/gcov-tool gcov-tool /opt/rh/gcc-toolset-${GCC_VERSION}/root/usr/bin/gcov-tool-${GCC_VERSION}
57+
--install /usr/bin/cc cc /opt/rh/gcc-toolset-${GCC_VERSION}/root/usr/bin/gcc 999
58+
update-alternatives \
59+
--install /usr/bin/c++ c++ /opt/rh/gcc-toolset-${GCC_VERSION}/root/usr/bin/g++ 999
60+
update-alternatives \
61+
--install /usr/bin/gcc gcc /opt/rh/gcc-toolset-${GCC_VERSION}/root/usr/bin/gcc 100 \
62+
--slave /usr/bin/g++ g++ /opt/rh/gcc-toolset-${GCC_VERSION}/root/usr/bin/g++ \
63+
--slave /usr/bin/cpp cpp /opt/rh/gcc-toolset-${GCC_VERSION}/root/usr/bin/cpp \
64+
--slave /usr/bin/gcov gcov /opt/rh/gcc-toolset-${GCC_VERSION}/root/usr/bin/gcov \
65+
--slave /usr/bin/gcov-dump gcov-dump /opt/rh/gcc-toolset-${GCC_VERSION}/root/usr/bin/gcov-dump-${GCC_VERSION} \
66+
--slave /usr/bin/gcov-tool gcov-tool /opt/rh/gcc-toolset-${GCC_VERSION}/root/usr/bin/gcov-tool-${GCC_VERSION}
6467
update-alternatives --auto cc
68+
update-alternatives --auto c++
6569
update-alternatives --auto gcc
6670
EOF
6771
# Set the compiler environment variables to point to the GCC binaries.
@@ -110,7 +114,7 @@ RUN conan profile show
110114
# Test the image by compiling a simple C++ program.
111115
RUN --mount=type=bind,source=test,target=/test,readonly <<EOF
112116
cp -r /test test
113-
cd test && ./run.sh
117+
cd test && ./run.sh gcc
114118
cd ..
115119
rm -rf test
116120
EOF
@@ -119,13 +123,18 @@ EOF
119123
FROM base AS clang
120124

121125
# Install Clang. Note that in the RHEL UBIs, we cannot choose the Clang version
122-
# to install and we get what is available.
126+
# to install and we get what is available. Some build dependencies require GCC
127+
# to be also available.
123128
RUN <<EOF
124-
dnf install -y --setopt=tsflags=nodocs clang llvm
129+
dnf install -y --setopt=tsflags=nodocs clang llvm gcc gcc-c++
125130
dnf clean -y all
126131
rm -rf /var/cache/dnf/*
127-
update-alternatives --install /usr/bin/cc cc /usr/bin/clang 999
132+
update-alternatives \
133+
--install /usr/bin/cc cc /usr/bin/clang 999
134+
update-alternatives \
135+
--install /usr/bin/c++ c++ /usr/bin/clang++ 999
128136
update-alternatives --auto cc
137+
update-alternatives --auto c++
129138
EOF
130139
# Set the compiler environment variables to point to the GCC binaries.
131140
ENV CC=/usr/bin/clang
@@ -174,7 +183,7 @@ RUN conan profile show
174183
# Test the image by compiling a simple C++ program.
175184
RUN --mount=type=bind,source=test,target=/test,readonly <<EOF
176185
cp -r /test test
177-
cd test && ./run.sh
186+
cd test && ./run.sh clang
178187
cd ..
179188
rm -rf test
180189
EOF

docker/ubuntu/Dockerfile

Lines changed: 30 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -67,19 +67,23 @@ ARG GCC_VERSION
6767
RUN <<EOF
6868
apt-get update
6969
apt-get install -y --no-install-recommends \
70-
gcc-${GCC_VERSION} \
71-
g++-${GCC_VERSION} \
72-
debhelper
70+
gcc-${GCC_VERSION} \
71+
g++-${GCC_VERSION} \
72+
debhelper
7373
apt-get clean
7474
rm -rf /var/lib/apt/lists/*
75-
update-alternatives --install /usr/bin/cc cc /usr/bin/gcc-${GCC_VERSION} 999
7675
update-alternatives \
77-
--install /usr/bin/gcc gcc /usr/bin/gcc-${GCC_VERSION} 100 \
78-
--slave /usr/bin/g++ g++ /usr/bin/g++-${GCC_VERSION} \
79-
--slave /usr/bin/gcov gcov /usr/bin/gcov-${GCC_VERSION} \
80-
--slave /usr/bin/gcov-dump gcov-dump /usr/bin/gcov-dump-${GCC_VERSION} \
81-
--slave /usr/bin/gcov-tool gcov-tool /usr/bin/gcov-tool-${GCC_VERSION}
76+
--install /usr/bin/cc cc /usr/bin/gcc-${GCC_VERSION} 999
77+
update-alternatives \
78+
--install /usr/bin/c++ c++ /usr/bin/g++-${GCC_VERSION} 999
79+
update-alternatives \
80+
--install /usr/bin/gcc gcc /usr/bin/gcc-${GCC_VERSION} 100 \
81+
--slave /usr/bin/g++ g++ /usr/bin/g++-${GCC_VERSION} \
82+
--slave /usr/bin/gcov gcov /usr/bin/gcov-${GCC_VERSION} \
83+
--slave /usr/bin/gcov-dump gcov-dump /usr/bin/gcov-dump-${GCC_VERSION} \
84+
--slave /usr/bin/gcov-tool gcov-tool /usr/bin/gcov-tool-${GCC_VERSION}
8285
update-alternatives --auto cc
86+
update-alternatives --auto c++
8387
update-alternatives --auto gcc
8488
EOF
8589
# Set the compiler environment variables to point to the GCC binaries.
@@ -128,7 +132,7 @@ RUN conan profile show
128132
# Test the image by compiling a simple C++ program.
129133
RUN --mount=type=bind,source=test,target=/test,readonly <<EOF
130134
cp -r /test test
131-
cd test && ./run.sh
135+
cd test && ./run.sh gcc
132136
cd ..
133137
rm -rf test
134138
EOF
@@ -139,22 +143,28 @@ FROM base AS clang
139143
# This is not inherited from base image, ensure no manual interaction needed.
140144
ARG DEBIAN_FRONTEND=noninteractive
141145

142-
# Install Clang.
146+
# Install Clang. Some build dependencies require GCC to be also available.
143147
ARG CLANG_VERSION
144148
RUN <<EOF
145149
apt-get update
146150
apt-get install -y --no-install-recommends \
147-
clang-${CLANG_VERSION} \
148-
llvm-${CLANG_VERSION}
151+
clang-${CLANG_VERSION} \
152+
llvm-${CLANG_VERSION} \
153+
gcc \
154+
g++
149155
apt-get clean
150156
rm -rf /var/lib/apt/lists/*
151-
update-alternatives --install /usr/bin/cc cc /usr/bin/clang-${CLANG_VERSION} 999
152-
update-alternatives --install \
153-
/usr/bin/clang clang /usr/bin/clang-${CLANG_VERSION} 100 \
154-
--slave /usr/bin/clang++ clang++ /usr/bin/clang++-${CLANG_VERSION}
155-
update-alternatives --install \
156-
/usr/bin/llvm-cov llvm-cov /usr/bin/llvm-cov-${CLANG_VERSION} 100
157+
update-alternatives \
158+
--install /usr/bin/cc cc /usr/bin/clang-${CLANG_VERSION} 999
159+
update-alternatives \
160+
--install /usr/bin/c++ c++ /usr/bin/clang++-${CLANG_VERSION} 999
161+
update-alternatives \
162+
--install /usr/bin/clang clang /usr/bin/clang-${CLANG_VERSION} 100 \
163+
--slave /usr/bin/clang++ clang++ /usr/bin/clang++-${CLANG_VERSION}
164+
update-alternatives \
165+
--install /usr/bin/llvm-cov llvm-cov /usr/bin/llvm-cov-${CLANG_VERSION} 100
157166
update-alternatives --auto cc
167+
update-alternatives --auto c++
158168
update-alternatives --auto clang
159169
update-alternatives --auto llvm-cov
160170
EOF
@@ -204,7 +214,7 @@ RUN conan profile show
204214
# Test the image by compiling a simple C++ program.
205215
RUN --mount=type=bind,source=test,target=/test,readonly <<EOF
206216
cp -r /test test
207-
cd test && ./run.sh
217+
cd test && ./run.sh clang
208218
cd ..
209219
rm -rf test
210220
EOF

test/run.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#!/bin/bash
22

33
set -ex
4+
set -o pipefail
45

56
# Install Conan dependencies, configure the project, and build the executable.
67
conan install . --output-folder=build --build=missing
@@ -9,7 +10,7 @@ cmake .. -DCMAKE_TOOLCHAIN_FILE=conan_toolchain.cmake -DCMAKE_BUILD_TYPE=Release
910
cmake --build .
1011

1112
# Run the executable.
12-
./example
13+
./example | grep -E "^Compiler used: $1$"
1314

1415
# Remove the Conan dependencies.
1516
conan remove -c "*"

test/src/main.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,14 @@ int main(void) {
3030

3131
std::printf("ZLIB VERSION: %s\n", zlibVersion());
3232

33+
#ifdef __clang__
34+
constexpr char which[] = "clang";
35+
#elif __GNUC__
36+
constexpr char which[] = "gcc";
37+
#else
38+
constexpr char which[] = "unknown";
39+
#endif
40+
std::printf("Compiler used: %s\n", which);
41+
3342
return EXIT_SUCCESS;
3443
}

0 commit comments

Comments
 (0)