Skip to content

Commit a712aed

Browse files
committed
fix leaking compile-check output binaries
1 parent a6f59cf commit a712aed

1 file changed

Lines changed: 24 additions & 3 deletions

File tree

‎CompileCheck.zig‎

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -193,9 +193,30 @@ fn make(step: *std.Build.Step, options: std.Build.Step.MakeOptions) anyerror!voi
193193
}
194194
}
195195
}
196-
break :blk try std.process.run(b.allocator, b.graph.io, .{
197-
.argv = zig_args.items,
198-
});
196+
switch (check.kind) {
197+
.exe => {
198+
var rand_int: u64 = undefined;
199+
b.graph.io.random(std.mem.asBytes(&rand_int));
200+
const path = "tmp" ++ std.fs.path.sep_str ++ std.fmt.hex(rand_int);
201+
b.cache_root.handle.createDirPath(b.graph.io, path) catch |err| return step.fail(
202+
"create dir '{f}{s}' failed with {t}",
203+
.{ b.cache_root, path, err },
204+
);
205+
const emit_bin_path = try b.cache_root.join(b.allocator, &.{ path, "compilecheck-exe" });
206+
try zig_args.append(b.fmt("-femit-bin={s}", .{emit_bin_path}));
207+
const result = try std.process.run(b.allocator, b.graph.io, .{
208+
.argv = zig_args.items,
209+
});
210+
try b.cache_root.handle.deleteTree(b.graph.io, path);
211+
break :blk result;
212+
},
213+
.header => {
214+
try zig_args.append("-fno-emit-bin");
215+
break :blk try std.process.run(b.allocator, b.graph.io, .{
216+
.argv = zig_args.items,
217+
});
218+
},
219+
}
199220
};
200221

201222
std.debug.assert(result.stdout.len == 0);

0 commit comments

Comments
 (0)