authorgravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2025-02-24 11:58:18+01:00
committergravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2025-02-24 11:58:18+01:00
log2404e7f5d64c526f13c7e187a2fdf884f6d08506
tree29b05bc9495ee98368b2d34f70b317186435ef39
parent68bd82d0cc9b0cd07cde509c1c89a438b6d297c9
signaturebadge-check Signed by SSH key SHA256:7B/LJ7bpR1eX8aCXSr4mtd5M45VMPKcx9zY8e95b5QM

update_mingw: Add update logic for winpthreads files.

Also rename a few constants for clarity.

1 files changed, 55 insertions(+), 9 deletions(-)

tools/update_mingw.zig+55-9
...@@ -42,11 +42,12 @@ pub fn main() !void {...@@ -42,11 +42,12 @@ pub fn main() !void {
4242
43 src_crt_dir.copyFile(entry.path, dest_crt_dir, entry.path, .{}) catch |err| switch (err) {43 src_crt_dir.copyFile(entry.path, dest_crt_dir, entry.path, .{}) catch |err| switch (err) {
44 error.FileNotFound => {44 error.FileNotFound => {
45 const whitelisted = for (whitelist) |item| {45 const keep = for (kept_crt_files) |item| {
46 if (std.mem.eql(u8, entry.path, item)) break true;46 if (std.mem.eql(u8, entry.path, item)) break true;
47 if (std.mem.startsWith(u8, entry.path, "winpthreads/")) break true;
47 } else false;48 } else false;
4849
49 if (!whitelisted) {50 if (!keep) {
50 std.log.warn("deleting {s}", .{entry.path});51 std.log.warn("deleting {s}", .{entry.path});
51 try dest_crt_dir.deleteFile(entry.path);52 try dest_crt_dir.deleteFile(entry.path);
52 }53 }
...@@ -61,6 +62,51 @@ pub fn main() !void {...@@ -61,6 +62,51 @@ pub fn main() !void {
61 if (fail) std.process.exit(1);62 if (fail) std.process.exit(1);
62 }63 }
6364
65 {
66 const dest_mingw_winpthreads_path = try std.fs.path.join(arena, &.{
67 zig_src_lib_path, "libc", "mingw", "winpthreads",
68 });
69 const src_mingw_libraries_winpthreads_src_path = try std.fs.path.join(arena, &.{
70 mingw_src_path, "mingw-w64-libraries", "winpthreads", "src",
71 });
72
73 var dest_winpthreads_dir = std.fs.cwd().openDir(dest_mingw_winpthreads_path, .{ .iterate = true }) catch |err| {
74 std.log.err("unable to open directory '{s}': {s}", .{ dest_mingw_winpthreads_path, @errorName(err) });
75 std.process.exit(1);
76 };
77 defer dest_winpthreads_dir.close();
78
79 var src_winpthreads_dir = std.fs.cwd().openDir(src_mingw_libraries_winpthreads_src_path, .{ .iterate = true }) catch |err| {
80 std.log.err("unable to open directory '{s}': {s}", .{ src_mingw_libraries_winpthreads_src_path, @errorName(err) });
81 std.process.exit(1);
82 };
83 defer src_winpthreads_dir.close();
84
85 {
86 var walker = try dest_winpthreads_dir.walk(arena);
87 defer walker.deinit();
88
89 var fail = false;
90
91 while (try walker.next()) |entry| {
92 if (entry.kind != .file) continue;
93
94 src_winpthreads_dir.copyFile(entry.path, dest_winpthreads_dir, entry.path, .{}) catch |err| switch (err) {
95 error.FileNotFound => {
96 std.log.warn("deleting {s}", .{entry.path});
97 try dest_winpthreads_dir.deleteFile(entry.path);
98 },
99 else => {
100 std.log.err("unable to copy {s}: {s}", .{ entry.path, @errorName(err) });
101 fail = true;
102 },
103 };
104 }
105
106 if (fail) std.process.exit(1);
107 }
108 }
109
64 {110 {
65 // Also add all new def and def.in files.111 // Also add all new def and def.in files.
66 var walker = try src_crt_dir.walk(arena);112 var walker = try src_crt_dir.walk(arena);
...@@ -71,19 +117,19 @@ pub fn main() !void {...@@ -71,19 +117,19 @@ pub fn main() !void {
71 while (try walker.next()) |entry| {117 while (try walker.next()) |entry| {
72 if (entry.kind != .file) continue;118 if (entry.kind != .file) continue;
73119
74 const ok_ext = for (ok_exts) |ext| {120 const ok_ext = for (def_exts) |ext| {
75 if (std.mem.endsWith(u8, entry.path, ext)) break true;121 if (std.mem.endsWith(u8, entry.path, ext)) break true;
76 } else false;122 } else false;
77123
78 if (!ok_ext) continue;124 if (!ok_ext) continue;
79125
80 const ok_prefix = for (ok_prefixes) |p| {126 const ok_prefix = for (def_dirs) |p| {
81 if (std.mem.startsWith(u8, entry.path, p)) break true;127 if (std.mem.startsWith(u8, entry.path, p)) break true;
82 } else false;128 } else false;
83129
84 if (!ok_prefix) continue;130 if (!ok_prefix) continue;
85131
86 const blacklisted = for (blacklist) |item| {132 const blacklisted = for (blacklisted_defs) |item| {
87 if (std.mem.eql(u8, entry.basename, item)) break true;133 if (std.mem.eql(u8, entry.basename, item)) break true;
88 } else false;134 } else false;
89135
...@@ -106,17 +152,17 @@ pub fn main() !void {...@@ -106,17 +152,17 @@ pub fn main() !void {
106 return std.process.cleanExit();152 return std.process.cleanExit();
107}153}
108154
109const whitelist = [_][]const u8{155const kept_crt_files = [_][]const u8{
110 "COPYING",156 "COPYING",
111 "include" ++ std.fs.path.sep_str ++ "config.h",157 "include" ++ std.fs.path.sep_str ++ "config.h",
112};158};
113159
114const ok_exts = [_][]const u8{160const def_exts = [_][]const u8{
115 ".def",161 ".def",
116 ".def.in",162 ".def.in",
117};163};
118164
119const ok_prefixes = [_][]const u8{165const def_dirs = [_][]const u8{
120 "lib32" ++ std.fs.path.sep_str,166 "lib32" ++ std.fs.path.sep_str,
121 "lib64" ++ std.fs.path.sep_str,167 "lib64" ++ std.fs.path.sep_str,
122 "libarm32" ++ std.fs.path.sep_str,168 "libarm32" ++ std.fs.path.sep_str,
...@@ -125,7 +171,7 @@ const ok_prefixes = [_][]const u8{...@@ -125,7 +171,7 @@ const ok_prefixes = [_][]const u8{
125 "def-include" ++ std.fs.path.sep_str,171 "def-include" ++ std.fs.path.sep_str,
126};172};
127173
128const blacklist = [_][]const u8{174const blacklisted_defs = [_][]const u8{
129 "crtdll.def.in",175 "crtdll.def.in",
130176
131 "msvcp60.def",177 "msvcp60.def",