|
| 1 | +# [Choice] bionic (18.04), focal (20.04) |
| 2 | +ARG VARIANT="focal" |
| 3 | +FROM ubuntu:${VARIANT} |
| 4 | + |
| 5 | +# Restate the variant to use it later on in the llvm and cmake installations |
| 6 | +ARG VARIANT |
| 7 | + |
| 8 | +# Install necessary packages available from standard repos |
| 9 | +RUN apt-get update -qq && export DEBIAN_FRONTEND=noninteractive && \ |
| 10 | + apt-get install -y --no-install-recommends \ |
| 11 | + software-properties-common wget apt-utils file zip \ |
| 12 | + openssh-client gpg-agent socat rsync \ |
| 13 | + make ninja-build git \ |
| 14 | + python3 python3-pip |
| 15 | + |
| 16 | +# Install conan |
| 17 | +RUN python3 -m pip install --upgrade pip setuptools && \ |
| 18 | + python3 -m pip install conan && \ |
| 19 | + conan --version |
| 20 | + |
| 21 | +# By default, anything you run in Docker is done as superuser. |
| 22 | +# Conan runs some install commands as superuser, and will prepend `sudo` to |
| 23 | +# these commands, unless `CONAN_SYSREQUIRES_SUDO=0` is in your env variables. |
| 24 | +ENV CONAN_SYSREQUIRES_SUDO 0 |
| 25 | +# Some packages request that Conan use the system package manager to install |
| 26 | +# a few dependencies. This flag allows Conan to proceed with these installations; |
| 27 | +# leaving this flag undefined can cause some installation failures. |
| 28 | +ENV CONAN_SYSREQUIRES_MODE enabled |
| 29 | + |
| 30 | +# User-settable versions: |
| 31 | +# This Dockerfile should support gcc-[7, 8, 9, 10, 11] and clang-[10, 11, 12, 13] |
| 32 | +# Earlier versions of clang will require significant modifications to the IWYU section |
| 33 | +ARG GCC_VER="11" |
| 34 | +# Add gcc-${GCC_VER} |
| 35 | +RUN add-apt-repository -y ppa:ubuntu-toolchain-r/test && \ |
| 36 | + apt-get update -qq && export DEBIAN_FRONTEND=noninteractive && \ |
| 37 | + apt-get install -y --no-install-recommends \ |
| 38 | + gcc-${GCC_VER} g++-${GCC_VER} gdb |
| 39 | + |
| 40 | +# Set gcc-${GCC_VER} as default gcc |
| 41 | +RUN update-alternatives --install /usr/bin/gcc gcc $(which gcc-${GCC_VER}) 100 |
| 42 | +RUN update-alternatives --install /usr/bin/g++ g++ $(which g++-${GCC_VER}) 100 |
| 43 | + |
| 44 | +ARG LLVM_VER="13" |
| 45 | +# Add clang-${LLVM_VER} |
| 46 | +ARG LLVM_URL="http://apt.llvm.org/${VARIANT}/" |
| 47 | +ARG LLVM_PKG="llvm-toolchain-${VARIANT}-${LLVM_VER}" |
| 48 | +RUN wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | apt-key add - 2>/dev/null && \ |
| 49 | + add-apt-repository -y "deb ${LLVM_URL} ${LLVM_PKG} main" && \ |
| 50 | + apt-get update -qq && export DEBIAN_FRONTEND=noninteractive && \ |
| 51 | + apt-get install -y --no-install-recommends \ |
| 52 | + clang-${LLVM_VER} lldb-${LLVM_VER} lld-${LLVM_VER} clangd-${LLVM_VER} \ |
| 53 | + llvm-${LLVM_VER}-dev libclang-${LLVM_VER}-dev clang-tidy-${LLVM_VER} |
| 54 | + |
| 55 | +# Set the default clang-tidy, so CMake can find it |
| 56 | +RUN update-alternatives --install /usr/bin/clang-tidy clang-tidy $(which clang-tidy-${LLVM_VER}) 1 |
| 57 | + |
| 58 | +# Set clang-${LLVM_VER} as default clang |
| 59 | +RUN update-alternatives --install /usr/bin/clang clang $(which clang-${LLVM_VER}) 100 |
| 60 | +RUN update-alternatives --install /usr/bin/clang++ clang++ $(which clang++-${LLVM_VER}) 100 |
| 61 | + |
| 62 | +# Add current cmake/ccmake, from Kitware |
| 63 | +ARG CMAKE_URL="https://apt.kitware.com/ubuntu/" |
| 64 | +ARG CMAKE_PKG=${VARIANT} |
| 65 | +RUN wget -O - https://apt.kitware.com/keys/kitware-archive-latest.asc 2>/dev/null \ |
| 66 | + | gpg --dearmor - | tee /etc/apt/trusted.gpg.d/kitware.gpg >/dev/null && \ |
| 67 | + apt-add-repository -y "deb ${CMAKE_URL} ${CMAKE_PKG} main" && \ |
| 68 | + apt-get update -qq && export DEBIAN_FRONTEND=noninteractive && \ |
| 69 | + apt-get install -y --no-install-recommends cmake cmake-curses-gui |
| 70 | + |
| 71 | +# Install editors |
| 72 | +RUN apt-get update -qq && export DEBIAN_FRONTEND=noninteractive && \ |
| 73 | + apt-get install -y --no-install-recommends \ |
| 74 | + neovim emacs nano |
| 75 | + |
| 76 | +# Install optional dependecies |
| 77 | +RUN apt-get update -qq && export DEBIAN_FRONTEND=noninteractive && \ |
| 78 | + apt-get install -y --no-install-recommends \ |
| 79 | + doxygen graphviz ccache cppcheck |
| 80 | + |
| 81 | +# Install include-what-you-use |
| 82 | +ENV IWYU /home/iwyu |
| 83 | +ENV IWYU_BUILD ${IWYU}/build |
| 84 | +ENV IWYU_SRC ${IWYU}/include-what-you-use |
| 85 | +RUN mkdir -p ${IWYU_BUILD} && \ |
| 86 | + git clone --branch clang_${LLVM_VER} \ |
| 87 | + https://github.com/include-what-you-use/include-what-you-use.git \ |
| 88 | + ${IWYU_SRC} |
| 89 | +RUN CC=clang-${LLVM_VER} CXX=clang++-${LLVM_VER} cmake -S ${IWYU_SRC} \ |
| 90 | + -B ${IWYU_BUILD} \ |
| 91 | + -G "Unix Makefiles" -DCMAKE_PREFIX_PATH=/usr/lib/llvm-${LLVM_VER} && \ |
| 92 | + cmake --build ${IWYU_BUILD} -j && \ |
| 93 | + cmake --install ${IWYU_BUILD} |
| 94 | + |
| 95 | +# Per https://github.com/include-what-you-use/include-what-you-use#how-to-install: |
| 96 | +# `You need to copy the Clang include directory to the expected location before |
| 97 | +# running (similarly, use include-what-you-use -print-resource-dir to learn |
| 98 | +# exactly where IWYU wants the headers).` |
| 99 | +RUN mkdir -p $(include-what-you-use -print-resource-dir 2>/dev/null) |
| 100 | +RUN ln -s $(readlink -f /usr/lib/clang/${LLVM_VER}/include) \ |
| 101 | + $(include-what-you-use -print-resource-dir 2>/dev/null)/include |
| 102 | + |
| 103 | +## Cleanup cached apt data we don't need anymore |
| 104 | +RUN apt-get autoremove -y && apt-get clean && \ |
| 105 | + rm -rf /var/lib/apt/lists/* |
| 106 | + |
| 107 | +# Allow the user to set compiler defaults |
| 108 | +ARG USE_CLANG |
| 109 | +# if --build-arg USE_CLANG=1, set CC to 'clang' or set to null otherwise. |
| 110 | +ENV CC=${USE_CLANG:+"clang"} |
| 111 | +ENV CXX=${USE_CLANG:+"clang++"} |
| 112 | +# if CC is null, set it to 'gcc' (or leave as is otherwise). |
| 113 | +ENV CC=${CC:-"gcc"} |
| 114 | +ENV CXX=${CXX:-"g++"} |
| 115 | + |
| 116 | +# Include project |
| 117 | +#ADD . /workspaces/cpp_starter_project |
| 118 | +#WORKDIR /workspaces/cpp_starter_project |
| 119 | + |
| 120 | +CMD ["/bin/bash"] |
0 commit comments