authorgravatar for topolarity@tapscott.meCody Tapscott <topolarity@tapscott.me> 2022-07-11 18:47:54-07:00
committergravatar for topolarity@tapscott.meCody Tapscott <topolarity@tapscott.me> 2022-07-28 22:21:24-07:00
logf1feb1369b128fb515a369b1144574b4c1b53b6e
tree3c2cd656163ef72cae6a296d1b8ec47f6d4b0857
parentb0525344a2b0b158369251c031159bef241048da

Dynamically link libc++, if integrating with system LLVM

This ensures that the zigcpp clang driver and LLVM are using the same copy of libc++. See prior commit for more details.

1 files changed, 10 insertions(+), 6 deletions(-)

build.zig+10-6
......@@ -565,13 +565,17 @@ fn addCmakeCfgOptionsToExe(
565565 exe.linkLibCpp();
566566 } else {
567567 const need_cpp_includes = true;
568 const lib_suffix = switch (cfg.llvm_linkage) {
569 .static => exe.target.staticLibSuffix()[1..],
570 .dynamic => exe.target.dynamicLibSuffix()[1..],
571 };
568572
569573 // System -lc++ must be used because in this code path we are attempting to link
570574 // against system-provided LLVM, Clang, LLD.
571575 if (exe.target.getOsTag() == .linux) {
572 // First we try to static link against gcc libstdc++. If that doesn't work,
573 // we fall back to -lc++ and cross our fingers.
574 addCxxKnownPath(b, cfg, exe, "libstdc++.a", "", need_cpp_includes) catch |err| switch (err) {
576 // First we try to link against gcc libstdc++. If that doesn't work, we fall
577 // back to -lc++ and cross our fingers.
578 addCxxKnownPath(b, cfg, exe, b.fmt("libstdc++.{s}", .{lib_suffix}), "", need_cpp_includes) catch |err| switch (err) {
575579 error.RequiredLibraryNotFound => {
576580 exe.linkSystemLibrary("c++");
577581 },
......@@ -579,11 +583,11 @@ fn addCmakeCfgOptionsToExe(
579583 };
580584 exe.linkSystemLibrary("unwind");
581585 } else if (exe.target.isFreeBSD()) {
582 try addCxxKnownPath(b, cfg, exe, "libc++.a", null, need_cpp_includes);
586 try addCxxKnownPath(b, cfg, exe, b.fmt("libc++.{s}", .{lib_suffix}), null, need_cpp_includes);
583587 exe.linkSystemLibrary("pthread");
584588 } else if (exe.target.getOsTag() == .openbsd) {
585 try addCxxKnownPath(b, cfg, exe, "libc++.a", null, need_cpp_includes);
586 try addCxxKnownPath(b, cfg, exe, "libc++abi.a", null, need_cpp_includes);
589 try addCxxKnownPath(b, cfg, exe, b.fmt("libc++.{s}", .{lib_suffix}), null, need_cpp_includes);
590 try addCxxKnownPath(b, cfg, exe, b.fmt("libc++abi.{s}", .{lib_suffix}), null, need_cpp_includes);
587591 } else if (exe.target.isDarwin()) {
588592 exe.linkSystemLibrary("c++");
589593 }