From 6c27288e6156c41ad754c7a195faaf40dcce0c18 Mon Sep 17 00:00:00 2001 From: Arthur LAURENT Date: Thu, 4 Aug 2022 23:27:28 +0200 Subject: Fix bmi generation path when module is generated by build chain --- xmake/rules/c++/modules/modules_support/msvc.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (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 c2351371f..fa5741676 100644 --- a/xmake/rules/c++/modules/modules_support/msvc.lua +++ b/xmake/rules/c++/modules/modules_support/msvc.lua @@ -90,7 +90,7 @@ function generate_dependencies(target, sourcebatch, opt) local dependfile = target:dependfile(sourcefile) depend.on_changed(function () progress.show(opt.progress, "${color.build.object}generating.cxx.module.deps %s", sourcefile) - local outputdir = path.join(cachedir, path.directory(path.relative(sourcefile, target:scriptdir()))) + local outputdir = path.join(cachedir, path.directory(path.relative(sourcefile, projectdir))) if not os.isdir(outputdir) then os.mkdir(outputdir) end -- cgit v1.3.1 From d2d7292907f6aecbcb0b52aca4897bc7fbaf94cd Mon Sep 17 00:00:00 2001 From: Arthur LAURENT Date: Thu, 4 Aug 2022 23:27:42 +0200 Subject: Improve header unit support --- xmake/rules/c++/modules/modules_support/clang.lua | 114 +++++++++++++--------- xmake/rules/c++/modules/modules_support/gcc.lua | 112 +++++++++++---------- xmake/rules/c++/modules/modules_support/msvc.lua | 110 ++++++++++++--------- xmake/rules/c++/modules/xmake.lua | 26 +++-- 4 files changed, 214 insertions(+), 148 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 fd71b298f..e023acccb 100644 --- a/xmake/rules/c++/modules/modules_support/clang.lua +++ b/xmake/rules/c++/modules/modules_support/clang.lua @@ -127,13 +127,44 @@ function generate_dependencies(target, sourcebatch, opt) end end --- generate target header units -function generate_headerunits(target, batchcmds, headerunits, opt) +-- generate target stl header units +function generate_stl_headerunits(target, batchcmds, headerunits, opt) local compinst = target:compiler("cxx") - local cachedir = common.modules_cachedir(target) + + -- get cachedirs local stlcachedir = common.stlmodules_cachedir(target) + + -- get headerunits flags + local modulecachepathflag = get_modulecachepathflag(target) + local modulefileflag = get_modulefileflag(target) + + -- build headerunits + local projectdir = os.projectdir() + local flags = {} + for i, headerunit in ipairs(headerunits) do + local bmifile = path.join(stlcachedir, headerunit.name .. get_bmi_extension()) + if not os.isfile(bmifile) then + local args = {modulecachepathflag .. stlcachedir, "-c", "-o", bmifile, "-x", "c++-system-header", headerunit.path} + batchcmds:show_progress(opt.progress, "${color.build.object}generating.cxx.headerunit.bmi %s", headerunit.name) + batchcmds:vrunv(compinst:program(), table.join(compinst:compflags({target = target}), args)) + end + + batchcmds:set_depmtime(os.mtime(bmifile)) + batchcmds:set_depcache(target:dependfile(bmifile)) + + table.insert(flags, modulefileflag .. bmifile) + end + return flags +end + +-- generate target user header units +function generate_user_headerunits(target, batchcmds, headerunits, opt) + local compinst = target:compiler("cxx") assert(has_headerunitsupport(target), "compiler(clang): does not support c++ header units!") + -- get cachedirs + local cachedir = common.modules_cachedir(target) + -- get headerunits flags local modulecachepathflag = get_modulecachepathflag(target) local emitmoduleflag = get_emitmoduleflag(target) @@ -141,65 +172,52 @@ function generate_headerunits(target, batchcmds, headerunits, opt) -- build headerunits local objectfiles = {} - local public_flags = {} - local private_flags = {} + local flags = {} local projectdir = os.projectdir() for _, headerunit in ipairs(headerunits) do - if not headerunit.stl then - local file = path.relative(headerunit.path, target:scriptdir()) - local objectfile = target:objectfile(file) - - local outdir - if headerunit.type == ":quote" then - outdir = path.join(cachedir, path.directory(path.relative(headerunit.path, projectdir))) - else - outdir = path.join(cachedir, path.directory(headerunit.path)) - end - if not os.isdir(outdir) then - os.mkdir(outdir) - end - - local bmifilename = path.basename(objectfile) .. get_bmi_extension() - local bmifile = (outdir and path.join(outdir, bmifilename) or bmifilename) - if not os.isdir(path.directory(objectfile)) then - os.mkdir(path.directory(objectfile)) - end + local file = path.relative(headerunit.path, target:scriptdir()) + local objectfile = target:objectfile(file) - local args = { modulecachepathflag .. cachedir, emitmoduleflag, "-c", "-o", bmifile} - if headerunit.type == ":quote" then - table.join2(args, {"-I", path.directory(headerunit.path), "-x", "c++-user-header", headerunit.path}) - elseif headerunit.type == ":angle" then - table.join2(args, {"-x", "c++-system-header", headerunit.name}) - end + local outdir + if headerunit.type == ":quote" then + outdir = path.join(cachedir, path.directory(path.relative(headerunit.path, projectdir))) + else + outdir = path.join(cachedir, path.directory(headerunit.path)) + end + if not os.isdir(outdir) then + os.mkdir(outdir) + end - batchcmds:show_progress(opt.progress, "${color.build.object}generating.cxx.headerunit.bmi %s", headerunit.name) - batchcmds:vrunv(compinst:program(), table.join(compinst:compflags({target = target}), args)) + local bmifilename = path.basename(objectfile) .. get_bmi_extension() + local bmifile = (outdir and path.join(outdir, bmifilename) or bmifilename) + if not os.isdir(path.directory(objectfile)) then + os.mkdir(path.directory(objectfile)) + end - batchcmds:add_depfiles(headerunit.path) - batchcmds:set_depmtime(os.mtime(bmifile)) - batchcmds:set_depcache(target:dependfile(bmifile)) + local args = { modulecachepathflag .. cachedir, emitmoduleflag, "-c", "-o", bmifile} + if headerunit.type == ":quote" then + table.join2(args, {"-I", path.directory(headerunit.path), "-x", "c++-user-header", headerunit.path}) + elseif headerunit.type == ":angle" then + table.join2(args, {"-x", "c++-system-header", headerunit.name}) + end - table.insert(public_flags, modulefileflag .. bmifile) - else - local bmifile = path.join(stlcachedir, headerunit.name .. get_bmi_extension()) - if not os.isfile(bmifile) then - local args = {modulecachepathflag .. stlcachedir, "-c", "-o", bmifile, "-x", "c++-system-header", headerunit.path} - batchcmds:show_progress(opt.progress, "${color.build.object}generating.cxx.headerunit.bmi %s", headerunit.name) - batchcmds:vrunv(compinst:program(), table.join(compinst:compflags({target = target}), args)) - end + batchcmds:show_progress(opt.progress, "${color.build.object}generating.cxx.headerunit.bmi %s", headerunit.name) + batchcmds:vrunv(compinst:program(), table.join(compinst:compflags({target = target}), args)) - batchcmds:set_depmtime(os.mtime(bmifile)) - batchcmds:set_depcache(target:dependfile(bmifile)) + batchcmds:add_depfiles(headerunit.path) + batchcmds:set_depmtime(os.mtime(bmifile)) + batchcmds:set_depcache(target:dependfile(bmifile)) - table.insert(private_flags, modulefileflag .. bmifile) - end + table.insert(flags, modulefileflag .. bmifile) end - return public_flags, private_flags + return flags end -- build module files function build_modules(target, batchcmds, objectfiles, modules, opt) local compinst = target:compiler("cxx") + + -- get cachedirs local cachedir = common.modules_cachedir(target) -- get modules flags diff --git a/xmake/rules/c++/modules/modules_support/gcc.lua b/xmake/rules/c++/modules/modules_support/gcc.lua index dba8b7e79..23e89a30b 100644 --- a/xmake/rules/c++/modules/modules_support/gcc.lua +++ b/xmake/rules/c++/modules/modules_support/gcc.lua @@ -149,77 +149,91 @@ function generate_dependencies(target, sourcebatch, opt) end end --- generate target header units -function generate_headerunits(target, batchcmds, headerunits, opt) +-- generate target stl header units +function generate_stl_headerunits(target, batchcmds, headerunits, opt) local compinst = target:compiler("cxx") - local cachedir = common.modules_cachedir(target) - local stlcachedir = common.stlmodules_cachedir(target) local mapper_file = _get_module_mapper() + -- get cachedirs + local stlcachedir = common.stlmodules_cachedir(target) + -- build headerunits - local objectfiles = {} local projectdir = os.projectdir() - for _, headerunit in ipairs(headerunits) do - if not headerunit.stl then - local file = path.relative(headerunit.path, target:scriptdir()) - local objectfile = target:objectfile(file) + for i, headerunit in ipairs(headerunits) do + local bmifile = path.join(stlcachedir, headerunit.name .. get_bmi_extension()) + if _add_module_to_mapper(mapper_file, headerunit.path, path.absolute(bmifile, projectdir)) then + local args = { "-c", "-x", "c++-system-header", headerunit.name } - local outdir - if headerunit.type == ":quote" then - outdir = path.join(cachedir, path.directory(path.relative(headerunit.path, projectdir))) - else - outdir = path.join(cachedir, path.directory(headerunit.path)) - end - if not os.isdir(outdir) then - os.mkdir(outdir) - end + batchcmds:show_progress(opt.progress, "${color.build.object}generating.cxx.headerunit.bmi %s", headerunit.name) + batchcmds:vrunv(compinst:program(), table.join(compinst:compflags({target = target}), args)) - local bmifilename = path.basename(objectfile) .. get_bmi_extension() - local bmifile = (outdir and path.join(outdir, bmifilename) or bmifilename) - if not os.isdir(path.directory(objectfile)) then - os.mkdir(path.directory(objectfile)) - end + batchcmds:set_depmtime(os.mtime(bmifile)) + batchcmds:set_depcache(target:dependfile(bmifile)) + end + end +end - if _add_module_to_mapper(mapper_file, headerunit.path, path.absolute(bmifile, projectdir)) then - local args = { "-c" } - if headerunit.type == ":quote" then - table.join2(args, { "-I", path.directory(headerunit.path), "-x", "c++-user-header", headerunit.name }) - _add_module_to_mapper(mapper_file, path.join(".", path.relative(headerunit.path, projectdir)), path.absolute(bmifile, projectdir)) - elseif headerunit.type == ":angle" then - table.join2(args, { "-x", "c++-system-header", headerunit.name }) - _add_module_to_mapper(mapper_file, headerunit.name, path.absolute(bmifile, projectdir)) - end +-- generate target user header units +function generate_user_headerunits(target, batchcmds, headerunits, opt) + local compinst = target:compiler("cxx") + local mapper_file = _get_module_mapper() - batchcmds:show_progress(opt.progress, "${color.build.object}generating.cxx.headerunit.bmi %s", headerunit.name) - batchcmds:vrunv(compinst:program(), table.join(compinst:compflags({target = target}), args)) + -- get cachedirs + local cachedir = common.modules_cachedir(target) - batchcmds:add_depfiles(headerunit.path) - batchcmds:set_depmtime(os.mtime(bmifile)) - batchcmds:set_depcache(target:dependfile(bmifile)) - end + -- build headerunits + local projectdir = os.projectdir() + for _, headerunit in ipairs(headerunits) do + local file = path.relative(headerunit.path, projectdir) + local objectfile = target:objectfile(file) + + local outdir + if headerunit.type == ":quote" then + outdir = path.join(cachedir, path.directory(path.relative(headerunit.path, projectdir))) else - local bmifile = path.join(stlcachedir, headerunit.name .. get_bmi_extension()) - if _add_module_to_mapper(mapper_file, headerunit.path, path.absolute(bmifile, projectdir)) then - if not os.isfile(bmifile) then - local args = { "-c", "-x", "c++-system-header", headerunit.name } + outdir = path.join(cachedir, path.directory(headerunit.path)) + end + if not os.isdir(outdir) then + os.mkdir(outdir) + end - batchcmds:show_progress(opt.progress, "${color.build.object}generating.cxx.headerunit.bmi %s", headerunit.name) - batchcmds:vrunv(compinst:program(), table.join(compinst:compflags({target = target}), args)) + local bmifilename = path.basename(objectfile) .. get_bmi_extension() + local bmifile = (outdir and path.join(outdir, bmifilename) or bmifilename) + if not os.isdir(path.directory(objectfile)) then + os.mkdir(path.directory(objectfile)) + end - batchcmds:set_depmtime(os.mtime(bmifile)) - batchcmds:set_depcache(target:dependfile(bmifile)) - end - end + local args = { "-c" } + local headerunit_path + if headerunit.type == ":quote" then + table.join2(args, { "-I", path.directory(path.relative(headerunit.path, projectdir)), "-x", "c++-user-header", headerunit.name }) + headerunit_path = path.join(".", path.relative(headerunit.path, projectdir)) + elseif headerunit.type == ":angle" then + table.join2(args, { "-x", "c++-system-header", headerunit.name }) + -- if path is relative then its a subtarget path + headerunit_path = path.is_absolute(headerunit.path) and headerunit.path or path.join(".", headerunit.path) + end + + if _add_module_to_mapper(mapper_file, headerunit_path, path.absolute(bmifile, projectdir)) then + batchcmds:show_progress(opt.progress, "${color.build.object}generating.cxx.headerunit.bmi %s", headerunit.name) + batchcmds:vrunv(compinst:program(), table.join(compinst:compflags({target = target}), args)) + + batchcmds:add_depfiles(headerunit.path) + batchcmds:set_depmtime(os.mtime(bmifile)) + batchcmds:set_depcache(target:dependfile(bmifile)) end end end -- build module files function build_modules(target, batchcmds, objectfiles, modules, opt) - local cachedir = common.modules_cachedir(target) local compinst = target:compiler("cxx") local mapper_file = _get_module_mapper() local common_args = {"-x", "c++"} + + -- get cachedirs + local cachedir = common.modules_cachedir(target) + local projectdir = os.projectdir() for _, objectfile in ipairs(objectfiles) do local m = modules[objectfile] diff --git a/xmake/rules/c++/modules/modules_support/msvc.lua b/xmake/rules/c++/modules/modules_support/msvc.lua index fa5741676..5006b4d9f 100644 --- a/xmake/rules/c++/modules/modules_support/msvc.lua +++ b/xmake/rules/c++/modules/modules_support/msvc.lua @@ -109,8 +109,8 @@ function generate_dependencies(target, sourcebatch, opt) end end --- generate target header units -function generate_headerunits(target, batchcmds, headerunits, opt) +-- generate target stl header units +function generate_stl_headerunits(target, batchcmds, headerunits, opt) local compinst = target:compiler("cxx") local toolchain = target:toolchain("msvc") local vcvars = toolchain:config("vcvars") @@ -123,62 +123,84 @@ function generate_headerunits(target, batchcmds, headerunits, opt) assert(headerunitflag and headernameflag and exportheaderflag, "compiler(msvc): does not support c++ header units!") -- get cachedirs - local cachedir = common.modules_cachedir(target) local stlcachedir = common.stlmodules_cachedir(target) -- build headerunits local common_args = {"/TP", exportheaderflag, "/c"} local objectfiles = {} - local public_flags = {} - local private_flags = {} - local projectdir = os.projectdir() + local flags = {} for _, headerunit in ipairs(headerunits) do - if not headerunit.stl then - local file = path.relative(headerunit.path, target:scriptdir()) - local objectfile = target:objectfile(file) - local outputdir - if headerunit.type == ":quote" then - outputdir = path.join(cachedir, path.directory(path.relative(headerunit.path, projectdir))) - else - outputdir = path.join(cachedir, path.directory(headerunit.path):sub(3)) - end - if not os.isdir(outputdir) then - os.mkdir(outputdir) - end + local bmifile = path.join(stlcachedir, headerunit.name .. get_bmi_extension()) + if not os.isfile(bmifile) then + local args = {exportheaderflag, headernameflag .. ":angle", headerunit.name, ifcoutputflag, stlcachedir} + batchcmds:show_progress(opt.progress, "${color.build.object}generating.cxx.headerunit.bmi %s", headerunit.name) + batchcmds:vrunv(compinst:program(), table.join(compinst:compflags({target = target}), args), {envs = vcvars}) + end - local bmifilename = path.basename(objectfile) .. get_bmi_extension() - local bmifile = (outputdir and path.join(outputdir, bmifilename) or bmifilename) - if not os.isdir(path.directory(objectfile)) then - os.mkdir(path.directory(objectfile)) - end + batchcmds:set_depmtime(os.mtime(bmifile)) + batchcmds:set_depcache(target:dependfile(bmifile)) - local args = {headernameflag .. headerunit.type, headerunit.path, ifcoutputflag, outputdir, "/Fo" .. objectfile} - batchcmds:show_progress(opt.progress, "${color.build.object}generating.cxx.headerunit.bmi %s", headerunit.name) - batchcmds:vrunv(compinst:program(), table.join(compinst:compflags({target = target}), common_args, args), {envs = vcvars}) + local flag = {headerunitflag .. ":angle", headerunit.name .. "=" .. headerunit.name .. get_bmi_extension()} + table.join2(flags, flag) + end + return flags +end - batchcmds:add_depfiles(headerunit.path) - batchcmds:set_depmtime(os.mtime(bmifile)) - batchcmds:set_depcache(target:dependfile(bmifile)) - batchcmds:set_depmtime(os.mtime(objectfile)) - batchcmds:set_depcache(target:dependfile(objectfile)) +-- generate target user header units +function generate_user_headerunits(target, batchcmds, headerunits, opt) + local compinst = target:compiler("cxx") + local toolchain = target:toolchain("msvc") + local vcvars = toolchain:config("vcvars") - local flag = {headerunitflag .. headerunit.type, headerunit.name .. "=" .. path.relative(bmifile, cachedir)} - table.join2(public_flags, flag) - target:add("objectfiles", objectfile) - else - local bmifile = path.join(stlcachedir, headerunit.name .. get_bmi_extension()) - local args = {exportheaderflag, headernameflag .. ":angle", headerunit.name, ifcoutputflag, stlcachedir} - batchcmds:show_progress(opt.progress, "${color.build.object}generating.cxx.headerunit.bmi %s", headerunit.name) - batchcmds:vrunv(compinst:program(), table.join(compinst:compflags({target = target}), args), {envs = vcvars}) + -- get flags + local exportheaderflag = get_exportheaderflag(target) + local headerunitflag = get_headerunitflag(target) + local headernameflag = get_headernameflag(target) + local ifcoutputflag = get_ifcoutputflag(target) + assert(headerunitflag and headernameflag and exportheaderflag, "compiler(msvc): does not support c++ header units!") - batchcmds:set_depmtime(os.mtime(bmifile)) - batchcmds:set_depcache(target:dependfile(bmifile)) + -- get cachedirs + local cachedir = common.modules_cachedir(target) - local flag = {headerunitflag .. ":angle", headerunit.name .. "=" .. headerunit.name .. get_bmi_extension()} - table.join2(private_flags, flag) + -- build headerunits + local common_args = {"/TP", exportheaderflag, "/c"} + local objectfiles = {} + local flags = {} + local projectdir = os.projectdir() + for _, headerunit in ipairs(headerunits) do + local file = path.relative(headerunit.path, target:scriptdir()) + local objectfile = target:objectfile(file) + local outputdir + if headerunit.type == ":quote" then + outputdir = path.join(cachedir, path.directory(path.relative(headerunit.path, projectdir))) + else + outputdir = path.join(cachedir, path.directory(headerunit.path):sub(3)) + end + if not os.isdir(outputdir) then + os.mkdir(outputdir) end + + local bmifilename = path.basename(objectfile) .. get_bmi_extension() + local bmifile = (outputdir and path.join(outputdir, bmifilename) or bmifilename) + if not os.isdir(path.directory(objectfile)) then + os.mkdir(path.directory(objectfile)) + end + + local args = {headernameflag .. headerunit.type, headerunit.path, ifcoutputflag, outputdir, "/Fo" .. objectfile} + batchcmds:show_progress(opt.progress, "${color.build.object}generating.cxx.headerunit.bmi %s", headerunit.name) + batchcmds:vrunv(compinst:program(), table.join(compinst:compflags({target = target}), common_args, args), {envs = vcvars}) + + batchcmds:add_depfiles(headerunit.path) + batchcmds:set_depmtime(os.mtime(bmifile)) + batchcmds:set_depcache(target:dependfile(bmifile)) + batchcmds:set_depmtime(os.mtime(objectfile)) + batchcmds:set_depcache(target:dependfile(objectfile)) + + local flag = {headerunitflag .. headerunit.type, headerunit.name .. "=" .. path.relative(bmifile, cachedir)} + table.join2(flags, flag) + target:add("objectfiles", objectfile) end - return public_flags, private_flags + return flags end -- build module files diff --git a/xmake/rules/c++/modules/xmake.lua b/xmake/rules/c++/modules/xmake.lua index a1d6fdca4..7c68f25e0 100644 --- a/xmake/rules/c++/modules/xmake.lua +++ b/xmake/rules/c++/modules/xmake.lua @@ -91,15 +91,22 @@ rule("c++.build.modules.builder") -- get headerunits info local headerunits + local stl_headerunits local modules = target:data("cxx.modules") for _, objectfile in ipairs(sourcebatch.objectfiles) do local m = modules[objectfile] if m then for name, r in pairs(m.requires) do if r.method ~= "by-name" then - headerunits = headerunits or {} local unittype = r.method == "include-angle" and ":angle" or ":quote" - table.insert(headerunits, {name = name, path = r.path, type = unittype, stl = stl_headers.is_stl_header(name)}) + + if stl_headers.is_stl_header(name) then + stl_headerunits = stl_headerunits or {} + table.insert(stl_headerunits, {name = name, path = r.path, type = unittype}) + else + headerunits = headerunits or {} + table.insert(headerunits, {name = name, path = r.path, type = unittype,}) + end end end end @@ -107,17 +114,22 @@ rule("c++.build.modules.builder") -- generate headerunits local headerunits_flags - local private_headerunits_flags local modules_support = common.modules_support(target) + -- build stl header units as other headerunits may need them + if stl_headerunits then + headerunits_flags = headerunits_flags or {} + table.join2(headerunits_flags, modules_support.generate_stl_headerunits(target, batchcmds, stl_headerunits, opt)) + + -- force STL header unit generation + batchcmds:runcmds(opt) + end if headerunits then - headerunits_flags, private_headerunits_flags = modules_support.generate_headerunits(target, batchcmds, headerunits, opt) + headerunits_flags = headerunits_flags or {} + table.join2(headerunits_flags, modules_support.generate_user_headerunits(target, batchcmds, headerunits, opt)) end if headerunits_flags then target:add("cxxflags", headerunits_flags, {force = true, expand = false}) end - if private_headerunits_flags then - target:add("cxxflags", private_headerunits_flags, {force = true, expand = false}) - end -- topological sort local objectfiles = common.sort_modules_by_dependencies(sourcebatch.objectfiles, modules) -- cgit v1.3.1 From bd2fc3f699e468604bdf489c3348d22962f14012 Mon Sep 17 00:00:00 2001 From: Arthur LAURENT Date: Fri, 5 Aug 2022 03:26:43 +0200 Subject: Use batchcmds:mkdir instead of os.mkdir when possible --- xmake/rules/c++/modules/modules_support/clang.lua | 6 +++--- xmake/rules/c++/modules/modules_support/gcc.lua | 6 +++--- xmake/rules/c++/modules/modules_support/msvc.lua | 6 +++--- 3 files changed, 9 insertions(+), 9 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 e023acccb..4ab3c3892 100644 --- a/xmake/rules/c++/modules/modules_support/clang.lua +++ b/xmake/rules/c++/modules/modules_support/clang.lua @@ -185,13 +185,13 @@ function generate_user_headerunits(target, batchcmds, headerunits, opt) outdir = path.join(cachedir, path.directory(headerunit.path)) end if not os.isdir(outdir) then - os.mkdir(outdir) + batchcmds:mkdir(outdir) end local bmifilename = path.basename(objectfile) .. get_bmi_extension() local bmifile = (outdir and path.join(outdir, bmifilename) or bmifilename) if not os.isdir(path.directory(objectfile)) then - os.mkdir(path.directory(objectfile)) + batchcmds:mkdir(path.directory(objectfile)) end local args = { modulecachepathflag .. cachedir, emitmoduleflag, "-c", "-o", bmifile} @@ -238,7 +238,7 @@ function build_modules(target, batchcmds, objectfiles, modules, opt) local m = modules[objectfile] if m then if not os.isdir(path.directory(objectfile)) then - os.mkdir(path.directory(objectfile)) + batchcmds:mkdir(path.directory(objectfile)) end local args = { emitmoduleinterfaceflag } diff --git a/xmake/rules/c++/modules/modules_support/gcc.lua b/xmake/rules/c++/modules/modules_support/gcc.lua index 23e89a30b..a3ef5c8a8 100644 --- a/xmake/rules/c++/modules/modules_support/gcc.lua +++ b/xmake/rules/c++/modules/modules_support/gcc.lua @@ -194,13 +194,13 @@ function generate_user_headerunits(target, batchcmds, headerunits, opt) outdir = path.join(cachedir, path.directory(headerunit.path)) end if not os.isdir(outdir) then - os.mkdir(outdir) + batchcmds:mkdir(outdir) end local bmifilename = path.basename(objectfile) .. get_bmi_extension() local bmifile = (outdir and path.join(outdir, bmifilename) or bmifilename) if not os.isdir(path.directory(objectfile)) then - os.mkdir(path.directory(objectfile)) + batchcmds:mkdir(path.directory(objectfile)) end local args = { "-c" } @@ -239,7 +239,7 @@ function build_modules(target, batchcmds, objectfiles, modules, opt) local m = modules[objectfile] if m then if not os.isdir(path.directory(objectfile)) then - os.mkdir(path.directory(objectfile)) + batchcmds:mkdir(path.directory(objectfile)) end local args = {"-o", objectfile} diff --git a/xmake/rules/c++/modules/modules_support/msvc.lua b/xmake/rules/c++/modules/modules_support/msvc.lua index 5006b4d9f..abc7f7319 100644 --- a/xmake/rules/c++/modules/modules_support/msvc.lua +++ b/xmake/rules/c++/modules/modules_support/msvc.lua @@ -177,13 +177,13 @@ function generate_user_headerunits(target, batchcmds, headerunits, opt) outputdir = path.join(cachedir, path.directory(headerunit.path):sub(3)) end if not os.isdir(outputdir) then - os.mkdir(outputdir) + batchcmds:mkdir(outputdir) end local bmifilename = path.basename(objectfile) .. get_bmi_extension() local bmifile = (outputdir and path.join(outputdir, bmifilename) or bmifilename) if not os.isdir(path.directory(objectfile)) then - os.mkdir(path.directory(objectfile)) + batchcmds:mkdir(path.directory(objectfile)) end local args = {headernameflag .. headerunit.type, headerunit.path, ifcoutputflag, outputdir, "/Fo" .. objectfile} @@ -230,7 +230,7 @@ function build_modules(target, batchcmds, objectfiles, modules, opt) local m = modules[objectfile] if m then if not os.isdir(path.directory(objectfile)) then - os.mkdir(path.directory(objectfile)) + batchcmds:mkdir(path.directory(objectfile)) end local args = {"/c", "/Fo" .. objectfile} -- cgit v1.3.1 From 886364620b81ad0024e5e98bee9b5a44e6c6f160 Mon Sep 17 00:00:00 2001 From: Arthur LAURENT Date: Fri, 5 Aug 2022 03:30:52 +0200 Subject: Remove useless isdir checks --- xmake/rules/c++/modules/modules_support/clang.lua | 12 +++--------- xmake/rules/c++/modules/modules_support/gcc.lua | 12 +++--------- xmake/rules/c++/modules/modules_support/msvc.lua | 12 +++--------- 3 files changed, 9 insertions(+), 27 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 4ab3c3892..cc6e2f927 100644 --- a/xmake/rules/c++/modules/modules_support/clang.lua +++ b/xmake/rules/c++/modules/modules_support/clang.lua @@ -184,15 +184,11 @@ function generate_user_headerunits(target, batchcmds, headerunits, opt) else outdir = path.join(cachedir, path.directory(headerunit.path)) end - if not os.isdir(outdir) then - batchcmds:mkdir(outdir) - end + batchcmds:mkdir(outdir) local bmifilename = path.basename(objectfile) .. get_bmi_extension() local bmifile = (outdir and path.join(outdir, bmifilename) or bmifilename) - if not os.isdir(path.directory(objectfile)) then - batchcmds:mkdir(path.directory(objectfile)) - end + batchcmds:mkdir(path.directory(objectfile)) local args = { modulecachepathflag .. cachedir, emitmoduleflag, "-c", "-o", bmifile} if headerunit.type == ":quote" then @@ -237,9 +233,7 @@ function build_modules(target, batchcmds, objectfiles, modules, opt) for _, objectfile in ipairs(objectfiles) do local m = modules[objectfile] if m then - if not os.isdir(path.directory(objectfile)) then - batchcmds:mkdir(path.directory(objectfile)) - end + batchcmds:mkdir(path.directory(objectfile)) local args = { emitmoduleinterfaceflag } local bmiflags = {} diff --git a/xmake/rules/c++/modules/modules_support/gcc.lua b/xmake/rules/c++/modules/modules_support/gcc.lua index a3ef5c8a8..1c53d22b5 100644 --- a/xmake/rules/c++/modules/modules_support/gcc.lua +++ b/xmake/rules/c++/modules/modules_support/gcc.lua @@ -193,15 +193,11 @@ function generate_user_headerunits(target, batchcmds, headerunits, opt) else outdir = path.join(cachedir, path.directory(headerunit.path)) end - if not os.isdir(outdir) then - batchcmds:mkdir(outdir) - end + batchcmds:mkdir(outdir) local bmifilename = path.basename(objectfile) .. get_bmi_extension() local bmifile = (outdir and path.join(outdir, bmifilename) or bmifilename) - if not os.isdir(path.directory(objectfile)) then - batchcmds:mkdir(path.directory(objectfile)) - end + batchcmds:mkdir(path.directory(objectfile)) local args = { "-c" } local headerunit_path @@ -238,9 +234,7 @@ function build_modules(target, batchcmds, objectfiles, modules, opt) for _, objectfile in ipairs(objectfiles) do local m = modules[objectfile] if m then - if not os.isdir(path.directory(objectfile)) then - batchcmds:mkdir(path.directory(objectfile)) - end + batchcmds:mkdir(path.directory(objectfile)) local args = {"-o", objectfile} for name, provide in pairs(m.provides) do diff --git a/xmake/rules/c++/modules/modules_support/msvc.lua b/xmake/rules/c++/modules/modules_support/msvc.lua index abc7f7319..93eef7c8c 100644 --- a/xmake/rules/c++/modules/modules_support/msvc.lua +++ b/xmake/rules/c++/modules/modules_support/msvc.lua @@ -176,15 +176,11 @@ function generate_user_headerunits(target, batchcmds, headerunits, opt) else outputdir = path.join(cachedir, path.directory(headerunit.path):sub(3)) end - if not os.isdir(outputdir) then - batchcmds:mkdir(outputdir) - end + batchcmds:mkdir(outputdir) local bmifilename = path.basename(objectfile) .. get_bmi_extension() local bmifile = (outputdir and path.join(outputdir, bmifilename) or bmifilename) - if not os.isdir(path.directory(objectfile)) then - batchcmds:mkdir(path.directory(objectfile)) - end + batchcmds:mkdir(path.directory(objectfile)) local args = {headernameflag .. headerunit.type, headerunit.path, ifcoutputflag, outputdir, "/Fo" .. objectfile} batchcmds:show_progress(opt.progress, "${color.build.object}generating.cxx.headerunit.bmi %s", headerunit.name) @@ -229,9 +225,7 @@ function build_modules(target, batchcmds, objectfiles, modules, opt) for _, objectfile in ipairs(objectfiles) do local m = modules[objectfile] if m then - if not os.isdir(path.directory(objectfile)) then - batchcmds:mkdir(path.directory(objectfile)) - end + batchcmds:mkdir(path.directory(objectfile)) local args = {"/c", "/Fo" .. objectfile} local bmiflags = {} -- cgit v1.3.1 From b370625fbf37fe5e957677ec4c04ec3503d0da90 Mon Sep 17 00:00:00 2001 From: Arthur LAURENT Date: Fri, 5 Aug 2022 04:40:47 +0200 Subject: Handle angle relative path --- xmake/rules/c++/modules/modules_support/msvc.lua | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (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 93eef7c8c..04d34f02c 100644 --- a/xmake/rules/c++/modules/modules_support/msvc.lua +++ b/xmake/rules/c++/modules/modules_support/msvc.lua @@ -174,7 +174,8 @@ function generate_user_headerunits(target, batchcmds, headerunits, opt) if headerunit.type == ":quote" then outputdir = path.join(cachedir, path.directory(path.relative(headerunit.path, projectdir))) else - outputdir = path.join(cachedir, path.directory(headerunit.path):sub(3)) + -- if path is relative then its a subtarget path + outputdir = path.join(cachedir, path.is_absolute(headerunit.path) and path.directory(headerunit.path):sub(3) or headerunit.path) end batchcmds:mkdir(outputdir) -- cgit v1.3.1 From 9051b99608fe2f339eea7ac4c9eab8b799e230df Mon Sep 17 00:00:00 2001 From: Arthur LAURENT Date: Fri, 5 Aug 2022 04:41:46 +0200 Subject: Move headerunits extracting into a dedicated function --- xmake/rules/c++/modules/modules_support/common.lua | 31 ++++++++++++++++++++-- xmake/rules/c++/modules/modules_support/msvc.lua | 2 +- xmake/rules/c++/modules/xmake.lua | 28 +++---------------- 3 files changed, 34 insertions(+), 27 deletions(-) (limited to 'xmake/rules/c++/modules/modules_support/msvc.lua') diff --git a/xmake/rules/c++/modules/modules_support/common.lua b/xmake/rules/c++/modules/modules_support/common.lua index a8b36e0fa..18647ded1 100644 --- a/xmake/rules/c++/modules/modules_support/common.lua +++ b/xmake/rules/c++/modules/modules_support/common.lua @@ -26,6 +26,7 @@ import("core.tool.compiler") import("core.cache.memcache", {alias = "_memcache"}) import("core.project.project") import("lib.detect.find_file") +import("stl_headers") -- get memcache function memcache() @@ -53,12 +54,38 @@ function modules_cachedir(target) return cachedir end +-- get headerunits info +function get_headerunits(target, sourcebatch) + local headerunits + local stl_headerunits + local modules = target:data("cxx.modules") + for _, objectfile in ipairs(sourcebatch.objectfiles) do + local m = modules[objectfile] + if m then + for name, r in pairs(m.requires) do + if r.method ~= "by-name" then + local unittype = r.method == "include-angle" and ":angle" or ":quote" + + if stl_headers.is_stl_header(name) then + stl_headerunits = stl_headerunits or {} + table.insert(stl_headerunits, {name = name, path = r.path, type = unittype}) + else + headerunits = headerunits or {} + table.insert(headerunits, {name = name, path = r.path, type = unittype}) + end + end + end + end + end + return headerunits, stl_headerunits +end + -- patch sourcebatch function patch_sourcebatch(target, sourcebatch, opt) local cachedir = modules_cachedir(target) sourcebatch.sourcekind = "cxx" - sourcebatch.objectfiles = sourcebatch.objectfiles or {} - sourcebatch.dependfiles = sourcebatch.dependfiles or {} + sourcebatch.objectfiles = {} + sourcebatch.dependfiles = {} for _, sourcefile in ipairs(sourcebatch.sourcefiles) do local objectfile = target:objectfile(sourcefile) local dependfile = target:dependfile(objectfile) diff --git a/xmake/rules/c++/modules/modules_support/msvc.lua b/xmake/rules/c++/modules/modules_support/msvc.lua index 04d34f02c..2c3818995 100644 --- a/xmake/rules/c++/modules/modules_support/msvc.lua +++ b/xmake/rules/c++/modules/modules_support/msvc.lua @@ -183,7 +183,7 @@ function generate_user_headerunits(target, batchcmds, headerunits, opt) local bmifile = (outputdir and path.join(outputdir, bmifilename) or bmifilename) batchcmds:mkdir(path.directory(objectfile)) - local args = {headernameflag .. headerunit.type, headerunit.path, ifcoutputflag, outputdir, "/Fo" .. objectfile} + local args = {headernameflag .. headerunit.type, path.normalize(headerunit.path), ifcoutputflag, outputdir, "/Fo" .. objectfile} batchcmds:show_progress(opt.progress, "${color.build.object}generating.cxx.headerunit.bmi %s", headerunit.name) batchcmds:vrunv(compinst:program(), table.join(compinst:compflags({target = target}), common_args, args), {envs = vcvars}) diff --git a/xmake/rules/c++/modules/xmake.lua b/xmake/rules/c++/modules/xmake.lua index 7c68f25e0..45ba38ca8 100644 --- a/xmake/rules/c++/modules/xmake.lua +++ b/xmake/rules/c++/modules/xmake.lua @@ -82,35 +82,14 @@ rule("c++.build.modules.builder") return end - -- patch sourcebatch import("modules_support.common") import("modules_support.stl_headers") - sourcebatch.objectfiles = {} - sourcebatch.dependfiles = {} + + -- patch sourcebatch common.patch_sourcebatch(target, sourcebatch, opt) -- get headerunits info - local headerunits - local stl_headerunits - local modules = target:data("cxx.modules") - for _, objectfile in ipairs(sourcebatch.objectfiles) do - local m = modules[objectfile] - if m then - for name, r in pairs(m.requires) do - if r.method ~= "by-name" then - local unittype = r.method == "include-angle" and ":angle" or ":quote" - - if stl_headers.is_stl_header(name) then - stl_headerunits = stl_headerunits or {} - table.insert(stl_headerunits, {name = name, path = r.path, type = unittype}) - else - headerunits = headerunits or {} - table.insert(headerunits, {name = name, path = r.path, type = unittype,}) - end - end - end - end - end + local headerunits, stl_headerunits = common.get_headerunits(target, sourcebatch) -- generate headerunits local headerunits_flags @@ -132,6 +111,7 @@ rule("c++.build.modules.builder") end -- topological sort + local modules = target:data("cxx.modules") local objectfiles = common.sort_modules_by_dependencies(sourcebatch.objectfiles, modules) modules_support.build_modules(target, batchcmds, objectfiles, modules, opt) end) -- cgit v1.3.1 From 4cdf4838df5d5903b8d2ac31c9a169c5d88a2ebb Mon Sep 17 00:00:00 2001 From: Arthur LAURENT Date: Fri, 5 Aug 2022 04:44:30 +0200 Subject: outputdir is never nil --- xmake/rules/c++/modules/modules_support/msvc.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 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 2c3818995..3f371c5c7 100644 --- a/xmake/rules/c++/modules/modules_support/msvc.lua +++ b/xmake/rules/c++/modules/modules_support/msvc.lua @@ -180,10 +180,10 @@ function generate_user_headerunits(target, batchcmds, headerunits, opt) batchcmds:mkdir(outputdir) local bmifilename = path.basename(objectfile) .. get_bmi_extension() - local bmifile = (outputdir and path.join(outputdir, bmifilename) or bmifilename) + local bmifile = path.join(outputdir, bmifilename) batchcmds:mkdir(path.directory(objectfile)) - local args = {headernameflag .. headerunit.type, path.normalize(headerunit.path), ifcoutputflag, outputdir, "/Fo" .. objectfile} + local args = {headernameflag .. headerunit.type, headerunit.path, ifcoutputflag, outputdir, "/Fo" .. objectfile} batchcmds:show_progress(opt.progress, "${color.build.object}generating.cxx.headerunit.bmi %s", headerunit.name) batchcmds:vrunv(compinst:program(), table.join(compinst:compflags({target = target}), common_args, args), {envs = vcvars}) -- cgit v1.3.1 From e4179556134ffba995299eb3e949c48ad80d8678 Mon Sep 17 00:00:00 2001 From: Arthur LAURENT Date: Fri, 5 Aug 2022 05:11:14 +0200 Subject: Fix incorrect usage of set_depmtime/set_depcache --- xmake/rules/c++/modules/modules_support/clang.lua | 35 ++++++++++++++--------- xmake/rules/c++/modules/modules_support/gcc.lua | 29 ++++++++++++------- xmake/rules/c++/modules/modules_support/msvc.lua | 34 +++++++++++++--------- 3 files changed, 62 insertions(+), 36 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 cc6e2f927..c91decb97 100644 --- a/xmake/rules/c++/modules/modules_support/clang.lua +++ b/xmake/rules/c++/modules/modules_support/clang.lua @@ -141,6 +141,8 @@ function generate_stl_headerunits(target, batchcmds, headerunits, opt) -- build headerunits local projectdir = os.projectdir() local flags = {} + local bmifiles = {} + local depmtime = 0 for i, headerunit in ipairs(headerunits) do local bmifile = path.join(stlcachedir, headerunit.name .. get_bmi_extension()) if not os.isfile(bmifile) then @@ -149,11 +151,12 @@ function generate_stl_headerunits(target, batchcmds, headerunits, opt) batchcmds:vrunv(compinst:program(), table.join(compinst:compflags({target = target}), args)) end - batchcmds:set_depmtime(os.mtime(bmifile)) - batchcmds:set_depcache(target:dependfile(bmifile)) - table.insert(flags, modulefileflag .. bmifile) + table.append(bmifiles, bmifile) + depmtime = math.max(depmtime, os.mtime(bmifile)) end + batchcmds:set_depmtime(depmtime) + batchcmds:set_depcache(target:dependfile(bmifiles)) return flags end @@ -174,6 +177,8 @@ function generate_user_headerunits(target, batchcmds, headerunits, opt) local objectfiles = {} local flags = {} local projectdir = os.projectdir() + local bmifiles = {} + local depmtime = 0 for _, headerunit in ipairs(headerunits) do local file = path.relative(headerunit.path, target:scriptdir()) local objectfile = target:objectfile(file) @@ -201,11 +206,13 @@ function generate_user_headerunits(target, batchcmds, headerunits, opt) batchcmds:vrunv(compinst:program(), table.join(compinst:compflags({target = target}), args)) batchcmds:add_depfiles(headerunit.path) - batchcmds:set_depmtime(os.mtime(bmifile)) - batchcmds:set_depcache(target:dependfile(bmifile)) table.insert(flags, modulefileflag .. bmifile) + table.append(bmifiles, bmifile) + depmtime = math.max(depmtime, os.mtime(bmifile)) end + batchcmds:set_depmtime(depmtime) + batchcmds:set_depcache(target:dependfile(bmifiles)) return flags end @@ -229,7 +236,10 @@ function build_modules(target, batchcmds, objectfiles, modules, opt) end end + -- build modules local common_args = {modulecachepathflag .. cachedir} + local bmifiles = {} + local depmtime = 0 for _, objectfile in ipairs(objectfiles) do local m = modules[objectfile] if m then @@ -237,34 +247,33 @@ function build_modules(target, batchcmds, objectfiles, modules, opt) local args = { emitmoduleinterfaceflag } local bmiflags = {} - local bmifiles = {} + local bmifiles_ = {} for name, provide in pairs(m.provides) do batchcmds:show_progress(opt.progress, "${color.build.object}generating.cxx.module.bmi %s", name) local bmifile = provide.bmi table.join2(args, { "-c", "-x", "c++-module", "--precompile", provide.sourcefile, "-o", bmifile }) - table.join2(bmifiles, bmifile) + table.append(bmifiles_, bmifile) batchcmds:add_depfiles(provide.sourcefile) - batchcmds:set_depmtime(os.mtime(bmifile)) - batchcmds:set_depcache(target:dependfile(bmifile)) table.join2(bmiflags, {modulefileflag .. bmifile}) + depmtime = math.max(depmtime, os.mtime(bmifile)) end batchcmds:vrunv(compinst:program(), table.join(compinst:compflags({target = target}), common_args, args)) - batchcmds:vrunv(compinst:program(), table.join(compinst:compflags({target = target}), common_args, bmifiles, {"-c", "-o", objectfile})) - - batchcmds:set_depmtime(os.mtime(objectfile)) - batchcmds:set_depcache(target:dependfile(objectfile)) + batchcmds:vrunv(compinst:program(), table.join(compinst:compflags({target = target}), common_args, bmifiles_, {"-c", "-o", objectfile})) target:add("cxxflags", bmiflags, {public = true, force = true}) target:add("objectfiles", objectfile) for _, f in ipairs(bmiflags) do target:data_add("cxx.modules.flags", f) end + table.join2(bmifiles, bmifiles_) end end + batchcmds:set_depmtime(depmtime) + batchcmds:set_depcache(target:dependfile(bmifiles)) end function get_bmi_extension() diff --git a/xmake/rules/c++/modules/modules_support/gcc.lua b/xmake/rules/c++/modules/modules_support/gcc.lua index 1c53d22b5..c23ced122 100644 --- a/xmake/rules/c++/modules/modules_support/gcc.lua +++ b/xmake/rules/c++/modules/modules_support/gcc.lua @@ -159,6 +159,8 @@ function generate_stl_headerunits(target, batchcmds, headerunits, opt) -- build headerunits local projectdir = os.projectdir() + local bmifiles = {} + local depmtime = 0 for i, headerunit in ipairs(headerunits) do local bmifile = path.join(stlcachedir, headerunit.name .. get_bmi_extension()) if _add_module_to_mapper(mapper_file, headerunit.path, path.absolute(bmifile, projectdir)) then @@ -166,11 +168,12 @@ function generate_stl_headerunits(target, batchcmds, headerunits, opt) batchcmds:show_progress(opt.progress, "${color.build.object}generating.cxx.headerunit.bmi %s", headerunit.name) batchcmds:vrunv(compinst:program(), table.join(compinst:compflags({target = target}), args)) - - batchcmds:set_depmtime(os.mtime(bmifile)) - batchcmds:set_depcache(target:dependfile(bmifile)) end + table.append(bmifiles, bmifile) + depmtime = math.max(depmtime, os.mtime(bmifile)) end + batchcmds:set_depmtime(depmtime) + batchcmds:set_depcache(target:dependfile(bmifiles)) end -- generate target user header units @@ -183,6 +186,8 @@ function generate_user_headerunits(target, batchcmds, headerunits, opt) -- build headerunits local projectdir = os.projectdir() + local bmifiles = {} + local depmtime = 0 for _, headerunit in ipairs(headerunits) do local file = path.relative(headerunit.path, projectdir) local objectfile = target:objectfile(file) @@ -215,10 +220,12 @@ function generate_user_headerunits(target, batchcmds, headerunits, opt) batchcmds:vrunv(compinst:program(), table.join(compinst:compflags({target = target}), args)) batchcmds:add_depfiles(headerunit.path) - batchcmds:set_depmtime(os.mtime(bmifile)) - batchcmds:set_depcache(target:dependfile(bmifile)) end + table.append(bmifiles, bmifile) + depmtime = math.max(depmtime, os.mtime(bmifile)) end + batchcmds:set_depmtime(depmtime) + batchcmds:set_depcache(target:dependfile(bmifiles)) end -- build module files @@ -230,7 +237,10 @@ function build_modules(target, batchcmds, objectfiles, modules, opt) -- get cachedirs local cachedir = common.modules_cachedir(target) + -- build modules local projectdir = os.projectdir() + local bmifiles = {} + local depmtime = 0 for _, objectfile in ipairs(objectfiles) do local m = modules[objectfile] if m then @@ -245,19 +255,18 @@ function build_modules(target, batchcmds, objectfiles, modules, opt) table.join2(args, {"-c", provide.sourcefile}) batchcmds:add_depfiles(provide.sourcefile) - batchcmds:set_depmtime(os.mtime(bmifile)) - batchcmds:set_depcache(target:dependfile(bmifile)) end + table.append(bmifiles, bmifile) + depmtime = math.max(depmtime, os.mtime(bmifile)) end batchcmds:vrunv(compinst:program(), table.join(compinst:compflags({target = target}), common_args, args)) - batchcmds:set_depmtime(os.mtime(objectfile)) - batchcmds:set_depcache(target:dependfile(objectfile)) - target:add("objectfiles", objectfile) end end + batchcmds:set_depmtime(depmtime) + batchcmds:set_depcache(target:dependfile(bmifiles)) end function get_bmi_extension() diff --git a/xmake/rules/c++/modules/modules_support/msvc.lua b/xmake/rules/c++/modules/modules_support/msvc.lua index 3f371c5c7..89cc35f6b 100644 --- a/xmake/rules/c++/modules/modules_support/msvc.lua +++ b/xmake/rules/c++/modules/modules_support/msvc.lua @@ -129,6 +129,8 @@ function generate_stl_headerunits(target, batchcmds, headerunits, opt) local common_args = {"/TP", exportheaderflag, "/c"} local objectfiles = {} local flags = {} + local bmifiles = {} + local depmtime = 0 for _, headerunit in ipairs(headerunits) do local bmifile = path.join(stlcachedir, headerunit.name .. get_bmi_extension()) if not os.isfile(bmifile) then @@ -137,12 +139,14 @@ function generate_stl_headerunits(target, batchcmds, headerunits, opt) batchcmds:vrunv(compinst:program(), table.join(compinst:compflags({target = target}), args), {envs = vcvars}) end - batchcmds:set_depmtime(os.mtime(bmifile)) - batchcmds:set_depcache(target:dependfile(bmifile)) - local flag = {headerunitflag .. ":angle", headerunit.name .. "=" .. headerunit.name .. get_bmi_extension()} table.join2(flags, flag) + + table.append(bmifiles, bmifile) + depmtime = math.max(depmtime, os.mtime(bmifile)) end + batchcmds:set_depmtime(depmtime) + batchcmds:set_depcache(target:dependfile(bmifiles)) return flags end @@ -167,6 +171,8 @@ function generate_user_headerunits(target, batchcmds, headerunits, opt) local objectfiles = {} local flags = {} local projectdir = os.projectdir() + local bmifiles = {} + local depmtime = 0 for _, headerunit in ipairs(headerunits) do local file = path.relative(headerunit.path, target:scriptdir()) local objectfile = target:objectfile(file) @@ -188,15 +194,16 @@ function generate_user_headerunits(target, batchcmds, headerunits, opt) batchcmds:vrunv(compinst:program(), table.join(compinst:compflags({target = target}), common_args, args), {envs = vcvars}) batchcmds:add_depfiles(headerunit.path) - batchcmds:set_depmtime(os.mtime(bmifile)) - batchcmds:set_depcache(target:dependfile(bmifile)) - batchcmds:set_depmtime(os.mtime(objectfile)) - batchcmds:set_depcache(target:dependfile(objectfile)) local flag = {headerunitflag .. headerunit.type, headerunit.name .. "=" .. path.relative(bmifile, cachedir)} table.join2(flags, flag) target:add("objectfiles", objectfile) + + table.append(bmifiles, bmifile) + depmtime = math.max(depmtime, os.mtime(bmifile)) end + batchcmds:set_depmtime(depmtime) + batchcmds:set_depcache(target:dependfile(bmifiles)) return flags end @@ -221,8 +228,10 @@ function build_modules(target, batchcmds, objectfiles, modules, opt) end end - -- compile module files to bmi files + -- build modules local common_args = {"/TP"} + local bmifiles = {} + local depmtime = 0 for _, objectfile in ipairs(objectfiles) do local m = modules[objectfile] if m then @@ -237,17 +246,14 @@ function build_modules(target, batchcmds, objectfiles, modules, opt) table.join2(args, {interfaceflag, ifcoutputflag, bmifile, provide.sourcefile}) batchcmds:add_depfiles(provide.sourcefile) - batchcmds:set_depmtime(os.mtime(bmifile)) - batchcmds:set_depcache(target:dependfile(bmifile)) table.join2(bmiflags, {referenceflag, name .. "=" .. path.filename(bmifile)}) + table.append(bmifiles, bmifile) + depmtime = math.max(depmtime, os.mtime(bmifile)) end batchcmds:vrunv(compinst:program(), table.join(compinst:compflags({target = target}), common_args, args, bmi_args), {envs = vcvars}) - batchcmds:set_depmtime(os.mtime(objectfile)) - batchcmds:set_depcache(target:dependfile(objectfile)) - target:add("cxxflags", bmiflags, {force = true, expand = false}) for _, f in ipairs(bmiflags) do target:data_add("cxx.modules.flags", f) @@ -255,6 +261,8 @@ function build_modules(target, batchcmds, objectfiles, modules, opt) target:add("objectfiles", objectfile) end end + batchcmds:set_depmtime(depmtime) + batchcmds:set_depcache(target:dependfile(bmifiles)) end function get_bmi_extension() -- cgit v1.3.1 From 913fecaf3b83198105cd56d10156b1adbc901a7e Mon Sep 17 00:00:00 2001 From: Arthur LAURENT Date: Fri, 5 Aug 2022 05:34:45 +0200 Subject: Use table.insert instead of table.append --- xmake/rules/c++/modules/modules_support/clang.lua | 6 +++--- xmake/rules/c++/modules/modules_support/gcc.lua | 6 +++--- xmake/rules/c++/modules/modules_support/msvc.lua | 6 +++--- 3 files changed, 9 insertions(+), 9 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 c91decb97..90d74b654 100644 --- a/xmake/rules/c++/modules/modules_support/clang.lua +++ b/xmake/rules/c++/modules/modules_support/clang.lua @@ -152,7 +152,7 @@ function generate_stl_headerunits(target, batchcmds, headerunits, opt) end table.insert(flags, modulefileflag .. bmifile) - table.append(bmifiles, bmifile) + table.insert(bmifiles, bmifile) depmtime = math.max(depmtime, os.mtime(bmifile)) end batchcmds:set_depmtime(depmtime) @@ -208,7 +208,7 @@ function generate_user_headerunits(target, batchcmds, headerunits, opt) batchcmds:add_depfiles(headerunit.path) table.insert(flags, modulefileflag .. bmifile) - table.append(bmifiles, bmifile) + table.insert(bmifiles, bmifile) depmtime = math.max(depmtime, os.mtime(bmifile)) end batchcmds:set_depmtime(depmtime) @@ -253,7 +253,7 @@ function build_modules(target, batchcmds, objectfiles, modules, opt) local bmifile = provide.bmi table.join2(args, { "-c", "-x", "c++-module", "--precompile", provide.sourcefile, "-o", bmifile }) - table.append(bmifiles_, bmifile) + table.insert(bmifiles_, bmifile) batchcmds:add_depfiles(provide.sourcefile) diff --git a/xmake/rules/c++/modules/modules_support/gcc.lua b/xmake/rules/c++/modules/modules_support/gcc.lua index c23ced122..700e92210 100644 --- a/xmake/rules/c++/modules/modules_support/gcc.lua +++ b/xmake/rules/c++/modules/modules_support/gcc.lua @@ -169,7 +169,7 @@ function generate_stl_headerunits(target, batchcmds, headerunits, opt) batchcmds:show_progress(opt.progress, "${color.build.object}generating.cxx.headerunit.bmi %s", headerunit.name) batchcmds:vrunv(compinst:program(), table.join(compinst:compflags({target = target}), args)) end - table.append(bmifiles, bmifile) + table.insert(bmifiles, bmifile) depmtime = math.max(depmtime, os.mtime(bmifile)) end batchcmds:set_depmtime(depmtime) @@ -221,7 +221,7 @@ function generate_user_headerunits(target, batchcmds, headerunits, opt) batchcmds:add_depfiles(headerunit.path) end - table.append(bmifiles, bmifile) + table.insert(bmifiles, bmifile) depmtime = math.max(depmtime, os.mtime(bmifile)) end batchcmds:set_depmtime(depmtime) @@ -256,7 +256,7 @@ function build_modules(target, batchcmds, objectfiles, modules, opt) batchcmds:add_depfiles(provide.sourcefile) end - table.append(bmifiles, bmifile) + table.insert(bmifiles, bmifile) depmtime = math.max(depmtime, os.mtime(bmifile)) end diff --git a/xmake/rules/c++/modules/modules_support/msvc.lua b/xmake/rules/c++/modules/modules_support/msvc.lua index 89cc35f6b..22dc4485f 100644 --- a/xmake/rules/c++/modules/modules_support/msvc.lua +++ b/xmake/rules/c++/modules/modules_support/msvc.lua @@ -142,7 +142,7 @@ function generate_stl_headerunits(target, batchcmds, headerunits, opt) local flag = {headerunitflag .. ":angle", headerunit.name .. "=" .. headerunit.name .. get_bmi_extension()} table.join2(flags, flag) - table.append(bmifiles, bmifile) + table.insert(bmifiles, bmifile) depmtime = math.max(depmtime, os.mtime(bmifile)) end batchcmds:set_depmtime(depmtime) @@ -199,7 +199,7 @@ function generate_user_headerunits(target, batchcmds, headerunits, opt) table.join2(flags, flag) target:add("objectfiles", objectfile) - table.append(bmifiles, bmifile) + table.insert(bmifiles, bmifile) depmtime = math.max(depmtime, os.mtime(bmifile)) end batchcmds:set_depmtime(depmtime) @@ -248,7 +248,7 @@ function build_modules(target, batchcmds, objectfiles, modules, opt) batchcmds:add_depfiles(provide.sourcefile) table.join2(bmiflags, {referenceflag, name .. "=" .. path.filename(bmifile)}) - table.append(bmifiles, bmifile) + table.insert(bmifiles, bmifile) depmtime = math.max(depmtime, os.mtime(bmifile)) end -- cgit v1.3.1 From 08bf176c09948d0a9662ca72b804e42e90ad341d Mon Sep 17 00:00:00 2001 From: Arthur LAURENT Date: Fri, 5 Aug 2022 05:38:34 +0200 Subject: Remove incorrect usage of set_depcache --- xmake/rules/c++/modules/modules_support/clang.lua | 15 +++------------ xmake/rules/c++/modules/modules_support/gcc.lua | 9 --------- xmake/rules/c++/modules/modules_support/msvc.lua | 9 --------- 3 files changed, 3 insertions(+), 30 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 90d74b654..2cc4b0bb4 100644 --- a/xmake/rules/c++/modules/modules_support/clang.lua +++ b/xmake/rules/c++/modules/modules_support/clang.lua @@ -141,7 +141,6 @@ function generate_stl_headerunits(target, batchcmds, headerunits, opt) -- build headerunits local projectdir = os.projectdir() local flags = {} - local bmifiles = {} local depmtime = 0 for i, headerunit in ipairs(headerunits) do local bmifile = path.join(stlcachedir, headerunit.name .. get_bmi_extension()) @@ -152,11 +151,9 @@ function generate_stl_headerunits(target, batchcmds, headerunits, opt) end table.insert(flags, modulefileflag .. bmifile) - table.insert(bmifiles, bmifile) depmtime = math.max(depmtime, os.mtime(bmifile)) end batchcmds:set_depmtime(depmtime) - batchcmds:set_depcache(target:dependfile(bmifiles)) return flags end @@ -177,7 +174,6 @@ function generate_user_headerunits(target, batchcmds, headerunits, opt) local objectfiles = {} local flags = {} local projectdir = os.projectdir() - local bmifiles = {} local depmtime = 0 for _, headerunit in ipairs(headerunits) do local file = path.relative(headerunit.path, target:scriptdir()) @@ -208,11 +204,9 @@ function generate_user_headerunits(target, batchcmds, headerunits, opt) batchcmds:add_depfiles(headerunit.path) table.insert(flags, modulefileflag .. bmifile) - table.insert(bmifiles, bmifile) depmtime = math.max(depmtime, os.mtime(bmifile)) end batchcmds:set_depmtime(depmtime) - batchcmds:set_depcache(target:dependfile(bmifiles)) return flags end @@ -238,7 +232,6 @@ function build_modules(target, batchcmds, objectfiles, modules, opt) -- build modules local common_args = {modulecachepathflag .. cachedir} - local bmifiles = {} local depmtime = 0 for _, objectfile in ipairs(objectfiles) do local m = modules[objectfile] @@ -247,13 +240,13 @@ function build_modules(target, batchcmds, objectfiles, modules, opt) local args = { emitmoduleinterfaceflag } local bmiflags = {} - local bmifiles_ = {} + local bmifiles = {} for name, provide in pairs(m.provides) do batchcmds:show_progress(opt.progress, "${color.build.object}generating.cxx.module.bmi %s", name) local bmifile = provide.bmi table.join2(args, { "-c", "-x", "c++-module", "--precompile", provide.sourcefile, "-o", bmifile }) - table.insert(bmifiles_, bmifile) + table.insert(bmifiles, bmifile) batchcmds:add_depfiles(provide.sourcefile) @@ -262,18 +255,16 @@ function build_modules(target, batchcmds, objectfiles, modules, opt) end batchcmds:vrunv(compinst:program(), table.join(compinst:compflags({target = target}), common_args, args)) - batchcmds:vrunv(compinst:program(), table.join(compinst:compflags({target = target}), common_args, bmifiles_, {"-c", "-o", objectfile})) + batchcmds:vrunv(compinst:program(), table.join(compinst:compflags({target = target}), common_args, bmifiles, {"-c", "-o", objectfile})) target:add("cxxflags", bmiflags, {public = true, force = true}) target:add("objectfiles", objectfile) for _, f in ipairs(bmiflags) do target:data_add("cxx.modules.flags", f) end - table.join2(bmifiles, bmifiles_) end end batchcmds:set_depmtime(depmtime) - batchcmds:set_depcache(target:dependfile(bmifiles)) end function get_bmi_extension() diff --git a/xmake/rules/c++/modules/modules_support/gcc.lua b/xmake/rules/c++/modules/modules_support/gcc.lua index 700e92210..ee4013d3e 100644 --- a/xmake/rules/c++/modules/modules_support/gcc.lua +++ b/xmake/rules/c++/modules/modules_support/gcc.lua @@ -159,7 +159,6 @@ function generate_stl_headerunits(target, batchcmds, headerunits, opt) -- build headerunits local projectdir = os.projectdir() - local bmifiles = {} local depmtime = 0 for i, headerunit in ipairs(headerunits) do local bmifile = path.join(stlcachedir, headerunit.name .. get_bmi_extension()) @@ -169,11 +168,9 @@ function generate_stl_headerunits(target, batchcmds, headerunits, opt) batchcmds:show_progress(opt.progress, "${color.build.object}generating.cxx.headerunit.bmi %s", headerunit.name) batchcmds:vrunv(compinst:program(), table.join(compinst:compflags({target = target}), args)) end - table.insert(bmifiles, bmifile) depmtime = math.max(depmtime, os.mtime(bmifile)) end batchcmds:set_depmtime(depmtime) - batchcmds:set_depcache(target:dependfile(bmifiles)) end -- generate target user header units @@ -186,7 +183,6 @@ function generate_user_headerunits(target, batchcmds, headerunits, opt) -- build headerunits local projectdir = os.projectdir() - local bmifiles = {} local depmtime = 0 for _, headerunit in ipairs(headerunits) do local file = path.relative(headerunit.path, projectdir) @@ -221,11 +217,9 @@ function generate_user_headerunits(target, batchcmds, headerunits, opt) batchcmds:add_depfiles(headerunit.path) end - table.insert(bmifiles, bmifile) depmtime = math.max(depmtime, os.mtime(bmifile)) end batchcmds:set_depmtime(depmtime) - batchcmds:set_depcache(target:dependfile(bmifiles)) end -- build module files @@ -239,7 +233,6 @@ function build_modules(target, batchcmds, objectfiles, modules, opt) -- build modules local projectdir = os.projectdir() - local bmifiles = {} local depmtime = 0 for _, objectfile in ipairs(objectfiles) do local m = modules[objectfile] @@ -256,7 +249,6 @@ function build_modules(target, batchcmds, objectfiles, modules, opt) batchcmds:add_depfiles(provide.sourcefile) end - table.insert(bmifiles, bmifile) depmtime = math.max(depmtime, os.mtime(bmifile)) end @@ -266,7 +258,6 @@ function build_modules(target, batchcmds, objectfiles, modules, opt) end end batchcmds:set_depmtime(depmtime) - batchcmds:set_depcache(target:dependfile(bmifiles)) end function get_bmi_extension() diff --git a/xmake/rules/c++/modules/modules_support/msvc.lua b/xmake/rules/c++/modules/modules_support/msvc.lua index 22dc4485f..f3437eeab 100644 --- a/xmake/rules/c++/modules/modules_support/msvc.lua +++ b/xmake/rules/c++/modules/modules_support/msvc.lua @@ -129,7 +129,6 @@ function generate_stl_headerunits(target, batchcmds, headerunits, opt) local common_args = {"/TP", exportheaderflag, "/c"} local objectfiles = {} local flags = {} - local bmifiles = {} local depmtime = 0 for _, headerunit in ipairs(headerunits) do local bmifile = path.join(stlcachedir, headerunit.name .. get_bmi_extension()) @@ -142,11 +141,9 @@ function generate_stl_headerunits(target, batchcmds, headerunits, opt) local flag = {headerunitflag .. ":angle", headerunit.name .. "=" .. headerunit.name .. get_bmi_extension()} table.join2(flags, flag) - table.insert(bmifiles, bmifile) depmtime = math.max(depmtime, os.mtime(bmifile)) end batchcmds:set_depmtime(depmtime) - batchcmds:set_depcache(target:dependfile(bmifiles)) return flags end @@ -171,7 +168,6 @@ function generate_user_headerunits(target, batchcmds, headerunits, opt) local objectfiles = {} local flags = {} local projectdir = os.projectdir() - local bmifiles = {} local depmtime = 0 for _, headerunit in ipairs(headerunits) do local file = path.relative(headerunit.path, target:scriptdir()) @@ -199,11 +195,9 @@ function generate_user_headerunits(target, batchcmds, headerunits, opt) table.join2(flags, flag) target:add("objectfiles", objectfile) - table.insert(bmifiles, bmifile) depmtime = math.max(depmtime, os.mtime(bmifile)) end batchcmds:set_depmtime(depmtime) - batchcmds:set_depcache(target:dependfile(bmifiles)) return flags end @@ -230,7 +224,6 @@ function build_modules(target, batchcmds, objectfiles, modules, opt) -- build modules local common_args = {"/TP"} - local bmifiles = {} local depmtime = 0 for _, objectfile in ipairs(objectfiles) do local m = modules[objectfile] @@ -248,7 +241,6 @@ function build_modules(target, batchcmds, objectfiles, modules, opt) batchcmds:add_depfiles(provide.sourcefile) table.join2(bmiflags, {referenceflag, name .. "=" .. path.filename(bmifile)}) - table.insert(bmifiles, bmifile) depmtime = math.max(depmtime, os.mtime(bmifile)) end @@ -262,7 +254,6 @@ function build_modules(target, batchcmds, objectfiles, modules, opt) end end batchcmds:set_depmtime(depmtime) - batchcmds:set_depcache(target:dependfile(bmifiles)) end function get_bmi_extension() -- cgit v1.3.1 From cf4a7193ea34e3f82d710114343c7fb1f00e261d Mon Sep 17 00:00:00 2001 From: Arthur LAURENT Date: Fri, 5 Aug 2022 06:11:54 +0200 Subject: Assert on multiple provides --- xmake/rules/c++/modules/modules_support/clang.lua | 43 ++++++++++++----------- xmake/rules/c++/modules/modules_support/gcc.lua | 33 ++++++++++------- xmake/rules/c++/modules/modules_support/msvc.lua | 34 ++++++++++-------- 3 files changed, 61 insertions(+), 49 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 2cc4b0bb4..734fa5a4d 100644 --- a/xmake/rules/c++/modules/modules_support/clang.lua +++ b/xmake/rules/c++/modules/modules_support/clang.lua @@ -235,33 +235,34 @@ function build_modules(target, batchcmds, objectfiles, modules, opt) local depmtime = 0 for _, objectfile in ipairs(objectfiles) do local m = modules[objectfile] - if m then - batchcmds:mkdir(path.directory(objectfile)) - - local args = { emitmoduleinterfaceflag } - local bmiflags = {} - local bmifiles = {} - for name, provide in pairs(m.provides) do - batchcmds:show_progress(opt.progress, "${color.build.object}generating.cxx.module.bmi %s", name) - - local bmifile = provide.bmi - table.join2(args, { "-c", "-x", "c++-module", "--precompile", provide.sourcefile, "-o", bmifile }) - table.insert(bmifiles, bmifile) - - batchcmds:add_depfiles(provide.sourcefile) - - table.join2(bmiflags, {modulefileflag .. bmifile}) - depmtime = math.max(depmtime, os.mtime(bmifile)) + if m and m.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 + length = length + 1 + name = k + provide = v + if length > 1 then + raise("multiple provides are not supported now!") + end end + local bmifile = provide.bmi + + local args = { emitmoduleinterfaceflag, "-c", "-x", "c++-module", "--precompile", provide.sourcefile, "-o", bmifile } + batchcmds:show_progress(opt.progress, "${color.build.object}generating.cxx.module.bmi %s", name) + batchcmds:mkdir(path.directory(objectfile)) batchcmds:vrunv(compinst:program(), table.join(compinst:compflags({target = target}), common_args, args)) - batchcmds:vrunv(compinst:program(), table.join(compinst:compflags({target = target}), common_args, bmifiles, {"-c", "-o", objectfile})) + batchcmds:vrunv(compinst:program(), table.join(compinst:compflags({target = target}), common_args, {bmifile}, {"-c", "-o", objectfile})) + batchcmds:add_depfiles(provide.sourcefile) + + local bmiflags = modulefileflag .. bmifile target:add("cxxflags", bmiflags, {public = true, force = true}) target:add("objectfiles", objectfile) - for _, f in ipairs(bmiflags) do - target:data_add("cxx.modules.flags", f) - end + target:data_add("cxx.modules.flags", f) + depmtime = math.max(depmtime, os.mtime(bmifile)) 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 ee4013d3e..0da739a7a 100644 --- a/xmake/rules/c++/modules/modules_support/gcc.lua +++ b/xmake/rules/c++/modules/modules_support/gcc.lua @@ -236,25 +236,32 @@ function build_modules(target, batchcmds, objectfiles, modules, opt) local depmtime = 0 for _, objectfile in ipairs(objectfiles) do local m = modules[objectfile] - if m then - batchcmds:mkdir(path.directory(objectfile)) + if m and m.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 + length = length + 1 + name = k + provide = v + if length > 1 then + raise("multiple provides are not supported now!") + end + end + + local bmifile = provide.bmi + if _add_module_to_mapper(mapper_file, name, path.absolute(bmifile, projectdir)) then + local args = {"-o", objectfile, "-c", provide.sourcefile}) - local args = {"-o", objectfile} - for name, provide in pairs(m.provides) do batchcmds:show_progress(opt.progress, "${color.build.object}generating.cxx.module.bmi %s", name) + batchcmds:mkdir(path.directory(objectfile)) + batchcmds:vrunv(compinst:program(), table.join(compinst:compflags({target = target}), common_args, args)) - local bmifile = provide.bmi - if _add_module_to_mapper(mapper_file, name, path.absolute(bmifile, projectdir)) then - table.join2(args, {"-c", provide.sourcefile}) + batchcmds:add_depfiles(provide.sourcefile) + target:add("objectfiles", objectfile) - batchcmds:add_depfiles(provide.sourcefile) - end depmtime = math.max(depmtime, os.mtime(bmifile)) end - - batchcmds:vrunv(compinst:program(), table.join(compinst:compflags({target = target}), common_args, args)) - - target:add("objectfiles", objectfile) end end batchcmds:set_depmtime(depmtime) diff --git a/xmake/rules/c++/modules/modules_support/msvc.lua b/xmake/rules/c++/modules/modules_support/msvc.lua index f3437eeab..96997b5b9 100644 --- a/xmake/rules/c++/modules/modules_support/msvc.lua +++ b/xmake/rules/c++/modules/modules_support/msvc.lua @@ -227,30 +227,34 @@ function build_modules(target, batchcmds, objectfiles, modules, opt) local depmtime = 0 for _, objectfile in ipairs(objectfiles) do local m = modules[objectfile] - if m then - batchcmds:mkdir(path.directory(objectfile)) - - local args = {"/c", "/Fo" .. objectfile} - local bmiflags = {} - for name, provide in pairs(m.provides) do - batchcmds:show_progress(opt.progress, "${color.build.object}generating.cxx.module.bmi %s", name) - - local bmifile = provide.bmi - table.join2(args, {interfaceflag, ifcoutputflag, bmifile, provide.sourcefile}) - - batchcmds:add_depfiles(provide.sourcefile) - - table.join2(bmiflags, {referenceflag, name .. "=" .. path.filename(bmifile)}) - depmtime = math.max(depmtime, os.mtime(bmifile)) + if m and m.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 + length = length + 1 + name = k + provide = v + if length > 1 then + raise("multiple provides are not supported now!") + end end + local bmifile = provide.bmi + local args = {"/c", "/Fo" .. objectfile, interfaceflag, ifcoutputflag, bmifile, provide.sourcefile} + batchcmds:show_progress(opt.progress, "${color.build.object}generating.cxx.module.bmi %s", name) + batchcmds:mkdir(path.directory(objectfile)) batchcmds:vrunv(compinst:program(), table.join(compinst:compflags({target = target}), common_args, args, bmi_args), {envs = vcvars}) + batchcmds:add_depfiles(provide.sourcefile) + + local bmiflags = {referenceflag, name .. "=" .. path.filename(bmifile)} target:add("cxxflags", bmiflags, {force = true, expand = false}) for _, f in ipairs(bmiflags) do target:data_add("cxx.modules.flags", f) end target:add("objectfiles", objectfile) + depmtime = math.max(depmtime, os.mtime(bmifile)) end end batchcmds:set_depmtime(depmtime) -- cgit v1.3.1