From 8a00ad8b7c0697d549129b2d09914606d1525361 Mon Sep 17 00:00:00 2001 From: Arthur LAURENT Date: Fri, 2 Dec 2022 23:47:45 +0100 Subject: minor refactor and improvements to C++ module build --- xmake/rules/c++/modules/modules_support/msvc.lua | 69 ++++++------------------ 1 file changed, 15 insertions(+), 54 deletions(-) (limited to 'xmake/rules/c++/modules/modules_support/msvc.lua') diff --git a/xmake/rules/c++/modules/modules_support/msvc.lua b/xmake/rules/c++/modules/modules_support/msvc.lua index 092e23c24..d3c35e7c8 100644 --- a/xmake/rules/c++/modules/modules_support/msvc.lua +++ b/xmake/rules/c++/modules/modules_support/msvc.lua @@ -101,51 +101,10 @@ function _build_modulefile(target, sourcefile, opt) end -- init flags - local requiresflags = opt.requiresflags - local flags = table.join("-TP", requiresflags or {}, compflags) + local flags = table.join("-TP", compflags, opt.flags or {}) -- trace - progress.show(opt.progress, "${color.build.object}build.cxx.module %s", sourcefile) - vprint(compinst:compcmd(sourcefile, objectfile, {compflags = flags, rawargs = true})) - - if not dryrun then - - -- do compile - dependinfo.files = {} - assert(compinst:compile(sourcefile, objectfile, {dependinfo = dependinfo, compflags = flags})) - - -- update files and values to the dependent file - dependinfo.values = depvalues - table.join2(dependinfo.files, sourcefile) - depend.save(dependinfo, dependfile) - end -end - --- build interface module file -function _build_interfacemodulefile(target, sourcefile, opt) - local objectfile = opt.objectfile - local dependfile = opt.dependfile - local compinst = compiler.load("cxx", {target = target}) - local compflags = compinst:compflags({target = target}) - local dependinfo = option.get("rebuild") and {} or (depend.load(dependfile) or {}) - - -- need build this object? - local dryrun = option.get("dry-run") - local depvalues = {compinst:program(), compflags} - local lastmtime = os.isfile(objectfile) and os.mtime(dependfile) or 0 - if not dryrun and not depend.is_changed(dependinfo, {lastmtime = lastmtime, values = depvalues}) then - return - end - - -- init flags - local requiresflags = opt.requiresflags - local interfaceflag = opt.interfaceflag - local ifcoutputflag = opt.ifcoutputflag - local bmifile = opt.bmifile - local flags = table.join("-TP", requiresflags or {}, interfaceflag, ifcoutputflag, bmifile, compflags) - - -- trace - progress.show(opt.progress, "${color.build.object}generating.cxx.module.bmi %s", opt.name) + progress.show(opt.progress, "${color.build.object}compiling.module.$(mode) %s", opt.name) vprint(compinst:compcmd(sourcefile, objectfile, {compflags = flags, rawargs = true})) if not dryrun then @@ -217,7 +176,7 @@ function generate_dependencies(target, sourcebatch, opt) local dependfile = target:dependfile(sourcefile) depend.on_changed(function () if opt.progress then - progress.show(opt.progress, "${color.build.object}generating.cxx.module.deps %s", sourcefile) + progress.show(opt.progress, "${color.build.object}generating.module.deps %s", sourcefile) end local outputdir = path.join(cachedir, path.directory(path.relative(sourcefile, projectdir))) if not os.isdir(outputdir) then @@ -276,7 +235,7 @@ function generate_headerunit_for_batchjob(target, name, flags, objectfile, index if not common.memcache():get2(name, "generating") then local common_flags = {"-TP", "-c"} common.memcache():set2(name, "generating", true) - progress.show((index * 100) / total, "${color.build.object}generating.cxx.headerunit.bmi %s", name) + progress.show((index * 100) / total, "${color.build.object}compiling.headerunit.$(mode) %s", name) _compile(target, table.join(common_flags, flags)) _add_objectfile_to_link_arguments(target, objectfile) end @@ -287,7 +246,7 @@ function generate_headerunit_for_batchcmds(target, name, flags, objectfile, batc local compinst = target:compiler("cxx") local msvc = target:toolchain("msvc") local common_flags = {"-TP", "-c"} - batchcmds:show_progress(opt.progress, "${color.build.object}generating.cxx.headerunit.bmi %s", name) + batchcmds:show_progress(opt.progress, "${color.build.object}compiling.headerunit.$(mode) %s", name) batchcmds:vrunv(compinst:program(), table.join(compinst:compflags({target = target}), common_flags, flags), {envs = msvc:runenvs()}) _add_objectfile_to_link_arguments(target, objectfile) end @@ -508,14 +467,15 @@ function build_modules_for_batchjobs(target, batchjobs, objectfiles, modules, op requiresflags = get_requiresflags(target, module.requires, {expand = true}) end - _build_interfacemodulefile(target, provide.sourcefile, { + local flags = {ifcoutputflag, bmifile} + table.join2(flags, requiresflags or {}) + table.join2(flags, provide.interface and interfaceflag or {}) + + _build_modulefile(target, provide.sourcefile, { objectfile = objectfile, dependfile = target:dependfile(bmifile), name = name, - bmifile = bmifile, - requiresflags = requiresflags, - interfaceflag = interfaceflag, - ifcoutputflag = ifcoutputflag, + flags = flags, progress = (index * 100) / total}) _add_module_to_mapper(target, referenceflag, name, name, objectfile, bmifile, requiresflags) @@ -541,7 +501,8 @@ function build_modules_for_batchjobs(target, batchjobs, objectfiles, modules, op _build_modulefile(target, module.cppfile, { objectfile = objectfile, dependfile = target:dependfile(objectfile), - requiresflags = requiresflags, + name = module.cppfile, + flags = requiresflags or {}, progress = (index * 100) / total}) target:add("objectfiles", objectfile) elseif requiresflags then @@ -597,7 +558,7 @@ function build_modules_for_batchcmds(target, batchcmds, objectfiles, modules, op ifcoutputflag, path(bmifile), path(provide.sourcefile)} - batchcmds:show_progress(opt.progress, "${color.build.object}generating.cxx.module.bmi %s", name) + batchcmds:show_progress(opt.progress, "${color.build.object}compiling.module.$(mode) %s", name) batchcmds:mkdir(path.directory(objectfile)) batchcmds:vrunv(compinst:program(), table.join(compinst:compflags({target = target}), common_flags, requiresflags or {}, flags), {envs = msvc:runenvs()}) batchcmds:add_depfiles(provide.sourcefile) @@ -614,7 +575,7 @@ function build_modules_for_batchcmds(target, batchcmds, objectfiles, modules, op local flags = {"-c", path(objectfile, function (p) return "-Fo" .. p end), path(module.cppfile)} - batchcmds:show_progress(opt.progress, "${color.build.object}build.cxx.module %s", module.cppfile) + batchcmds:show_progress(opt.progress, "${color.build.object}compiling.module.$(mode) %s", module.cppfile) batchcmds:mkdir(path.directory(objectfile)) batchcmds:vrunv(compinst:program(), table.join(compinst:compflags({target = target}), requiresflags or {}, flags), {envs = msvc:runenvs()}) batchcmds:add_depfiles(module.cppfile) -- cgit v1.3.1 From 919115f8faab05b6915dbe336720e2d7cbc42671 Mon Sep 17 00:00:00 2001 From: Arthur LAURENT Date: Fri, 2 Dec 2022 23:47:45 +0100 Subject: minor refactor and improvements to C++ module build --- xmake/rules/c++/modules/modules_support/clang.lua | 18 +++--- xmake/rules/c++/modules/modules_support/common.lua | 3 +- xmake/rules/c++/modules/modules_support/gcc.lua | 52 ++++------------ xmake/rules/c++/modules/modules_support/msvc.lua | 69 +++++----------------- 4 files changed, 36 insertions(+), 106 deletions(-) (limited to 'xmake/rules/c++/modules/modules_support/msvc.lua') diff --git a/xmake/rules/c++/modules/modules_support/clang.lua b/xmake/rules/c++/modules/modules_support/clang.lua index ad32931de..69419b4e2 100644 --- a/xmake/rules/c++/modules/modules_support/clang.lua +++ b/xmake/rules/c++/modules/modules_support/clang.lua @@ -154,7 +154,7 @@ function _build_modulefile(target, sourcefile, opt) local flags = table.join({"-x", "c++"}, requiresflags or {}, compflags) -- trace - progress.show(opt.progress, "${color.build.object}build.cxx.module %s", sourcefile) + progress.show(opt.progress, "${color.build.object}compiling.module.$(mode) %s", sourcefile) vprint(compinst:compcmd(sourcefile, objectfile, {compflags = flags, rawargs = true})) if not dryrun then @@ -193,7 +193,7 @@ function _build_interfacemodulefile(target, sourcefile, opt) local objflags = table.join(compflags, common_args, requiresflags or {}) -- trace - progress.show(opt.progress, "${color.build.object}generating.cxx.module.bmi %s", opt.name) + progress.show(opt.progress, "${color.build.object}compiling.module.$(mode) %s", opt.name) vprint(compinst:compcmd(sourcefile, bmifile, {compflags = bmiflags, rawargs = true})) vprint(compinst:compcmd(bmifile, objectfile, {compflags = objflags, rawargs = true})) @@ -243,7 +243,7 @@ function generate_dependencies(target, sourcebatch, opt) local dependfile = target:dependfile(sourcefile) depend.on_changed(function() if opt.progress then - progress.show(opt.progress, "${color.build.object}generating.cxx.module.deps %s", sourcefile) + progress.show(opt.progress, "${color.build.object}generating.module.deps %s", sourcefile) end local outputdir = path.translate(path.join(cachedir, path.directory(path.relative(sourcefile, projectdir)))) @@ -311,7 +311,7 @@ function generate_stl_headerunits_for_batchjobs(target, batchjobs, headerunits, -- don't build same header unit at the same time if not common.memcache():get2(headerunit.name, "building") then common.memcache():set2(headerunit.name, "building", true) - progress.show((index * 100) / total, "${color.build.object}generating.cxx.headerunit.bmi %s", headerunit.name) + progress.show((index * 100) / total, "${color.build.object}compiling.headerunit.$(mode) %s", headerunit.name) local args = {modulecachepathflag .. stlcachedir, "-c", "-o", bmifile, "-x", "c++-system-header", headerunit.name} os.vrunv(compinst:program(), table.join(compinst:compflags({target = target}), args)) end @@ -344,7 +344,7 @@ function generate_stl_headerunits_for_batchcmds(target, batchcmds, headerunits, local args = { path(stlcachedir, function (p) return modulecachepathflag .. p end), "-c", "-o", path(bmifile), "-x", "c++-system-header", headerunit.name} - batchcmds:show_progress(opt.progress, "${color.build.object}generating.cxx.headerunit.bmi %s", headerunit.name) + batchcmds:show_progress(opt.progress, "${color.build.object}compiling.headerunit.$(mode) %s", headerunit.name) batchcmds:vrunv(compinst:program(), table.join(compinst:compflags({target = target}), args)) end -- libc++ have a builtin module mapper @@ -387,7 +387,7 @@ function generate_user_headerunits_for_batchjobs(target, batchjobs, headerunits, local bmifile = (outputdir and path.join(outputdir, bmifilename) or 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) + progress.show((index * 100) / total, "${color.build.object}compiling.headerunit.$(mode) %s", headerunit.name) local objectdir = path.directory(objectfile) if not os.isdir(objectdir) then os.mkdir(objectdir) @@ -446,7 +446,7 @@ function generate_user_headerunits_for_batchcmds(target, batchcmds, headerunits, table.join2(args, {"-x", "c++-system-header", headerunit.name}) end - batchcmds:show_progress(opt.progress, "${color.build.object}generating.cxx.headerunit.bmi %s", headerunit.name) + batchcmds:show_progress(opt.progress, "${color.build.object}compiling.headerunit.$(mode) %s", headerunit.name) batchcmds:vrunv(compinst:program(), table.join(compinst:compflags({target = target}), args)) batchcmds:add_depfiles(headerunit.path) @@ -576,7 +576,7 @@ function build_modules_for_batchcmds(target, batchcmds, objectfiles, modules, op if module.requires then requiresflags = get_requiresflags(target, module.requires) end - batchcmds:show_progress(opt.progress, "${color.build.object}generating.cxx.module.bmi %s", name) + batchcmds:show_progress(opt.progress, "${color.build.object}compiling.module.$(mode) %s", name) batchcmds:mkdir(path.directory(objectfile)) batchcmds:vrunv(compinst:program(), table.join(compinst:compflags({target = target}), common_args, requiresflags or {}, args)) batchcmds:vrunv(compinst:program(), table.join(compinst:compflags({target = target}), common_args, requiresflags or {}, path(bmifile), {"-c", "-o", path(objectfile)})) @@ -591,7 +591,7 @@ function build_modules_for_batchcmds(target, batchcmds, objectfiles, modules, op if common.has_module_extension(module.cppfile) then local flags = {"-o", path(objectfile), "-c", path(module.cppfile)} - batchcmds:show_progress(opt.progress, "${color.build.object}build.cxx.module %s", module.cppfile) + batchcmds:show_progress(opt.progress, "${color.build.object}compiling.module.$(mode) %s", module.cppfile) batchcmds:mkdir(path.directory(objectfile)) batchcmds:vrunv(compinst:program(), table.join(compinst:compflags({target = target}), requiresflags or {}, flags)) batchcmds:add_depfiles(module.cppfile) diff --git a/xmake/rules/c++/modules/modules_support/common.lua b/xmake/rules/c++/modules/modules_support/common.lua index b21613f61..6401f1f5b 100644 --- a/xmake/rules/c++/modules/modules_support/common.lua +++ b/xmake/rules/c++/modules/modules_support/common.lua @@ -229,7 +229,8 @@ function _parse_dependencies_data(target, moduleinfos) name = name:replace(":", "-") m.provides[provide["logical-name"]] = { bmi = path.join(cachedir, name), - sourcefile = moduleinfo.sourcefile + sourcefile = moduleinfo.sourcefile, + interface = provide["is-interface"] } end end diff --git a/xmake/rules/c++/modules/modules_support/gcc.lua b/xmake/rules/c++/modules/modules_support/gcc.lua index 476bc6487..cbdf9b1bf 100644 --- a/xmake/rules/c++/modules/modules_support/gcc.lua +++ b/xmake/rules/c++/modules/modules_support/gcc.lua @@ -111,40 +111,7 @@ function _build_modulefile(target, sourcefile, opt) end -- trace - progress.show(opt.progress, "${color.build.object}build.cxx.module %s", sourcefile) - vprint(compinst:compcmd(sourcefile, objectfile, {compflags = compflags, rawargs = true})) - - if not dryrun then - - -- do compile - dependinfo.files = {} - assert(compinst:compile(sourcefile, objectfile, {dependinfo = dependinfo, compflags = compflags})) - - -- update files and values to the dependent file - dependinfo.values = depvalues - table.join2(dependinfo.files, sourcefile) - depend.save(dependinfo, dependfile) - end -end - --- build interface module file -function _build_interfacemodulefile(target, sourcefile, opt) - local objectfile = opt.objectfile - local dependfile = opt.dependfile - local compinst = compiler.load("cxx", {target = target}) - local compflags = table.join("-x", "c++", compinst:compflags({target = target})) - local dependinfo = option.get("rebuild") and {} or (depend.load(dependfile) or {}) - - -- need build this object? - local dryrun = option.get("dry-run") - local depvalues = {compinst:program(), compflags} - local lastmtime = os.isfile(objectfile) and os.mtime(dependfile) or 0 - if not dryrun and not depend.is_changed(dependinfo, {lastmtime = lastmtime, values = depvalues}) then - return - end - - -- trace - progress.show(opt.progress, "${color.build.object}generating.cxx.module.bmi %s", opt.name) + progress.show(opt.progress, "${color.build.object}compiling.module.$(mode) %s", opt.name) vprint(compinst:compcmd(sourcefile, objectfile, {compflags = compflags, rawargs = true})) if not dryrun then @@ -197,7 +164,7 @@ function generate_dependencies(target, sourcebatch, opt) local dependfile = target:dependfile(sourcefile) depend.on_changed(function() if opt.progress then - progress.show(opt.progress, "${color.build.object}generating.cxx.module.deps %s", sourcefile) + progress.show(opt.progress, "${color.build.object}generating.module.deps %s", sourcefile) end local outputdir = path.translate(path.join(cachedir, path.directory(path.relative(sourcefile, projectdir)))) @@ -264,7 +231,7 @@ function generate_stl_headerunits_for_batchjobs(target, batchjobs, headerunits, if not os.isfile(bmifile) 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) + progress.show((index * 100) / total, "${color.build.object}compiling.headerunit.$(mode) %s", headerunit.name) local args = {"-c", "-x", "c++-system-header", headerunit.name} local flags = table.join(compinst:compflags({target = target}), args) -- we need to support reading and writing mapperfile in parallel, otherwise it will be broken @@ -302,7 +269,7 @@ function generate_stl_headerunits_for_batchcmds(target, batchcmds, headerunits, local bmifile = path.join(stlcachedir, headerunit.name .. get_bmi_extension()) if not os.isfile(bmifile) then local args = {"-c", "-x", "c++-system-header", headerunit.name} - batchcmds:show_progress(opt.progress, "${color.build.object}generating.cxx.headerunit.bmi %s", headerunit.name) + batchcmds:show_progress(opt.progress, "${color.build.object}compiling.headerunit.$(mode) %s", headerunit.name) batchcmds:vrunv(compinst:program(), table.join(compinst:compflags({target = target}), args)) end batchcmds:add_depfiles(headerunit.path) @@ -340,7 +307,7 @@ function generate_user_headerunits_for_batchjobs(target, batchjobs, headerunits, end 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) + progress.show((index * 100) / total, "${color.build.object}compiling.headerunit.$(mode) %s", headerunit.name) local objectdir = path.directory(objectfile) if not os.isdir(objectdir) then os.mkdir(objectdir) @@ -399,7 +366,7 @@ function generate_user_headerunits_for_batchcmds(target, batchcmds, headerunits, headerunit_path = path.is_absolute(headerunit.path) and headerunit.path or path.join(".", headerunit.path) end - batchcmds:show_progress(opt.progress, "${color.build.object}generating.cxx.headerunit.bmi %s", headerunit.name) + batchcmds:show_progress(opt.progress, "${color.build.object}compiling.headerunit.$(mode) %s", headerunit.name) batchcmds:vrunv(compinst:program(), table.join(compinst:compflags({target = target}), args)) batchcmds:add_depfiles(headerunit.path) @@ -436,7 +403,7 @@ function build_modules_for_batchjobs(target, batchjobs, objectfiles, modules, op local bmifile = provide.bmi local moduleinfo = table.copy(provide) moduleinfo.job = batchjobs:newjob(provide.sourcefile, function (index, total) - _build_interfacemodulefile(target, provide.sourcefile, { + _build_modulefile(target, provide.sourcefile, { objectfile = objectfile, dependfile = target:dependfile(bmifile), name = name, @@ -458,6 +425,7 @@ function build_modules_for_batchjobs(target, batchjobs, objectfiles, modules, op _build_modulefile(target, m.cppfile, { objectfile = objectfile, dependfile = target:dependfile(objectfile), + name = m.cppfile, progress = (index * 100) / total}) target:add("objectfiles", objectfile) end) @@ -498,7 +466,7 @@ function build_modules_for_batchcmds(target, batchcmds, objectfiles, modules, op local bmifile = provide.bmi local args = {"-o", path(objectfile), "-c", path(provide.sourcefile)} - batchcmds:show_progress(opt.progress, "${color.build.object}generating.cxx.module.bmi %s", name) + batchcmds:show_progress(opt.progress, "${color.build.object}compiling.module.$(mode) %s", name) batchcmds:mkdir(path.directory(objectfile)) batchcmds:vrunv(compinst:program(), table.join(compinst:compflags({target = target}), common_args, args)) batchcmds:add_depfiles(provide.sourcefile) @@ -507,7 +475,7 @@ function build_modules_for_batchcmds(target, batchcmds, objectfiles, modules, op depmtime = math.max(depmtime, os.mtime(bmifile)) elseif common.has_module_extension(m.cppfile) then local args = {"-o", path(objectfile), "-c", path(m.cppfile)} - batchcmds:show_progress(opt.progress, "${color.build.object}build.cxx.module %s", m.cppfile) + batchcmds:show_progress(opt.progress, "${color.build.object}compiling.module.$(mode) %s", m.cppfile) batchcmds:mkdir(path.directory(objectfile)) batchcmds:vrunv(compinst:program(), table.join(compinst:compflags({target = target}), args)) batchcmds:add_depfiles(m.cppfile) diff --git a/xmake/rules/c++/modules/modules_support/msvc.lua b/xmake/rules/c++/modules/modules_support/msvc.lua index 092e23c24..d3c35e7c8 100644 --- a/xmake/rules/c++/modules/modules_support/msvc.lua +++ b/xmake/rules/c++/modules/modules_support/msvc.lua @@ -101,51 +101,10 @@ function _build_modulefile(target, sourcefile, opt) end -- init flags - local requiresflags = opt.requiresflags - local flags = table.join("-TP", requiresflags or {}, compflags) + local flags = table.join("-TP", compflags, opt.flags or {}) -- trace - progress.show(opt.progress, "${color.build.object}build.cxx.module %s", sourcefile) - vprint(compinst:compcmd(sourcefile, objectfile, {compflags = flags, rawargs = true})) - - if not dryrun then - - -- do compile - dependinfo.files = {} - assert(compinst:compile(sourcefile, objectfile, {dependinfo = dependinfo, compflags = flags})) - - -- update files and values to the dependent file - dependinfo.values = depvalues - table.join2(dependinfo.files, sourcefile) - depend.save(dependinfo, dependfile) - end -end - --- build interface module file -function _build_interfacemodulefile(target, sourcefile, opt) - local objectfile = opt.objectfile - local dependfile = opt.dependfile - local compinst = compiler.load("cxx", {target = target}) - local compflags = compinst:compflags({target = target}) - local dependinfo = option.get("rebuild") and {} or (depend.load(dependfile) or {}) - - -- need build this object? - local dryrun = option.get("dry-run") - local depvalues = {compinst:program(), compflags} - local lastmtime = os.isfile(objectfile) and os.mtime(dependfile) or 0 - if not dryrun and not depend.is_changed(dependinfo, {lastmtime = lastmtime, values = depvalues}) then - return - end - - -- init flags - local requiresflags = opt.requiresflags - local interfaceflag = opt.interfaceflag - local ifcoutputflag = opt.ifcoutputflag - local bmifile = opt.bmifile - local flags = table.join("-TP", requiresflags or {}, interfaceflag, ifcoutputflag, bmifile, compflags) - - -- trace - progress.show(opt.progress, "${color.build.object}generating.cxx.module.bmi %s", opt.name) + progress.show(opt.progress, "${color.build.object}compiling.module.$(mode) %s", opt.name) vprint(compinst:compcmd(sourcefile, objectfile, {compflags = flags, rawargs = true})) if not dryrun then @@ -217,7 +176,7 @@ function generate_dependencies(target, sourcebatch, opt) local dependfile = target:dependfile(sourcefile) depend.on_changed(function () if opt.progress then - progress.show(opt.progress, "${color.build.object}generating.cxx.module.deps %s", sourcefile) + progress.show(opt.progress, "${color.build.object}generating.module.deps %s", sourcefile) end local outputdir = path.join(cachedir, path.directory(path.relative(sourcefile, projectdir))) if not os.isdir(outputdir) then @@ -276,7 +235,7 @@ function generate_headerunit_for_batchjob(target, name, flags, objectfile, index if not common.memcache():get2(name, "generating") then local common_flags = {"-TP", "-c"} common.memcache():set2(name, "generating", true) - progress.show((index * 100) / total, "${color.build.object}generating.cxx.headerunit.bmi %s", name) + progress.show((index * 100) / total, "${color.build.object}compiling.headerunit.$(mode) %s", name) _compile(target, table.join(common_flags, flags)) _add_objectfile_to_link_arguments(target, objectfile) end @@ -287,7 +246,7 @@ function generate_headerunit_for_batchcmds(target, name, flags, objectfile, batc local compinst = target:compiler("cxx") local msvc = target:toolchain("msvc") local common_flags = {"-TP", "-c"} - batchcmds:show_progress(opt.progress, "${color.build.object}generating.cxx.headerunit.bmi %s", name) + batchcmds:show_progress(opt.progress, "${color.build.object}compiling.headerunit.$(mode) %s", name) batchcmds:vrunv(compinst:program(), table.join(compinst:compflags({target = target}), common_flags, flags), {envs = msvc:runenvs()}) _add_objectfile_to_link_arguments(target, objectfile) end @@ -508,14 +467,15 @@ function build_modules_for_batchjobs(target, batchjobs, objectfiles, modules, op requiresflags = get_requiresflags(target, module.requires, {expand = true}) end - _build_interfacemodulefile(target, provide.sourcefile, { + local flags = {ifcoutputflag, bmifile} + table.join2(flags, requiresflags or {}) + table.join2(flags, provide.interface and interfaceflag or {}) + + _build_modulefile(target, provide.sourcefile, { objectfile = objectfile, dependfile = target:dependfile(bmifile), name = name, - bmifile = bmifile, - requiresflags = requiresflags, - interfaceflag = interfaceflag, - ifcoutputflag = ifcoutputflag, + flags = flags, progress = (index * 100) / total}) _add_module_to_mapper(target, referenceflag, name, name, objectfile, bmifile, requiresflags) @@ -541,7 +501,8 @@ function build_modules_for_batchjobs(target, batchjobs, objectfiles, modules, op _build_modulefile(target, module.cppfile, { objectfile = objectfile, dependfile = target:dependfile(objectfile), - requiresflags = requiresflags, + name = module.cppfile, + flags = requiresflags or {}, progress = (index * 100) / total}) target:add("objectfiles", objectfile) elseif requiresflags then @@ -597,7 +558,7 @@ function build_modules_for_batchcmds(target, batchcmds, objectfiles, modules, op ifcoutputflag, path(bmifile), path(provide.sourcefile)} - batchcmds:show_progress(opt.progress, "${color.build.object}generating.cxx.module.bmi %s", name) + batchcmds:show_progress(opt.progress, "${color.build.object}compiling.module.$(mode) %s", name) batchcmds:mkdir(path.directory(objectfile)) batchcmds:vrunv(compinst:program(), table.join(compinst:compflags({target = target}), common_flags, requiresflags or {}, flags), {envs = msvc:runenvs()}) batchcmds:add_depfiles(provide.sourcefile) @@ -614,7 +575,7 @@ function build_modules_for_batchcmds(target, batchcmds, objectfiles, modules, op local flags = {"-c", path(objectfile, function (p) return "-Fo" .. p end), path(module.cppfile)} - batchcmds:show_progress(opt.progress, "${color.build.object}build.cxx.module %s", module.cppfile) + batchcmds:show_progress(opt.progress, "${color.build.object}compiling.module.$(mode) %s", module.cppfile) batchcmds:mkdir(path.directory(objectfile)) batchcmds:vrunv(compinst:program(), table.join(compinst:compflags({target = target}), requiresflags or {}, flags), {envs = msvc:runenvs()}) batchcmds:add_depfiles(module.cppfile) -- cgit v1.3.1 From 9129440bc0f65f7aea3ddd1fbfe4c977bac5eaac Mon Sep 17 00:00:00 2001 From: Arthur LAURENT Date: Sat, 3 Dec 2022 01:40:33 +0100 Subject: fix msvc and refactor GCC --- xmake/rules/c++/modules/modules_support/gcc.lua | 59 ++++++++++-------------- xmake/rules/c++/modules/modules_support/msvc.lua | 7 ++- 2 files changed, 28 insertions(+), 38 deletions(-) (limited to 'xmake/rules/c++/modules/modules_support/msvc.lua') diff --git a/xmake/rules/c++/modules/modules_support/gcc.lua b/xmake/rules/c++/modules/modules_support/gcc.lua index cbdf9b1bf..3888644db 100644 --- a/xmake/rules/c++/modules/modules_support/gcc.lua +++ b/xmake/rules/c++/modules/modules_support/gcc.lua @@ -379,58 +379,49 @@ end -- build module files for batchjobs function build_modules_for_batchjobs(target, batchjobs, objectfiles, modules, opt) local mapper_file = _get_module_mapper() - local cachedir = common.modules_cachedir(target) -- build modules local projectdir = os.projectdir() local modulesjobs = {} for _, objectfile in ipairs(objectfiles) do - local m = modules[objectfile] - if m then - if m.provides then + local module = modules[objectfile] + if module then + local cppfile = module.cppfile + local name, provide + if module.provides then -- assume there that provides is only one, until we encounter the case local length = 0 - local name, provide - for k, v in pairs(m.provides) do + for k, v in pairs(module.provides) do length = length + 1 name = k provide = v + cppfile = provide.sourcefile if length > 1 then raise("multiple provides are not supported now!") end end - - local bmifile = provide.bmi - local moduleinfo = table.copy(provide) - moduleinfo.job = batchjobs:newjob(provide.sourcefile, function (index, total) - _build_modulefile(target, provide.sourcefile, { - objectfile = objectfile, - dependfile = target:dependfile(bmifile), - name = name, - progress = (index * 100) / total}) - end) - if m.requires then - moduleinfo.deps = table.keys(m.requires) - end - moduleinfo.name = name - modulesjobs[name] = moduleinfo - _add_module_to_mapper(mapper_file, name, path.absolute(bmifile, projectdir)) - target:add("objectfiles", objectfile) - elseif common.has_module_extension(m.cppfile) then - modulesjobs[m.cppfile] = { - name = m.cppfile, - deps = table.keys(m.requires or {}), - sourcefile = m.cppfile, - job = batchjobs:newjob(m.cppfile, function(index, total) - _build_modulefile(target, m.cppfile, { + end + local moduleinfo = table.copy(provide) or {} + table.join2(moduleinfo, { + name = name or cppfile, + deps = table.keys(module.requires or {}), + sourcefile = cppfile, + job = batchjobs:newjob(name or cppfile, function(index, total) + + local dependfile = (provide and provide.bmi) and target:dependfile(provide.bmi) or target:dependfile(objectfile) + if provide or common.has_module_extension(cppfile) then + _build_modulefile(target, cppfile, { objectfile = objectfile, - dependfile = target:dependfile(objectfile), - name = m.cppfile, + dependfile = dependfile, + name = name or cppfile, progress = (index * 100) / total}) target:add("objectfiles", objectfile) - end) - } + end + end)}) + if provide then + _add_module_to_mapper(mapper_file, name, path.absolute(provide.bmi, projectdir)) end + modulesjobs[name or cppfile] = moduleinfo end end diff --git a/xmake/rules/c++/modules/modules_support/msvc.lua b/xmake/rules/c++/modules/modules_support/msvc.lua index 6753021ab..9945185e6 100644 --- a/xmake/rules/c++/modules/modules_support/msvc.lua +++ b/xmake/rules/c++/modules/modules_support/msvc.lua @@ -443,8 +443,8 @@ function build_modules_for_batchjobs(target, batchjobs, objectfiles, modules, op local modulesjobs = {} for _, objectfile in ipairs(objectfiles) do local module = modules[objectfile] - local cppfile = module.cppfile if module then + local cppfile = module.cppfile local name, provide if module.provides then -- assume there that provides is only one, until we encounter the case @@ -476,14 +476,13 @@ function build_modules_for_batchjobs(target, batchjobs, objectfiles, modules, op table.join2(flags, requiresflags or {}) table.join2(flags, (provide and provide.interface) and interfaceflag or {}) - local fileconfig = target:fileconfig(cppfile) local dependfile = target:dependfile(objectfile) if provide then table.join2(flags, {ifcoutputflag, provide.bmi}) - dependfile = target:dependfile(provide and provide.bmi or objectfile) + dependfile = target:dependfile(provide.bmi) end - if provide then + if provide or common.has_module_extension(cppfile) then _build_modulefile(target, cppfile, { objectfile = objectfile, dependfile = dependfile, -- cgit v1.3.1 From dd233c5b036b37994b661ef61387cdb3f67eb252 Mon Sep 17 00:00:00 2001 From: Arthur LAURENT Date: Sat, 3 Dec 2022 02:16:08 +0100 Subject: refactor clang --- xmake/rules/c++/modules/modules_support/clang.lua | 80 ++++++++++------------- xmake/rules/c++/modules/modules_support/gcc.lua | 4 +- xmake/rules/c++/modules/modules_support/msvc.lua | 18 ++--- 3 files changed, 47 insertions(+), 55 deletions(-) (limited to 'xmake/rules/c++/modules/modules_support/msvc.lua') diff --git a/xmake/rules/c++/modules/modules_support/clang.lua b/xmake/rules/c++/modules/modules_support/clang.lua index 69419b4e2..adc4ac967 100644 --- a/xmake/rules/c++/modules/modules_support/clang.lua +++ b/xmake/rules/c++/modules/modules_support/clang.lua @@ -460,13 +460,13 @@ end -- build module files for batchjobs function build_modules_for_batchjobs(target, batchjobs, objectfiles, modules, opt) - local compinst = target:compiler("cxx") + + -- get flags local cachedir = common.modules_cachedir(target) local modulecachepathflag = get_modulecachepathflag(target) - local modulefileflag = get_modulefileflag(target) -- flush job - local flushjob = batchjobs:addjob(target:name() .. "_stl_flush_mapper", function(index, total) + local flushjob = batchjobs:addjob(target:name() .. "_modules", function(index, total) _flush_mapper(target) end, {rootjob = opt.rootjob}) @@ -476,22 +476,27 @@ function build_modules_for_batchjobs(target, batchjobs, objectfiles, modules, op for _, objectfile in ipairs(objectfiles) do local module = modules[objectfile] if module then + local cppfile = module.cppfile + local name, provide if module.provides then -- assume there that provides is only one, until we encounter the case local length = 0 - local name, provide for k, v in pairs(module.provides) do length = length + 1 name = k provide = v + cppfile = provide.sourcefile if length > 1 then raise("multiple provides are not supported now!") end end - - local bmifile = provide.bmi - local moduleinfo = table.copy(provide) - moduleinfo.job = batchjobs:newjob(provide.sourcefile, function (index, total) + end + local moduleinfo = table.copy(provide) or {} + table.join2(moduleinfo, { + name = name or cppfile, + deps = table.keys(module.requires or {}), + sourcefile = cppfile, + job = batchjobs:newjob(name or cppfile, function(index, total) -- append module mapper flags first -- @note we add it at the end to ensure that the full modulemap are already stored in the mapper local requiresflags @@ -499,53 +504,38 @@ function build_modules_for_batchjobs(target, batchjobs, objectfiles, modules, op requiresflags = get_requiresflags(target, module.requires) end - _build_interfacemodulefile(target, provide.sourcefile, { - objectfile = objectfile, - dependfile = target:dependfile(bmifile), - bmifile = bmifile, - name = name, - common_args = common_args, - requiresflags = requiresflags, - progress = (index * 100) / total}) - - _add_module_to_mapper(target, name, bmifile, requiresflags) - end) - if module.requires then - moduleinfo.deps = table.keys(module.requires) - end - moduleinfo.name = name - modulesjobs[name] = moduleinfo - target:add("objectfiles", objectfile) - else - modulesjobs[module.cppfile] = { - name = module.cppfile, - deps = table.keys(module.requires or {}), - sourcefile = module.cppfile, - job = batchjobs:newjob(module.cppfile, function(index, total) - local requiresflags - if module.requires then - requiresflags = get_requiresflags(target, module.requires) - end - - if common.has_module_extension(module.cppfile) then - _build_modulefile(target, module.cppfile, { + if provide then + local bmifile = provide.bmi + _build_interfacemodulefile(target, provide.sourcefile, { + objectfile = objectfile, + dependfile = target:dependfile(bmifile), + bmifile = bmifile, + name = name, + common_args = common_args, + requiresflags = requiresflags, + progress = (index * 100) / total}) + target:add("objectfiles", objectfile) + + _add_module_to_mapper(target, name, bmifile, requiresflags) + else + if common.has_module_extension(cppfile) then + _build_modulefile(target, cppfile, { objectfile = objectfile, dependfile = target:dependfile(objectfile), requiresflags = requiresflags, progress = (index * 100) / total}) target:add("objectfiles", objectfile) elseif requiresflags then - -- 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) - target:fileconfig_add(module.cppfile, {force = {cxxflags = requiresflags}}) + target:fileconfig_add(cppfile, {force = {cxxflags = requiresflags}}) end - end) - } - end + end + end)}) + modulesjobs[name or cppfile] = moduleinfo end end + print(modulesjobs) + -- build batchjobs for modules common.build_batchjobs_for_modules(modulesjobs, batchjobs, flushjob) end diff --git a/xmake/rules/c++/modules/modules_support/gcc.lua b/xmake/rules/c++/modules/modules_support/gcc.lua index 3888644db..c8a10da86 100644 --- a/xmake/rules/c++/modules/modules_support/gcc.lua +++ b/xmake/rules/c++/modules/modules_support/gcc.lua @@ -402,13 +402,13 @@ function build_modules_for_batchjobs(target, batchjobs, objectfiles, modules, op end end local moduleinfo = table.copy(provide) or {} + local dependfile = (provide and provide.bmi) and target:dependfile(provide.bmi) or target:dependfile(objectfile) table.join2(moduleinfo, { name = name or cppfile, deps = table.keys(module.requires or {}), sourcefile = cppfile, job = batchjobs:newjob(name or cppfile, function(index, total) - local dependfile = (provide and provide.bmi) and target:dependfile(provide.bmi) or target:dependfile(objectfile) if provide or common.has_module_extension(cppfile) then _build_modulefile(target, cppfile, { objectfile = objectfile, @@ -425,6 +425,8 @@ function build_modules_for_batchjobs(target, batchjobs, objectfiles, modules, op end end + print(modulesjobs) + -- build batchjobs for modules common.build_batchjobs_for_modules(modulesjobs, batchjobs, opt.rootjob) end diff --git a/xmake/rules/c++/modules/modules_support/msvc.lua b/xmake/rules/c++/modules/modules_support/msvc.lua index 9945185e6..a94820b4a 100644 --- a/xmake/rules/c++/modules/modules_support/msvc.lua +++ b/xmake/rules/c++/modules/modules_support/msvc.lua @@ -460,6 +460,15 @@ function build_modules_for_batchjobs(target, batchjobs, objectfiles, modules, op end end local moduleinfo = table.copy(provide) or {} + local flags = {"-TP"} + table.join2(flags, (provide and provide.interface) and interfaceflag or {}) + local dependfile = target:dependfile(objectfile) + + if provide then + table.join2(flags, {ifcoutputflag, provide.bmi}) + dependfile = target:dependfile(provide.bmi) + end + table.join2(moduleinfo, { name = name or cppfile, deps = table.keys(module.requires or {}), @@ -471,16 +480,7 @@ function build_modules_for_batchjobs(target, batchjobs, objectfiles, modules, op if module.requires then requiresflags = get_requiresflags(target, module.requires, {expand = true}) end - - local flags = {"-TP"} table.join2(flags, requiresflags or {}) - table.join2(flags, (provide and provide.interface) and interfaceflag or {}) - - local dependfile = target:dependfile(objectfile) - if provide then - table.join2(flags, {ifcoutputflag, provide.bmi}) - dependfile = target:dependfile(provide.bmi) - end if provide or common.has_module_extension(cppfile) then _build_modulefile(target, cppfile, { -- cgit v1.3.1 From bf2256fbfafd21a3087ad40d93edfe92ec3dee9a Mon Sep 17 00:00:00 2001 From: Arthur LAURENT Date: Sat, 3 Dec 2022 03:30:59 +0100 Subject: refactor clang batchcmds --- xmake/rules/c++/modules/modules_support/clang.lua | 66 +++++++++++------------ xmake/rules/c++/modules/modules_support/gcc.lua | 4 +- xmake/rules/c++/modules/modules_support/msvc.lua | 6 +++ 3 files changed, 39 insertions(+), 37 deletions(-) (limited to 'xmake/rules/c++/modules/modules_support/msvc.lua') diff --git a/xmake/rules/c++/modules/modules_support/clang.lua b/xmake/rules/c++/modules/modules_support/clang.lua index adc4ac967..7bb9b2725 100644 --- a/xmake/rules/c++/modules/modules_support/clang.lua +++ b/xmake/rules/c++/modules/modules_support/clang.lua @@ -43,7 +43,7 @@ function _add_module_to_mapper(target, name, bmifile, deps) end local modulefileflag = get_modulefileflag(target) - local mapflag = format("%s%s", modulefileflag, bmifile) + local mapflag = modulefileflag .. bmifile modulemap[name] = {flag = mapflag, deps = deps} common.localcache():set2(_mapper_cachekey(target), "modulemap", modulemap) end @@ -489,6 +489,7 @@ function build_modules_for_batchjobs(target, batchjobs, objectfiles, modules, op if length > 1 then raise("multiple provides are not supported now!") end + break end end local moduleinfo = table.copy(provide) or {} @@ -497,7 +498,6 @@ function build_modules_for_batchjobs(target, batchjobs, objectfiles, modules, op deps = table.keys(module.requires or {}), sourcefile = cppfile, job = batchjobs:newjob(name or cppfile, function(index, total) - -- append module mapper flags first -- @note we add it at the end to ensure that the full modulemap are already stored in the mapper local requiresflags if module.requires then @@ -534,8 +534,6 @@ function build_modules_for_batchjobs(target, batchjobs, objectfiles, modules, op end end - print(modulesjobs) - -- build batchjobs for modules common.build_batchjobs_for_modules(modulesjobs, batchjobs, flushjob) end @@ -545,52 +543,50 @@ function build_modules_for_batchcmds(target, batchcmds, objectfiles, modules, op local compinst = target:compiler("cxx") local cachedir = common.modules_cachedir(target) local modulecachepathflag = get_modulecachepathflag(target) - local modulefileflag = get_modulefileflag(target) -- build modules local depmtime = 0 - local common_args = {path(cachedir, function (p) return modulecachepathflag .. p end)} for _, objectfile in ipairs(objectfiles) do local module = modules[objectfile] if module then + local cppfile = module.cppfile + local name, provide if module.provides then - local name, provide + local length = 0 for k, v in pairs(module.provides) do + length = length + 1 name = k provide = v + cppfile = provide.sourcefile + if length > 1 then + raise("multiple provides are not supported now!") + end break end - local bmifile = provide.bmi - local args = {"-c", "-x", "c++-module", "--precompile", path(provide.sourcefile), "-o", path(bmifile)} - local requiresflags - if module.requires then - requiresflags = get_requiresflags(target, module.requires) - end - batchcmds:show_progress(opt.progress, "${color.build.object}compiling.module.$(mode) %s", name) - batchcmds:mkdir(path.directory(objectfile)) - batchcmds:vrunv(compinst:program(), table.join(compinst:compflags({target = target}), common_args, requiresflags or {}, args)) - batchcmds:vrunv(compinst:program(), table.join(compinst:compflags({target = target}), common_args, requiresflags or {}, path(bmifile), {"-c", "-o", path(objectfile)})) - batchcmds:add_depfiles(provide.sourcefile) - _add_module_to_mapper(target, name, bmifile) - depmtime = math.max(depmtime, os.mtime(bmifile)) - else - local requiresflags - if module.requires then - requiresflags = get_requiresflags(target, module.requires) - end + end + local requiresflags + if module.requires then + requiresflags = get_requiresflags(target, module.requires) + end + + local flags = table.join({path(cachedir, function (p) return modulecachepathflag .. p end)}, requiresflags or {}) + if provide or common.has_module_extension(cppfile) then + local file = provide and path(provide.bmi) or path(cppfile) - if common.has_module_extension(module.cppfile) then - local flags = {"-o", path(objectfile), "-c", path(module.cppfile)} - batchcmds:show_progress(opt.progress, "${color.build.object}compiling.module.$(mode) %s", module.cppfile) - batchcmds:mkdir(path.directory(objectfile)) - batchcmds:vrunv(compinst:program(), table.join(compinst:compflags({target = target}), requiresflags or {}, flags)) - batchcmds:add_depfiles(module.cppfile) - target:add("objectfiles", objectfile) - depmtime = math.max(depmtime, os.mtime(objectfile)) - elseif requiresflags then - target:fileconfig_add(module.cppfile, {force = {cxxflags = requiresflags}}) + batchcmds:show_progress(opt.progress, "${color.build.object}compiling.module.$(mode) %s", name or cppfile) + batchcmds:mkdir(path.directory(objectfile)) + if provide then + batchcmds:vrunv(compinst:program(), table.join(compinst:compflags({target = target}), flags, {"-x", "c++-module", "--precompile", "-c", path(cppfile), "-o", path(provide.bmi)})) + _add_module_to_mapper(target, name, provide.bmi) end + batchcmds:vrunv(compinst:program(), table.join(compinst:compflags({target = target}), flags, not provide and {"-x", "c++"} or {}, {"-c", file, "-o", path(objectfile)})) + target:add("objectfiles", objectfile) + elseif requiresflags then + target:fileconfig_add(cppfile, {force = {cxxflags = requiresflags}}) end + + batchcmds:add_depfiles(cppfile) + depmtime = math.max(depmtime, os.mtime(objectfile)) end end batchcmds:set_depmtime(depmtime) diff --git a/xmake/rules/c++/modules/modules_support/gcc.lua b/xmake/rules/c++/modules/modules_support/gcc.lua index c8a10da86..5242bd938 100644 --- a/xmake/rules/c++/modules/modules_support/gcc.lua +++ b/xmake/rules/c++/modules/modules_support/gcc.lua @@ -399,6 +399,7 @@ function build_modules_for_batchjobs(target, batchjobs, objectfiles, modules, op if length > 1 then raise("multiple provides are not supported now!") end + break end end local moduleinfo = table.copy(provide) or {} @@ -425,8 +426,6 @@ function build_modules_for_batchjobs(target, batchjobs, objectfiles, modules, op end end - print(modulesjobs) - -- build batchjobs for modules common.build_batchjobs_for_modules(modulesjobs, batchjobs, opt.rootjob) end @@ -455,6 +454,7 @@ function build_modules_for_batchcmds(target, batchcmds, objectfiles, modules, op if length > 1 then raise("multiple provides are not supported now!") end + break end local bmifile = provide.bmi diff --git a/xmake/rules/c++/modules/modules_support/msvc.lua b/xmake/rules/c++/modules/modules_support/msvc.lua index a94820b4a..904ef82c6 100644 --- a/xmake/rules/c++/modules/modules_support/msvc.lua +++ b/xmake/rules/c++/modules/modules_support/msvc.lua @@ -457,6 +457,7 @@ function build_modules_for_batchjobs(target, batchjobs, objectfiles, modules, op if length > 1 then raise("multiple provides are not supported now!") end + break end end local moduleinfo = table.copy(provide) or {} @@ -524,9 +525,14 @@ function build_modules_for_batchcmds(target, batchcmds, objectfiles, modules, op if module then if module.provides then local name, provide + local length = 0 for k, v in pairs(module.provides) do + length = length + 1 name = k provide = v + if length > 1 then + raise("multiple provides are not supported now!") + end break end -- cgit v1.3.1 From b0a3ca100afda323d50c2ab7eb1b6dd5a84dc0e9 Mon Sep 17 00:00:00 2001 From: Arthur LAURENT Date: Sat, 3 Dec 2022 03:55:56 +0100 Subject: refactor msvc batchcmds --- xmake/rules/c++/modules/modules_support/gcc.lua | 2 +- xmake/rules/c++/modules/modules_support/msvc.lua | 77 +++++++++++------------- 2 files changed, 36 insertions(+), 43 deletions(-) (limited to 'xmake/rules/c++/modules/modules_support/msvc.lua') diff --git a/xmake/rules/c++/modules/modules_support/gcc.lua b/xmake/rules/c++/modules/modules_support/gcc.lua index d20c7455e..6f1539891 100644 --- a/xmake/rules/c++/modules/modules_support/gcc.lua +++ b/xmake/rules/c++/modules/modules_support/gcc.lua @@ -457,7 +457,7 @@ function build_modules_for_batchcmds(target, batchcmds, objectfiles, modules, op end end local flags = {"-x", "c++","-c", path(cppfile), "-o", path(objectfile)} - batchcmds:show_progress(opt.progress, "${color.build.object}compiling.module.$(mode) %s", name) + batchcmds:show_progress(opt.progress, "${color.build.object}compiling.module.$(mode) %s", name or cppfile) batchcmds:mkdir(path.directory(objectfile)) batchcmds:vrunv(compinst:program(), table.join(compinst:compflags({target = target}), flags)) batchcmds:add_depfiles(cppfile) diff --git a/xmake/rules/c++/modules/modules_support/msvc.lua b/xmake/rules/c++/modules/modules_support/msvc.lua index 904ef82c6..616a2d082 100644 --- a/xmake/rules/c++/modules/modules_support/msvc.lua +++ b/xmake/rules/c++/modules/modules_support/msvc.lua @@ -462,12 +462,15 @@ function build_modules_for_batchjobs(target, batchjobs, objectfiles, modules, op end local moduleinfo = table.copy(provide) or {} local flags = {"-TP"} - table.join2(flags, (provide and provide.interface) and interfaceflag or {}) local dependfile = target:dependfile(objectfile) if provide then table.join2(flags, {ifcoutputflag, provide.bmi}) dependfile = target:dependfile(provide.bmi) + + if provide.interface then + table.insert(flags, interfaceflag) + end end table.join2(moduleinfo, { @@ -481,19 +484,19 @@ function build_modules_for_batchjobs(target, batchjobs, objectfiles, modules, op if module.requires then requiresflags = get_requiresflags(target, module.requires, {expand = true}) end - table.join2(flags, requiresflags or {}) + local _flags = table.join(flags, requiresflags or {}) if provide or common.has_module_extension(cppfile) then _build_modulefile(target, cppfile, { objectfile = objectfile, dependfile = dependfile, name = name or module.cppfile, - flags = flags, + flags = _flags, progress = (index * 100) / total}) target:add("objectfiles", objectfile) - else - local flags = get_requiresflags(target, module.requires) - target:fileconfig_add(cppfile, {force = {cxxflags = flags}}) + elseif requiresflags then + requiresflags = get_requiresflags(target, module.requires) + target:fileconfig_add(cppfile, {force = {cxxflags = table.join(flags, requiresflags)}}) end if provide then @@ -523,59 +526,49 @@ function build_modules_for_batchcmds(target, batchcmds, objectfiles, modules, op for _, objectfile in ipairs(objectfiles) do local module = modules[objectfile] if module then + local cppfile = module.cppfile + local name, provide if module.provides then - local name, provide local length = 0 for k, v in pairs(module.provides) do length = length + 1 name = k provide = v + cppfile = provide.sourcefile if length > 1 then raise("multiple provides are not supported now!") end break end + end + -- append required modulemap flags to module + local requiresflags + if module.requires then + requiresflags = get_requiresflags(target, module.requires, {expand = true}) + end - -- append required modulemap flags to module - local requiresflags - if module.requires then - requiresflags = get_requiresflags(target, module.requires, {expand = true}) + local flags = table.join({"-TP", "-c", path(cppfile), path(objectfile, function (p) return "-Fo" .. p end)}) + if provide or common.has_module_extension(cppfile) then + if provide then + table.join2(flags, {ifcoutputflag, path(provide.bmi)}) + + if provide.interface then + table.insert(flags, interfaceflag) + end end - local bmifile = provide.bmi - local flags = {"-TP", "-c", - path(objectfile, function (p) return "-Fo" .. p end), - ifcoutputflag, - path(bmifile), - path(provide.sourcefile)} - table.join2(flags, requiresflags or {}) - table.join2(flags, provide.interface and interfaceflag or {}) - batchcmds:show_progress(opt.progress, "${color.build.object}compiling.module.$(mode) %s", name) + batchcmds:show_progress(opt.progress, "${color.build.object}compiling.module.$(mode) %s", name or cppfile) batchcmds:mkdir(path.directory(objectfile)) - batchcmds:vrunv(compinst:program(), table.join(compinst:compflags({target = target}), flags), {envs = msvc:runenvs()}) - batchcmds:add_depfiles(provide.sourcefile) + batchcmds:vrunv(compinst:program(), table.join(compinst:compflags({target = target}), table.join(flags, requiresflags or {})), {envs = msvc:runenvs()}) + batchcmds:add_depfiles(cppfile) target:add("objectfiles", objectfile) - _add_module_to_mapper(target, referenceflag, name, name, objectfile, bmifile, requiresflags) - depmtime = math.max(depmtime, os.mtime(bmifile)) - else - local requiresflags - if module.requires then - requiresflags = get_requiresflags(target, module.requires, {expand = true}) - end - - if common.has_module_extension(module.cppfile) then - local flags = {"-c", - path(objectfile, function (p) return "-Fo" .. p end), - path(module.cppfile)} - batchcmds:show_progress(opt.progress, "${color.build.object}compiling.module.$(mode) %s", module.cppfile) - batchcmds:mkdir(path.directory(objectfile)) - batchcmds:vrunv(compinst:program(), table.join(compinst:compflags({target = target}), requiresflags or {}, flags), {envs = msvc:runenvs()}) - batchcmds:add_depfiles(module.cppfile) - target:add("objectfiles", objectfile) - depmtime = math.max(depmtime, os.mtime(objectfile)) - elseif requiresflags then - target:fileconfig_add(module.cppfile, {force = {cxxflags = requiresflags}}) + if provide then + _add_module_to_mapper(target, referenceflag, name, name, objectfile, provide.bmi, requiresflags) end + depmtime = math.max(depmtime, os.mtime(provide and provide.bmi or objectfile)) + elseif requiresflags then + requiresflags = get_requiresflags(target, module.requires) + target:fileconfig_add(cppfile, {force = {cxxflags = table.join(flags, requiresflags)}}) end end end -- cgit v1.3.1