authorgravatar for michael.dusan@gmail.comMichael Dusan <michael.dusan@gmail.com> 2023-01-06 00:57:08-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-01-09 15:16:38-07:00
logda96e7efccba51ad3749636d32f82b4193a590b8
tree364aff5efc0e4c51603eb7f0ca254e61de5f40d2
parent6bb82dad43aba6530a8ec89ec2d810d000097b76

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 files changed, 16 insertions(+), 15 deletions(-)

build.zig+16-15
......@@ -589,14 +589,11 @@ fn addCmakeCfgOptionsToExe(
589589 if (use_zig_libcxx) {
590590 exe.linkLibCpp();
591591 } else {
592 const need_cpp_includes = true;
593 const lib_suffix = switch (cfg.llvm_linkage) {
594 .static => exe.target.staticLibSuffix()[1..],
595 .dynamic => exe.target.dynamicLibSuffix()[1..],
596 };
597
598592 // System -lc++ must be used because in this code path we are attempting to link
599593 // against system-provided LLVM, Clang, LLD.
594 const need_cpp_includes = true;
595 const static = cfg.llvm_linkage == .static;
596 const lib_suffix = if (static) exe.target.staticLibSuffix()[1..] else exe.target.dynamicLibSuffix()[1..];
600597 switch (exe.target.getOsTag()) {
601598 .linux => {
602599 // First we try to link against gcc libstdc++. If that doesn't work, we fall
......@@ -613,20 +610,24 @@ fn addCmakeCfgOptionsToExe(
613610 exe.linkSystemLibrary("c++");
614611 },
615612 .freebsd => {
616 try addCxxKnownPath(b, cfg, exe, b.fmt("libc++.{s}", .{lib_suffix}), null, need_cpp_includes);
617 try addCxxKnownPath(b, cfg, exe, b.fmt("libgcc_eh.{s}", .{lib_suffix}), null, need_cpp_includes);
613 if (static) {
614 try addCxxKnownPath(b, cfg, exe, b.fmt("libc++.{s}", .{lib_suffix}), null, need_cpp_includes);
615 try addCxxKnownPath(b, cfg, exe, b.fmt("libgcc_eh.{s}", .{lib_suffix}), null, need_cpp_includes);
616 } else {
617 try addCxxKnownPath(b, cfg, exe, b.fmt("libc++.{s}", .{lib_suffix}), null, need_cpp_includes);
618 }
618619 },
619620 .openbsd => {
620621 try addCxxKnownPath(b, cfg, exe, b.fmt("libc++.{s}", .{lib_suffix}), null, need_cpp_includes);
621622 try addCxxKnownPath(b, cfg, exe, b.fmt("libc++abi.{s}", .{lib_suffix}), null, need_cpp_includes);
622623 },
623 .netbsd => {
624 try addCxxKnownPath(b, cfg, exe, b.fmt("libstdc++.{s}", .{lib_suffix}), null, need_cpp_includes);
625 try addCxxKnownPath(b, cfg, exe, b.fmt("libgcc_eh.{s}", .{lib_suffix}), null, need_cpp_includes);
626 },
627 .dragonfly => {
628 try addCxxKnownPath(b, cfg, exe, b.fmt("libstdc++.{s}", .{lib_suffix}), null, need_cpp_includes);
629 try addCxxKnownPath(b, cfg, exe, b.fmt("libgcc_eh.{s}", .{lib_suffix}), null, need_cpp_includes);
624 .netbsd, .dragonfly => {
625 if (static) {
626 try addCxxKnownPath(b, cfg, exe, b.fmt("libstdc++.{s}", .{lib_suffix}), null, need_cpp_includes);
627 try addCxxKnownPath(b, cfg, exe, b.fmt("libgcc_eh.{s}", .{lib_suffix}), null, need_cpp_includes);
628 } else {
629 try addCxxKnownPath(b, cfg, exe, b.fmt("libstdc++.{s}", .{lib_suffix}), null, need_cpp_includes);
630 }
630631 },
631632 else => {},
632633 }