summaryrefslogtreecommitdiff
path: root/xmake/rules/c++/modules
diff options
context:
space:
mode:
authorruki <[email protected]>2022-08-28 00:19:18 +0800
committerGitHub <[email protected]>2022-08-28 00:19:18 +0800
commitdb8df9d14e65c427cd9130280d910f2f60031029 (patch)
tree74cdb84b69c4feffdf81c8fb998d55de3c4ce47b /xmake/rules/c++/modules
parenteb9a71b929de0c144dad3d137c61297c908440c8 (diff)
parent15617ba485850dd33c2ff8c329a1c24f8631da9f (diff)
Merge pull request #2726 from xmake-io/modules
Improve modules and fix rule/before_build
Diffstat (limited to 'xmake/rules/c++/modules')
-rw-r--r--xmake/rules/c++/modules/modules_support/clang.lua2
-rw-r--r--xmake/rules/c++/modules/modules_support/common.lua38
-rw-r--r--xmake/rules/c++/modules/modules_support/msvc.lua12
-rw-r--r--xmake/rules/c++/modules/xmake.lua39
4 files changed, 29 insertions, 62 deletions
diff --git a/xmake/rules/c++/modules/modules_support/clang.lua b/xmake/rules/c++/modules/modules_support/clang.lua
index fb3a2d1fa..ea11cbe1c 100644
--- a/xmake/rules/c++/modules/modules_support/clang.lua
+++ b/xmake/rules/c++/modules/modules_support/clang.lua
@@ -153,7 +153,7 @@ function generate_dependencies(target, sourcebatch, opt)
changed = true
local dependinfo = io.readfile(jsonfile)
- return { moduleinfo = dependinfo }
+ return {moduleinfo = dependinfo}
end, {dependfile = dependfile, files = {sourcefile}})
end
return changed
diff --git a/xmake/rules/c++/modules/modules_support/common.lua b/xmake/rules/c++/modules/modules_support/common.lua
index 92c92d465..ae1b1ca9e 100644
--- a/xmake/rules/c++/modules/modules_support/common.lua
+++ b/xmake/rules/c++/modules/modules_support/common.lua
@@ -459,41 +459,15 @@ function get_module_dependencies(target, sourcebatch, opt)
return modules
end
--- generate headerunits for batchjobs
-function generate_headerunits_for_batchjobs(target, batchjobs, sourcebatch, modules, opt)
-
- -- get headerunits info
- local headerunits, stl_headerunits = get_headerunits(target, sourcebatch, modules)
-
- -- generate headerunits
- -- build stl header units as other headerunits may need them
- local headerunits_flags
- if stl_headerunits then
- headerunits_flags = headerunits_flags or {}
- table.join2(headerunits_flags, modules_support(target).generate_stl_headerunits_for_batchjobs(target, batchjobs, stl_headerunits, opt))
- end
- if headerunits then
- headerunits_flags = headerunits_flags or {}
- table.join2(headerunits_flags, modules_support(target).generate_user_headerunits_for_batchjobs(target, batchjobs, headerunits, opt))
- end
- return headerunits_flags
-end
-
-- generate headerunits for batchcmds
function generate_headerunits_for_batchcmds(target, batchcmds, sourcebatch, modules, opt)
-
- -- get headerunits info
local user_headerunits, stl_headerunits = get_headerunits(target, sourcebatch, modules)
-
- -- generate headerunits
-- build stl header units as other headerunits may need them
- if stl_headerunits or user_headerunits then
- if stl_headerunits then
- modules_support(target).generate_stl_headerunits_for_batchcmds(target, batchcmds, stl_headerunits, opt)
- end
- if user_headerunits then
- modules_support(target).generate_user_headerunits_for_batchcmds(target, batchcmds, user_headerunits, opt)
- end
+ if stl_headerunits then
+ modules_support(target).generate_stl_headerunits_for_batchcmds(target, batchcmds, stl_headerunits, opt)
+ end
+ if user_headerunits then
+ modules_support(target).generate_user_headerunits_for_batchcmds(target, batchcmds, user_headerunits, opt)
end
end
@@ -553,7 +527,7 @@ end
function append_dependency_objectfiles(target)
local cachekey = target:name() .. "dependency_objectfiles"
local cache = localcache():get(cachekey)
- if cache then
+ if cache then
if target:is_binary() then
target:add("ldflags", cache, {force = true})
elseif target:is_static() then
diff --git a/xmake/rules/c++/modules/modules_support/msvc.lua b/xmake/rules/c++/modules/modules_support/msvc.lua
index f7dc7451c..4439a578e 100644
--- a/xmake/rules/c++/modules/modules_support/msvc.lua
+++ b/xmake/rules/c++/modules/modules_support/msvc.lua
@@ -154,7 +154,7 @@ end
-- generate header unit module bmi for batchjobs
function generate_headerunit_for_batchjob(target, name, flags, objectfile, index, total)
-- don't generate same header unit bmi at the same time across targets
- if not common.memcache():get2(name, "generating") then
+ if not common.memcache():get2(name, "generating") then
local compinst = target:compiler("cxx")
local toolchain = target:toolchain("msvc")
local vcvars = toolchain:config("vcvars")
@@ -234,7 +234,7 @@ function generate_stl_headerunits_for_batchcmds(target, batchcmds, headerunits,
local bmifile = path.join(stlcachedir, headerunit.name .. get_bmi_extension())
local objectfile = bmifile .. ".obj"
local flags = {
- exportheaderflag,
+ exportheaderflag,
headernameflag .. ":angle",
headerunit.name,
ifcoutputflag,
@@ -429,14 +429,6 @@ function build_modules_for_batchjobs(target, batchjobs, objectfiles, modules, op
deps = table.keys(module.requires),
sourcefile = module.cppfile,
job = batchjobs:newjob(module.cppfile, function(index, total)
- function contains(t, v)
- for _, flag in ipairs(t) do
- if table.contains(flag, v) then
- return true
- end
- end
- return false
- end
-- append module mapper flags
-- @note we add it at the end to ensure that the full modulemap are already stored in the mapper
local requiresflags = get_requiresflags(target, module.requires)
diff --git a/xmake/rules/c++/modules/xmake.lua b/xmake/rules/c++/modules/xmake.lua
index 062dea52b..4a7193710 100644
--- a/xmake/rules/c++/modules/xmake.lua
+++ b/xmake/rules/c++/modules/xmake.lua
@@ -52,32 +52,33 @@ rule("c++.build.modules.builder")
set_sourcekinds("cxx")
set_extensions(".mpp", ".mxx", ".cppm", ".ixx")
- -- 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)
-
- -- 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()
- 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 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)
+
+ -- build modules
common.build_modules_for_batchjobs(target, batchjobs, sourcebatch, modules, opt)
+
+ -- generate headerunits and we need do it before building modules
+ local user_headerunits, stl_headerunits = common.get_headerunits(target, sourcebatch, modules)
+ if user_headerunits or stl_headerunits then
+ -- we need new group(headerunits)
+ -- e.g. group(build_modules) -> group(headerunits)
+ opt.rootjob = batchjobs:group_leave() or opt.rootjob
+ batchjobs:group_enter(target:name() .. "/generate_headerunits", {rootjob = opt.rootjob})
+ local modules_support = common.modules_support(target)
+ if stl_headerunits then
+ -- build stl header units as other headerunits may need them
+ -- TODO maybe we need new group(build_modules) -> group(user_headerunits) -> group(stl_headerunits)
+ modules_support.generate_stl_headerunits_for_batchjobs(target, batchjobs, stl_headerunits, opt)
+ end
+ if user_headerunits then
+ modules_support.generate_user_headerunits_for_batchjobs(target, batchjobs, user_headerunits, opt)
+ end
+ end
else
-- avoid duplicate linking of object files of non-module programs
sourcebatch.objectfiles = {}