Skip to content

Commit d9d1fb7

Browse files
authored
Merge pull request #79 from codecrafters-io/CC-1222-cpp-upgrade
CC-1222: update cpp version, and add vcpkg support for dependency resolution
2 parents b002802 + e6185e7 commit d9d1fb7

20 files changed

+140
-24
lines changed

compiled_starters/cpp/.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,7 @@ cmake_install.cmake
4343
install_manifest.txt
4444
compile_commands.json
4545
CTestTestfile.cmake
46-
_deps
46+
_deps
47+
48+
build/
49+
vcpkg_installed

compiled_starters/cpp/CMakeLists.txt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
cmake_minimum_required(VERSION 3.13)
2+
23
project(grep-starter-cpp)
3-
set(CMAKE_CXX_STANDARD 20) # Enable the C++20 standard
44

5-
file(GLOB_RECURSE SOURCE_FILES src/*.cpp)
5+
set(CMAKE_CXX_STANDARD 23) # Enable the C++23 standard
6+
7+
file(GLOB_RECURSE SOURCE_FILES src/*.cpp src/*.hpp)
68

79
add_executable(server ${SOURCE_FILES})

compiled_starters/cpp/codecrafters.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@ debug: false
77
# Use this to change the C++ version used to run your code
88
# on Codecrafters.
99
#
10-
# Available versions: cpp-20
11-
language_pack: cpp-20
10+
# Available versions: cpp-23
11+
language_pack: cpp-23
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"default-registry": {
3+
"kind": "git",
4+
"baseline": "c4af3593e1f1aa9e14a560a09e45ea2cb0dfd74d",
5+
"repository": "https://github.com/microsoft/vcpkg"
6+
},
7+
"registries": [
8+
{
9+
"kind": "artifact",
10+
"location": "https://github.com/microsoft/vcpkg-ce-catalog/archive/refs/heads/main.zip",
11+
"name": "microsoft"
12+
}
13+
]
14+
}

compiled_starters/cpp/vcpkg.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"dependencies": []
3+
}

compiled_starters/cpp/your_grep.sh

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#
77
# DON'T EDIT THIS!
88
set -e
9-
cmake $(dirname $0) > /dev/null
10-
make > /dev/null
11-
exec ./server "$@"
9+
# vcpkg & cmake are required.
10+
cmake -B build -S . -DCMAKE_TOOLCHAIN_FILE=${VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake
11+
cmake --build ./build
12+
exec ./build/server "$@"

dockerfiles/cpp-23.Dockerfile

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# syntax=docker/dockerfile:1.7-labs
2+
FROM gcc:13.2.0-bookworm
3+
4+
ENV CODECRAFTERS_DEPENDENCY_FILE_PATHS="vcpkg.json,vcpkg-configuration.json"
5+
6+
RUN apt-get update && \
7+
apt-get install --no-install-recommends -y zip=3.* && \
8+
apt-get install --no-install-recommends -y g++=4:* && \
9+
apt-get install --no-install-recommends -y build-essential=12.* && \
10+
apt-get clean && \
11+
rm -rf /var/lib/apt/lists/*
12+
13+
# cmake 3.29.2 is required by vcpkg
14+
RUN wget --progress=dot:giga https://github.com/Kitware/CMake/releases/download/v3.29.2/cmake-3.29.2-Linux-x86_64.tar.gz && \
15+
tar -xzvf cmake-3.29.2-Linux-x86_64.tar.gz && \
16+
mv cmake-3.29.2-linux-x86_64/ /cmake
17+
18+
ENV CMAKE_BIN="/cmake/bin"
19+
ENV PATH="${CMAKE_BIN}:$PATH"
20+
21+
RUN git clone https://github.com/microsoft/vcpkg.git && \
22+
./vcpkg/bootstrap-vcpkg.sh -disableMetrics
23+
24+
ENV VCPKG_ROOT="/vcpkg"
25+
ENV PATH="${VCPKG_ROOT}:$PATH"
26+
27+
WORKDIR /app
28+
29+
# .git & README.md are unique per-repository. We ignore them on first copy to prevent cache misses
30+
COPY --exclude=.git --exclude=README.md . /app
31+
32+
RUN vcpkg install --no-print-usage
33+
RUN sed -i '1s/^/set(VCPKG_INSTALL_OPTIONS --no-print-usage)\n/' ${VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake
34+
35+
RUN mkdir -p /app-cached/build
36+
RUN if [ -d "/app/build" ]; then mv /app/build /app-cached; fi
37+
RUN if [ -d "/app/vcpkg_installed" ]; then mv /app/vcpkg_installed /app-cached/build; fi
38+
39+
RUN echo "cd \${CODECRAFTERS_SUBMISSION_DIR} && cmake -B build -S . -DCMAKE_TOOLCHAIN_FILE=${VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake && cmake --build ./build && sed -i '/^cmake/ s/^/# /' ./your_grep.sh" > /codecrafters-precompile.sh
40+
RUN chmod +x /codecrafters-precompile.sh
41+
42+
# Once the heavy steps are done, we can copy all files back
43+
COPY . /app

solutions/cpp/01-cq2/code/.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,7 @@ cmake_install.cmake
4343
install_manifest.txt
4444
compile_commands.json
4545
CTestTestfile.cmake
46-
_deps
46+
_deps
47+
48+
build/
49+
vcpkg_installed
Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
cmake_minimum_required(VERSION 3.13)
2+
23
project(grep-starter-cpp)
3-
set(CMAKE_CXX_STANDARD 20) # Enable the C++20 standard
44

5-
file(GLOB_RECURSE SOURCE_FILES src/*.cpp)
5+
set(CMAKE_CXX_STANDARD 23) # Enable the C++23 standard
6+
7+
file(GLOB_RECURSE SOURCE_FILES src/*.cpp src/*.hpp)
68

79
add_executable(server ${SOURCE_FILES})

solutions/cpp/01-cq2/code/codecrafters.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@ debug: false
77
# Use this to change the C++ version used to run your code
88
# on Codecrafters.
99
#
10-
# Available versions: cpp-20
11-
language_pack: cpp-20
10+
# Available versions: cpp-23
11+
language_pack: cpp-23
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"default-registry": {
3+
"kind": "git",
4+
"baseline": "c4af3593e1f1aa9e14a560a09e45ea2cb0dfd74d",
5+
"repository": "https://github.com/microsoft/vcpkg"
6+
},
7+
"registries": [
8+
{
9+
"kind": "artifact",
10+
"location": "https://github.com/microsoft/vcpkg-ce-catalog/archive/refs/heads/main.zip",
11+
"name": "microsoft"
12+
}
13+
]
14+
}

solutions/cpp/01-cq2/code/vcpkg.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"dependencies": []
3+
}

solutions/cpp/01-cq2/code/your_grep.sh

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#
77
# DON'T EDIT THIS!
88
set -e
9-
cmake $(dirname $0) > /dev/null
10-
make > /dev/null
11-
exec ./server "$@"
9+
# vcpkg & cmake are required.
10+
cmake -B build -S . -DCMAKE_TOOLCHAIN_FILE=${VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake
11+
cmake --build ./build
12+
exec ./build/server "$@"

starter-repository-definitions.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,10 @@
118118
target: src/Server.cpp
119119
- source: starter_templates/cpp/CMakeLists.txt
120120
target: CMakeLists.txt
121+
- source: starter_templates/cpp/vcpkg.json
122+
target: vcpkg.json
123+
- source: starter_templates/cpp/vcpkg-configuration.json
124+
target: vcpkg-configuration.json
121125
- source: starter_templates/cpp/your_grep.sh
122126
target: your_grep.sh
123127
- source: starter_templates/.gitattributes

starter_templates/codecrafters.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,8 @@ language_pack: clojure-1.10.3
7272
language_pack: dotnet-8.0
7373
{{/language_is_csharp}}
7474
{{#language_is_cpp}}
75-
# Available versions: cpp-20
76-
language_pack: cpp-20
75+
# Available versions: cpp-23
76+
language_pack: cpp-23
7777
{{/language_is_cpp}}
7878
{{#language_is_typescript}}
7979
# Available versions: bun-1.1

starter_templates/cpp/.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,7 @@ cmake_install.cmake
4343
install_manifest.txt
4444
compile_commands.json
4545
CTestTestfile.cmake
46-
_deps
46+
_deps
47+
48+
build/
49+
vcpkg_installed

starter_templates/cpp/CMakeLists.txt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
cmake_minimum_required(VERSION 3.13)
2+
23
project(grep-starter-cpp)
3-
set(CMAKE_CXX_STANDARD 20) # Enable the C++20 standard
44

5-
file(GLOB_RECURSE SOURCE_FILES src/*.cpp)
5+
set(CMAKE_CXX_STANDARD 23) # Enable the C++23 standard
6+
7+
file(GLOB_RECURSE SOURCE_FILES src/*.cpp src/*.hpp)
68

79
add_executable(server ${SOURCE_FILES})
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"default-registry": {
3+
"kind": "git",
4+
"baseline": "c4af3593e1f1aa9e14a560a09e45ea2cb0dfd74d",
5+
"repository": "https://github.com/microsoft/vcpkg"
6+
},
7+
"registries": [
8+
{
9+
"kind": "artifact",
10+
"location": "https://github.com/microsoft/vcpkg-ce-catalog/archive/refs/heads/main.zip",
11+
"name": "microsoft"
12+
}
13+
]
14+
}

starter_templates/cpp/vcpkg.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"dependencies": []
3+
}

starter_templates/cpp/your_grep.sh

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#
77
# DON'T EDIT THIS!
88
set -e
9-
cmake $(dirname $0) > /dev/null
10-
make > /dev/null
11-
exec ./server "$@"
9+
# vcpkg & cmake are required.
10+
cmake -B build -S . -DCMAKE_TOOLCHAIN_FILE=${VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake
11+
cmake --build ./build
12+
exec ./build/server "$@"

0 commit comments

Comments
 (0)