summaryrefslogtreecommitdiff
path: root/xmake/rules/c++/modules
diff options
context:
space:
mode:
authorArthur LAURENT <[email protected]>2025-08-25 12:48:58 +0200
committerArthur LAURENT <[email protected]>2025-08-25 12:48:58 +0200
commit0f3fd89593450c21b2fb75e89950f47f9a85202e (patch)
treeb1c3081753ea4e814a45812c24a284b34a04b30e /xmake/rules/c++/modules
parent57a0f0e067544e6d4767a4fa37102ce949d465e3 (diff)
feat(C++ modules support) use a file for requires files when --verbose or --diagnosis is supplied
Diffstat (limited to 'xmake/rules/c++/modules')
-rw-r--r--xmake/rules/c++/modules/clang/builder.lua47
-rw-r--r--xmake/rules/c++/modules/msvc/builder.lua37
-rw-r--r--xmake/rules/c++/modules/support.lua12
3 files changed, 80 insertions, 16 deletions
diff --git a/xmake/rules/c++/modules/clang/builder.lua b/xmake/rules/c++/modules/clang/builder.lua
index df65bb213..2a5b85fc6 100644
--- a/xmake/rules/c++/modules/clang/builder.lua
+++ b/xmake/rules/c++/modules/clang/builder.lua
@@ -104,6 +104,24 @@ function _make_headerunitflags(target, headerunit)
return flags
end
+
+function _get_mapper_str(target, module, opt)
+ local mapper_str
+ if target:policy("build.c++.modules.hide_dependencies") and option.get("diagnosis") then
+ if not opt.headerunit then
+ local requires_flagsfile = target:autogenfile(module.sourcefile .. ".requiresflags.txt")
+ if os.isfile(requires_flagsfile) then
+ if module.name then
+ mapper_str = format("\n${dim color.warning}mapper file for %s (%s) --------\n%s\n--------", module.name, module.sourcefile, io.readfile(requires_flagsfile):trim())
+ else
+ mapper_str = format("\n${dim color.warning}mapper file for %s --------\n%s\n--------", module.sourcefile, io.readfile(requires_flagsfile):trim())
+ end
+ end
+ end
+ end
+ return mapper_str
+end
+
-- do compile
function _compile(target, flags, module, opt)
@@ -119,7 +137,7 @@ function _compile(target, flags, module, opt)
if option.get("verbose") then
cmd = "\n" .. compinst:compcmd(sourcefile, outputfile, {target = target, compflags = flags, sourcekind = "cxx", rawargs = true})
end
- show_progress(target, module, table.join(opt, {cmd = cmd}))
+ show_progress(target, module, table.join(opt, {cmd = cmd, suffix = _get_mapper_str(target, module, opt)}))
-- do compile
if not dryrun then
@@ -142,7 +160,7 @@ function _batchcmds_compile(batchcmds, target, flags, module, opt)
if option.get("verbose") then
cmd = "\n" .. compinst:compcmd(sourcefile, outputfile, {target = target, compflags = flags, sourcekind = "cxx", rawargs = true})
end
- show_progress(target, module, table.join(opt, {cmd = cmd, batchcmds = batchcmds}))
+ show_progress(target, module, table.join(opt, {cmd = cmd, batchcmds = batchcmds, suffix = _get_mapper_str(target, module, opt)}))
-- do compile
batchcmds:compilev(flags, {compiler = compinst, sourcekind = "cxx", verbose = false})
@@ -194,15 +212,28 @@ end
function _append_requires_flags(target, module)
local cxxflags = {}
local requiresflags = _get_requiresflags(target, module)
- for _, flag in ipairs(requiresflags) do
- -- we need to wrap flag to support flag with space
- if type(flag) == "string" and flag:find(" ", 1, true) then
- table.insert(cxxflags, {flag})
+ local hide_dependencies = target:policy("build.c++.modules.hide_dependencies")
+ if #requiresflags> 0 then
+ for _, flag in ipairs(requiresflags) do
+ -- we need to wrap flag to support flag with space
+ if type(flag) == "string" and flag:find(" ", 1, true) and not hide_dependencies then
+ table.insert(cxxflags, {flag})
+ else
+ if hide_dependencies then
+ table.insert(cxxflags, '"' .. path.unix(flag) .. '"')
+ else
+ table.insert(cxxflags, flag)
+ end
+ end
+ end
+ if hide_dependencies then
+ local requires_flagsfile = target:autogenfile(module.sourcefile .. ".requiresflags.txt")
+ io.writefile(requires_flagsfile, path.unix(table.concat(cxxflags, "\n")))
+ target:fileconfig_add(module.sourcefile, {force = {cxxflags = {{"@" .. requires_flagsfile}}}})
else
- table.insert(cxxflags, flag)
+ target:fileconfig_add(module.sourcefile, {force = {cxxflags = cxxflags}})
end
end
- target:fileconfig_add(module.sourcefile, {force = {cxxflags = cxxflags}})
end
function append_requires_flags(target, built_modules)
diff --git a/xmake/rules/c++/modules/msvc/builder.lua b/xmake/rules/c++/modules/msvc/builder.lua
index 44519695d..b59115477 100644
--- a/xmake/rules/c++/modules/msvc/builder.lua
+++ b/xmake/rules/c++/modules/msvc/builder.lua
@@ -102,6 +102,23 @@ function _make_headerunitflags(target, headerunit, headertype)
return flags
end
+function _get_mapper_str(target, module, opt)
+ local mapper_str
+ if target:policy("build.c++.modules.hide_dependencies") and option.get("diagnosis") then
+ if not opt.headerunit then
+ local requires_flagsfile = target:autogenfile(module.sourcefile .. ".requiresflags.txt")
+ if os.isfile(requires_flagsfile) then
+ if module.name then
+ mapper_str = format("\n${dim color.warning}mapper file for %s (%s) --------\n%s\n--------", module.name, module.sourcefile, io.readfile(requires_flagsfile):trim())
+ else
+ mapper_str = format("\n${dim color.warning}mapper file for %s --------\n%s\n--------", module.sourcefile, io.readfile(requires_flagsfile):trim())
+ end
+ end
+ end
+ end
+ return mapper_str
+end
+
-- do compile
function _compile(target, flags, module, opt)
opt = opt or {}
@@ -121,7 +138,7 @@ function _compile(target, flags, module, opt)
cmd = "\n" .. compinst:compcmd(sourcefile, outputfile, {target = target, compflags = flags, sourcekind = "cxx", rawargs = true})
end
end
- show_progress(target, module, table.join(opt, {cmd = cmd}))
+ show_progress(target, module, table.join(opt, {cmd = cmd, suffix = _get_mapper_str(target, module, opt)}))
-- do compile
if not dryrun then
@@ -148,7 +165,7 @@ function _batchcmds_compile(batchcmds, target, flags, module, opt)
cmd = "\n" .. compinst:compcmd(sourcefile, outputfile, {target = target, compflags = flags, sourcekind = "cxx", rawargs = true})
end
end
- show_progress(target, module, table.join(opt, {cmd = cmd, batchcmds = batchcmds}))
+ show_progress(target, module, table.join(opt, {cmd = cmd, batchcmds = batchcmds, suffit = _get_mapper_str(target, module, opt)}))
-- do compile
batchcmds:compilev(flags, {compiler = compinst, sourcekind = "cxx", verbose = false})
@@ -215,8 +232,20 @@ function _get_requiresflags(target, module)
end
function _append_requires_flags(target, module)
- local requiresflags = _get_requiresflags(target, module)
- target:fileconfig_add(module.sourcefile, {force = {cxxflags = requiresflags}})
+ local cxxflags = _get_requiresflags(target, module)
+ if #cxxflags > 0 then
+ if target:policy("build.c++.modules.hide_dependencies") then
+ local _cxxflags = {}
+ for _, flag in ipairs(cxxflags) do
+ table.insert(_cxxflags, flag[1] .. ' "' .. path.unix(flag[2]) .. '"')
+ end
+ local requires_flagsfile = target:autogenfile(module.sourcefile .. ".requiresflags.txt")
+ io.writefile(requires_flagsfile, table.concat(_cxxflags, "\n"))
+ target:fileconfig_add(module.sourcefile, {force = {cxxflags = {{"@" .. requires_flagsfile}}}})
+ else
+ target:fileconfig_add(module.sourcefile, {force = {cxxflags = cxxflags}})
+ end
+ end
end
function append_requires_flags(target, built_modules)
diff --git a/xmake/rules/c++/modules/support.lua b/xmake/rules/c++/modules/support.lua
index 29fc92fb0..ef1d1f9dd 100644
--- a/xmake/rules/c++/modules/support.lua
+++ b/xmake/rules/c++/modules/support.lua
@@ -76,10 +76,14 @@ end
-- strip flags not relevent for module reuse
function strip_flags(target, flags, opt)
- local strippeable_flags, splitted_strippeable_flags = _support(target).strippeable_flags()
-
- if opt and opt.strip_defines then
- table.join2(splitted_strippeable_flags, {"D", "U"})
+ local strippeable_flags, splitted_strippeable_flags
+ if not opt.requiresonly then
+ strippeable_flags, splitted_strippeable_flags = _support(target).strippeable_flags()
+ if opt and opt.strip_defines then
+ table.join2(splitted_strippeable_flags, {"D", "U"})
+ end
+ else
+ strippeable_flags, splitted_strippeable_flags = _support(target).require_flags()
end
local splitted_strippeable_flags_set = hashset.new()