Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Redis] CC-1656 Upgrade Zig to 0.14 #293

Merged
merged 1 commit into from
Mar 19, 2025
Merged

[Redis] CC-1656 Upgrade Zig to 0.14 #293

merged 1 commit into from
Mar 19, 2025

Conversation

andy1li
Copy link
Member

@andy1li andy1li commented Mar 19, 2025

Summary by CodeRabbit

  • Documentation

    • Updated instructions now require Zig version 0.14 instead of the previous release, ensuring alignment with the latest environment.
  • Chores

    • Revised package configurations to improve consistency and unique package identification.
  • New Features

    • Introduced a new container setup that streamlines dependency management for Zig version 0.14.

@andy1li andy1li self-assigned this Mar 19, 2025
Copy link

linear bot commented Mar 19, 2025

Copy link

coderabbitai bot commented Mar 19, 2025

Walkthrough

The changes update the minimum required Zig version from 0.13 to 0.14 across multiple project files, including README, YAML configuration, and Dockerfile settings. Additionally, the package metadata in several build.zig.zon files has been modified by converting the hardcoded package name into a variable reference and introducing a fingerprint for identification. A new Dockerfile specifically for Zig 0.14 has been added to automate the installation and build process in an Alpine environment.

Changes

File(s) Change Summary
compiled_starters/zig/README.md
solutions/zig/01-jm1/code/README.md
Updated Zig version requirement from zig (0.13+) to zig (0.14).
compiled_starters/zig/build.zig.zon
solutions/zig/01-jm1/code/build.zig.zon
starter_templates/zig/code/build.zig.zon
Changed package metadata: updated the .name field from a string literal to a variable reference and added a new .fingerprint field with value 0xf806bb97907ce4a5.
compiled_starters/zig/codecrafters.yml
solutions/zig/01-jm1/code/codecrafters.yml
Updated the language_pack field from zig-0.13 to zig-0.14.
starter_templates/zig/config.yml Modified the required_executable attribute from zig (0.13+) to zig (0.14).
dockerfiles/zig-0.14.Dockerfile Introduced a new Dockerfile that uses Alpine 3.20, installs required packages (xz, curl), downloads and configures Zig 0.14.0, sets environment variables, copies project files, runs the compile script, and sets up caching for build artifacts.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant DockerEngine as Docker Engine
    participant Alpine as Alpine Container
    participant ZigInstaller as Zig Installer
    participant BuildScript as Build Script

    User->>DockerEngine: Initiate build for Zig 0.14
    DockerEngine->>Alpine: Start from alpine:3.20 base image
    Alpine->>Alpine: Install dependencies (xz, curl)
    Alpine->>ZigInstaller: Download and extract Zig 0.14.0 tarball
    ZigInstaller-->>Alpine: Zig installed in /usr/local/zig
    Alpine->>DockerEngine: Update PATH and set env vars
    DockerEngine->>BuildScript: Copy project files and execute .codecrafters/compile.sh
    BuildScript-->>DockerEngine: Build complete with cached artifacts
Loading

Poem

I hopped through files with a twitchy nose,
Upgraded Zig to version 0.14 in all our code rows.
The package name now dances with a variable gleam,
And fingerprints mark our work like a dream.
I'm a rabbit, delighted by these changes supreme!
🐇✨


🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3a55a81 and 28bcda1.

📒 Files selected for processing (9)
  • compiled_starters/zig/README.md (1 hunks)
  • compiled_starters/zig/build.zig.zon (1 hunks)
  • compiled_starters/zig/codecrafters.yml (1 hunks)
  • dockerfiles/zig-0.14.Dockerfile (1 hunks)
  • solutions/zig/01-jm1/code/README.md (1 hunks)
  • solutions/zig/01-jm1/code/build.zig.zon (1 hunks)
  • solutions/zig/01-jm1/code/codecrafters.yml (1 hunks)
  • starter_templates/zig/code/build.zig.zon (1 hunks)
  • starter_templates/zig/config.yml (1 hunks)
🧰 Additional context used
🪛 Hadolint (2.12.0)
dockerfiles/zig-0.14.Dockerfile

[error] 20-20: invalid flag: --exclude

(DL1000)

⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: test_course_definition / test (swift)
  • GitHub Check: test_course_definition / test (scala)
  • GitHub Check: test_course_definition / test (ocaml)
  • GitHub Check: test_course_definition / test (haskell)
