authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-05-04 19:15:31-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-05-04 19:15:31-07:00
logba127058d1fcf3ca042794244eee052915998b1a
tree6656d5e03d77e22aef099379174cd9e798a71e2f
parent080e870a717124204cbfa58a1f29061a701b0362

CLI: detect MinGW-flavored static libraries

Ideally on Windows, static libraries look like "foo.lib". However, CMake and other build systems will unfortunately produce static libraries that instead look like "libfoo.a". This patch makes Zig's CLI resolve "-lfoo" arguments into static libraries that match this other pattern. This patch fixes an issue with zig-bootstrap where it won't find the LLVM, Clang, and LLD libraries.

1 files changed, 19 insertions(+), 0 deletions(-)

src/main.zig+19
......@@ -2118,6 +2118,25 @@ fn buildOutputType(
21182118 continue :syslib;
21192119 }
21202120
2121 // Unfortunately, in the case of MinGW we also need to look for `libfoo.a`.
2122 if (target_info.target.isMinGW()) {
2123 for (lib_dirs.items) |lib_dir_path| {
2124 test_path.clearRetainingCapacity();
2125 try test_path.writer().print("{s}" ++ sep ++ "lib{s}.a", .{
2126 lib_dir_path, lib_name,
2127 });
2128 fs.cwd().access(test_path.items, .{}) catch |err| switch (err) {
2129 error.FileNotFound => continue,
2130 else => |e| fatal("unable to search for static library '{s}': {s}", .{
2131 test_path.items, @errorName(e),
2132 }),
2133 };
2134 try link_objects.append(.{ .path = try arena.dupe(u8, test_path.items) });
2135 system_libs.orderedRemoveAt(i);
2136 continue :syslib;
2137 }
2138 }
2139
21212140 std.log.scoped(.cli).debug("depending on system for -l{s}", .{lib_name});
21222141
21232142 i += 1;