diff options
| author | ruki <[email protected]> | 2025-09-26 22:14:46 +0800 |
|---|---|---|
| committer | GitHub <[email protected]> | 2025-09-26 22:14:46 +0800 |
| commit | 7c9fbf87ba1d4b48fb111bf3cc4090b5ebcf90b3 (patch) | |
| tree | 94e3d5a47e819b573ada0c418846f70fe1224ae6 /xmake/rules/c++ | |
| parent | f6e00b1cc570b023c618f3753f9e0c91b82df652 (diff) | |
| parent | bcc3c5617baad62989a45a44aa2890fda5eba0f3 (diff) | |
Merge pull request #6809 from Arthapz/fix-stdmodule-priority
fix(C++ modules) fix stdmodule priority
Diffstat (limited to 'xmake/rules/c++')
| -rw-r--r-- | xmake/rules/c++/modules/clang/support.lua | 24 | ||||
| -rw-r--r-- | xmake/rules/c++/modules/support.lua | 31 |
2 files changed, 30 insertions, 25 deletions
diff --git a/xmake/rules/c++/modules/clang/support.lua b/xmake/rules/c++/modules/clang/support.lua index 1aae7a2dc..11c2f9a67 100644 --- a/xmake/rules/c++/modules/clang/support.lua +++ b/xmake/rules/c++/modules/clang/support.lua @@ -38,7 +38,7 @@ function _get_toolchain_includedirs_for_stlheaders(target, includedirs, clang) local tmpfile = os.tmpfile() .. ".cc" io.writefile(tmpfile, "#include <vector>") local argv = {"-E", "-x", "c++", tmpfile} - local cpplib = _get_cpplibrary_name(target) + local cpplib = get_cpplibrary_name(target) if cpplib then if cpplib == "c++" then table.insert(argv, 1, "-stdlib=libc++") @@ -62,24 +62,6 @@ function _get_toolchain_includedirs_for_stlheaders(target, includedirs, clang) os.tryrm(tmpfile) end -function _get_cpplibrary_name(target) - -- libc++ come first because on windows, if we use libc++ clang will still use msvc crt so MD / MT / MDd / MTd can be set - if target:has_runtime("c++_shared", "c++_static") then - return "c++" - elseif target:has_runtime("stdc++_shared", "stdc++_static") then - return "stdc++" - elseif target:has_runtime("MD", "MT", "MDd", "MTd") then - return "msstl" - end - if target:is_plat("macosx", "iphoneos", "appletvos") then - return "c++" - elseif target:is_plat("linux") then - return "stdc++" - elseif target:is_plat("windows") then - return "msstl" - end -end - function _get_std_module_manifest_path(target) local print_module_manifest_flag = get_print_library_module_manifest_path_flag(target) local clang_path = path.directory(get_clang_path(target)) @@ -168,7 +150,7 @@ function toolchain_includedirs(target) local clang, toolname = target:tool("cxx") assert(toolname:startswith("clang")) _get_toolchain_includedirs_for_stlheaders(target, includedirs, clang) - local cpplib = _get_cpplibrary_name(target) + local cpplib = get_cpplibrary_name(target) local runtime_flag if cpplib then if cpplib == "c++" then @@ -261,7 +243,7 @@ function get_stdmodules(target) if not target:policy("build.c++.modules.std") then return end - local cpplib = _get_cpplibrary_name(target) + local cpplib = get_cpplibrary_name(target) if cpplib then if cpplib == "c++" then -- libc++ module is found by parsing libc++.modules.json diff --git a/xmake/rules/c++/modules/support.lua b/xmake/rules/c++/modules/support.lua index ef1d1f9dd..8d1c39531 100644 --- a/xmake/rules/c++/modules/support.lua +++ b/xmake/rules/c++/modules/support.lua @@ -69,6 +69,25 @@ function load(target) _support(target).load(target) end +function get_cpplibrary_name(target) + -- libc++ come first because on windows, if we use libc++ clang will still use msvc crt so MD / MT / MDd / MTd can be set + if target:has_runtime("c++_shared", "c++_static") then + return "c++" + elseif target:has_runtime("stdc++_shared", "stdc++_static") then + return "stdc++" + elseif target:has_runtime("MD", "MT", "MDd", "MTd") then + return "msstl" + end + -- if no specified runtime, fallback on native platform C++ library + if target:is_plat("macosx", "iphoneos", "appletvos") then + return "c++" + elseif target:is_plat("linux") or target:is_plat("mingw") then + return "stdc++" + elseif target:is_plat("windows") then + return "msstl" + end +end + function has_two_phase_compilation_support(target) return _support(target).has_two_phase_compilation_support(target) end @@ -240,6 +259,9 @@ function can_be_culled(target, sourcefile) can_cull = can_cull and fileconfig.cull end end + if can_cull then + can_cull = is_stdmodule or (fileconfig and fileconfig.external) + end return can_cull and not public end @@ -282,13 +304,14 @@ end -- get stdmodules function get_stdmodules(target) - local stdmodules = memcache():get("c++.modules.stdmodules") - local stdmodules_set = memcache():get("c++.modules.stdmodules_set") + local cpplib = get_cpplibrary_name(target) + local stdmodules = memcache():get2(cpplib, "c++.modules.stdmodules") + local stdmodules_set = memcache():get2(cpplib, "c++.modules.stdmodules_set") if not stdmodules or not stdmodules_set then stdmodules = _support(target).get_stdmodules(target) stdmodules_set = hashset.from(stdmodules or {}) - memcache():set("c++.modules.stdmodules", stdmodules) - memcache():set("c++.modules.stdmodules_set", stdmodules_set) + memcache():set2(cpplib, "c++.modules.stdmodules", stdmodules) + memcache():set2(cpplib, "c++.modules.stdmodules_set", stdmodules_set) end return stdmodules, stdmodules_set end |
