Skip to content

Commit cee59f1

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 1b0bde0 commit cee59f1

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
@@ -1222,11 +1222,19 @@ fn getZigArgs(compile: *Compile, fuzz: bool) ![][]const u8 {
12221222
break :prefix "-l";
12231223
};
12241224
switch (system_lib.use_pkg_config) {
1225-
.no => try zig_args.append(b.fmt("{s}{s}", .{ prefix, system_lib.name })),
1225+
.no => {
1226+
if (compile.linkage != .static) {
1227+
// Avoid putting another compiled library inside a static library.
1228+
try zig_args.append(b.fmt("{s}{s}", .{ prefix, system_lib.name }));
1229+
}
1230+
},
12261231
.yes, .force => {
12271232
if (compile.runPkgConfig(system_lib.name)) |result| {
12281233
try zig_args.appendSlice(result.cflags);
1229-
try zig_args.appendSlice(result.libs);
1234+
if (compile.linkage != .static) {
1235+
// Avoid putting another compiled library inside a static library.
1236+
try zig_args.appendSlice(result.libs);
1237+
}
12301238
try seen_system_libs.put(arena, system_lib.name, result.cflags);
12311239
} else |err| switch (err) {
12321240
error.PkgConfigInvalidOutput,
@@ -1268,10 +1276,10 @@ fn getZigArgs(compile: *Compile, fuzz: bool) ![][]const u8 {
12681276
},
12691277
.lib => l: {
12701278
const other_produces_implib = other.producesImplib();
1271-
const other_is_static = other_produces_implib or other.isStaticLibrary();
1279+
const other_is_compiled_lib = other_produces_implib or other.isStaticLibrary() or other.isDynamicLibrary();
12721280

1273-
if (compile.isStaticLibrary() and other_is_static) {
1274-
// Avoid putting a static library inside a static library.
1281+
if (compile.isStaticLibrary() and other_is_compiled_lib) {
1282+
// Avoid putting another compiled library inside a static library.
12751283
break :l;
12761284
}
12771285

0 commit comments

Comments
 (0)