🔇 Additional comments (11)
compiled_starters/zig/README.md (1)

29-29: Update Zig Version in Documentation

The version requirement update from zig (0.13+) to zig (0.14) is correctly applied. This clearly informs users about the new minimum requirement and matches the PR objectives.

solutions/zig/01-jm1/code/README.md (1)

29-29: Update Zig Version in Documentation

The change to require zig (0.14) instead of the previous version is accurately reflected here. It ensures consistency with the updated configuration across the project.

starter_templates/zig/config.yml (1)

2-2: Updated Zig Version Requirement

The required_executable attribute now correctly specifies zig (0.14), aligning with the overall upgrade objective. This change helps enforce the new minimum version for execution.

solutions/zig/01-jm1/code/codecrafters.yml (1)

10-11: Updated Language Pack Version

Changing the language pack from zig-0.13 to zig-0.14 ensures that the new version is consistently used in the Codecrafters environment. The inline comment clarifies the available version, which is a helpful touch.

compiled_starters/zig/codecrafters.yml (1)

10-11: Consistent Zig Version Configuration

The update to zig-0.14 in the language_pack field is correctly implemented and consistent with the other configuration files and documentation. This uniform update helps prevent version mismatches.

solutions/zig/01-jm1/code/build.zig.zon (1)

2-3: Correct update for Zig 0.14 compatibility

The changes to the package metadata are necessary for compatibility with Zig 0.14's package system. Using the .codecrafters_redis reference instead of a string literal and adding the .fingerprint field align with Zig 0.14's enhanced package identification requirements.

compiled_starters/zig/build.zig.zon (1)

2-3: Properly updated package metadata for Zig 0.14

These changes correctly adapt the package configuration to Zig 0.14's package system requirements. The consistent use of .codecrafters_redis reference and identical .fingerprint value across build files ensures compatibility throughout the project.

starter_templates/zig/code/build.zig.zon (1)

2-3: Consistent package metadata updates

The package metadata changes match those in the other build.zig.zon files, ensuring consistent configuration across all project templates. This uniformity is important for maintaining compatibility with Zig 0.14 throughout the codebase.

dockerfiles/zig-0.14.Dockerfile (3)

1-28: New Dockerfile properly configured for Zig 0.14

The Dockerfile correctly sets up an environment with Zig 0.14.0 installed. The approach of downloading from the official source and setting up the appropriate paths follows best practices.

🧰 Tools
🪛 Hadolint (2.12.0)

[error] 20-20: invalid flag: --exclude

(DL1000)


4-4:

❓ Verification inconclusive

Verify package versions

The specified minimum versions for xz (5.6) and curl (8.9) are quite high. Verify that Alpine 3.20 provides these versions to avoid build failures.


🏁 Script executed:

#!/bin/bash
# Check what versions of xz and curl are available in Alpine 3.20
echo "Checking Alpine package repository for xz and curl versions..."
docker run --rm alpine:3.20 apk info -v xz curl

Length of output: 281


Manual Verification Required: Confirm Package Versions in Alpine 3.20

The automated script did not produce the expected output due to the missing Docker command, so please verify manually that Alpine 3.20 indeed provides at least xz version 5.6 and curl version 8.9 to prevent potential build failures. Specifically, ensure:

  • xz is version 5.6 or newer.
  • curl is version 8.9 or newer.

Once verified, adjust the version constraints in the Dockerfile if necessary.


1-1:

✅ Verification successful

Dockerfile uses experimental syntax

The docker/dockerfile:1.7-labs syntax is an experimental feature that enables advanced capabilities like the --exclude flag. This is appropriate if the build environment supports it, but consider documenting this requirement.


🌐 Web query:

What is docker/dockerfile:1.7-labs syntax?

💡 Result:

The docker/dockerfile:1.7-labs syntax enables experimental Dockerfile features through Docker's labs channel, which provides early access to cutting-edge capabilities before they reach the stable release[2][4]. This syntax version introduces several advanced features:

