commit efd473bbfc1417c5cc376f1b8ec44036752570bf (tree)
parent 9c1c4747f46cbf2911d3383154acce41b3f532c4
Author: Stephen Gutekanst <stephen@hexops.com>
Date: Mon, 21 Feb 2022 13:06:23 -0700
std: Builder: use response files for zig test invocations too
Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
Diffstat:
| M | lib/std/build.zig | | | 71 | ++++++++++++++++++++++++++++++++--------------------------------------- |
1 file changed, 32 insertions(+), 39 deletions(-)
diff --git a/lib/std/build.zig b/lib/std/build.zig
@@ -2889,48 +2889,41 @@ pub const LibExeObjStep = struct {
try zig_args.append("--enable-cache");
- const is_build = switch (self.kind) {
- .lib => true,
- .exe => true,
- .obj => true,
- else => false,
- };
- if (is_build) {
- // Windows has an argument length limit of 32,766 characters, macOS 262,144 and Linux
- // 2,097,152. If our args exceed 30 KiB, we instead write them to a "response file" and
- // pass that to zig, e.g. via 'zig build-lib @args.rsp'
- var args_length: usize = 0;
- for (zig_args.items) |arg| {
- args_length += arg.len + 1; // +1 to account for null terminator
- }
- if (args_length >= 30 * 1024) {
- const args_dir = try fs.path.join(
- builder.allocator,
- &[_][]const u8{ builder.pathFromRoot("zig-cache"), "args" },
- );
- try std.fs.cwd().makePath(args_dir);
-
- // Write the args to zig-cache/args/<SHA256 hash of args> to avoid conflicts with
- // other zig build commands running in parallel.
- const partially_quoted = try std.mem.join(builder.allocator, "\" \"", zig_args.items[2..]);
- const args = try std.mem.concat(builder.allocator, u8, &[_][]const u8{ "\"", partially_quoted, "\"" });
-
- var args_hash: [Sha256.digest_length]u8 = undefined;
- Sha256.hash(args, &args_hash, .{});
- var args_hex_hash: [Sha256.digest_length * 2]u8 = undefined;
- _ = try std.fmt.bufPrint(
- &args_hex_hash,
- "{s}",
- .{std.fmt.fmtSliceHexLower(&args_hash)},
- );
+ // Windows has an argument length limit of 32,766 characters, macOS 262,144 and Linux
+ // 2,097,152. If our args exceed 30 KiB, we instead write them to a "response file" and
+ // pass that to zig, e.g. via 'zig build-lib @args.rsp'
+ var args_length: usize = 0;
+ for (zig_args.items) |arg| {
+ args_length += arg.len + 1; // +1 to account for null terminator
+ }
+ if (args_length >= 30 * 1024) {
+ const args_dir = try fs.path.join(
+ builder.allocator,
+ &[_][]const u8{ builder.pathFromRoot("zig-cache"), "args" },
+ );
+ try std.fs.cwd().makePath(args_dir);
+
+ // Write the args to zig-cache/args/<SHA256 hash of args> to avoid conflicts with
+ // other zig build commands running in parallel.
+ const partially_quoted = try std.mem.join(builder.allocator, "\" \"", zig_args.items[2..]);
+ const args = try std.mem.concat(builder.allocator, u8, &[_][]const u8{ "\"", partially_quoted, "\"" });
+
+ var args_hash: [Sha256.digest_length]u8 = undefined;
+ Sha256.hash(args, &args_hash, .{});
+ var args_hex_hash: [Sha256.digest_length * 2]u8 = undefined;
+ _ = try std.fmt.bufPrint(
+ &args_hex_hash,
+ "{s}",
+ .{std.fmt.fmtSliceHexLower(&args_hash)},
+ );
- const args_file = try fs.path.join(builder.allocator, &[_][]const u8{ args_dir, args_hex_hash[0..] });
- try std.fs.cwd().writeFile(args_file, args);
+ const args_file = try fs.path.join(builder.allocator, &[_][]const u8{ args_dir, args_hex_hash[0..] });
+ try std.fs.cwd().writeFile(args_file, args);
- zig_args.shrinkRetainingCapacity(2);
- try zig_args.append(try std.mem.concat(builder.allocator, u8, &[_][]const u8{ "@", args_file }));
- }
+ zig_args.shrinkRetainingCapacity(2);
+ try zig_args.append(try std.mem.concat(builder.allocator, u8, &[_][]const u8{ "@", args_file }));
}
+
const output_dir_nl = try builder.execFromStep(zig_args.items, &self.step);
const build_output_dir = mem.trimRight(u8, output_dir_nl, "\r\n");