diff options
| author | Arthur LAURENT <[email protected]> | 2025-04-22 18:40:37 +0200 |
|---|---|---|
| committer | Arthur LAURENT <[email protected]> | 2025-04-22 18:40:37 +0200 |
| commit | f49af9018f3efbcdf3d49bb30c6663b300f1a133 (patch) | |
| tree | c047b0622ec6aa2b8f12a6c4dd19f2b1cbf1f768 /xmake/rules/c++/modules/xmake.lua | |
| parent | 40bfb6e1980d81454c9592da7eaaf0aded11f1ec (diff) | |
(C++ modules) cleanup module rules
Diffstat (limited to 'xmake/rules/c++/modules/xmake.lua')
| -rw-r--r-- | xmake/rules/c++/modules/xmake.lua | 145 |
1 files changed, 7 insertions, 138 deletions
diff --git a/xmake/rules/c++/modules/xmake.lua b/xmake/rules/c++/modules/xmake.lua index 2c7eaedff..c1b48ed41 100644 --- a/xmake/rules/c++/modules/xmake.lua +++ b/xmake/rules/c++/modules/xmake.lua @@ -27,43 +27,7 @@ rule("c++.build.modules") add_deps("c++.build.modules.builder") add_deps("c++.build.modules.install") - on_config(function (target) - import("support") - - -- we disable to build across targets in parallel, because the source files may depend on other target modules - -- @see https://github.com/xmake-io/xmake/issues/1858 - if support.contains_modules(target) then - -- @note this will cause cross-parallel builds to be disabled for all sub-dependent targets, - -- even if some sub-targets do not contain C++ modules. - -- - -- maybe we will have a more fine-grained configuration strategy to disable it in the future. - target:set("policy", "build.fence", true) - - -- disable ccache for this target - -- - -- Caching can affect incremental compilation, for example - -- by interfering with the results of depfile generation for msvc. - -- - -- @see https://github.com/xmake-io/xmake/issues/3000 - target:set("policy", "build.ccache", false) - - -- load compiler support - support.load(target) - - -- mark this target with modules - target:data_set("cxx.has_modules", true) - - -- moduleonly modules are implicitly public - if target:is_moduleonly() then - local sourcebatch = target:sourcebatches()["c++.build.modules.builder"] - if sourcebatch then - for _, sourcefile in ipairs(sourcebatch.sourcefiles) do - target:fileconfig_add(sourcefile, {public = true}) - end - end - end - end - end) + on_config("config") -- build modules rule("c++.build.modules.builder") @@ -71,117 +35,22 @@ rule("c++.build.modules.builder") set_extensions(".mpp", ".mxx", ".cppm", ".ixx") -- generate module dependencies - on_prepare_files(function (target, jobgraph, sourcebatch, opt) - if target:data("cxx.has_modules") then - import("builder") - import("scanner") - - -- patch sourcebatch - builder.patch_sourcebatch(target, sourcebatch) - - -- generate module dependencies - scanner.generate_module_dependencies(target, jobgraph, sourcebatch, opt) - end - end, {jobgraph = true}) + on_prepare_files("scanner", {jobgraph = true}) -- parallel build support to accelerate `xmake build` to build modules - before_build_files(function(target, jobgraph, sourcebatch, opt) - if target:data("cxx.has_modules") then - import("support") - import("scanner") - import("builder") - - -- get module dependencies - local modules = scanner.get_module_dependencies(target, sourcebatch) - if not target:is_moduleonly() then - -- avoid building non referenced modules - local build_objectfiles, link_objectfiles = scanner.sort_modules_by_dependencies(target, sourcebatch.objectfiles, modules) - sourcebatch.objectfiles = build_objectfiles - - -- build modules and headerunits - builder.build_modules_and_headerunits(target, jobgraph, sourcebatch, modules, opt) - sourcebatch.objectfiles = link_objectfiles - else - sourcebatch.objectfiles = {} - end - - support.localcache():set2(target:fullname(), "c++.modules", modules) - support.localcache():save() - else - -- avoid duplicate linking of object files of non-module programs - sourcebatch.objectfiles = {} - end - end, {jobgraph = true, batch = true}) + before_build_files("builder", {jobgraph = true, batch = true}) -- serial compilation only, usually used to support project generator - before_buildcmd_files(function(target, batchcmds, sourcebatch, opt) - if target:data("cxx.has_modules") then - import("support") - import("scanner") - import("builder") - - -- get module dependencies - local modules = scanner.get_module_dependencies(target, sourcebatch) - if not target:is_moduleonly() then - -- avoid building non referenced modules - local build_objectfiles, link_objectfiles = scanner.sort_modules_by_dependencies(target, sourcebatch.objectfiles, modules) - sourcebatch.objectfiles = build_objectfiles - - -- build headerunits and modules - builder.build_modules_and_headerunits(target, batchcmds, sourcebatch, modules, opt) - sourcebatch.objectfiles = link_objectfiles - else - -- avoid duplicate linking of object files of non-module programs - sourcebatch.objectfiles = {} - end - - support.localcache():set2(target:fullname(), "c++.modules", modules) - support.localcache():save() - else - sourcebatch.sourcefiles = {} - sourcebatch.objectfiles = {} - sourcebatch.dependfiles = {} - end - end) + before_buildcmd_files("builder") after_clean(function (target) - import("core.base.option") - import("support") - import("private.action.clean.remove_files") - - -- we cannot use target:data("cxx.has_modules"), - -- because on_config will be not called when cleaning targets - if support.contains_modules(target) then - remove_files(support.modules_cachedir(target)) - if option.get("all") then - remove_files(support.stlmodules_cachedir(target)) - support.localcache():clear() - support.localcache():save() - end - end + import("builder.clean") end) -- install modules rule("c++.build.modules.install") set_extensions(".mpp", ".mxx", ".cppm", ".ixx") - before_install(function (target) - import("support") - import("builder") - - -- we cannot use target:data("cxx.has_modules"), - -- because on_config will be not called when installing targets - if support.contains_modules(target) then - local modules = support.localcache():get2(target:fullname(), "c++.modules") - builder.generate_metadata(target, modules) + before_install("builder.install") - support.add_installfiles_for_modules(target) - end - end) - - before_uninstall(function (target) - import("support") - if support.contains_modules(target) then - support.add_installfiles_for_modules(target) - end - end) + before_uninstall("builder.uninstall") |
