From 9ae739c4c95aec30e2ac4c49d0dc879ff4b5d169 Mon Sep 17 00:00:00 2001 From: Arnold Filip Date: Mon, 21 Jul 2025 15:00:15 +0200 Subject: [PATCH 1/9] Fix zig 0.15.0-dev.1149+4e6a04929 build errors --- build.zig | 11 +++++------ test/tests.zig | 11 +++++++---- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/build.zig b/build.zig index 6c76917..7522dee 100644 --- a/build.zig +++ b/build.zig @@ -126,19 +126,18 @@ pub fn build(b: *Build) !void { if (!validate_exercises()) std.process.exit(2); use_color_escapes = false; - if (std.io.getStdErr().supportsAnsiEscapeCodes()) { + if (std.fs.File.stderr().supportsAnsiEscapeCodes()) { use_color_escapes = true; } else if (builtin.os.tag == .windows) { const w32 = struct { - const WINAPI = std.os.windows.WINAPI; const DWORD = std.os.windows.DWORD; const ENABLE_VIRTUAL_TERMINAL_PROCESSING = 0x0004; const STD_ERROR_HANDLE: DWORD = @bitCast(@as(i32, -12)); - extern "kernel32" fn GetStdHandle(id: DWORD) callconv(WINAPI) ?*anyopaque; - extern "kernel32" fn GetConsoleMode(console: ?*anyopaque, out_mode: *DWORD) callconv(WINAPI) u32; - extern "kernel32" fn SetConsoleMode(console: ?*anyopaque, mode: DWORD) callconv(WINAPI) u32; + const GetStdHandle = std.os.windows.kernel32.GetStdHandle; + const GetConsoleMode = std.os.windows.kernel32.GetConsoleMode; + const SetConsoleMode = std.os.windows.kernel32.SetConsoleMode; }; - const handle = w32.GetStdHandle(w32.STD_ERROR_HANDLE); + const handle = w32.GetStdHandle(w32.STD_ERROR_HANDLE).?; var mode: w32.DWORD = 0; if (w32.GetConsoleMode(handle, &mode) != 0) { mode |= w32.ENABLE_VIRTUAL_TERMINAL_PROCESSING; diff --git a/test/tests.zig b/test/tests.zig index 5f64f8e..42c3653 100644 --- a/test/tests.zig +++ b/test/tests.zig @@ -161,7 +161,8 @@ const CheckNamedStep = struct { ); defer stderr_file.close(); - const stderr = stderr_file.reader(); + var buffer: [4096]u8 = undefined; + const stderr = stderr_file.reader(&buffer); { // Skip the logo. const nlines = mem.count(u8, root.logo, "\n"); @@ -213,7 +214,8 @@ const CheckStep = struct { ); defer stderr_file.close(); - const stderr = stderr_file.reader(); + var buffer: [4096]u8 = undefined; + const stderr = stderr_file.reader(&buffer); for (exercises) |ex| { if (ex.number() == 1) { // Skip the logo. @@ -298,7 +300,7 @@ fn check( } fn readLine(reader: fs.File.Reader, buf: []u8) !?[]const u8 { - if (try reader.readUntilDelimiterOrEof(buf, '\n')) |line| { + if (try reader.file.deprecatedReader().readUntilDelimiterOrEof(buf, '\n')) |line| { return mem.trimRight(u8, line, " \r\n"); } @@ -405,7 +407,8 @@ fn heal(allocator: Allocator, exercises: []const Exercise, work_path: []const u8 /// difference that returns an error when the temp path cannot be created. pub fn makeTempPath(b: *Build) ![]const u8 { const rand_int = std.crypto.random.int(u64); - const tmp_dir_sub_path = "tmp" ++ fs.path.sep_str ++ Build.hex64(rand_int); + const rand_hex64 = std.fmt.hex(rand_int); + const tmp_dir_sub_path = "tmp" ++ fs.path.sep_str ++ rand_hex64; const path = b.cache_root.join(b.allocator, &.{tmp_dir_sub_path}) catch @panic("OOM"); try b.cache_root.handle.makePath(tmp_dir_sub_path); From 49e73db5f5e139b610306ec6495aa6889eb83170 Mon Sep 17 00:00:00 2001 From: Chris Boesch Date: Tue, 22 Jul 2025 00:28:03 +0200 Subject: [PATCH 2/9] Switched to new reader version --- test/tests.zig | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/test/tests.zig b/test/tests.zig index 42c3653..b191610 100644 --- a/test/tests.zig +++ b/test/tests.zig @@ -161,8 +161,7 @@ const CheckNamedStep = struct { ); defer stderr_file.close(); - var buffer: [4096]u8 = undefined; - const stderr = stderr_file.reader(&buffer); + var stderr = stderr_file.readerStreaming(&.{}); { // Skip the logo. const nlines = mem.count(u8, root.logo, "\n"); @@ -170,10 +169,10 @@ const CheckNamedStep = struct { var lineno: usize = 0; while (lineno < nlines) : (lineno += 1) { - _ = try readLine(stderr, &buf); + _ = try readLine(&stderr, &buf); } } - try check_output(step, ex, stderr); + try check_output(step, ex, &stderr); } }; @@ -214,8 +213,7 @@ const CheckStep = struct { ); defer stderr_file.close(); - var buffer: [4096]u8 = undefined; - const stderr = stderr_file.reader(&buffer); + var stderr = stderr_file.readerStreaming(&.{}); for (exercises) |ex| { if (ex.number() == 1) { // Skip the logo. @@ -224,15 +222,15 @@ const CheckStep = struct { var lineno: usize = 0; while (lineno < nlines) : (lineno += 1) { - _ = try readLine(stderr, &buf); + _ = try readLine(&stderr, &buf); } } - try check_output(step, ex, stderr); + try check_output(step, ex, &stderr); } } }; -fn check_output(step: *Step, exercise: Exercise, reader: Reader) !void { +fn check_output(step: *Step, exercise: Exercise, reader: *Reader) !void { const b = step.owner; var buf: [1024]u8 = undefined; @@ -299,12 +297,9 @@ fn check( } } -fn readLine(reader: fs.File.Reader, buf: []u8) !?[]const u8 { - if (try reader.file.deprecatedReader().readUntilDelimiterOrEof(buf, '\n')) |line| { - return mem.trimRight(u8, line, " \r\n"); - } - - return null; +fn readLine(reader: *fs.File.Reader, buf: []u8) !?[]const u8 { + try reader.interface.readSliceAll(buf); + return mem.trimRight(u8, buf, " \r\n"); } /// Fails with a custom error message. From b499788606d83aac75e82da2d32b5b7ceb3d6896 Mon Sep 17 00:00:00 2001 From: Chris Boesch Date: Tue, 22 Jul 2025 00:40:06 +0200 Subject: [PATCH 3/9] Corrected the necessary Zig version --- build.zig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.zig b/build.zig index 7522dee..ebe6838 100644 --- a/build.zig +++ b/build.zig @@ -15,7 +15,7 @@ const print = std.debug.print; // 1) Getting Started // 2) Version Changes comptime { - const required_zig = "0.14.0-dev.1573"; + const required_zig = "0.15.0-dev.1092"; const current_zig = builtin.zig_version; const min_zig = std.SemanticVersion.parse(required_zig) catch unreachable; if (current_zig.order(min_zig) == .lt) { From f21f8f7863f512aed8ae0418351756819990df67 Mon Sep 17 00:00:00 2001 From: Arnold Filip Date: Tue, 22 Jul 2025 09:17:24 +0200 Subject: [PATCH 4/9] Update stdout writer usage to use std.fs.File --- exercises/026_hello2.zig | 4 ++-- exercises/034_quiz4.zig | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/exercises/026_hello2.zig b/exercises/026_hello2.zig index cd59b86..582dba9 100644 --- a/exercises/026_hello2.zig +++ b/exercises/026_hello2.zig @@ -16,12 +16,12 @@ const std = @import("std"); // pub fn main() !void { // We get a Writer for Standard Out so we can print() to it. - const stdout = std.io.getStdOut().writer(); + var stdout = std.fs.File.stdout().writer(&.{}); // Unlike std.debug.print(), the Standard Out writer can fail // with an error. We don't care _what_ the error is, we want // to be able to pass it up as a return value of main(). // // We just learned of a single statement which can accomplish this. - stdout.print("Hello world!\n", .{}); + stdout.interface.print("Hello world!\n", .{}); } diff --git a/exercises/034_quiz4.zig b/exercises/034_quiz4.zig index 2d843f2..8704397 100644 --- a/exercises/034_quiz4.zig +++ b/exercises/034_quiz4.zig @@ -10,11 +10,11 @@ const std = @import("std"); const NumError = error{IllegalNumber}; pub fn main() void { - const stdout = std.io.getStdOut().writer(); + var stdout = std.fs.File.stdout().writer(&.{}); const my_num: u32 = getNumber(); - try stdout.print("my_num={}\n", .{my_num}); + try stdout.interface.print("my_num={}\n", .{my_num}); } // This function is obviously weird and non-functional. But you will not be changing it for this quiz. From ed2f76e9600ce63405a5b4de0d7a2ea9f21cf4a6 Mon Sep 17 00:00:00 2001 From: Chris Boesch Date: Tue, 22 Jul 2025 10:08:24 +0200 Subject: [PATCH 5/9] Added patch files. --- patches/patches/026_hello2.patch | 8 ++++---- patches/patches/034_quiz4.patch | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/patches/patches/026_hello2.patch b/patches/patches/026_hello2.patch index f0224a1..f99cc67 100644 --- a/patches/patches/026_hello2.patch +++ b/patches/patches/026_hello2.patch @@ -1,9 +1,9 @@ ---- exercises/026_hello2.zig 2023-10-03 22:15:22.122241138 +0200 -+++ answers/026_hello2.zig 2023-10-05 20:04:06.959431737 +0200 +--- exercises/026_hello2.zig 2025-07-22 09:55:51.337832401 +0200 ++++ answers/026_hello2.zig 2025-07-22 10:00:11.233348058 +0200 @@ -23,5 +23,5 @@ // to be able to pass it up as a return value of main(). // // We just learned of a single statement which can accomplish this. -- stdout.print("Hello world!\n", .{}); -+ try stdout.print("Hello world!\n", .{}); +- stdout.interface.print("Hello world!\n", .{}); ++ try stdout.interface.print("Hello world!\n", .{}); } diff --git a/patches/patches/034_quiz4.patch b/patches/patches/034_quiz4.patch index 8c0bc0e..15c95fc 100644 --- a/patches/patches/034_quiz4.patch +++ b/patches/patches/034_quiz4.patch @@ -1,15 +1,15 @@ ---- exercises/034_quiz4.zig 2023-10-03 22:15:22.122241138 +0200 -+++ answers/034_quiz4.zig 2023-10-05 20:04:06.996099091 +0200 +--- exercises/034_quiz4.zig 2025-07-22 09:55:51.337832401 +0200 ++++ answers/034_quiz4.zig 2025-07-22 10:05:08.320323184 +0200 @@ -9,10 +9,10 @@ const NumError = error{IllegalNumber}; -pub fn main() void { +pub fn main() !void { - const stdout = std.io.getStdOut().writer(); + var stdout = std.fs.File.stdout().writer(&.{}); - const my_num: u32 = getNumber(); + const my_num: u32 = try getNumber(); - try stdout.print("my_num={}\n", .{my_num}); + try stdout.interface.print("my_num={}\n", .{my_num}); } From 54f48c75c415f03acba5c3744454e7e9e45840d4 Mon Sep 17 00:00:00 2001 From: Chris Boesch Date: Tue, 22 Jul 2025 10:16:17 +0200 Subject: [PATCH 6/9] Fixed 82 --- build.zig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.zig b/build.zig index ebe6838..f3dd2d2 100644 --- a/build.zig +++ b/build.zig @@ -1063,7 +1063,7 @@ const exercises = [_]Exercise{ .{ .main_file = "082_anonymous_structs3.zig", .output = - \\"0"(bool):true "1"(bool):false "2"(i32):42 "3"(f32):3.141592e0 + \\"0"(bool):true "1"(bool):false "2"(i32):42 "3"(f32):3.141592 , .hint = "This one is a challenge! But you have everything you need.", }, From 0d06220ec5d0623cef4d90a019040a984e9317f5 Mon Sep 17 00:00:00 2001 From: Chris Boesch Date: Tue, 22 Jul 2025 10:24:22 +0200 Subject: [PATCH 7/9] Fixed 98 --- exercises/098_bit_manipulation2.zig | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/exercises/098_bit_manipulation2.zig b/exercises/098_bit_manipulation2.zig index 979b103..8b51265 100644 --- a/exercises/098_bit_manipulation2.zig +++ b/exercises/098_bit_manipulation2.zig @@ -32,7 +32,7 @@ const print = std.debug.print; pub fn main() !void { // let's check the pangram - print("Is this a pangram? {?}!\n", .{isPangram("The quick brown fox jumps over the lazy dog.")}); + print("Is this a pangram? {}!\n", .{isPangram("The quick brown fox jumps over the lazy dog.")}); } fn isPangram(str: []const u8) bool { @@ -45,7 +45,7 @@ fn isPangram(str: []const u8) bool { // loop about all characters in the string for (str) |c| { // if the character is an alphabetical character - if (ascii.isASCII(c) and ascii.isAlphabetic(c)) { + if (ascii.isAscii(c) and ascii.isAlphabetic(c)) { // then we set the bit at the position // // to do this, we use a little trick: From f4619868961828bc943cd29d4e2c99edd76fbb00 Mon Sep 17 00:00:00 2001 From: Chris Boesch Date: Tue, 22 Jul 2025 10:30:19 +0200 Subject: [PATCH 8/9] Fixed 104 --- exercises/104_threading.zig | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/exercises/104_threading.zig b/exercises/104_threading.zig index 9c4e216..638769f 100644 --- a/exercises/104_threading.zig +++ b/exercises/104_threading.zig @@ -106,7 +106,7 @@ pub fn main() !void { // After the threads have been started, // they run in parallel and we can still do some work in between. - std.time.sleep(1500 * std.time.ns_per_ms); + std.Thread.sleep(1500 * std.time.ns_per_ms); std.debug.print("Some weird stuff, after starting the threads.\n", .{}); } // After we have left the closed area, we wait until @@ -117,12 +117,12 @@ pub fn main() !void { // This function is started with every thread that we set up. // In our example, we pass the number of the thread as a parameter. fn thread_function(num: usize) !void { - std.time.sleep(200 * num * std.time.ns_per_ms); + std.Thread.sleep(200 * num * std.time.ns_per_ms); std.debug.print("thread {d}: {s}\n", .{ num, "started." }); // This timer simulates the work of the thread. const work_time = 3 * ((5 - num % 3) - 2); - std.time.sleep(work_time * std.time.ns_per_s); + std.Thread.sleep(work_time * std.time.ns_per_s); std.debug.print("thread {d}: {s}\n", .{ num, "finished." }); } From 4044b93dd210cb3eb8c1993f2be0e286c4383f2f Mon Sep 17 00:00:00 2001 From: Chris Boesch Date: Tue, 22 Jul 2025 10:45:09 +0200 Subject: [PATCH 9/9] Added Readme --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index a6e760f..b497666 100644 --- a/README.md +++ b/README.md @@ -87,7 +87,8 @@ that if you update one, you may need to also update the other. ### Version Changes -Version-0.14.0-dev.1573 +Version-0.15.0-dev.1092 +* *2025-07-22* zig 0.15.0-dev.1092 - various changes due to new I/O API, see [#24488](https://github.com/ziglang/zig/pull/24488) * *2024-09-16* zig 0.14.0-dev.1573 - introduction of labeled switch, see [#21257](https://github.com/ziglang/zig/pull/21257) * *2024-09-02* zig 0.14.0-dev.1409 - several changes in std.builtin, see [#21225](https://github.com/ziglang/zig/pull/21225) * *2024-08-04* zig 0.14.0-dev.1224 - several changes in build system, see [#21115](https://github.com/ziglang/zig/pull/21115)