diff options
Diffstat (limited to 'xmake/rules/c++/modules/modules_support/msvc.lua')
| -rw-r--r-- | xmake/rules/c++/modules/modules_support/msvc.lua | 94 |
1 files changed, 77 insertions, 17 deletions
diff --git a/xmake/rules/c++/modules/modules_support/msvc.lua b/xmake/rules/c++/modules/modules_support/msvc.lua index b57ac4520..d9f3019d6 100644 --- a/xmake/rules/c++/modules/modules_support/msvc.lua +++ b/xmake/rules/c++/modules/modules_support/msvc.lua @@ -102,6 +102,43 @@ function _build_modulefile(target, sourcefile, opt) -- init flags local requiresflags = opt.requiresflags + local flags = table.join("-TP", requiresflags or {}, compflags) + + -- 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 @@ -440,7 +477,7 @@ function build_modules_for_batchjobs(target, batchjobs, objectfiles, modules, op requiresflags = get_requiresflags(target, module.requires, {expand = true}) end - _build_modulefile(target, provide.sourcefile, { + _build_interfacemodulefile(target, provide.sourcefile, { objectfile = objectfile, dependfile = target:dependfile(bmifile), name = name, @@ -459,21 +496,31 @@ function build_modules_for_batchjobs(target, batchjobs, objectfiles, modules, op modulesjobs[name] = moduleinfo target:add("objectfiles", objectfile) else - if module.requires then - modulesjobs[module.cppfile] = { - name = module.cppfile, - deps = table.keys(module.requires), - sourcefile = module.cppfile, - job = batchjobs:newjob(module.cppfile, function(index, total) + 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 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) - if requiresflags then - target:fileconfig_add(module.cppfile, {force = {cxxflags = requiresflags}}) - end - end) - } - end + target:fileconfig_add(module.cppfile, {force = {cxxflags = requiresflags}}) + end + end) + } end end end @@ -523,14 +570,27 @@ function build_modules_for_batchcmds(target, batchcmds, objectfiles, modules, op 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) + 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 - local requiresflags = get_requiresflags(target, module.requires) - if requiresflags then - target:fileconfig_add(module.cppfile, {force = {cxxflags = requiresflags}}) - end + 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}}) end end end |
