From d04b6d766168b3639315e0634eec3a481e6d5451 Mon Sep 17 00:00:00 2001 From: Andy Li <1450947+andy1li@users.noreply.github.com> Date: Thu, 24 Oct 2024 19:52:25 +0800 Subject: [PATCH] remote test --- compiled_starters/c/.codecrafters/compile.sh | 3 +- compiled_starters/c/.codecrafters/run.sh | 2 +- compiled_starters/c/CMakeLists.txt | 10 +++++ compiled_starters/c/codecrafters.yml | 4 +- compiled_starters/c/vcpkg-configuration.json | 14 ++++++ compiled_starters/c/vcpkg.json | 6 +++ compiled_starters/c/your_program.sh | 5 ++- dockerfiles/c-14.2.Dockerfile | 13 ------ dockerfiles/c-23.Dockerfile | 43 +++++++++++++++++++ .../c/01-ry8/code/.codecrafters/compile.sh | 3 +- solutions/c/01-ry8/code/.codecrafters/run.sh | 2 +- solutions/c/01-ry8/code/CMakeLists.txt | 10 +++++ solutions/c/01-ry8/code/codecrafters.yml | 4 +- .../c/01-ry8/code/vcpkg-configuration.json | 14 ++++++ solutions/c/01-ry8/code/vcpkg.json | 6 +++ solutions/c/01-ry8/code/your_program.sh | 5 ++- .../c/code/.codecrafters/compile.sh | 3 +- starter_templates/c/code/.codecrafters/run.sh | 2 +- starter_templates/c/code/CMakeLists.txt | 10 +++++ .../c/code/vcpkg-configuration.json | 14 ++++++ starter_templates/c/code/vcpkg.json | 6 +++ 21 files changed, 152 insertions(+), 27 deletions(-) create mode 100644 compiled_starters/c/CMakeLists.txt create mode 100644 compiled_starters/c/vcpkg-configuration.json create mode 100644 compiled_starters/c/vcpkg.json delete mode 100644 dockerfiles/c-14.2.Dockerfile create mode 100644 dockerfiles/c-23.Dockerfile create mode 100644 solutions/c/01-ry8/code/CMakeLists.txt create mode 100644 solutions/c/01-ry8/code/vcpkg-configuration.json create mode 100644 solutions/c/01-ry8/code/vcpkg.json create mode 100644 starter_templates/c/code/CMakeLists.txt create mode 100644 starter_templates/c/code/vcpkg-configuration.json create mode 100644 starter_templates/c/code/vcpkg.json diff --git a/compiled_starters/c/.codecrafters/compile.sh b/compiled_starters/c/.codecrafters/compile.sh index 7f237f6..9da226b 100755 --- a/compiled_starters/c/.codecrafters/compile.sh +++ b/compiled_starters/c/.codecrafters/compile.sh @@ -8,4 +8,5 @@ set -e # Exit on failure -gcc -o /tmp/codecrafters-build-interpreter-c app/*.c +cmake -B build -S . -DCMAKE_TOOLCHAIN_FILE=${VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake +cmake --build ./build diff --git a/compiled_starters/c/.codecrafters/run.sh b/compiled_starters/c/.codecrafters/run.sh index f52bdc0..13341c8 100755 --- a/compiled_starters/c/.codecrafters/run.sh +++ b/compiled_starters/c/.codecrafters/run.sh @@ -8,4 +8,4 @@ set -e # Exit on failure -exec /tmp/codecrafters-build-interpreter-c "$@" +exec ./build/redis "$@" diff --git a/compiled_starters/c/CMakeLists.txt b/compiled_starters/c/CMakeLists.txt new file mode 100644 index 0000000..72ae685 --- /dev/null +++ b/compiled_starters/c/CMakeLists.txt @@ -0,0 +1,10 @@ +cmake_minimum_required(VERSION 3.13) + +project(redis-starter-c) + +file(GLOB_RECURSE SOURCE_FILES app/*.c) + +set(CMAKE_C_STANDARD 23) # Enable the C23 standard +set(THREADS_PREFER_PTHREAD_FLAG ON) + +add_executable(redis ${SOURCE_FILES}) diff --git a/compiled_starters/c/codecrafters.yml b/compiled_starters/c/codecrafters.yml index 0a06ac0..51a9b70 100644 --- a/compiled_starters/c/codecrafters.yml +++ b/compiled_starters/c/codecrafters.yml @@ -7,5 +7,5 @@ debug: false # Use this to change the C version used to run your code # on Codecrafters. # -# Available versions: c-14.2 -language_pack: c-14.2 +# Available versions: c-23 +language_pack: c-23 diff --git a/compiled_starters/c/vcpkg-configuration.json b/compiled_starters/c/vcpkg-configuration.json new file mode 100644 index 0000000..16b40d6 --- /dev/null +++ b/compiled_starters/c/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" + } + ] +} diff --git a/compiled_starters/c/vcpkg.json b/compiled_starters/c/vcpkg.json new file mode 100644 index 0000000..c4ec5d2 --- /dev/null +++ b/compiled_starters/c/vcpkg.json @@ -0,0 +1,6 @@ +{ + "dependencies": [ + "asio", + "pthreads" + ] +} diff --git a/compiled_starters/c/your_program.sh b/compiled_starters/c/your_program.sh index 80e5830..ee04699 100755 --- a/compiled_starters/c/your_program.sh +++ b/compiled_starters/c/your_program.sh @@ -14,11 +14,12 @@ set -e # Exit early if any commands fail # - Edit .codecrafters/compile.sh to change how your program compiles remotely ( cd "$(dirname "$0")" # Ensure compile steps are run within the repository directory - gcc -o /tmp/codecrafters-build-interpreter-c app/*.c + cmake -B build -S . -DCMAKE_TOOLCHAIN_FILE=${VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake + cmake --build ./build ) # Copied from .codecrafters/run.sh # # - Edit this to change how your program runs locally # - Edit .codecrafters/run.sh to change how your program runs remotely -exec /tmp/codecrafters-build-interpreter-c "$@" +exec ./build/redis "$@" diff --git a/dockerfiles/c-14.2.Dockerfile b/dockerfiles/c-14.2.Dockerfile deleted file mode 100644 index aafcddd..0000000 --- a/dockerfiles/c-14.2.Dockerfile +++ /dev/null @@ -1,13 +0,0 @@ -# syntax=docker/dockerfile:1.7-labs -FROM gcc:14.2.0-bookworm - -# Ensures the container is re-built if dependency files change -# ENV CODECRAFTERS_DEPENDENCY_FILE_PATHS="" - -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 - -# Install language-specific dependencies -RUN .codecrafters/compile.sh diff --git a/dockerfiles/c-23.Dockerfile b/dockerfiles/c-23.Dockerfile new file mode 100644 index 0000000..c818edc --- /dev/null +++ b/dockerfiles/c-23.Dockerfile @@ -0,0 +1,43 @@ +# syntax=docker/dockerfile:1.7-labs +FROM gcc:14.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" + +# Ensures the container is re-built if dependency files change +# ENV CODECRAFTERS_DEPENDENCY_FILE_PATHS="" + +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 + +# Install language-specific dependencies +RUN .codecrafters/compile.sh \ No newline at end of file diff --git a/solutions/c/01-ry8/code/.codecrafters/compile.sh b/solutions/c/01-ry8/code/.codecrafters/compile.sh index 7f237f6..9da226b 100755 --- a/solutions/c/01-ry8/code/.codecrafters/compile.sh +++ b/solutions/c/01-ry8/code/.codecrafters/compile.sh @@ -8,4 +8,5 @@ set -e # Exit on failure -gcc -o /tmp/codecrafters-build-interpreter-c app/*.c +cmake -B build -S . -DCMAKE_TOOLCHAIN_FILE=${VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake +cmake --build ./build diff --git a/solutions/c/01-ry8/code/.codecrafters/run.sh b/solutions/c/01-ry8/code/.codecrafters/run.sh index f52bdc0..13341c8 100755 --- a/solutions/c/01-ry8/code/.codecrafters/run.sh +++ b/solutions/c/01-ry8/code/.codecrafters/run.sh @@ -8,4 +8,4 @@ set -e # Exit on failure -exec /tmp/codecrafters-build-interpreter-c "$@" +exec ./build/redis "$@" diff --git a/solutions/c/01-ry8/code/CMakeLists.txt b/solutions/c/01-ry8/code/CMakeLists.txt new file mode 100644 index 0000000..72ae685 --- /dev/null +++ b/solutions/c/01-ry8/code/CMakeLists.txt @@ -0,0 +1,10 @@ +cmake_minimum_required(VERSION 3.13) + +project(redis-starter-c) + +file(GLOB_RECURSE SOURCE_FILES app/*.c) + +set(CMAKE_C_STANDARD 23) # Enable the C23 standard +set(THREADS_PREFER_PTHREAD_FLAG ON) + +add_executable(redis ${SOURCE_FILES}) diff --git a/solutions/c/01-ry8/code/codecrafters.yml b/solutions/c/01-ry8/code/codecrafters.yml index 0a06ac0..51a9b70 100644 --- a/solutions/c/01-ry8/code/codecrafters.yml +++ b/solutions/c/01-ry8/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: c-14.2 -language_pack: c-14.2 +# Available versions: c-23 +language_pack: c-23 diff --git a/solutions/c/01-ry8/code/vcpkg-configuration.json b/solutions/c/01-ry8/code/vcpkg-configuration.json new file mode 100644 index 0000000..16b40d6 --- /dev/null +++ b/solutions/c/01-ry8/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" + } + ] +} diff --git a/solutions/c/01-ry8/code/vcpkg.json b/solutions/c/01-ry8/code/vcpkg.json new file mode 100644 index 0000000..c4ec5d2 --- /dev/null +++ b/solutions/c/01-ry8/code/vcpkg.json @@ -0,0 +1,6 @@ +{ + "dependencies": [ + "asio", + "pthreads" + ] +} diff --git a/solutions/c/01-ry8/code/your_program.sh b/solutions/c/01-ry8/code/your_program.sh index 80e5830..ee04699 100755 --- a/solutions/c/01-ry8/code/your_program.sh +++ b/solutions/c/01-ry8/code/your_program.sh @@ -14,11 +14,12 @@ set -e # Exit early if any commands fail # - Edit .codecrafters/compile.sh to change how your program compiles remotely ( cd "$(dirname "$0")" # Ensure compile steps are run within the repository directory - gcc -o /tmp/codecrafters-build-interpreter-c app/*.c + cmake -B build -S . -DCMAKE_TOOLCHAIN_FILE=${VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake + cmake --build ./build ) # Copied from .codecrafters/run.sh # # - Edit this to change how your program runs locally # - Edit .codecrafters/run.sh to change how your program runs remotely -exec /tmp/codecrafters-build-interpreter-c "$@" +exec ./build/redis "$@" diff --git a/starter_templates/c/code/.codecrafters/compile.sh b/starter_templates/c/code/.codecrafters/compile.sh index 7f237f6..9da226b 100755 --- a/starter_templates/c/code/.codecrafters/compile.sh +++ b/starter_templates/c/code/.codecrafters/compile.sh @@ -8,4 +8,5 @@ set -e # Exit on failure -gcc -o /tmp/codecrafters-build-interpreter-c app/*.c +cmake -B build -S . -DCMAKE_TOOLCHAIN_FILE=${VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake +cmake --build ./build diff --git a/starter_templates/c/code/.codecrafters/run.sh b/starter_templates/c/code/.codecrafters/run.sh index f52bdc0..13341c8 100755 --- a/starter_templates/c/code/.codecrafters/run.sh +++ b/starter_templates/c/code/.codecrafters/run.sh @@ -8,4 +8,4 @@ set -e # Exit on failure -exec /tmp/codecrafters-build-interpreter-c "$@" +exec ./build/redis "$@" diff --git a/starter_templates/c/code/CMakeLists.txt b/starter_templates/c/code/CMakeLists.txt new file mode 100644 index 0000000..72ae685 --- /dev/null +++ b/starter_templates/c/code/CMakeLists.txt @@ -0,0 +1,10 @@ +cmake_minimum_required(VERSION 3.13) + +project(redis-starter-c) + +file(GLOB_RECURSE SOURCE_FILES app/*.c) + +set(CMAKE_C_STANDARD 23) # Enable the C23 standard +set(THREADS_PREFER_PTHREAD_FLAG ON) + +add_executable(redis ${SOURCE_FILES}) diff --git a/starter_templates/c/code/vcpkg-configuration.json b/starter_templates/c/code/vcpkg-configuration.json new file mode 100644 index 0000000..16b40d6 --- /dev/null +++ b/starter_templates/c/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" + } + ] +} diff --git a/starter_templates/c/code/vcpkg.json b/starter_templates/c/code/vcpkg.json new file mode 100644 index 0000000..c4ec5d2 --- /dev/null +++ b/starter_templates/c/code/vcpkg.json @@ -0,0 +1,6 @@ +{ + "dependencies": [ + "asio", + "pthreads" + ] +}