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(...@@ -589,14 +589,11 @@ fn addCmakeCfgOptionsToExe(
589 if (use_zig_libcxx) {589 if (use_zig_libcxx) {
590 exe.linkLibCpp();590 exe.linkLibCpp();
591 } else {591 } 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
598 // System -lc++ must be used because in this code path we are attempting to link592 // System -lc++ must be used because in this code path we are attempting to link
599 // against system-provided LLVM, Clang, LLD.593 // 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..];
600 switch (exe.target.getOsTag()) {597 switch (exe.target.getOsTag()) {
601 .linux => {598 .linux => {
602 // First we try to link against gcc libstdc++. If that doesn't work, we fall599 // First we try to link against gcc libstdc++. If that doesn't work, we fall
...@@ -613,20 +610,24 @@ fn addCmakeCfgOptionsToExe(...@@ -613,20 +610,24 @@ fn addCmakeCfgOptionsToExe(
613 exe.linkSystemLibrary("c++");610 exe.linkSystemLibrary("c++");
614 },611 },
615 .freebsd => {612 .freebsd => {
616 try addCxxKnownPath(b, cfg, exe, b.fmt("libc++.{s}", .{lib_suffix}), null, need_cpp_includes);613 if (static) {
617 try addCxxKnownPath(b, cfg, exe, b.fmt("libgcc_eh.{s}", .{lib_suffix}), null, need_cpp_includes);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 }
618 },619 },
619 .openbsd => {620 .openbsd => {
620 try addCxxKnownPath(b, cfg, exe, b.fmt("libc++.{s}", .{lib_suffix}), null, need_cpp_includes);621 try addCxxKnownPath(b, cfg, exe, b.fmt("libc++.{s}", .{lib_suffix}), null, need_cpp_includes);
621 try addCxxKnownPath(b, cfg, exe, b.fmt("libc++abi.{s}", .{lib_suffix}), null, need_cpp_includes);622 try addCxxKnownPath(b, cfg, exe, b.fmt("libc++abi.{s}", .{lib_suffix}), null, need_cpp_includes);
622 },623 },
623 .netbsd => {624 .netbsd, .dragonfly => {
624 try addCxxKnownPath(b, cfg, exe, b.fmt("libstdc++.{s}", .{lib_suffix}), null, need_cpp_includes);625 if (static) {
625 try addCxxKnownPath(b, cfg, exe, b.fmt("libgcc_eh.{s}", .{lib_suffix}), null, need_cpp_includes);626 try addCxxKnownPath(b, cfg, exe, b.fmt("libstdc++.{s}", .{lib_suffix}), null, need_cpp_includes);
626 },627 try addCxxKnownPath(b, cfg, exe, b.fmt("libgcc_eh.{s}", .{lib_suffix}), null, need_cpp_includes);
627 .dragonfly => {628 } else {
628 try addCxxKnownPath(b, cfg, exe, b.fmt("libstdc++.{s}", .{lib_suffix}), null, need_cpp_includes);629 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);630 }
630 },631 },
631 else => {},632 else => {},
632 }633 }