diff options
| author | ruki <[email protected]> | 2022-08-13 09:37:29 +0800 |
|---|---|---|
| committer | GitHub <[email protected]> | 2022-08-13 09:37:29 +0800 |
| commit | b48b6397a93042487711181b387ad23375de1673 (patch) | |
| tree | 32e6d93517e77bff761fe2b2732ceb6a8947b0b2 /xmake/rules/c++/modules/modules_support/common.lua | |
| parent | 2723282a4fd0af130ac5d65c5b40fa12f7ce803f (diff) | |
| parent | 8dccc2d987d20b6df18360adab034ebd42f6ec9b (diff) | |
Merge pull request #2664 from Arthapz/cxxmodules
Improve MSVC and clang modules compilation
Diffstat (limited to 'xmake/rules/c++/modules/modules_support/common.lua')
| -rw-r--r-- | xmake/rules/c++/modules/modules_support/common.lua | 59 |
1 files changed, 40 insertions, 19 deletions
diff --git a/xmake/rules/c++/modules/modules_support/common.lua b/xmake/rules/c++/modules/modules_support/common.lua index 31ab47a81..39ad17f2e 100644 --- a/xmake/rules/c++/modules/modules_support/common.lua +++ b/xmake/rules/c++/modules/modules_support/common.lua @@ -125,13 +125,24 @@ function bmi_extension(target) return modules_support(target).get_bmi_extension() end +-- has module extension? e.g. *.mpp, ... +function has_module_extension(sourcefile) + local modulexts = _g.modulexts + if modulexts == nil then + modulexts = hashset.of(".mpp", ".mxx", ".cppm", ".ixx") + _g.modulexts = modulexts + end + local extension = path.extension(sourcefile) + return modulexts:has(extension:lower()) +end + -- this target contains module files? function contains_modules(target) local target_with_modules = target:sourcebatches()["c++.build.modules"] and true or false if not target_with_modules then for _, dep in ipairs(target:orderdeps()) do local sourcebatches = dep:sourcebatches() - if sourcebatches and sourcebatches["c++.build.modules"] then + if sourcebatches["c++.build.modules"] then target_with_modules = true break end @@ -196,24 +207,28 @@ function parse_dependency_data(target, moduleinfos) for _, rule in ipairs(moduleinfo.rules) do modules = modules or {} local m = {} - for _, provide in ipairs(rule.provides) do - m.provides = m.provides or {} - assert(provide["logical-name"]) - if provide["compiled-module-path"] then - if not path.is_absolute(provide["compiled-module-path"]) then - m.provides[provide["logical-name"]] = path.absolute(path.translate(provide["compiled-module-path"])) + if rule.provides then + for _, provide in ipairs(rule.provides) do + m.provides = m.provides or {} + assert(provide["logical-name"]) + if provide["compiled-module-path"] then + if not path.is_absolute(provide["compiled-module-path"]) then + m.provides[provide["logical-name"]] = path.absolute(path.translate(provide["compiled-module-path"])) + else + m.provides[provide["logical-name"]] = path.translate(provide["compiled-module-path"]) + end else - m.provides[provide["logical-name"]] = path.translate(provide["compiled-module-path"]) + -- assume path with name + local name = provide["logical-name"] .. bmi_extension(target) + name:replace(":", "-") + m.provides[provide["logical-name"]] = { + bmi = path.join(cachedir, name), + sourcefile = moduleinfo.sourcefile + } end - else - -- assume path with name - local name = provide["logical-name"] .. bmi_extension(target) - name:replace(":", "-") - m.provides[provide["logical-name"]] = { - bmi = path.join(cachedir, name), - sourcefile = moduleinfo.sourcefile - } end + else + m.cppfile = moduleinfo.sourcefile end assert(rule["primary-output"]) modules[path.translate(rule["primary-output"])] = m @@ -373,6 +388,11 @@ function fallback_generate_dependencies(target, jsonfile, sourcefile) module_name = line:match("export%s+module%s+(.+)%s*;") end local module_depname = line:match("import%s+(.+)%s*;") + -- we need parse module interface dep in cxx/impl_unit.cpp, e.g. hello.mpp and hello_impl.cpp + -- @see https://github.com/xmake-io/xmake/pull/2664#issuecomment-1213167314 + if not module_depname and not has_module_extension(sourcefile) then + module_depname = line:match("module%s+(.+)%s*;") + end if module_depname then local module_dep = {} -- partition? import :xxx; @@ -523,12 +543,13 @@ end -- append headerunits objectfiles to link function append_headerunits_objectfiles(target) - local cache = localcache():get("headerunit_objectfiles") or {} + local cachekey = target:name() .. "headerunit_objectfiles" + local cache = localcache():get(cachekey) or {} if target:is_binary() then target:add("ldflags", cache, {force = true}) - elseif target:is_static() == "static" then + elseif target:is_static() then target:add("arflags", cache, {force = true}) - elseif target:is_shared() == "shared" then + elseif target:is_shared() then target:add("shflags", cache, {force = true}) end end |
