From a7f03a1e652abe8c89b376d090cec50acb0d2a1a Mon Sep 17 00:00:00 2001 From: Meghan Denny Date: Thu, 9 May 2024 02:52:39 -0700 Subject: [PATCH] upgrade to zig 0.12 --- .gitignore | 1 + build.zig | 13 ++++++++++--- licenses.txt | 3 +++ src/base/client.zig | 10 +++++----- 4 files changed, 19 insertions(+), 8 deletions(-) create mode 100644 licenses.txt diff --git a/.gitignore b/.gitignore index 5b994af..6a38d92 100644 --- a/.gitignore +++ b/.gitignore @@ -6,6 +6,7 @@ deps.zig # zigmod .zigmod/ +zigmod.lock # gyro .gyro/ diff --git a/build.zig b/build.zig index 745f977..c58fe72 100644 --- a/build.zig +++ b/build.zig @@ -1,5 +1,8 @@ const std = @import("std"); +var filters: [1][]const u8 = undefined; +var filters_len: usize = 0; + pub fn build(b: *std.Build) void { const target = b.standardTargetOptions(.{}); const optimize = b.standardOptimizeOption(.{}); @@ -7,15 +10,19 @@ pub fn build(b: *std.Build) void { const emit_docs = b.option(bool, "emit-docs", "Build library documentation") orelse false; const module = b.addModule("hzzp", .{ - .source_file = .{ .path = "src/main.zig" }, + .root_source_file = b.path("src/main.zig"), }); const test_compile_step = b.addTest(.{ - .root_source_file = module.source_file, + .root_source_file = module.root_source_file.?, .target = target, .optimize = optimize, }); - test_compile_step.filter = test_filter; + if (test_filter) |_| { + filters[0] = test_filter.?; + filters_len += 1; + } + test_compile_step.filters = filters[0..filters_len]; const test_run_step = b.addRunArtifact(test_compile_step); diff --git a/licenses.txt b/licenses.txt new file mode 100644 index 0000000..6336b47 --- /dev/null +++ b/licenses.txt @@ -0,0 +1,3 @@ +MIT: += https://spdx.org/licenses/MIT +- This diff --git a/src/base/client.zig b/src/base/client.zig index f47df3c..d957861 100644 --- a/src/base/client.zig +++ b/src/base/client.zig @@ -72,21 +72,21 @@ pub fn BaseClient(comptime Reader: type, comptime Writer: type) type { } // This makes interacting with URI parsers like Vexu/zuri much nicer, because you don't need to reconstruct the path. - pub fn writeStatusLineParts(self: *Self, method: []const u8, path: []const u8, query: ?[]const u8, fragment: ?[]const u8) Writer.Error!void { + pub fn writeStatusLineParts(self: *Self, method: []const u8, path: std.Uri.Component, query: ?std.Uri.Component, fragment: ?std.Uri.Component) (Writer.Error || std.mem.Allocator.Error)!void { assert(!self.head_finished); try self.writer.writeAll(method); try self.writer.writeAll(" "); - try self.writer.writeAll(path); + try self.writer.writeAll(try path.toRawMaybeAlloc(std.testing.failing_allocator)); if (query) |qs| { try self.writer.writeAll("?"); - try self.writer.writeAll(qs); + try self.writer.writeAll(try qs.toRawMaybeAlloc(std.testing.failing_allocator)); } if (fragment) |frag| { try self.writer.writeAll("#"); - try self.writer.writeAll(frag); + try self.writer.writeAll(try frag.toRawMaybeAlloc(std.testing.failing_allocator)); } try self.writer.writeAll(" HTTP/1.1\r\n"); @@ -241,7 +241,7 @@ pub fn BaseClient(comptime Reader: type, comptime Writer: type) type { const size = @min(buffer.len, self.payload_size - start); const end = start + size; - mem.copy(u8, buffer[0..size], self.read_buffer[start..end]); + @memcpy(buffer[0..size], self.read_buffer[start..end]); self.payload_index = end; return size;