Skip to content

Commit fd89bfa

Browse files
authored
Fix(CI): Update CI to the Zig 0.16.0 development cycle. (#178)
* fix(ci): follow the Zig 0.16.0 release cycle * fix(ci): remove use of FixedBufferStream * fix(interpreter): EndOfStream should exit gracefully * fix(examples): remove TODOs since Zig 0.15 is released * fix(ci): reenable lua 5.1 testing * fix(build): avoid readToEndAlloc in patch.zig
1 parent bf9fc6e commit fd89bfa

File tree

5 files changed

+28
-39
lines changed

5 files changed

+28
-39
lines changed

.github/workflows/tests.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ jobs:
2727
- name: Run tests
2828
run: make test_zig_nightly
2929

30-
#------ zig-0.14 ------
31-
test_zig_014:
30+
#------ zig-0.15 ------
31+
test_zig_015:
3232
strategy:
3333
matrix:
3434
os: [ubuntu-latest, macos-latest, windows-latest, ubuntu-24.04-arm]
@@ -42,10 +42,10 @@ jobs:
4242
- name: Setup Zig
4343
uses: mlugg/setup-zig@v2
4444
with:
45-
version: "0.14.1"
45+
version: "0.15.1"
4646

4747
- name: Run tests
48-
run: make test_zig_014
48+
run: make test_zig_stable
4949

5050
#------ cross compilation ------
5151
test_cross:

build/patch.zig

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ pub fn main() !void {
1717
const patch_file = patch_file: {
1818
const patch_file = try std.fs.cwd().openFile(patch_file_path, .{ .mode = .read_only });
1919
defer patch_file.close();
20-
break :patch_file try patch_file.readToEndAlloc(allocator, std.math.maxInt(usize));
20+
var buf: [4096]u8 = undefined;
21+
var reader = patch_file.reader(&buf);
22+
break :patch_file try reader.interface.allocRemaining(allocator, .unlimited);
2123
};
2224
const chunk_details = Chunk.init(allocator, patch_file, 0) orelse @panic("No chunk data found");
2325

examples/interpreter.zig

Lines changed: 14 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -9,38 +9,23 @@ const zlua = @import("zlua");
99
const ReadError = error{BufferTooSmall};
1010

1111
fn readlineStdin(out_buf: []u8) anyerror!usize {
12-
const builtin = @import("builtin");
13-
// Backwards compatibility with zig-0.14
14-
// TODO remove when zig-0.15 is released
15-
if (builtin.zig_version.major == 0 and builtin.zig_version.minor < 15) {
16-
var stdin = std.io.getStdIn().reader();
17-
return try stdin.read(out_buf);
18-
} else {
19-
var in_buf: [4096]u8 = undefined;
20-
var stdin_file = std.fs.File.stdin().reader(&in_buf);
21-
const stdin = &stdin_file.interface;
22-
const s = try stdin.takeDelimiterExclusive('\n');
23-
if (s.len < out_buf.len) {
24-
@memcpy(out_buf[0..s.len], s);
25-
return s.len;
26-
}
27-
return error.BufferTooSmall;
12+
var in_buf: [4096]u8 = undefined;
13+
var stdin_file = std.fs.File.stdin().reader(&in_buf);
14+
const stdin = &stdin_file.interface;
15+
const s = try stdin.takeDelimiterExclusive('\n');
16+
if (s.len < out_buf.len) {
17+
@memcpy(out_buf[0..s.len], s);
18+
return s.len;
2819
}
20+
return error.BufferTooSmall;
2921
}
3022

3123
fn flushedStdoutPrint(comptime fmt: []const u8, args: anytype) !void {
32-
const builtin = @import("builtin");
33-
// Backwards compatibility with zig-0.14
34-
// TODO remove when zig-0.15 is released
35-
if (builtin.zig_version.major == 0 and builtin.zig_version.minor < 15) {
36-
try std.io.getStdOut().writer().print(fmt, args);
37-
} else {
38-
var out_buf: [4096]u8 = undefined;
39-
var w = std.fs.File.stdout().writer(&out_buf);
40-
const stdout = &w.interface;
41-
try stdout.print(fmt, args);
42-
try stdout.flush();
43-
}
24+
var out_buf: [4096]u8 = undefined;
25+
var w = std.fs.File.stdout().writer(&out_buf);
26+
const stdout = &w.interface;
27+
try stdout.print(fmt, args);
28+
try stdout.flush();
4429
}
4530

4631
pub fn main() anyerror!void {
@@ -68,6 +53,7 @@ pub fn main() anyerror!void {
6853
try flushedStdoutPrint("error: line too long!\n", .{});
6954
continue;
7055
},
56+
error.EndOfStream => break,
7157
else => return err,
7258
}
7359
};

makefile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@ test_zig_nightly:
1313

1414
zig build -Dlang=luajit
1515

16-
# A subset of tests that are expected to work also on zig-0.14
17-
test_zig_014:
16+
# A subset of tests that are expected to work also on stable builds of zig
17+
test_zig_stable:
18+
zig build test --summary failures -Dlang=lua51
1819
zig build test --summary failures -Dlang=lua52
1920
zig build test --summary failures -Dlang=lua53
2021
zig build test --summary failures -Dlang=lua54

src/tests.zig

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2987,16 +2987,16 @@ test "define" {
29872987
_ = try zlua.def.addClass(&state, a, my_type);
29882988
}
29892989

2990-
var buffer: [10000]u8 = .{0} ** 10000;
2991-
var buffer_stream = std.io.fixedBufferStream(&buffer);
2992-
var writer = buffer_stream.writer();
2990+
var buffer: [10000]u8 = @splat(0);
2991+
var writer: std.Io.Writer = .failing;
2992+
writer.buffer = &buffer;
29932993

29942994
for (state.definitions.items) |def| {
29952995
try writer.writeAll(def.items);
29962996
try writer.writeAll("\n");
29972997
}
29982998

2999-
try std.testing.expectEqualSlices(u8, expected, buffer_stream.getWritten());
2999+
try std.testing.expectEqualSlices(u8, expected, buffer[0..writer.end]);
30003000
}
30013001

30023002
test "interrupt" {

0 commit comments

Comments
 (0)