Skip to content

Commit

Permalink
Merge pull request #345 from ydb-platform/add-devcontainer
Browse files Browse the repository at this point in the history
Add C++ development environment configuration with Docker and scripts
  • Loading branch information
polRk authored Nov 27, 2024
2 parents 67c902d + 1dc3385 commit 61ed7e1
Show file tree
Hide file tree
Showing 4 changed files with 121 additions and 0 deletions.
61 changes: 61 additions & 0 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
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 gdb 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/clangd clangd /usr/bin/clangd-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
8 changes: 8 additions & 0 deletions .devcontainer/configure.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/sh
WORKSPACE_FOLDER=$1

cd $1
mkdir -p build
git submodule update --init --recursive
ccache -o cache_dir=/root/.ccache
cmake --preset release-test-with-ccache-basedir -DCMAKE_EXPORT_COMPILE_COMMANDS=1
49 changes: 49 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// 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"
]
},
// Allows the container to use ptrace, which is useful for debugging.
"capAdd": [
"SYS_PTRACE"
],
// Disables seccomp, which can be necessary for some debugging tools to function correctly.
"securityOpt": [
"seccomp=unconfined"
],
// 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": "mkdir -p ${localEnv:HOME}/.ccache && 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",
"llvm-vs-code-extensions.vscode-clangd"
]
}
},
"mounts": [
"source=${localEnv:HOME}/.ccache,target=/root/.ccache,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 61ed7e1

Please sign in to comment.