Skip to content

Commit 2404e7f

Browse files
committed
update_mingw: Add update logic for winpthreads files.
Also rename a few constants for clarity.
1 parent 68bd82d commit 2404e7f

File tree

1 file changed

+55
-9
lines changed

1 file changed

+55
-9
lines changed

tools/update_mingw.zig

Lines changed: 55 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,12 @@ pub fn main() !void {
4242

4343
src_crt_dir.copyFile(entry.path, dest_crt_dir, entry.path, .{}) catch |err| switch (err) {
4444
error.FileNotFound => {
45-
const whitelisted = for (whitelist) |item| {
45+
const keep = for (kept_crt_files) |item| {
4646
if (std.mem.eql(u8, entry.path, item)) break true;
47+
if (std.mem.startsWith(u8, entry.path, "winpthreads/")) break true;
4748
} else false;
4849

49-
if (!whitelisted) {
50+
if (!keep) {
5051
std.log.warn("deleting {s}", .{entry.path});
5152
try dest_crt_dir.deleteFile(entry.path);
5253
}
@@ -61,6 +62,51 @@ pub fn main() !void {
6162
if (fail) std.process.exit(1);
6263
}
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+
64110
{
65111
// Also add all new def and def.in files.
66112
var walker = try src_crt_dir.walk(arena);
@@ -71,19 +117,19 @@ pub fn main() !void {
71117
while (try walker.next()) |entry| {
72118
if (entry.kind != .file) continue;
73119

74-
const ok_ext = for (ok_exts) |ext| {
120+
const ok_ext = for (def_exts) |ext| {
75121
if (std.mem.endsWith(u8, entry.path, ext)) break true;
76122
} else false;
77123

78124
if (!ok_ext) continue;
79125

80-
const ok_prefix = for (ok_prefixes) |p| {
126+
const ok_prefix = for (def_dirs) |p| {
81127
if (std.mem.startsWith(u8, entry.path, p)) break true;
82128
} else false;
83129

84130
if (!ok_prefix) continue;
85131

86-
const blacklisted = for (blacklist) |item| {
132+
const blacklisted = for (blacklisted_defs) |item| {
87133
if (std.mem.eql(u8, entry.basename, item)) break true;
88134
} else false;
89135

@@ -106,17 +152,17 @@ pub fn main() !void {
106152
return std.process.cleanExit();
107153
}
108154

109-
const whitelist = [_][]const u8{
155+
const kept_crt_files = [_][]const u8{
110156
"COPYING",
111157
"include" ++ std.fs.path.sep_str ++ "config.h",
112158
};
113159

114-
const ok_exts = [_][]const u8{
160+
const def_exts = [_][]const u8{
115161
".def",
116162
".def.in",
117163
};
118164

119-
const ok_prefixes = [_][]const u8{
165+
const def_dirs = [_][]const u8{
120166
"lib32" ++ std.fs.path.sep_str,
121167
"lib64" ++ std.fs.path.sep_str,
122168
"libarm32" ++ std.fs.path.sep_str,
@@ -125,7 +171,7 @@ const ok_prefixes = [_][]const u8{
125171
"def-include" ++ std.fs.path.sep_str,
126172
};
127173

128-
const blacklist = [_][]const u8{
174+
const blacklisted_defs = [_][]const u8{
129175
"crtdll.def.in",
130176

131177
"msvcp60.def",

0 commit comments

Comments
 (0)