summaryrefslogtreecommitdiff
path: root/xmake/modules
diff options
context:
space:
mode:
Diffstat (limited to 'xmake/modules')
-rw-r--r--xmake/modules/core/tools/clang.lua10
-rw-r--r--xmake/modules/private/utils/toolchain.lua18
2 files changed, 27 insertions, 1 deletions
diff --git a/xmake/modules/core/tools/clang.lua b/xmake/modules/core/tools/clang.lua
index 1250d1a46..e29950e81 100644
--- a/xmake/modules/core/tools/clang.lua
+++ b/xmake/modules/core/tools/clang.lua
@@ -286,6 +286,16 @@ function nf_runtime(self, runtime, opt)
end
if runtime:endswith("_static") and _has_static_libstdcxx(self) then
maps["stdc++_static"] = table.join(maps["stdc++_static"], "-static-libstdc++")
+ -- statically link libc++. -static-libstdc++ only pulls in libc++.a, so when libc++abi
+ -- is a separate archive we link both in a group (they reference each other), otherwise
+ -- (bundled abi) fall back to -static-libstdc++.
+ -- @see https://github.com/xmake-io/xmake/issues/7656, https://github.com/xmake-io/xmake/issues/7442
+ if llvm_dirs.libcxx_static and llvm_dirs.libcxxabi_static then
+ maps["c++_static"] = table.join(maps["c++_static"], "-nostdlib++",
+ "-Wl,--start-group", llvm_dirs.libcxx_static, llvm_dirs.libcxxabi_static, "-Wl,--end-group")
+ else
+ maps["c++_static"] = table.join(maps["c++_static"], "-static-libstdc++")
+ end
end
end
end
diff --git a/xmake/modules/private/utils/toolchain.lua b/xmake/modules/private/utils/toolchain.lua
index c2840a591..3ae8d5e4f 100644
--- a/xmake/modules/private/utils/toolchain.lua
+++ b/xmake/modules/private/utils/toolchain.lua
@@ -457,6 +457,7 @@ function get_llvm_dirs(toolchain)
end
local bindir, libdir, cxxlibdir, includedir, cxxincludedir, resourcedir, rtdir, rtlink, rtlibdir
+ local libcxx_static, libcxxabi_static
if rootdir then
bindir = path.join(rootdir, "bin")
bindir = os.isdir(bindir) and bindir or nil
@@ -476,6 +477,19 @@ function get_llvm_dirs(toolchain)
end
end
+ -- detect the static c++ runtime archives (for --runtimes=c++_static with libc++)
+ if libdir then
+ local staticdirs = cxxlibdir and {cxxlibdir, libdir} or {libdir}
+ for _, dir in ipairs(staticdirs) do
+ if not libcxx_static and os.isfile(path.join(dir, "libc++.a")) then
+ libcxx_static = path.join(dir, "libc++.a")
+ end
+ if not libcxxabi_static and os.isfile(path.join(dir, "libc++abi.a")) then
+ libcxxabi_static = path.join(dir, "libc++abi.a")
+ end
+ end
+ end
+
includedir = path.join(rootdir, "include")
includedir = os.isdir(includedir) and includedir or nil
@@ -502,7 +516,9 @@ function get_llvm_dirs(toolchain)
resourcedir = resourcedir,
rtdir = rtdir,
rtlibdir = rtlibdir,
- rtlink = rtlink }
+ rtlink = rtlink,
+ libcxx_static = libcxx_static,
+ libcxxabi_static = libcxxabi_static }
memcache:set(cachekey, llvm_dirs)
end
return llvm_dirs