From 3a7d68de17f19afadc2f7eec698d54861ecd729d Mon Sep 17 00:00:00 2001 From: Arthur LAURENT Date: Mon, 5 Feb 2024 18:22:44 +0100 Subject: update relevent tests to use moduleonly target rule --- tests/projects/c++/modules/moduleonly/xmake.lua | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 tests/projects/c++/modules/moduleonly/xmake.lua (limited to 'tests/projects/c++/modules/moduleonly/xmake.lua') diff --git a/tests/projects/c++/modules/moduleonly/xmake.lua b/tests/projects/c++/modules/moduleonly/xmake.lua new file mode 100644 index 000000000..c6cb7cef4 --- /dev/null +++ b/tests/projects/c++/modules/moduleonly/xmake.lua @@ -0,0 +1,7 @@ +add_rules("mode.release", "mode.debug") +set_languages("c++20") + +target("mod") + set_kind("headeronly") + add_rules("c++.moduleonly") + add_files("src/mod.mpp") -- cgit v1.3.1 From 8929c381e0cd70ff804e7c52bb3efc134e056e78 Mon Sep 17 00:00:00 2001 From: Arthur LAURENT Date: Tue, 6 Feb 2024 18:31:13 +0100 Subject: implement target kind moduleonly --- tests/projects/c++/modules/link_order/xmake.lua | 8 +- tests/projects/c++/modules/moduleonly/xmake.lua | 3 +- .../packages/my-repo/packages/b/bar2/src/xmake.lua | 4 +- .../packages/my-repo/packages/b/bar2/xmake.lua | 2 +- .../c++/modules/user_headerunit2/a/xmake.lua | 4 +- .../c++/modules/user_headerunit2/b/xmake.lua | 4 +- xmake/actions/build/build.lua | 2 +- xmake/actions/build/kinds/moduleonly.lua | 257 +++++++++++++++++++++ xmake/core/project/target.lua | 9 +- .../private/check/checkers/api/target/kind.lua | 2 +- xmake/plugins/project/cmake/cmakelists.lua | 2 + .../modules/modules_support/compiler_support.lua | 4 +- .../modules/modules_support/dependency_scanner.lua | 2 +- xmake/rules/c++/modules/xmake.lua | 182 ++++++--------- 14 files changed, 353 insertions(+), 132 deletions(-) create mode 100644 xmake/actions/build/kinds/moduleonly.lua (limited to 'tests/projects/c++/modules/moduleonly/xmake.lua') diff --git a/tests/projects/c++/modules/link_order/xmake.lua b/tests/projects/c++/modules/link_order/xmake.lua index 1ae6639bb..5c7b8a236 100644 --- a/tests/projects/c++/modules/link_order/xmake.lua +++ b/tests/projects/c++/modules/link_order/xmake.lua @@ -3,14 +3,14 @@ set_languages("c++20") target("foo") add_rules("c++") - set_kind("headeronly") - add_rules("c++.moduleonly") + set_kind("moduleonly") + add_files("src/foo.mpp") target("bar") add_rules("c++") - set_kind("headeronly") - add_rules("c++.moduleonly") + set_kind("moduleonly") + add_files("src/bar.mpp") target("link_order_1") diff --git a/tests/projects/c++/modules/moduleonly/xmake.lua b/tests/projects/c++/modules/moduleonly/xmake.lua index c6cb7cef4..54c681cc8 100644 --- a/tests/projects/c++/modules/moduleonly/xmake.lua +++ b/tests/projects/c++/modules/moduleonly/xmake.lua @@ -2,6 +2,5 @@ add_rules("mode.release", "mode.debug") set_languages("c++20") target("mod") - set_kind("headeronly") - add_rules("c++.moduleonly") + set_kind("moduleonly") add_files("src/mod.mpp") diff --git a/tests/projects/c++/modules/packages/my-repo/packages/b/bar2/src/xmake.lua b/tests/projects/c++/modules/packages/my-repo/packages/b/bar2/src/xmake.lua index 9312aee2d..905c38a02 100644 --- a/tests/projects/c++/modules/packages/my-repo/packages/b/bar2/src/xmake.lua +++ b/tests/projects/c++/modules/packages/my-repo/packages/b/bar2/src/xmake.lua @@ -2,6 +2,6 @@ add_rules("mode.release", "mode.debug") set_languages("c++20") target("bar2") - set_kind("headeronly") - add_rules("c++.moduleonly") + set_kind("moduleonly") + add_files("*.mpp") diff --git a/tests/projects/c++/modules/packages/my-repo/packages/b/bar2/xmake.lua b/tests/projects/c++/modules/packages/my-repo/packages/b/bar2/xmake.lua index e56cdaf43..343a52e02 100644 --- a/tests/projects/c++/modules/packages/my-repo/packages/b/bar2/xmake.lua +++ b/tests/projects/c++/modules/packages/my-repo/packages/b/bar2/xmake.lua @@ -1,5 +1,5 @@ package("bar2") - set_kind("headeronly") + set_kind("moduleonly") set_sourcedir(path.join(os.scriptdir(), "src")) on_install(function(package) diff --git a/tests/projects/c++/modules/user_headerunit2/a/xmake.lua b/tests/projects/c++/modules/user_headerunit2/a/xmake.lua index 261428921..8d9a4cb8b 100644 --- a/tests/projects/c++/modules/user_headerunit2/a/xmake.lua +++ b/tests/projects/c++/modules/user_headerunit2/a/xmake.lua @@ -1,6 +1,6 @@ target("a") set_languages("cxxlatest") - set_kind("headeronly") - add_rules("c++.moduleonly") + set_kind("moduleonly") + add_headerfiles("*.hpp") add_files("a.mpp") diff --git a/tests/projects/c++/modules/user_headerunit2/b/xmake.lua b/tests/projects/c++/modules/user_headerunit2/b/xmake.lua index 9821fcd6d..5be8ae50b 100644 --- a/tests/projects/c++/modules/user_headerunit2/b/xmake.lua +++ b/tests/projects/c++/modules/user_headerunit2/b/xmake.lua @@ -1,6 +1,6 @@ target("b") add_deps("a") set_languages("cxxlatest") - set_kind("headeronly") - add_rules("c++.moduleonly") + set_kind("moduleonly") + add_files("b.mpp") diff --git a/xmake/actions/build/build.lua b/xmake/actions/build/build.lua index bb0b61cc1..1db197cd6 100644 --- a/xmake/actions/build/build.lua +++ b/xmake/actions/build/build.lua @@ -65,7 +65,7 @@ function _add_batchjobs_builtin(batchjobs, rootjob, target) end -- uses the builtin target script - if not job and (target:is_static() or target:is_binary() or target:is_shared() or target:is_object()) then + if not job and (target:is_static() or target:is_binary() or target:is_shared() or target:is_object() or target:is_moduleonly()) then job, job_leaf = import("kinds." .. target:kind(), {anonymous = true})(batchjobs, rootjob, target) end job = job or rootjob diff --git a/xmake/actions/build/kinds/moduleonly.lua b/xmake/actions/build/kinds/moduleonly.lua new file mode 100644 index 000000000..1a5997712 --- /dev/null +++ b/xmake/actions/build/kinds/moduleonly.lua @@ -0,0 +1,257 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015-present, TBOOX Open Source Group. +-- +-- @author ruki, Arthapz +-- @file modules.lua +-- + +-- imports +import("core.base.option") +import("core.project.rule") +import("core.project.config") +import("core.project.project") +import("async.runjobs") +import("private.utils.batchcmds") +import("private.utils.rule_groups") + +-- has scripts for the custom rule +function _has_scripts_for_rule(ruleinst, suffix) + + -- add batch jobs for xx_build_files + local scriptname = "build_files" .. (suffix and ("_" .. suffix) or "") + local script = ruleinst:script(scriptname) + if script then + return true + end + + -- add batch jobs for xx_build_file + scriptname = "build_file" .. (suffix and ("_" .. suffix) or "") + script = ruleinst:script(scriptname) + if script then + return true + end + + -- add batch jobs for xx_buildcmd_files + scriptname = "buildcmd_files" .. (suffix and ("_" .. suffix) or "") + script = ruleinst:script(scriptname) + if script then + return true + end + + -- add batch jobs for xx_buildcmd_file + scriptname = "buildcmd_file" .. (suffix and ("_" .. suffix) or "") + script = ruleinst:script(scriptname) + if script then + return true + end +end + +-- has scripts for target +function _has_scripts_for_target(target, suffix) + local scriptname = "build_files" .. (suffix and ("_" .. suffix) or "") + local script = target:script(scriptname) + if script then + return true + else + scriptname = "build_file" .. (suffix and ("_" .. suffix) or "") + script = target:script(scriptname) + if script then + return true + end + end +end + +-- has scripts for group +function _has_scripts_for_group(group, suffix) + for _, item in pairs(group) do + if item.target and _has_scripts_for_target(item.target, suffix) then + return true + end + if item.rule and _has_scripts_for_rule(item.rule, suffix) then + return true + end + end +end + +-- add batch jobs for the custom rule +function _add_batchjobs_for_rule(batchjobs, rootjob, target, sourcebatch, suffix) + + -- get rule + local rulename = assert(sourcebatch.rulename, "unknown rule for sourcebatch!") + local ruleinst = rule_groups.get_rule(target, rulename) + + -- add batch jobs for xx_build_files + local scriptname = "build_files" .. (suffix and ("_" .. suffix) or "") + local script = ruleinst:script(scriptname) + if script then + if ruleinst:extraconf(scriptname, "batch") then + script(target, batchjobs, sourcebatch, {rootjob = rootjob, distcc = ruleinst:extraconf(scriptname, "distcc")}) + else + batchjobs:addjob("rule/" .. rulename .. "/" .. scriptname, function (index, total) + script(target, sourcebatch, {progress = (index * 100) / total}) + end, {rootjob = rootjob}) + end + end + + -- add batch jobs for xx_build_file + if not script then + scriptname = "build_file" .. (suffix and ("_" .. suffix) or "") + script = ruleinst:script(scriptname) + if script then + local sourcekind = sourcebatch.sourcekind + for _, sourcefile in ipairs(sourcebatch.sourcefiles) do + batchjobs:addjob(sourcefile, function (index, total) + script(target, sourcefile, {sourcekind = sourcekind, progress = (index * 100) / total}) + end, {rootjob = rootjob, distcc = ruleinst:extraconf(scriptname, "distcc")}) + end + end + end + + -- add batch jobs for xx_buildcmd_files + if not script then + scriptname = "buildcmd_files" .. (suffix and ("_" .. suffix) or "") + script = ruleinst:script(scriptname) + if script then + batchjobs:addjob("rule/" .. rulename .. "/" .. scriptname, function (index, total) + local batchcmds_ = batchcmds.new({target = target}) + local distcc = ruleinst:extraconf(scriptname, "distcc") + script(target, batchcmds_, sourcebatch, {progress = (index * 100) / total, distcc = distcc}) + batchcmds_:runcmds({changed = target:is_rebuilt(), dryrun = option.get("dry-run")}) + end, {rootjob = rootjob}) + end + end + + -- add batch jobs for xx_buildcmd_file + if not script then + scriptname = "buildcmd_file" .. (suffix and ("_" .. suffix) or "") + script = ruleinst:script(scriptname) + if script then + local sourcekind = sourcebatch.sourcekind + for _, sourcefile in ipairs(sourcebatch.sourcefiles) do + batchjobs:addjob(sourcefile, function (index, total) + local batchcmds_ = batchcmds.new({target = target}) + script(target, batchcmds_, sourcefile, {sourcekind = sourcekind, progress = (index * 100) / total}) + batchcmds_:runcmds({changed = target:is_rebuilt(), dryrun = option.get("dry-run")}) + end, {rootjob = rootjob, distcc = ruleinst:extraconf(scriptname, "distcc")}) + end + end + end +end + +-- add batch jobs for target +function _add_batchjobs_for_target(batchjobs, rootjob, target, sourcebatch, suffix) + -- we just build sourcebatch with on_build_files scripts + -- + -- for example, c++.build and c++.build.modules.builder rules have same sourcefiles, + -- but we just build it for c++.build + -- + -- @see https://github.com/xmake-io/xmake/issues/3171 + -- + local rulename = sourcebatch.rulename + if rulename then + local ruleinst = rule_groups.get_rule(target, rulename) + if not ruleinst:script("build_file") and + not ruleinst:script("build_files") then + return + end + end + + -- add batch jobs + local scriptname = "build_files" .. (suffix and ("_" .. suffix) or "") + local script = target:script(scriptname) + if script then + if target:extraconf(scriptname, "batch") then + script(target, batchjobs, sourcebatch, {rootjob = rootjob, distcc = target:extraconf(scriptname, "distcc")}) + else + batchjobs:addjob(target:name() .. "/" .. scriptname, function (index, total) + script(target, sourcebatch, {progress = (index * 100) / total}) + end, {rootjob = rootjob}) + end + return true + else + scriptname = "build_file" .. (suffix and ("_" .. suffix) or "") + script = target:script(scriptname) + if script then + local sourcekind = sourcebatch.sourcekind + for _, sourcefile in ipairs(sourcebatch.sourcefiles) do + batchjobs:addjob(sourcefile, function (index, total) + script(target, sourcefile, {sourcekind = sourcekind, progress = (index * 100) / total}) + end, {rootjob = rootjob, distcc = target:extraconf(scriptname, "distcc")}) + end + return true + end + end +end + +-- add batch jobs for group +function _add_batchjobs_for_group(batchjobs, rootjob, target, group, suffix) + for _, item in pairs(group) do + local sourcebatch = item.sourcebatch + if item.target then + _add_batchjobs_for_target(batchjobs, rootjob, target, sourcebatch, suffix) + end + -- override on_xxx script in target? we need to ignore rule scripts + if item.rule and (suffix or not _has_scripts_for_target(target, suffix)) then + _add_batchjobs_for_rule(batchjobs, rootjob, target, sourcebatch, suffix) + end + end +end + +-- add batch jobs for building source files +function add_batchjobs_for_sourcefiles(batchjobs, rootjob, target, sourcebatches) + + -- build sourcebatch groups first + local groups = rule_groups.build_sourcebatch_groups(target, sourcebatches) + + -- add batch jobs for build_after + local groups_root + local groups_leaf = rootjob + for idx, group in ipairs(groups) do + if _has_scripts_for_group(group, "after") then + batchjobs:group_enter(target:name() .. "/after_build_files" .. idx) + _add_batchjobs_for_group(batchjobs, groups_leaf, target, group, "after") + groups_leaf = batchjobs:group_leave() or groups_leaf + groups_root = groups_root or groups_leaf + end + end + + -- add batch jobs for build + for idx, group in ipairs(groups) do + if _has_scripts_for_group(group) then + batchjobs:group_enter(target:name() .. "/build_files" .. idx) + _add_batchjobs_for_group(batchjobs, groups_leaf, target, group) + groups_leaf = batchjobs:group_leave() or groups_leaf + groups_root = groups_root or groups_leaf + end + end + + -- add batch jobs for build_before + for idx, group in ipairs(groups) do + if _has_scripts_for_group(group, "before") then + batchjobs:group_enter(target:name() .. "/before_build_files" .. idx) + _add_batchjobs_for_group(batchjobs, groups_leaf, target, group, "before") + groups_leaf = batchjobs:group_leave() or groups_leaf + groups_root = groups_root or groups_leaf + end + end + return groups_leaf, groups_root or groups_leaf +end + +-- add batch jobs for generating modules deps files +function main(batchjobs, rootjob, target) + return add_batchjobs_for_sourcefiles(batchjobs, rootjob, target, target:sourcebatches()) +end + diff --git a/xmake/core/project/target.lua b/xmake/core/project/target.lua index 8cc2ff824..b6835a277 100644 --- a/xmake/core/project/target.lua +++ b/xmake/core/project/target.lua @@ -1201,9 +1201,14 @@ function _instance:is_headeronly() return self:kind() == "headeronly" end +-- is moduleonly target? +function _instance:is_moduleonly() + return self:kind() == "moduleonly" +end + -- is library target? function _instance:is_library() - return self:is_static() or self:is_shared() or self:is_headeronly() + return self:is_static() or self:is_shared() or self:is_headeronly() or self:is_moduleonly() end -- is default target? @@ -1555,7 +1560,7 @@ end function _instance:filename() -- no target file? - if self:is_object() or self:is_phony() or self:is_headeronly() then + if self:is_object() or self:is_phony() or self:is_headeronly() or self:is_moduleonly() then return end diff --git a/xmake/modules/private/check/checkers/api/target/kind.lua b/xmake/modules/private/check/checkers/api/target/kind.lua index 127f78ad5..5d716b129 100644 --- a/xmake/modules/private/check/checkers/api/target/kind.lua +++ b/xmake/modules/private/check/checkers/api/target/kind.lua @@ -23,5 +23,5 @@ import(".api_checker") function main(opt) opt = opt or {} - api_checker.check_targets("kind", table.join(opt, {values = {"object", "binary", "static", "shared", "headeronly", "phony"}})) + api_checker.check_targets("kind", table.join(opt, {values = {"object", "binary", "static", "shared", "headeronly", "moduleonly", "phony"}})) end diff --git a/xmake/plugins/project/cmake/cmakelists.lua b/xmake/plugins/project/cmake/cmakelists.lua index 6fcf38313..a91328d54 100644 --- a/xmake/plugins/project/cmake/cmakelists.lua +++ b/xmake/plugins/project/cmake/cmakelists.lua @@ -1003,6 +1003,8 @@ function _add_target(cmakelists, target, outputdir) _add_target_headeronly(cmakelists, target) _add_target_include_directories(cmakelists, target, outputdir) return + elseif targetkind == 'moduleonly' then + raise("target kind moduleonly is currently not supported for cmakelists") else raise("unknown target kind %s", target:kind()) end diff --git a/xmake/rules/c++/modules/modules_support/compiler_support.lua b/xmake/rules/c++/modules/modules_support/compiler_support.lua index d7e8a0bd8..d9d849454 100644 --- a/xmake/rules/c++/modules/modules_support/compiler_support.lua +++ b/xmake/rules/c++/modules/modules_support/compiler_support.lua @@ -116,14 +116,14 @@ end -- this target contains module files? function contains_modules(target) -- we can not use `"c++.build.builder"`, because it contains sourcekind/cxx. - local target_with_modules = (target:sourcebatches()["c++.moduleonly"] or target:sourcebatches()["c++.build.modules"]) and true or false + local target_with_modules = target:sourcebatches()["c++.build.modules"] and true or false if not target_with_modules then target_with_modules = target:policy("build.c++.modules") end if not target_with_modules then for _, dep in ipairs(target:orderdeps()) do local sourcebatches = dep:sourcebatches() - if sourcebatches["c++.moduleonly"] or sourcebatches["c++.build.modules"] then + if sourcebatches["c++.build.modules"] then target_with_modules = true break end diff --git a/xmake/rules/c++/modules/modules_support/dependency_scanner.lua b/xmake/rules/c++/modules/modules_support/dependency_scanner.lua index e4e6783bd..0b02292ef 100644 --- a/xmake/rules/c++/modules/modules_support/dependency_scanner.lua +++ b/xmake/rules/c++/modules/modules_support/dependency_scanner.lua @@ -438,7 +438,7 @@ end function get_targetdeps_modules(target) local sourcefiles for _, dep in ipairs(target:orderdeps()) do - local sourcebatch = dep:sourcebatches()["c++.moduleonly"] or dep:sourcebatches()["c++.build.modules.builder"] + local sourcebatch = dep:sourcebatches()["c++.build.modules.builder"] if sourcebatch and sourcebatch.sourcefiles then for _, sourcefile in ipairs(sourcebatch.sourcefiles) do local fileconfig = dep:fileconfig(sourcefile) diff --git a/xmake/rules/c++/modules/xmake.lua b/xmake/rules/c++/modules/xmake.lua index 34d636ca1..13fb405d8 100644 --- a/xmake/rules/c++/modules/xmake.lua +++ b/xmake/rules/c++/modules/xmake.lua @@ -54,8 +54,8 @@ rule("c++.build.modules") target:data_set("cxx.has_modules", true) -- moduleonly modules are implicitly public - if target:rule("c++.moduleonly") then - local sourcebatch = target:sourcebatches()["c++.moduleonly"] + if target:is_moduleonly() then + local sourcebatch = target:sourcebatches()["c++.build.modules.builder"] for _, sourcefile in ipairs(sourcebatch.sourcefiles) do target:fileconfig_add(sourcefile, {public = true}) end @@ -70,43 +70,43 @@ rule("c++.build.modules.builder") -- parallel build support to accelerate `xmake build` to build modules before_build_files(function(target, batchjobs, sourcebatch, opt) - if not target:rule("c++.moduleonly") then - if target:data("cxx.has_modules") then - import("modules_support.compiler_support") - import("modules_support.dependency_scanner") - import("modules_support.builder") - - -- add target deps modules - if target:orderdeps() then - local deps_sourcefiles = dependency_scanner.get_targetdeps_modules(target) - if deps_sourcefiles then - table.join2(sourcebatch.sourcefiles, deps_sourcefiles) - end - end + if target:data("cxx.has_modules") then + import("modules_support.compiler_support") + import("modules_support.dependency_scanner") + import("modules_support.builder") - -- append std module - local std_modules = compiler_support.get_stdmodules(target) - if std_modules then - table.join2(sourcebatch.sourcefiles, std_modules) - target:fileconfig_set(std_modules[1], {external = true}) - target:fileconfig_set(std_modules[2], {external = true}) + -- add target deps modules + if target:orderdeps() then + local deps_sourcefiles = dependency_scanner.get_targetdeps_modules(target) + if deps_sourcefiles then + table.join2(sourcebatch.sourcefiles, deps_sourcefiles) end + end - -- extract packages modules dependencies - local package_modules_data = dependency_scanner.get_all_packages_modules(target, opt) - if package_modules_data then - -- append to sourcebatch - for _, package_module_data in table.orderpairs(package_modules_data) do - table.insert(sourcebatch.sourcefiles, package_module_data.file) - target:fileconfig_set(package_module_data.file, {external = true, defines = package_module_data.metadata.defines}) - end + -- append std module + local std_modules = compiler_support.get_stdmodules(target) + if std_modules then + table.join2(sourcebatch.sourcefiles, std_modules) + target:fileconfig_set(std_modules[1], {external = true}) + target:fileconfig_set(std_modules[2], {external = true}) + end + + -- extract packages modules dependencies + local package_modules_data = dependency_scanner.get_all_packages_modules(target, opt) + if package_modules_data then + -- append to sourcebatch + for _, package_module_data in table.orderpairs(package_modules_data) do + table.insert(sourcebatch.sourcefiles, package_module_data.file) + target:fileconfig_set(package_module_data.file, {external = true, defines = package_module_data.metadata.defines}) end + end - opt.batchjobs = true + opt.batchjobs = true - compiler_support.patch_sourcebatch(target, sourcebatch, opt) - local modules = dependency_scanner.get_module_dependencies(target, sourcebatch, opt) + compiler_support.patch_sourcebatch(target, sourcebatch, opt) + local modules = dependency_scanner.get_module_dependencies(target, sourcebatch, opt) + if not target:is_moduleonly() then -- avoid building non referenced modules sourcebatch.objectfiles = dependency_scanner.sort_modules_by_dependencies(target, sourcebatch.objectfiles, modules) @@ -118,58 +118,57 @@ rule("c++.build.modules.builder") -- cull external modules objectfile compiler_support.cull_objectfiles(target, modules, sourcebatch) - compiler_support.localcache():set2(target:name(), "c++.modules", modules) - compiler_support.localcache():save() else - -- avoid duplicate linking of object files of non-module programs sourcebatch.objectfiles = {} end + + compiler_support.localcache():set2(target:name(), "c++.modules", modules) + compiler_support.localcache():save() else - sourcebatch.sourcefiles = {} + -- avoid duplicate linking of object files of non-module programs sourcebatch.objectfiles = {} - sourcebatch.dependfiles = {} end end, {batch = true}) -- serial compilation only, usually used to support project generator before_buildcmd_files(function(target, batchcmds, sourcebatch, opt) - if not target:rule("c++.moduleonly") then - if target:data("cxx.has_modules") then - import("modules_support.compiler_support") - import("modules_support.dependency_scanner") - import("modules_support.builder") - - -- add target deps modules - if target:orderdeps() then - local deps_sourcefiles = dependency_scanner.get_targetdeps_modules(target) - if deps_sourcefiles then - table.join2(sourcebatch.sourcefiles, deps_sourcefiles) - end - end + if target:data("cxx.has_modules") then + import("modules_support.compiler_support") + import("modules_support.dependency_scanner") + import("modules_support.builder") - -- append std module - local std_modules = compiler_support.get_stdmodules(target) - if std_modules then - table.join2(sourcebatch.sourcefiles, std_modules) - target:fileconfig_set(std_modules[1], {external = true}) - target:fileconfig_set(std_modules[2], {external = true}) + -- add target deps modules + if target:orderdeps() then + local deps_sourcefiles = dependency_scanner.get_targetdeps_modules(target) + if deps_sourcefiles then + table.join2(sourcebatch.sourcefiles, deps_sourcefiles) end + end - -- extract packages modules dependencies - local package_modules_data = dependency_scanner.get_all_packages_modules(target, opt) - if package_modules_data then - -- append to sourcebatch - for _, package_module_data in table.orderpairs(package_modules_data) do - table.insert(sourcebatch.sourcefiles, package_module_data.file) - target:fileconfig_set(package_module_data.file, {external = true, defines = package_module_data.metadata.defines}) - end + -- append std module + local std_modules = compiler_support.get_stdmodules(target) + if std_modules then + table.join2(sourcebatch.sourcefiles, std_modules) + target:fileconfig_set(std_modules[1], {external = true}) + target:fileconfig_set(std_modules[2], {external = true}) + end + + -- extract packages modules dependencies + local package_modules_data = dependency_scanner.get_all_packages_modules(target, opt) + if package_modules_data then + -- append to sourcebatch + for _, package_module_data in table.orderpairs(package_modules_data) do + table.insert(sourcebatch.sourcefiles, package_module_data.file) + target:fileconfig_set(package_module_data.file, {external = true, defines = package_module_data.metadata.defines}) end + end - opt.batchjobs = false + opt.batchjobs = false - compiler_support.patch_sourcebatch(target, sourcebatch, opt) - local modules = dependency_scanner.get_module_dependencies(target, sourcebatch, opt) + compiler_support.patch_sourcebatch(target, sourcebatch, opt) + local modules = dependency_scanner.get_module_dependencies(target, sourcebatch, opt) + if not target:is_moduleonly() then -- avoid building non referenced modules sourcebatch.objectfiles = dependency_scanner.sort_modules_by_dependencies(target, sourcebatch.objectfiles, modules) @@ -181,12 +180,13 @@ rule("c++.build.modules.builder") -- cull external modules objectfile compiler_support.cull_objectfiles(target, modules, sourcebatch) - compiler_support.localcache():set2(target:name(), "c++.modules", modules) - compiler_support.localcache():save() else -- avoid duplicate linking of object files of non-module programs sourcebatch.objectfiles = {} end + + compiler_support.localcache():set2(target:name(), "c++.modules", modules) + compiler_support.localcache():save() else sourcebatch.sourcefiles = {} sourcebatch.objectfiles = {} @@ -211,48 +211,6 @@ rule("c++.build.modules.builder") end end) --- moduleonly -rule("c++.moduleonly") - add_deps("c++.build.modules.install") - set_extensions(".mpp", ".mxx", ".cppm", ".ixx", ".cpp") - - before_build(function(target) - if target:data("cxx.has_modules") then - import("modules_support.compiler_support") - import("modules_support.dependency_scanner") - - local sourcebatch = target:sourcebatches()["c++.moduleonly"] - - -- add target deps modules - if target:orderdeps() then - local deps_sourcefiles = dependency_scanner.get_targetdeps_modules(target) - if deps_sourcefiles then - table.join2(sourcebatch.sourcefiles, deps_sourcefiles) - end - end - - -- append std module - table.join2(sourcebatch.sourcefiles, compiler_support.get_stdmodules(target) or {}) - - -- extract packages modules dependencies - local package_modules_data = dependency_scanner.get_all_packages_modules(target, opt) - if package_modules_data then - -- append to sourcebatch - for _, package_module_data in table.orderpairs(package_modules_data) do - table.insert(sourcebatch.sourcefiles, package_module_data.file) - target:fileconfig_add(package_module_data.file, {external = true, defines = package_module_data.metadata.defines}) - end - end - - local opt = {batchjobs = true} - - compiler_support.patch_sourcebatch(target, sourcebatch, opt) - local modules = dependency_scanner.get_module_dependencies(target, sourcebatch, opt) - compiler_support.localcache():set2(target:name(), "c++.modules", modules) - compiler_support.localcache():save() - end - end) - -- install modules rule("c++.build.modules.install") set_extensions(".mpp", ".mxx", ".cppm", ".ixx") @@ -266,7 +224,7 @@ rule("c++.build.modules.install") if compiler_support.contains_modules(target) then local modules = compiler_support.localcache():get2(target:name(), "c++.modules") builder.generate_metadata(target, modules) - + compiler_support.install_module_target(target) end end) -- cgit v1.3.1