Skip to content

Commit

Permalink
Merge pull request #4681 from Arthapz/fix-libcppruntime-windows
Browse files Browse the repository at this point in the history
fix libc++ support on windows
  • Loading branch information
waruqi authored Feb 4, 2024
2 parents 0beb108 + 9f47d45 commit 54d678d
Showing 1 changed file with 33 additions and 1 deletion.
34 changes: 33 additions & 1 deletion xmake/modules/core/tools/clang.lua
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,21 @@ function _has_static_libstdcxx(self)
return has_static_libstdcxx
end

-- get llvm sdk root directory
function _get_llvm_rootdir(self)
local llvm_rootdir = _g._LLVM_ROOTDIR
if llvm_rootdir == nil then
local outdata = try { function() return os.iorun(self:program() .. " -print-resource-dir") end }
if outdata then
llvm_rootdir = path.normalize(path.join(outdata:trim(), "..", "..", ".."))
if not os.isdir(llvm_rootdir) then
llvm_rootdir = nil
end
end
_g._LLVM_ROOTDIR = llvm_rootdir or false
end
return llvm_rootdir or nil
end

-- make the runtime flag
-- @see https://github.com/xmake-io/xmake/issues/3546
Expand Down Expand Up @@ -228,13 +243,31 @@ function nf_runtime(self, runtime, opt)
maps["c++_shared"] = "-stdlib=libc++"
maps["stdc++_static"] = "-stdlib=libstdc++"
maps["stdc++_shared"] = "-stdlib=libstdc++"
-- clang on windows fail to add libc++ includepath when using -stdlib=libc++ so we manually add it
-- @see https://github.com/llvm/llvm-project/issues/79647
if self:is_plat("windows") then
local llvm_rootdir = _get_llvm_rootdir(self)
if llvm_rootdir then
maps["c++_static"] = table.join(maps["c++_static"], "-cxx-isystem" .. path.join(llvm_rootdir, "include", "c++", "v1"))
maps["c++_shared"] = table.join(maps["c++_shared"], "-cxx-isystem" .. path.join(llvm_rootdir, "include", "c++", "v1"))
end
end
elseif kind == "ld" or kind == "sh" then
local target = opt.target
if target and target.sourcekinds and table.contains(table.wrap(target:sourcekinds()), "cxx") then
maps["c++_static"] = "-stdlib=libc++"
maps["c++_shared"] = "-stdlib=libc++"
maps["stdc++_static"] = "-stdlib=libstdc++"
maps["stdc++_shared"] = "-stdlib=libstdc++"
-- clang on windows fail to add libc++ librarypath when using -stdlib=libc++ so we manually add it
-- @see https://github.com/llvm/llvm-project/issues/79647
if self:is_plat("windows") then
local llvm_rootdir = _get_llvm_rootdir(self)
if llvm_rootdir then
maps["c++_static"] = table.join(maps["c++_static"], "-L" .. path.join(llvm_rootdir, "lib"))
maps["c++_shared"] = table.join(maps["c++_shared"], "-L" .. path.join(llvm_rootdir, "lib"))
end
end
if runtime:endswith("_static") and _has_static_libstdcxx(self) then
maps["c++_static"] = table.join(maps["c++_static"], "-static-libstdc++")
maps["stdc++_static"] = table.join(maps["stdc++_static"], "-static-libstdc++")
Expand All @@ -244,4 +277,3 @@ function nf_runtime(self, runtime, opt)
end
return maps and maps[runtime]
end

0 comments on commit 54d678d

Please sign in to comment.