diff options
| author | ruki <[email protected]> | 2026-01-24 22:09:55 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2026-01-24 22:09:55 +0800 |
| commit | 5ed27569ffb41d7ce65a9185e26ad258bd2707fd (patch) | |
| tree | ec9b6e68065f2c9e32783771434ddc354f8274c8 | |
| parent | 54be8114524841180f4e3741f23668c149b0553e (diff) | |
improve pch
| -rw-r--r-- | xmake/rules/c++/precompiled_header/xmake.lua | 25 |
1 files changed, 22 insertions, 3 deletions
diff --git a/xmake/rules/c++/precompiled_header/xmake.lua b/xmake/rules/c++/precompiled_header/xmake.lua index a2b08fe46..d67535cc6 100644 --- a/xmake/rules/c++/precompiled_header/xmake.lua +++ b/xmake/rules/c++/precompiled_header/xmake.lua @@ -22,19 +22,38 @@ rule("c.build.pcheader") on_config(function (target, opt) import("private.action.build.pcheader").config(target, "c", opt) end) - before_prepare(function (target, jobgraph, opt) + + before_build(function (target, jobgraph, opt) if not os.getenv("XMAKE_IN_COMPILE_COMMANDS_PROJECT_GENERATOR") then import("private.action.build.pcheader").build(target, jobgraph, "c", opt) end end, {jobgraph = true}) rule("c++.build.pcheader") - add_orders("c++.build.modules.scanner", "c++.build.pcheader", "c++.build.modules.builder") on_config(function (target, opt) import("private.action.build.pcheader").config(target, "cxx", opt) end) + + -- If the current target has a C++ modules file, + -- we can only compile it earlier in the before_prepare stage, + -- because the C++ modules will perform a complete dependency scan of + -- the C++ files in on_prepare and then build the dependency graph. + -- At this time, the pch header file must have already been generated. before_prepare(function (target, jobgraph, opt) - if not os.getenv("XMAKE_IN_COMPILE_COMMANDS_PROJECT_GENERATOR") then + local has_modules = target:data("cxx.has_modules") + if has_modules and not os.getenv("XMAKE_IN_COMPILE_COMMANDS_PROJECT_GENERATOR") then + import("private.action.build.pcheader").build(target, jobgraph, "cxx", opt) + end + end, {jobgraph = true}) + + -- To enable parallel compilation across targets + -- without blocking the compilation of other cpp files, + -- we perform this as much as possible during the before_build stage. + -- + -- @see: https://github.com/xmake-io/xmake/issues/4167 + before_build(function (target, jobgraph, opt) + local has_modules = target:data("cxx.has_modules") + if not has_modules then import("private.action.build.pcheader").build(target, jobgraph, "cxx", opt) end end, {jobgraph = true}) |
