summaryrefslogtreecommitdiff
path: root/xmake
diff options
context:
space:
mode:
authorruki <[email protected]>2026-01-25 10:20:26 +0800
committerGitHub <[email protected]>2026-01-25 10:20:26 +0800
commitc3989a33c7644a43d4c3cc5567e4e117785bc67d (patch)
tree063cbf139fc243e6b872d84b2b465b152ef6febb /xmake
parent0e77fe915b391f51d2460f33dca632171e0612ca (diff)
parent6f2f989f19df66e73999ffaaffc69b8df1159a68 (diff)
Merge pull request #7262 from xmake-io/pch
Improve pch concurrently to the other targets
Diffstat (limited to 'xmake')
-rw-r--r--xmake/modules/private/action/build/pcheader.lua3
-rw-r--r--xmake/rules/c++/precompiled_header/xmake.lua35
-rw-r--r--xmake/rules/objc++/precompiled_header/xmake.lua24
3 files changed, 52 insertions, 10 deletions
diff --git a/xmake/modules/private/action/build/pcheader.lua b/xmake/modules/private/action/build/pcheader.lua
index 2e3210dca..4e984f62b 100644
--- a/xmake/modules/private/action/build/pcheader.lua
+++ b/xmake/modules/private/action/build/pcheader.lua
@@ -51,6 +51,9 @@ function config(target, langkind, opt)
target:pcheaderfile_set(langkind, headerfile)
end
end
+
+ -- enable precompiled header?
+ return true
end
end
diff --git a/xmake/rules/c++/precompiled_header/xmake.lua b/xmake/rules/c++/precompiled_header/xmake.lua
index a2b08fe46..8bfdd09dd 100644
--- a/xmake/rules/c++/precompiled_header/xmake.lua
+++ b/xmake/rules/c++/precompiled_header/xmake.lua
@@ -20,21 +20,46 @@
rule("c.build.pcheader")
on_config(function (target, opt)
- import("private.action.build.pcheader").config(target, "c", opt)
+ import("private.action.build.pcheader")
+ if not pcheader.config(target, "c", opt) then
+ target:rule_enable("c.build.pcheader", false)
+ end
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)
+ import("private.action.build.pcheader")
+ if not pcheader.config(target, "cxx", opt) then
+ target:rule_enable("c++.build.pcheader", false)
+ end
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})
diff --git a/xmake/rules/objc++/precompiled_header/xmake.lua b/xmake/rules/objc++/precompiled_header/xmake.lua
index ed0eda0a4..5dafb0e84 100644
--- a/xmake/rules/objc++/precompiled_header/xmake.lua
+++ b/xmake/rules/objc++/precompiled_header/xmake.lua
@@ -20,18 +20,32 @@
rule("objc.build.pcheader")
on_config(function (target, opt)
- import("private.action.build.pcheader").config(target, "m", opt)
+ import("private.action.build.pcheader")
+ if not pcheader.config(target, "m", opt) then
+ target:rule_enable("objc.build.pcheader", false)
+ end
end)
- before_prepare(function (target, jobgraph, opt)
- import("private.action.build.pcheader").build(target, jobgraph, "m", 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, "m", opt)
+ end
end, {jobgraph = true})
rule("objc++.build.pcheader")
add_orders("objc++.build.pcheader", "c++.build.modules.builder")
on_config(function (target, opt)
- import("private.action.build.pcheader").config(target, "mxx", opt)
+ import("private.action.build.pcheader")
+ if not pcheader.config(target, "mxx", opt) then
+ target:rule_enable("objc++.build.pcheader", false)
+ end
end)
- before_prepare(function (target, jobgraph, opt)
+
+ -- Since Objective-C typically does not have C++ modules,
+ -- we can always 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.
+ before_build(function (target, jobgraph, opt)
import("private.action.build.pcheader").build(target, jobgraph, "mxx", opt)
end, {jobgraph = true})