diff options
| author | ruki <[email protected]> | 2025-12-18 22:59:45 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2025-12-18 22:59:45 +0800 |
| commit | 882f1dcc718bfa248c835f2da9b9a135e3b18cd5 (patch) | |
| tree | 6ab04ab790963cc0c6b0d1c8f20d2b69ce286257 | |
| parent | b1e1b3e8017e37d0db6983a8a69be87d3e419002 (diff) | |
fix some vars
| -rw-r--r-- | xmake/modules/core/tools/clang.lua | 26 | ||||
| -rw-r--r-- | xmake/modules/private/utils/toolchain.lua | 119 |
2 files changed, 73 insertions, 72 deletions
diff --git a/xmake/modules/core/tools/clang.lua b/xmake/modules/core/tools/clang.lua index 754516c59..67af3da51 100644 --- a/xmake/modules/core/tools/clang.lua +++ b/xmake/modules/core/tools/clang.lua @@ -239,39 +239,39 @@ function nf_runtime(self, runtime, opt) if kind == "cxx" then -- force the toolchain libc++ headers to prevent clang picking the systems one -- @see https://github.com/llvm/llvm-project/issues/79647 - if llvm_dirs.cxxinclude then - maps["c++_static"] = table.join(maps["c++_static"], "-cxx-isystem" .. llvm_dirs.cxxinclude) - maps["c++_shared"] = table.join(maps["c++_shared"], "-cxx-isystem" .. llvm_dirs.cxxinclude) + if llvm_dirs.cxxincludedir then + maps["c++_static"] = table.join(maps["c++_static"], "-cxx-isystem" .. llvm_dirs.cxxincludedir) + maps["c++_shared"] = table.join(maps["c++_shared"], "-cxx-isystem" .. llvm_dirs.cxxincludedir) end end end if self:is_plat("windows") and language.sourcekinds()[kind] then -- on windows force link to compiler_rt builtins - if llvm_dirs.rt and llvm_dirs.rtlink then + if llvm_dirs.rtdir and llvm_dirs.rtlink then for name, _ in pairs(maps) do maps[name] = table.join({"-Xclang", "--dependent-lib=" .. llvm_dirs.rtlink}, maps[name]) end end end if kind == "ld" or kind == "sh" then - if self:is_plat("windows") and llvm_dirs.rt then + if self:is_plat("windows") and llvm_dirs.rtdir then -- on windows force add compiler_rt link directories for name, _ in pairs(maps) do - maps[name] = table.join(nf_linkdir(self, llvm_dirs.rt), maps[name]) - maps[name] = table.join("-resource-dir=" .. llvm_dirs.res, maps[name]) + maps[name] = table.join(nf_linkdir(self, llvm_dirs.rtdir), maps[name]) + maps[name] = table.join("-resource-dir=" .. llvm_dirs.resourcedir, maps[name]) end end local is_cxx = target and (target.sourcekinds and table.contains(table.wrap(target:sourcekinds()), "cxx")) if is_cxx then - if llvm_dirs.lib then - maps["c++_static"] = table.join(maps["c++_static"], nf_linkdir(self, llvm_dirs.lib)) - maps["c++_shared"] = table.join(maps["c++_shared"], nf_linkdir(self, llvm_dirs.lib)) + if llvm_dirs.libdir then + maps["c++_static"] = table.join(maps["c++_static"], nf_linkdir(self, llvm_dirs.libdir)) + maps["c++_shared"] = table.join(maps["c++_shared"], nf_linkdir(self, llvm_dirs.libdir)) -- sometimes llvm c++ runtimes are located in c++ subfolder (e.g homebrew llvm) - if llvm_dirs.cxxlib then - maps["c++_static"] = table.join(maps["c++_static"], nf_linkdir(self, llvm_dirs.cxxlib)) - maps["c++_shared"] = table.join(maps["c++_shared"], nf_linkdir(self, llvm_dirs.cxxlib)) + if llvm_dirs.cxxlibdir then + maps["c++_static"] = table.join(maps["c++_static"], nf_linkdir(self, llvm_dirs.cxxlibdir)) + maps["c++_shared"] = table.join(maps["c++_shared"], nf_linkdir(self, llvm_dirs.cxxlibdir)) end -- add rpath to avoid the user need to set DYLD_LIBRARY_PATH by hand diff --git a/xmake/modules/private/utils/toolchain.lua b/xmake/modules/private/utils/toolchain.lua index d687adf09..0536c3afa 100644 --- a/xmake/modules/private/utils/toolchain.lua +++ b/xmake/modules/private/utils/toolchain.lua @@ -182,16 +182,19 @@ function map_linkflags_for_package(package, targetkind, sourcekinds, name, value end -- get llvm sdk resource directory -function _get_llvm_resourcedir(toolchain) +function get_llvm_resourcedir(toolchain) local memcache = toolchain:memcache() local cachekey = "get_llvm_resourcedir" local llvm_resourcedir = memcache:get(cachekey) if llvm_resourcedir == nil then - local outdata = try { function() return os.iorunv(toolchain:tool("cc"), {"-print-resource-dir"}) end } - if outdata then - llvm_resourcedir = path.normalize(outdata:trim()) - if not os.isdir(llvm_resourcedir) then - llvm_resourcedir = nil + local cc = toolchain:tool("cc") + if cc then + local outdata = try { function() return os.iorunv(cc, {"-print-resource-dir"}) end } + if outdata then + llvm_resourcedir = path.normalize(outdata:trim()) + if not os.isdir(llvm_resourcedir) then + llvm_resourcedir = nil + end end end memcache:set(cachekey, llvm_resourcedir or false) @@ -200,12 +203,12 @@ function _get_llvm_resourcedir(toolchain) end -- get llvm sdk root directory -function _get_llvm_rootdir(toolchain) +function get_llvm_rootdir(toolchain) local memcache = toolchain:memcache() local cachekey = "get_llvm_rootdir" local llvm_rootdir = memcache:get(cachekey) if llvm_rootdir == nil then - local resourcedir = _get_llvm_resourcedir(toolchain) + local resourcedir = get_llvm_resourcedir(toolchain) if resourcedir then llvm_rootdir = path.normalize(path.join(resourcedir, "..", "..", "..")) if not os.isdir(llvm_rootdir) then @@ -219,51 +222,49 @@ end -- find compiler-rt dir function _get_llvm_compiler_rtdir_and_link(toolchain) + local resdir = get_llvm_resourcedir(toolchain) + if resdir then + local res_libdir = path.join(resdir, "lib") + -- when -DLLVM_ENABLE_TARGET_RUNTIME_DIR=OFF rtdir is windows/ and rtlink is clang_rt.builtins_<arch>.lib + -- when ON rtdir is windows/<target-triple> and rtlink is clang_rt.builtins.lib + local target_triple = get_llvm_target_triple(toolchain) + local arch = target_triple and target_triple:split("-")[1] - local cc = toolchain:tool("cc") - local cc_tool = find_tool(cc, {version = true}) - if cc_tool and cc_tool.version then - local resdir = _get_llvm_resourcedir(toolchain) - if resdir then - local res_libdir = path.join(resdir, "lib") - -- when -DLLVM_ENABLE_TARGET_RUNTIME_DIR=OFF rtdir is windows/ and rtlink is clang_rt.builtins_<arch>.lib - -- when ON rtdir is windows/<target-triple> and rtlink is clang_rt.builtins.lib - local target_triple = _get_llvm_target_triple(toolchain) - local arch = target_triple and target_triple:split("-")[1] - - local plat - if toolchain:is_plat("windows", "mingw") then - plat = "windows" - elseif toolchain:is_plat("linux") then - plat = "linux" - elseif toolchain:is_plat("macosx", "ios", "watchos", "appletvos", "applexros") then - plat = "darwin" - end - - local tripletdir = target_triple and path.join(res_libdir, "windows", target_triple) - tripletdir = os.isdir(tripletdir) or nil + local plat + if toolchain:is_plat("windows", "mingw") then + plat = "windows" + elseif toolchain:is_plat("linux") then + plat = "linux" + elseif toolchain:is_plat("macosx", "ios", "watchos", "appletvos", "applexros") then + plat = "darwin" + end + + local tripletdir = target_triple and path.join(res_libdir, "windows", target_triple) + tripletdir = os.isdir(tripletdir) or nil - local rtdir = tripletdir and path.join(plat, target_triple) or plat - if os.isdir(path.join(res_libdir, rtdir)) and toolchain:is_plat("windows", "mingw") then - local rtlink = "clang_rt.builtins" .. (tripletdir and ".lib" or ("-" .. arch .. ".lib")) - if os.isfile(path.join(res_libdir, rtdir, rtlink)) then - return res_libdir, path.join(rtdir, rtlink), path.join(res_libdir, rtdir) - end + local rtdir = tripletdir and path.join(plat, target_triple) or plat + if os.isdir(path.join(res_libdir, rtdir)) and toolchain:is_plat("windows", "mingw") then + local rtlink = "clang_rt.builtins" .. (tripletdir and ".lib" or ("-" .. arch .. ".lib")) + if os.isfile(path.join(res_libdir, rtdir, rtlink)) then + return res_libdir, path.join(rtdir, rtlink), path.join(res_libdir, rtdir) end - return res_libdir, nil, path.join(res_libdir, rtdir) end + return res_libdir, nil, path.join(res_libdir, rtdir) end end -- get llvm target triple -function _get_llvm_target_triple(toolchain) +function get_llvm_target_triple(toolchain) local memcache = toolchain:memcache() local cachekey = "get_llvm_target_triple" local llvm_targettriple = memcache:get(cachekey) if llvm_targettriple == nil then - local outdata = try { function() return os.iorunv(toolchain:tool("cc"), {"-print-target-triple"}) end } - if outdata then - llvm_targettriple = outdata:trim() + local cc = toolchain:tool("cc") + if cc then + local outdata = try { function() return os.iorunv(cc, {"-print-target-triple"}) end } + if outdata then + llvm_targettriple = outdata:trim() + end end memcache:set(cachekey, llvm_targettriple or false) end @@ -278,10 +279,10 @@ function get_llvm_dirs(toolchain) if llvm_dirs == nil then local rootdir = toolchain:sdkdir() if not rootdir and (toolchain:is_plat("windows") or is_host("windows")) then - rootdir = _get_llvm_rootdir(toolchain) + rootdir = get_llvm_rootdir(toolchain) end - local bindir, libdir, cxxlibdir, includedir, cxxincludedir, resdir, rtdir, rtlink, rtlib + local bindir, libdir, cxxlibdir, includedir, cxxincludedir, resourcedir, rtdir, rtlink, rtlib if rootdir then bindir = path.join(rootdir, "bin") bindir = os.isdir(bindir) and bindir or nil @@ -293,7 +294,7 @@ function get_llvm_dirs(toolchain) cxxlibdir = path.join(libdir, "c++") cxxlibdir = os.isdir(cxxlibdir) and cxxlibdir or nil if not cxxlibdir then - cxxlibdir = path.join(libdir, _get_llvm_target_triple(toolchain)) + cxxlibdir = path.join(libdir, get_llvm_target_triple(toolchain)) cxxlibdir = os.isdir(cxxlibdir) and cxxlibdir or nil end end @@ -306,19 +307,19 @@ function get_llvm_dirs(toolchain) cxxincludedir = os.isdir(cxxincludedir) and cxxincludedir or nil end - resdir = _get_llvm_resourcedir(toolchain) + resourcedir = get_llvm_resourcedir(toolchain) rtdir, rtlink, rtlib = _get_llvm_compiler_rtdir_and_link(toolchain) end - llvm_dirs = {root = rootdir, - bin = bindir, - lib = libdir, - cxxlib = cxxlibdir, - include = includedir, - cxxinclude = cxxincludedir, - res = resdir, - rt = rtdir, - rtlib = rtlib, + llvm_dirs = {rootdir = rootdir, + bindir = bindir, + libdir = libdir, + cxxlibdir = cxxlibdir, + includedir = includedir, + cxxincludedir = cxxincludedir, + resourcedir = resourcedir, + rtdir = rtdir, + rtlibdir = rtlib, rtlink = rtlink } memcache:set(cachekey, llvm_dirs) end @@ -329,10 +330,10 @@ end function set_llvm_runenvs(toolchain) local dirs = get_llvm_dirs(toolchain) if dirs then - if dirs.bin and (toolchain:is_plat("windows") or is_host("windows")) then - toolchain:add("runenvs", "PATH", dirs.bin) + if dirs.bindir and (toolchain:is_plat("windows") or is_host("windows")) then + toolchain:add("runenvs", "PATH", dirs.bindir) end - for _, dir in ipairs({dirs.lib or false, dirs.cxxlib or false, dirs.rtlib or false}) do + for _, dir in ipairs({dirs.libdir or false, dirs.cxxlibdir or false, dirs.rtlibdir or false}) do if dir then if toolchain:is_plat("windows") or is_host("windows") then toolchain:add("runenvs", "PATH", dir) @@ -353,8 +354,8 @@ end -- add compiler-rt for llvm function add_llvm_compiler_rt(toolchain) local dirs = get_llvm_dirs(toolchain) - if dirs and dirs.rtlib and dirs.rtlink then - local rtlib_path = path.join(dirs.rtlib, path.filename(dirs.rtlink)) + if dirs and dirs.rtlibdir and dirs.rtlink then + local rtlib_path = path.join(dirs.rtlibdir, path.filename(dirs.rtlink)) toolchain:add("ldflags", rtlib_path) toolchain:add("shflags", rtlib_path) end |
