From cf0827635b313ccc68b8cf2c1744556289321c7b Mon Sep 17 00:00:00 2001 From: ruki Date: Fri, 7 Jul 2023 23:32:50 +0800 Subject: fix headerunit errors for msvc #3927 --- tests/projects/c++/modules/user_headerunit2/a/a.mpp | 3 +++ tests/projects/c++/modules/user_headerunit2/a/c.hpp | 1 + tests/projects/c++/modules/user_headerunit2/a/d.hpp | 1 + tests/projects/c++/modules/user_headerunit2/a/xmake.lua | 4 ++++ tests/projects/c++/modules/user_headerunit2/b/b.mpp | 3 +++ tests/projects/c++/modules/user_headerunit2/b/xmake.lua | 5 +++++ tests/projects/c++/modules/user_headerunit2/test.lua | 1 + tests/projects/c++/modules/user_headerunit2/xmake.lua | 4 ++++ xmake/rules/c++/modules/modules_support/msvc.lua | 16 +++++++++++++++- 9 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 tests/projects/c++/modules/user_headerunit2/a/a.mpp create mode 100644 tests/projects/c++/modules/user_headerunit2/a/c.hpp create mode 100644 tests/projects/c++/modules/user_headerunit2/a/d.hpp create mode 100644 tests/projects/c++/modules/user_headerunit2/a/xmake.lua create mode 100644 tests/projects/c++/modules/user_headerunit2/b/b.mpp create mode 100644 tests/projects/c++/modules/user_headerunit2/b/xmake.lua create mode 100644 tests/projects/c++/modules/user_headerunit2/test.lua create mode 100644 tests/projects/c++/modules/user_headerunit2/xmake.lua diff --git a/tests/projects/c++/modules/user_headerunit2/a/a.mpp b/tests/projects/c++/modules/user_headerunit2/a/a.mpp new file mode 100644 index 000000000..d940a0635 --- /dev/null +++ b/tests/projects/c++/modules/user_headerunit2/a/a.mpp @@ -0,0 +1,3 @@ +export module A; +import "c.hpp"; +import "d.hpp"; diff --git a/tests/projects/c++/modules/user_headerunit2/a/c.hpp b/tests/projects/c++/modules/user_headerunit2/a/c.hpp new file mode 100644 index 000000000..7c6c88c00 --- /dev/null +++ b/tests/projects/c++/modules/user_headerunit2/a/c.hpp @@ -0,0 +1 @@ +#pragma once \ No newline at end of file diff --git a/tests/projects/c++/modules/user_headerunit2/a/d.hpp b/tests/projects/c++/modules/user_headerunit2/a/d.hpp new file mode 100644 index 000000000..7c6c88c00 --- /dev/null +++ b/tests/projects/c++/modules/user_headerunit2/a/d.hpp @@ -0,0 +1 @@ +#pragma once \ No newline at end of file diff --git a/tests/projects/c++/modules/user_headerunit2/a/xmake.lua b/tests/projects/c++/modules/user_headerunit2/a/xmake.lua new file mode 100644 index 000000000..cffe161b2 --- /dev/null +++ b/tests/projects/c++/modules/user_headerunit2/a/xmake.lua @@ -0,0 +1,4 @@ +target("a") + set_languages("cxxlatest") + set_kind("object") + add_files("a.mpp") diff --git a/tests/projects/c++/modules/user_headerunit2/b/b.mpp b/tests/projects/c++/modules/user_headerunit2/b/b.mpp new file mode 100644 index 000000000..486174a4b --- /dev/null +++ b/tests/projects/c++/modules/user_headerunit2/b/b.mpp @@ -0,0 +1,3 @@ +export module B; +import A; +import "../a/c.hpp"; \ No newline at end of file diff --git a/tests/projects/c++/modules/user_headerunit2/b/xmake.lua b/tests/projects/c++/modules/user_headerunit2/b/xmake.lua new file mode 100644 index 000000000..98cff4124 --- /dev/null +++ b/tests/projects/c++/modules/user_headerunit2/b/xmake.lua @@ -0,0 +1,5 @@ +target("b") + add_deps("a") + set_languages("cxxlatest") + set_kind("object") + add_files("b.mpp") diff --git a/tests/projects/c++/modules/user_headerunit2/test.lua b/tests/projects/c++/modules/user_headerunit2/test.lua new file mode 100644 index 000000000..c18e5a1d0 --- /dev/null +++ b/tests/projects/c++/modules/user_headerunit2/test.lua @@ -0,0 +1 @@ +inherit(".test_headerunits") diff --git a/tests/projects/c++/modules/user_headerunit2/xmake.lua b/tests/projects/c++/modules/user_headerunit2/xmake.lua new file mode 100644 index 000000000..09517502b --- /dev/null +++ b/tests/projects/c++/modules/user_headerunit2/xmake.lua @@ -0,0 +1,4 @@ +includes("a", "b") +target("test") + add_deps("a", "b") + set_kind("phony") diff --git a/xmake/rules/c++/modules/modules_support/msvc.lua b/xmake/rules/c++/modules/modules_support/msvc.lua index 3ee88715c..411b32b20 100644 --- a/xmake/rules/c++/modules/modules_support/msvc.lua +++ b/xmake/rules/c++/modules/modules_support/msvc.lua @@ -226,6 +226,7 @@ function generate_headerunit_for_batchjob(target, name, flags, objectfile, index progress.show((index * 100) / total, "${color.build.object}compiling.headerunit.$(mode) %s", name) _compile(target, table.join(common_flags, flags)) _add_objectfile_to_link_arguments(target, objectfile) + common.memcache():set2(name, "generating", false) end end @@ -740,7 +741,20 @@ function get_requiresflags(target, requires, opt) local modulemap_ = _get_modulemap_from_mapper(dep) if modulemap_[name] then table.join2(flags, modulemap_[name].flag) - table.join2(flags, modulemap_[name].deps or {}) + -- we need ignore headerunits from deps + -- @see https://github.com/xmake-io/xmake/issues/3925 + local skip = 0 + for _, flag in ipairs(modulemap_[name].deps) do + if flag:find("headerUnit:quote", 1, true) then + skip = 2 + end + if skip == 0 then + table.insert(flags, flag) + end + if skip > 0 then + skip = skip - 1 + end + end already_mapped_modules[name] = true goto continue end -- cgit v1.3.1 From 37027172b64368c13b1498a1a9b1ce1940831cce Mon Sep 17 00:00:00 2001 From: ruki Date: Sat, 8 Jul 2023 00:56:04 +0800 Subject: fix includedir for gcc --- xmake/rules/c++/modules/modules_support/gcc.lua | 32 +++++++++++++++++++++---- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/xmake/rules/c++/modules/modules_support/gcc.lua b/xmake/rules/c++/modules/modules_support/gcc.lua index 3c509edf5..a5452601a 100644 --- a/xmake/rules/c++/modules/modules_support/gcc.lua +++ b/xmake/rules/c++/modules/modules_support/gcc.lua @@ -44,14 +44,15 @@ end -- /usr/include/c++/11/iostream build/.gens/stl_headerunit/linux/x86_64/release/stlmodules/cache/iostream.gcm -- hello build/.gens/stl_headerunit/linux/x86_64/release/rules/modules/cache/hello.gcm -- -function _add_module_to_mapper(file, module, bmi) +function _add_module_to_mapper(file, modulepath, bmi) +-- modulepath = path.normalize(modulepath) for line in io.lines(file) do - if line:startswith(module .. " ") then + if line:startswith(modulepath .. " ") then return false end end local f = io.open(file, "a") - f:print("%s %s", module, bmi) + f:print("%s %s", modulepath, bmi) f:close() return true end @@ -293,6 +294,7 @@ function generate_user_headerunits_for_batchjobs(target, batchjobs, headerunits, -- build headerunits local projectdir = os.projectdir() for _, headerunit in ipairs(headerunits) do + print(headerunit) local headerunit_path if headerunit.type == ":quote" then headerunit_path = path.join(".", path.relative(headerunit.path, projectdir)) @@ -315,7 +317,17 @@ function generate_user_headerunits_for_batchjobs(target, batchjobs, headerunits, -- generate headerunit local args = { "-c" } if headerunit.type == ":quote" then - table.join2(args, { "-I", path.directory(path.relative(headerunit.path, projectdir)), "-x", "c++-user-header", headerunit.name }) + local includedir + local p = headerunit.path + if p:endswith(headerunit.name) then + includedir = p:sub(1, #p - #headerunit.name - 1) + else + includedir = path.directory(p) + end + if path.is_absolute(includedir) then + includedir = path.relative(includedir, projectdir) + end + table.join2(args, { "-I", includedir, "-x", "c++-user-header", headerunit.name }) elseif headerunit.type == ":angle" then table.join2(args, { "-x", "c++-system-header", headerunit.name }) end @@ -338,7 +350,17 @@ function generate_user_headerunits_for_batchcmds(target, batchcmds, headerunits, local flags = {"-c"} local headerunit_path if headerunit.type == ":quote" then - table.join2(flags, {"-I", path(path.relative(headerunit.path, projectdir)):directory(), "-x", "c++-user-header", headerunit.name}) + local includedir + local p = headerunit.path + if p:endswith(headerunit.name) then + includedir = p:sub(1, #p - #headerunit.name - 1) + else + includedir = path.directory(p) + end + if path.is_absolute(includedir) then + includedir = path.relative(includedir, projectdir) + end + table.join2(flags, {"-I", path(includedir), "-x", "c++-user-header", headerunit.name}) headerunit_path = path.join(".", path.relative(headerunit.path, projectdir)) elseif headerunit.type == ":angle" then table.join2(flags, {"-x", "c++-system-header", headerunit.name}) -- cgit v1.3.1 From 97a18a69740f5b464d2bb8649c65d5ac7cf3a815 Mon Sep 17 00:00:00 2001 From: ruki Date: Sat, 8 Jul 2023 00:56:18 +0800 Subject: remove unused line --- xmake/rules/c++/modules/modules_support/gcc.lua | 1 - 1 file changed, 1 deletion(-) diff --git a/xmake/rules/c++/modules/modules_support/gcc.lua b/xmake/rules/c++/modules/modules_support/gcc.lua index a5452601a..00a63bb03 100644 --- a/xmake/rules/c++/modules/modules_support/gcc.lua +++ b/xmake/rules/c++/modules/modules_support/gcc.lua @@ -45,7 +45,6 @@ end -- hello build/.gens/stl_headerunit/linux/x86_64/release/rules/modules/cache/hello.gcm -- function _add_module_to_mapper(file, modulepath, bmi) --- modulepath = path.normalize(modulepath) for line in io.lines(file) do if line:startswith(modulepath .. " ") then return false -- cgit v1.3.1