Skip to content

Commit af45504

Browse files
committed
Pick the default gcc/g++ from distro
1 parent 4701b6b commit af45504

File tree

5 files changed

+27
-30
lines changed

5 files changed

+27
-30
lines changed

docker/debian/Dockerfile

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ RUN conan profile show
143143
# Test the image by compiling a simple C++ program.
144144
RUN --mount=type=bind,source=test,target=/test,readonly <<EOF
145145
cp -r /test test
146-
cd test && ./run.sh
146+
cd test && ./run.sh gcc
147147
cd ..
148148
rm -rf test
149149
EOF
@@ -154,19 +154,12 @@ FROM base AS clang
154154
# This is not inherited from base image, ensure no manual interaction needed.
155155
ARG DEBIAN_FRONTEND=noninteractive
156156

157-
# Some build dependencies require GCC to be available.
158-
COPY --from=gcc-src /usr/local/ /usr/local/
159-
COPY --from=gcc-src /etc/ld.so.conf.d/*.conf /etc/ld.so.conf.d/
157+
# Some build dependencies require GCC to be also available.
160158
RUN <<EOF
161-
ldconfig -v
162-
dpkg-divert --divert /usr/bin/gcc.orig --rename /usr/bin/gcc
163-
update-alternatives --install /usr/bin/gcc gcc /usr/local/bin/gcc 100
164-
update-alternatives --install \
165-
/usr/bin/gcc gcc /usr/local/bin/gcc 100 \
166-
--slave /usr/bin/g++ g++ /usr/local/bin/g++ \
167-
--slave /usr/bin/gcc-ar gcc-ar /usr/local/bin/gcc-ar \
168-
--slave /usr/bin/gcc-nm gcc-nm /usr/local/bin/gcc-nm \
169-
--slave /usr/bin/gcc-ranlib gcc-ranlib /usr/local/bin/gcc-ranlib
159+
apt-get update
160+
apt-get install -y --no-install-recommends gcc g++
161+
apt-get clean
162+
rm -rf /var/lib/apt/lists/*
170163
EOF
171164

172165
# Install Clang. Use the LLVM apt repository to access the latest versions. We
@@ -245,7 +238,7 @@ RUN conan profile show
245238
# Test the image by compiling a simple C++ program.
246239
RUN --mount=type=bind,source=test,target=/test,readonly <<EOF
247240
cp -r /test test
248-
cd test && ./run.sh
241+
cd test && ./run.sh clang
249242
cd ..
250243
rm -rf test
251244
EOF

docker/rhel/Dockerfile

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ RUN conan profile show
110110
# Test the image by compiling a simple C++ program.
111111
RUN --mount=type=bind,source=test,target=/test,readonly <<EOF
112112
cp -r /test test
113-
cd test && ./run.sh
113+
cd test && ./run.sh gcc
114114
cd ..
115115
rm -rf test
116116
EOF
@@ -119,9 +119,10 @@ EOF
119119
FROM base AS clang
120120

121121
# Install Clang. Note that in the RHEL UBIs, we cannot choose the Clang version
122-
# to install and we get what is available.
122+
# to install and we get what is available. Some build dependencies require GCC
123+
# to be also available.
123124
RUN <<EOF
124-
dnf install -y --setopt=tsflags=nodocs clang llvm
125+
dnf install -y --setopt=tsflags=nodocs clang llvm gcc gcc-c++
125126
dnf clean -y all
126127
rm -rf /var/cache/dnf/*
127128
update-alternatives --install /usr/bin/cc cc /usr/bin/clang 999
@@ -180,7 +181,7 @@ RUN conan profile show
180181
# Test the image by compiling a simple C++ program.
181182
RUN --mount=type=bind,source=test,target=/test,readonly <<EOF
182183
cp -r /test test
183-
cd test && ./run.sh
184+
cd test && ./run.sh clang
184185
cd ..
185186
rm -rf test
186187
EOF

docker/ubuntu/Dockerfile

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ RUN conan profile show
128128
# Test the image by compiling a simple C++ program.
129129
RUN --mount=type=bind,source=test,target=/test,readonly <<EOF
130130
cp -r /test test
131-
cd test && ./run.sh
131+
cd test && ./run.sh gcc
132132
cd ..
133133
rm -rf test
134134
EOF
@@ -139,19 +139,12 @@ FROM base AS clang
139139
# This is not inherited from base image, ensure no manual interaction needed.
140140
ARG DEBIAN_FRONTEND=noninteractive
141141

142-
# Some build dependencies require GCC to be available.
143-
ARG GCC_VERSION
142+
# Some build dependencies require GCC to be also available.
144143
RUN <<EOF
145144
apt-get update
146-
apt-get install -y --no-install-recommends \
147-
gcc-${GCC_VERSION} \
148-
g++-${GCC_VERSION} \
149-
debhelper
145+
apt-get install -y --no-install-recommends gcc g++
150146
apt-get clean
151147
rm -rf /var/lib/apt/lists/*
152-
update-alternatives \
153-
--install /usr/bin/gcc gcc /usr/bin/gcc-${GCC_VERSION} 100 \
154-
--slave /usr/bin/g++ g++ /usr/bin/g++-${GCC_VERSION}
155148
EOF
156149

157150
# Install Clang.
@@ -225,7 +218,7 @@ RUN conan profile show
225218
# Test the image by compiling a simple C++ program.
226219
RUN --mount=type=bind,source=test,target=/test,readonly <<EOF
227220
cp -r /test test
228-
cd test && ./run.sh
221+
cd test && ./run.sh clang
229222
cd ..
230223
rm -rf test
231224
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)