From 1559125e07441a96a937ad58a283b5732a04f2f4 Mon Sep 17 00:00:00 2001 From: Arthur LAURENT Date: Thu, 1 Dec 2022 12:50:12 +0100 Subject: compile privates module on clang --- xmake/rules/c++/modules/modules_support/clang.lua | 93 ++++++++++++++++++----- 1 file changed, 75 insertions(+), 18 deletions(-) (limited to 'xmake/rules/c++/modules/modules_support/clang.lua') diff --git a/xmake/rules/c++/modules/modules_support/clang.lua b/xmake/rules/c++/modules/modules_support/clang.lua index 10042abe2..fd7b4ca33 100644 --- a/xmake/rules/c++/modules/modules_support/clang.lua +++ b/xmake/rules/c++/modules/modules_support/clang.lua @@ -133,7 +133,7 @@ function _get_toolchain_includedirs_for_stlheaders(target, includedirs, clang) os.tryrm(tmpfile) end --- build module file +-- build interface module file function _build_modulefile(target, sourcefile, opt) local objectfile = opt.objectfile local dependfile = opt.dependfile @@ -149,6 +149,43 @@ function _build_modulefile(target, sourcefile, opt) return end + -- init flags + local requiresflags = opt.requiresflags + local flags = table.join({"-x", "c++"}, requiresflags or {}, compflags) + + -- trace + progress.show(opt.progress, "${color.build.object}build.cxx.module %s", sourcefile) + vprint(compinst:compcmd(sourcefile, objectfile, {compflags = flags, rawargs = true})) + + if not dryrun then + + -- do compile + dependinfo.files = {} + assert(compinst:compile(sourcefile, objectfile, {dependinfo = dependinfo, compflags = flags})) + + -- update files and values to the dependent file + dependinfo.values = depvalues + table.join2(dependinfo.files, sourcefile) + depend.save(dependinfo, dependfile) + end +end + +-- build module file +function _build_interfacemodulefile(target, sourcefile, opt) + local objectfile = opt.objectfile + local dependfile = opt.dependfile + local compinst = compiler.load("cxx", {target = target}) + local compflags = compinst:compflags({target = target}) + local dependinfo = option.get("rebuild") and {} or (depend.load(dependfile) or {}) + + -- need build this object? + local dryrun = option.get("dry-run") + local depvalues = {compinst:program(), compflags} + local lastmtime = os.isfile(objectfile) and os.mtime(dependfile) or 0 + if not dryrun and not depend.is_changed(dependinfo, {lastmtime = lastmtime, values = depvalues}) then + return + end + local bmifile = opt.bmifile local common_args = opt.common_args local requiresflags = opt.requiresflags @@ -435,7 +472,7 @@ function build_modules_for_batchjobs(target, batchjobs, objectfiles, modules, op requiresflags = get_requiresflags(target, module.requires) end - _build_modulefile(target, provide.sourcefile, { + _build_interfacemodulefile(target, provide.sourcefile, { objectfile = objectfile, dependfile = target:dependfile(bmifile), bmifile = bmifile, @@ -453,21 +490,31 @@ function build_modules_for_batchjobs(target, batchjobs, objectfiles, modules, op modulesjobs[name] = moduleinfo target:add("objectfiles", objectfile) else - if module.requires then - modulesjobs[module.cppfile] = { - name = module.cppfile, - deps = table.keys(module.requires), - sourcefile = module.cppfile, - job = batchjobs:newjob(module.cppfile, function(index, total) + modulesjobs[module.cppfile] = { + name = module.cppfile, + deps = table.keys(module.requires or {}), + sourcefile = module.cppfile, + job = batchjobs:newjob(module.cppfile, function(index, total) + local requiresflags + if module.requires then + requiresflags = get_requiresflags(target, module.requires) + end + + if common.has_module_extension(module.cppfile) then + _build_modulefile(target, module.cppfile, { + objectfile = objectfile, + dependfile = target:dependfile(module.cppfile), + requiresflags = requiresflags, + progress = (index * 100) / total}) + target:add("objectfiles", objectfile) + elseif requiresflags then -- append module mapper flags -- @note we add it at the end to ensure that the full modulemap are already stored in the mapper local requiresflags = get_requiresflags(target, module.requires) - if requiresflags then - target:fileconfig_add(module.cppfile, {force = {cxxflags = requiresflags}}) - end - end) - } - end + target:fileconfig_add(module.cppfile, {force = {cxxflags = requiresflags}}) + end + end) + } end end end @@ -510,11 +557,21 @@ function build_modules_for_batchcmds(target, batchcmds, objectfiles, modules, op _add_module_to_mapper(target, name, bmifile) depmtime = math.max(depmtime, os.mtime(bmifile)) else + local requiresflags if module.requires then - local requiresflags = get_requiresflags(target, module.requires) - if requiresflags then - target:fileconfig_add(module.cppfile, {force = {cxxflags = requiresflags}}) - end + requiresflags = get_requiresflags(target, module.requires) + end + + if common.has_module_extension(module.cppfile) then + local flags = {"-o", path(objectfile), "-c", path(module.cppfile)} + batchcmds:show_progress(opt.progress, "${color.build.object}build.cxx.module %s", module.cppfile) + batchcmds:mkdir(path.directory(objectfile)) + batchcmds:vrunv(compinst:program(), table.join(compinst:compflags({target = target}), requiresflags or {}, flags)) + batchcmds:add_depfiles(module.cppfile) + target:add("objectfiles", objectfile) + depmtime = math.max(depmtime, os.mtime(objectfile)) + elseif requiresflags then + target:fileconfig_add(module.cppfile, {force = {cxxflags = requiresflags}}) end end end -- cgit v1.3.1 From 0760075dfdc49d14aaf122f9a232c6cb70f75263 Mon Sep 17 00:00:00 2001 From: Arthur LAURENT Date: Thu, 1 Dec 2022 15:09:37 +0100 Subject: fix comments --- xmake/rules/c++/modules/modules_support/clang.lua | 4 ++-- xmake/rules/c++/modules/modules_support/gcc.lua | 2 +- xmake/rules/c++/modules/modules_support/msvc.lua | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) (limited to 'xmake/rules/c++/modules/modules_support/clang.lua') diff --git a/xmake/rules/c++/modules/modules_support/clang.lua b/xmake/rules/c++/modules/modules_support/clang.lua index fd7b4ca33..aae0e2aa5 100644 --- a/xmake/rules/c++/modules/modules_support/clang.lua +++ b/xmake/rules/c++/modules/modules_support/clang.lua @@ -133,7 +133,7 @@ function _get_toolchain_includedirs_for_stlheaders(target, includedirs, clang) os.tryrm(tmpfile) end --- build interface module file +-- build module file function _build_modulefile(target, sourcefile, opt) local objectfile = opt.objectfile local dependfile = opt.dependfile @@ -170,7 +170,7 @@ function _build_modulefile(target, sourcefile, opt) end end --- build module file +-- build interface module file function _build_interfacemodulefile(target, sourcefile, opt) local objectfile = opt.objectfile local dependfile = opt.dependfile diff --git a/xmake/rules/c++/modules/modules_support/gcc.lua b/xmake/rules/c++/modules/modules_support/gcc.lua index 53127c6da..78a56976e 100644 --- a/xmake/rules/c++/modules/modules_support/gcc.lua +++ b/xmake/rules/c++/modules/modules_support/gcc.lua @@ -94,7 +94,7 @@ function _get_toolchain_includedirs_for_stlheaders(includedirs, gcc) os.tryrm(tmpfile) end --- build interface module file +-- build module file function _build_modulefile(target, sourcefile, opt) local objectfile = opt.objectfile local dependfile = opt.dependfile diff --git a/xmake/rules/c++/modules/modules_support/msvc.lua b/xmake/rules/c++/modules/modules_support/msvc.lua index 0e4610c0e..ec59421c0 100644 --- a/xmake/rules/c++/modules/modules_support/msvc.lua +++ b/xmake/rules/c++/modules/modules_support/msvc.lua @@ -84,7 +84,7 @@ function _add_objectfile_to_link_arguments(target, objectfile) common.localcache():save(cachekey) end --- build interface module file +-- build module file function _build_modulefile(target, sourcefile, opt) local objectfile = opt.objectfile local dependfile = opt.dependfile -- cgit v1.3.1 From 4554eaf6b7aa25027c49803dc5288fdc272c3363 Mon Sep 17 00:00:00 2001 From: Arthur LAURENT Date: Thu, 1 Dec 2022 16:09:08 +0100 Subject: support incremental private module build --- xmake/rules/c++/modules/modules_support/clang.lua | 2 +- xmake/rules/c++/modules/modules_support/gcc.lua | 2 +- xmake/rules/c++/modules/modules_support/msvc.lua | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) (limited to 'xmake/rules/c++/modules/modules_support/clang.lua') diff --git a/xmake/rules/c++/modules/modules_support/clang.lua b/xmake/rules/c++/modules/modules_support/clang.lua index aae0e2aa5..379aa517c 100644 --- a/xmake/rules/c++/modules/modules_support/clang.lua +++ b/xmake/rules/c++/modules/modules_support/clang.lua @@ -503,7 +503,7 @@ function build_modules_for_batchjobs(target, batchjobs, objectfiles, modules, op if common.has_module_extension(module.cppfile) then _build_modulefile(target, module.cppfile, { objectfile = objectfile, - dependfile = target:dependfile(module.cppfile), + dependfile = target:dependfile(objectfile), requiresflags = requiresflags, progress = (index * 100) / total}) target:add("objectfiles", objectfile) diff --git a/xmake/rules/c++/modules/modules_support/gcc.lua b/xmake/rules/c++/modules/modules_support/gcc.lua index 78a56976e..d02512e59 100644 --- a/xmake/rules/c++/modules/modules_support/gcc.lua +++ b/xmake/rules/c++/modules/modules_support/gcc.lua @@ -430,7 +430,7 @@ function build_modules_for_batchjobs(target, batchjobs, objectfiles, modules, op job = batchjobs:newjob(m.cppfile, function(index, total) _build_modulefile(target, m.cppfile, { objectfile = objectfile, - dependfile = target:dependfile(m.cppfile), + dependfile = target:dependfile(objectfile), progress = (index * 100) / total}) target:add("objectfiles", objectfile) end) diff --git a/xmake/rules/c++/modules/modules_support/msvc.lua b/xmake/rules/c++/modules/modules_support/msvc.lua index ec59421c0..d9f3019d6 100644 --- a/xmake/rules/c++/modules/modules_support/msvc.lua +++ b/xmake/rules/c++/modules/modules_support/msvc.lua @@ -509,7 +509,7 @@ function build_modules_for_batchjobs(target, batchjobs, objectfiles, modules, op if common.has_module_extension(module.cppfile) then _build_modulefile(target, module.cppfile, { objectfile = objectfile, - dependfile = target:dependfile(module.cppfile), + dependfile = target:dependfile(objectfile), requiresflags = requiresflags, progress = (index * 100) / total}) target:add("objectfiles", objectfile) -- cgit v1.3.1