Skip to content

Commit

Permalink
Add C++ development environment configuration with Docker and scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
polRk committed Nov 21, 2024
1 parent a2817be commit aa0af8f
Show file tree
Hide file tree
Showing 4 changed files with 109 additions and 0 deletions.
60 changes: 60 additions & 0 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
FROM --platform=linux/amd64 mcr.microsoft.com/devcontainers/cpp:1-ubuntu-22.04

# Install software-properties-common for add-apt-repository
RUN apt-get update && apt-get -y install software-properties-common

# Install C++ tools and libraries
RUN add-apt-repository ppa:ubuntu-toolchain-r/test && apt-get -y update && apt-get -y install \
git cmake ninja-build libidn11-dev ragel yasm protobuf-compiler \
protobuf-compiler-grpc libprotobuf-dev libgrpc++-dev libgrpc-dev libgrpc++1 libgrpc10 \
rapidjson-dev zlib1g-dev libxxhash-dev libzstd-dev libsnappy-dev libgtest-dev libgmock-dev \
libbz2-dev libdouble-conversion-dev libstdc++-13-dev liblz4-dev libssl-dev \
&& apt-get clean && rm -rf /var/lib/apt/lists/*

# Install LLVM
RUN wget https://apt.llvm.org/llvm.sh && \
chmod u+x llvm.sh && \
./llvm.sh 16

# Update alternatives to use clang-16 and clang++-16 by default
RUN update-alternatives --install /usr/bin/clang clang /usr/bin/clang-16 100 && \
update-alternatives --install /usr/bin/clang++ clang++ /usr/bin/clang++-16 100

# Install libiconv
ENV LIBICONV_VERSION=1.15
RUN wget https://ftp.gnu.org/pub/gnu/libiconv/libiconv-${LIBICONV_VERSION}.tar.gz && \
tar -xvzf libiconv-${LIBICONV_VERSION}.tar.gz && cd libiconv-${LIBICONV_VERSION} && \
./configure --prefix=/usr/local && \
make && \
make install

# Install base64
ENV BASE64_VERSION=0.5.2
RUN wget -O base64-${BASE64_VERSION}.tar.gz https://github.com/aklomp/base64/archive/refs/tags/v${BASE64_VERSION}.tar.gz && \
tar -xvzf base64-${BASE64_VERSION}.tar.gz && cd base64-${BASE64_VERSION} && \
mkdir build && cd build && \
cmake -DCMAKE_BUILD_TYPE=Release .. && \
cmake --build . --config Release --target install

# Install brotli
ENV BROTLI_VERSION=1.1.0
RUN wget -O brotli-${BROTLI_VERSION}.tar.gz https://github.com/google/brotli/archive/refs/tags/v${BROTLI_VERSION}.tar.gz && \
tar -xvzf brotli-${BROTLI_VERSION}.tar.gz && cd brotli-${BROTLI_VERSION} && \
mkdir build && cd build && \
cmake -DCMAKE_BUILD_TYPE=Release .. && \
cmake --build . --config Release --target install

# Install jwt-cpp
ENV JWT_CPP_VERSION=0.7.0
RUN wget -O jwt-cpp-${JWT_CPP_VERSION}.tar.gz https://github.com/Thalhammer/jwt-cpp/archive/refs/tags/v${JWT_CPP_VERSION}.tar.gz && \
tar -xvzf jwt-cpp-${JWT_CPP_VERSION}.tar.gz && cd jwt-cpp-${JWT_CPP_VERSION} && \
mkdir build && cd build && \
cmake -DCMAKE_BUILD_TYPE=Release .. && \
cmake --build . --config Release --target install

# Install ccache 4.8.1 or above
ENV CCACHE_VERSION=4.8.1
RUN wget https://github.com/ccache/ccache/releases/download/v${CCACHE_VERSION}/ccache-${CCACHE_VERSION}-linux-x86_64.tar.xz \
&& tar -xf ccache-${CCACHE_VERSION}-linux-x86_64.tar.xz \
&& cp ccache-${CCACHE_VERSION}-linux-x86_64/ccache /usr/local/bin/ \
&& rm -rf ccache-${CCACHE_VERSION}-linux-x86_64 ccache-${CCACHE_VERSION}-linux-x86_64.tar.xz
5 changes: 5 additions & 0 deletions .devcontainer/configure.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/sh
WORKSPACE_FOLDER=$1

cd $1
cmake --preset release
41 changes: 41 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// 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",
"options": [
"--platform",
"linux/amd64"
]
},
// Features to add to the dev container. More info: https://containers.dev/features.
"features": {
"ghcr.io/devcontainers/features/github-cli:1": {
"installDirectlyFromGitHubRelease": true,
"version": "latest"
}
},
// Use 'forwardPorts' to make a list of ports inside the container available locally.
"forwardPorts": [],
"initializeCommand": "cd \"${localWorkspaceFolder}\" && git config --local user.email \"$(git config user.email)\" && git config --local user.name \"$(git config user.name)\"",
// Use 'postCreateCommand' to run commands after the container is created.
"postCreateCommand": ".devcontainer/configure.sh ${containerWorkspaceFolder}",
// Configure tool-specific properties.
"customizations": {
"vscode": {
"extensions": [
"ms-vscode.cpptools",
"ms-vscode.cmake-tools",
"twxs.cmake",
"ms-vscode.cpptools-extension-pack"
]
}
},
"mounts": [
"source=${localEnv:HOME}/.ssh,target=/root/.ssh,type=bind,consistency=cached",
"source=${localEnv:HOME}/.skotty,target=/root/.skotty,type=bind,consistency=cached"
],
// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
"remoteUser": "root"
}
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,6 @@ llvm.sh

# User CMake presets
CMakeUserPresets.json

# Dev Containers
!.devcontainer/Dockerfile

0 comments on commit aa0af8f

Please sign in to comment.