| ... | ... | @@ -42,11 +42,12 @@ pub fn main() !void { |
| 42 | 42 | |
| 43 | 43 | src_crt_dir.copyFile(entry.path, dest_crt_dir, entry.path, .{}) catch |err| switch (err) { |
| 44 | 44 | error.FileNotFound => { |
| 45 | | const whitelisted = for (whitelist) |item| { |
| 45 | const keep = for (kept_crt_files) |item| { |
| 46 | 46 | if (std.mem.eql(u8, entry.path, item)) break true; |
| 47 | if (std.mem.startsWith(u8, entry.path, "winpthreads/")) break true; |
| 47 | 48 | } else false; |
| 48 | 49 | |
| 49 | | if (!whitelisted) { |
| 50 | if (!keep) { |
| 50 | 51 | std.log.warn("deleting {s}", .{entry.path}); |
| 51 | 52 | try dest_crt_dir.deleteFile(entry.path); |
| 52 | 53 | } |
| ... | ... | @@ -61,6 +62,51 @@ pub fn main() !void { |
| 61 | 62 | if (fail) std.process.exit(1); |
| 62 | 63 | } |
| 63 | 64 | |
| 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 | 111 | // Also add all new def and def.in files. |
| 66 | 112 | var walker = try src_crt_dir.walk(arena); |
| ... | ... | @@ -71,19 +117,19 @@ pub fn main() !void { |
| 71 | 117 | while (try walker.next()) |entry| { |
| 72 | 118 | if (entry.kind != .file) continue; |
| 73 | 119 | |
| 74 | | const ok_ext = for (ok_exts) |ext| { |
| 120 | const ok_ext = for (def_exts) |ext| { |
| 75 | 121 | if (std.mem.endsWith(u8, entry.path, ext)) break true; |
| 76 | 122 | } else false; |
| 77 | 123 | |
| 78 | 124 | if (!ok_ext) continue; |
| 79 | 125 | |
| 80 | | const ok_prefix = for (ok_prefixes) |p| { |
| 126 | const ok_prefix = for (def_dirs) |p| { |
| 81 | 127 | if (std.mem.startsWith(u8, entry.path, p)) break true; |
| 82 | 128 | } else false; |
| 83 | 129 | |
| 84 | 130 | if (!ok_prefix) continue; |
| 85 | 131 | |
| 86 | | const blacklisted = for (blacklist) |item| { |
| 132 | const blacklisted = for (blacklisted_defs) |item| { |
| 87 | 133 | if (std.mem.eql(u8, entry.basename, item)) break true; |
| 88 | 134 | } else false; |
| 89 | 135 | |
| ... | ... | @@ -106,17 +152,17 @@ pub fn main() !void { |
| 106 | 152 | return std.process.cleanExit(); |
| 107 | 153 | } |
| 108 | 154 | |
| 109 | | const whitelist = [_][]const u8{ |
| 155 | const kept_crt_files = [_][]const u8{ |
| 110 | 156 | "COPYING", |
| 111 | 157 | "include" ++ std.fs.path.sep_str ++ "config.h", |
| 112 | 158 | }; |
| 113 | 159 | |
| 114 | | const ok_exts = [_][]const u8{ |
| 160 | const def_exts = [_][]const u8{ |
| 115 | 161 | ".def", |
| 116 | 162 | ".def.in", |
| 117 | 163 | }; |
| 118 | 164 | |
| 119 | | const ok_prefixes = [_][]const u8{ |
| 165 | const def_dirs = [_][]const u8{ |
| 120 | 166 | "lib32" ++ std.fs.path.sep_str, |
| 121 | 167 | "lib64" ++ std.fs.path.sep_str, |
| 122 | 168 | "libarm32" ++ std.fs.path.sep_str, |
| ... | ... | @@ -125,7 +171,7 @@ const ok_prefixes = [_][]const u8{ |
| 125 | 171 | "def-include" ++ std.fs.path.sep_str, |
| 126 | 172 | }; |
| 127 | 173 | |
| 128 | | const blacklist = [_][]const u8{ |
| 174 | const blacklisted_defs = [_][]const u8{ |
| 129 | 175 | "crtdll.def.in", |
| 130 | 176 | |
| 131 | 177 | "msvcp60.def", |