Skip to content

Commit 1ffecd9

Browse files
authored
Merge pull request #144 from codecrafters-io/andy/upgrade-zig
[sqlite] CC-1935: Upgrade Zig to v0.15
2 parents 19f57a3 + eb6ff5b commit 1ffecd9

File tree

22 files changed

+94
-37
lines changed

22 files changed

+94
-37
lines changed

compiled_starters/zig/.codecrafters/run.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@
88

99
set -e # Exit on failure
1010

11-
exec $(dirname $0)/zig-out/bin/main "$@"
11+
exec "$(dirname "$0")"/zig-out/bin/main "$@"

compiled_starters/zig/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ Time to move on to the next stage!
2929

3030
Note: This section is for stages 2 and beyond.
3131

32-
1. Ensure you have `zig (0.14)` installed locally
32+
1. Ensure you have `zig (0.15)` installed locally
3333
1. Run `./your_program.sh` to run your program, which is implemented in
3434
`src/main.zig`.
3535
1. Commit your changes and run `git push origin master` to submit your solution

compiled_starters/zig/build.zig

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@ const std = @import("std");
44
pub fn build(b: *std.Build) void {
55
const exe = b.addExecutable(.{
66
.name = "main",
7-
.root_source_file = b.path("src/main.zig"),
8-
.target = b.standardTargetOptions(.{}),
9-
.optimize = b.standardOptimizeOption(.{}),
7+
.root_module = b.createModule(.{
8+
.root_source_file = b.path("src/main.zig"),
9+
.target = b.graph.host,
10+
}),
1011
});
1112

1213
// This declares intent for the executable to be installed into the

compiled_starters/zig/build.zig.zon

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
// This field is optional.
1010
// This is currently advisory only; Zig does not yet do anything
1111
// with this value.
12-
.minimum_zig_version = "0.14.0",
12+
.minimum_zig_version = "0.15.1",
1313

1414
// This field is optional.
1515
// Each dependency must either provide a `url` and `hash`, or a `path`.

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.14
11-
buildpack: zig-0.14
10+
# Available versions: zig-0.15
11+
buildpack: zig-0.15

compiled_starters/zig/src/main.zig

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,13 @@ pub fn main() !void {
88
const args = try std.process.argsAlloc(allocator);
99
defer std.process.argsFree(allocator, args);
1010

11+
var stdout_buffer: [1024]u8 = undefined;
12+
var stdout_writer = std.fs.File.stdout().writer(&stdout_buffer);
13+
const stdout = &stdout_writer.interface;
14+
1115
if (args.len < 3) {
12-
try std.io.getStdErr().writer().print("Usage: {s} <database_file_path> <command>\n", .{args[0]});
16+
try stdout.print("Usage: {s} <database_file_path> <command>\n", .{args[0]});
17+
try stdout.flush();
1318
return;
1419
}
1520

@@ -28,6 +33,7 @@ pub fn main() !void {
2833
// _ = try file.seekTo(16);
2934
// _ = try file.read(&buf);
3035
// const page_size = std.mem.readInt(u16, &buf, .big);
31-
// try std.io.getStdOut().writer().print("database page size: {}\n", .{page_size});
36+
// try stdout.print("database page size: {}\n", .{page_size});
37+
// try stdout.flush();
3238
}
3339
}

compiled_starters/zig/your_program.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,4 @@ set -e # Exit early if any commands fail
2121
#
2222
# - Edit this to change how your program runs locally
2323
# - Edit .codecrafters/run.sh to change how your program runs remotely
24-
exec $(dirname $0)/zig-out/bin/main "$@"
24+
exec "$(dirname "$0")"/zig-out/bin/main "$@"

dockerfiles/zig-0.15.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.1/zig-x86_64-linux-0.15.1.tar.xz \
11+
&& tar -xf zig-x86_64-linux-0.15.1.tar.xz \
12+
&& mv zig-x86_64-linux-0.15.1 /usr/local/zig \
13+
&& rm zig-x86_64-linux-0.15.1.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-dr6/code/.codecrafters/run.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@
88

99
set -e # Exit on failure
1010

11-
exec $(dirname $0)/zig-out/bin/main "$@"
11+
exec "$(dirname "$0")"/zig-out/bin/main "$@"

solutions/zig/01-dr6/code/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ Time to move on to the next stage!
2929

3030
Note: This section is for stages 2 and beyond.
3131

32-
1. Ensure you have `zig (0.14)` installed locally
32+
1. Ensure you have `zig (0.15)` installed locally
3333
1. Run `./your_program.sh` to run your program, which is implemented in
3434
`src/main.zig`.
3535
1. Commit your changes and run `git push origin master` to submit your solution

0 commit comments

Comments
 (0)