Skip to content

Commit

Permalink
Merge pull request #288 from codecrafters-io/andy/upgrade
Browse files Browse the repository at this point in the history
[Redis] CC-1594: Move away from alpine based buildpacks to debian based ones for C
  • Loading branch information
andy1li authored Feb 20, 2025
2 parents 2b0cd32 + 6e5c3b7 commit e9f515e
Show file tree
Hide file tree
Showing 31 changed files with 309 additions and 23 deletions.
3 changes: 2 additions & 1 deletion compiled_starters/c/.codecrafters/compile.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@

set -e # Exit on failure

gcc -o /tmp/codecrafters-build-redis-c app/*.c
cmake -B build -S . -DCMAKE_TOOLCHAIN_FILE=${VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake
cmake --build ./build
2 changes: 1 addition & 1 deletion compiled_starters/c/.codecrafters/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@

set -e # Exit on failure

exec /tmp/codecrafters-build-redis-c "$@"
exec $(dirname $0)/build/redis "$@"
55 changes: 55 additions & 0 deletions compiled_starters/c/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# Prerequisites
*.d

# Object files
*.o
*.ko
*.obj
*.elf

# Linker output
*.ilk
*.map
*.exp

# Precompiled Headers
*.gch
*.pch

# Libraries
*.lib
*.a
*.la
*.lo

# Shared objects (inc. Windows DLLs)
*.dll
*.so
*.so.*
*.dylib

# Executables
*.exe
*.out
*.app
*.i*86
*.x86_64
*.hex

# Debug files
*.dSYM/
*.su
*.idb
*.pdb

# Kernel Module Compile Results
*.mod*
*.cmd
.tmp_versions/
modules.order
Module.symvers
Mkfile.old
dkms.conf

build
vcpkg_installed
9 changes: 9 additions & 0 deletions compiled_starters/c/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
cmake_minimum_required(VERSION 3.13)

project(codecrafters-redis)

file(GLOB_RECURSE SOURCE_FILES src/*.c src/*.h)

set(CMAKE_C_STANDARD 23) # Enable the C23 standard

add_executable(redis ${SOURCE_FILES})
6 changes: 3 additions & 3 deletions compiled_starters/c/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ event loops, the Redis protocol and more.

# Passing the first stage

The entry point for your Redis implementation is in `app/server.c`. Study and
The entry point for your Redis implementation is in `src/main.c`. Study and
uncomment the relevant code, and push your changes to pass the first stage:

```sh
Expand All @@ -26,8 +26,8 @@ That's all!

Note: This section is for stages 2 and beyond.

1. Ensure you have `gcc` installed locally
1. Ensure you have `cmake` installed locally
1. Run `./your_program.sh` to run your Redis server, which is implemented in
`app/server.c`.
`src/main.c`.
1. Commit your changes and run `git push origin master` to submit your solution
to CodeCrafters. Test output will be streamed to your terminal.
4 changes: 2 additions & 2 deletions compiled_starters/c/codecrafters.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ debug: false
# Use this to change the C version used to run your code
# on Codecrafters.
#
# Available versions: c-9.2
language_pack: c-9.2
# Available versions: c-23
language_pack: c-23
File renamed without changes.
14 changes: 14 additions & 0 deletions compiled_starters/c/vcpkg-configuration.json
Original file line number Diff line number Diff line change
@@ -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"
}
]
}
3 changes: 3 additions & 0 deletions compiled_starters/c/vcpkg.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"dependencies": []
}
5 changes: 3 additions & 2 deletions compiled_starters/c/your_program.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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-redis-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-redis-c "$@"
exec $(dirname $0)/build/redis "$@"
38 changes: 38 additions & 0 deletions dockerfiles/c-23.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# 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="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 is required by vcpkg
RUN wget --progress=dot:giga https://github.com/Kitware/CMake/releases/download/v3.30.5/cmake-3.30.5-Linux-x86_64.tar.gz && \
tar -xzvf cmake-3.30.5-Linux-x86_64.tar.gz && \
mv cmake-3.30.5-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
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; fi
3 changes: 2 additions & 1 deletion solutions/c/01-jm1/code/.codecrafters/compile.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@

set -e # Exit on failure

gcc -o /tmp/codecrafters-build-redis-c app/*.c
cmake -B build -S . -DCMAKE_TOOLCHAIN_FILE=${VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake
cmake --build ./build
2 changes: 1 addition & 1 deletion solutions/c/01-jm1/code/.codecrafters/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@

set -e # Exit on failure

exec /tmp/codecrafters-build-redis-c "$@"
exec $(dirname $0)/build/redis "$@"
55 changes: 55 additions & 0 deletions solutions/c/01-jm1/code/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# Prerequisites
*.d

# Object files
*.o
*.ko
*.obj
*.elf

# Linker output
*.ilk
*.map
*.exp

# Precompiled Headers
*.gch
*.pch

# Libraries
*.lib
*.a
*.la
*.lo

# Shared objects (inc. Windows DLLs)
*.dll
*.so
*.so.*
*.dylib

# Executables
*.exe
*.out
*.app
*.i*86
*.x86_64
*.hex

# Debug files
*.dSYM/
*.su
*.idb
*.pdb

# Kernel Module Compile Results
*.mod*
*.cmd
.tmp_versions/
modules.order
Module.symvers
Mkfile.old
dkms.conf

build
vcpkg_installed
9 changes: 9 additions & 0 deletions solutions/c/01-jm1/code/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
cmake_minimum_required(VERSION 3.13)

project(codecrafters-redis)

file(GLOB_RECURSE SOURCE_FILES src/*.c src/*.h)

set(CMAKE_C_STANDARD 23) # Enable the C23 standard

add_executable(redis ${SOURCE_FILES})
6 changes: 3 additions & 3 deletions solutions/c/01-jm1/code/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ event loops, the Redis protocol and more.

# Passing the first stage

The entry point for your Redis implementation is in `app/server.c`. Study and
The entry point for your Redis implementation is in `src/main.c`. Study and
uncomment the relevant code, and push your changes to pass the first stage:

```sh
Expand All @@ -26,8 +26,8 @@ That's all!

Note: This section is for stages 2 and beyond.

1. Ensure you have `gcc` installed locally
1. Ensure you have `cmake` installed locally
1. Run `./your_program.sh` to run your Redis server, which is implemented in
`app/server.c`.
`src/main.c`.
1. Commit your changes and run `git push origin master` to submit your solution
to CodeCrafters. Test output will be streamed to your terminal.
4 changes: 2 additions & 2 deletions solutions/c/01-jm1/code/codecrafters.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ debug: false
# Use this to change the C version used to run your code
# on Codecrafters.
#
# Available versions: c-9.2
language_pack: c-9.2
# Available versions: c-23
language_pack: c-23
File renamed without changes.
14 changes: 14 additions & 0 deletions solutions/c/01-jm1/code/vcpkg-configuration.json
Original file line number Diff line number Diff line change
@@ -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"
}
]
}
3 changes: 3 additions & 0 deletions solutions/c/01-jm1/code/vcpkg.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"dependencies": []
}
5 changes: 3 additions & 2 deletions solutions/c/01-jm1/code/your_program.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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-redis-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-redis-c "$@"
exec $(dirname $0)/build/redis "$@"
File renamed without changes.
2 changes: 1 addition & 1 deletion solutions/c/01-jm1/explanation.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
The entry point for your Redis implementation is in `app/server.c`.
The entry point for your Redis implementation is in `src/main.c`.

Study and uncomment the relevant code:

Expand Down
3 changes: 2 additions & 1 deletion starter_templates/c/code/.codecrafters/compile.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@

set -e # Exit on failure

gcc -o /tmp/codecrafters-build-redis-c app/*.c
cmake -B build -S . -DCMAKE_TOOLCHAIN_FILE=${VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake
cmake --build ./build
2 changes: 1 addition & 1 deletion starter_templates/c/code/.codecrafters/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@

set -e # Exit on failure

exec /tmp/codecrafters-build-redis-c "$@"
exec $(dirname $0)/build/redis "$@"
Loading

0 comments on commit e9f515e

Please sign in to comment.