Skip to content

Commit 5a35e28

Browse files
authored
Merge pull request #23 from StephanKa/feature/add-cpp-devcontainer
added VSCode devcontainer
2 parents 3670701 + 189ac4d commit 5a35e28

3 files changed

Lines changed: 179 additions & 0 deletions

File tree

.devcontainer/.dockerignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Build directories and binary files
2+
build/
3+
out/
4+
cmake-build-*/
5+
6+
# User spesific settings
7+
CMakeUserPresets.json

.devcontainer/Dockerfile

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
# [Choice] focal (20.04), jammy (22.04), lunar (23.04)
2+
ARG VARIANT="lunar"
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-[10, 11, 12, 13] and clang-[10, 11, 12, 13, 14, 15]
32+
# Earlier versions of clang will require significant modifications to the IWYU section
33+
ARG GCC_VER="13"
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="15"
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_project
118+
#WORKDIR /workspaces/cpp_project
119+
120+
CMD ["/bin/bash"]

.devcontainer/devcontainer.json

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
// For format details, see https://aka.ms/devcontainer.json. For config options, see the README at:
2+
// https://github.com/microsoft/vscode-dev-containers/tree/v0.205.2/containers/cpp
3+
{
4+
"name": "C++",
5+
"build": {
6+
"dockerfile": "Dockerfile",
7+
// Update 'VARIANT' to pick an Ubuntu OS version. Options: [focal, jammy, lunar]. Default: lunar
8+
// Update 'GCC_VER' to pick a gcc and g++ version. Options: [10, 11, 12, 13]. Default: 13
9+
// Update 'LLVM_VER' to pick clang version. Options: [10, 11, 12, 13, 14, 15]. Default: 15
10+
// Update 'USE_CLANG' to set clang as the default C and C++ compiler. Options: [1, null]. Default null
11+
// "args": {
12+
// "VARIANT": "focal",
13+
// "GCC_VER": "11",
14+
// "LLVM_VER": "13"
15+
// }
16+
},
17+
"runArgs": [
18+
"--cap-add=SYS_PTRACE",
19+
"--security-opt",
20+
"seccomp=unconfined"
21+
],
22+
// Set *default* container specific settings.json values on container create.
23+
"settings": {
24+
"cmake.configureOnOpen": true,
25+
"editor.formatOnSave": true
26+
},
27+
// Add the IDs of extensions you want installed when the container is created.
28+
"extensions": [
29+
"ms-vscode.cpptools",
30+
"ms-vscode.cmake-tools",
31+
"twxs.cmake",
32+
"ms-vscode.cpptools-themes",
33+
"cschlosser.doxdocgen",
34+
"eamodio.gitlens",
35+
"ms-python.python",
36+
"ms-python.vscode-pylance",
37+
"mutantdino.resourcemonitor"
38+
],
39+
// Use 'forwardPorts' to make a list of ports inside the container available locally.
40+
// "forwardPorts": [],
41+
// Use 'postCreateCommand' to run commands after the container is created.
42+
//"postCreateCommand": "uname -a",
43+
// Comment out connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root.
44+
//"remoteUser": "vscode",
45+
"workspaceMount": "source=${localWorkspaceFolder},target=/workspaces/${localWorkspaceFolderBasename},type=bind,consistency=delegated",
46+
"workspaceFolder": "/workspaces/${localWorkspaceFolderBasename}",
47+
"features": {
48+
"git": "latest",
49+
"git-lfs": "latest",
50+
"powershell": "latest"
51+
}
52+
}

0 commit comments

Comments
 (0)