diff options
| author | ruki <[email protected]> | 2022-08-05 21:22:47 +0800 |
|---|---|---|
| committer | GitHub <[email protected]> | 2022-08-05 21:22:47 +0800 |
| commit | 765b7041868da4a3aa08b97b8a1d73c48dbd9dbd (patch) | |
| tree | 18c29fed4cf1fb0897559925b497bfb90af3fe98 /xmake/rules/c++/modules/modules_support/clang.lua | |
| parent | 1579f0f9b0b0d255028212454a1242bfc6de4605 (diff) | |
| parent | 67568c5b063f00ed1131cf25f53bbb88d1e2db3b (diff) | |
Merge pull request #2644 from Arthapz/cxxmodules
Improve cxx20 modules support
Diffstat (limited to 'xmake/rules/c++/modules/modules_support/clang.lua')
| -rw-r--r-- | xmake/rules/c++/modules/modules_support/clang.lua | 161 |
1 files changed, 87 insertions, 74 deletions
diff --git a/xmake/rules/c++/modules/modules_support/clang.lua b/xmake/rules/c++/modules/modules_support/clang.lua index 7d841a2be..4cefed14d 100644 --- a/xmake/rules/c++/modules/modules_support/clang.lua +++ b/xmake/rules/c++/modules/modules_support/clang.lua @@ -112,7 +112,7 @@ function generate_dependencies(target, sourcebatch, opt) depend.on_changed(function() progress.show(opt.progress, "${color.build.object}generating.cxx.module.deps %s", sourcefile) - local outdir = path.translate(path.join(cachedir, path.directory(path.relative(sourcefile, target:scriptdir())))) + local outdir = path.translate(path.join(cachedir, path.directory(path.relative(sourcefile, projectdir)))) if not os.isdir(outdir) then os.mkdir(outdir) end @@ -127,79 +127,94 @@ 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) - assert(has_headerunitsupport(target), "compiler(clang): does not support c++ header units!") -- get headerunits flags local modulecachepathflag = get_modulecachepathflag(target) - local emitmoduleflag = get_emitmoduleflag(target) local modulefileflag = get_modulefileflag(target) -- build headerunits - local objectfiles = {} - local public_flags = {} - local private_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 flags = {} + 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 + 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 - 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 + table.insert(flags, modulefileflag .. bmifile) + depmtime = math.max(depmtime, os.mtime(bmifile)) + end + batchcmds:set_depmtime(depmtime) + return flags +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 +-- 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!") - 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 + -- get cachedirs + local cachedir = common.modules_cachedir(target) - 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 headerunits flags + local modulecachepathflag = get_modulecachepathflag(target) + local emitmoduleflag = get_emitmoduleflag(target) + local modulefileflag = get_modulefileflag(target) - batchcmds:add_depfiles(headerunit.path) - batchcmds:set_depmtime(os.mtime(bmifile)) - batchcmds:set_depcache(target:dependfile(bmifile)) + -- build headerunits + local objectfiles = {} + local flags = {} + local projectdir = os.projectdir() + local depmtime = 0 + for _, headerunit in ipairs(headerunits) do + local file = path.relative(headerunit.path, target:scriptdir()) + local objectfile = target:objectfile(file) - table.insert(public_flags, modulefileflag .. bmifile) + 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 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 + outdir = path.join(cachedir, path.directory(headerunit.path)) + end + batchcmds:mkdir(outdir) - batchcmds:set_depmtime(os.mtime(bmifile)) - batchcmds:set_depcache(target:dependfile(bmifile)) + local bmifilename = path.basename(objectfile) .. get_bmi_extension() + local bmifile = (outdir and path.join(outdir, bmifilename) or bmifilename) + batchcmds:mkdir(path.directory(objectfile)) - table.insert(private_flags, modulefileflag .. 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 + + 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) + + table.insert(flags, modulefileflag .. bmifile) + depmtime = math.max(depmtime, os.mtime(bmifile)) end - return public_flags, private_flags + batchcmds:set_depmtime(depmtime) + 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 @@ -215,44 +230,42 @@ function build_modules(target, batchcmds, objectfiles, modules, opt) end end + -- build modules local common_args = {modulecachepathflag .. cachedir} + local depmtime = 0 for _, objectfile in ipairs(objectfiles) do local m = modules[objectfile] - if m then - if not os.isdir(path.directory(objectfile)) then - os.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 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.join2(bmifiles, bmifile) - - batchcmds:add_depfiles(provide.sourcefile) - batchcmds:set_depmtime(os.mtime(bmifile)) - batchcmds:set_depcache(target:dependfile(bmifile)) - - table.join2(bmiflags, {modulefileflag .. bmifile}) - 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:set_depmtime(os.mtime(objectfile)) - batchcmds:set_depcache(target:dependfile(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", bmiflags) + depmtime = math.max(depmtime, os.mtime(bmifile)) end end + batchcmds:set_depmtime(depmtime) end function get_bmi_extension() |
