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