authorgravatar for stephen@hexops.comStephen Gutekanst <stephen@hexops.com> 2022-02-21 13:06:23-07:00
committergravatar for stephen@hexops.comStephen Gutekanst <stephen@hexops.com> 2022-02-21 13:06:23-07:00
logefd473bbfc1417c5cc376f1b8ec44036752570bf
treebfe76a535217426ce8330f32db12bfac34958810
parent9c1c4747f46cbf2911d3383154acce41b3f532c4

std: Builder: use response files for zig test invocations too

Signed-off-by: Stephen Gutekanst <stephen@hexops.com>

1 files changed, 32 insertions(+), 39 deletions(-)

lib/std/build.zig+32-39
...@@ -2889,48 +2889,41 @@ pub const LibExeObjStep = struct {...@@ -2889,48 +2889,41 @@ pub const LibExeObjStep = struct {
28892889
2890 try zig_args.append("--enable-cache");2890 try zig_args.append("--enable-cache");
28912891
2892 const is_build = switch (self.kind) {2892 // Windows has an argument length limit of 32,766 characters, macOS 262,144 and Linux
2893 .lib => true,2893 // 2,097,152. If our args exceed 30 KiB, we instead write them to a "response file" and
2894 .exe => true,2894 // pass that to zig, e.g. via 'zig build-lib @args.rsp'
2895 .obj => true,2895 var args_length: usize = 0;
2896 else => false,2896 for (zig_args.items) |arg| {
2897 };2897 args_length += arg.len + 1; // +1 to account for null terminator
2898 if (is_build) {2898 }
2899 // Windows has an argument length limit of 32,766 characters, macOS 262,144 and Linux2899 if (args_length >= 30 * 1024) {
2900 // 2,097,152. If our args exceed 30 KiB, we instead write them to a "response file" and2900 const args_dir = try fs.path.join(
2901 // pass that to zig, e.g. via 'zig build-lib @args.rsp'2901 builder.allocator,
2902 var args_length: usize = 0;2902 &[_][]const u8{ builder.pathFromRoot("zig-cache"), "args" },
2903 for (zig_args.items) |arg| {2903 );
2904 args_length += arg.len + 1; // +1 to account for null terminator2904 try std.fs.cwd().makePath(args_dir);
2905 }2905
2906 if (args_length >= 30 * 1024) {2906 // Write the args to zig-cache/args/<SHA256 hash of args> to avoid conflicts with
2907 const args_dir = try fs.path.join(2907 // other zig build commands running in parallel.
2908 builder.allocator,2908 const partially_quoted = try std.mem.join(builder.allocator, "\" \"", zig_args.items[2..]);
2909 &[_][]const u8{ builder.pathFromRoot("zig-cache"), "args" },2909 const args = try std.mem.concat(builder.allocator, u8, &[_][]const u8{ "\"", partially_quoted, "\"" });
2910 );2910
2911 try std.fs.cwd().makePath(args_dir);2911 var args_hash: [Sha256.digest_length]u8 = undefined;
29122912 Sha256.hash(args, &args_hash, .{});
2913 // Write the args to zig-cache/args/<SHA256 hash of args> to avoid conflicts with2913 var args_hex_hash: [Sha256.digest_length * 2]u8 = undefined;
2914 // other zig build commands running in parallel.2914 _ = try std.fmt.bufPrint(
2915 const partially_quoted = try std.mem.join(builder.allocator, "\" \"", zig_args.items[2..]);2915 &args_hex_hash,
2916 const args = try std.mem.concat(builder.allocator, u8, &[_][]const u8{ "\"", partially_quoted, "\"" });2916 "{s}",
29172917 .{std.fmt.fmtSliceHexLower(&args_hash)},
2918 var args_hash: [Sha256.digest_length]u8 = undefined;2918 );
2919 Sha256.hash(args, &args_hash, .{});
2920 var args_hex_hash: [Sha256.digest_length * 2]u8 = undefined;
2921 _ = try std.fmt.bufPrint(
2922 &args_hex_hash,
2923 "{s}",
2924 .{std.fmt.fmtSliceHexLower(&args_hash)},
2925 );
29262919
2927 const args_file = try fs.path.join(builder.allocator, &[_][]const u8{ args_dir, args_hex_hash[0..] });2920 const args_file = try fs.path.join(builder.allocator, &[_][]const u8{ args_dir, args_hex_hash[0..] });
2928 try std.fs.cwd().writeFile(args_file, args);2921 try std.fs.cwd().writeFile(args_file, args);
29292922
2930 zig_args.shrinkRetainingCapacity(2);2923 zig_args.shrinkRetainingCapacity(2);
2931 try zig_args.append(try std.mem.concat(builder.allocator, u8, &[_][]const u8{ "@", args_file }));2924 try zig_args.append(try std.mem.concat(builder.allocator, u8, &[_][]const u8{ "@", args_file }));
2932 }
2933 }2925 }
2926
2934 const output_dir_nl = try builder.execFromStep(zig_args.items, &self.step);2927 const output_dir_nl = try builder.execFromStep(zig_args.items, &self.step);
2935 const build_output_dir = mem.trimRight(u8, output_dir_nl, "\r\n");2928 const build_output_dir = mem.trimRight(u8, output_dir_nl, "\r\n");
29362929