authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-02-17 21:43:52-08:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-07-01 16:35:26-07:00
logbf00eb3006a358bbb1da694fb6d725eb6a8eeaaa
tree083cc624f6cd2ad07ab4912ec7df12d2518813d3
parent09af68de80da4319d552a9eefc3f3e86a4c64caf

more of the compiler updated to new Writer API


6 files changed, 28 insertions(+), 68 deletions(-)

lib/std/crypto/tls/Client.zig+3-2
......@@ -125,9 +125,10 @@ pub const Options = struct {
125125 /// Verify that the server certificate is authorized by a given ca bundle.
126126 bundle: Certificate.Bundle,
127127 },
128 /// If non-null, ssl secrets are logged to this stream. Creating such a log file allows
128 /// If non-null, ssl secrets are logged to this file. Creating such a log file allows
129129 /// other programs with access to that file to decrypt all traffic over this connection.
130 ssl_key_log_file: ?*std.io.BufferedWriter = null,
130 /// TODO `std.crypto` should have no dependencies on `std.fs`.
131 ssl_key_log_file: ?std.fs.File = null,
131132};
132133
133134pub fn InitError(comptime Stream: type) type {
lib/std/io.zig+4-46
......@@ -123,59 +123,17 @@ pub fn GenericReader(
123123 return @errorCast(self.any().readAllAlloc(allocator, max_size));
124124 }
125125
126 pub inline fn readUntilDelimiterAlloc(
127 self: Self,
128 allocator: Allocator,
129 delimiter: u8,
130 max_size: usize,
131 ) (NoEofError || Allocator.Error || error{StreamTooLong})![]u8 {
132 return @errorCast(self.any().readUntilDelimiterAlloc(
133 allocator,
134 delimiter,
135 max_size,
136 ));
137 }
138
139 pub inline fn readUntilDelimiter(
140 self: Self,
141 buf: []u8,
142 delimiter: u8,
143 ) (NoEofError || error{StreamTooLong})![]u8 {
144 return @errorCast(self.any().readUntilDelimiter(buf, delimiter));
145 }
146
147 pub inline fn readUntilDelimiterOrEofAlloc(
148 self: Self,
149 allocator: Allocator,
150 delimiter: u8,
151 max_size: usize,
152 ) (Error || Allocator.Error || error{StreamTooLong})!?[]u8 {
153 return @errorCast(self.any().readUntilDelimiterOrEofAlloc(
154 allocator,
155 delimiter,
156 max_size,
157 ));
158 }
159
160 pub inline fn readUntilDelimiterOrEof(
161 self: Self,
162 buf: []u8,
163 delimiter: u8,
164 ) (Error || error{StreamTooLong})!?[]u8 {
165 return @errorCast(self.any().readUntilDelimiterOrEof(buf, delimiter));
166 }
167
168126 pub inline fn streamUntilDelimiter(
169127 self: Self,
170 writer: anytype,
128 writer: *std.io.BufferedWriter,
171129 delimiter: u8,
172130 optional_max_size: ?usize,
173 ) (NoEofError || error{StreamTooLong} || @TypeOf(writer).Error)!void {
174 return @errorCast(self.any().streamUntilDelimiter(
131 ) anyerror!void {
132 return self.any().streamUntilDelimiter(
175133 writer,
176134 delimiter,
177135 optional_max_size,
178 ));
136 );
179137 }
180138
181139 pub inline fn skipUntilDelimiterOrEof(self: Self, delimiter: u8) Error!void {
lib/std/io/BufferedWriter.zig+2-5
......@@ -663,7 +663,7 @@ pub fn printValue(
663663 }
664664 },
665665 .error_set => {
666 if (actual_fmt.len > 0 and actual_fmt.len[0] == 's') {
666 if (actual_fmt.len > 0 and actual_fmt[0] == 's') {
667667 return bw.writeAll(@errorName(value));
668668 } else if (actual_fmt.len != 0) {
669669 invalidFmtError(fmt, value);
......@@ -1147,13 +1147,11 @@ pub fn printByteSize(
11471147 const magnitude = switch (units) {
11481148 .decimal => @min(log2 / comptime std.math.log2(1000), mags_si.len - 1),
11491149 .binary => @min(log2 / 10, mags_iec.len - 1),
1150 else => unreachable,
11511150 };
11521151 const new_value = std.math.lossyCast(f64, value) / std.math.pow(f64, std.math.lossyCast(f64, base), std.math.lossyCast(f64, magnitude));
11531152 const suffix = switch (units) {
11541153 .decimal => mags_si[magnitude],
11551154 .binary => mags_iec[magnitude],
1156 else => unreachable,
11571155 };
11581156
11591157 const s = switch (magnitude) {
......@@ -1176,10 +1174,9 @@ pub fn printByteSize(
11761174 buf[i..][0..3].* = [_]u8{ suffix, 'i', 'B' };
11771175 i += 3;
11781176 },
1179 else => unreachable,
11801177 }
11811178
1182 return alignBufferOptions(buf[0..i], options, bw);
1179 return alignBufferOptions(bw, buf[0..i], options);
11831180}
11841181
11851182// This ANY const is a workaround for: https://github.com/ziglang/zig/issues/7948
src/Compilation.zig+1-2
......@@ -1880,9 +1880,8 @@ pub fn create(gpa: Allocator, arena: Allocator, options: CreateOptions) !*Compil
18801880
18811881 if (options.verbose_llvm_cpu_features) {
18821882 if (options.root_mod.resolved_target.llvm_cpu_features) |cf| print: {
1883 std.debug.lockStdErr();
1883 var stderr = std.debug.lockStdErr2();
18841884 defer std.debug.unlockStdErr();
1885 const stderr = std.io.getStdErr().writer();
18861885 nosuspend {
18871886 stderr.print("compilation: {s}\n", .{options.root_name}) catch break :print;
18881887 stderr.print(" target: {s}\n", .{try target.zigTriple(arena)}) catch break :print;
src/Package/Fetch.zig+17-12
......@@ -184,7 +184,7 @@ pub const JobQueue = struct {
184184
185185 const hash_slice = hash.toSlice();
186186
187 try buf.writer().print(
187 try buf.print(
188188 \\ pub const {} = struct {{
189189 \\
190190 , .{std.zig.fmtId(hash_slice)});
......@@ -210,13 +210,13 @@ pub const JobQueue = struct {
210210 }
211211 }
212212
213 try buf.writer().print(
213 try buf.print(
214214 \\ pub const build_root = "{q}";
215215 \\
216216 , .{fetch.package_root});
217217
218218 if (fetch.has_build_zig) {
219 try buf.writer().print(
219 try buf.print(
220220 \\ pub const build_zig = @import("{}");
221221 \\
222222 , .{std.zig.fmtEscapes(hash_slice)});
......@@ -229,7 +229,7 @@ pub const JobQueue = struct {
229229 );
230230 for (manifest.dependencies.keys(), manifest.dependencies.values()) |name, dep| {
231231 const h = depDigest(fetch.package_root, jq.global_cache, dep) orelse continue;
232 try buf.writer().print(
232 try buf.print(
233233 " .{{ \"{}\", \"{}\" }},\n",
234234 .{ std.zig.fmtEscapes(name), std.zig.fmtEscapes(h.toSlice()) },
235235 );
......@@ -261,7 +261,7 @@ pub const JobQueue = struct {
261261
262262 for (root_manifest.dependencies.keys(), root_manifest.dependencies.values()) |name, dep| {
263263 const h = depDigest(root_fetch.package_root, jq.global_cache, dep) orelse continue;
264 try buf.writer().print(
264 try buf.print(
265265 " .{{ \"{}\", \"{}\" }},\n",
266266 .{ std.zig.fmtEscapes(name), std.zig.fmtEscapes(h.toSlice()) },
267267 );
......@@ -1366,8 +1366,12 @@ fn unpackGitPack(f: *Fetch, out_dir: fs.Dir, resource: *Resource.Git) anyerror!U
13661366 {
13671367 const index_prog_node = f.prog_node.start("Index pack", 0);
13681368 defer index_prog_node.end();
1369 var index_buffered_writer = std.io.bufferedWriter(index_file.writer());
1370 try git.indexPack(gpa, object_format, pack_file, index_buffered_writer.writer());
1369 var buffer: [4096]u8 = undefined;
1370 var index_buffered_writer: std.io.BufferedWriter = .{
1371 .unbuffered_writer = index_file.writer(),
1372 .buffer = &buffer,
1373 };
1374 try git.indexPack(gpa, object_format, pack_file, &index_buffered_writer);
13711375 try index_buffered_writer.flush();
13721376 try index_file.sync();
13731377 }
......@@ -1638,12 +1642,13 @@ fn computeHash(f: *Fetch, pkg_path: Cache.Path, filter: Filter) RunError!Compute
16381642}
16391643
16401644fn dumpHashInfo(all_files: []const *const HashedFile) !void {
1641 const stdout = std.io.getStdOut();
1642 var bw = std.io.bufferedWriter(stdout.writer());
1643 const w = bw.writer();
1644
1645 var buffer: [4096]u8 = undefined;
1646 var bw: std.io.BufferedWriter = .{
1647 .unbuffered_writer = std.io.getStdOut().writer(),
1648 .buffer = &buffer,
1649 };
16451650 for (all_files) |hashed_file| {
1646 try w.print("{s}: {x}: {s}\n", .{
1651 try bw.print("{s}: {x}: {s}\n", .{
16471652 @tagName(hashed_file.kind), &hashed_file.hash, hashed_file.normalized_path,
16481653 });
16491654 }
src/print_env.zig+1-1
......@@ -26,7 +26,7 @@ pub fn cmdEnv(arena: Allocator, args: []const []const u8) !void {
2626 .buffer = &buffer,
2727 .unbuffered_writer = std.io.getStdOut().writer(),
2828 };
29 var jws = std.json.writeStream(bw, .{ .whitespace = .indent_1 });
29 var jws: std.json.Stringify = .{ .writer = &bw, .options = .{ .whitespace = .indent_1 } };
3030
3131 try jws.beginObject();
3232