From 927b8d17594df88853b4a232c8b1119b4a786b7e Mon Sep 17 00:00:00 2001 From: Andy Li <1450947+andy1li@users.noreply.github.com> Date: Thu, 11 Sep 2025 07:34:59 +0800 Subject: [PATCH] Update Zig buildpack to version 0.15 and refactor script execution for improved compatibility. --- compiled_starters/zig/.codecrafters/run.sh | 2 +- compiled_starters/zig/codecrafters.yml | 4 +-- compiled_starters/zig/your_program.sh | 2 +- dockerfiles/zig-0.15.Dockerfile | 30 +++++++++++++++++++ .../zig/01-at4/code/.codecrafters/run.sh | 2 +- solutions/zig/01-at4/code/codecrafters.yml | 4 +-- solutions/zig/01-at4/code/your_program.sh | 2 +- .../zig/code/.codecrafters/run.sh | 2 +- 8 files changed, 39 insertions(+), 9 deletions(-) create mode 100644 dockerfiles/zig-0.15.Dockerfile diff --git a/compiled_starters/zig/.codecrafters/run.sh b/compiled_starters/zig/.codecrafters/run.sh index b7cab59..18ffaf9 100755 --- a/compiled_starters/zig/.codecrafters/run.sh +++ b/compiled_starters/zig/.codecrafters/run.sh @@ -8,4 +8,4 @@ set -e # Exit on failure -exec $(dirname $0)/zig-out/bin/main "$@" +exec "$(dirname "$0")"/zig-out/bin/main "$@" diff --git a/compiled_starters/zig/codecrafters.yml b/compiled_starters/zig/codecrafters.yml index 7bb803b..77a7f76 100644 --- a/compiled_starters/zig/codecrafters.yml +++ b/compiled_starters/zig/codecrafters.yml @@ -7,5 +7,5 @@ debug: false # Use this to change the Zig version used to run your code # on Codecrafters. # -# Available versions: zig-0.14 -buildpack: zig-0.14 +# Available versions: zig-0.15 +buildpack: zig-0.15 diff --git a/compiled_starters/zig/your_program.sh b/compiled_starters/zig/your_program.sh index cb84633..9691601 100755 --- a/compiled_starters/zig/your_program.sh +++ b/compiled_starters/zig/your_program.sh @@ -21,4 +21,4 @@ set -e # Exit early if any commands fail # # - Edit this to change how your program runs locally # - Edit .codecrafters/run.sh to change how your program runs remotely -exec $(dirname $0)/zig-out/bin/main "$@" +exec "$(dirname "$0")"/zig-out/bin/main "$@" diff --git a/dockerfiles/zig-0.15.Dockerfile b/dockerfiles/zig-0.15.Dockerfile new file mode 100644 index 0000000..1bb31e8 --- /dev/null +++ b/dockerfiles/zig-0.15.Dockerfile @@ -0,0 +1,30 @@ +# syntax=docker/dockerfile:1.7-labs +FROM debian:bookworm + +RUN apt-get update && \ + apt-get install --no-install-recommends -y xz-utils=5.4.1-1 && \ + apt-get clean && \ + rm -rf /var/lib/apt/lists/* + +# Download and install Zig +RUN curl -O https://ziglang.org/download/0.15.1/zig-x86_64-linux-0.15.1.tar.xz \ + && tar -xf zig-x86_64-linux-0.15.1.tar.xz \ + && mv zig-x86_64-linux-0.15.1 /usr/local/zig \ + && rm zig-x86_64-linux-0.15.1.tar.xz + +# Add Zig to PATH +ENV PATH="/usr/local/zig:${PATH}" + +ENV CODECRAFTERS_DEPENDENCY_FILE_PATHS="build.zig,build.zig.zon" + +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 + +# This runs zig build +RUN .codecrafters/compile.sh + +# Cache build directory +RUN mkdir -p /app-cached +RUN mv /app/.zig-cache /app-cached/.zig-cache || true diff --git a/solutions/zig/01-at4/code/.codecrafters/run.sh b/solutions/zig/01-at4/code/.codecrafters/run.sh index b7cab59..18ffaf9 100755 --- a/solutions/zig/01-at4/code/.codecrafters/run.sh +++ b/solutions/zig/01-at4/code/.codecrafters/run.sh @@ -8,4 +8,4 @@ set -e # Exit on failure -exec $(dirname $0)/zig-out/bin/main "$@" +exec "$(dirname "$0")"/zig-out/bin/main "$@" diff --git a/solutions/zig/01-at4/code/codecrafters.yml b/solutions/zig/01-at4/code/codecrafters.yml index 7bb803b..77a7f76 100644 --- a/solutions/zig/01-at4/code/codecrafters.yml +++ b/solutions/zig/01-at4/code/codecrafters.yml @@ -7,5 +7,5 @@ debug: false # Use this to change the Zig version used to run your code # on Codecrafters. # -# Available versions: zig-0.14 -buildpack: zig-0.14 +# Available versions: zig-0.15 +buildpack: zig-0.15 diff --git a/solutions/zig/01-at4/code/your_program.sh b/solutions/zig/01-at4/code/your_program.sh index cb84633..9691601 100755 --- a/solutions/zig/01-at4/code/your_program.sh +++ b/solutions/zig/01-at4/code/your_program.sh @@ -21,4 +21,4 @@ set -e # Exit early if any commands fail # # - Edit this to change how your program runs locally # - Edit .codecrafters/run.sh to change how your program runs remotely -exec $(dirname $0)/zig-out/bin/main "$@" +exec "$(dirname "$0")"/zig-out/bin/main "$@" diff --git a/starter_templates/zig/code/.codecrafters/run.sh b/starter_templates/zig/code/.codecrafters/run.sh index b7cab59..18ffaf9 100755 --- a/starter_templates/zig/code/.codecrafters/run.sh +++ b/starter_templates/zig/code/.codecrafters/run.sh @@ -8,4 +8,4 @@ set -e # Exit on failure -exec $(dirname $0)/zig-out/bin/main "$@" +exec "$(dirname "$0")"/zig-out/bin/main "$@"