Skip to content

Commit 620ca05

Browse files
authored
Merge pull request #176 from codecrafters-io/upgrade-zig-0.15.2
Upgrade Zig to 0.15.2
2 parents bc4e8d3 + 26f33da commit 620ca05

File tree

7 files changed

+60
-30
lines changed

7 files changed

+60
-30
lines changed

compiled_starters/zig/codecrafters.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@ debug: false
77
# Use this to change the Zig version used to run your code
88
# on Codecrafters.
99
#
10-
# Available versions: zig-0.15
11-
buildpack: zig-0.15
10+
# Available versions: zig-0.15.2
11+
buildpack: zig-0.15.2

compiled_starters/zig/src/main.zig

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
const std = @import("std");
2-
var stdin = std.fs.File.stdin().readerStreaming(&.{});
2+
3+
var stdin_buffer: [4096]u8 = undefined;
4+
var stdin_reader = std.fs.File.stdin().readerStreaming(&stdin_buffer);
5+
const stdin = &stdin_reader.interface;
36

47
fn matchPattern(input_line: []const u8, pattern: []const u8) bool {
58
if (pattern.len == 1) {
@@ -27,12 +30,10 @@ pub fn main() !void {
2730

2831
// TODO: Uncomment the code below to pass the first stage
2932
//
30-
// var input_buffer: [1024]u8 = undefined;
31-
// const input_len = try stdin.read(&input_buffer);
32-
// const input_slice = input_buffer[0..input_len];
33+
// const input_slice = try stdin.takeDelimiter('\n');
3334
//
3435
// const pattern = args[2];
35-
// if (matchPattern(input_slice, pattern)) {
36+
// if (matchPattern(input_slice.?, pattern)) {
3637
// std.process.exit(0);
3738
// } else {
3839
// std.process.exit(1);

dockerfiles/zig-0.15.2.Dockerfile

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# syntax=docker/dockerfile:1.7-labs
2+
FROM debian:bookworm
3+
4+
RUN apt-get update && \
5+
apt-get install --no-install-recommends -y xz-utils=5.4.1-1 && \
6+
apt-get clean && \
7+
rm -rf /var/lib/apt/lists/*
8+
9+
# Download and install Zig
10+
RUN curl -O https://ziglang.org/download/0.15.2/zig-x86_64-linux-0.15.2.tar.xz \
11+
&& tar -xf zig-x86_64-linux-0.15.2.tar.xz \
12+
&& mv zig-x86_64-linux-0.15.2 /usr/local/zig \
13+
&& rm zig-x86_64-linux-0.15.2.tar.xz
14+
15+
# Add Zig to PATH
16+
ENV PATH="/usr/local/zig:${PATH}"
17+
18+
ENV CODECRAFTERS_DEPENDENCY_FILE_PATHS="build.zig,build.zig.zon"
19+
20+
WORKDIR /app
21+
22+
# .git & README.md are unique per-repository. We ignore them on first copy to prevent cache misses
23+
COPY --exclude=.git --exclude=README.md . /app
24+
25+
# This runs zig build
26+
RUN .codecrafters/compile.sh
27+
28+
# Cache build directory
29+
RUN mkdir -p /app-cached
30+
RUN mv /app/.zig-cache /app-cached/.zig-cache || true

solutions/zig/01-cq2/code/codecrafters.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@ debug: false
77
# Use this to change the Zig version used to run your code
88
# on Codecrafters.
99
#
10-
# Available versions: zig-0.15
11-
buildpack: zig-0.15
10+
# Available versions: zig-0.15.2
11+
buildpack: zig-0.15.2

solutions/zig/01-cq2/code/src/main.zig

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
const std = @import("std");
2-
var stdin = std.fs.File.stdin().readerStreaming(&.{});
2+
3+
var stdin_buffer: [4096]u8 = undefined;
4+
var stdin_reader = std.fs.File.stdin().readerStreaming(&stdin_buffer);
5+
const stdin = &stdin_reader.interface;
36

47
fn matchPattern(input_line: []const u8, pattern: []const u8) bool {
58
if (pattern.len == 1) {
@@ -22,12 +25,10 @@ pub fn main() !void {
2225
std.process.exit(1);
2326
}
2427

25-
var input_buffer: [1024]u8 = undefined;
26-
const input_len = try stdin.read(&input_buffer);
27-
const input_slice = input_buffer[0..input_len];
28+
const input_slice = try stdin.takeDelimiter('\n');
2829

2930
const pattern = args[2];
30-
if (matchPattern(input_slice, pattern)) {
31+
if (matchPattern(input_slice.?, pattern)) {
3132
std.process.exit(0);
3233
} else {
3334
std.process.exit(1);

solutions/zig/01-cq2/diff/src/main.zig.diff

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
@@ -1,40 +1,35 @@
2-
const std = @import("std");
3-
var stdin = std.fs.File.stdin().readerStreaming(&.{});
1+
@@ -3,39 +3,34 @@
2+
var stdin_buffer: [4096]u8 = undefined;
3+
var stdin_reader = std.fs.File.stdin().readerStreaming(&stdin_buffer);
4+
const stdin = &stdin_reader.interface;
45

56
fn matchPattern(input_line: []const u8, pattern: []const u8) bool {
67
if (pattern.len == 1) {
@@ -25,24 +26,20 @@
2526

2627
- // You can use print statements as follows for debugging, they'll be visible when running tests.
2728
- std.debug.print("Logs from your program will appear here!\n", .{});
28-
+ var input_buffer: [1024]u8 = undefined;
29-
+ const input_len = try stdin.read(&input_buffer);
30-
+ const input_slice = input_buffer[0..input_len];
29+
+ const input_slice = try stdin.takeDelimiter('\n');
3130

3231
- // TODO: Uncomment the code below to pass the first stage
3332
- //
34-
- // var input_buffer: [1024]u8 = undefined;
35-
- // const input_len = try stdin.read(&input_buffer);
36-
- // const input_slice = input_buffer[0..input_len];
33+
- // const input_slice = try stdin.takeDelimiter('\n');
3734
- //
3835
- // const pattern = args[2];
39-
- // if (matchPattern(input_slice, pattern)) {
36+
- // if (matchPattern(input_slice.?, pattern)) {
4037
- // std.process.exit(0);
4138
- // } else {
4239
- // std.process.exit(1);
4340
- // }
4441
+ const pattern = args[2];
45-
+ if (matchPattern(input_slice, pattern)) {
42+
+ if (matchPattern(input_slice.?, pattern)) {
4643
+ std.process.exit(0);
4744
+ } else {
4845
+ std.process.exit(1);

starter_templates/zig/code/src/main.zig

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
const std = @import("std");
2-
var stdin = std.fs.File.stdin().readerStreaming(&.{});
2+
3+
var stdin_buffer: [4096]u8 = undefined;
4+
var stdin_reader = std.fs.File.stdin().readerStreaming(&stdin_buffer);
5+
const stdin = &stdin_reader.interface;
36

47
fn matchPattern(input_line: []const u8, pattern: []const u8) bool {
58
if (pattern.len == 1) {
@@ -27,12 +30,10 @@ pub fn main() !void {
2730

2831
// TODO: Uncomment the code below to pass the first stage
2932
//
30-
// var input_buffer: [1024]u8 = undefined;
31-
// const input_len = try stdin.read(&input_buffer);
32-
// const input_slice = input_buffer[0..input_len];
33+
// const input_slice = try stdin.takeDelimiter('\n');
3334
//
3435
// const pattern = args[2];
35-
// if (matchPattern(input_slice, pattern)) {
36+
// if (matchPattern(input_slice.?, pattern)) {
3637
// std.process.exit(0);
3738
// } else {
3839
// std.process.exit(1);

0 commit comments

Comments
 (0)