diff options
| author | ruki <[email protected]> | 2021-10-15 00:46:08 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2021-10-15 00:46:08 +0800 |
| commit | 6cd055242dad6d0697f340f0cdc6b8f56e63df12 (patch) | |
| tree | 54325b23c8255e466621e75fba4c0cb8e93bc7c8 | |
| parent | 3404b2307d5c191f27a140f51b78908de5e579de (diff) | |
improve gcc modules
| -rw-r--r-- | xmake/modules/private/action/build/object.lua | 6 | ||||
| -rw-r--r-- | xmake/rules/c++/modules/gcc.lua | 26 |
2 files changed, 18 insertions, 14 deletions
diff --git a/xmake/modules/private/action/build/object.lua b/xmake/modules/private/action/build/object.lua index 7a99de91e..e07ab76b7 100644 --- a/xmake/modules/private/action/build/object.lua +++ b/xmake/modules/private/action/build/object.lua @@ -85,7 +85,7 @@ function _do_build_file(target, sourcefile, opt) end -- build object -function _build_object(target, sourcefile, opt) +function build_object(target, sourcefile, opt) local script = target:script("build_file", _do_build_file) if script then script(target, sourcefile, opt) @@ -99,7 +99,7 @@ function build(target, sourcebatch, opt) opt.objectfile = sourcebatch.objectfiles[i] opt.dependfile = sourcebatch.dependfiles[i] opt.sourcekind = assert(sourcebatch.sourcekind, "%s: sourcekind not found!", sourcefile) - _build_object(target, sourcefile, opt) + build_object(target, sourcefile, opt) end end @@ -113,7 +113,7 @@ function main(target, batchjobs, sourcebatch, opt) local sourcekind = assert(sourcebatch.sourcekind, "%s: sourcekind not found!", sourcefile) batchjobs:addjob(sourcefile, function (index, total) local build_opt = table.join({objectfile = objectfile, dependfile = dependfile, sourcekind = sourcekind, progress = (index * 100) / total}, opt) - _build_object(target, sourcefile, build_opt) + build_object(target, sourcefile, build_opt) end, {rootjob = rootjob}) end end diff --git a/xmake/rules/c++/modules/gcc.lua b/xmake/rules/c++/modules/gcc.lua index 98d266c26..cd1dac970 100644 --- a/xmake/rules/c++/modules/gcc.lua +++ b/xmake/rules/c++/modules/gcc.lua @@ -20,9 +20,10 @@ -- imports import("core.tool.compiler") +import("private.action.build.object", {alias = "objectbuilder"}) -- build module files -function _build_modulefiles(target, sourcebatch, opt) +function build_with_batchjobs(target, batchjobs, sourcebatch, opt) -- get modules flag local modulesflag @@ -32,7 +33,7 @@ function _build_modulefiles(target, sourcebatch, opt) end assert(modulesflag, "compiler(gcc): does not support c++ module!") - -- attempt to compile the module files as cxx + -- we need patch objectfiles to sourcebatch for linking module objects sourcebatch.sourcekind = "cxx" sourcebatch.objectfiles = sourcebatch.objectfiles or {} sourcebatch.dependfiles = sourcebatch.dependfiles or {} @@ -43,17 +44,20 @@ function _build_modulefiles(target, sourcebatch, opt) end -- compile module files to object files - opt = table.join(opt, {configs = {force = {cxxflags = {modulesflag, "-x c++"}}}}) - import("private.action.build.object").build(target, sourcebatch, opt) + local rootjob = opt.rootjob + for i = 1, #sourcebatch.sourcefiles do + local sourcefile = sourcebatch.sourcefiles[i] + batchjobs:addjob(sourcefile, function (index, total) + opt = table.join(opt, {configs = {force = {cxxflags = {modulesflag, "-x c++"}}}}) + opt.progress = (index * 100) / total + opt.objectfile = sourcebatch.objectfiles[i] + opt.dependfile = sourcebatch.dependfiles[i] + opt.sourcekind = assert(sourcebatch.sourcekind, "%s: sourcekind not found!", sourcefile) + objectbuilder.build_object(target, sourcefile, opt) + end, {rootjob = rootjob}) + end -- add module files target:add("cxxflags", modulesflag) end -function build_with_batchjobs(target, batchjobs, sourcebatch, opt) - local rootjob = opt.rootjob - batchjobs:addjob("rule/c++.build.modules/gcc", function (index, total) - opt.progress = (index * 100) / total - _build_modulefiles(target, sourcebatch, opt) - end, {rootjob = rootjob}) -end |
