Skip to content

Commit d4a0f9b

Browse files
authored
Merge pull request #28 from bernardassan/zig-0.15.1
2 parents e934f66 + bcb833c commit d4a0f9b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+658
-526
lines changed

.github/workflows/ci.yaml

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ jobs:
1515
name: Build and Unit Tests
1616
runs-on: ubuntu-latest
1717
steps:
18-
- uses: actions/checkout@v2
19-
- uses: goto-bus-stop/setup-zig@v2
18+
- uses: actions/checkout@v5
19+
- uses: mlugg/setup-zig@v2
2020
with:
21-
version: 0.14.0
21+
version: 0.15.1
2222
- name: Build Examples
2323
run: zig build -Dexample=all
2424
- name: Run unit tests
@@ -32,10 +32,10 @@ jobs:
3232
matrix:
3333
async: [io_uring, epoll, poll]
3434
steps:
35-
- uses: actions/checkout@v2
36-
- uses: goto-bus-stop/setup-zig@v2
35+
- uses: actions/checkout@v5
36+
- uses: mlugg/setup-zig@v2
3737
with:
38-
version: 0.14.0
38+
version: 0.15.1
3939
- name: Generate random 64-bit integer
4040
id: random
4141
shell: bash
@@ -51,10 +51,10 @@ jobs:
5151
matrix:
5252
async: [kqueue, poll]
5353
steps:
54-
- uses: actions/checkout@v2
55-
- uses: goto-bus-stop/setup-zig@v2
54+
- uses: actions/checkout@v5
55+
- uses: mlugg/setup-zig@v2
5656
with:
57-
version: 0.14.0
57+
version: 0.15.1
5858
- name: Generate random 64-bit integer
5959
id: random
6060
shell: bash
@@ -67,10 +67,10 @@ jobs:
6767
needs: unit-tests
6868
runs-on: windows-latest
6969
steps:
70-
- uses: actions/checkout@v2
71-
- uses: goto-bus-stop/setup-zig@v2
70+
- uses: actions/checkout@v5
71+
- uses: mlugg/setup-zig@v2
7272
with:
73-
version: 0.14.0
73+
version: 0.15.1
7474
- name: Generate random 64-bit integer
7575
id: random
7676
shell: pwsh

build.zig

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
const std = @import("std");
2-
const builtin = @import("builtin");
32
const assert = std.debug.assert;
3+
const builtin = @import("builtin");
44

5-
const zig_version = std.SemanticVersion{ .major = 0, .minor = 14, .patch = 1 };
5+
const AsyncKind = @import("src/aio/lib.zig").AsyncKind;
66

