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(...@@ -556,14 +556,11 @@ fn addCmakeCfgOptionsToExe(
556 if (use_zig_libcxx) {556 if (use_zig_libcxx) {
557 exe.linkLibCpp();557 exe.linkLibCpp();
558 } else {558 } 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
565 // System -lc++ must be used because in this code path we are attempting to link559 // System -lc++ must be used because in this code path we are attempting to link
566 // against system-provided LLVM, Clang, LLD.560 // 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..];
567 switch (exe.target.getOsTag()) {564 switch (exe.target.getOsTag()) {
568 .linux => {565 .linux => {
569 // First we try to link against gcc libstdc++. If that doesn't work, we fall566 // First we try to link against gcc libstdc++. If that doesn't work, we fall
...@@ -580,20 +577,24 @@ fn addCmakeCfgOptionsToExe(...@@ -580,20 +577,24 @@ fn addCmakeCfgOptionsToExe(
580 exe.linkSystemLibrary("c++");577 exe.linkSystemLibrary("c++");
581 },578 },
582 .freebsd => {579 .freebsd => {
583 try addCxxKnownPath(b, cfg, exe, b.fmt("libc++.{s}", .{lib_suffix}), null, need_cpp_includes);580 if (static) {
584 try addCxxKnownPath(b, cfg, exe, b.fmt("libgcc_eh.{s}", .{lib_suffix}), null, need_cpp_includes);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 }
585 },586 },
586 .openbsd => {587 .openbsd => {
587 try addCxxKnownPath(b, cfg, exe, b.fmt("libc++.{s}", .{lib_suffix}), null, need_cpp_includes);588 try addCxxKnownPath(b, cfg, exe, b.fmt("libc++.{s}", .{lib_suffix}), null, need_cpp_includes);
588 try addCxxKnownPath(b, cfg, exe, b.fmt("libc++abi.{s}", .{lib_suffix}), null, need_cpp_includes);589 try addCxxKnownPath(b, cfg, exe, b.fmt("libc++abi.{s}", .{lib_suffix}), null, need_cpp_includes);
589 },590 },
590 .netbsd => {591 .netbsd, .dragonfly => {
591 try addCxxKnownPath(b, cfg, exe, b.fmt("libstdc++.{s}", .{lib_suffix}), null, need_cpp_includes);592 if (static) {
592 try addCxxKnownPath(b, cfg, exe, b.fmt("libgcc_eh.{s}", .{lib_suffix}), null, need_cpp_includes);593 try addCxxKnownPath(b, cfg, exe, b.fmt("libstdc++.{s}", .{lib_suffix}), null, need_cpp_includes);
593 },594 try addCxxKnownPath(b, cfg, exe, b.fmt("libgcc_eh.{s}", .{lib_suffix}), null, need_cpp_includes);
594 .dragonfly => {595 } else {
595 try addCxxKnownPath(b, cfg, exe, b.fmt("libstdc++.{s}", .{lib_suffix}), null, need_cpp_includes);596 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);597 }
597 },598 },
598 else => {},599 else => {},
599 }600 }