zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

commit 0507ced8cd1bc40a8118adf7a7b00eb0cbd203dc (tree)
parent 24b4e643f486ce803f758a6eab0c587c44b9cfa4
Author: Michael Dusan <michael.dusan@gmail.com>
Date:   Fri,  6 Jan 2023 00:57:08 -0500

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.

Diffstat:
Mbuild.zig | 31++++++++++++++++---------------
1 file changed, 16 insertions(+), 15 deletions(-)

diff --git a/build.zig b/build.zig @@ -556,14 +556,11 @@ fn addCmakeCfgOptionsToExe( if (use_zig_libcxx) { exe.linkLibCpp(); } else { - const need_cpp_includes = true; - const lib_suffix = switch (cfg.llvm_linkage) { - .static => exe.target.staticLibSuffix()[1..], - .dynamic => exe.target.dynamicLibSuffix()[1..], - }; - // System -lc++ must be used because in this code path we are attempting to link // against system-provided LLVM, Clang, LLD. + const need_cpp_includes = true; + const static = cfg.llvm_linkage == .static; + const lib_suffix = if (static) exe.target.staticLibSuffix()[1..] else exe.target.dynamicLibSuffix()[1..]; switch (exe.target.getOsTag()) { .linux => { // First we try to link against gcc libstdc++. If that doesn't work, we fall @@ -580,20 +577,24 @@ fn addCmakeCfgOptionsToExe( exe.linkSystemLibrary("c++"); }, .freebsd => { - try addCxxKnownPath(b, cfg, exe, b.fmt("libc++.{s}", .{lib_suffix}), null, need_cpp_includes); - try addCxxKnownPath(b, cfg, exe, b.fmt("libgcc_eh.{s}", .{lib_suffix}), null, need_cpp_includes); + if (static) { + try addCxxKnownPath(b, cfg, exe, b.fmt("libc++.{s}", .{lib_suffix}), null, need_cpp_includes); + try addCxxKnownPath(b, cfg, exe, b.fmt("libgcc_eh.{s}", .{lib_suffix}), null, need_cpp_includes); + } else { + try addCxxKnownPath(b, cfg, exe, b.fmt("libc++.{s}", .{lib_suffix}), null, need_cpp_includes); + } }, .openbsd => { try addCxxKnownPath(b, cfg, exe, b.fmt("libc++.{s}", .{lib_suffix}), null, need_cpp_includes); try addCxxKnownPath(b, cfg, exe, b.fmt("libc++abi.{s}", .{lib_suffix}), null, need_cpp_includes); }, - .netbsd => { - try addCxxKnownPath(b, cfg, exe, b.fmt("libstdc++.{s}", .{lib_suffix}), null, need_cpp_includes); - try addCxxKnownPath(b, cfg, exe, b.fmt("libgcc_eh.{s}", .{lib_suffix}), null, need_cpp_includes); - }, - .dragonfly => { - try addCxxKnownPath(b, cfg, exe, b.fmt("libstdc++.{s}", .{lib_suffix}), null, need_cpp_includes); - try addCxxKnownPath(b, cfg, exe, b.fmt("libgcc_eh.{s}", .{lib_suffix}), null, need_cpp_includes); + .netbsd, .dragonfly => { + if (static) { + try addCxxKnownPath(b, cfg, exe, b.fmt("libstdc++.{s}", .{lib_suffix}), null, need_cpp_includes); + try addCxxKnownPath(b, cfg, exe, b.fmt("libgcc_eh.{s}", .{lib_suffix}), null, need_cpp_includes); + } else { + try addCxxKnownPath(b, cfg, exe, b.fmt("libstdc++.{s}", .{lib_suffix}), null, need_cpp_includes); + } }, else => {}, }