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 {...@@ -335,7 +335,6 @@ pub const Manifest = struct {
335 manifest_create: fs.File.OpenError,335 manifest_create: fs.File.OpenError,
336 manifest_read: fs.File.ReadError,336 manifest_read: fs.File.ReadError,
337 manifest_lock: fs.File.LockError,337 manifest_lock: fs.File.LockError,
338 manifest_seek: fs.File.SeekError,
339 file_open: FileOp,338 file_open: FileOp,
340 file_stat: FileOp,339 file_stat: FileOp,
341 file_read: FileOp,340 file_read: FileOp,
...@@ -609,12 +608,6 @@ pub const Manifest = struct {...@@ -609,12 +608,6 @@ pub const Manifest = struct {
609 var file = self.files.pop().?;608 var file = self.files.pop().?;
610 file.key.deinit(self.cache.gpa);609 file.key.deinit(self.cache.gpa);
611 }610 }
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
618 switch (try self.hitWithCurrentLock()) {611 switch (try self.hitWithCurrentLock()) {
619 .hit => break :hit,612 .hit => break :hit,
620 .miss => |m| break :digests m.file_digests_populated,613 .miss => |m| break :digests m.file_digests_populated,
...@@ -659,9 +652,8 @@ pub const Manifest = struct {...@@ -659,9 +652,8 @@ pub const Manifest = struct {
659 return true;652 return true;
660 }653 }
661654
662 /// Assumes that `self.hash.hasher` has been updated only with the original digest, that655 /// Assumes that `self.hash.hasher` has been updated only with the original digest and that
663 /// `self.files` contains only the original input files, and that `self.manifest_file.?` is656 /// `self.files` contains only the original input files.
664 /// seeked to the start of the file.
665 fn hitWithCurrentLock(self: *Manifest) HitError!union(enum) {657 fn hitWithCurrentLock(self: *Manifest) HitError!union(enum) {
666 hit,658 hit,
667 miss: struct {659 miss: struct {
...@@ -670,12 +662,13 @@ pub const Manifest = struct {...@@ -670,12 +662,13 @@ pub const Manifest = struct {
670 } {662 } {
671 const gpa = self.cache.gpa;663 const gpa = self.cache.gpa;
672 const input_file_count = self.files.entries.len;664 const input_file_count = self.files.entries.len;
673665 var manifest_reader = self.manifest_file.?.reader(); // Reads positionally from zero.
674 const file_contents = self.manifest_file.?.reader().readAllAlloc(gpa, manifest_file_size_max) catch |err| switch (err) {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) {
675 error.OutOfMemory => return error.OutOfMemory,668 error.OutOfMemory => return error.OutOfMemory,
676 error.StreamTooLong => return error.OutOfMemory,669 error.StreamTooLong => return error.OutOfMemory,
677 else => |e| {670 error.ReadFailed => {
678 self.diagnostic = .{ .manifest_read = e };671 self.diagnostic = .{ .manifest_read = manifest_reader.err.? };
679 return error.CacheCheckFailed;672 return error.CacheCheckFailed;
680 },673 },
681 };674 };
lib/std/Build/Fuzz/WebServer.zig+4-6
...@@ -109,7 +109,7 @@ fn accept(ws: *WebServer, connection: std.net.Server.Connection) void {...@@ -109,7 +109,7 @@ fn accept(ws: *WebServer, connection: std.net.Server.Connection) void {
109 var server: std.http.Server = .init(&br, &bw);109 var server: std.http.Server = .init(&br, &bw);
110 var web_socket: std.http.WebSocket = undefined;110 var web_socket: std.http.WebSocket = undefined;
111 var ws_recv_buffer: [0x4000]u8 align(4) = undefined;111 var ws_recv_buffer: [0x4000]u8 align(4) = undefined;
112 while (server.state == .ready) {112 while (server.reader.state == .ready) {
113 var request = server.receiveHead() catch |err| switch (err) {113 var request = server.receiveHead() catch |err| switch (err) {
114 error.HttpConnectionClosing => return,114 error.HttpConnectionClosing => return,
115 else => {115 else => {
...@@ -476,7 +476,7 @@ fn serveSourcesTar(ws: *WebServer, request: *std.http.Server.Request) !void {...@@ -476,7 +476,7 @@ fn serveSourcesTar(ws: *WebServer, request: *std.http.Server.Request) !void {
476 defer arena_instance.deinit();476 defer arena_instance.deinit();
477 const arena = arena_instance.allocator();477 const arena = arena_instance.allocator();
478478
479 var response = try request.respondStreaming(.{479 var body_writer = try request.respondStreaming(.{
480 .respond_options = .{480 .respond_options = .{
481 .extra_headers = &.{481 .extra_headers = &.{
482 .{ .name = "content-type", .value = "application/x-tar" },482 .{ .name = "content-type", .value = "application/x-tar" },
...@@ -517,7 +517,7 @@ fn serveSourcesTar(ws: *WebServer, request: *std.http.Server.Request) !void {...@@ -517,7 +517,7 @@ fn serveSourcesTar(ws: *WebServer, request: *std.http.Server.Request) !void {
517517
518 var cwd_cache: ?[]const u8 = null;518 var cwd_cache: ?[]const u8 = null;
519519
520 var response_writer = response.writer().unbuffered();520 var response_writer = body_writer.interface().unbuffered();
521 var archiver: std.tar.Writer = .{ .underlying_writer = &response_writer };521 var archiver: std.tar.Writer = .{ .underlying_writer = &response_writer };
522522
523 for (deduped_paths) |joined_path| {523 for (deduped_paths) |joined_path| {
...@@ -531,9 +531,7 @@ fn serveSourcesTar(ws: *WebServer, request: *std.http.Server.Request) !void {...@@ -531,9 +531,7 @@ fn serveSourcesTar(ws: *WebServer, request: *std.http.Server.Request) !void {
531 try archiver.writeFile(joined_path.sub_path, file, try file.stat());531 try archiver.writeFile(joined_path.sub_path, file, try file.stat());
532 }532 }
533533
534 // intentionally omitting the pointless trailer534 try body_writer.end();
535 //try archiver.finish();
536 try response.end();
537}535}
538536
539fn memoizedCwd(arena: Allocator, opt_ptr: *?[]const u8) ![]const u8 {537fn 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...@@ -812,7 +812,7 @@ fn failWithCacheError(s: *Step, man: *const Build.Cache.Manifest, err: Build.Cac
812 switch (err) {812 switch (err) {
813 error.CacheCheckFailed => switch (man.diagnostic) {813 error.CacheCheckFailed => switch (man.diagnostic) {
814 .none => unreachable,814 .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}", .{
816 @tagName(man.diagnostic), @errorName(e),816 @tagName(man.diagnostic), @errorName(e),
817 }),817 }),
818 .file_open, .file_stat, .file_read, .file_hash => |op| {818 .file_open, .file_stat, .file_read, .file_hash => |op| {
lib/std/http.zig+2
...@@ -772,6 +772,7 @@ pub const BodyWriter = struct {...@@ -772,6 +772,7 @@ pub const BodyWriter = struct {
772 /// * `endChunked`772 /// * `endChunked`
773 pub fn endUnflushed(w: *BodyWriter) WriteError!void {773 pub fn endUnflushed(w: *BodyWriter) WriteError!void {
774 switch (w.state) {774 switch (w.state) {
775 .end => unreachable,
775 .content_length => |len| {776 .content_length => |len| {
776 assert(len == 0); // Trips when end() called before all bytes written.777 assert(len == 0); // Trips when end() called before all bytes written.
777 w.state = .end;778 w.state = .end;
...@@ -1033,6 +1034,7 @@ pub const BodyWriter = struct {...@@ -1033,6 +1034,7 @@ pub const BodyWriter = struct {
1033 .writeSplat = chunkedWriteSplat,1034 .writeSplat = chunkedWriteSplat,
1034 .writeFile = chunkedWriteFile,1035 .writeFile = chunkedWriteFile,
1035 },1036 },
1037 .end => unreachable,
1036 },1038 },
1037 };1039 };
1038 }1040 }
lib/std/http/Server.zig+4-4
...@@ -11,7 +11,6 @@ const Server = @This();...@@ -11,7 +11,6 @@ const Server = @This();
1111
12/// Data from the HTTP server to the HTTP client.12/// Data from the HTTP server to the HTTP client.
13out: *std.io.BufferedWriter,13out: *std.io.BufferedWriter,
14/// Internal state managed by this abstraction.
15reader: http.Reader,14reader: http.Reader,
1615
17/// Initialize an HTTP server that can respond to multiple requests on the same16/// 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 {...@@ -26,6 +25,7 @@ pub fn init(in: *std.io.BufferedReader, out: *std.io.BufferedWriter) Server {
26 .reader = .{25 .reader = .{
27 .in = in,26 .in = in,
28 .state = .ready,27 .state = .ready,
28 .body_state = undefined,
29 },29 },
30 .out = out,30 .out = out,
31 };31 };
...@@ -39,7 +39,7 @@ pub const ReceiveHeadError = http.Reader.HeadError || error{...@@ -39,7 +39,7 @@ pub const ReceiveHeadError = http.Reader.HeadError || error{
39 HttpHeadersInvalid,39 HttpHeadersInvalid,
40};40};
4141
42pub fn receiveHead(s: *Server) http.Reader.HeadError!Request {42pub fn receiveHead(s: *Server) ReceiveHeadError!Request {
43 try s.reader.receiveHead();43 try s.reader.receiveHead();
44 return .{44 return .{
45 .server = s,45 .server = s,
...@@ -490,13 +490,13 @@ pub const Request = struct {...@@ -490,13 +490,13 @@ pub const Request = struct {
490490
491 return .{491 return .{
492 .http_protocol_output = request.server.out,492 .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) {
494 .chunked => .{ .chunked = .init },494 .chunked => .{ .chunked = .init },
495 .none => .none,495 .none => .none,
496 } else if (options.content_length) |len| .{496 } else if (options.content_length) |len| .{
497 .content_length = len,497 .content_length = len,
498 } else .{ .chunked = .init },498 } else .{ .chunked = .init },
499 .elide_body = elide_body,499 .elide = elide_body,
500 };500 };
501 }501 }
502502
lib/std/tar/Writer.zig+8-3
...@@ -50,9 +50,14 @@ pub fn writeFile(...@@ -50,9 +50,14 @@ pub fn writeFile(
50 try w.setPath(&header, sub_path);50 try w.setPath(&header, sub_path);
51 try header.setSize(stat.size);51 try header.setSize(stat.size);
52 try header.setMtime(mtime);52 try header.setMtime(mtime);
53 try header.write(w.underlying_writer);53 try header.updateChecksum();
5454
55 try w.underlying_writer.writeFileAll(file, .{ .limit = .limited(stat.size) });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 });
56 try w.writePadding(stat.size);61 try w.writePadding(stat.size);
57}62}
5863