Skip to content

Commit adcaae3

Browse files
committed
Compile: Don't add libs as sources to static libs
When compiling static libraries, don't tell the linker to include other libraries (static OR dynamic) as sources to include in the archive. Should resolve #19341
1 parent 5e51205 commit adcaae3

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

lib/std/Build/Step/Compile.zig

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1169,11 +1169,19 @@ fn getZigArgs(compile: *Compile, fuzz: bool) ![][]const u8 {
11691169
break :prefix "-l";
11701170
};
11711171
switch (system_lib.use_pkg_config) {
1172-
.no => try zig_args.append(b.fmt("{s}{s}", .{ prefix, system_lib.name })),
1172+
.no => {
1173+
if (compile.linkage != .static) {
1174+
// Avoid putting another compiled library inside a static library.
1175+
try zig_args.append(b.fmt("{s}{s}", .{ prefix, system_lib.name }));
1176+
}
1177+
},
11731178
.yes, .force => {
11741179
if (compile.runPkgConfig(system_lib.name)) |result| {
11751180
try zig_args.appendSlice(result.cflags);
1176-
try zig_args.appendSlice(result.libs);
1181+
if (compile.linkage != .static) {
1182+
// Avoid putting another compiled library inside a static library.
1183+
try zig_args.appendSlice(result.libs);
1184+
}
11771185
try seen_system_libs.put(arena, system_lib.name, result.cflags);
11781186
} else |err| switch (err) {
11791187
error.PkgConfigInvalidOutput,
@@ -1215,10 +1223,10 @@ fn getZigArgs(compile: *Compile, fuzz: bool) ![][]const u8 {
12151223
},
12161224
.lib => l: {
12171225
const other_produces_implib = other.producesImplib();
1218-
const other_is_static = other_produces_implib or other.isStaticLibrary();
1226+
const other_is_compiled_lib = other_produces_implib or other.isStaticLibrary() or other.isDynamicLibrary();
12191227

1220-
if (compile.isStaticLibrary() and other_is_static) {
1221-
// Avoid putting a static library inside a static library.
1228+
if (compile.isStaticLibrary() and other_is_compiled_lib) {
1229+
// Avoid putting another compiled library inside a static library.
12221230
break :l;
12231231
}
12241232

0 commit comments

Comments
 (0)