diff options
| author | ruki <[email protected]> | 2025-09-09 13:53:02 +0800 |
|---|---|---|
| committer | GitHub <[email protected]> | 2025-09-09 13:53:02 +0800 |
| commit | e115e55c064eb6b475914989ea4d5fbaa9f4f83c (patch) | |
| tree | e8f223786841a106c686d244dda6291ed4ad48ed /xmake/rules/c++/modules | |
| parent | 30f935da29e7e003b2cea2c26a4be59020fe1b47 (diff) | |
| parent | 736bc53d54e12a508af4a4bec77049a1929984c7 (diff) | |
Merge pull request #6744 from Arthapz/hide-dependency-flags2
feat(C++ modules support) use a file for requires flags when --verbose or --diagnosis is supplied
Diffstat (limited to 'xmake/rules/c++/modules')
| -rw-r--r-- | xmake/rules/c++/modules/clang/builder.lua | 47 | ||||
| -rw-r--r-- | xmake/rules/c++/modules/msvc/builder.lua | 37 | ||||
| -rw-r--r-- | xmake/rules/c++/modules/support.lua | 12 |
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..a43c8aebe 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() |
