diff options
| author | ruki <[email protected]> | 2026-05-26 00:57:08 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2026-07-08 22:17:00 +0800 |
| commit | b2e698ae8a56ef12d69f76415d712b3247ea88c4 (patch) | |
| tree | 7dac37bf123ddf7c2ce9e8cca5f207d03c602dd3 | |
| parent | 83369f6bea88b1820329d2a2addbbf640aa792aa (diff) | |
improve pch for std modules
| -rw-r--r-- | xmake/modules/core/tools/gcc.lua | 3 | ||||
| -rw-r--r-- | xmake/rules/c++/modules/support.lua | 16 |
2 files changed, 18 insertions, 1 deletions
diff --git a/xmake/modules/core/tools/gcc.lua b/xmake/modules/core/tools/gcc.lua index 3bd9aefef..9172dd2ed 100644 --- a/xmake/modules/core/tools/gcc.lua +++ b/xmake/modules/core/tools/gcc.lua @@ -974,7 +974,8 @@ function compargv(self, sourcefile, objectfile, flags, opt) local extension = path.extension(sourcefile) if toolchain_utils.is_cxx_headerext(extension) then flags = _translate_flags_for_pch(self, flags) - elseif support.has_module_extension(sourcefile, {extension = extension}) then + elseif support.has_module_extension(sourcefile, {extension = extension}) + or support.is_stdmodule_file(opt.target, sourcefile) then flags = _translate_flags_for_mpp(self, flags) end diff --git a/xmake/rules/c++/modules/support.lua b/xmake/rules/c++/modules/support.lua index 1dd7625bb..126e25c61 100644 --- a/xmake/rules/c++/modules/support.lua +++ b/xmake/rules/c++/modules/support.lua @@ -201,6 +201,22 @@ function has_module_extension(sourcefile, opt) return modulexts:has(extension:lower()) end +-- is std module file? +-- e.g. libstdc++'s bits/std.cc and bits/std.compat.cc, which use the .cc extension +-- and therefore are not detected by has_module_extension. +-- @see https://github.com/xmake-io/xmake/issues/4051 +-- @see https://github.com/xmake-io/xmake/issues/7560 +function is_stdmodule_file(target, sourcefile) + if not target or not target.policy then + return false + end + if not target:policy("build.c++.modules.std") then + return false + end + local _, stdmodules_set = get_stdmodules(target) + return stdmodules_set and stdmodules_set:has(sourcefile) or false +end + -- this target contains module files? function contains_modules(target) -- we can not use `"c++.build.modules.builder"`, because it contains sourcekind/cxx. |
