authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-03-01 23:45:54-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-03-15 10:48:13-07:00
loga2dc49a0f3d5761eae271d9b353542edb6e8f6e9
tree3b3e5b3fdcca56039f828aa65ddee202c71bbef6
parent58edefc6d1716c0731ee2fe672ec8d073651aafb

fix Step.evalZigProcess to handle more than 1 message per poll


1 files changed, 49 insertions(+), 48 deletions(-)

lib/std/Build/Step.zig+49-48
...@@ -240,57 +240,58 @@ pub fn evalZigProcess(...@@ -240,57 +240,58 @@ pub fn evalZigProcess(
240 var sub_prog_node: ?std.Progress.Node = null;240 var sub_prog_node: ?std.Progress.Node = null;
241 defer if (sub_prog_node) |*n| n.end();241 defer if (sub_prog_node) |*n| n.end();
242242
243 while (try poller.poll()) {243 const stdout = poller.fifo(.stdout);
244 const stdout = poller.fifo(.stdout);244
245 const buf = stdout.readableSlice(0);245 poll: while (try poller.poll()) {
246 assert(stdout.readableLength() == buf.len);246 while (true) {
247 if (buf.len >= @sizeOf(Header)) {247 const buf = stdout.readableSlice(0);
248 assert(stdout.readableLength() == buf.len);
249 if (buf.len < @sizeOf(Header)) continue :poll;
248 const header = @ptrCast(*align(1) const Header, buf[0..@sizeOf(Header)]);250 const header = @ptrCast(*align(1) const Header, buf[0..@sizeOf(Header)]);
249 const header_and_msg_len = header.bytes_len + @sizeOf(Header);251 const header_and_msg_len = header.bytes_len + @sizeOf(Header);
250 if (buf.len >= header_and_msg_len) {252 if (buf.len < header_and_msg_len) continue :poll;
251 const body = buf[@sizeOf(Header)..][0..header.bytes_len];253 const body = buf[@sizeOf(Header)..][0..header.bytes_len];
252 switch (header.tag) {254 switch (header.tag) {
253 .zig_version => {255 .zig_version => {
254 if (!std.mem.eql(u8, builtin.zig_version_string, body)) {256 if (!std.mem.eql(u8, builtin.zig_version_string, body)) {
255 return s.fail(257 return s.fail(
256 "zig version mismatch build runner vs compiler: '{s}' vs '{s}'",258 "zig version mismatch build runner vs compiler: '{s}' vs '{s}'",
257 .{ builtin.zig_version_string, body },259 .{ builtin.zig_version_string, body },
258 );260 );
259 }261 }
260 },262 },
261 .error_bundle => {263 .error_bundle => {
262 const EbHdr = std.zig.Server.Message.ErrorBundle;264 const EbHdr = std.zig.Server.Message.ErrorBundle;
263 const eb_hdr = @ptrCast(*align(1) const EbHdr, body);265 const eb_hdr = @ptrCast(*align(1) const EbHdr, body);
264 const extra_bytes =266 const extra_bytes =
265 body[@sizeOf(EbHdr)..][0 .. @sizeOf(u32) * eb_hdr.extra_len];267 body[@sizeOf(EbHdr)..][0 .. @sizeOf(u32) * eb_hdr.extra_len];
266 const string_bytes =268 const string_bytes =
267 body[@sizeOf(EbHdr) + extra_bytes.len ..][0..eb_hdr.string_bytes_len];269 body[@sizeOf(EbHdr) + extra_bytes.len ..][0..eb_hdr.string_bytes_len];
268 // TODO: use @ptrCast when the compiler supports it270 // TODO: use @ptrCast when the compiler supports it
269 const unaligned_extra = std.mem.bytesAsSlice(u32, extra_bytes);271 const unaligned_extra = std.mem.bytesAsSlice(u32, extra_bytes);
270 const extra_array = try arena.alloc(u32, unaligned_extra.len);272 const extra_array = try arena.alloc(u32, unaligned_extra.len);
271 // TODO: use @memcpy when it supports slices273 // TODO: use @memcpy when it supports slices
272 for (extra_array, unaligned_extra) |*dst, src| dst.* = src;274 for (extra_array, unaligned_extra) |*dst, src| dst.* = src;
273 s.result_error_bundle = .{275 s.result_error_bundle = .{
274 .string_bytes = try arena.dupe(u8, string_bytes),276 .string_bytes = try arena.dupe(u8, string_bytes),
275 .extra = extra_array,277 .extra = extra_array,
276 };278 };
277 },279 },
278 .progress => {280 .progress => {
279 if (sub_prog_node) |*n| n.end();281 if (sub_prog_node) |*n| n.end();
280 node_name.clearRetainingCapacity();282 node_name.clearRetainingCapacity();
281 try node_name.appendSlice(gpa, body);283 try node_name.appendSlice(gpa, body);
282 sub_prog_node = prog_node.start(node_name.items, 0);284 sub_prog_node = prog_node.start(node_name.items, 0);
283 sub_prog_node.?.activate();285 sub_prog_node.?.activate();
284 },286 },
285 .emit_bin_path => {287 .emit_bin_path => {
286 result = try arena.dupe(u8, body);288 result = try arena.dupe(u8, body);
287 },289 },
288 _ => {290 _ => {
289 // Unrecognized message.291 // Unrecognized message.
290 },292 },
291 }
292 stdout.discard(header_and_msg_len);
293 }293 }
294 stdout.discard(header_and_msg_len);
294 }295 }
295 }296 }
296297