From 3e2d67ad6f00b9a88a633f30640c41703561d231 Mon Sep 17 00:00:00 2001 From: Mikael Lund Date: Mon, 27 Feb 2023 16:17:54 +0000 Subject: [PATCH] Add VSC dev container config files (#425) * Add devcontainer and update dockerfiles * Update documentation * Update VSC settings --- .devcontainer/Dockerfile | 18 ++++++++++ .devcontainer/devcontainer.json | 26 ++++++++++++++ .devcontainer/reinstall-cmake.sh | 58 ++++++++++++++++++++++++++++++++ .vscode/settings.json | 4 +++ docs/_docs/install.md | 17 ++++++++-- scripts/Dockerfile | 15 ++++----- scripts/environment.yml | 2 +- 7 files changed, 128 insertions(+), 12 deletions(-) create mode 100644 .devcontainer/Dockerfile create mode 100644 .devcontainer/devcontainer.json create mode 100644 .devcontainer/reinstall-cmake.sh create mode 100644 .vscode/settings.json diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile new file mode 100644 index 000000000..7691c4d51 --- /dev/null +++ b/.devcontainer/Dockerfile @@ -0,0 +1,18 @@ +FROM mcr.microsoft.com/devcontainers/cpp:0-ubuntu-22.04 + +ARG REINSTALL_CMAKE_VERSION_FROM_SOURCE="3.25.2" + +# Optionally install the cmake for vcpkg +COPY ./reinstall-cmake.sh /tmp/ + +RUN if [ "${REINSTALL_CMAKE_VERSION_FROM_SOURCE}" != "none" ]; then \ + chmod +x /tmp/reinstall-cmake.sh && /tmp/reinstall-cmake.sh ${REINSTALL_CMAKE_VERSION_FROM_SOURCE}; \ + fi \ + && rm -f /tmp/reinstall-cmake.sh + +# [Optional] Uncomment this section to install additional vcpkg ports. +# RUN su vscode -c "${VCPKG_ROOT}/vcpkg install " + +# [Optional] Uncomment this section to install additional packages. +# RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \ +# && apt-get -y install --no-install-recommends diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 000000000..c3e3d7d59 --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,26 @@ +// For format details, see https://aka.ms/devcontainer.json. For config options, see the +// README at: https://github.com/devcontainers/templates/tree/main/src/cpp +{ + "name": "C++", + "build": { + "dockerfile": "Dockerfile" + }, + "features": { + "ghcr.io/rocker-org/devcontainer-features/miniforge:1": {} + } + + // Features to add to the dev container. More info: https://containers.dev/features. + // "features": {}, + + // Use 'forwardPorts' to make a list of ports inside the container available locally. + // "forwardPorts": [], + + // Use 'postCreateCommand' to run commands after the container is created. + // "postCreateCommand": "gcc -v", + + // Configure tool-specific properties. + // "customizations": {}, + + // Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root. + // "remoteUser": "root" +} diff --git a/.devcontainer/reinstall-cmake.sh b/.devcontainer/reinstall-cmake.sh new file mode 100644 index 000000000..c83325383 --- /dev/null +++ b/.devcontainer/reinstall-cmake.sh @@ -0,0 +1,58 @@ +#!/usr/bin/env bash +#------------------------------------------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See https://go.microsoft.com/fwlink/?linkid=2090316 for license information. +#------------------------------------------------------------------------------------------------------------- +# +set -e + +CMAKE_VERSION=${1:-"none"} + +if [ "${CMAKE_VERSION}" = "none" ]; then + echo "No CMake version specified, skipping CMake reinstallation" + exit 0 +fi + +# Cleanup temporary directory and associated files when exiting the script. +cleanup() { + EXIT_CODE=$? + set +e + if [[ -n "${TMP_DIR}" ]]; then + echo "Executing cleanup of tmp files" + rm -Rf "${TMP_DIR}" + fi + exit $EXIT_CODE +} +trap cleanup EXIT + + +echo "Installing CMake..." +apt-get -y purge --auto-remove cmake +mkdir -p /opt/cmake + +architecture=$(dpkg --print-architecture) +case "${architecture}" in + arm64) + ARCH=aarch64 ;; + amd64) + ARCH=x86_64 ;; + *) + echo "Unsupported architecture ${architecture}." + exit 1 + ;; +esac + +CMAKE_BINARY_NAME="cmake-${CMAKE_VERSION}-linux-${ARCH}.sh" +CMAKE_CHECKSUM_NAME="cmake-${CMAKE_VERSION}-SHA-256.txt" +TMP_DIR=$(mktemp -d -t cmake-XXXXXXXXXX) + +echo "${TMP_DIR}" +cd "${TMP_DIR}" + +curl -sSL "https://github.com/Kitware/CMake/releases/download/v${CMAKE_VERSION}/${CMAKE_BINARY_NAME}" -O +curl -sSL "https://github.com/Kitware/CMake/releases/download/v${CMAKE_VERSION}/${CMAKE_CHECKSUM_NAME}" -O + +sha256sum -c --ignore-missing "${CMAKE_CHECKSUM_NAME}" +sh "${TMP_DIR}/${CMAKE_BINARY_NAME}" --prefix=/opt/cmake --skip-license + +ln -s /opt/cmake/bin/cmake /usr/local/bin/cmake diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 000000000..ef7ca21af --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,4 @@ +{ + "cmake.configureOnOpen": false, + "cmake.preferredGenerators": [ "Unix Makefiles" ] +} \ No newline at end of file diff --git a/docs/_docs/install.md b/docs/_docs/install.md index 3e5c8e9ad..ddcf0d023 100644 --- a/docs/_docs/install.md +++ b/docs/_docs/install.md @@ -45,6 +45,9 @@ alias faunus='docker exec --interactive -u 1000 faunuslab faunus' faunus < input.json # piping input to docker ~~~ +For development using VSC, we also provide a `devcontainer` configuration for setting +up a Linux development environment, see description below. + ## Build from source code @@ -166,10 +169,18 @@ where `{tbb-root}` is the installation directory of TBB, _e.g._ # Development -The development of Faunus is done mainly in Jetbrain's [CLion](https://www.jetbrains.com/clion) -(free academic license) but any other IDE or merely a text editor can be used. -We recommend to use tools that respect the provided `.clang-format` which will ease merging +We recommend to use an IDE or text editor that respect the provided `.clang-format` which will ease merging changes into the codebase, see below. +For Visual Studio Code (VSC) users, it is very easy to setup a development environment using Docker and +[Dev Containers](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-containers): + +~~~ bash +cd faunus +code . +~~~ + +(when asked, select "open in devcontainer", assuming you have Docker running) + ## Code Style diff --git a/scripts/Dockerfile b/scripts/Dockerfile index 8a6b04365..5778692e5 100644 --- a/scripts/Dockerfile +++ b/scripts/Dockerfile @@ -12,7 +12,7 @@ # - clone of mlund/chemistry-notebooks # ARG OWNER=jupyter -ARG BASE_CONTAINER=jupyter/scipy-notebook:lab-3.3.2 +ARG BASE_CONTAINER=jupyter/scipy-notebook:lab-3.6.1 FROM $BASE_CONTAINER LABEL maintainer="the faun" @@ -26,12 +26,10 @@ RUN apt-get update --yes && \ apt-get install --yes --no-install-recommends \ software-properties-common -RUN add-apt-repository -y ppa:ubuntu-toolchain-r/test && \ - apt-get update --yes && \ +RUN apt-get update --yes && \ apt-get install --yes --no-install-recommends \ - cmake \ - gcc-11 \ - g++-11 \ + gcc \ + g++ \ libopenmpi-dev openmpi-bin openmpi-common \ zlib1g-dev && \ apt autoremove --yes && \ @@ -39,6 +37,7 @@ RUN add-apt-repository -y ppa:ubuntu-toolchain-r/test && \ USER ${NB_UID} RUN mamba install --quiet --yes \ + 'cmake' \ 'jsonschema' \ 'jinja2' \ 'pypandoc' \ @@ -54,8 +53,8 @@ RUN git clone https://github.com/mlund/chemistry-notebooks.git USER root RUN git clone https://github.com/mlund/faunus.git && \ - export CXX=g++-11 && \ - export CC=gcc-11 && \ + export CXX=g++ && \ + export CC=gcc && \ cd faunus && \ cmake -DENABLE_PYTHON=on -DENABLE_OPENMP=on -DENABLE_MPI=on -DCMAKE_BUILD_TYPE=RelWithDebInfo -DPYBIND11_FINDPYTHON=on . && \ make faunus && \ diff --git a/scripts/environment.yml b/scripts/environment.yml index 2f74b5b3b..aef4cbaf1 100644 --- a/scripts/environment.yml +++ b/scripts/environment.yml @@ -10,7 +10,7 @@ channels: dependencies: - clangdev - libcxx - - cmake>=3.16 + - cmake>=3.25 - python=3 - pandoc=2 - pypandoc=1