Key Experimental Features:

  1. Enhanced COPY Command:

    • --parents flag replicates source directory structure in the image (similar to cp --parents):
      COPY --parents ./nested/file.txt /destination/  # Creates /destination/nested/file.txt[1][5]
    • --exclude filters files during copy operations:
      COPY --exclude=*.tmp ./src/ ./dest/[3][6]
  2. Advanced Variable Expansion:

    • String manipulation directly in ${variable} substitutions:
      ARG VERSION=v2.1.0
      RUN wget https://example.com/pkg/${VERSION#v}-linux.tar.gz  # Resolves to 2.1.0-linux.tar.gz[3]
  3. Git Repository Integration:

    • Direct cloning into images using ADD:
      ADD [email protected]:user/repo.git /app/src[1][5]
  4. Path Pivot Syntax (/./):

    • Granular control over copied directory structure:
      COPY --parents /out/./**/bin/ /  # Copies only bin/ subdirectories[3]

Usage Requirements:

# syntax=docker/dockerfile:1.7-labs
FROM base-image

Important Notes:

  • Features might change incompatibly between versions[2]
  • To access both 1.7 features and older labs capabilities, use docker/dockerfile:1-labs[2]
  • Stable counterparts for these features may arrive in future non-labs releases like docker/dockerfile:1.8[4]

This syntax version is particularly useful for developers needing cutting-edge Docker capabilities, though production environments should prefer stable releases[2][4].

Citations:


Experimental Dockerfile Syntax: Document Build Environment Requirements

  • The Dockerfile in dockerfiles/zig-0.14.Dockerfile uses the experimental docker/dockerfile:1.7-labs directive. This syntax unlocks advanced features such as enhanced COPY capabilities (e.g., using the --exclude flag), advanced variable expansion, Git integration, and path pivot syntax.
  • These features require that the build environment supports BuildKit with labs channel capabilities. Please consider documenting this prerequisite in the project’s build documentation or README to ensure that all users are aware of the needed environmental configurations.

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
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Verification agent

🧩 Analysis chain

Fix invalid COPY flag in Dockerfile

The --exclude flag isn't supported in standard Docker COPY commands. Consider using a .dockerignore file or multi-stage builds to achieve the same result.

- COPY --exclude=.git --exclude=README.md . /app
+ # Create .dockerignore with .git and README.md, then:
+ COPY . /app

🏁 Script executed:

#!/bin/bash
# Check if this is using a special Docker syntax
head -1 dockerfiles/zig-0.14.Dockerfile

Length of output: 77


Fix invalid COPY flag in Dockerfile

