| ... | @@ -130,10 +130,10 @@ const TargetToHash = std.ArrayHashMap(DestTarget, []const u8, DestTarget.HashCon | ... | @@ -130,10 +130,10 @@ const TargetToHash = std.ArrayHashMap(DestTarget, []const u8, DestTarget.HashCon |
| 130 | const PathTable = std.StringHashMap(*TargetToHash); | 130 | const PathTable = std.StringHashMap(*TargetToHash); |
| 131 | | 131 | |
| 132 | pub fn main() !void { | 132 | pub fn main() !void { |
| 133 | var arena = std.heap.ArenaAllocator.init(std.heap.page_allocator); | 133 | var arena_state = std.heap.ArenaAllocator.init(std.heap.page_allocator); |
| 134 | const allocator = &arena.allocator; | 134 | const arena = &arena_state.allocator; |
| 135 | const args = try std.process.argsAlloc(allocator); | 135 | const args = try std.process.argsAlloc(arena); |
| 136 | var search_paths = std.ArrayList([]const u8).init(allocator); | 136 | var search_paths = std.ArrayList([]const u8).init(arena); |
| 137 | var opt_out_dir: ?[]const u8 = null; | 137 | var opt_out_dir: ?[]const u8 = null; |
| 138 | | 138 | |
| 139 | var arg_i: usize = 1; | 139 | var arg_i: usize = 1; |
| ... | @@ -161,8 +161,8 @@ pub fn main() !void { | ... | @@ -161,8 +161,8 @@ pub fn main() !void { |
| 161 | const out_dir = opt_out_dir orelse usageAndExit(args[0]); | 161 | const out_dir = opt_out_dir orelse usageAndExit(args[0]); |
| 162 | const generic_name = "any-linux-any"; | 162 | const generic_name = "any-linux-any"; |
| 163 | | 163 | |
| 164 | var path_table = PathTable.init(allocator); | 164 | var path_table = PathTable.init(arena); |
| 165 | var hash_to_contents = HashToContents.init(allocator); | 165 | var hash_to_contents = HashToContents.init(arena); |
| 166 | var max_bytes_saved: usize = 0; | 166 | var max_bytes_saved: usize = 0; |
| 167 | var total_bytes: usize = 0; | 167 | var total_bytes: usize = 0; |
| 168 | | 168 | |
| ... | @@ -173,10 +173,10 @@ pub fn main() !void { | ... | @@ -173,10 +173,10 @@ pub fn main() !void { |
| 173 | .arch = linux_target.arch, | 173 | .arch = linux_target.arch, |
| 174 | }; | 174 | }; |
| 175 | search: for (search_paths.items) |search_path| { | 175 | search: for (search_paths.items) |search_path| { |
| 176 | const target_include_dir = try std.fs.path.join(allocator, &.{ | 176 | const target_include_dir = try std.fs.path.join(arena, &.{ |
| 177 | search_path, linux_target.name, "include", | 177 | search_path, linux_target.name, "include", |
| 178 | }); | 178 | }); |
| 179 | var dir_stack = std.ArrayList([]const u8).init(allocator); | 179 | var dir_stack = std.ArrayList([]const u8).init(arena); |
| 180 | try dir_stack.append(target_include_dir); | 180 | try dir_stack.append(target_include_dir); |
| 181 | | 181 | |
| 182 | while (dir_stack.popOrNull()) |full_dir_name| { | 182 | while (dir_stack.popOrNull()) |full_dir_name| { |
| ... | @@ -190,16 +190,16 @@ pub fn main() !void { | ... | @@ -190,16 +190,16 @@ pub fn main() !void { |
| 190 | var dir_it = dir.iterate(); | 190 | var dir_it = dir.iterate(); |
| 191 | | 191 | |
| 192 | while (try dir_it.next()) |entry| { | 192 | while (try dir_it.next()) |entry| { |
| 193 | const full_path = try std.fs.path.join(allocator, &[_][]const u8{ full_dir_name, entry.name }); | 193 | const full_path = try std.fs.path.join(arena, &[_][]const u8{ full_dir_name, entry.name }); |
| 194 | switch (entry.kind) { | 194 | switch (entry.kind) { |
| 195 | .Directory => try dir_stack.append(full_path), | 195 | .Directory => try dir_stack.append(full_path), |
| 196 | .File => { | 196 | .File => { |
| 197 | const rel_path = try std.fs.path.relative(allocator, target_include_dir, full_path); | 197 | const rel_path = try std.fs.path.relative(arena, target_include_dir, full_path); |
| 198 | const max_size = 2 * 1024 * 1024 * 1024; | 198 | const max_size = 2 * 1024 * 1024 * 1024; |
| 199 | const raw_bytes = try std.fs.cwd().readFileAlloc(allocator, full_path, max_size); | 199 | const raw_bytes = try std.fs.cwd().readFileAlloc(arena, full_path, max_size); |
| 200 | const trimmed = std.mem.trim(u8, raw_bytes, " \r\n\t"); | 200 | const trimmed = std.mem.trim(u8, raw_bytes, " \r\n\t"); |
| 201 | total_bytes += raw_bytes.len; | 201 | total_bytes += raw_bytes.len; |
| 202 | const hash = try allocator.alloc(u8, 32); | 202 | const hash = try arena.alloc(u8, 32); |
| 203 | hasher = Blake3.init(.{}); | 203 | hasher = Blake3.init(.{}); |
| 204 | hasher.update(rel_path); | 204 | hasher.update(rel_path); |
| 205 | hasher.update(trimmed); | 205 | hasher.update(trimmed); |
| ... | @@ -223,8 +223,8 @@ pub fn main() !void { | ... | @@ -223,8 +223,8 @@ pub fn main() !void { |
| 223 | } | 223 | } |
| 224 | const path_gop = try path_table.getOrPut(rel_path); | 224 | const path_gop = try path_table.getOrPut(rel_path); |
| 225 | const target_to_hash = if (path_gop.found_existing) path_gop.value_ptr.* else blk: { | 225 | const target_to_hash = if (path_gop.found_existing) path_gop.value_ptr.* else blk: { |
| 226 | const ptr = try allocator.create(TargetToHash); | 226 | const ptr = try arena.create(TargetToHash); |
| 227 | ptr.* = TargetToHash.init(allocator); | 227 | ptr.* = TargetToHash.init(arena); |
| 228 | path_gop.value_ptr.* = ptr; | 228 | path_gop.value_ptr.* = ptr; |
| 229 | break :blk ptr; | 229 | break :blk ptr; |
| 230 | }; | 230 | }; |
| ... | @@ -251,7 +251,7 @@ pub fn main() !void { | ... | @@ -251,7 +251,7 @@ pub fn main() !void { |
| 251 | // gets their header in a separate arch directory. | 251 | // gets their header in a separate arch directory. |
| 252 | var path_it = path_table.iterator(); | 252 | var path_it = path_table.iterator(); |
| 253 | while (path_it.next()) |path_kv| { | 253 | while (path_it.next()) |path_kv| { |
| 254 | var contents_list = std.ArrayList(*Contents).init(allocator); | 254 | var contents_list = std.ArrayList(*Contents).init(arena); |
| 255 | { | 255 | { |
| 256 | var hash_it = path_kv.value_ptr.*.iterator(); | 256 | var hash_it = path_kv.value_ptr.*.iterator(); |
| 257 | while (hash_it.next()) |hash_kv| { | 257 | while (hash_it.next()) |hash_kv| { |
| ... | @@ -263,7 +263,7 @@ pub fn main() !void { | ... | @@ -263,7 +263,7 @@ pub fn main() !void { |
| 263 | const best_contents = contents_list.popOrNull().?; | 263 | const best_contents = contents_list.popOrNull().?; |
| 264 | if (best_contents.hit_count > 1) { | 264 | if (best_contents.hit_count > 1) { |
| 265 | // worth it to make it generic | 265 | // worth it to make it generic |
| 266 | const full_path = try std.fs.path.join(allocator, &[_][]const u8{ out_dir, generic_name, path_kv.key_ptr.* }); | 266 | const full_path = try std.fs.path.join(arena, &[_][]const u8{ out_dir, generic_name, path_kv.key_ptr.* }); |
| 267 | try std.fs.cwd().makePath(std.fs.path.dirname(full_path).?); | 267 | try std.fs.cwd().makePath(std.fs.path.dirname(full_path).?); |
| 268 | try std.fs.cwd().writeFile(full_path, best_contents.bytes); | 268 | try std.fs.cwd().writeFile(full_path, best_contents.bytes); |
| 269 | best_contents.is_generic = true; | 269 | best_contents.is_generic = true; |
| ... | @@ -288,12 +288,27 @@ pub fn main() !void { | ... | @@ -288,12 +288,27 @@ pub fn main() !void { |
| 288 | .specific => |a| @tagName(a), | 288 | .specific => |a| @tagName(a), |
| 289 | else => @tagName(dest_target.arch), | 289 | else => @tagName(dest_target.arch), |
| 290 | }; | 290 | }; |
| 291 | const out_subpath = try std.fmt.allocPrint(allocator, "{s}-linux-any", .{arch_name}); | 291 | const out_subpath = try std.fmt.allocPrint(arena, "{s}-linux-any", .{arch_name}); |
| 292 | const full_path = try std.fs.path.join(allocator, &[_][]const u8{ out_dir, out_subpath, path_kv.key_ptr.* }); | 292 | const full_path = try std.fs.path.join(arena, &[_][]const u8{ out_dir, out_subpath, path_kv.key_ptr.* }); |
| 293 | try std.fs.cwd().makePath(std.fs.path.dirname(full_path).?); | 293 | try std.fs.cwd().makePath(std.fs.path.dirname(full_path).?); |
| 294 | try std.fs.cwd().writeFile(full_path, contents.bytes); | 294 | try std.fs.cwd().writeFile(full_path, contents.bytes); |
| 295 | } | 295 | } |
| 296 | } | 296 | } |
| | 297 | |
| | 298 | const bad_files = [_][]const u8{ |
| | 299 | "any-linux-any/linux/netfilter/xt_CONNMARK.h", |
| | 300 | "any-linux-any/linux/netfilter/xt_DSCP.h", |
| | 301 | "any-linux-any/linux/netfilter/xt_MARK.h", |
| | 302 | "any-linux-any/linux/netfilter/xt_RATEEST.h", |
| | 303 | "any-linux-any/linux/netfilter/xt_TCPMSS.h", |
| | 304 | "any-linux-any/linux/netfilter_ipv4/ipt_ECN.h", |
| | 305 | "any-linux-any/linux/netfilter_ipv4/ipt_TTL.h", |
| | 306 | "any-linux-any/linux/netfilter_ipv6/ip6t_HL.h", |
| | 307 | }; |
| | 308 | for (bad_files) |bad_file| { |
| | 309 | const full_path = try std.fs.path.join(arena, &[_][]const u8{ out_dir, bad_file }); |
| | 310 | try std.fs.cwd().deleteFile(full_path); |
| | 311 | } |
| 297 | } | 312 | } |
| 298 | | 313 | |
| 299 | fn usageAndExit(arg0: []const u8) noreturn { | 314 | fn usageAndExit(arg0: []const u8) noreturn { |