summaryrefslogtreecommitdiff
path: root/xmake/rules/c++/modules
diff options
context:
space:
mode:
authorArthur LAURENT <[email protected]>2022-08-09 06:56:47 +0200
committerArthur LAURENT <[email protected]>2022-08-10 16:52:51 +0200
commit172d2c7fcd0bf09fb24d286df3d2da5b556c291b (patch)
treebfcb02144ece8e29236a050c647d5fb98a45da91 /xmake/rules/c++/modules
parent334a540681025ad0d71fc5f390252c4879593858 (diff)
Avoid building a same header unit at the same time
Diffstat (limited to 'xmake/rules/c++/modules')
-rw-r--r--xmake/rules/c++/modules/modules_support/msvc.lua37
-rw-r--r--xmake/rules/c++/modules/xmake.lua6
2 files changed, 29 insertions, 14 deletions
diff --git a/xmake/rules/c++/modules/modules_support/msvc.lua b/xmake/rules/c++/modules/modules_support/msvc.lua
index bcc781248..d1a09cbeb 100644
--- a/xmake/rules/c++/modules/modules_support/msvc.lua
+++ b/xmake/rules/c++/modules/modules_support/msvc.lua
@@ -181,9 +181,14 @@ function generate_stl_headerunits_for_batchjobs(target, batchjobs, headerunits,
if not os.isfile(bmifile) or not os.isfile(objectfile) then
batchjobs:addjob(headerunit.name, function(index, total)
depend.on_changed(function()
- progress.show((index * 100) / total, "${color.build.object}generating.cxx.headerunit.bmi %s", headerunit.name)
- local args = {headernameflag .. ":angle", headerunit.name, ifcoutputflag, stlcachedir, "-Fo" .. objectfile}
- os.vrunv(compinst:program(), table.join(compinst:compflags({target = target}), common_args, args), {envs = vcvars})
+ if not common.localcache():get2(headerunit.name, "building") then
+ common.localcache():set2(headerunit.name, "building", true)
+ progress.show((index * 100) / total, "${color.build.object}generating.cxx.headerunit.bmi %s", headerunit.name)
+ local args = {headernameflag .. ":angle", headerunit.name, ifcoutputflag, stlcachedir, "-Fo" .. objectfile}
+ os.vrunv(compinst:program(), table.join(compinst:compflags({target = target}), common_args, args), {envs = vcvars})
+ common.localcache():set2(headerunit.name, "building", false)
+ end
+
end, {dependfile = target:dependfile(bmifile), files = {headerunit.path}})
end, {rootjob = opt.rootjob})
_add_module_to_mapper(headerunitflag .. ":angle", headerunit.name .. "=" .. path.filename(headerunit.name) .. get_bmi_extension())
@@ -259,18 +264,22 @@ function generate_user_headerunits_for_batchjobs(target, batchjobs, headerunits,
local bmifile = path.join(outputdir, bmifilename)
batchjobs:addjob(headerunit.name, function (index, total)
depend.on_changed(function()
- progress.show((index * 100) / total, "${color.build.object}generating.cxx.headerunit.bmi %s", headerunit.name)
- local objectdir = path.directory(objectfile)
- if not os.isdir(objectdir) then
- os.mkdir(objectdir)
- end
- if not os.isdir(outputdir) then
- os.mkdir(outputdir)
- end
+ if not common.localcache():get2(headerunit.name, "building") then
+ common.localcache():set2(headerunit.name, "building", true)
+ progress.show((index * 100) / total, "${color.build.object}generating.cxx.headerunit.bmi %s", headerunit.name)
+ local objectdir = path.directory(objectfile)
+ if not os.isdir(objectdir) then
+ os.mkdir(objectdir)
+ end
+ if not os.isdir(outputdir) then
+ os.mkdir(outputdir)
+ end
- -- generate headerunit
- local args = {headernameflag .. headerunit.type, headerunit.path, ifcoutputflag, outputdir, "/Fo" .. objectfile}
- os.vrunv(compinst:program(), table.join(compinst:compflags({target = target}), common_args, args), {envs = vcvars})
+ -- generate headerunit
+ local args = {headernameflag .. headerunit.type, headerunit.path, ifcoutputflag, outputdir, "/Fo" .. objectfile}
+ os.vrunv(compinst:program(), table.join(compinst:compflags({target = target}), common_args, args), {envs = vcvars})
+ common.localcache():set2(headerunit.name, "building", false)
+ end
end, {dependfile = target:dependfile(bmifile), files = {headerunit.path}})
end, {rootjob = opt.rootjob})
diff --git a/xmake/rules/c++/modules/xmake.lua b/xmake/rules/c++/modules/xmake.lua
index 23f9a0f77..05d7a76e9 100644
--- a/xmake/rules/c++/modules/xmake.lua
+++ b/xmake/rules/c++/modules/xmake.lua
@@ -61,10 +61,16 @@ rule("c++.build.modules.builder")
import("modules_support.common")
local sourcebatch = target:sourcebatches()["c++.build.modules.builder"]
common.patch_sourcebatch(target, sourcebatch, opt)
+
+ -- generate headerunits
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()
+
+ -- append module mapper flags
+ local cache = common.localcache():get("mapflags") or {}
+ target:add("cxxflags", cache, {force = true})
end
return job or opt.rootjob
end, {batch = true})