Skip to content

Commit dc262af

Browse files
committed
Update to zig 0.15.1
1 parent 5ffc771 commit dc262af

5 files changed

Lines changed: 34 additions & 22 deletions

File tree

build.zig

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ pub fn build(b: *std.Build) void {
1212
});
1313

1414
const librdkafka_artifact = librdkafka.artifact("rdkafka");
15+
b.installArtifact(librdkafka_artifact);
1516

1617
const zk = b.addModule("zig-kafka", .{
1718
.root_source_file = b.path("lib/kafka.zig"),
@@ -36,10 +37,14 @@ pub fn build(b: *std.Build) void {
3637
zk.linkSystemLibrary("liblz4", .{ .needed = true, .preferred_link_mode = .static });
3738
zk.linkSystemLibrary("libsasl2", .{ .needed = true, .preferred_link_mode = .static });
3839

40+
// b.installArtifact(zk);
41+
3942
const exe_unit_tests = b.addTest(.{
40-
.root_source_file = b.path("lib/kafka.zig"),
41-
.target = target,
42-
.optimize = optimize,
43+
.root_module = b.createModule(.{
44+
.root_source_file = b.path("lib/kafka.zig"),
45+
.target = target,
46+
.optimize = optimize,
47+
}),
4348
});
4449

4550
exe_unit_tests.addIncludePath(librdkafka_artifact.getEmittedIncludeTree());

build.zig.zon

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
.{
22
.name = .zigkafka,
33
.fingerprint = 0xcef3e6efcff2a10e,
4-
.version = "4.0.2",
4+
.version = "5.0.0",
55
.dependencies = .{
66
.librdkafka = .{
7-
.url = "https://github.com/theothornhill/librdkafka/archive/refs/tags/2.8.0+4.zip",
8-
.hash = "librdkafka-2.8.0-WaVnhWBgkAB5V1DwZrkkFFf6gYDex2g4OtZSUS0jX5hV",
7+
.url = "https://github.com/theothornhill/librdkafka/archive/refs/tags/2.8.0+5.zip",
8+
.hash = "librdkafka-2.8.0-WaVnhedgkABjPXsz_2L10ORZmLCXhQd3eFpFJJqJdn_g",
99
},
1010
.@"zig-avro" = .{
11-
.url = "https://github.com/theothornhill/zig-avro/archive/refs/tags/3.0.1.zip",
12-
.hash = "zig_avro-3.0.1-LSuFEQ94AgDwMaOoQlLqsq1m8A9FBx003kUoz3gEpEdu",
11+
.url = "https://github.com/theothornhill/zig-avro/archive/refs/tags/4.0.0.tar.gz",
12+
.hash = "zig_avro-4.0.0-LSuFEfaCAgCFXlX1IlE5SWxHQf3vUYF-4eDxy2QqevY0",
1313
},
1414
},
1515
.paths = .{

lib/config.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ pub fn init(allocator: std.mem.Allocator) !Config {
1616
};
1717

1818
try cfg.set(allocator, "client.software.name", "zig-kafka");
19-
try cfg.set(allocator, "client.software.version", "4.0.2");
19+
try cfg.set(allocator, "client.software.version", "5.0.0");
2020

2121
return cfg;
2222
}

lib/producer.zig

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const Producer = @This();
1111

1212
handle: *c.rd_kafka_t,
1313
queue: ?*c.rd_kafka_queue_t,
14-
buffer: std.ArrayList(u8),
14+
buffer: std.Io.Writer.Allocating,
1515
allocator: std.mem.Allocator,
1616

1717
pub fn init(allocator: std.mem.Allocator, cfg: *Config) !Producer {
@@ -27,7 +27,7 @@ pub fn init(allocator: std.mem.Allocator, cfg: *Config) !Producer {
2727
.allocator = allocator,
2828
.handle = ph,
2929
.queue = c.rd_kafka_queue_get_main(ph),
30-
.buffer = try std.ArrayList(u8).initCapacity(allocator, 1024),
30+
.buffer = try .initCapacity(allocator, 1024),
3131
};
3232
}
3333
@panic("Producer handle failed initializing");
@@ -63,7 +63,7 @@ pub fn poller(self: @This(), timeout_ms: usize, healthy: *bool) !void {
6363
std.log.debug("Producer poll", .{});
6464
try self.poll(timeout_ms);
6565

66-
std.time.sleep(std.time.ns_per_s * 15);
66+
std.Thread.sleep(std.time.ns_per_s * 15);
6767
}
6868
}
6969

lib/schemaregistry.zig

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ fn authUrl(self: @This(), url_path: []const u8) !std.Uri {
2020
};
2121
}
2222

23-
fn fetchSchema(self: @This(), response_storage: *std.ArrayList(u8), subject: []const u8, schema: []const u8) !void {
23+
fn fetchSchema(self: @This(), response_storage: *std.Io.Writer, subject: []const u8, schema: []const u8) !void {
2424
const Schema = struct { schema: []const u8 };
2525
var client = std.http.Client{ .allocator = self.allocator };
2626
defer client.deinit();
@@ -29,34 +29,41 @@ fn fetchSchema(self: @This(), response_storage: *std.ArrayList(u8), subject: []c
2929
const auth_url = try self.authUrl(url_path);
3030
const shb = try self.allocator.alloc(u8, 1024);
3131
defer self.allocator.free(shb);
32-
var schema_json = std.ArrayList(u8).init(self.allocator);
32+
var schema_json: std.Io.Writer.Allocating = .init(self.allocator);
3333
defer schema_json.deinit();
34-
try std.json.stringify(Schema{ .schema = schema }, .{}, schema_json.writer());
34+
var json_writer: std.json.Stringify = .{ .writer = &schema_json.writer };
35+
36+
try json_writer.write(Schema{ .schema = schema });
37+
3538
const result = client.fetch(.{
36-
.response_storage = .{ .dynamic = response_storage },
37-
.server_header_buffer = shb,
39+
.response_writer = response_storage,
3840
.method = std.http.Method.POST,
3941
.location = .{ .uri = auth_url },
40-
.payload = schema_json.items,
42+
.payload = schema_json.written(),
4143
}) catch |err| {
4244
std.log.err("error reaching {s} on {} port {}: {}", .{ url_path, auth_url.host.?, auth_url.port.?, err });
4345
return errors.SchemaError.RegistryUnreachable;
4446
};
4547
if (result.status != std.http.Status.ok) {
46-
std.log.err("response {} not 200 OK on {s} getting schema at {s}: {s}", .{ result.status, subject, url_path, response_storage.items });
48+
std.log.err("response {} not 200 OK on {s} getting schema at {s}: {s}", .{
49+
result.status,
50+
subject,
51+
url_path,
52+
response_storage.buffer[0..response_storage.end],
53+
});
4754
return errors.SchemaError.RegistryAngry;
4855
}
4956
}
5057

5158
pub fn findSchemaId(self: @This(), topic: []const u8, schema: []const u8) !u32 {
5259
const SchemaVersionResponse = struct { id: u32 };
53-
var response_storage = std.ArrayList(u8).init(self.allocator);
54-
try self.fetchSchema(&response_storage, topic, schema);
60+
var response_storage: std.Io.Writer.Allocating = .init(self.allocator);
61+
try self.fetchSchema(&response_storage.writer, topic, schema);
5562
errdefer response_storage.deinit();
5663
const parsed = try std.json.parseFromSlice(
5764
SchemaVersionResponse,
5865
self.allocator,
59-
response_storage.items,
66+
response_storage.written(),
6067
.{ .ignore_unknown_fields = true },
6168
);
6269
defer parsed.deinit();

0 commit comments

Comments
 (0)