Skip to content

Commit 88e10b0

Browse files
committed
fix(ci): update to latest zig
1 parent d13d43e commit 88e10b0

File tree

4 files changed

+60
-30
lines changed

4 files changed

+60
-30
lines changed

.github/workflows/docs.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ jobs:
2727
uses: actions/configure-pages@v5
2828
- uses: mlugg/setup-zig@v1
2929
with:
30-
version: 0.15.0-dev.441+c1649d586
30+
version: 0.15.0-dev.1034+bd97b6618
3131
- run: make docs
3232
- name: Upload artifact
3333
uses: actions/upload-pages-artifact@v3

.github/workflows/tests.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ jobs:
1111
strategy:
1212
matrix:
1313
os: [ubuntu-latest, macos-latest, windows-latest]
14-
zig: ["0.14.0", "0.15.0-dev.441+c1649d586"]
14+
zig: ["0.14.0", "0.15.0-dev.1034+bd97b6618"]
1515

1616
runs-on: ${{matrix.os}}
1717

@@ -31,7 +31,7 @@ jobs:
3131
strategy:
3232
matrix:
3333
os: [ubuntu-latest, macos-latest, windows-latest]
34-
zig: ["0.14.0", "0.15.0-dev.441+c1649d586"]
34+
zig: ["0.14.0", "0.15.0-dev.1034+bd97b6618"]
3535

3636
runs-on: ${{matrix.os}}
3737

@@ -45,4 +45,4 @@ jobs:
4545
version: ${{ matrix.zig }}
4646

4747
- name: Run tests
48-
run: make test_cross
48+
run: make test_cross

build/patch.zig

