From 92bd964f8e420a2bb72fd82a17603b5fddc865d3 Mon Sep 17 00:00:00 2001 From: Arthur LAURENT Date: Thu, 4 Aug 2022 22:44:13 +0200 Subject: Insert deps includedirs/sysincludedirs when search angle header files --- xmake/rules/c++/modules/modules_support/common.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'xmake/rules/c++/modules/modules_support/common.lua') diff --git a/xmake/rules/c++/modules/modules_support/common.lua b/xmake/rules/c++/modules/modules_support/common.lua index 331f1bea5..a8b36e0fa 100644 --- a/xmake/rules/c++/modules/modules_support/common.lua +++ b/xmake/rules/c++/modules/modules_support/common.lua @@ -279,7 +279,7 @@ end function find_angle_header_file(target, file) local headerpaths = modules_support(target).toolchain_includedirs(target) for _, dep in ipairs(target:orderdeps()) do - table.insert(headerpaths, dep:scriptdir()) + table.insert(headerpaths, dep:get("sysincludedirs") or dep:get("includedirs")) end for _, pkg in ipairs(target:pkgs()) do local includedirs = pkg:get("sysincludedirs") or pkg:get("includedirs") -- cgit v1.3.1 From 9051b99608fe2f339eea7ac4c9eab8b799e230df Mon Sep 17 00:00:00 2001 From: Arthur LAURENT Date: Fri, 5 Aug 2022 04:41:46 +0200 Subject: Move headerunits extracting into a dedicated function --- xmake/rules/c++/modules/modules_support/common.lua | 31 ++++++++++++++++++++-- xmake/rules/c++/modules/modules_support/msvc.lua | 2 +- xmake/rules/c++/modules/xmake.lua | 28 +++---------------- 3 files changed, 34 insertions(+), 27 deletions(-) (limited to 'xmake/rules/c++/modules/modules_support/common.lua') diff --git a/xmake/rules/c++/modules/modules_support/common.lua b/xmake/rules/c++/modules/modules_support/common.lua index a8b36e0fa..18647ded1 100644 --- a/xmake/rules/c++/modules/modules_support/common.lua +++ b/xmake/rules/c++/modules/modules_support/common.lua @@ -26,6 +26,7 @@ import("core.tool.compiler") import("core.cache.memcache", {alias = "_memcache"}) import("core.project.project") import("lib.detect.find_file") +import("stl_headers") -- get memcache function memcache() @@ -53,12 +54,38 @@ function modules_cachedir(target) return cachedir end +-- get headerunits info +function get_headerunits(target, sourcebatch) + local headerunits + local stl_headerunits + local modules = target:data("cxx.modules") + for _, objectfile in ipairs(sourcebatch.objectfiles) do + local m = modules[objectfile] + if m then + for name, r in pairs(m.requires) do + if r.method ~= "by-name" then + local unittype = r.method == "include-angle" and ":angle" or ":quote" + + if stl_headers.is_stl_header(name) then + stl_headerunits = stl_headerunits or {} + table.insert(stl_headerunits, {name = name, path = r.path, type = unittype}) + else + headerunits = headerunits or {} + table.insert(headerunits, {name = name, path = r.path, type = unittype}) + end + end + end + end + end + return headerunits, stl_headerunits +end + -- patch sourcebatch function patch_sourcebatch(target, sourcebatch, opt) local cachedir = modules_cachedir(target) sourcebatch.sourcekind = "cxx" - sourcebatch.objectfiles = sourcebatch.objectfiles or {} - sourcebatch.dependfiles = sourcebatch.dependfiles or {} + sourcebatch.objectfiles = {} + sourcebatch.dependfiles = {} for _, sourcefile in ipairs(sourcebatch.sourcefiles) do local objectfile = target:objectfile(sourcefile) local dependfile = target:dependfile(objectfile) diff --git a/xmake/rules/c++/modules/modules_support/msvc.lua b/xmake/rules/c++/modules/modules_support/msvc.lua index 04d34f02c..2c3818995 100644 --- a/xmake/rules/c++/modules/modules_support/msvc.lua +++ b/xmake/rules/c++/modules/modules_support/msvc.lua @@ -183,7 +183,7 @@ function generate_user_headerunits(target, batchcmds, headerunits, opt) local bmifile = (outputdir and path.join(outputdir, bmifilename) or bmifilename) batchcmds:mkdir(path.directory(objectfile)) - local args = {headernameflag .. headerunit.type, headerunit.path, ifcoutputflag, outputdir, "/Fo" .. objectfile} + local args = {headernameflag .. headerunit.type, path.normalize(headerunit.path), ifcoutputflag, outputdir, "/Fo" .. objectfile} batchcmds:show_progress(opt.progress, "${color.build.object}generating.cxx.headerunit.bmi %s", headerunit.name) batchcmds:vrunv(compinst:program(), table.join(compinst:compflags({target = target}), common_args, args), {envs = vcvars}) diff --git a/xmake/rules/c++/modules/xmake.lua b/xmake/rules/c++/modules/xmake.lua index 7c68f25e0..45ba38ca8 100644 --- a/xmake/rules/c++/modules/xmake.lua +++ b/xmake/rules/c++/modules/xmake.lua @@ -82,35 +82,14 @@ rule("c++.build.modules.builder") return end - -- patch sourcebatch import("modules_support.common") import("modules_support.stl_headers") - sourcebatch.objectfiles = {} - sourcebatch.dependfiles = {} + + -- patch sourcebatch common.patch_sourcebatch(target, sourcebatch, opt) -- get headerunits info - local headerunits - local stl_headerunits - local modules = target:data("cxx.modules") - for _, objectfile in ipairs(sourcebatch.objectfiles) do - local m = modules[objectfile] - if m then - for name, r in pairs(m.requires) do - if r.method ~= "by-name" then - local unittype = r.method == "include-angle" and ":angle" or ":quote" - - if stl_headers.is_stl_header(name) then - stl_headerunits = stl_headerunits or {} - table.insert(stl_headerunits, {name = name, path = r.path, type = unittype}) - else - headerunits = headerunits or {} - table.insert(headerunits, {name = name, path = r.path, type = unittype,}) - end - end - end - end - end + local headerunits, stl_headerunits = common.get_headerunits(target, sourcebatch) -- generate headerunits local headerunits_flags @@ -132,6 +111,7 @@ rule("c++.build.modules.builder") end -- topological sort + local modules = target:data("cxx.modules") local objectfiles = common.sort_modules_by_dependencies(sourcebatch.objectfiles, modules) modules_support.build_modules(target, batchcmds, objectfiles, modules, opt) end) -- cgit v1.3.1 From 279689863b3ced10d7d1639b77ec57c70db11fde Mon Sep 17 00:00:00 2001 From: Arthur LAURENT Date: Fri, 5 Aug 2022 05:33:21 +0200 Subject: Do not insert duplicate header unit --- xmake/rules/c++/modules/modules_support/common.lua | 8 ++++++-- xmake/rules/c++/modules/xmake.lua | 3 --- 2 files changed, 6 insertions(+), 5 deletions(-) (limited to 'xmake/rules/c++/modules/modules_support/common.lua') diff --git a/xmake/rules/c++/modules/modules_support/common.lua b/xmake/rules/c++/modules/modules_support/common.lua index 18647ded1..8d3c8456d 100644 --- a/xmake/rules/c++/modules/modules_support/common.lua +++ b/xmake/rules/c++/modules/modules_support/common.lua @@ -68,10 +68,14 @@ function get_headerunits(target, sourcebatch) if stl_headers.is_stl_header(name) then stl_headerunits = stl_headerunits or {} - table.insert(stl_headerunits, {name = name, path = r.path, type = unittype}) + if not table.find_if(stl_headerunits, function(i, v) return v.name == name end) then + table.insert(stl_headerunits, {name = name, path = r.path, type = unittype}) + end else headerunits = headerunits or {} - table.insert(headerunits, {name = name, path = r.path, type = unittype}) + if not table.find_if(headerunits, function(i, v) return v.name == name end) then + table.insert(headerunits, {name = name, path = r.path, type = unittype}) + end end end end diff --git a/xmake/rules/c++/modules/xmake.lua b/xmake/rules/c++/modules/xmake.lua index 45ba38ca8..4eae5f522 100644 --- a/xmake/rules/c++/modules/xmake.lua +++ b/xmake/rules/c++/modules/xmake.lua @@ -98,9 +98,6 @@ rule("c++.build.modules.builder") if stl_headerunits then headerunits_flags = headerunits_flags or {} table.join2(headerunits_flags, modules_support.generate_stl_headerunits(target, batchcmds, stl_headerunits, opt)) - - -- force STL header unit generation - batchcmds:runcmds(opt) end if headerunits then headerunits_flags = headerunits_flags or {} -- cgit v1.3.1 From 59bdca35cd89624f1706ece6fb9d3b448a491a86 Mon Sep 17 00:00:00 2001 From: Arthur LAURENT Date: Fri, 5 Aug 2022 06:30:01 +0200 Subject: Improve find angle header file --- xmake/rules/c++/modules/modules_support/common.lua | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'xmake/rules/c++/modules/modules_support/common.lua') diff --git a/xmake/rules/c++/modules/modules_support/common.lua b/xmake/rules/c++/modules/modules_support/common.lua index 8d3c8456d..564517ea1 100644 --- a/xmake/rules/c++/modules/modules_support/common.lua +++ b/xmake/rules/c++/modules/modules_support/common.lua @@ -310,7 +310,10 @@ end function find_angle_header_file(target, file) local headerpaths = modules_support(target).toolchain_includedirs(target) for _, dep in ipairs(target:orderdeps()) do - table.insert(headerpaths, dep:get("sysincludedirs") or dep:get("includedirs")) + local includedirs = dep:get("sysincludedirs") or dep:get("includedirs") + if includedirs then + table.join2(headerpaths, includedirs) + end end for _, pkg in ipairs(target:pkgs()) do local includedirs = pkg:get("sysincludedirs") or pkg:get("includedirs") -- cgit v1.3.1 From a4f39242acb700b507c3fdd026e4fb77c4e13510 Mon Sep 17 00:00:00 2001 From: Arthur LAURENT Date: Fri, 5 Aug 2022 06:35:28 +0200 Subject: Fix find_angle_header_file pkgs discovery --- xmake/rules/c++/modules/modules_support/common.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'xmake/rules/c++/modules/modules_support/common.lua') diff --git a/xmake/rules/c++/modules/modules_support/common.lua b/xmake/rules/c++/modules/modules_support/common.lua index 564517ea1..1be3b5170 100644 --- a/xmake/rules/c++/modules/modules_support/common.lua +++ b/xmake/rules/c++/modules/modules_support/common.lua @@ -315,7 +315,7 @@ function find_angle_header_file(target, file) table.join2(headerpaths, includedirs) end end - for _, pkg in ipairs(target:pkgs()) do + for _, pkg in pairs(target:pkgs()) do local includedirs = pkg:get("sysincludedirs") or pkg:get("includedirs") if includedirs then table.join2(headerpaths, includedirs) -- cgit v1.3.1 From a7e5b395286033c03d45b260713304ab04c7cc8a Mon Sep 17 00:00:00 2001 From: Arthur LAURENT Date: Fri, 5 Aug 2022 08:27:09 +0200 Subject: Use common stl cache across targets --- xmake/rules/c++/modules/modules_support/common.lua | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'xmake/rules/c++/modules/modules_support/common.lua') diff --git a/xmake/rules/c++/modules/modules_support/common.lua b/xmake/rules/c++/modules/modules_support/common.lua index 1be3b5170..9c15cffbe 100644 --- a/xmake/rules/c++/modules/modules_support/common.lua +++ b/xmake/rules/c++/modules/modules_support/common.lua @@ -35,10 +35,7 @@ end -- get stl modules cache directory function stlmodules_cachedir(target) - local stlcachedir = path.join(target:autogendir(), "stlmodules", "cache") - if target:has_tool("cxx", "clang", "clangxx") then - stlcachedir = path.join(config.buildir(), "stlmodules", "cache") - end + local stlcachedir = path.join(config.buildir(), "stlmodules", "cache") if not os.isdir(stlcachedir) then os.mkdir(stlcachedir) end -- cgit v1.3.1