╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ update-linux-headers.zig ─────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭ find file ─ ─ ─ ─ ─ ─ ─ ─ ─ ─╮ ╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │ │ │http│ ssh │ │ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─╯ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
274 try contents_list.append(contents); 275 } 276 } 277 std.mem.sort(*Contents, contents_list.items, {}, Contents.hitCountLessThan); 278 const best_contents = contents_list.pop().?; 279 if (best_contents.hit_count > 1) { 280 // worth it to make it generic 281 const full_path = try Dir.path.join(arena, &[_][]const u8{ out_dir, generic_name, path_kv.key_ptr.* }); 282 try Dir.cwd().createDirPath(io, Dir.path.dirname(full_path).?); 283 try Dir.cwd().writeFile(io, .{ .sub_path = full_path, .data = best_contents.bytes }); 284 best_contents.is_generic = true; 285 while (contents_list.pop()) |contender| { 286 if (contender.hit_count > 1) { 287 const this_missed_bytes = contender.hit_count * contender.bytes.len; 288 missed_opportunity_bytes += this_missed_bytes; 289 std.debug.print("Missed opportunity ({B}): {s}\n", .{ 290 this_missed_bytes, 291 path_kv.key_ptr.*, 292 }); 293 } else break; 294 } 295 } 296 var hash_it = path_kv.value_ptr.*.iterator(); 297 while (hash_it.next()) |hash_kv| { 298 const contents = hash_to_contents.get(hash_kv.value_ptr.*).?; 299 if (contents.is_generic) continue; 300 301 const dest_target = hash_kv.key_ptr.*; 302 const arch_name = switch (dest_target.arch) { 303 .specific => |a| @tagName(a), 304 else => @tagName(dest_target.arch), 305 }; 306 const out_subpath = try std.fmt.allocPrint(arena, "{s}-linux-any", .{arch_name}); 307 const full_path = try Dir.path.join(arena, &[_][]const u8{ out_dir, out_subpath, path_kv.key_ptr.* }); 308 try Dir.cwd().createDirPath(io, Dir.path.dirname(full_path).?); 309 try Dir.cwd().writeFile(io, .{ .sub_path = full_path, .data = contents.bytes }); 310 } 311 } 312 313 const bad_files = [_][]const u8{ 314 "any-linux-any/linux/netfilter/xt_CONNMARK.h", 315 "any-linux-any/linux/netfilter/xt_DSCP.h", 316 "any-linux-any/linux/netfilter/xt_MARK.h", 317 "any-linux-any/linux/netfilter/xt_RATEEST.h", 318 "any-linux-any/linux/netfilter/xt_TCPMSS.h", 319 "any-linux-any/linux/netfilter_ipv4/ipt_ECN.h", 320 "any-linux-any/linux/netfilter_ipv4/ipt_TTL.h", 321 "any-linux-any/linux/netfilter_ipv6/ip6t_HL.h", 322 }; 323 for (bad_files) |bad_file| { 324 const full_path = try Dir.path.join(arena, &[_][]const u8{ out_dir, bad_file }); 325 try Dir.cwd().deleteFile(io, full_path); 326 } 327 } 328 329 fn usageAndExit(arg0: []const u8) noreturn { 330 std.debug.print("Usage: {s} [--search-path <dir>] --out <dir> --abi <name>\n", .{arg0}); 331 std.debug.print("--search-path can be used any number of times.\n", .{}); 332 std.debug.print(" subdirectories of search paths look like, e.g. x86_64-linux-gnu\n", .{}); 333 std.debug.print("--out is a dir that will be created, and populated with the results\n", .{}); 334 std.process.exit(1); 335 } 336