authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-04-27 13:07:58-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-07-01 16:35:28-07:00
logab3a947bef0b167665068ab40232609e4d9b656c
tree43a05171c80cea016cb603f76c72526530dc86e0
parent81b0d14e2ba43732c80a259b578997f167c23cdd

get build runner compiling again


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

lib/std/Build/Cache.zig+7-14
......@@ -335,7 +335,6 @@ pub const Manifest = struct {
335335 manifest_create: fs.File.OpenError,
336336 manifest_read: fs.File.ReadError,
337337 manifest_lock: fs.File.LockError,
338 manifest_seek: fs.File.SeekError,
339338 file_open: FileOp,
340339 file_stat: FileOp,
341340 file_read: FileOp,
......@@ -609,12 +608,6 @@ pub const Manifest = struct {
609608 var file = self.files.pop().?;
610609 file.key.deinit(self.cache.gpa);
611610 }
612 // Also, seek the file back to the start.
613 self.manifest_file.?.seekTo(0) catch |err| {
614 self.diagnostic = .{ .manifest_seek = err };
615 return error.CacheCheckFailed;
616 };
617
618611 switch (try self.hitWithCurrentLock()) {
619612 .hit => break :hit,
620613 .miss => |m| break :digests m.file_digests_populated,
......@@ -659,9 +652,8 @@ pub const Manifest = struct {
659652 return true;
660653 }
661654
662 /// Assumes that `self.hash.hasher` has been updated only with the original digest, that
663 /// `self.files` contains only the original input files, and that `self.manifest_file.?` is
664 /// seeked to the start of the file.
655 /// Assumes that `self.hash.hasher` has been updated only with the original digest and that
656 /// `self.files` contains only the original input files.
665657 fn hitWithCurrentLock(self: *Manifest) HitError!union(enum) {
666658 hit,
667659 miss: struct {
......@@ -670,12 +662,13 @@ pub const Manifest = struct {
670662 } {
671663 const gpa = self.cache.gpa;
672664 const input_file_count = self.files.entries.len;
673
674 const file_contents = self.manifest_file.?.reader().readAllAlloc(gpa, manifest_file_size_max) catch |err| switch (err) {
665 var manifest_reader = self.manifest_file.?.reader(); // Reads positionally from zero.
666 const limit: std.io.Reader.Limit = .limited(manifest_file_size_max);
667 const file_contents = manifest_reader.interface().readRemainingAlloc(gpa, limit) catch |err| switch (err) {
675668 error.OutOfMemory => return error.OutOfMemory,
676669 error.StreamTooLong => return error.OutOfMemory,
677 else => |e| {
678 self.diagnostic = .{ .manifest_read = e };
670 error.ReadFailed => {
671 self.diagnostic = .{ .manifest_read = manifest_reader.err.? };
679672 return error.CacheCheckFailed;
680673 },
681674 };
lib/std/Build/Fuzz/WebServer.zig+4-6
......@@ -109,7 +109,7 @@ fn accept(ws: *WebServer, connection: std.net.Server.Connection) void {
109109 var server: std.http.Server = .init(&br, &bw);
110110 var web_socket: std.http.WebSocket = undefined;
111111 var ws_recv_buffer: [0x4000]u8 align(4) = undefined;
112 while (server.state == .ready) {
112 while (server.reader.state == .ready) {
113113 var request = server.receiveHead() catch |err| switch (err) {
114114 error.HttpConnectionClosing => return,
115115 else => {
......@@ -476,7 +476,7 @@ fn serveSourcesTar(ws: *WebServer, request: *std.http.Server.Request) !void {
476476 defer arena_instance.deinit();
477477 const arena = arena_instance.allocator();
478478
479 var response = try request.respondStreaming(.{
479 var body_writer = try request.respondStreaming(.{
480480 .respond_options = .{
481481 .extra_headers = &.{
482482 .{ .name = "content-type", .value = "application/x-tar" },
......@@ -517,7 +517,7 @@ fn serveSourcesTar(ws: *WebServer, request: *std.http.Server.Request) !void {
517517
518518 var cwd_cache: ?[]const u8 = null;
519519
520 var response_writer = response.writer().unbuffered();
520 var response_writer = body_writer.interface().unbuffered();
521521 var archiver: std.tar.Writer = .{ .underlying_writer = &response_writer };
522522
523523 for (deduped_paths) |joined_path| {
......@@ -531,9 +531,7 @@ fn serveSourcesTar(ws: *WebServer, request: *std.http.Server.Request) !void {
531531 try archiver.writeFile(joined_path.sub_path, file, try file.stat());
532532 }
533533
534 // intentionally omitting the pointless trailer
535 //try archiver.finish();
536 try response.end();
534 try body_writer.end();
537535}
538536
539537fn memoizedCwd(arena: Allocator, opt_ptr: *?[]const u8) ![]const u8 {
lib/std/Build/Step.zig+1-1
......@@ -812,7 +812,7 @@ fn failWithCacheError(s: *Step, man: *const Build.Cache.Manifest, err: Build.Cac
812812 switch (err) {
813813 error.CacheCheckFailed => switch (man.diagnostic) {
814814 .none => unreachable,
815 .manifest_create, .manifest_read, .manifest_lock, .manifest_seek => |e| return s.fail("failed to check cache: {s} {s}", .{
815 .manifest_create, .manifest_read, .manifest_lock => |e| return s.fail("failed to check cache: {s} {s}", .{
816816 @tagName(man.diagnostic), @errorName(e),
817817 }),
818818 .file_open, .file_stat, .file_read, .file_hash => |op| {
lib/std/http.zig+2
......@@ -772,6 +772,7 @@ pub const BodyWriter = struct {
772772 /// * `endChunked`
773773 pub fn endUnflushed(w: *BodyWriter) WriteError!void {
774774 switch (w.state) {
775 .end => unreachable,
775776 .content_length => |len| {
776777 assert(len == 0); // Trips when end() called before all bytes written.
777778 w.state = .end;
......@@ -1033,6 +1034,7 @@ pub const BodyWriter = struct {
10331034 .writeSplat = chunkedWriteSplat,
10341035 .writeFile = chunkedWriteFile,
10351036 },
1037 .end => unreachable,
10361038 },
10371039 };
10381040 }
lib/std/http/Server.zig+4-4
......@@ -11,7 +11,6 @@ const Server = @This();
1111
1212/// Data from the HTTP server to the HTTP client.
1313out: *std.io.BufferedWriter,
14/// Internal state managed by this abstraction.
1514reader: http.Reader,
1615
1716/// Initialize an HTTP server that can respond to multiple requests on the same
......@@ -26,6 +25,7 @@ pub fn init(in: *std.io.BufferedReader, out: *std.io.BufferedWriter) Server {
2625 .reader = .{
2726 .in = in,
2827 .state = .ready,
28 .body_state = undefined,
2929 },
3030 .out = out,
3131 };
......@@ -39,7 +39,7 @@ pub const ReceiveHeadError = http.Reader.HeadError || error{
3939 HttpHeadersInvalid,
4040};
4141
42pub fn receiveHead(s: *Server) http.Reader.HeadError!Request {
42pub fn receiveHead(s: *Server) ReceiveHeadError!Request {
4343 try s.reader.receiveHead();
4444 return .{
4545 .server = s,
......@@ -490,13 +490,13 @@ pub const Request = struct {
490490
491491 return .{
492492 .http_protocol_output = request.server.out,
493 .transfer_encoding = if (o.transfer_encoding) |te| switch (te) {
493 .state = if (o.transfer_encoding) |te| switch (te) {
494494 .chunked => .{ .chunked = .init },
495495 .none => .none,
496496 } else if (options.content_length) |len| .{
497497 .content_length = len,
498498 } else .{ .chunked = .init },
499 .elide_body = elide_body,
499 .elide = elide_body,
500500 };
501501 }
502502
lib/std/tar/Writer.zig+8-3
......@@ -50,9 +50,14 @@ pub fn writeFile(
5050 try w.setPath(&header, sub_path);
5151 try header.setSize(stat.size);
5252 try header.setMtime(mtime);
53 try header.write(w.underlying_writer);
54
55 try w.underlying_writer.writeFileAll(file, .{ .limit = .limited(stat.size) });
53 try header.updateChecksum();
54
55 var vec: [1][]const u8 = .{@ptrCast((&header)[0..1])};
56 try w.underlying_writer.writeFileAll(file, .{
57 .limit = .limited(stat.size),
58 .headers_and_trailers = &vec,
59 .headers_len = 1,
60 });
5661 try w.writePadding(stat.size);
5762}
5863