Skip to content

Commit af3a970

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 43b4368 commit af3a970

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

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

0 commit comments

Comments
 (0)