The Dockerfile is using the experimental BuildKit syntax (# syntax=docker/dockerfile:1.7-labs), but even with this syntax, the COPY command does not support the --exclude flags. To exclude files like .git and README.md, please use a .dockerignore file and update the COPY command accordingly.

  • File: dockerfiles/zig-0.14.Dockerfile (line 20)
  • Action: Remove the invalid --exclude flags and ensure that .dockerignore is configured with the appropriate entries.
- COPY --exclude=.git --exclude=README.md . /app
+ # Create a .dockerignore file that excludes .git and README.md, then:
+ COPY . /app
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
COPY --exclude=.git --exclude=README.md . /app
# Create .dockerignore with .git and README.md, then:
COPY . /app
🧰 Tools
🪛 Hadolint (2.12.0)

[error] 20-20: invalid flag: --exclude

(DL1000)

…_redis package name and upgrade required Zig version to 0.14
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

♻️ Duplicate comments (1)
dockerfiles/zig-0.14.Dockerfile (1)

20-20: ⚠️ Potential issue

Fix invalid COPY flag in Dockerfile

The Dockerfile is using the experimental BuildKit syntax (# syntax=docker/dockerfile:1.7-labs), but even with this syntax, the COPY command does not support the --exclude flags. To exclude files like .git and README.md, please use a .dockerignore file.

- COPY --exclude=.git --exclude=README.md . /app
+ # Create a .dockerignore file that excludes .git and README.md, then:
+ COPY . /app
🧰 Tools
🪛 Hadolint (2.12.0)

[error] 20-20: invalid flag: --exclude

(DL1000)

🧹 Nitpick comments (1)
dockerfiles/zig-0.14.Dockerfile (1)

27-27: Consider handling the cache directory more robustly

The current approach uses || true to ignore failures when moving the cache directory. While this works, consider adding a check if the directory exists before attempting to move it.

- RUN mv /app/.zig-cache /app-cached/.zig-cache || true
+ RUN if [ -d "/app/.zig-cache" ]; then \
+       mv /app/.zig-cache /app-cached/.zig-cache; \
+     fi
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro (Legacy)

📥 Commits

Reviewing files that changed from the base of the PR and between 28bcda1 and 5ac5b24.

📒 Files selected for processing (9)
  • compiled_starters/zig/README.md (1 hunks)
  • compiled_starters/zig/build.zig.zon (2 hunks)
  • compiled_starters/zig/codecrafters.yml (1 hunks)
  • dockerfiles/zig-0.14.Dockerfile (1 hunks)
  • solutions/zig/01-jm1/code/README.md (1 hunks)
  • solutions/zig/01-jm1/code/build.zig.zon (2 hunks)
  • solutions/zig/01-jm1/code/codecrafters.yml (1 hunks)
  • starter_templates/zig/code/build.zig.zon (2 hunks)
  • starter_templates/zig/config.yml (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (7)
  • solutions/zig/01-jm1/code/README.md
  • starter_templates/zig/config.yml
  • compiled_starters/zig/codecrafters.yml
  • compiled_starters/zig/README.md
  • solutions/zig/01-jm1/code/codecrafters.yml
  • compiled_starters/zig/build.zig.zon
  • starter_templates/zig/code/build.zig.zon
🧰 Additional context used
🪛 Hadolint (2.12.0)
dockerfiles/zig-0.14.Dockerfile

[error] 20-20: invalid flag: --exclude

(DL1000)

⏰ Context from checks skipped due to timeout of 90000ms (5)
  • GitHub Check: test_course_definition / test (swift)
  • GitHub Check: test_course_definition / test (scala)
  • GitHub Check: test_course_definition / test (ocaml)
  • GitHub Check: test_course_definition / test (kotlin)
  • GitHub Check: test_course_definition / test (haskell)
🔇 Additional comments (6)
solutions/zig/01-jm1/code/build.zig.zon (3)

3-3: Added fingerprint for package identification

The fingerprint 0xf806bb97907ce4a5 has been added, which helps with package identification in Zig 0.14+. This is a good practice for package management.


12-12: Minimum Zig version updated to 0.14.0

The minimum required Zig version has been updated from 0.11.0 to 0.14.0, which aligns with the PR objective of upgrading to Zig 0.14.


2-2:

❓ Verification inconclusive

Check variable reference .codecrafters_redis

The package name has been changed from a hardcoded string to a variable reference .codecrafters_redis. Make sure this variable is defined somewhere in your build system, otherwise this will cause build failures.


🏁 Script executed:

#!/bin/bash
# Check if .codecrafters_redis is defined in any Zig build files
rg -l "codecrafters_redis" --type zig

Length of output: 37


I'll run a more generic search (without restricting the file type) to verify if the variable reference .codecrafters_redis is defined anywhere in the repository. This will help ensure we're not missing it due to file extension filtering.


🏁 Script executed:

#!/bin/bash
# Re-run search across the repository for "codecrafters_redis" (not limiting to Zig file types)
rg -l "codecrafters_redis"

# Additionally, check for a definition pattern (e.g., a constant assignment)
rg -l "const\s\+codecrafters_redis"

Length of output: 1024


Action Required: Verify .codecrafters_redis Variable Definition

In the file solutions/zig/01-jm1/code/build.zig.zon (line 2), the package name is now referenced as .codecrafters_redis instead of a hardcoded string. Automated searches did not reveal any corresponding definition (e.g., a const assignment or similar binding) in the Zig build files. Please perform a manual check—if this variable isn’t defined or injected by your build configuration, it could lead to build failures.

dockerfiles/zig-0.14.Dockerfile (3)

1-2: New Dockerfile for Zig 0.14 with modern syntax

Good use of the experimental BuildKit syntax and Alpine 3.20 as the base image for the new Zig 0.14 Dockerfile.


4-4: Package versions are pinned with minimums

Good practice using version constraints ('xz>=5.6' 'curl>=8.9') to ensure minimum required versions while still allowing security updates.


7-10: Zig 0.14.0 installation looks good

The Zig installation process correctly downloads, extracts, and places the binary in an appropriate location, then cleans up temporary files.

@andy1li andy1li merged commit 2670935 into main Mar 19, 2025
32 checks passed
@andy1li andy1li mentioned this pull request Mar 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant