Skip to content

Commit 0507ced

Browse files
mikdusanandrewrk
authored andcommitted
stage3 bsd: support dynamic libstdc++/libc++
Currently llvm-linkage mode (static vs dynamic) decides linkage mode for system libstdc++/libc++ . A previous commit only tested static mode for *BSD and netbsd was reported to not work in dynamic mode. We now special-case freebsd, openbsd, netbsd and dragonfly for dynamic linking too.
1 parent 24b4e64 commit 0507ced

File tree

1 file changed

+16
-15
lines changed

1 file changed

+16
-15
lines changed

build.zig

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -556,14 +556,11 @@ fn addCmakeCfgOptionsToExe(
556556
if (use_zig_libcxx) {
557557
exe.linkLibCpp();
558558
} else {
559-
const need_cpp_includes = true;
560-
const lib_suffix = switch (cfg.llvm_linkage) {
561-
.static => exe.target.staticLibSuffix()[1..],
562-
.dynamic => exe.target.dynamicLibSuffix()[1..],
563-
};
564-
565559
// System -lc++ must be used because in this code path we are attempting to link
566560
// against system-provided LLVM, Clang, LLD.
561+
const need_cpp_includes = true;
562+
const static = cfg.llvm_linkage == .static;
563+
const lib_suffix = if (static) exe.target.staticLibSuffix()[1..] else exe.target.dynamicLibSuffix()[1..];
567564
switch (exe.target.getOsTag()) {
568565
.linux => {
569566
// First we try to link against gcc libstdc++. If that doesn't work, we fall
@@ -580,20 +577,24 @@ fn addCmakeCfgOptionsToExe(
580577
exe.linkSystemLibrary("c++");
581578
},
582579
.freebsd => {
583-
try addCxxKnownPath(b, cfg, exe, b.fmt("libc++.{s}", .{lib_suffix}), null, need_cpp_includes);
584-
try addCxxKnownPath(b, cfg, exe, b.fmt("libgcc_eh.{s}", .{lib_suffix}), null, need_cpp_includes);
580+
if (static) {
581+
try addCxxKnownPath(b, cfg, exe, b.fmt("libc++.{s}", .{lib_suffix}), null, need_cpp_includes);
582+
try addCxxKnownPath(b, cfg, exe, b.fmt("libgcc_eh.{s}", .{lib_suffix}), null, need_cpp_includes);
583+
} else {
584+
try addCxxKnownPath(b, cfg, exe, b.fmt("libc++.{s}", .{lib_suffix}), null, need_cpp_includes);
585+
}
585586
},
586587
.openbsd => {
587588
try addCxxKnownPath(b, cfg, exe, b.fmt("libc++.{s}", .{lib_suffix}), null, need_cpp_includes);
588589
try addCxxKnownPath(b, cfg, exe, b.fmt("libc++abi.{s}", .{lib_suffix}), null, need_cpp_includes);
589590
},
590-
.netbsd => {
591-
try addCxxKnownPath(b, cfg, exe, b.fmt("libstdc++.{s}", .{lib_suffix}), null, need_cpp_includes);
592-
try addCxxKnownPath(b, cfg, exe, b.fmt("libgcc_eh.{s}", .{lib_suffix}), null, need_cpp_includes);
593-
},
594-
.dragonfly => {
595-
try addCxxKnownPath(b, cfg, exe, b.fmt("libstdc++.{s}", .{lib_suffix}), null, need_cpp_includes);
596-
try addCxxKnownPath(b, cfg, exe, b.fmt("libgcc_eh.{s}", .{lib_suffix}), null, need_cpp_includes);
591+
.netbsd, .dragonfly => {
592+
if (static) {
593+
try addCxxKnownPath(b, cfg, exe, b.fmt("libstdc++.{s}", .{lib_suffix}), null, need_cpp_includes);
594+
try addCxxKnownPath(b, cfg, exe, b.fmt("libgcc_eh.{s}", .{lib_suffix}), null, need_cpp_includes);
595+
} else {
596+
try addCxxKnownPath(b, cfg, exe, b.fmt("libstdc++.{s}", .{lib_suffix}), null, need_cpp_includes);
597+
}
597598
},
598599
else => {},
599600
}

0 commit comments

Comments
 (0)