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-06 18:04:52-05:00
log0507ced8cd1bc40a8118adf7a7b00eb0cbd203dc
treeaf305439f85dd746673572af7db9f9a7e54f375e
parent24b4e643f486ce803f758a6eab0c587c44b9cfa4

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
......@@ -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 }