diff options
Diffstat (limited to 'xmake/rules/c++/modules/modules_support/msvc.lua')
| -rw-r--r-- | xmake/rules/c++/modules/modules_support/msvc.lua | 206 |
1 files changed, 76 insertions, 130 deletions
diff --git a/xmake/rules/c++/modules/modules_support/msvc.lua b/xmake/rules/c++/modules/modules_support/msvc.lua index 092e23c24..616a2d082 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 @@ -485,74 +444,66 @@ 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 + break + end + end + local moduleinfo = table.copy(provide) or {} + local flags = {"-TP"} + 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 - local bmifile = provide.bmi - local moduleinfo = table.copy(provide) - moduleinfo.job = batchjobs:newjob(provide.sourcefile, function (index, total) + 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 if module.requires then requiresflags = get_requiresflags(target, module.requires, {expand = true}) end + local _flags = table.join(flags, requiresflags or {}) - _build_interfacemodulefile(target, provide.sourcefile, { - objectfile = objectfile, - dependfile = target:dependfile(bmifile), - name = name, - bmifile = bmifile, - requiresflags = requiresflags, - interfaceflag = interfaceflag, - ifcoutputflag = ifcoutputflag, - progress = (index * 100) / total}) - - _add_module_to_mapper(target, referenceflag, name, name, objectfile, 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, {expand = true}) - end + if provide or common.has_module_extension(cppfile) then + _build_modulefile(target, cppfile, { + objectfile = objectfile, + dependfile = dependfile, + name = name or module.cppfile, + flags = _flags, + progress = (index * 100) / total}) + target:add("objectfiles", objectfile) + elseif requiresflags then + requiresflags = get_requiresflags(target, module.requires) + target:fileconfig_add(cppfile, {force = {cxxflags = table.join(flags, requiresflags)}}) + end - if common.has_module_extension(module.cppfile) then - _build_modulefile(target, module.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}}) - end - end) - } - end + if provide then + _add_module_to_mapper(target, referenceflag, name, name, objectfile, provide.bmi, requiresflags) + end + end)}) + modulesjobs[name or cppfile] = moduleinfo end end @@ -571,58 +522,53 @@ function build_modules_for_batchcmds(target, batchcmds, objectfiles, modules, op local referenceflag = get_referenceflag(target) -- build modules - local common_flags = {"-TP"} local depmtime = 0 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 + + 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)}) - -- append required modulemap flags to module - local requiresflags - if module.requires then - requiresflags = get_requiresflags(target, module.requires, {expand = true}) + if provide.interface then + table.insert(flags, interfaceflag) + end end - local bmifile = provide.bmi - local flags = {"-c", - path(objectfile, function (p) return "-Fo" .. p end), - interfaceflag, - 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 or cppfile) 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) + 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}build.cxx.module %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 |
