From 8a64e38397ae2f63c3d4393dc7683e5cca5e2216 Mon Sep 17 00:00:00 2001 From: Ryan Gang Date: Wed, 5 Jun 2024 17:08:03 +0530 Subject: [PATCH 1/2] feat: update cpp version, and add vcpkg support for cpp deps --- compiled_starters/cpp/.gitignore | 5 ++- compiled_starters/cpp/CMakeLists.txt | 4 +- compiled_starters/cpp/codecrafters.yml | 4 +- .../cpp/vcpkg-configuration.json | 14 ++++++ compiled_starters/cpp/vcpkg.json | 3 ++ compiled_starters/cpp/your_grep.sh | 7 +-- dockerfiles/cpp-23.Dockerfile | 43 +++++++++++++++++++ solutions/cpp/01-cq2/code/.gitignore | 5 ++- solutions/cpp/01-cq2/code/CMakeLists.txt | 4 +- solutions/cpp/01-cq2/code/codecrafters.yml | 4 +- .../cpp/01-cq2/code/vcpkg-configuration.json | 14 ++++++ solutions/cpp/01-cq2/code/vcpkg.json | 3 ++ solutions/cpp/01-cq2/code/your_grep.sh | 7 +-- starter-repository-definitions.yml | 4 ++ starter_templates/codecrafters.yml | 4 +- starter_templates/cpp/.gitignore | 5 ++- starter_templates/cpp/CMakeLists.txt | 4 +- .../cpp/vcpkg-configuration.json | 14 ++++++ starter_templates/cpp/vcpkg.json | 3 ++ starter_templates/cpp/your_grep.sh | 7 +-- 20 files changed, 137 insertions(+), 21 deletions(-) create mode 100644 compiled_starters/cpp/vcpkg-configuration.json create mode 100644 compiled_starters/cpp/vcpkg.json create mode 100644 dockerfiles/cpp-23.Dockerfile create mode 100644 solutions/cpp/01-cq2/code/vcpkg-configuration.json create mode 100644 solutions/cpp/01-cq2/code/vcpkg.json create mode 100644 starter_templates/cpp/vcpkg-configuration.json create mode 100644 starter_templates/cpp/vcpkg.json diff --git a/compiled_starters/cpp/.gitignore b/compiled_starters/cpp/.gitignore index 1a127f2..d66be1c 100644 --- a/compiled_starters/cpp/.gitignore +++ b/compiled_starters/cpp/.gitignore @@ -43,4 +43,7 @@ cmake_install.cmake install_manifest.txt compile_commands.json CTestTestfile.cmake -_deps \ No newline at end of file +_deps + +build/ +vcpkg_installed \ No newline at end of file diff --git a/compiled_starters/cpp/CMakeLists.txt b/compiled_starters/cpp/CMakeLists.txt index 88f2647..4aa0c78 100755 --- a/compiled_starters/cpp/CMakeLists.txt +++ b/compiled_starters/cpp/CMakeLists.txt @@ -1,6 +1,8 @@ cmake_minimum_required(VERSION 3.13) + project(grep-starter-cpp) -set(CMAKE_CXX_STANDARD 20) # Enable the C++20 standard + +set(CMAKE_CXX_STANDARD 23) # Enable the C++23 standard file(GLOB_RECURSE SOURCE_FILES src/*.cpp) diff --git a/compiled_starters/cpp/codecrafters.yml b/compiled_starters/cpp/codecrafters.yml index 07ffa4e..ad26fa0 100644 --- a/compiled_starters/cpp/codecrafters.yml +++ b/compiled_starters/cpp/codecrafters.yml @@ -7,5 +7,5 @@ debug: false # Use this to change the C++ version used to run your code # on Codecrafters. # -# Available versions: cpp-20 -language_pack: cpp-20 +# Available versions: cpp-23 +language_pack: cpp-23 diff --git a/compiled_starters/cpp/vcpkg-configuration.json b/compiled_starters/cpp/vcpkg-configuration.json new file mode 100644 index 0000000..61d215f --- /dev/null +++ b/compiled_starters/cpp/vcpkg-configuration.json @@ -0,0 +1,14 @@ +{ + "default-registry": { + "kind": "git", + "baseline": "c4af3593e1f1aa9e14a560a09e45ea2cb0dfd74d", + "repository": "https://github.com/microsoft/vcpkg" + }, + "registries": [ + { + "kind": "artifact", + "location": "https://github.com/microsoft/vcpkg-ce-catalog/archive/refs/heads/main.zip", + "name": "microsoft" + } + ] +} \ No newline at end of file diff --git a/compiled_starters/cpp/vcpkg.json b/compiled_starters/cpp/vcpkg.json new file mode 100644 index 0000000..f55ce3f --- /dev/null +++ b/compiled_starters/cpp/vcpkg.json @@ -0,0 +1,3 @@ +{ + "dependencies": [] +} \ No newline at end of file diff --git a/compiled_starters/cpp/your_grep.sh b/compiled_starters/cpp/your_grep.sh index 1b2ec9a..4b8635d 100755 --- a/compiled_starters/cpp/your_grep.sh +++ b/compiled_starters/cpp/your_grep.sh @@ -6,6 +6,7 @@ # # DON'T EDIT THIS! set -e -cmake $(dirname $0) > /dev/null -make > /dev/null -exec ./server "$@" \ No newline at end of file +# vcpkg & cmake are required. +cmake -B build -S . -DCMAKE_TOOLCHAIN_FILE=${VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake +cmake --build ./build +exec ./build/server "$@" \ No newline at end of file diff --git a/dockerfiles/cpp-23.Dockerfile b/dockerfiles/cpp-23.Dockerfile new file mode 100644 index 0000000..0745cfa --- /dev/null +++ b/dockerfiles/cpp-23.Dockerfile @@ -0,0 +1,43 @@ +# syntax=docker/dockerfile:1.7-labs +FROM gcc:13.2.0-bookworm + +ENV CODECRAFTERS_DEPENDENCY_FILE_PATHS="vcpkg.json,vcpkg-configuration.json" + +RUN apt-get update && \ + apt-get install --no-install-recommends -y zip=3.* && \ + apt-get install --no-install-recommends -y g++=4:* && \ + apt-get install --no-install-recommends -y build-essential=12.* && \ + apt-get clean && \ + rm -rf /var/lib/apt/lists/* + +# cmake 3.29.2 is required by vcpkg +RUN wget --progress=dot:giga https://github.com/Kitware/CMake/releases/download/v3.29.2/cmake-3.29.2-Linux-x86_64.tar.gz && \ + tar -xzvf cmake-3.29.2-Linux-x86_64.tar.gz && \ + mv cmake-3.29.2-linux-x86_64/ /cmake + +ENV CMAKE_BIN="/cmake/bin" +ENV PATH="${CMAKE_BIN}:$PATH" + +RUN git clone https://github.com/microsoft/vcpkg.git && \ + ./vcpkg/bootstrap-vcpkg.sh -disableMetrics + +ENV VCPKG_ROOT="/vcpkg" +ENV PATH="${VCPKG_ROOT}:$PATH" + +WORKDIR /app + +# .git & README.md are unique per-repository. We ignore them on first copy to prevent cache misses +COPY --exclude=.git --exclude=README.md . /app + +RUN vcpkg install --no-print-usage +RUN sed -i '1s/^/set(VCPKG_INSTALL_OPTIONS --no-print-usage)\n/' ${VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake + +RUN mkdir -p /app-cached/build +RUN if [ -d "/app/build" ]; then mv /app/build /app-cached; fi +RUN if [ -d "/app/vcpkg_installed" ]; then mv /app/vcpkg_installed /app-cached/build; fi + +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 +RUN chmod +x /codecrafters-precompile.sh + +# Once the heavy steps are done, we can copy all files back +COPY . /app \ No newline at end of file diff --git a/solutions/cpp/01-cq2/code/.gitignore b/solutions/cpp/01-cq2/code/.gitignore index 1a127f2..d66be1c 100644 --- a/solutions/cpp/01-cq2/code/.gitignore +++ b/solutions/cpp/01-cq2/code/.gitignore @@ -43,4 +43,7 @@ cmake_install.cmake install_manifest.txt compile_commands.json CTestTestfile.cmake -_deps \ No newline at end of file +_deps + +build/ +vcpkg_installed \ No newline at end of file diff --git a/solutions/cpp/01-cq2/code/CMakeLists.txt b/solutions/cpp/01-cq2/code/CMakeLists.txt index 88f2647..4aa0c78 100755 --- a/solutions/cpp/01-cq2/code/CMakeLists.txt +++ b/solutions/cpp/01-cq2/code/CMakeLists.txt @@ -1,6 +1,8 @@ cmake_minimum_required(VERSION 3.13) + project(grep-starter-cpp) -set(CMAKE_CXX_STANDARD 20) # Enable the C++20 standard + +set(CMAKE_CXX_STANDARD 23) # Enable the C++23 standard file(GLOB_RECURSE SOURCE_FILES src/*.cpp) diff --git a/solutions/cpp/01-cq2/code/codecrafters.yml b/solutions/cpp/01-cq2/code/codecrafters.yml index 07ffa4e..ad26fa0 100644 --- a/solutions/cpp/01-cq2/code/codecrafters.yml +++ b/solutions/cpp/01-cq2/code/codecrafters.yml @@ -7,5 +7,5 @@ debug: false # Use this to change the C++ version used to run your code # on Codecrafters. # -# Available versions: cpp-20 -language_pack: cpp-20 +# Available versions: cpp-23 +language_pack: cpp-23 diff --git a/solutions/cpp/01-cq2/code/vcpkg-configuration.json b/solutions/cpp/01-cq2/code/vcpkg-configuration.json new file mode 100644 index 0000000..61d215f --- /dev/null +++ b/solutions/cpp/01-cq2/code/vcpkg-configuration.json @@ -0,0 +1,14 @@ +{ + "default-registry": { + "kind": "git", + "baseline": "c4af3593e1f1aa9e14a560a09e45ea2cb0dfd74d", + "repository": "https://github.com/microsoft/vcpkg" + }, + "registries": [ + { + "kind": "artifact", + "location": "https://github.com/microsoft/vcpkg-ce-catalog/archive/refs/heads/main.zip", + "name": "microsoft" + } + ] +} \ No newline at end of file diff --git a/solutions/cpp/01-cq2/code/vcpkg.json b/solutions/cpp/01-cq2/code/vcpkg.json new file mode 100644 index 0000000..f55ce3f --- /dev/null +++ b/solutions/cpp/01-cq2/code/vcpkg.json @@ -0,0 +1,3 @@ +{ + "dependencies": [] +} \ No newline at end of file diff --git a/solutions/cpp/01-cq2/code/your_grep.sh b/solutions/cpp/01-cq2/code/your_grep.sh index 1b2ec9a..4b8635d 100755 --- a/solutions/cpp/01-cq2/code/your_grep.sh +++ b/solutions/cpp/01-cq2/code/your_grep.sh @@ -6,6 +6,7 @@ # # DON'T EDIT THIS! set -e -cmake $(dirname $0) > /dev/null -make > /dev/null -exec ./server "$@" \ No newline at end of file +# vcpkg & cmake are required. +cmake -B build -S . -DCMAKE_TOOLCHAIN_FILE=${VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake +cmake --build ./build +exec ./build/server "$@" \ No newline at end of file diff --git a/starter-repository-definitions.yml b/starter-repository-definitions.yml index 037aacf..fae6a44 100644 --- a/starter-repository-definitions.yml +++ b/starter-repository-definitions.yml @@ -118,6 +118,10 @@ target: src/Server.cpp - source: starter_templates/cpp/CMakeLists.txt target: CMakeLists.txt + - source: starter_templates/cpp/vcpkg.json + target: vcpkg.json + - source: starter_templates/cpp/vcpkg-configuration.json + target: vcpkg-configuration.json - source: starter_templates/cpp/your_grep.sh target: your_grep.sh - source: starter_templates/.gitattributes diff --git a/starter_templates/codecrafters.yml b/starter_templates/codecrafters.yml index a182a87..60a2e13 100644 --- a/starter_templates/codecrafters.yml +++ b/starter_templates/codecrafters.yml @@ -72,8 +72,8 @@ language_pack: clojure-1.10.3 language_pack: dotnet-8.0 {{/language_is_csharp}} {{#language_is_cpp}} -# Available versions: cpp-20 -language_pack: cpp-20 +# Available versions: cpp-23 +language_pack: cpp-23 {{/language_is_cpp}} {{#language_is_typescript}} # Available versions: bun-1.1 diff --git a/starter_templates/cpp/.gitignore b/starter_templates/cpp/.gitignore index 1a127f2..d66be1c 100644 --- a/starter_templates/cpp/.gitignore +++ b/starter_templates/cpp/.gitignore @@ -43,4 +43,7 @@ cmake_install.cmake install_manifest.txt compile_commands.json CTestTestfile.cmake -_deps \ No newline at end of file +_deps + +build/ +vcpkg_installed \ No newline at end of file diff --git a/starter_templates/cpp/CMakeLists.txt b/starter_templates/cpp/CMakeLists.txt index 88f2647..4aa0c78 100755 --- a/starter_templates/cpp/CMakeLists.txt +++ b/starter_templates/cpp/CMakeLists.txt @@ -1,6 +1,8 @@ cmake_minimum_required(VERSION 3.13) + project(grep-starter-cpp) -set(CMAKE_CXX_STANDARD 20) # Enable the C++20 standard + +set(CMAKE_CXX_STANDARD 23) # Enable the C++23 standard file(GLOB_RECURSE SOURCE_FILES src/*.cpp) diff --git a/starter_templates/cpp/vcpkg-configuration.json b/starter_templates/cpp/vcpkg-configuration.json new file mode 100644 index 0000000..61d215f --- /dev/null +++ b/starter_templates/cpp/vcpkg-configuration.json @@ -0,0 +1,14 @@ +{ + "default-registry": { + "kind": "git", + "baseline": "c4af3593e1f1aa9e14a560a09e45ea2cb0dfd74d", + "repository": "https://github.com/microsoft/vcpkg" + }, + "registries": [ + { + "kind": "artifact", + "location": "https://github.com/microsoft/vcpkg-ce-catalog/archive/refs/heads/main.zip", + "name": "microsoft" + } + ] +} \ No newline at end of file diff --git a/starter_templates/cpp/vcpkg.json b/starter_templates/cpp/vcpkg.json new file mode 100644 index 0000000..f55ce3f --- /dev/null +++ b/starter_templates/cpp/vcpkg.json @@ -0,0 +1,3 @@ +{ + "dependencies": [] +} \ No newline at end of file diff --git a/starter_templates/cpp/your_grep.sh b/starter_templates/cpp/your_grep.sh index 1b2ec9a..4b8635d 100755 --- a/starter_templates/cpp/your_grep.sh +++ b/starter_templates/cpp/your_grep.sh @@ -6,6 +6,7 @@ # # DON'T EDIT THIS! set -e -cmake $(dirname $0) > /dev/null -make > /dev/null -exec ./server "$@" \ No newline at end of file +# vcpkg & cmake are required. +cmake -B build -S . -DCMAKE_TOOLCHAIN_FILE=${VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake +cmake --build ./build +exec ./build/server "$@" \ No newline at end of file From e6185e778737607493931058361358c8a170c1a9 Mon Sep 17 00:00:00 2001 From: Ryan Gang Date: Thu, 6 Jun 2024 19:54:36 +0530 Subject: [PATCH 2/2] feat: update CMakeLists.txt to include all header files too --- compiled_starters/cpp/CMakeLists.txt | 2 +- solutions/cpp/01-cq2/code/CMakeLists.txt | 2 +- starter_templates/cpp/CMakeLists.txt | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/compiled_starters/cpp/CMakeLists.txt b/compiled_starters/cpp/CMakeLists.txt index 4aa0c78..190fc63 100755 --- a/compiled_starters/cpp/CMakeLists.txt +++ b/compiled_starters/cpp/CMakeLists.txt @@ -4,6 +4,6 @@ project(grep-starter-cpp) set(CMAKE_CXX_STANDARD 23) # Enable the C++23 standard -file(GLOB_RECURSE SOURCE_FILES src/*.cpp) +file(GLOB_RECURSE SOURCE_FILES src/*.cpp src/*.hpp) add_executable(server ${SOURCE_FILES}) \ No newline at end of file diff --git a/solutions/cpp/01-cq2/code/CMakeLists.txt b/solutions/cpp/01-cq2/code/CMakeLists.txt index 4aa0c78..190fc63 100755 --- a/solutions/cpp/01-cq2/code/CMakeLists.txt +++ b/solutions/cpp/01-cq2/code/CMakeLists.txt @@ -4,6 +4,6 @@ project(grep-starter-cpp) set(CMAKE_CXX_STANDARD 23) # Enable the C++23 standard -file(GLOB_RECURSE SOURCE_FILES src/*.cpp) +file(GLOB_RECURSE SOURCE_FILES src/*.cpp src/*.hpp) add_executable(server ${SOURCE_FILES}) \ No newline at end of file diff --git a/starter_templates/cpp/CMakeLists.txt b/starter_templates/cpp/CMakeLists.txt index 4aa0c78..190fc63 100755 --- a/starter_templates/cpp/CMakeLists.txt +++ b/starter_templates/cpp/CMakeLists.txt @@ -4,6 +4,6 @@ project(grep-starter-cpp) set(CMAKE_CXX_STANDARD 23) # Enable the C++23 standard -file(GLOB_RECURSE SOURCE_FILES src/*.cpp) +file(GLOB_RECURSE SOURCE_FILES src/*.cpp src/*.hpp) add_executable(server ${SOURCE_FILES}) \ No newline at end of file