7+
const zig_version = std.SemanticVersion{ .major = 0, .minor = 15, .patch = 1 };
78
comptime {
89
// Compare versions while allowing different pre/patch metadata.
910
const zig_version_eq = zig_version.major == builtin.zig_version.major and
1011
zig_version.minor == builtin.zig_version.minor and
1112
zig_version.patch == builtin.zig_version.patch;
1213
if (!zig_version_eq) {
1314
@compileError(std.fmt.comptimePrint(
14-
"unsupported zig version: expected {}, found {}",
15+
"unsupported zig version: expected {f}, found {f}",
1516
.{ zig_version, builtin.zig_version },
1617
));
1718
}
@@ -20,7 +21,6 @@ comptime {
2021
const Example = enum {
2122
none,
2223
all,
23-
2424
basic,
2525
cat,
2626
channel,
@@ -49,8 +49,6 @@ const Example = enum {
4949
return ex_string;
5050
}
5151
};
52-
const AsyncKind = @import("src/aio/lib.zig").AsyncKind;
53-
5452
pub fn build(b: *std.Build) void {
5553

5654
// Top-level steps you can invoke on the command line.
@@ -114,7 +112,7 @@ pub fn build(b: *std.Build) void {
114112
});
115113

116114
// build and run e2e test
117-
// usage: zig build test_e2e --Dasync=[async_backend] -- [u64 num]
115+
// usage: zig build test_e2e -Dasync=[async_backend] -- [u64 num]
118116
build_test_e2e(b, .{
119117
.test_e2e = build_steps.test_e2e,
120118
}, .{
@@ -253,6 +251,8 @@ fn build_example_exe(
253251
const example_exe = b.addExecutable(.{
254252
.name = options.example.toString(),
255253
.root_module = example_mod,
254+
// without llvm leads to error: undefined symbol: tardy_swap_frame
255+
.use_llvm = true,
256256
});
257257

258258
const install_artifact = b.addInstallArtifact(example_exe, .{});
@@ -269,6 +269,11 @@ fn build_example_exe(
269269
const run_artifact = b.addRunArtifact(example_exe);
270270
run_artifact.step.dependOn(&install_artifact.step);
271271

272+
// pass args to examples (.ie cat, rmdir, shove, stat)
273+
if (b.args) |args| {
274+
run_artifact.addArgs(args);
275+
}
276+
272277
steps.run.dependOn(&install_artifact.step);
273278
steps.run.dependOn(&run_artifact.step);
274279
}
@@ -317,9 +322,11 @@ fn build_test(
317322
// usage: zig build test_unit
318323
const unit_tests = b.addTest(.{
319324
.name = "general unit tests",
320-
.root_source_file = b.path("./src/tests.zig"),
321-
.optimize = options.optimize,
322-
.target = options.target,
325+
.root_module = b.createModule(.{
326+
.root_source_file = b.path("./src/tests.zig"),
327+
.optimize = options.optimize,
328+
.target = options.target,
329+
}),
323330
});
324331

325332
const run_unit_tests = b.addRunArtifact(unit_tests);
@@ -355,6 +362,7 @@ fn build_test_e2e(
355362
.root_source_file = b.path("test/e2e/main.zig"),
356363
.target = options.target,
357364
.optimize = options.optimize,
365+
.strip = false,
358366
});
359367

360368
e2e_mod.addImport("tardy", options.tardy_mod);
@@ -374,7 +382,8 @@ fn build_test_e2e(
374382
const exe = b.addExecutable(.{
375383
.name = "e2e",
376384
.root_module = e2e_mod,
377-
.strip = false,
385+
// without llvm leads to error: undefined symbol: tardy_swap_frame
386+
.use_llvm = true,
378387
});
379388

380389
// build/install e2e test

examples/basic/main.zig

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
const std = @import("std");
2-
const log = std.log.scoped(.@"tardy/example/basic");
32

43
const Runtime = @import("tardy").Runtime;
54
const Task = @import("tardy").Task;
6-
75
const Timer = @import("tardy").Timer;
86

97
const Tardy = @import("tardy").Tardy(.auto);
8+
const log = std.log.scoped(.@"tardy/example/basic");
109

1110
fn log_frame(rt: *Runtime) !void {
1211
var count: usize = 0;
@@ -20,7 +19,7 @@ fn log_frame(rt: *Runtime) !void {
2019
pub fn main() !void {
2120
const allocator = std.heap.page_allocator;
2221

23-
var tardy = try Tardy.init(allocator, .{
22+
var tardy: Tardy = try .init(allocator, .{
2423
.threading = .single,
2524
.pooling = .static,
2625
.size_tasks_initial = 2,

examples/cat/main.zig

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,19 @@
11
const std = @import("std");
2-
const log = std.log.scoped(.@"tardy/example/cat");
32

4-
const Runtime = @import("tardy").Runtime;
5-
const Frame = @import("tardy").Frame;
6-
const Task = @import("tardy").Task;
7-
const Tardy = @import("tardy").Tardy(.auto);
83
const Cross = @import("tardy").Cross;
9-
104
const Dir = @import("tardy").Dir;
115
const File = @import("tardy").File;
6+
const Frame = @import("tardy").Frame;
7+
const Runtime = @import("tardy").Runtime;
8+
const Task = @import("tardy").Task;
129

10+
const log = std.log.scoped(.@"tardy/example/cat");
1311
pub const std_options: std.Options = .{ .log_level = .err };
1412

13+
const Tardy = @import("tardy").Tardy(.auto);
1514
const EntryParams = struct { file_name: [:0]const u8 };
1615

1716
fn main_frame(rt: *Runtime, p: *EntryParams) !void {
18-
const std_out = File.std_out();
1917
const file = Dir.cwd().open_file(rt, p.file_name, .{}) catch |e| switch (e) {
2018
error.NotFound => {
2119
std.debug.print("{s}: No such file!", .{p.file_name});
@@ -24,25 +22,28 @@ fn main_frame(rt: *Runtime, p: *EntryParams) !void {
2422
else => return e,
2523
};
2624

27-
const reader = file.reader(rt);
28-
const writer = std_out.writer(rt);
25+
var file_reader = file.reader(rt, &.{});
26+
const file_r = &file_reader.interface;
27+
28+
var std_out = File.std_out().writer(rt, &.{});
29+
const stdout_w = &std_out.interface;
30+
defer stdout_w.flush() catch unreachable;
2931

3032
var buffer: [1024 * 32]u8 = undefined;
3133
var done: bool = false;
32-
3334
while (!done) {
34-
const length = try reader.readAll(&buffer);
35+
const length = file_r.readSliceShort(&buffer) catch unreachable;
3536
done = length < buffer.len;
36-
try writer.writeAll(buffer[0..length]);
37+
stdout_w.writeAll(buffer[0..length]) catch unreachable;
3738
}
3839
}
3940

4041
pub fn main() !void {
41-
var gpa = std.heap.GeneralPurposeAllocator(.{ .thread_safe = true }){};
42+
var gpa: std.heap.DebugAllocator(.{ .thread_safe = true }) = .init;
4243
const allocator = gpa.allocator();
4344
defer _ = gpa.deinit();
4445

45-
var tardy = try Tardy.init(allocator, .{
46+
var tardy: Tardy = try .init(allocator, .{
4647
.threading = .single,
4748
.pooling = .static,
4849
.size_tasks_initial = 1,
@@ -59,7 +60,7 @@ pub fn main() !void {
5960
if (i == 1) break :blk arg;
6061
}
6162

62-
try std.io.getStdOut().writeAll("file name not passed in: ./cat [file name]");
63+
try std.fs.File.stdout().writeAll("file name not passed in: ./cat [file name]");
6364
return;
6465
};
6566

examples/channel/main.zig

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
const std = @import("std");
2-
const log = std.log.scoped(.@"tardy/example/channel");
32

43
const Runtime = @import("tardy").Runtime;
4+
const Spsc = @import("tardy").Spsc;
55
const Task = @import("tardy").Task;
66
const Timer = @import("tardy").Timer;
7-
const Tardy = @import("tardy").Tardy(.auto);
87

9-
const Spsc = @import("tardy").Spsc;
8+
const Tardy = @import("tardy").Tardy(.auto);
109

10+
const log = std.log.scoped(.@"tardy/example/channel");
1111
pub const std_options: std.Options = .{ .log_level = .err };
1212

1313
const MAX_COUNT = 100;
@@ -39,17 +39,17 @@ fn consumer_frame(_: *Runtime, consumer: Spsc(usize).Consumer) !void {
3939
}
4040

4141
pub fn main() !void {
42-
const allocator = std.heap.page_allocator;
42+
const allocator = std.heap.smp_allocator;
4343

44-
var tardy = try Tardy.init(allocator, .{
44+
var tardy: Tardy = try .init(allocator, .{
4545
.threading = .{ .multi = 2 },
4646
.pooling = .static,
4747
.size_tasks_initial = 1,
4848
.size_aio_reap_max = 1,
4949
});
5050
defer tardy.deinit();
5151

52-
var channel = try Spsc(usize).init(allocator, 2);
52+
var channel: Spsc(usize) = try .init(allocator, 2);
5353
defer channel.deinit();
5454

5555
try tardy.entry(

examples/echo/main.zig

Lines changed: 30 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,65 @@
11
const std = @import("std");
2-
const log = std.log.scoped(.@"tardy/example/echo");
32

3+
const AcceptResult = @import("tardy").AcceptResult;
4+
const Cross = @import("tardy").Cross;
45
const Pool = @import("tardy").Pool;
6+
const RecvResult = @import("tardy").RecvResult;
57
const Runtime = @import("tardy").Runtime;
6-
const Task = @import("tardy").Task;
7-
const Tardy = @import("tardy").Tardy(.auto);
8-
const Cross = @import("tardy").Cross;
9-
8+
const SendResult = @import("tardy").SendResult;
109
const Socket = @import("tardy").Socket;
10+
const Task = @import("tardy").Task;
1111
const Timer = @import("tardy").Timer;
1212

13-
const AcceptResult = @import("tardy").AcceptResult;
14-
const RecvResult = @import("tardy").RecvResult;
15-
const SendResult = @import("tardy").SendResult;
13+
const Tardy = @import("tardy").Tardy(.auto);
14+
const log = std.log.scoped(.@"tardy/example/echo");
1615

1716
fn echo_frame(rt: *Runtime, server: *const Socket) !void {
1817
const socket = try server.accept(rt);
1918
defer socket.close_blocking();
2019

21-
const reader = socket.reader(rt);
22-
const writer = socket.writer(rt);
20+
var sock_reader = socket.reader(rt, &.{});
21+
const sock_r = &sock_reader.interface;
22+
23+
var sock_writer = socket.writer(rt, &.{});
24+
const sock_w = &sock_writer.interface;
25+
defer sock_w.flush() catch unreachable;
2326

2427
log.debug(
25-
"{d} - accepted socket [{}]",
28+
"{d} - accepted socket [{f}]",
2629
.{ std.time.milliTimestamp(), socket.addr },
2730
);
2831

2932
// spawn off a new frame.
3033
try rt.spawn(.{ rt, server }, echo_frame, 1024 * 16);
3134

32-
var buffer: [1024]u8 = undefined;
35+
//TODO: investigate why using readSliceShort with a buffer bigger
36+
// than reader size leads to a connection reset (try to get a repro)
37+
var buffer: [501]u8 = undefined;
3338
while (true) {
34-
const recv_length = reader.read(&buffer) catch |e| {
35-
log.err("Failed to recv on socket | {}", .{e});
36-
return;
39+
const recv_length = sock_r.readSliceShort(&buffer) catch |e| {
40+
log.err("Failed to recv on socket | {t}", .{e});
41+
break;
3742
};
3843

39-
writer.writeAll(buffer[0..recv_length]) catch |e| {
40-
log.err("Failed to send on socket | {}", .{e});
41-
return;
44+
if (recv_length == 0) {
45+
break;
46+
}
47+
48+
sock_w.writeAll(buffer[0..recv_length]) catch |e| {
49+
log.err("Failed to send on socket | {t}", .{e});
50+
break;
4251
};
4352

4453
log.debug("Echoed: {s}", .{buffer[0..recv_length]});
4554
}
4655
}
4756

4857
pub fn main() !void {
49-
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
58+
var gpa: std.heap.DebugAllocator(.{}) = .init;
5059
const allocator = gpa.allocator();
5160
defer _ = gpa.deinit();
5261

53-
var tardy = try Tardy.init(allocator, .{
62+
var tardy: Tardy = try .init(allocator, .{
5463
.threading = .single,
5564
.pooling = .static,
5665
.size_tasks_initial = 256,
@@ -61,7 +70,7 @@ pub fn main() !void {
6170
const host = "0.0.0.0";
6271
const port = 9862;
6372

64-
const server = try Socket.init(.{ .tcp = .{ .host = host, .port = port } });
73+
const server: Socket = try .init(.{ .tcp = .{ .host = host, .port = port } });
6574
try server.bind();
6675
try server.listen(1024);
6776

0 commit comments

Comments
 (0)