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 {...@@ -125,9 +125,10 @@ pub const Options = struct {
125 /// Verify that the server certificate is authorized by a given ca bundle.125 /// Verify that the server certificate is authorized by a given ca bundle.
126 bundle: Certificate.Bundle,126 bundle: Certificate.Bundle,
127 },127 },
128 /// If non-null, ssl secrets are logged to this stream. Creating such a log file allows128 /// If non-null, ssl secrets are logged to this file. Creating such a log file allows
129 /// other programs with access to that file to decrypt all traffic over this connection.129 /// 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,
131};132};
132133
133pub fn InitError(comptime Stream: type) type {134pub fn InitError(comptime Stream: type) type {
lib/std/io.zig+4-46
...@@ -123,59 +123,17 @@ pub fn GenericReader(...@@ -123,59 +123,17 @@ pub fn GenericReader(
123 return @errorCast(self.any().readAllAlloc(allocator, max_size));123 return @errorCast(self.any().readAllAlloc(allocator, max_size));
124 }124 }
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
168 pub inline fn streamUntilDelimiter(126 pub inline fn streamUntilDelimiter(
169 self: Self,127 self: Self,
170 writer: anytype,128 writer: *std.io.BufferedWriter,
171 delimiter: u8,129 delimiter: u8,
172 optional_max_size: ?usize,130 optional_max_size: ?usize,
173 ) (NoEofError || error{StreamTooLong} || @TypeOf(writer).Error)!void {131 ) anyerror!void {
174 return @errorCast(self.any().streamUntilDelimiter(132 return self.any().streamUntilDelimiter(
175 writer,133 writer,
176 delimiter,134 delimiter,
177 optional_max_size,135 optional_max_size,
178 ));136 );
179 }137 }
180138
181 pub inline fn skipUntilDelimiterOrEof(self: Self, delimiter: u8) Error!void {139 pub inline fn skipUntilDelimiterOrEof(self: Self, delimiter: u8) Error!void {
lib/std/io/BufferedWriter.zig+2-5
...@@ -663,7 +663,7 @@ pub fn printValue(...@@ -663,7 +663,7 @@ pub fn printValue(
663 }663 }
664 },664 },
665 .error_set => {665 .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') {
667 return bw.writeAll(@errorName(value));667 return bw.writeAll(@errorName(value));
668 } else if (actual_fmt.len != 0) {668 } else if (actual_fmt.len != 0) {
669 invalidFmtError(fmt, value);669 invalidFmtError(fmt, value);
...@@ -1147,13 +1147,11 @@ pub fn printByteSize(...@@ -1147,13 +1147,11 @@ pub fn printByteSize(
1147 const magnitude = switch (units) {1147 const magnitude = switch (units) {
1148 .decimal => @min(log2 / comptime std.math.log2(1000), mags_si.len - 1),1148 .decimal => @min(log2 / comptime std.math.log2(1000), mags_si.len - 1),
1149 .binary => @min(log2 / 10, mags_iec.len - 1),1149 .binary => @min(log2 / 10, mags_iec.len - 1),
1150 else => unreachable,
1151 };1150 };
1152 const new_value = std.math.lossyCast(f64, value) / std.math.pow(f64, std.math.lossyCast(f64, base), std.math.lossyCast(f64, magnitude));1151 const new_value = std.math.lossyCast(f64, value) / std.math.pow(f64, std.math.lossyCast(f64, base), std.math.lossyCast(f64, magnitude));
1153 const suffix = switch (units) {1152 const suffix = switch (units) {
1154 .decimal => mags_si[magnitude],1153 .decimal => mags_si[magnitude],
1155 .binary => mags_iec[magnitude],1154 .binary => mags_iec[magnitude],
1156 else => unreachable,
1157 };1155 };
11581156
1159 const s = switch (magnitude) {1157 const s = switch (magnitude) {
...@@ -1176,10 +1174,9 @@ pub fn printByteSize(...@@ -1176,10 +1174,9 @@ pub fn printByteSize(
1176 buf[i..][0..3].* = [_]u8{ suffix, 'i', 'B' };1174 buf[i..][0..3].* = [_]u8{ suffix, 'i', 'B' };
1177 i += 3;1175 i += 3;
1178 },1176 },
1179 else => unreachable,
1180 }1177 }
11811178
1182 return alignBufferOptions(buf[0..i], options, bw);1179 return alignBufferOptions(bw, buf[0..i], options);
1183}1180}
11841181
1185// This ANY const is a workaround for: https://github.com/ziglang/zig/issues/79481182// 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...@@ -1880,9 +1880,8 @@ pub fn create(gpa: Allocator, arena: Allocator, options: CreateOptions) !*Compil
18801880
1881 if (options.verbose_llvm_cpu_features) {1881 if (options.verbose_llvm_cpu_features) {
1882 if (options.root_mod.resolved_target.llvm_cpu_features) |cf| print: {1882 if (options.root_mod.resolved_target.llvm_cpu_features) |cf| print: {
1883 std.debug.lockStdErr();1883 var stderr = std.debug.lockStdErr2();
1884 defer std.debug.unlockStdErr();1884 defer std.debug.unlockStdErr();
1885 const stderr = std.io.getStdErr().writer();
1886 nosuspend {1885 nosuspend {
1887 stderr.print("compilation: {s}\n", .{options.root_name}) catch break :print;1886 stderr.print("compilation: {s}\n", .{options.root_name}) catch break :print;
1888 stderr.print(" target: {s}\n", .{try target.zigTriple(arena)}) catch break :print;1887 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 {...@@ -184,7 +184,7 @@ pub const JobQueue = struct {
184184
185 const hash_slice = hash.toSlice();185 const hash_slice = hash.toSlice();
186186
187 try buf.writer().print(187 try buf.print(
188 \\ pub const {} = struct {{188 \\ pub const {} = struct {{
189 \\189 \\
190 , .{std.zig.fmtId(hash_slice)});190 , .{std.zig.fmtId(hash_slice)});
...@@ -210,13 +210,13 @@ pub const JobQueue = struct {...@@ -210,13 +210,13 @@ pub const JobQueue = struct {
210 }210 }
211 }211 }
212212
213 try buf.writer().print(213 try buf.print(
214 \\ pub const build_root = "{q}";214 \\ pub const build_root = "{q}";
215 \\215 \\
216 , .{fetch.package_root});216 , .{fetch.package_root});
217217
218 if (fetch.has_build_zig) {218 if (fetch.has_build_zig) {
219 try buf.writer().print(219 try buf.print(
220 \\ pub const build_zig = @import("{}");220 \\ pub const build_zig = @import("{}");
221 \\221 \\
222 , .{std.zig.fmtEscapes(hash_slice)});222 , .{std.zig.fmtEscapes(hash_slice)});
...@@ -229,7 +229,7 @@ pub const JobQueue = struct {...@@ -229,7 +229,7 @@ pub const JobQueue = struct {
229 );229 );
230 for (manifest.dependencies.keys(), manifest.dependencies.values()) |name, dep| {230 for (manifest.dependencies.keys(), manifest.dependencies.values()) |name, dep| {
231 const h = depDigest(fetch.package_root, jq.global_cache, dep) orelse continue;231 const h = depDigest(fetch.package_root, jq.global_cache, dep) orelse continue;
232 try buf.writer().print(232 try buf.print(
233 " .{{ \"{}\", \"{}\" }},\n",233 " .{{ \"{}\", \"{}\" }},\n",
234 .{ std.zig.fmtEscapes(name), std.zig.fmtEscapes(h.toSlice()) },234 .{ std.zig.fmtEscapes(name), std.zig.fmtEscapes(h.toSlice()) },
235 );235 );
...@@ -261,7 +261,7 @@ pub const JobQueue = struct {...@@ -261,7 +261,7 @@ pub const JobQueue = struct {
261261
262 for (root_manifest.dependencies.keys(), root_manifest.dependencies.values()) |name, dep| {262 for (root_manifest.dependencies.keys(), root_manifest.dependencies.values()) |name, dep| {
263 const h = depDigest(root_fetch.package_root, jq.global_cache, dep) orelse continue;263 const h = depDigest(root_fetch.package_root, jq.global_cache, dep) orelse continue;
264 try buf.writer().print(264 try buf.print(
265 " .{{ \"{}\", \"{}\" }},\n",265 " .{{ \"{}\", \"{}\" }},\n",
266 .{ std.zig.fmtEscapes(name), std.zig.fmtEscapes(h.toSlice()) },266 .{ std.zig.fmtEscapes(name), std.zig.fmtEscapes(h.toSlice()) },
267 );267 );
...@@ -1366,8 +1366,12 @@ fn unpackGitPack(f: *Fetch, out_dir: fs.Dir, resource: *Resource.Git) anyerror!U...@@ -1366,8 +1366,12 @@ fn unpackGitPack(f: *Fetch, out_dir: fs.Dir, resource: *Resource.Git) anyerror!U
1366 {1366 {
1367 const index_prog_node = f.prog_node.start("Index pack", 0);1367 const index_prog_node = f.prog_node.start("Index pack", 0);
1368 defer index_prog_node.end();1368 defer index_prog_node.end();
1369 var index_buffered_writer = std.io.bufferedWriter(index_file.writer());1369 var buffer: [4096]u8 = undefined;
1370 try git.indexPack(gpa, object_format, pack_file, index_buffered_writer.writer());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);
1371 try index_buffered_writer.flush();1375 try index_buffered_writer.flush();
1372 try index_file.sync();1376 try index_file.sync();
1373 }1377 }
...@@ -1638,12 +1642,13 @@ fn computeHash(f: *Fetch, pkg_path: Cache.Path, filter: Filter) RunError!Compute...@@ -1638,12 +1642,13 @@ fn computeHash(f: *Fetch, pkg_path: Cache.Path, filter: Filter) RunError!Compute
1638}1642}
16391643
1640fn dumpHashInfo(all_files: []const *const HashedFile) !void {1644fn dumpHashInfo(all_files: []const *const HashedFile) !void {
1641 const stdout = std.io.getStdOut();1645 var buffer: [4096]u8 = undefined;
1642 var bw = std.io.bufferedWriter(stdout.writer());1646 var bw: std.io.BufferedWriter = .{
1643 const w = bw.writer();1647 .unbuffered_writer = std.io.getStdOut().writer(),
16441648 .buffer = &buffer,
1649 };
1645 for (all_files) |hashed_file| {1650 for (all_files) |hashed_file| {
1646 try w.print("{s}: {x}: {s}\n", .{1651 try bw.print("{s}: {x}: {s}\n", .{
1647 @tagName(hashed_file.kind), &hashed_file.hash, hashed_file.normalized_path,1652 @tagName(hashed_file.kind), &hashed_file.hash, hashed_file.normalized_path,
1648 });1653 });
1649 }1654 }
src/print_env.zig+1-1
...@@ -26,7 +26,7 @@ pub fn cmdEnv(arena: Allocator, args: []const []const u8) !void {...@@ -26,7 +26,7 @@ pub fn cmdEnv(arena: Allocator, args: []const []const u8) !void {
26 .buffer = &buffer,26 .buffer = &buffer,
27 .unbuffered_writer = std.io.getStdOut().writer(),27 .unbuffered_writer = std.io.getStdOut().writer(),
28 };28 };
29 var jws = std.json.writeStream(bw, .{ .whitespace = .indent_1 });29 var jws: std.json.Stringify = .{ .writer = &bw, .options = .{ .whitespace = .indent_1 } };
3030
31 try jws.beginObject();31 try jws.beginObject();
3232