diff --git a/compiled_starters/zig/.codecrafters/run.sh b/compiled_starters/zig/.codecrafters/run.sh index b7cab59..18ffaf9 100755 --- a/compiled_starters/zig/.codecrafters/run.sh +++ b/compiled_starters/zig/.codecrafters/run.sh @@ -8,4 +8,4 @@ set -e # Exit on failure -exec $(dirname $0)/zig-out/bin/main "$@" +exec "$(dirname "$0")"/zig-out/bin/main "$@" diff --git a/compiled_starters/zig/README.md b/compiled_starters/zig/README.md index 56373de..1affc4f 100644 --- a/compiled_starters/zig/README.md +++ b/compiled_starters/zig/README.md @@ -29,7 +29,7 @@ Time to move on to the next stage! Note: This section is for stages 2 and beyond. -1. Ensure you have `zig (0.14)` installed locally +1. Ensure you have `zig (0.15)` installed locally 1. Run `./your_program.sh` to run your program, which is implemented in `src/main.zig`. 1. Commit your changes and run `git push origin master` to submit your solution diff --git a/compiled_starters/zig/build.zig b/compiled_starters/zig/build.zig index d211b57..0eccf2a 100644 --- a/compiled_starters/zig/build.zig +++ b/compiled_starters/zig/build.zig @@ -4,9 +4,10 @@ const std = @import("std"); pub fn build(b: *std.Build) void { const exe = b.addExecutable(.{ .name = "main", - .root_source_file = b.path("src/main.zig"), - .target = b.standardTargetOptions(.{}), - .optimize = b.standardOptimizeOption(.{}), + .root_module = b.createModule(.{ + .root_source_file = b.path("src/main.zig"), + .target = b.graph.host, + }), }); // This declares intent for the executable to be installed into the diff --git a/compiled_starters/zig/build.zig.zon b/compiled_starters/zig/build.zig.zon index 6f04e8a..8891635 100644 --- a/compiled_starters/zig/build.zig.zon +++ b/compiled_starters/zig/build.zig.zon @@ -9,7 +9,7 @@ // This field is optional. // This is currently advisory only; Zig does not yet do anything // with this value. - .minimum_zig_version = "0.14.0", + .minimum_zig_version = "0.15.1", // This field is optional. // Each dependency must either provide a `url` and `hash`, or a `path`. diff --git a/compiled_starters/zig/codecrafters.yml b/compiled_starters/zig/codecrafters.yml index 7bb803b..77a7f76 100644 --- a/compiled_starters/zig/codecrafters.yml +++ b/compiled_starters/zig/codecrafters.yml @@ -7,5 +7,5 @@ debug: false # Use this to change the Zig version used to run your code # on Codecrafters. # -# Available versions: zig-0.14 -buildpack: zig-0.14 +# Available versions: zig-0.15 +buildpack: zig-0.15 diff --git a/compiled_starters/zig/src/main.zig b/compiled_starters/zig/src/main.zig index c31a418..e5d80df 100755 --- a/compiled_starters/zig/src/main.zig +++ b/compiled_starters/zig/src/main.zig @@ -8,8 +8,13 @@ pub fn main() !void { const args = try std.process.argsAlloc(allocator); defer std.process.argsFree(allocator, args); + var stdout_buffer: [1024]u8 = undefined; + var stdout_writer = std.fs.File.stdout().writer(&stdout_buffer); + const stdout = &stdout_writer.interface; + if (args.len < 3) { - try std.io.getStdErr().writer().print("Usage: {s} \n", .{args[0]}); + try stdout.print("Usage: {s} \n", .{args[0]}); + try stdout.flush(); return; } @@ -28,6 +33,7 @@ pub fn main() !void { // _ = try file.seekTo(16); // _ = try file.read(&buf); // const page_size = std.mem.readInt(u16, &buf, .big); - // try std.io.getStdOut().writer().print("database page size: {}\n", .{page_size}); + // try stdout.print("database page size: {}\n", .{page_size}); + // try stdout.flush(); } } diff --git a/compiled_starters/zig/your_program.sh b/compiled_starters/zig/your_program.sh index cb84633..9691601 100755 --- a/compiled_starters/zig/your_program.sh +++ b/compiled_starters/zig/your_program.sh @@ -21,4 +21,4 @@ set -e # Exit early if any commands fail # # - Edit this to change how your program runs locally # - Edit .codecrafters/run.sh to change how your program runs remotely -exec $(dirname $0)/zig-out/bin/main "$@" +exec "$(dirname "$0")"/zig-out/bin/main "$@" diff --git a/dockerfiles/zig-0.15.Dockerfile b/dockerfiles/zig-0.15.Dockerfile new file mode 100644 index 0000000..1bb31e8 --- /dev/null +++ b/dockerfiles/zig-0.15.Dockerfile @@ -0,0 +1,30 @@ +# syntax=docker/dockerfile:1.7-labs +FROM debian:bookworm + +RUN apt-get update && \ + apt-get install --no-install-recommends -y xz-utils=5.4.1-1 && \ + apt-get clean && \ + rm -rf /var/lib/apt/lists/* + +# Download and install Zig +RUN curl -O https://ziglang.org/download/0.15.1/zig-x86_64-linux-0.15.1.tar.xz \ + && tar -xf zig-x86_64-linux-0.15.1.tar.xz \ + && mv zig-x86_64-linux-0.15.1 /usr/local/zig \ + && rm zig-x86_64-linux-0.15.1.tar.xz + +# Add Zig to PATH +ENV PATH="/usr/local/zig:${PATH}" + +ENV CODECRAFTERS_DEPENDENCY_FILE_PATHS="build.zig,build.zig.zon" + +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 + +# This runs zig build +RUN .codecrafters/compile.sh + +# Cache build directory +RUN mkdir -p /app-cached +RUN mv /app/.zig-cache /app-cached/.zig-cache || true diff --git a/solutions/zig/01-dr6/code/.codecrafters/run.sh b/solutions/zig/01-dr6/code/.codecrafters/run.sh index b7cab59..18ffaf9 100755 --- a/solutions/zig/01-dr6/code/.codecrafters/run.sh +++ b/solutions/zig/01-dr6/code/.codecrafters/run.sh @@ -8,4 +8,4 @@ set -e # Exit on failure -exec $(dirname $0)/zig-out/bin/main "$@" +exec "$(dirname "$0")"/zig-out/bin/main "$@" diff --git a/solutions/zig/01-dr6/code/README.md b/solutions/zig/01-dr6/code/README.md index 56373de..1affc4f 100644 --- a/solutions/zig/01-dr6/code/README.md +++ b/solutions/zig/01-dr6/code/README.md @@ -29,7 +29,7 @@ Time to move on to the next stage! Note: This section is for stages 2 and beyond. -1. Ensure you have `zig (0.14)` installed locally +1. Ensure you have `zig (0.15)` installed locally 1. Run `./your_program.sh` to run your program, which is implemented in `src/main.zig`. 1. Commit your changes and run `git push origin master` to submit your solution diff --git a/solutions/zig/01-dr6/code/build.zig b/solutions/zig/01-dr6/code/build.zig index d211b57..0eccf2a 100644 --- a/solutions/zig/01-dr6/code/build.zig +++ b/solutions/zig/01-dr6/code/build.zig @@ -4,9 +4,10 @@ const std = @import("std"); pub fn build(b: *std.Build) void { const exe = b.addExecutable(.{ .name = "main", - .root_source_file = b.path("src/main.zig"), - .target = b.standardTargetOptions(.{}), - .optimize = b.standardOptimizeOption(.{}), + .root_module = b.createModule(.{ + .root_source_file = b.path("src/main.zig"), + .target = b.graph.host, + }), }); // This declares intent for the executable to be installed into the diff --git a/solutions/zig/01-dr6/code/build.zig.zon b/solutions/zig/01-dr6/code/build.zig.zon index 6f04e8a..8891635 100644 --- a/solutions/zig/01-dr6/code/build.zig.zon +++ b/solutions/zig/01-dr6/code/build.zig.zon @@ -9,7 +9,7 @@ // This field is optional. // This is currently advisory only; Zig does not yet do anything // with this value. - .minimum_zig_version = "0.14.0", + .minimum_zig_version = "0.15.1", // This field is optional. // Each dependency must either provide a `url` and `hash`, or a `path`. diff --git a/solutions/zig/01-dr6/code/codecrafters.yml b/solutions/zig/01-dr6/code/codecrafters.yml index 7bb803b..77a7f76 100644 --- a/solutions/zig/01-dr6/code/codecrafters.yml +++ b/solutions/zig/01-dr6/code/codecrafters.yml @@ -7,5 +7,5 @@ debug: false # Use this to change the Zig version used to run your code # on Codecrafters. # -# Available versions: zig-0.14 -buildpack: zig-0.14 +# Available versions: zig-0.15 +buildpack: zig-0.15 diff --git a/solutions/zig/01-dr6/code/src/main.zig b/solutions/zig/01-dr6/code/src/main.zig index 6c09beb..26d9aee 100755 --- a/solutions/zig/01-dr6/code/src/main.zig +++ b/solutions/zig/01-dr6/code/src/main.zig @@ -8,8 +8,13 @@ pub fn main() !void { const args = try std.process.argsAlloc(allocator); defer std.process.argsFree(allocator, args); + var stdout_buffer: [1024]u8 = undefined; + var stdout_writer = std.fs.File.stdout().writer(&stdout_buffer); + const stdout = &stdout_writer.interface; + if (args.len < 3) { - try std.io.getStdErr().writer().print("Usage: {s} \n", .{args[0]}); + try stdout.print("Usage: {s} \n", .{args[0]}); + try stdout.flush(); return; } @@ -24,6 +29,7 @@ pub fn main() !void { _ = try file.seekTo(16); _ = try file.read(&buf); const page_size = std.mem.readInt(u16, &buf, .big); - try std.io.getStdOut().writer().print("database page size: {}\n", .{page_size}); + try stdout.print("database page size: {}\n", .{page_size}); + try stdout.flush(); } } diff --git a/solutions/zig/01-dr6/code/your_program.sh b/solutions/zig/01-dr6/code/your_program.sh index cb84633..9691601 100755 --- a/solutions/zig/01-dr6/code/your_program.sh +++ b/solutions/zig/01-dr6/code/your_program.sh @@ -21,4 +21,4 @@ set -e # Exit early if any commands fail # # - Edit this to change how your program runs locally # - Edit .codecrafters/run.sh to change how your program runs remotely -exec $(dirname $0)/zig-out/bin/main "$@" +exec "$(dirname "$0")"/zig-out/bin/main "$@" diff --git a/solutions/zig/01-dr6/diff/src/main.zig.diff b/solutions/zig/01-dr6/diff/src/main.zig.diff index 39d27cc..c05a28a 100644 --- a/solutions/zig/01-dr6/diff/src/main.zig.diff +++ b/solutions/zig/01-dr6/diff/src/main.zig.diff @@ -1,6 +1,4 @@ -@@ -1,33 +1,29 @@ - const std = @import("std"); - +@@ -3,37 +3,33 @@ pub fn main() !void { var gpa = std.heap.GeneralPurposeAllocator(.{}){}; defer _ = gpa.deinit(); @@ -9,8 +7,13 @@ const args = try std.process.argsAlloc(allocator); defer std.process.argsFree(allocator, args); + var stdout_buffer: [1024]u8 = undefined; + var stdout_writer = std.fs.File.stdout().writer(&stdout_buffer); + const stdout = &stdout_writer.interface; + if (args.len < 3) { - try std.io.getStdErr().writer().print("Usage: {s} \n", .{args[0]}); + try stdout.print("Usage: {s} \n", .{args[0]}); + try stdout.flush(); return; } @@ -29,11 +32,13 @@ - // _ = try file.seekTo(16); - // _ = try file.read(&buf); - // const page_size = std.mem.readInt(u16, &buf, .big); -- // try std.io.getStdOut().writer().print("database page size: {}\n", .{page_size}); +- // try stdout.print("database page size: {}\n", .{page_size}); +- // try stdout.flush(); + var buf: [2]u8 = undefined; + _ = try file.seekTo(16); + _ = try file.read(&buf); + const page_size = std.mem.readInt(u16, &buf, .big); -+ try std.io.getStdOut().writer().print("database page size: {}\n", .{page_size}); ++ try stdout.print("database page size: {}\n", .{page_size}); ++ try stdout.flush(); } } diff --git a/solutions/zig/01-dr6/explanation.md b/solutions/zig/01-dr6/explanation.md index 0be4263..195b465 100644 --- a/solutions/zig/01-dr6/explanation.md +++ b/solutions/zig/01-dr6/explanation.md @@ -8,7 +8,8 @@ var buf: [2]u8 = undefined; _ = try file.seekTo(16); _ = try file.read(&buf); const page_size = std.mem.readInt(u16, &buf, .big); -try std.io.getStdOut().writer().print("database page size: {}\n", .{page_size}); +try stdout.print("database page size: {}\n", .{page_size}); +try stdout.flush(); ``` Push your changes to pass the first stage: diff --git a/starter_templates/zig/code/.codecrafters/run.sh b/starter_templates/zig/code/.codecrafters/run.sh index b7cab59..18ffaf9 100755 --- a/starter_templates/zig/code/.codecrafters/run.sh +++ b/starter_templates/zig/code/.codecrafters/run.sh @@ -8,4 +8,4 @@ set -e # Exit on failure -exec $(dirname $0)/zig-out/bin/main "$@" +exec "$(dirname "$0")"/zig-out/bin/main "$@" diff --git a/starter_templates/zig/code/build.zig b/starter_templates/zig/code/build.zig index d211b57..0eccf2a 100644 --- a/starter_templates/zig/code/build.zig +++ b/starter_templates/zig/code/build.zig @@ -4,9 +4,10 @@ const std = @import("std"); pub fn build(b: *std.Build) void { const exe = b.addExecutable(.{ .name = "main", - .root_source_file = b.path("src/main.zig"), - .target = b.standardTargetOptions(.{}), - .optimize = b.standardOptimizeOption(.{}), + .root_module = b.createModule(.{ + .root_source_file = b.path("src/main.zig"), + .target = b.graph.host, + }), }); // This declares intent for the executable to be installed into the diff --git a/starter_templates/zig/code/build.zig.zon b/starter_templates/zig/code/build.zig.zon index 6f04e8a..8891635 100644 --- a/starter_templates/zig/code/build.zig.zon +++ b/starter_templates/zig/code/build.zig.zon @@ -9,7 +9,7 @@ // This field is optional. // This is currently advisory only; Zig does not yet do anything // with this value. - .minimum_zig_version = "0.14.0", + .minimum_zig_version = "0.15.1", // This field is optional. // Each dependency must either provide a `url` and `hash`, or a `path`. diff --git a/starter_templates/zig/code/src/main.zig b/starter_templates/zig/code/src/main.zig index c31a418..e5d80df 100755 --- a/starter_templates/zig/code/src/main.zig +++ b/starter_templates/zig/code/src/main.zig @@ -8,8 +8,13 @@ pub fn main() !void { const args = try std.process.argsAlloc(allocator); defer std.process.argsFree(allocator, args); + var stdout_buffer: [1024]u8 = undefined; + var stdout_writer = std.fs.File.stdout().writer(&stdout_buffer); + const stdout = &stdout_writer.interface; + if (args.len < 3) { - try std.io.getStdErr().writer().print("Usage: {s} \n", .{args[0]}); + try stdout.print("Usage: {s} \n", .{args[0]}); + try stdout.flush(); return; } @@ -28,6 +33,7 @@ pub fn main() !void { // _ = try file.seekTo(16); // _ = try file.read(&buf); // const page_size = std.mem.readInt(u16, &buf, .big); - // try std.io.getStdOut().writer().print("database page size: {}\n", .{page_size}); + // try stdout.print("database page size: {}\n", .{page_size}); + // try stdout.flush(); } } diff --git a/starter_templates/zig/config.yml b/starter_templates/zig/config.yml index a113b98..fda894a 100644 --- a/starter_templates/zig/config.yml +++ b/starter_templates/zig/config.yml @@ -1,3 +1,3 @@ attributes: - required_executable: zig (0.14) + required_executable: zig (0.15) user_editable_file: src/main.zig