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

Zig: fix issues with using c_allocator #213

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion compiled_starters/zig/build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ 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 = "redis_challenge",
.root_source_file = b.path("src/main.zig"),
.target = b.standardTargetOptions(.{}),
.optimize = b.standardOptimizeOption(.{}),
.link_libc = true,
});

// This declares intent for the executable to be installed into the
Expand Down
2 changes: 1 addition & 1 deletion compiled_starters/zig/spawn_redis_server.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@
# DON'T EDIT THIS!
set -e

exec zig build run -- $@
exec zig build run -Doptimize=ReleaseFast -- $@
30 changes: 24 additions & 6 deletions dockerfiles/zig-0.12.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,25 @@
FROM alpine:3.19
FROM debian:stable-slim

# Add the testing repository
RUN echo "@community http://dl-cdn.alpinelinux.org/alpine/edge/community" >> /etc/apk/repositories
# Update package list and install required packages
RUN apt-get update && \

Check failure on line 4 in dockerfiles/zig-0.12.Dockerfile

View workflow job for this annotation

GitHub Actions / test_course_definition / docker_lint

DL3008 warning: Pin versions in apt get install. Instead of `apt-get install <package>` use `apt-get install <package>=<version>`

Check failure on line 4 in dockerfiles/zig-0.12.Dockerfile

View workflow job for this annotation

GitHub Actions / test_course_definition / docker_lint

DL3015 info: Avoid additional packages by specifying `--no-install-recommends`
apt-get install -y curl xz-utils build-essential libc-dev && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*

# Set Zig version
ENV ZIG_VERSION=0.12.0

WORKDIR /app

# Download and install Zig to /usr/local/bin
RUN curl -LO https://ziglang.org/download/${ZIG_VERSION}/zig-linux-$(uname -m)-${ZIG_VERSION}.tar.xz && \

Check failure on line 15 in dockerfiles/zig-0.12.Dockerfile

View workflow job for this annotation

GitHub Actions / test_course_definition / docker_lint

SC2046 warning: Quote this to prevent word splitting.
tar -xf zig-linux-$(uname -m)-${ZIG_VERSION}.tar.xz && \
mkdir -p /usr/local/zig && \
mv zig-linux-$(uname -m)-${ZIG_VERSION}/* /usr/local/zig/ && \
rmdir zig-linux-$(uname -m)-${ZIG_VERSION} && \
rm zig-linux-$(uname -m)-${ZIG_VERSION}.tar.xz

ENV PATH="/usr/local/zig:${PATH}"

# We should use build.zig & build.zig.zon to cache downloading deps, but we don't have this wired up yet.
#
Expand All @@ -14,8 +32,8 @@
#
# ENV CODECRAFTERS_DEPENDENCY_FILE_PATHS="build.zig,build.zig.zon"

# Update the package list and install Zig
RUN apk add --no-cache zig@community=0.12.0-r0
# Create precompile script
RUN printf "set -e \ncd \${CODECRAFTERS_SUBMISSION_DIR} \necho 'Running zig build' \nzig build -Doptimize=ReleaseFast \necho 'zig build completed.' \n" > /codecrafters-precompile.sh

RUN printf "set -e \ncd \${CODECRAFTERS_SUBMISSION_DIR} \necho 'Running zig build' \nzig build \necho 'zig build completed.' \n" > /codecrafters-precompile.sh
# Make precompile script executable
RUN chmod +x /codecrafters-precompile.sh
3 changes: 2 additions & 1 deletion solutions/zig/01-jm1/code/build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ 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 = "redis_challenge",
.root_source_file = b.path("src/main.zig"),
.target = b.standardTargetOptions(.{}),
.optimize = b.standardOptimizeOption(.{}),
.link_libc = true,
});

// This declares intent for the executable to be installed into the
Expand Down
2 changes: 1 addition & 1 deletion solutions/zig/01-jm1/code/spawn_redis_server.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@
# DON'T EDIT THIS!
set -e

exec zig build run -- $@
exec zig build run -Doptimize=ReleaseFast -- $@
3 changes: 2 additions & 1 deletion starter_templates/zig/build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ 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 = "redis_challenge",
.root_source_file = b.path("src/main.zig"),
.target = b.standardTargetOptions(.{}),
.optimize = b.standardOptimizeOption(.{}),
.link_libc = true,
});

// This declares intent for the executable to be installed into the
Expand Down
2 changes: 1 addition & 1 deletion starter_templates/zig/spawn_redis_server.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@
# DON'T EDIT THIS!
set -e

exec zig build run -- $@
exec zig build run -Doptimize=ReleaseFast -- $@
Loading