Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 22 additions & 12 deletions docker/debian/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,12 @@ ldconfig -v
dpkg-divert --divert /usr/bin/gcc.orig --rename /usr/bin/gcc
dpkg-divert --divert /usr/bin/g++.orig --rename /usr/bin/g++
dpkg-divert --divert /usr/bin/gfortran.orig --rename /usr/bin/gfortran
update-alternatives --install /usr/bin/cc cc /usr/local/bin/gcc 999
update-alternatives --install \
/usr/bin/gcc gcc /usr/local/bin/gcc 100 \
update-alternatives \
--install /usr/bin/cc cc /usr/local/bin/gcc 999
update-alternatives \
--install /usr/bin/c++ c++ /usr/local/bin/g++ 999
update-alternatives \
--install /usr/bin/gcc gcc /usr/local/bin/gcc 100 \
--slave /usr/bin/g++ g++ /usr/local/bin/g++ \
--slave /usr/bin/gcc-ar gcc-ar /usr/local/bin/gcc-ar \
--slave /usr/bin/gcc-nm gcc-nm /usr/local/bin/gcc-nm \
Expand All @@ -93,6 +96,7 @@ update-alternatives --install \
--slave /usr/bin/gcov-dump gcov-dump /usr/local/bin/gcov-dump \
--slave /usr/bin/lto-dump lto-dump /usr/local/bin/lto-dump
update-alternatives --auto cc
update-alternatives --auto c++
update-alternatives --auto gcc
EOF
# Set the compiler environment variables to point to the GCC binaries.
Expand Down Expand Up @@ -144,7 +148,7 @@ RUN conan profile show
# Test the image by compiling a simple C++ program.
RUN --mount=type=bind,source=test,target=/test,readonly <<EOF
cp -r /test test
cd test && ./run.sh
cd test && ./run.sh gcc
cd ..
rm -rf test
EOF
Expand All @@ -157,10 +161,12 @@ ARG DEBIAN_FRONTEND=noninteractive

