From ba127058d1fcf3ca042794244eee052915998b1a Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Wed, 4 May 2022 19:15:31 -0700 Subject: [PATCH] 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. --- src/main.zig | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/main.zig b/src/main.zig index 4d69bd51c7..9487f2e962 100644 --- a/src/main.zig +++ b/src/main.zig @@ -2118,6 +2118,25 @@ fn buildOutputType( continue :syslib; } + // Unfortunately, in the case of MinGW we also need to look for `libfoo.a`. + if (target_info.target.isMinGW()) { + for (lib_dirs.items) |lib_dir_path| { + test_path.clearRetainingCapacity(); + try test_path.writer().print("{s}" ++ sep ++ "lib{s}.a", .{ + lib_dir_path, lib_name, + }); + fs.cwd().access(test_path.items, .{}) catch |err| switch (err) { + error.FileNotFound => continue, + else => |e| fatal("unable to search for static library '{s}': {s}", .{ + test_path.items, @errorName(e), + }), + }; + try link_objects.append(.{ .path = try arena.dupe(u8, test_path.items) }); + system_libs.orderedRemoveAt(i); + continue :syslib; + } + } + std.log.scoped(.cli).debug("depending on system for -l{s}", .{lib_name}); i += 1;