| ... | ... | @@ -11,10 +11,10 @@ |
| 11 | 11 | // You'll then have to manually update Zig source repo with these new files. |
| 12 | 12 | |
| 13 | 13 | const std = @import("std"); |
| 14 | | const builtin = @import("builtin"); |
| 15 | | const Arch = builtin.Arch; |
| 16 | | const Abi = builtin.Abi; |
| 17 | | const Os = builtin.Os; |
| 14 | const builtin = std.builtin; |
| 15 | const Arch = std.Target.Cpu.Arch; |
| 16 | const Abi = std.Target.Abi; |
| 17 | const OsTag = std.Target.Os.Tag; |
| 18 | 18 | const assert = std.debug.assert; |
| 19 | 19 | |
| 20 | 20 | const LibCTarget = struct { |
| ... | ... | @@ -29,12 +29,12 @@ const MultiArch = union(enum) { |
| 29 | 29 | mips, |
| 30 | 30 | mips64, |
| 31 | 31 | powerpc64, |
| 32 | | specific: @TagType(Arch), |
| 32 | specific: Arch, |
| 33 | 33 | |
| 34 | 34 | fn eql(a: MultiArch, b: MultiArch) bool { |
| 35 | 35 | if (@enumToInt(a) != @enumToInt(b)) |
| 36 | 36 | return false; |
| 37 | | if (@TagType(MultiArch)(a) != .specific) |
| 37 | if (a != .specific) |
| 38 | 38 | return true; |
| 39 | 39 | return a.specific == b.specific; |
| 40 | 40 | } |
| ... | ... | @@ -221,7 +221,7 @@ const musl_targets = [_]LibCTarget{ |
| 221 | 221 | |
| 222 | 222 | const DestTarget = struct { |
| 223 | 223 | arch: MultiArch, |
| 224 | | os: Os, |
| 224 | os: OsTag, |
| 225 | 225 | abi: Abi, |
| 226 | 226 | |
| 227 | 227 | fn hash(a: DestTarget) u32 { |
| ... | ... | @@ -305,8 +305,8 @@ pub fn main() !void { |
| 305 | 305 | // TODO compiler crashed when I wrote this the canonical way |
| 306 | 306 | var libc_targets: []const LibCTarget = undefined; |
| 307 | 307 | switch (vendor) { |
| 308 | | .musl => libc_targets = musl_targets, |
| 309 | | .glibc => libc_targets = glibc_targets, |
| 308 | .musl => libc_targets = &musl_targets, |
| 309 | .glibc => libc_targets = &glibc_targets, |
| 310 | 310 | } |
| 311 | 311 | |
| 312 | 312 | var path_table = PathTable.init(allocator); |
| ... | ... | @@ -340,15 +340,17 @@ pub fn main() !void { |
| 340 | 340 | try dir_stack.append(target_include_dir); |
| 341 | 341 | |
| 342 | 342 | while (dir_stack.popOrNull()) |full_dir_name| { |
| 343 | | var dir = std.fs.Dir.cwd().openDirList(full_dir_name) catch |err| switch (err) { |
| 343 | var dir = std.fs.cwd().openDirList(full_dir_name) catch |err| switch (err) { |
| 344 | 344 | error.FileNotFound => continue :search, |
| 345 | 345 | error.AccessDenied => continue :search, |
| 346 | 346 | else => return err, |
| 347 | 347 | }; |
| 348 | 348 | defer dir.close(); |
| 349 | 349 | |
| 350 | | while (try dir.next()) |entry| { |
| 351 | | const full_path = try std.fs.path.join(allocator, [_][]const u8{ full_dir_name, entry.name }); |
| 350 | var dir_it = dir.iterate(); |
| 351 | |
| 352 | while (try dir_it.next()) |entry| { |
| 353 | const full_path = try std.fs.path.join(allocator, &[_][]const u8{ full_dir_name, entry.name }); |
| 352 | 354 | switch (entry.kind) { |
| 353 | 355 | .Directory => try dir_stack.append(full_path), |
| 354 | 356 | .File => { |
| ... | ... | @@ -396,8 +398,8 @@ pub fn main() !void { |
| 396 | 398 | std.debug.warn("warning: libc target not found: {}\n", .{libc_target.name}); |
| 397 | 399 | } |
| 398 | 400 | } |
| 399 | | std.debug.warn("summary: {Bi:2} could be reduced to {Bi:2}\n", .{total_bytes, total_bytes - max_bytes_saved}); |
| 400 | | try std.fs.makePath(allocator, out_dir); |
| 401 | std.debug.warn("summary: {Bi:2} could be reduced to {Bi:2}\n", .{ total_bytes, total_bytes - max_bytes_saved }); |
| 402 | try std.fs.cwd().makePath(out_dir); |
| 401 | 403 | |
| 402 | 404 | var missed_opportunity_bytes: usize = 0; |
| 403 | 405 | // iterate path_table. for each path, put all the hashes into a list. sort by hit_count. |
| ... | ... | @@ -417,15 +419,15 @@ pub fn main() !void { |
| 417 | 419 | var best_contents = contents_list.popOrNull().?; |
| 418 | 420 | if (best_contents.hit_count > 1) { |
| 419 | 421 | // worth it to make it generic |
| 420 | | const full_path = try std.fs.path.join(allocator, [_][]const u8{ out_dir, generic_name, path_kv.key }); |
| 421 | | try std.fs.makePath(allocator, std.fs.path.dirname(full_path).?); |
| 422 | const full_path = try std.fs.path.join(allocator, &[_][]const u8{ out_dir, generic_name, path_kv.key }); |
| 423 | try std.fs.cwd().makePath(std.fs.path.dirname(full_path).?); |
| 422 | 424 | try std.io.writeFile(full_path, best_contents.bytes); |
| 423 | 425 | best_contents.is_generic = true; |
| 424 | 426 | while (contents_list.popOrNull()) |contender| { |
| 425 | 427 | if (contender.hit_count > 1) { |
| 426 | 428 | const this_missed_bytes = contender.hit_count * contender.bytes.len; |
| 427 | 429 | missed_opportunity_bytes += this_missed_bytes; |
| 428 | | std.debug.warn("Missed opportunity ({Bi:2}): {}\n", .{this_missed_bytes, path_kv.key}); |
| 430 | std.debug.warn("Missed opportunity ({Bi:2}): {}\n", .{ this_missed_bytes, path_kv.key }); |
| 429 | 431 | } else break; |
| 430 | 432 | } |
| 431 | 433 | } |
| ... | ... | @@ -444,8 +446,8 @@ pub fn main() !void { |
| 444 | 446 | @tagName(dest_target.os), |
| 445 | 447 | @tagName(dest_target.abi), |
| 446 | 448 | }); |
| 447 | | const full_path = try std.fs.path.join(allocator, [_][]const u8{ out_dir, out_subpath, path_kv.key }); |
| 448 | | try std.fs.makePath(allocator, std.fs.path.dirname(full_path).?); |
| 449 | const full_path = try std.fs.path.join(allocator, &[_][]const u8{ out_dir, out_subpath, path_kv.key }); |
| 450 | try std.fs.cwd().makePath(std.fs.path.dirname(full_path).?); |
| 449 | 451 | try std.io.writeFile(full_path, contents.bytes); |
| 450 | 452 | } |
| 451 | 453 | } |