From 6cf35d1c4b051fff58d086b5f7d426ee13772dd8 Mon Sep 17 00:00:00 2001 From: Andy Li <1450947+andy1li@users.noreply.github.com> Date: Wed, 19 Mar 2025 20:16:17 +0800 Subject: [PATCH] Upgrade Zig starter template and dependencies to version 0.14 - Update Zig version in configuration files and README - Rename executable from 'zig' to 'main' in build scripts - Adjust .gitignore to include new patterns - Add Dockerfile for Zig 0.14 - Update run scripts to reflect changes in executable name --- compiled_starters/zig/.codecrafters/run.sh | 2 +- compiled_starters/zig/.gitignore | 8 +++--- compiled_starters/zig/README.md | 2 +- compiled_starters/zig/build.zig | 2 +- compiled_starters/zig/build.zig.zon | 6 +++-- compiled_starters/zig/codecrafters.yml | 4 +-- compiled_starters/zig/your_program.sh | 2 +- dockerfiles/zig-0.14.Dockerfile | 27 +++++++++++++++++++ .../zig/01-at4/code/.codecrafters/run.sh | 2 +- solutions/zig/01-at4/code/.gitignore | 8 +++--- solutions/zig/01-at4/code/README.md | 2 +- solutions/zig/01-at4/code/build.zig | 2 +- solutions/zig/01-at4/code/build.zig.zon | 6 +++-- solutions/zig/01-at4/code/codecrafters.yml | 4 +-- solutions/zig/01-at4/code/your_program.sh | 2 +- .../zig/code/.codecrafters/run.sh | 2 +- starter_templates/zig/code/.gitignore | 8 +++--- starter_templates/zig/code/build.zig | 2 +- starter_templates/zig/code/build.zig.zon | 6 +++-- starter_templates/zig/config.yml | 2 +- 20 files changed, 66 insertions(+), 33 deletions(-) create mode 100644 dockerfiles/zig-0.14.Dockerfile diff --git a/compiled_starters/zig/.codecrafters/run.sh b/compiled_starters/zig/.codecrafters/run.sh index b246c16..b7cab59 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 zig-out/bin/zig "$@" +exec $(dirname $0)/zig-out/bin/main "$@" diff --git a/compiled_starters/zig/.gitignore b/compiled_starters/zig/.gitignore index f798d2a..b7bb740 100644 --- a/compiled_starters/zig/.gitignore +++ b/compiled_starters/zig/.gitignore @@ -1,10 +1,10 @@ # Zig build artifacts -.zig-cache/ +main zig-cache/ +.zig-cache/ zig-out/ # Compiled binary output -main bin/ !bin/.gitkeep @@ -13,6 +13,6 @@ bin/ *.h # Ignore OS and editor specific files -.DS_Store +**/.DS_Store *.swp -*~ \ No newline at end of file +*~ diff --git a/compiled_starters/zig/README.md b/compiled_starters/zig/README.md index 2a4c580..b59e991 100644 --- a/compiled_starters/zig/README.md +++ b/compiled_starters/zig/README.md @@ -30,7 +30,7 @@ Time to move on to the next stage! Note: This section is for stages 2 and beyond. -1. Ensure you have `zig (0.12)` installed locally +1. Ensure you have `zig (0.14)` installed locally 1. Run `./your_program.sh` to run your program, which is implemented in `src/main.zig`. 1. Commit your changes and run `git push origin master` to submit your solution diff --git a/compiled_starters/zig/build.zig b/compiled_starters/zig/build.zig index c6727a8..d211b57 100644 --- a/compiled_starters/zig/build.zig +++ b/compiled_starters/zig/build.zig @@ -3,7 +3,7 @@ const std = @import("std"); // Learn more about this file here: https://ziglang.org/learn/build-system pub fn build(b: *std.Build) void { const exe = b.addExecutable(.{ - .name = "zig", + .name = "main", .root_source_file = b.path("src/main.zig"), .target = b.standardTargetOptions(.{}), .optimize = b.standardOptimizeOption(.{}), diff --git a/compiled_starters/zig/build.zig.zon b/compiled_starters/zig/build.zig.zon index 3f76c13..e424a22 100644 --- a/compiled_starters/zig/build.zig.zon +++ b/compiled_starters/zig/build.zig.zon @@ -1,5 +1,7 @@ .{ - .name = "zig", + .name = .codecrafters_http_server, + .fingerprint = 0xe0b9fabc244c324e, + // This is a [Semantic Version](https://semver.org/). // In a future version of Zig it will be used for package deduplication. .version = "0.0.0", @@ -7,7 +9,7 @@ // This field is optional. // This is currently advisory only; Zig does not yet do anything // with this value. - //.minimum_zig_version = "0.11.0", + .minimum_zig_version = "0.14.0", // This field is optional. // Each dependency must either provide a `url` and `hash`, or a `path`. diff --git a/compiled_starters/zig/codecrafters.yml b/compiled_starters/zig/codecrafters.yml index 8c3bf9c..90490e3 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.12 -language_pack: zig-0.12 +# Available versions: zig-0.14 +language_pack: zig-0.14 diff --git a/compiled_starters/zig/your_program.sh b/compiled_starters/zig/your_program.sh index e29d2eb..cb84633 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 zig-out/bin/zig "$@" +exec $(dirname $0)/zig-out/bin/main "$@" diff --git a/dockerfiles/zig-0.14.Dockerfile b/dockerfiles/zig-0.14.Dockerfile new file mode 100644 index 0000000..862d4f9 --- /dev/null +++ b/dockerfiles/zig-0.14.Dockerfile @@ -0,0 +1,27 @@ +# syntax=docker/dockerfile:1.7-labs +FROM alpine:3.20 + +RUN apk add --no-cache 'xz>=5.6' 'curl>=8.9' + +# Download and install Zig +RUN curl -O https://ziglang.org/download/0.14.0/zig-linux-x86_64-0.14.0.tar.xz \ + && tar -xf zig-linux-x86_64-0.14.0.tar.xz \ + && mv zig-linux-x86_64-0.14.0 /usr/local/zig \ + && rm zig-linux-x86_64-0.14.0.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 b246c16..b7cab59 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 zig-out/bin/zig "$@" +exec $(dirname $0)/zig-out/bin/main "$@" diff --git a/solutions/zig/01-at4/code/.gitignore b/solutions/zig/01-at4/code/.gitignore index f798d2a..b7bb740 100644 --- a/solutions/zig/01-at4/code/.gitignore +++ b/solutions/zig/01-at4/code/.gitignore @@ -1,10 +1,10 @@ # Zig build artifacts -.zig-cache/ +main zig-cache/ +.zig-cache/ zig-out/ # Compiled binary output -main bin/ !bin/.gitkeep @@ -13,6 +13,6 @@ bin/ *.h # Ignore OS and editor specific files -.DS_Store +**/.DS_Store *.swp -*~ \ No newline at end of file +*~ diff --git a/solutions/zig/01-at4/code/README.md b/solutions/zig/01-at4/code/README.md index 2a4c580..b59e991 100644 --- a/solutions/zig/01-at4/code/README.md +++ b/solutions/zig/01-at4/code/README.md @@ -30,7 +30,7 @@ Time to move on to the next stage! Note: This section is for stages 2 and beyond. -1. Ensure you have `zig (0.12)` installed locally +1. Ensure you have `zig (0.14)` installed locally 1. Run `./your_program.sh` to run your program, which is implemented in `src/main.zig`. 1. Commit your changes and run `git push origin master` to submit your solution diff --git a/solutions/zig/01-at4/code/build.zig b/solutions/zig/01-at4/code/build.zig index c6727a8..d211b57 100644 --- a/solutions/zig/01-at4/code/build.zig +++ b/solutions/zig/01-at4/code/build.zig @@ -3,7 +3,7 @@ const std = @import("std"); // Learn more about this file here: https://ziglang.org/learn/build-system pub fn build(b: *std.Build) void { const exe = b.addExecutable(.{ - .name = "zig", + .name = "main", .root_source_file = b.path("src/main.zig"), .target = b.standardTargetOptions(.{}), .optimize = b.standardOptimizeOption(.{}), diff --git a/solutions/zig/01-at4/code/build.zig.zon b/solutions/zig/01-at4/code/build.zig.zon index 3f76c13..e424a22 100644 --- a/solutions/zig/01-at4/code/build.zig.zon +++ b/solutions/zig/01-at4/code/build.zig.zon @@ -1,5 +1,7 @@ .{ - .name = "zig", + .name = .codecrafters_http_server, + .fingerprint = 0xe0b9fabc244c324e, + // This is a [Semantic Version](https://semver.org/). // In a future version of Zig it will be used for package deduplication. .version = "0.0.0", @@ -7,7 +9,7 @@ // This field is optional. // This is currently advisory only; Zig does not yet do anything // with this value. - //.minimum_zig_version = "0.11.0", + .minimum_zig_version = "0.14.0", // This field is optional. // Each dependency must either provide a `url` and `hash`, or a `path`. diff --git a/solutions/zig/01-at4/code/codecrafters.yml b/solutions/zig/01-at4/code/codecrafters.yml index 8c3bf9c..90490e3 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.12 -language_pack: zig-0.12 +# Available versions: zig-0.14 +language_pack: zig-0.14 diff --git a/solutions/zig/01-at4/code/your_program.sh b/solutions/zig/01-at4/code/your_program.sh index e29d2eb..cb84633 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 zig-out/bin/zig "$@" +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 b246c16..b7cab59 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 zig-out/bin/zig "$@" +exec $(dirname $0)/zig-out/bin/main "$@" diff --git a/starter_templates/zig/code/.gitignore b/starter_templates/zig/code/.gitignore index f798d2a..b7bb740 100644 --- a/starter_templates/zig/code/.gitignore +++ b/starter_templates/zig/code/.gitignore @@ -1,10 +1,10 @@ # Zig build artifacts -.zig-cache/ +main zig-cache/ +.zig-cache/ zig-out/ # Compiled binary output -main bin/ !bin/.gitkeep @@ -13,6 +13,6 @@ bin/ *.h # Ignore OS and editor specific files -.DS_Store +**/.DS_Store *.swp -*~ \ No newline at end of file +*~ diff --git a/starter_templates/zig/code/build.zig b/starter_templates/zig/code/build.zig index c6727a8..d211b57 100644 --- a/starter_templates/zig/code/build.zig +++ b/starter_templates/zig/code/build.zig @@ -3,7 +3,7 @@ const std = @import("std"); // Learn more about this file here: https://ziglang.org/learn/build-system pub fn build(b: *std.Build) void { const exe = b.addExecutable(.{ - .name = "zig", + .name = "main", .root_source_file = b.path("src/main.zig"), .target = b.standardTargetOptions(.{}), .optimize = b.standardOptimizeOption(.{}), diff --git a/starter_templates/zig/code/build.zig.zon b/starter_templates/zig/code/build.zig.zon index 3f76c13..e424a22 100644 --- a/starter_templates/zig/code/build.zig.zon +++ b/starter_templates/zig/code/build.zig.zon @@ -1,5 +1,7 @@ .{ - .name = "zig", + .name = .codecrafters_http_server, + .fingerprint = 0xe0b9fabc244c324e, + // This is a [Semantic Version](https://semver.org/). // In a future version of Zig it will be used for package deduplication. .version = "0.0.0", @@ -7,7 +9,7 @@ // This field is optional. // This is currently advisory only; Zig does not yet do anything // with this value. - //.minimum_zig_version = "0.11.0", + .minimum_zig_version = "0.14.0", // This field is optional. // Each dependency must either provide a `url` and `hash`, or a `path`. diff --git a/starter_templates/zig/config.yml b/starter_templates/zig/config.yml index 4a898af..a113b98 100644 --- a/starter_templates/zig/config.yml +++ b/starter_templates/zig/config.yml @@ -1,3 +1,3 @@ attributes: - required_executable: zig (0.12) + required_executable: zig (0.14) user_editable_file: src/main.zig