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(...@@ -565,13 +565,17 @@ fn addCmakeCfgOptionsToExe(
565 exe.linkLibCpp();565 exe.linkLibCpp();
566 } else {566 } else {
567 const need_cpp_includes = true;567 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
569 // System -lc++ must be used because in this code path we are attempting to link573 // System -lc++ must be used because in this code path we are attempting to link
570 // against system-provided LLVM, Clang, LLD.574 // against system-provided LLVM, Clang, LLD.
571 if (exe.target.getOsTag() == .linux) {575 if (exe.target.getOsTag() == .linux) {
572 // First we try to static link against gcc libstdc++. If that doesn't work,576 // First we try to link against gcc libstdc++. If that doesn't work, we fall
573 // we fall back to -lc++ and cross our fingers.577 // back to -lc++ and cross our fingers.
574 addCxxKnownPath(b, cfg, exe, "libstdc++.a", "", need_cpp_includes) catch |err| switch (err) {578 addCxxKnownPath(b, cfg, exe, b.fmt("libstdc++.{s}", .{lib_suffix}), "", need_cpp_includes) catch |err| switch (err) {
575 error.RequiredLibraryNotFound => {579 error.RequiredLibraryNotFound => {
576 exe.linkSystemLibrary("c++");580 exe.linkSystemLibrary("c++");
577 },581 },
...@@ -579,11 +583,11 @@ fn addCmakeCfgOptionsToExe(...@@ -579,11 +583,11 @@ fn addCmakeCfgOptionsToExe(
579 };583 };
580 exe.linkSystemLibrary("unwind");584 exe.linkSystemLibrary("unwind");
581 } else if (exe.target.isFreeBSD()) {585 } 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);
583 exe.linkSystemLibrary("pthread");587 exe.linkSystemLibrary("pthread");
584 } else if (exe.target.getOsTag() == .openbsd) {588 } else if (exe.target.getOsTag() == .openbsd) {
585 try addCxxKnownPath(b, cfg, exe, "libc++.a", null, need_cpp_includes);589 try addCxxKnownPath(b, cfg, exe, b.fmt("libc++.{s}", .{lib_suffix}), null, need_cpp_includes);
586 try addCxxKnownPath(b, cfg, exe, "libc++abi.a", null, need_cpp_includes);590 try addCxxKnownPath(b, cfg, exe, b.fmt("libc++abi.{s}", .{lib_suffix}), null, need_cpp_includes);
587 } else if (exe.target.isDarwin()) {591 } else if (exe.target.isDarwin()) {
588 exe.linkSystemLibrary("c++");592 exe.linkSystemLibrary("c++");
589 }593 }