Lines changed: 48 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,24 @@ pub fn main() !void {
1414
const patch_file_path = args[2];
1515
const output_path = args[3];
1616

17-
const patch_file = try std.fs.openFileAbsolute(patch_file_path, .{ .mode = .read_only });
18-
defer patch_file.close();
19-
const chunk_details = Chunk.next(allocator, patch_file) orelse @panic("No chunk data found");
17+
const patch_file = patch_file: {
18+
const patch_file = try std.fs.cwd().openFile(patch_file_path, .{ .mode = .read_only });
19+
defer patch_file.close();
20+
var patch_buf: [4096]u8 = undefined;
21+
var reader = patch_file.reader(&patch_buf);
22+
break :patch_file try reader.interface.allocRemaining(allocator, .unlimited);
23+
};
24+
const chunk_details = Chunk.init(allocator, patch_file, 0) orelse @panic("No chunk data found");
2025

21-
const file = try std.fs.openFileAbsolute(file_path, .{ .mode = .read_only });
26+
const file = try std.fs.cwd().openFile(file_path, .{ .mode = .read_only });
2227
defer file.close();
28+
var in_buf: [4096]u8 = undefined;
29+
var reader = file.reader(&in_buf);
2330

24-
const output = try std.fs.createFileAbsolute(output_path, .{});
31+
const output = try std.fs.cwd().createFile(output_path, .{});
2532
defer output.close();
33+
var out_buf: [4096]u8 = undefined;
34+
var writer = output.writer(&out_buf);
2635

2736
var state: State = .copy;
2837

@@ -32,26 +41,41 @@ pub fn main() !void {
3241

3342
switch (state) {
3443
.copy => {
35-
const line = getLine(allocator, file) orelse return;
36-
_ = try output.write(line);
37-
_ = try output.write("\n");
44+
_ = try reader.interface.streamDelimiterEnding(&writer.interface, '\n');
45+
_ = reader.interface.takeByte() catch |err| switch (err) {
46+
error.EndOfStream => {
47+
try writer.end();
48+
return;
49+
},
50+
else => return err,
51+
};
52+
try writer.interface.writeByte('\n');
3853
},
3954
.chunk => {
4055
const chunk = chunk_details.lines[line_number - chunk_details.src];
4156
switch (chunk.action) {
4257
.remove => {
43-
const line = getLine(allocator, file) orelse return;
58+
const line = reader.interface.takeDelimiterExclusive('\n') catch |err| switch (err) {
59+
error.EndOfStream => return,
60+
else => return err,
61+
};
4462
if (!std.mem.eql(u8, chunk.buf, line)) @panic("Failed to apply patch");
4563
},
4664
.keep => {
47-
const line = getLine(allocator, file) orelse return;
48-
if (!std.mem.eql(u8, chunk.buf, line)) @panic("Failed to apply patch");
49-
_ = try output.write(line);
50-
_ = try output.write("\n");
65+
const line = reader.interface.takeDelimiterExclusive('\n') catch |err| switch (err) {
66+
error.EndOfStream => return,
67+
else => return err,
68+
};
69+
if (!std.mem.eql(u8, chunk.buf, line)) {
70+
std.debug.print("exp {s}\ngot {s}\n", .{ chunk.buf, line });
71+
@panic("Failed to apply patch");
72+
}
73+
try writer.interface.writeAll(line);
74+
try writer.interface.writeByte('\n');
5175
},
5276
.add => {
53-
_ = try output.write(chunk.buf);
54-
_ = try output.write("\n");
77+
try writer.interface.writeAll(chunk.buf);
78+
try writer.interface.writeByte('\n');
5579
},
5680
}
5781

@@ -62,7 +86,8 @@ pub fn main() !void {
6286
}
6387

6488
fn getLine(allocator: Allocator, file: File) ?[]u8 {
65-
return file.reader().readUntilDelimiterAlloc(allocator, '\n', std.math.maxInt(usize)) catch |err| switch (err) {
89+
var buffer: [4096]u8 = undefined;
90+
return file.reader(&buffer).readUntilDelimiterAlloc(allocator, '\n', std.math.maxInt(usize)) catch |err| switch (err) {
6691
error.EndOfStream => return null,
6792
else => @panic("Error"),
6893
};
@@ -82,9 +107,9 @@ const Chunk = struct {
82107
buf: []const u8,
83108
};
84109

85-
fn next(allocator: Allocator, file: File) ?Chunk {
86-
while (true) {
87-
const line = getLine(allocator, file) orelse return null;
110+
fn init(arena: std.mem.Allocator, contents: []const u8, pos: usize) ?Chunk {
111+
var it = std.mem.tokenizeScalar(u8, contents[pos..], '\n');
112+
while (it.next()) |line| {
88113
if (std.mem.startsWith(u8, line, "@@")) {
89114
const end = std.mem.indexOfPosLinear(u8, line, 3, "@@").?;
90115
const details = line[4 .. end - 2];
@@ -95,7 +120,7 @@ const Chunk = struct {
95120

96121
var lines: std.ArrayListUnmanaged(Line) = .empty;
97122
while (true) {
98-
const diff_line = getLine(allocator, file) orelse break;
123+
const diff_line = it.next() orelse break;
99124
if (std.mem.startsWith(u8, diff_line, "@@")) break;
100125

101126
const action: Line.Action = switch (diff_line[0]) {
@@ -105,16 +130,17 @@ const Chunk = struct {
105130
else => @panic("Bad patch file"),
106131
};
107132

108-
lines.append(allocator, .{ .action = action, .buf = diff_line[1..] }) catch unreachable;
133+
lines.append(arena, .{ .action = action, .buf = diff_line[1..] }) catch unreachable;
109134
}
110135

111136
return .{
112-
.lines = lines.toOwnedSlice(allocator) catch unreachable,
137+
.lines = lines.toOwnedSlice(arena) catch unreachable,
113138
.src = src,
114139
.dst = dst,
115140
};
116141
}
117142
}
143+
return null;
118144
}
119145

120146
fn getLineNumber(buf: []const u8) usize {

examples/interpreter.zig

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,19 @@ pub fn main() anyerror!void {
2020
// Open all Lua standard libraries
2121
lua.openLibs();
2222

23-
var stdin = std.io.getStdIn().reader();
24-
var stdout = std.io.getStdOut().writer();
23+
var in_buf: [4096]u8 = undefined;
24+
var out_buf: [4096]u8 = undefined;
25+
var stdin_file = std.fs.File.stdin().reader(&in_buf);
26+
const stdin = &stdin_file.interface;
27+
var stdout_file = std.fs.File.stdout().writer(&out_buf);
28+
const stdout = &stdout_file.interface;
2529

2630
var buffer: [256]u8 = undefined;
2731
while (true) {
28-
_ = try stdout.write("> ");
32+
_ = try stdout.writeAll("> ");
2933

3034
// Read a line of input
31-
const len = try stdin.read(&buffer);
35+
const len = try stdin.readSliceShort(&buffer);
3236
if (len == 0) break; // EOF
3337
if (len >= buffer.len - 1) {
3438
try stdout.print("error: line too long!\n", .{});

0 commit comments

Comments
 (0)