diff options
| author | Arthur LAURENT <[email protected]> | 2024-07-22 18:28:48 +0200 |
|---|---|---|
| committer | Arthur LAURENT <[email protected]> | 2024-07-22 18:31:06 +0200 |
| commit | 4f2412e3a790cc0e240eb8bc6f0caa54170acbab (patch) | |
| tree | 47b059e30ca982efbaf1604f28b2cb6d9e220e68 /xmake/rules/c++/modules/modules_support | |
| parent | 6bc66f276570973aced27afc6dd56cc6ce5b2d3b (diff) | |
improve compilation of modules based on if it is from a package, an other target or an internal module
Diffstat (limited to 'xmake/rules/c++/modules/modules_support')
5 files changed, 40 insertions, 40 deletions
diff --git a/xmake/rules/c++/modules/modules_support/clang/builder.lua b/xmake/rules/c++/modules/modules_support/clang/builder.lua index b10a47e06..eda23566c 100644 --- a/xmake/rules/c++/modules/modules_support/clang/builder.lua +++ b/xmake/rules/c++/modules/modules_support/clang/builder.lua @@ -248,9 +248,14 @@ function make_module_buildjobs(target, batchjobs, job_name, deps, opt) local fileconfig = target:fileconfig(opt.cppfile) local public = fileconfig and fileconfig.public local external = fileconfig and fileconfig.external - local private_dep = fileconfig and fileconfig.private_dep + local from_moduleonly = external and external.moduleonly local bmifile = mapped_bmi or bmifile - if target:is_binary() then + if external and not from_moduleonly then + if not mapped_bmi then + progress.show(jobopt.progress, "${color.build.target}<%s> ${clear}${color.build.object}compiling.bmi.$(mode) %s", target:name(), name or opt.cppfile) + _compile_bmi_step(target, bmifile, opt.cppfile, {std = (name == "std" or name == "std.compat")}) + end + else if mapped_bmi then progress.show(jobopt.progress, "${color.build.target}<%s> ${clear}${color.build.object}compiling.objectfile.$(mode) %s", target:name(), name or opt.cppfile) _compile_objectfile_step(target, bmifile, opt.cppfile, opt.objectfile) @@ -258,14 +263,6 @@ function make_module_buildjobs(target, batchjobs, job_name, deps, opt) progress.show(jobopt.progress, "${color.build.target}<%s> ${clear}${color.build.object}compiling.module.$(mode) %s", target:name(), name or opt.cppfile) _compile_one_step(target, bmifile, opt.cppfile, opt.objectfile, {std = (name == "std" or name == "std.compat")}) end - else - if (not public and not external) or (external and private_dep) then - progress.show(jobopt.progress, "${color.build.target}<%s> ${clear}${color.build.object}compiling.module.$(mode) %s", target:name(), name or opt.cppfile) - _compile_one_step(target, bmifile, opt.cppfile, opt.objectfile, {std = (name == "std" or name == "std.compat")}) - else - progress.show(jobopt.progress, "${color.build.target}<%s> ${clear}${color.build.object}compiling.bmi.$(mode) %s", target:name(), name or opt.cppfile) - _compile_bmi_step(target, bmifile, opt.cppfile, {std = (name == "std" or name == "std.compat")}) - end end else os.tryrm(opt.objectfile) -- force rebuild for .cpp files diff --git a/xmake/rules/c++/modules/modules_support/compiler_support.lua b/xmake/rules/c++/modules/modules_support/compiler_support.lua index 72e7b93fd..2e4d1f5ef 100644 --- a/xmake/rules/c++/modules/modules_support/compiler_support.lua +++ b/xmake/rules/c++/modules/modules_support/compiler_support.lua @@ -87,9 +87,9 @@ end function cull_objectfiles(target, modules, sourcebatch) -- don't cull for executables - if target:is_binary() then - return - end + -- if target:is_binary() then + -- return + -- end sourcebatch.objectfiles = {} for _, sourcefile in ipairs(sourcebatch.sourcefiles) do @@ -100,8 +100,9 @@ function cull_objectfiles(target, modules, sourcebatch) local fileconfig = target:fileconfig(sourcefile) local public = fileconfig and fileconfig.public local external = fileconfig and fileconfig.external + local from_moduleonly = external and external.moduleonly local private_dep = fileconfig and fileconfig.private_dep - if (not public and not external) or (external and private_dep) then + if not external or from_moduleonly then table.insert(sourcebatch.objectfiles, objectfile) end else diff --git a/xmake/rules/c++/modules/modules_support/dependency_scanner.lua b/xmake/rules/c++/modules/modules_support/dependency_scanner.lua index 66b00f421..44a3da980 100644 --- a/xmake/rules/c++/modules/modules_support/dependency_scanner.lua +++ b/xmake/rules/c++/modules/modules_support/dependency_scanner.lua @@ -200,7 +200,9 @@ function _get_package_modules(target, package, opt) for _, metafile in ipairs(metafiles) do package_modules = package_modules or {} local modulefile, name, metadata = _parse_meta_info(target, metafile) - package_modules[name] = {file = path.join(modulesdir, modulefile), metadata = metadata} + local package_data = package["_INFO"] + local moduleonly = not package_data["libfiles"] + package_modules[name] = {file = path.join(modulesdir, modulefile), metadata = metadata, external = {moduleonly = moduleonly}} end return package_modules @@ -427,10 +429,12 @@ function sort_modules_by_dependencies(target, objectfiles, modules) local _, provide, cppfile = compiler_support.get_provided_module(modules[objectfile]) local fileconfig = target:fileconfig(cppfile) local public = fileconfig and fileconfig.public + local external = fileconfig and fileconfig.external + local from_moduleonly = external and external.moduleonly local dont_cull = fileconfig and fileconfig.cull ~= nil and not fileconfig.cull - if not provide or public or dont_cull then + if not provide or public or from_moduleonly or dont_cull then table.insert(result, objectfile) - else + elseif not external and not dont_cull then wprint("%s has been culled because it's not consumed by its target nor flagged as a public module (add_files(\"xxx.cppm\", {public = true}))", cppfile) end else @@ -438,6 +442,7 @@ function sort_modules_by_dependencies(target, objectfiles, modules) end end end + print(target:name(), result) return result end @@ -454,7 +459,7 @@ function get_targetdeps_modules(target) if public then sourcefiles = sourcefiles or {} table.insert(sourcefiles, sourcefile) - target:fileconfig_add(sourcefile, {external = true, private_dep = private_dep}) + target:fileconfig_add(sourcefile, {external = {moduleonly = dep:is_moduleonly()}, private_dep = private_dep}) end end end diff --git a/xmake/rules/c++/modules/modules_support/gcc/builder.lua b/xmake/rules/c++/modules/modules_support/gcc/builder.lua index d4f5a01f1..cbb8472a0 100644 --- a/xmake/rules/c++/modules/modules_support/gcc/builder.lua +++ b/xmake/rules/c++/modules/modules_support/gcc/builder.lua @@ -215,11 +215,18 @@ function make_module_buildjobs(target, batchjobs, job_name, deps, opt) local fileconfig = target:fileconfig(opt.cppfile) local public = fileconfig and fileconfig.public local external = fileconfig and fileconfig.external - local private_dep = fileconfig and fileconfig.private_dep + local from_moduleonly = external and external.moduleonly local bmifile = mapped_bmi or bmifile local flags = {"-x", "c++"} local sourcefile - if target:is_binary() then + if external and not from_moduleonly then + if not mapped_bmi then + progress.show(jobopt.progress, "${color.build.target}<%s> ${clear}${color.build.object}compiling.bmi.$(mode) %s", target:name(), name or opt.cppfile) + local module_onlyflag = compiler_support.get_moduleonlyflag(target) + table.insert(flags, module_onlyflag) + sourcefile = opt.cppfile + end + else if mapped_bmi then progress.show(jobopt.progress, "${color.build.target}<%s> ${clear}${color.build.object}compiling.objectfile.$(mode) %s", target:name(), name or opt.cppfile) sourcefile = bmifile @@ -227,21 +234,13 @@ function make_module_buildjobs(target, batchjobs, job_name, deps, opt) progress.show(jobopt.progress, "${color.build.target}<%s> ${clear}${color.build.object}compiling.module.$(mode) %s", target:name(), name or opt.cppfile) sourcefile = opt.cppfile end - else - if (not public and not external) or (external and private_dep) then - progress.show(jobopt.progress, "${color.build.target}<%s> ${clear}${color.build.object}compiling.module.$(mode) %s", target:name(), name or opt.cppfile) - sourcefile = opt.cppfile - else - progress.show(jobopt.progress, "${color.build.target}<%s> ${clear}${color.build.object}compiling.bmi.$(mode) %s", target:name(), name or opt.cppfile) - local module_onlyflag = compiler_support.get_moduleonlyflag(target) - table.insert(flags, module_onlyflag) - sourcefile = opt.cppfile - end end if option.get("diagnosis") then print("mapper file --------\n%s--------", io.readfile(module_mapper)) end - _compile(target, flags, sourcefile, opt.objectfile) + if sourcefile then + _compile(target, flags, sourcefile, opt.objectfile) + end os.tryrm(module_mapper) else os.tryrm(opt.objectfile) -- force rebuild for .cpp files diff --git a/xmake/rules/c++/modules/modules_support/msvc/builder.lua b/xmake/rules/c++/modules/modules_support/msvc/builder.lua index ccdbea141..2d79e48ac 100644 --- a/xmake/rules/c++/modules/modules_support/msvc/builder.lua +++ b/xmake/rules/c++/modules/modules_support/msvc/builder.lua @@ -313,8 +313,14 @@ function make_module_buildjobs(target, batchjobs, job_name, deps, opt) local public = fileconfig and fileconfig.public local external = fileconfig and fileconfig.external local private_dep = fileconfig and fileconfig.private_dep + local from_moduleonly = external and external.moduleonly local bmifile = mapped_bmi or bmifile - if target:is_binary() then + if external and not from_moduleonly then + if not mapped_bmi then + progress.show(jobopt.progress, "${color.build.target}<%s> ${clear}${color.build.object}compiling.bmi.$(mode) %s", target:name(), name or opt.cppfile) + _compile_bmi_step(target, bmifile, opt.cppfile, opt.objectfile, provide) + end + else if mapped_bmi then progress.show(jobopt.progress, "${color.build.target}<%s> ${clear}${color.build.object}compiling.objectfile.$(mode) %s", target:name(), name or opt.cppfile) _compile_objectfile_step(target, bmifile, opt.cppfile, opt.objectfile, provide) @@ -322,14 +328,6 @@ function make_module_buildjobs(target, batchjobs, job_name, deps, opt) progress.show(jobopt.progress, "${color.build.target}<%s> ${clear}${color.build.object}compiling.module.$(mode) %s", target:name(), name or opt.cppfile) _compile_one_step(target, bmifile, opt.cppfile, opt.objectfile, provide) end - else - if (not public and not external) or (external and private_dep) then - progress.show(jobopt.progress, "${color.build.target}<%s> ${clear}${color.build.object}compiling.module.$(mode) %s", target:name(), name or opt.cppfile) - _compile_one_step(target, bmifile, opt.cppfile, opt.objectfile, provide) - else - progress.show(jobopt.progress, "${color.build.target}<%s> ${clear}${color.build.object}compiling.bmi.$(mode) %s", target:name(), name or opt.cppfile) - _compile_bmi_step(target, bmifile, opt.cppfile, opt.objectfile, provide) - end end else os.tryrm(opt.objectfile) -- force rebuild for .cpp files |
