Skip to content

Commit c567b22

Browse files
authored
Create devcontainer and add .clang-format to simplify development (#509)
* Add .clang-format file This enables format-on-save to match the style in VSCode. Use "Google" style which matches `format.sh`. * Add GitHub devcontainer config This enables using things like GitHub Codespaces, which pre-configures a container with the proper dependencies so that it can build. I choose Ubuntu 21.04 as the base image, and needed to make one small modification over the README instructions: * Installed `libcurl4-openssl-dev` instead of `libcurl-dev` The files originate from the C++ devcontainer template, with minor modifications to install the dependency packages in `Dockerfile`.
1 parent db74a76 commit c567b22

File tree

4 files changed

+141
-0
lines changed

4 files changed

+141
-0
lines changed

.clang-format

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
---
2+
BasedOnStyle: Google
3+
---

.devcontainer/Dockerfile

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# See here for image contents: https://github.com/microsoft/vscode-dev-containers/tree/v0.224.3/containers/cpp/.devcontainer/base.Dockerfile
2+
3+
# [Choice] Debian / Ubuntu version (use Debian 11, Ubuntu 18.04/21.04 on local arm64/Apple Silicon): debian-11, debian-10, ubuntu-21.04, ubuntu-20.04, ubuntu-18.04
4+
ARG VARIANT="bullseye"
5+
FROM mcr.microsoft.com/vscode/devcontainers/cpp:0-${VARIANT}
6+
7+
ARG USERNAME=vscode
8+
9+
# [Optional] Install CMake version different from what base image has already installed.
10+
# CMake reinstall choices: none, 3.21.5, 3.22.2, or versions from https://cmake.org/download/
11+
ARG REINSTALL_CMAKE_VERSION_FROM_SOURCE="3.23.1"
12+
13+
# Use installed binaries from the system.
14+
# Do not download latest version of CMake and Ninja during vcpkg bootstrap!
15+
ENV VCPKG_FORCE_SYSTEM_BINARIES=1
16+
ENV VCPKG_USE_SYSTEM_BINARIES=1
17+
18+
# Optionally install the cmake for vcpkg
19+
COPY ./reinstall-cmake.sh /tmp/
20+
RUN if [ "${REINSTALL_CMAKE_VERSION_FROM_SOURCE}" != "none" ]; then \
21+
chmod +x /tmp/reinstall-cmake.sh && /tmp/reinstall-cmake.sh ${REINSTALL_CMAKE_VERSION_FROM_SOURCE}; \
22+
fi \
23+
&& rm -f /tmp/reinstall-cmake.sh
24+
25+
# Install dependencies.
26+
RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
27+
&& apt-get -y install --no-install-recommends \
28+
libboost-dev \
29+
libsodium-dev \
30+
libncurses5-dev \
31+
libprotobuf-dev \
32+
protobuf-compiler \
33+
libgflags-dev \
34+
libutempter-dev \
35+
build-essential \
36+
ninja-build \
37+
# Note that in Ubuntu 21.04, there is no libcurl-dev, use libcurl4-openssl-dev
38+
libcurl4-openssl-dev
39+
40+
#
41+
# Set up command history volume
42+
# See https://code.visualstudio.com/remote/advancedcontainers/persist-bash-history
43+
#
44+
RUN mkdir /commandhistory \
45+
&& chown -R $USERNAME /commandhistory

.devcontainer/devcontainer.json

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
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.224.3/containers/cpp
3+
{
4+
"name": "C++",
5+
"build": {
6+
"dockerfile": "Dockerfile",
7+
// Update 'VARIANT' to pick an Debian / Ubuntu OS version: debian-11, debian-10, debian-9, ubuntu-21.04, ubuntu-20.04, ubuntu-18.04
8+
// Use Debian 11, Debian 9, Ubuntu 18.04 or Ubuntu 21.04 on local arm64/Apple Silicon
9+
"args": { "VARIANT": "ubuntu-21.04" }
10+
},
11+
"runArgs": ["--cap-add=SYS_PTRACE", "--security-opt", "seccomp=unconfined"],
12+
13+
// Set *default* container specific settings.json values on container create.
14+
"settings": {},
15+
16+
// Add the IDs of extensions you want installed when the container is created.
17+
"extensions": [
18+
"ms-vscode.cpptools",
19+
"ms-vscode.cmake-tools"
20+
],
21+
22+
// Use 'forwardPorts' to make a list of ports inside the container available locally.
23+
// "forwardPorts": [],
24+
25+
// Use 'postCreateCommand' to run commands after the container is created.
26+
"postCreateCommand": "git submodule update --init --recursive",
27+
28+
// Comment out to connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root.
29+
"remoteUser": "vscode",
30+
31+
// For sharing shell history out of the container.
32+
"mounts": [
33+
"source=eternalterminal-history,target=/commandhistory,type=volume"
34+
]
35+
}

.devcontainer/reinstall-cmake.sh

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
#!/usr/bin/env bash
2+
#-------------------------------------------------------------------------------------------------------------
3+
# Copyright (c) Microsoft Corporation. All rights reserved.
4+
# Licensed under the MIT License. See https://go.microsoft.com/fwlink/?linkid=2090316 for license information.
5+
#-------------------------------------------------------------------------------------------------------------
6+
#
7+
set -e
8+
9+
CMAKE_VERSION=${1:-"none"}
10+
11+
if [ "${CMAKE_VERSION}" = "none" ]; then
12+
echo "No CMake version specified, skipping CMake reinstallation"
13+
exit 0
14+
fi
15+
16+
# Cleanup temporary directory and associated files when exiting the script.
17+
cleanup() {
18+
EXIT_CODE=$?
19+
set +e
20+
if [[ -n "${TMP_DIR}" ]]; then
21+
echo "Executing cleanup of tmp files"
22+
rm -Rf "${TMP_DIR}"
23+
fi
24+
exit $EXIT_CODE
25+
}
26+
trap cleanup EXIT
27+
28+
29+
echo "Installing CMake..."
30+
apt-get -y purge --auto-remove cmake
31+
mkdir -p /opt/cmake
32+
33+
architecture=$(dpkg --print-architecture)
34+
case "${architecture}" in
35+
arm64)
36+
ARCH=aarch64 ;;
37+
amd64)
38+
ARCH=x86_64 ;;
39+
*)
40+
echo "Unsupported architecture ${architecture}."
41+
exit 1
42+
;;
43+
esac
44+
45+
CMAKE_BINARY_NAME="cmake-${CMAKE_VERSION}-linux-${ARCH}.sh"
46+
CMAKE_CHECKSUM_NAME="cmake-${CMAKE_VERSION}-SHA-256.txt"
47+
TMP_DIR=$(mktemp -d -t cmake-XXXXXXXXXX)
48+
49+
echo "${TMP_DIR}"
50+
cd "${TMP_DIR}"
51+
52+
curl -sSL "https://github.com/Kitware/CMake/releases/download/v${CMAKE_VERSION}/${CMAKE_BINARY_NAME}" -O
53+
curl -sSL "https://github.com/Kitware/CMake/releases/download/v${CMAKE_VERSION}/${CMAKE_CHECKSUM_NAME}" -O
54+
55+
sha256sum -c --ignore-missing "${CMAKE_CHECKSUM_NAME}"
56+
sh "${TMP_DIR}/${CMAKE_BINARY_NAME}" --prefix=/opt/cmake --skip-license
57+
58+
ln -s /opt/cmake/bin/cmake /usr/local/bin/cmake

0 commit comments

Comments
 (0)