Skip to content

Zig: fix issues with using c_allocator #213

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

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 && \
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 && \
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 @@ RUN echo "@community http://dl-cdn.alpinelinux.org/alpine/edge/community" >> /et
#
# 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 -- $@