summaryrefslogtreecommitdiff
path: root/xmake/rules/c++/modules/modules_support
diff options
context:
space:
mode:
authorArthur LAURENT <[email protected]>2024-01-31 13:01:40 +0100
committerArthur LAURENT <[email protected]>2024-01-31 13:01:40 +0100
commitf3ec9cc0f7cf6d0b48dce8a69c5f6103b9dd6df3 (patch)
treeef053b0f6d8642ac4dd97d7d151557ebff97f0f0 /xmake/rules/c++/modules/modules_support
parent95996d7b59b420f9bc6b9f8e817e48d6be183acc (diff)
implement missing headerunit aliasing
Diffstat (limited to 'xmake/rules/c++/modules/modules_support')
-rw-r--r--xmake/rules/c++/modules/modules_support/builder.lua27
-rw-r--r--xmake/rules/c++/modules/modules_support/clang/builder.lua56
-rw-r--r--xmake/rules/c++/modules/modules_support/gcc/builder.lua19
-rw-r--r--xmake/rules/c++/modules/modules_support/msvc/builder.lua18
4 files changed, 80 insertions, 40 deletions
diff --git a/xmake/rules/c++/modules/modules_support/builder.lua b/xmake/rules/c++/modules/modules_support/builder.lua
index b17bb73b3..5c2ec113f 100644
--- a/xmake/rules/c++/modules/modules_support/builder.lua
+++ b/xmake/rules/c++/modules/modules_support/builder.lua
@@ -167,18 +167,13 @@ function _target_module_map_cachekey(target)
return target:name() .. "module_mapper" .. (mode or "")
end
-function _is_duplicated_headerunit(target, headerunit)
+function _is_duplicated_headerunit(target, key)
local mapper = get_target_module_mapper(target)
- local key = hash.md5(path.normalize(headerunit.path))
-
- -- for _, mapped in pairs(mapper) do
- -- print("CHECK", mapped.key, key)
- -- if mapped.key == key then
- -- return true
- -- end
- -- end
-
- return false
+ for _, mapped in pairs(mapper) do
+ if mapped.key == key then
+ return mapped
+ end
+ end
end
function _builder(target)
@@ -363,7 +358,13 @@ end
-- add a headerunit to target mapper
function add_headerunit_to_target_mapper(target, headerunit, bmifile)
local mapper = get_target_module_mapper(target)
- mapper[headerunit.name] = {name = headerunit.name, key = path.normalize(headerunit.path), headerunit = headerunit, bmi = bmifile}
- return _is_duplicated_headerunit(target, headerunit)
+ local key = hash.uuid(path.normalize(headerunit.path))
+ local deduplicated = _is_duplicated_headerunit(target, key)
+ if deduplicated then
+ mapper[headerunit.name] = {name = headerunit.name, key = key, aliasof = deduplicated.name}
+ else
+ mapper[headerunit.name] = {name = headerunit.name, key = key, headerunit = headerunit, bmi = bmifile}
+ end
+ return deduplicated and true or false
end
diff --git a/xmake/rules/c++/modules/modules_support/clang/builder.lua b/xmake/rules/c++/modules/modules_support/clang/builder.lua
index 1b414215f..6a2893ea9 100644
--- a/xmake/rules/c++/modules/modules_support/clang/builder.lua
+++ b/xmake/rules/c++/modules/modules_support/clang/builder.lua
@@ -134,7 +134,15 @@ function _get_requiresflags(target, module, opt)
assert(dep_module, "module dependency %s required for %s not found", required, name)
- local bmifile = dep_module.bmi
+ local bmifile
+ -- aliased headerunit
+ if dep_module.aliasof then
+ local aliased = get_from_target_mapper(target, dep_module.aliasof)
+ bmifile = aliased.bmi
+ -- named module or headerunit
+ else
+ bmifile = dep_module.bmi
+ end
local mapflag = (dep_module.opt and dep_module.opt.namedmodule) and format("%s%s=%s", modulefileflag, required, bmifile) or modulefileflag .. bmifile
table.insert(requiresflags, mapflag)
@@ -286,32 +294,34 @@ end
-- build headerunit file for batchjobs
function make_headerunit_build_job(target, job_name, batchjobs, headerunit, bmifile, outputdir, opt)
- add_headerunit_to_target_mapper(target, headerunit, bmifile)
- return {
- name = job_name,
- sourcefile = headerunit.path,
- job = batchjobs:newjob(job_name, function(index, total)
- if not os.isdir(outputdir) then
- os.mkdir(outputdir)
- end
+ local already_exists = add_headerunit_to_target_mapper(target, headerunit, bmifile)
+ if not already_exists then
+ return {
+ name = job_name,
+ sourcefile = headerunit.path,
+ job = batchjobs:newjob(job_name, function(index, total)
+ if not os.isdir(outputdir) then
+ os.mkdir(outputdir)
+ end
- local compinst = compiler.load("cxx", {target = target})
- local compflags = compinst:compflags({sourcefile = headerunit.path, target = target})
+ local compinst = compiler.load("cxx", {target = target})
+ local compflags = compinst:compflags({sourcefile = headerunit.path, target = target})
- local dependfile = target:dependfile(bmifile)
- local dependinfo = depend.load(dependfile) or {}
- dependinfo.files = {}
- local depvalues = {compinst:program(), compflags}
+ local dependfile = target:dependfile(bmifile)
+ local dependinfo = depend.load(dependfile) or {}
+ dependinfo.files = {}
+ local depvalues = {compinst:program(), compflags}
- if opt.build then
- progress.show((index * 100) / total, "${color.build.target}<%s> ${clear}${color.build.object}compiling.headerunit.$(mode) %s", target:name(), headerunit.name)
- _compile(target, _make_headerunitflags(target, headerunit, bmifile), headerunit.path)
- end
+ if opt.build then
+ progress.show((index * 100) / total, "${color.build.target}<%s> ${clear}${color.build.object}compiling.headerunit.$(mode) %s", target:name(), headerunit.name)
+ _compile(target, _make_headerunitflags(target, headerunit, bmifile), headerunit.path)
+ end
- table.insert(dependinfo.files, headerunit.path)
- dependinfo.values = depvalues
- depend.save(dependinfo, dependfile)
- end)}
+ table.insert(dependinfo.files, headerunit.path)
+ dependinfo.values = depvalues
+ depend.save(dependinfo, dependfile)
+ end)}
+ end
end
-- build headerunit file for batchcmds
diff --git a/xmake/rules/c++/modules/modules_support/gcc/builder.lua b/xmake/rules/c++/modules/modules_support/gcc/builder.lua
index 13755660d..19f5e813b 100644
--- a/xmake/rules/c++/modules/modules_support/gcc/builder.lua
+++ b/xmake/rules/c++/modules/modules_support/gcc/builder.lua
@@ -151,12 +151,27 @@ function _get_maplines(target, module)
assert(dep_module, "module dependency %s required for %s not found", required, name)
- local mapline = (dep_module.headerunit and dep_module.headerunit.path:replace("\\", "/") or required) .. " " .. dep_module.bmi:replace("\\", "/")
+ local bmifile
+ local mapline
+ -- aliased headerunit
+ if dep_module.aliasof then
+ local aliased = get_from_target_mapper(target, dep_module.aliasof)
+ bmifile = aliased.bmi
+ mapline = dep_module.headerunit.path:replace("\\", "/") .. " " bmifile:replace("\\", "/")
+ -- headerunit
+ elseif dep_module.headerunit then
+ bmifile = dep_module.bmi
+ mapline = dep_module.headerunit.path:replace("\\", "/") .. " " bmifile:replace("\\", "/")
+ -- named module
+ else
+ bmifile = dep_module.bmi
+ mapline = required .. " " .. bmifile:replace("\\", "/")
+ end
table.insert(maplines, mapline)
-- append deps
if dep_module.opt and dep_module.opt.deps then
- local deps = _get_maplines(dep_target, { name = dep_module.name, bmi = dep_module.bmifile, requires = dep_module.opt.deps })
+ local deps = _get_maplines(dep_target, { name = dep_module.name, bmi = bmifile, requires = dep_module.opt.deps })
table.join2(maplines, deps)
end
end
diff --git a/xmake/rules/c++/modules/modules_support/msvc/builder.lua b/xmake/rules/c++/modules/modules_support/msvc/builder.lua
index 8a77a7612..9b7bd330e 100644
--- a/xmake/rules/c++/modules/modules_support/msvc/builder.lua
+++ b/xmake/rules/c++/modules/modules_support/msvc/builder.lua
@@ -122,8 +122,22 @@ function _get_requiresflags(target, module, opt)
assert(dep_module, "module dependency %s required for %s not found <%s>", required, name, target:name())
- local bmifile = dep_module.bmi
- local mapflag = {dep_module.headerunit and headerunitflag .. dep_module.headerunit.type or referenceflag, required .. "=" .. bmifile}
+ local mapflag
+ local bmifile
+ -- aliased headerunit
+ if dep_module.aliasof then
+ local aliased = get_from_target_mapper(target, dep_module.aliasof)
+ bmifile = aliased.bmi
+ mapflag = {headerunitflag .. aliased.headerunit.type, required .. "=" .. bmifile}
+ -- headerunit
+ elseif dep_module.headerunit then
+ bmifile = dep_module.bmi
+ mapflag = {headerunitflag .. dep_module.headerunit.type, required .. "=" .. bmifile}
+ -- named module
+ else
+ bmifile = dep_module.bmi
+ mapflag = {referenceflag, required .. "=" .. bmifile}
+ end
table.insert(deps_flags, mapflag)
-- append deps