summaryrefslogtreecommitdiff
path: root/xmake/rules/c++/modules/xmake.lua
diff options
context:
space:
mode:
authorruki <[email protected]>2022-08-09 10:52:30 +0800
committerGitHub <[email protected]>2022-08-09 10:52:30 +0800
commitd025377baf093a035e11fccc68309a49ae6da471 (patch)
treeb4b59671a866348f471985125d3382d700cfe78c /xmake/rules/c++/modules/xmake.lua
parent46cf0ad2545d829a255e88371660dfe8bb11de22 (diff)
parentaf7118dcc94785f628abe1cea5cd030514ea9e88 (diff)
Merge pull request #2649 from xmake-io/batchjobs
Adding parallel compilation support for c++ modules
Diffstat (limited to 'xmake/rules/c++/modules/xmake.lua')
-rw-r--r--xmake/rules/c++/modules/xmake.lua85
1 files changed, 50 insertions, 35 deletions
diff --git a/xmake/rules/c++/modules/xmake.lua b/xmake/rules/c++/modules/xmake.lua
index 4117004cc..23f9a0f77 100644
--- a/xmake/rules/c++/modules/xmake.lua
+++ b/xmake/rules/c++/modules/xmake.lua
@@ -53,55 +53,70 @@ rule("c++.build.modules.builder")
set_sourcekinds("cxx")
set_extensions(".mpp", ".mxx", ".cppm", ".ixx")
- -- TODO parallel build support to accelerate `xmake build` to build modules
- --[[
+ -- generate headerunits
+ -- parallel build support to accelerate `xmake build` to build headerunits
+ before_build(function(target, batchjobs, opt)
+ local job
+ if target:data("cxx.has_modules") then
+ import("modules_support.common")
+ local sourcebatch = target:sourcebatches()["c++.build.modules.builder"]
+ common.patch_sourcebatch(target, sourcebatch, opt)
+ local modules = common.get_module_dependencies(target, sourcebatch, opt)
+ batchjobs:group_enter(target:name() .. "/generate_headerunits")
+ common.generate_headerunits_for_batchjobs(target, batchjobs, sourcebatch, modules, opt)
+ job = batchjobs:group_leave()
+ end
+ return job or opt.rootjob
+ end, {batch = true})
+
+ -- build modules
+ -- parallel build support to accelerate `xmake build` to build modules
before_build_files(function(target, batchjobs, sourcebatch, opt)
- if not target:data("cxx.has_modules") then
+ if target:data("cxx.has_modules") then
+ import("modules_support.common")
+ common.patch_sourcebatch(target, sourcebatch, opt)
+ local modules = common.get_module_dependencies(target, sourcebatch, opt)
+ common.build_modules_for_batchjobs(target, batchjobs, sourcebatch, modules, opt)
+ else
+ -- avoid duplicate linking of object files of non-module programs
sourcebatch.objectfiles = {}
- return
end
+ end, {batch = true})
- -- patch sourcebatch
- import("modules_support.common")
- common.patch_sourcebatch(target, sourcebatch, opt)
-
- -- generate dependencies
- local modules = common.generate_dependencies(target, sourcebatch, opt)
+ -- serial compilation only, usually used to support project generator
+ before_buildcmd_files(function(target, batchcmds, sourcebatch, opt)
+ if target:data("cxx.has_modules") then
+ import("modules_support.common")
- -- generate headerunits
- local headerunits_flags = common.generate_headerunits_for_batchjobs(target, batchjobs, sourcebatch, modules, opt)
- if headerunits_flags then
- target:add("cxxflags", headerunits_flags, {force = true, expand = false})
- end
+ -- patch sourcebatch
+ common.patch_sourcebatch(target, sourcebatch, opt)
- -- build modules
- common.build_modules_for_batchjobs(target, batchjobs, sourcebatch, modules, opt)
- end, {batch = true})]]
+ -- generate headerunits
+ local modules = common.get_module_dependencies(target, sourcebatch, opt)
+ common.generate_headerunits_for_batchcmds(target, batchcmds, sourcebatch, modules, opt)
- -- serial compilation only, usually used to support project generator
- before_buildcmd_files(function(target, batchcmds, sourcebatch, opt)
- if not target:data("cxx.has_modules") then
+ -- build modules
+ common.build_modules_for_batchcmds(target, batchcmds, sourcebatch, modules, opt)
+ else
+ -- avoid duplicate linking of object files of non-module programs
sourcebatch.objectfiles = {}
- return
end
+ end)
- -- patch sourcebatch
+ before_link(function (target)
import("modules_support.common")
- common.patch_sourcebatch(target, sourcebatch, opt)
-
- -- generate dependencies
- local modules = common.generate_dependencies(target, sourcebatch, opt)
-
- -- generate headerunits
- common.generate_headerunits_for_batchcmds(target, batchcmds, sourcebatch, modules, opt)
-
- -- build modules
- common.build_modules_for_batchcmds(target, batchcmds, sourcebatch, modules, opt)
+ common.append_headerunits_objectfiles(target)
end)
- before_link(function(target)
+ after_clean(function (target)
+ import("core.base.option")
import("modules_support.common")
- common.append_headerunits_objectfiles(target)
+ os.tryrm(common.modules_cachedir(target))
+ if option.get("all") then
+ os.tryrm(common.stlmodules_cachedir(target))
+ common.localcache():clear()
+ common.localcache():save()
+ end
end)
-- install modules