diff options
| author | kcbanner <kcbanner@gmail.com> | 2023-09-21 02:26:05 -0400 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2023-09-27 04:07:12 -0700 |
| commit | 70563aeac3e9efee7e8fb24744bc97197fc0ca9b (patch) | |
| tree | fc58b7cf3ee8340c46c13a4569caeb3651741d8e /src/main.zig | |
| parent | de4d1ea250f37c03cf2eec6c6bdf7436c8816893 (diff) | |
| download | zig-70563aeac3e9efee7e8fb24744bc97197fc0ca9b.tar.gz zig-70563aeac3e9efee7e8fb24744bc97197fc0ca9b.zip | |
windows: fix not finding system libs when compiling for *-windows-msvc
When compiling for *-windows-msvc, find the native libc_installation and
add the lib dirs to lib_dirs, so that system libs can be found.
Previously, `version` and `ole32` were detected via the mingw.libExists logic,
even on .msvc, which was a false positive. This detection logic for mingw doesn't
find uuid.lib, which was the failure that triggered this bugfix.
Only build the issue_5825 test if the native target is x86_64-windows-msvc,
since it requires the .msvc abi.
Diffstat (limited to 'src/main.zig')
| -rw-r--r-- | src/main.zig | 33 |
1 files changed, 23 insertions, 10 deletions
diff --git a/src/main.zig b/src/main.zig index 4193ab0b07..8970719509 100644 --- a/src/main.zig +++ b/src/main.zig @@ -2688,6 +2688,13 @@ fn buildOutputType( lib: Compilation.SystemLib, }) = .{}; + var libc_installation: ?LibCInstallation = null; + if (libc_paths_file) |paths_file| { + libc_installation = LibCInstallation.parse(arena, paths_file, cross_target) catch |err| { + fatal("unable to parse libc paths file at path {s}: {s}", .{ paths_file, @errorName(err) }); + }; + } + for (system_libs.keys(), system_libs.values()) |lib_name, info| { if (target_util.is_libc_lib_name(target_info.target, lib_name)) { link_libc = true; @@ -2709,7 +2716,7 @@ fn buildOutputType( }, } - if (target_info.target.os.tag == .windows) { + if (target_info.target.isMinGW()) { const exists = mingw.libExists(arena, target_info.target, zig_lib_directory, lib_name) catch |err| { fatal("failed to check zig installation for DLL import libs: {s}", .{ @errorName(err), @@ -2768,6 +2775,21 @@ fn buildOutputType( try rpath_list.appendSlice(paths.rpaths.items); } + if (builtin.target.os.tag == .windows and + target_info.target.abi == .msvc and + external_system_libs.len != 0) + { + if (libc_installation == null) { + libc_installation = try LibCInstallation.findNative(.{ + .allocator = arena, + .verbose = true, + .target = cross_target.toTarget(), + }); + + try lib_dirs.appendSlice(&.{ libc_installation.?.msvc_lib_dir.?, libc_installation.?.kernel32_lib_dir.? }); + } + } + // If any libs in this list are statically provided, we omit them from the // resolved list and populate the link_objects array instead. { @@ -3240,15 +3262,6 @@ fn buildOutputType( try thread_pool.init(.{ .allocator = gpa }); defer thread_pool.deinit(); - var libc_installation: ?LibCInstallation = null; - defer if (libc_installation) |*l| l.deinit(gpa); - - if (libc_paths_file) |paths_file| { - libc_installation = LibCInstallation.parse(gpa, paths_file, cross_target) catch |err| { - fatal("unable to parse libc paths file at path {s}: {s}", .{ paths_file, @errorName(err) }); - }; - } - var global_cache_directory: Compilation.Directory = l: { if (override_global_cache_dir) |p| { break :l .{ |