# Install Clang. Use the LLVM apt repository to access the latest versions. We
# must repeat the DEBIAN_VERSION argument here, as it is not inherited from the
# base or source images.
# base or source images. Some build dependencies require GCC to be also available.
ARG DEBIAN_VERSION
ARG CLANG_VERSION
RUN <<EOF
apt-get update
apt-get install -y --no-install-recommends gcc g++
curl --no-progress-meter https://apt.llvm.org/llvm-snapshot.gpg.key | gpg --dearmor -o /etc/apt/keyrings/llvm.gpg
printf "%s\n%s\n" \
"deb [signed-by=/etc/apt/keyrings/llvm.gpg] https://apt.llvm.org/${DEBIAN_VERSION}/ llvm-toolchain-${DEBIAN_VERSION}-${CLANG_VERSION} main" \
Expand All @@ -169,13 +175,17 @@ apt-get update
apt-get install -t llvm-toolchain-${DEBIAN_VERSION}-${CLANG_VERSION} -y --no-install-recommends clang-${CLANG_VERSION} llvm-${CLANG_VERSION}
apt-get clean
rm -rf /var/lib/apt/lists/*
update-alternatives --install /usr/bin/cc cc /usr/bin/clang-${CLANG_VERSION} 999
update-alternatives --install \
/usr/bin/clang clang /usr/bin/clang-${CLANG_VERSION} 100 \
--slave /usr/bin/clang++ clang++ /usr/bin/clang++-${CLANG_VERSION}
update-alternatives --install \
/usr/bin/llvm-cov llvm-cov /usr/bin/llvm-cov-${CLANG_VERSION} 100
update-alternatives \
--install /usr/bin/cc cc /usr/bin/clang-${CLANG_VERSION} 999
update-alternatives \
--install /usr/bin/c++ c++ /usr/bin/clang++-${CLANG_VERSION} 999
update-alternatives \
--install /usr/bin/clang clang /usr/bin/clang-${CLANG_VERSION} 100 \
--slave /usr/bin/clang++ clang++ /usr/bin/clang++-${CLANG_VERSION}
update-alternatives \
--install /usr/bin/llvm-cov llvm-cov /usr/bin/llvm-cov-${CLANG_VERSION} 100
update-alternatives --auto cc
update-alternatives --auto c++
update-alternatives --auto clang
update-alternatives --auto llvm-cov
EOF
Expand Down Expand Up @@ -225,7 +235,7 @@ RUN conan profile show
# Test the image by compiling a simple C++ program.
RUN --mount=type=bind,source=test,target=/test,readonly <<EOF
cp -r /test test
cd test && ./run.sh
cd test && ./run.sh clang
cd ..
rm -rf test
EOF
33 changes: 21 additions & 12 deletions docker/rhel/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,19 @@ dnf remove -y gcc gcc-c++
dnf install -y --setopt=tsflags=nodocs gcc-toolset-${GCC_VERSION}-gcc gcc-toolset-${GCC_VERSION}-gcc-c++
dnf clean -y all
rm -rf /var/cache/dnf/*
update-alternatives --install /usr/bin/cc cc /opt/rh/gcc-toolset-${GCC_VERSION}/root/usr/bin/gcc 999
update-alternatives \
--install /usr/bin/gcc gcc /opt/rh/gcc-toolset-${GCC_VERSION}/root/usr/bin/gcc 100 \
--slave /usr/bin/g++ g++ /opt/rh/gcc-toolset-${GCC_VERSION}/root/usr/bin/g++ \
--slave /usr/bin/cpp cpp /opt/rh/gcc-toolset-${GCC_VERSION}/root/usr/bin/cpp \
--slave /usr/bin/gcov gcov /opt/rh/gcc-toolset-${GCC_VERSION}/root/usr/bin/gcov \
--slave /usr/bin/gcov-dump gcov-dump /opt/rh/gcc-toolset-${GCC_VERSION}/root/usr/bin/gcov-dump-${GCC_VERSION} \
--slave /usr/bin/gcov-tool gcov-tool /opt/rh/gcc-toolset-${GCC_VERSION}/root/usr/bin/gcov-tool-${GCC_VERSION}
--install /usr/bin/cc cc /opt/rh/gcc-toolset-${GCC_VERSION}/root/usr/bin/gcc 999
update-alternatives \
--install /usr/bin/c++ c++ /opt/rh/gcc-toolset-${GCC_VERSION}/root/usr/bin/g++ 999
update-alternatives \
--install /usr/bin/gcc gcc /opt/rh/gcc-toolset-${GCC_VERSION}/root/usr/bin/gcc 100 \
--slave /usr/bin/g++ g++ /opt/rh/gcc-toolset-${GCC_VERSION}/root/usr/bin/g++ \
--slave /usr/bin/cpp cpp /opt/rh/gcc-toolset-${GCC_VERSION}/root/usr/bin/cpp \
--slave /usr/bin/gcov gcov /opt/rh/gcc-toolset-${GCC_VERSION}/root/usr/bin/gcov \
--slave /usr/bin/gcov-dump gcov-dump /opt/rh/gcc-toolset-${GCC_VERSION}/root/usr/bin/gcov-dump-${GCC_VERSION} \
--slave /usr/bin/gcov-tool gcov-tool /opt/rh/gcc-toolset-${GCC_VERSION}/root/usr/bin/gcov-tool-${GCC_VERSION}
update-alternatives --auto cc
update-alternatives --auto c++
update-alternatives --auto gcc
EOF
# Set the compiler environment variables to point to the GCC binaries.
Expand Down Expand Up @@ -110,7 +114,7 @@ RUN conan profile show
# Test the image by compiling a simple C++ program.
RUN --mount=type=bind,source=test,target=/test,readonly <<EOF
cp -r /test test
cd test && ./run.sh
cd test && ./run.sh gcc
cd ..
rm -rf test
EOF
Expand All @@ -119,13 +123,18 @@ EOF
FROM base AS clang

# Install Clang. Note that in the RHEL UBIs, we cannot choose the Clang version
# to install and we get what is available.
# to install and we get what is available. Some build dependencies require GCC
# to be also available.
RUN <<EOF
dnf install -y --setopt=tsflags=nodocs clang llvm
dnf install -y --setopt=tsflags=nodocs clang llvm gcc gcc-c++
dnf clean -y all
rm -rf /var/cache/dnf/*
update-alternatives --install /usr/bin/cc cc /usr/bin/clang 999
update-alternatives \
--install /usr/bin/cc cc /usr/bin/clang 999
update-alternatives \
--install /usr/bin/c++ c++ /usr/bin/clang++ 999
update-alternatives --auto cc
update-alternatives --auto c++
EOF
# Set the compiler environment variables to point to the GCC binaries.
ENV CC=/usr/bin/clang
Expand Down Expand Up @@ -174,7 +183,7 @@ RUN conan profile show
# Test the image by compiling a simple C++ program.
RUN --mount=type=bind,source=test,target=/test,readonly <<EOF
cp -r /test test
cd test && ./run.sh
cd test && ./run.sh clang
cd ..
rm -rf test
EOF
50 changes: 30 additions & 20 deletions docker/ubuntu/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -67,19 +67,23 @@ ARG GCC_VERSION
RUN <<EOF
apt-get update
apt-get install -y --no-install-recommends \
gcc-${GCC_VERSION} \
g++-${GCC_VERSION} \
debhelper
gcc-${GCC_VERSION} \
g++-${GCC_VERSION} \
debhelper
apt-get clean
rm -rf /var/lib/apt/lists/*
update-alternatives --install /usr/bin/cc cc /usr/bin/gcc-${GCC_VERSION} 999
update-alternatives \
--install /usr/bin/gcc gcc /usr/bin/gcc-${GCC_VERSION} 100 \
--slave /usr/bin/g++ g++ /usr/bin/g++-${GCC_VERSION} \
--slave /usr/bin/gcov gcov /usr/bin/gcov-${GCC_VERSION} \
--slave /usr/bin/gcov-dump gcov-dump /usr/bin/gcov-dump-${GCC_VERSION} \
--slave /usr/bin/gcov-tool gcov-tool /usr/bin/gcov-tool-${GCC_VERSION}
--install /usr/bin/cc cc /usr/bin/gcc-${GCC_VERSION} 999
update-alternatives \
--install /usr/bin/c++ c++ /usr/bin/g++-${GCC_VERSION} 999
update-alternatives \
--install /usr/bin/gcc gcc /usr/bin/gcc-${GCC_VERSION} 100 \
--slave /usr/bin/g++ g++ /usr/bin/g++-${GCC_VERSION} \
--slave /usr/bin/gcov gcov /usr/bin/gcov-${GCC_VERSION} \
--slave /usr/bin/gcov-dump gcov-dump /usr/bin/gcov-dump-${GCC_VERSION} \
--slave /usr/bin/gcov-tool gcov-tool /usr/bin/gcov-tool-${GCC_VERSION}
update-alternatives --auto cc
update-alternatives --auto c++
update-alternatives --auto gcc
EOF
# Set the compiler environment variables to point to the GCC binaries.
Expand Down Expand Up @@ -128,7 +132,7 @@ RUN conan profile show
# Test the image by compiling a simple C++ program.
RUN --mount=type=bind,source=test,target=/test,readonly <<EOF
cp -r /test test
cd test && ./run.sh
cd test && ./run.sh gcc
cd ..
rm -rf test
EOF
Expand All @@ -139,22 +143,28 @@ FROM base AS clang
# This is not inherited from base image, ensure no manual interaction needed.
ARG DEBIAN_FRONTEND=noninteractive

# Install Clang.
# Install Clang. Some build dependencies require GCC to be also available.
ARG CLANG_VERSION
RUN <<EOF
apt-get update
apt-get install -y --no-install-recommends \
clang-${CLANG_VERSION} \
llvm-${CLANG_VERSION}
clang-${CLANG_VERSION} \
llvm-${CLANG_VERSION} \
gcc \
g++
apt-get clean
rm -rf /var/lib/apt/lists/*
update-alternatives --install /usr/bin/cc cc /usr/bin/clang-${CLANG_VERSION} 999
update-alternatives --install \
/usr/bin/clang clang /usr/bin/clang-${CLANG_VERSION} 100 \
--slave /usr/bin/clang++ clang++ /usr/bin/clang++-${CLANG_VERSION}
update-alternatives --install \
/usr/bin/llvm-cov llvm-cov /usr/bin/llvm-cov-${CLANG_VERSION} 100
update-alternatives \
--install /usr/bin/cc cc /usr/bin/clang-${CLANG_VERSION} 999
update-alternatives \
--install /usr/bin/c++ c++ /usr/bin/clang++-${CLANG_VERSION} 999
update-alternatives \
--install /usr/bin/clang clang /usr/bin/clang-${CLANG_VERSION} 100 \
--slave /usr/bin/clang++ clang++ /usr/bin/clang++-${CLANG_VERSION}
update-alternatives \
--install /usr/bin/llvm-cov llvm-cov /usr/bin/llvm-cov-${CLANG_VERSION} 100
update-alternatives --auto cc
update-alternatives --auto c++
update-alternatives --auto clang
update-alternatives --auto llvm-cov
EOF
Expand Down Expand Up @@ -204,7 +214,7 @@ RUN conan profile show
# Test the image by compiling a simple C++ program.
RUN --mount=type=bind,source=test,target=/test,readonly <<EOF
cp -r /test test
cd test && ./run.sh
cd test && ./run.sh clang
cd ..
rm -rf test
EOF
3 changes: 2 additions & 1 deletion test/run.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/bin/bash

set -ex
set -o pipefail

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

# Run the executable.
./example
./example | grep -E "^Compiler used: $1$"

# Remove the Conan dependencies.
conan remove -c "*"
Expand Down
9 changes: 9 additions & 0 deletions test/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,14 @@ int main(void) {

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

#ifdef __clang__
constexpr char which[] = "clang";
#elif __GNUC__
constexpr char which[] = "gcc";
#else
constexpr char which[] = "unknown";
#endif
std::printf("Compiler used: %s\n", which);

return EXIT_SUCCESS;
}