@@ -24,24 +24,35 @@ const Arch = enum {
2424 }
2525};
2626
27- const Abi = enum {
28- any ,
29- gnu ,
27+ const Abi = enum { any , gnu };
28+
29+ const OsVer = enum (u32 ) {
30+ any = 0 ,
31+ catalina = 10 ,
32+ big_sur = 11 ,
33+ monterey = 12 ,
3034};
3135
3236const Target = struct {
3337 arch : Arch ,
3438 os : OsTag = .macos ,
39+ os_ver : OsVer ,
3540 abi : Abi = .gnu ,
3641
3742 fn hash (a : Target ) u32 {
38- return @enumToInt (a .arch ) +%
39- (@enumToInt (a .os ) *% @as (u32 , 4202347608 )) +%
40- (@enumToInt (a .abi ) *% @as (u32 , 4082223418 ));
43+ var hasher = std .hash .Wyhash .init (0 );
44+ std .hash .autoHash (& hasher , a .arch );
45+ std .hash .autoHash (& hasher , a .os );
46+ std .hash .autoHash (& hasher , a .os_ver );
47+ std .hash .autoHash (& hasher , a .abi );
48+ return @truncate (u32 , hasher .final ());
4149 }
4250
4351 fn eql (a : Target , b : Target ) bool {
44- return a .arch == b .arch and a .os == b .os and a .abi == b .abi ;
52+ return a .arch == b .arch and
53+ a .os == b .os and
54+ a .os_ver == b .os_ver and
55+ a .abi == b .abi ;
4556 }
4657
4758 fn name (self : Target , allocator : * Allocator ) ! []const u8 {
@@ -51,26 +62,60 @@ const Target = struct {
5162 @tagName (self .abi ),
5263 });
5364 }
65+
66+ fn fullName (self : Target , allocator : * Allocator ) ! []const u8 {
67+ if (self .os_ver == .any ) return self .name (allocator );
68+ return std .fmt .allocPrint (allocator , "{s}-{s}.{d}-{s}" , .{
69+ @tagName (self .arch ),
70+ @tagName (self .os ),
71+ @enumToInt (self .os_ver ),
72+ @tagName (self .abi ),
73+ });
74+ }
5475};
5576
5677const targets = [_ ]Target {
5778 Target {
5879 .arch = .any ,
5980 .abi = .any ,
81+ .os_ver = .any ,
6082 },
6183 Target {
6284 .arch = .aarch64 ,
85+ .os_ver = .any ,
86+ },
87+ Target {
88+ .arch = .x86_64 ,
89+ .os_ver = .any ,
6390 },
6491 Target {
6592 .arch = .x86_64 ,
93+ .os_ver = .catalina ,
94+ },
95+ Target {
96+ .arch = .x86_64 ,
97+ .os_ver = .big_sur ,
98+ },
99+ Target {
100+ .arch = .x86_64 ,
101+ .os_ver = .monterey ,
102+ },
103+ Target {
104+ .arch = .aarch64 ,
105+ .os_ver = .big_sur ,
106+ },
107+ Target {
108+ .arch = .aarch64 ,
109+ .os_ver = .monterey ,
66110 },
67111};
68112
69113const dest_target : Target = .{
70114 .arch = Arch .fromTargetCpuArch (@import ("builtin" ).cpu .arch ),
115+ .os_ver = .any ,
71116};
72117
73- const headers_source_prefix : []const u8 = "libc/include " ;
118+ const headers_source_prefix : []const u8 = "headers " ;
74119const common_name = "any-macos-any" ;
75120
76121const Contents = struct {
@@ -280,7 +325,7 @@ fn generateDedupDirs(allocator: *Allocator, args: []const []const u8) !void {
280325 var hash_to_contents = HashToContents .init (allocator );
281326
282327 var savings = FindResult {};
283- inline for (targets ) | target | {
328+ for (targets ) | target | {
284329 const res = try findDuplicates (target , allocator , headers_source_prefix , & path_table , & hash_to_contents );
285330 savings .max_bytes_saved += res .max_bytes_saved ;
286331 savings .total_bytes += res .total_bytes ;
@@ -340,15 +385,15 @@ fn generateDedupDirs(allocator: *Allocator, args: []const []const u8) !void {
340385 if (contents .is_generic ) continue ;
341386
342387 const target = hash_kv .key_ptr .* ;
343- const target_name = try target .name (allocator );
388+ const target_name = try target .fullName (allocator );
344389 const full_path = try fs .path .join (allocator , &[_ ][]const u8 { target_name , path_kv .key_ptr .* });
345390 try tmp .dir .makePath (fs .path .dirname (full_path ).? );
346391 try tmp .dir .writeFile (full_path , contents .bytes );
347392 }
348393 }
349394
350- inline for (targets ) | target | {
351- const target_name = try target .name (allocator );
395+ for (targets ) | target | {
396+ const target_name = try target .fullName (allocator );
352397 try dest_dir .deleteTree (target_name );
353398 }
354399 try dest_dir .deleteTree (common_name );
@@ -376,15 +421,15 @@ const FindResult = struct {
376421};
377422
378423fn findDuplicates (
379- comptime target : Target ,
424+ target : Target ,
380425 allocator : * Allocator ,
381426 dest_path : []const u8 ,
382427 path_table : * PathTable ,
383428 hash_to_contents : * HashToContents ,
384429) ! FindResult {
385430 var result = FindResult {};
386431
387- const target_name = try target .name (allocator );
432+ const target_name = try target .fullName (allocator );
388433 const target_include_dir = try fs .path .join (allocator , &[_ ][]const u8 { dest_path , target_name });
389434 var dir_stack = std .ArrayList ([]const u8 ).init (allocator );
390435 try dir_stack .append (target_include_dir );
0 commit comments