From 767f57b2e281a62f87d4e254cd93a41af00b55a8 Mon Sep 17 00:00:00 2001 From: ruki Date: Thu, 14 Oct 2021 22:45:34 +0800 Subject: improve c++ modules test --- .gitignore | 3 +++ tests/projects/c++/modules/partitions/src/math.math1.mpp | 5 +++++ tests/projects/c++/modules/partitions/src/math.math2.mpp | 7 +++++++ tests/projects/c++/modules/partitions/src/math1.mpp | 5 ----- tests/projects/c++/modules/partitions/src/math2.mpp | 7 ------- tests/projects/c++/modules/submodules/src/math.math1.mpp | 5 +++++ tests/projects/c++/modules/submodules/src/math.math2.mpp | 7 +++++++ tests/projects/c++/modules/submodules/src/math1.mpp | 5 ----- tests/projects/c++/modules/submodules/src/math2.mpp | 7 ------- xmake/rules/c++/modules/build_modulefiles.lua | 6 ++++-- 10 files changed, 31 insertions(+), 26 deletions(-) create mode 100644 tests/projects/c++/modules/partitions/src/math.math1.mpp create mode 100644 tests/projects/c++/modules/partitions/src/math.math2.mpp delete mode 100644 tests/projects/c++/modules/partitions/src/math1.mpp delete mode 100644 tests/projects/c++/modules/partitions/src/math2.mpp create mode 100644 tests/projects/c++/modules/submodules/src/math.math1.mpp create mode 100644 tests/projects/c++/modules/submodules/src/math.math2.mpp delete mode 100644 tests/projects/c++/modules/submodules/src/math1.mpp delete mode 100644 tests/projects/c++/modules/submodules/src/math2.mpp diff --git a/.gitignore b/.gitignore index 1631dd04d..7107445a1 100644 --- a/.gitignore +++ b/.gitignore @@ -5,6 +5,9 @@ .xmake/ build/ +# gcc cache +gcm.cache + # for VS Code .vscode/ diff --git a/tests/projects/c++/modules/partitions/src/math.math1.mpp b/tests/projects/c++/modules/partitions/src/math.math1.mpp new file mode 100644 index 000000000..8537d161a --- /dev/null +++ b/tests/projects/c++/modules/partitions/src/math.math1.mpp @@ -0,0 +1,5 @@ +export module math:math1; + +export int add(int fir, int sec) { + return fir + sec; +} diff --git a/tests/projects/c++/modules/partitions/src/math.math2.mpp b/tests/projects/c++/modules/partitions/src/math.math2.mpp new file mode 100644 index 000000000..78e14ed6f --- /dev/null +++ b/tests/projects/c++/modules/partitions/src/math.math2.mpp @@ -0,0 +1,7 @@ +export module math:math2; + +export { + int mul(int fir, int sec) { + return fir * sec; + } +} diff --git a/tests/projects/c++/modules/partitions/src/math1.mpp b/tests/projects/c++/modules/partitions/src/math1.mpp deleted file mode 100644 index 8537d161a..000000000 --- a/tests/projects/c++/modules/partitions/src/math1.mpp +++ /dev/null @@ -1,5 +0,0 @@ -export module math:math1; - -export int add(int fir, int sec) { - return fir + sec; -} diff --git a/tests/projects/c++/modules/partitions/src/math2.mpp b/tests/projects/c++/modules/partitions/src/math2.mpp deleted file mode 100644 index 78e14ed6f..000000000 --- a/tests/projects/c++/modules/partitions/src/math2.mpp +++ /dev/null @@ -1,7 +0,0 @@ -export module math:math2; - -export { - int mul(int fir, int sec) { - return fir * sec; - } -} diff --git a/tests/projects/c++/modules/submodules/src/math.math1.mpp b/tests/projects/c++/modules/submodules/src/math.math1.mpp new file mode 100644 index 000000000..3e06bf426 --- /dev/null +++ b/tests/projects/c++/modules/submodules/src/math.math1.mpp @@ -0,0 +1,5 @@ +export module math.math1; + +export int add(int fir, int sec) { + return fir + sec; +} diff --git a/tests/projects/c++/modules/submodules/src/math.math2.mpp b/tests/projects/c++/modules/submodules/src/math.math2.mpp new file mode 100644 index 000000000..f6c5381c3 --- /dev/null +++ b/tests/projects/c++/modules/submodules/src/math.math2.mpp @@ -0,0 +1,7 @@ +export module math.math2; + +export { + int mul(int fir, int sec) { + return fir * sec; + } +} diff --git a/tests/projects/c++/modules/submodules/src/math1.mpp b/tests/projects/c++/modules/submodules/src/math1.mpp deleted file mode 100644 index 3e06bf426..000000000 --- a/tests/projects/c++/modules/submodules/src/math1.mpp +++ /dev/null @@ -1,5 +0,0 @@ -export module math.math1; - -export int add(int fir, int sec) { - return fir + sec; -} diff --git a/tests/projects/c++/modules/submodules/src/math2.mpp b/tests/projects/c++/modules/submodules/src/math2.mpp deleted file mode 100644 index f6c5381c3..000000000 --- a/tests/projects/c++/modules/submodules/src/math2.mpp +++ /dev/null @@ -1,7 +0,0 @@ -export module math.math2; - -export { - int mul(int fir, int sec) { - return fir * sec; - } -} diff --git a/xmake/rules/c++/modules/build_modulefiles.lua b/xmake/rules/c++/modules/build_modulefiles.lua index efc1c3a38..c0a5ae381 100644 --- a/xmake/rules/c++/modules/build_modulefiles.lua +++ b/xmake/rules/c++/modules/build_modulefiles.lua @@ -42,13 +42,15 @@ function _build_modulefiles_clang(target, sourcebatch, opt) sourcebatch.objectfiles = sourcebatch.objectfiles or {} sourcebatch.dependfiles = sourcebatch.dependfiles or {} for _, sourcefile in ipairs(sourcebatch.sourcefiles) do - local objectfile = target:objectfile(sourcefile) .. ".pcm" + --local objectfile = target:objectfile(sourcefile) .. ".pcm" + local objectfile = path.join(cachedir, path.basename(sourcefile) .. ".pcm") table.insert(sourcebatch.objectfiles, objectfile) table.insert(sourcebatch.dependfiles, target:dependfile(objectfile)) end -- compile module files to *.pcm opt = table.join(opt, {configs = {force = {cxxflags = {modulesflag, + "-fimplicit-modules", "-fimplicit-module-maps", "-fprebuilt-module-path=" .. cachedir, "--precompile", "-x c++-module", "-fmodules-cache-path=" .. cachedir}}}}) import("private.action.build.object").build(target, sourcebatch, opt) @@ -62,7 +64,7 @@ function _build_modulefiles_clang(target, sourcebatch, opt) sourcebatch.dependfiles[idx] = target:dependfile(objectfile) table.insert(modulefiles, modulefile) end - opt.configs = {cxxflags = {modulesflag, "-fmodules-cache-path=" .. cachedir}} + opt.configs = {cxxflags = {modulesflag, "-fmodules-cache-path=" .. cachedir, "-fimplicit-modules", "-fimplicit-module-maps", "-fprebuilt-module-path=" .. cachedir}} opt.quiet = true import("private.action.build.object").build(target, sourcebatch, opt) -- cgit v1.3.1