| ... | @@ -7,9 +7,6 @@ const Allocator = std.mem.Allocator; | ... | @@ -7,9 +7,6 @@ const Allocator = std.mem.Allocator; |
| 7 | const assert = std.debug.assert; | 7 | const assert = std.debug.assert; |
| 8 | const log = std.log.scoped(.compilation); | 8 | const log = std.log.scoped(.compilation); |
| 9 | const Target = std.Target; | 9 | const Target = std.Target; |
| 10 | const ArrayList = std.ArrayList; | | |
| 11 | const Sha256 = std.crypto.hash.sha2.Sha256; | | |
| 12 | const fs = std.fs; | | |
| 13 | | 10 | |
| 14 | const Value = @import("value.zig").Value; | 11 | const Value = @import("value.zig").Value; |
| 15 | const Type = @import("type.zig").Type; | 12 | const Type = @import("type.zig").Type; |
| ... | @@ -3970,70 +3967,6 @@ fn updateCObject(comp: *Compilation, c_object: *CObject, c_obj_prog_node: *std.P | ... | @@ -3970,70 +3967,6 @@ fn updateCObject(comp: *Compilation, c_object: *CObject, c_obj_prog_node: *std.P |
| 3970 | } | 3967 | } |
| 3971 | } | 3968 | } |
| 3972 | | 3969 | |
| 3973 | // Windows has an argument length limit of 32,766 characters, macOS 262,144 and Linux | | |
| 3974 | // 2,097,152. If our args exceed 30 KiB, we instead write them to a "response file" and | | |
| 3975 | // pass that to zig, e.g. via 'zig build-lib @args.rsp' | | |
| 3976 | // See @file syntax here: https://gcc.gnu.org/onlinedocs/gcc/Overall-Options.html | | |
| 3977 | var args_length: usize = 0; | | |
| 3978 | for (argv.items) |arg| { | | |
| 3979 | args_length += arg.len + 1; // +1 to account for null terminator | | |
| 3980 | } | | |
| 3981 | if (args_length >= 30 * 1024) { | | |
| 3982 | const allocator = comp.gpa; | | |
| 3983 | const input_args = argv.items[2..]; | | |
| 3984 | const output_dir = comp.local_cache_directory; | | |
| 3985 | | | |
| 3986 | var args_arena = std.heap.ArenaAllocator.init(allocator); | | |
| 3987 | defer args_arena.deinit(); | | |
| 3988 | | | |
| 3989 | const args_to_escape = input_args; | | |
| 3990 | var escaped_args = try ArrayList([]const u8).initCapacity(args_arena.allocator(), args_to_escape.len); | | |
| 3991 | | | |
| 3992 | arg_blk: for (args_to_escape) |arg| { | | |
| 3993 | for (arg) |c, arg_idx| { | | |
| 3994 | if (c == '\\' or c == '"') { | | |
| 3995 | // Slow path for arguments that need to be escaped. We'll need to allocate and copy | | |
| 3996 | var escaped = try ArrayList(u8).initCapacity(args_arena.allocator(), arg.len + 1); | | |
| 3997 | const writer = escaped.writer(); | | |
| 3998 | writer.writeAll(arg[0..arg_idx]) catch unreachable; | | |
| 3999 | for (arg[arg_idx..]) |to_escape| { | | |
| 4000 | if (to_escape == '\\' or to_escape == '"') try writer.writeByte('\\'); | | |
| 4001 | try writer.writeByte(to_escape); | | |
| 4002 | } | | |
| 4003 | escaped_args.appendAssumeCapacity(escaped.items); | | |
| 4004 | continue :arg_blk; | | |
| 4005 | } | | |
| 4006 | } | | |
| 4007 | escaped_args.appendAssumeCapacity(arg); // no escaping needed so just use original argument | | |
| 4008 | } | | |
| 4009 | | | |
| 4010 | const partially_quoted = try std.mem.join(allocator, "\" \"", escaped_args.items); | | |
| 4011 | const args = try std.mem.concat(allocator, u8, &[_][]const u8{ "\"", partially_quoted, "\"" }); | | |
| 4012 | | | |
| 4013 | // Write the args to zig-cache/args/<SHA256 hash of args> to avoid conflicts with | | |
| 4014 | // other zig build commands running in parallel. | | |
| 4015 | | | |
| 4016 | var args_hash: [Sha256.digest_length]u8 = undefined; | | |
| 4017 | Sha256.hash(args, &args_hash, .{}); | | |
| 4018 | var args_hex_hash: [Sha256.digest_length * 2]u8 = undefined; | | |
| 4019 | _ = try std.fmt.bufPrint( | | |
| 4020 | &args_hex_hash, | | |
| 4021 | "{s}", | | |
| 4022 | .{std.fmt.fmtSliceHexLower(&args_hash)}, | | |
| 4023 | ); | | |
| 4024 | | | |
| 4025 | const args_dir = "args"; | | |
| 4026 | try output_dir.handle.makePath(args_dir); | | |
| 4027 | const args_file = try fs.path.join(allocator, &[_][]const u8{ | | |
| 4028 | args_dir, args_hex_hash[0..], | | |
| 4029 | }); | | |
| 4030 | try output_dir.handle.writeFile(args_file, args); | | |
| 4031 | const args_file_path = try output_dir.handle.realpathAlloc(allocator, args_file); | | |
| 4032 | | | |
| 4033 | argv.shrinkRetainingCapacity(2); | | |
| 4034 | try argv.append(try std.mem.concat(allocator, u8, &[_][]const u8{ "@", args_file_path })); | | |
| 4035 | } | | |
| 4036 | | | |
| 4037 | if (comp.verbose_cc) { | 3970 | if (comp.verbose_cc) { |
| 4038 | dump_argv(argv.items); | 3971 | dump_argv(argv.items); |
| 4039 | } | 3972 | } |