diff options
| author | ruki <[email protected]> | 2023-01-08 10:48:39 +0800 |
|---|---|---|
| committer | GitHub <[email protected]> | 2023-01-08 10:48:39 +0800 |
| commit | 1b19d2ba990e8714d0298de50d009ee7ff6576e5 (patch) | |
| tree | 3a90a3e96ab35b2ff9f86fce174abea25292b46b /xmake/rules/c++/modules/modules_support/msvc.lua | |
| parent | 06829c1ac295a74a62e4c2b9a1732017d1d7a80d (diff) | |
| parent | b5e29bdae4f381e343632cf5ea51224aea8f720a (diff) | |
Merge pull request #3228 from Arthapz/support-c++20-module-packages
Add support of importing modules from packages
Diffstat (limited to 'xmake/rules/c++/modules/modules_support/msvc.lua')
| -rw-r--r-- | xmake/rules/c++/modules/modules_support/msvc.lua | 64 |
1 files changed, 40 insertions, 24 deletions
diff --git a/xmake/rules/c++/modules/modules_support/msvc.lua b/xmake/rules/c++/modules/modules_support/msvc.lua index a902721c0..d0895490a 100644 --- a/xmake/rules/c++/modules/modules_support/msvc.lua +++ b/xmake/rules/c++/modules/modules_support/msvc.lua @@ -20,6 +20,7 @@ -- imports import("core.base.option") +import("core.base.json") import("core.tool.compiler") import("core.project.project") import("core.project.depend") @@ -450,6 +451,7 @@ function build_modules_for_batchjobs(target, batchjobs, objectfiles, modules, op for objectfile, module in pairs(get_stdmodules(target)) do table.insert(objectfiles, objectfile) modules[objectfile] = module + modules[objectfile].external = true end end @@ -480,6 +482,21 @@ function build_modules_for_batchjobs(target, batchjobs, objectfiles, modules, op if provide then table.join2(flags, {ifcoutputflag, path(provide.bmi), provide.interface and interfaceflag or internalpartitionflag}) dependfile = target:dependfile(provide.bmi) + + local fileconfig = target:fileconfig(cppfile) + if fileconfig and fileconfig.install then + batchjobs:addjob(name .. "_metafile", function(index, total) + local cachedir = common.modules_cachedir(target) + local metafilepath = path.join(cachedir, path.filename(cppfile) .. ".meta-info") + depend.on_changed(function() + progress.show(opt.progress, "${color.build.object}generating.module.metadata %s", name) + local metadata = common.generate_meta_module_info(target, name, cppfile, module.requires) + json.savefile(metafilepath, metadata) + + end, {dependfile = target:dependfile(metafilepath), files = {cppfile}}) + + end, {rootjob = flushjob}) + end end table.join2(moduleinfo, { @@ -497,17 +514,17 @@ function build_modules_for_batchjobs(target, batchjobs, objectfiles, modules, op if provide or common.has_module_extension(cppfile) then if not common.memcache():get2(name or cppfile, "compiling") then - if name and name:match("std") then - common.memcache():set2(name or cppfile, "compiling", true) + if name and module.external then + common.memcache():set2(name or cppfile, "compiling", true) end - _build_modulefile(target, cppfile, { - objectfile = objectfile, - dependfile = dependfile, - name = name or module.cppfile, - flags = _flags, - progress = (index * 100) / total}) - _add_objectfile_to_link_arguments(target, path(objectfile)) + _build_modulefile(target, cppfile, { + objectfile = objectfile, + dependfile = dependfile, + name = name or module.cppfile, + flags = _flags, + progress = (index * 100) / total}) end + _add_objectfile_to_link_arguments(target, objectfile) elseif requiresflags then requiresflags = get_requiresflags(target, module.requires) target:fileconfig_add(cppfile, {force = {cxxflags = table.join(flags, requiresflags)}}) @@ -577,7 +594,7 @@ function build_modules_for_batchcmds(target, batchcmds, objectfiles, modules, op batchcmds:mkdir(path.directory(objectfile)) _batchcmds_compile(batchcmds, target, table.join(flags, requiresflags or {})) batchcmds:add_depfiles(cppfile) - _add_objectfile_to_link_arguments(target, path(objectfile)) + _add_objectfile_to_link_arguments(target, path.translate(objectfile)) if provide then _add_module_to_mapper(target, referenceflag, name, name, objectfile, provide.bmi, requiresflags) end @@ -642,10 +659,10 @@ function get_ifcoutputflag(target) local ifcoutputflag = _g.ifcoutputflag if ifcoutputflag == nil then local compinst = target:compiler("cxx") - if compinst:has_flags("-ifcOutput", "cxxflags", {flagskey = "cl_ifc_output"}) then + if compinst:has_flags({"-ifcOutput", os.tmpfile()}, "cxxflags", {flagskey = "cl_ifc_output"}) then ifcoutputflag = "-ifcOutput" end - assert(ifcoutputflag, "compiler(msvc): does not support c++ module!") + assert(ifcoutputflag, "compiler(msvc): does not support c++ module flag(/ifcOutput)!") _g.ifcoutputflag = ifcoutputflag or false end return ifcoutputflag or nil @@ -655,10 +672,10 @@ function get_ifcsearchdirflag(target) local ifcsearchdirflag = _g.ifcsearchdirflag if ifcsearchdirflag == nil then local compinst = target:compiler("cxx") - if compinst:has_flags("-ifcSearchDir", "cxxflags", {flagskey = "cl_ifc_search_dir"}) then + if compinst:has_flags({"-ifcSearchDir", os.tmpdir()}, "cxxflags", {flagskey = "cl_ifc_search_dir"}) then ifcsearchdirflag = "-ifcSearchDir" end - assert(ifcsearchdirflag, "compiler(msvc): does not support c++ module!") + assert(ifcsearchdirflag, "compiler(msvc): does not support c++ module flag(/ifcSearchDir)!") _g.ifcsearchdirflag = ifcsearchdirflag or false end return ifcsearchdirflag or nil @@ -671,7 +688,7 @@ function get_interfaceflag(target) if compinst:has_flags("-interface", "cxxflags", {flagskey = "cl_interface"}) then interfaceflag = "-interface" end - assert(interfaceflag, "compiler(msvc): does not support c++ module!") + assert(interfaceflag, "compiler(msvc): does not support c++ module flag(/interface)!") _g.interfaceflag = interfaceflag or false end return interfaceflag @@ -681,10 +698,10 @@ function get_referenceflag(target) local referenceflag = _g.referenceflag if referenceflag == nil then local compinst = target:compiler("cxx") - if compinst:has_flags("-reference", "cxxflags", {flagskey = "cl_reference"}) then + if compinst:has_flags({"-reference", "Foo=" .. os.tmpfile()}, "cxxflags", {flagskey = "cl_reference"}) then referenceflag = "-reference" end - assert(referenceflag, "compiler(msvc): does not support c++ module!") + assert(referenceflag, "compiler(msvc): does not support c++ module flag(/reference)!") _g.referenceflag = referenceflag or false end return referenceflag or nil @@ -694,8 +711,8 @@ function get_headernameflag(target) local headernameflag = _g.headernameflag if headernameflag == nil then local compinst = target:compiler("cxx") - if compinst:has_flags("-headerName:quote", "cxxflags", {flagskey = "cl_header_name_quote"}) and - compinst:has_flags("-headerName:angle", "cxxflags", {flagskey = "cl_header_name_angle"}) then + if compinst:has_flags({"-std:c++latest", "-exportHeader", "-headerName:quote"}, "cxxflags", {flagskey = "cl_header_name_quote"}) and + compinst:has_flags({"-std:c++latest", "-exportHeader", "-headerName:angle"}, "cxxflags", {flagskey = "cl_header_name_angle"}) then headernameflag = "-headerName" end _g.headernameflag = headernameflag or false @@ -707,8 +724,9 @@ function get_headerunitflag(target) local headerunitflag = _g.headerunitflag if headerunitflag == nil then local compinst = target:compiler("cxx") - if compinst:has_flags("-headerUnit:quote", "cxxflags", {flagskey = "cl_header_unit_quote"}) and - compinst:has_flags("-headerUnit:angle", "cxxflags", {flagskey = "cl_header_unit_angle"}) then + local ifcfile = os.tmpfile() + if compinst:has_flags({"-std:c++latest", "-headerUnit:quote", "foo.h=" .. ifcfile}, "cxxflags", {flagskey = "cl_header_unit_quote"}) and + compinst:has_flags({"-std:c++latest", "-headerUnit:angle", "foo.h=" .. ifcfile}, "cxxflags", {flagskey = "cl_header_unit_angle"}) then headerunitflag = "-headerUnit" end _g.headerunitflag = headerunitflag or false @@ -717,11 +735,9 @@ function get_headerunitflag(target) end function get_exportheaderflag(target) - local modulesflag = get_modulesflag(target) local exportheaderflag = _g.exportheaderflag if exportheaderflag == nil then - local compinst = target:compiler("cxx") - if compinst:has_flags(modulesflag .. " -exportHeader", "cxxflags", {flagskey = "cl_export_header"}) then + if get_headernameflag(target) then exportheaderflag = "-exportHeader" end _g.exportheaderflag = exportheaderflag or false |
