diff options
| author | ruki <[email protected]> | 2024-02-02 09:50:14 +0800 |
|---|---|---|
| committer | GitHub <[email protected]> | 2024-02-02 09:50:14 +0800 |
| commit | b81eed59a532fdb69f8ef8533cf5b9ae22c381d8 (patch) | |
| tree | a6dc890de365cb05bbc4b3d46ed2e909dc4069e4 /tests/projects/c++/modules | |
| parent | 5c31fdb50c3230db5dd259d97285a8ac9e0fdf0c (diff) | |
| parent | b1005e8b51783d6ae0d997345dc365b7b6e3cbdf (diff) | |
Merge pull request #4321 from Arthapz/improve-modules-support
Refactor modules support
Diffstat (limited to 'tests/projects/c++/modules')
26 files changed, 142 insertions, 49 deletions
diff --git a/tests/projects/c++/modules/aliased_headerunit/src/foo/hello.mpp b/tests/projects/c++/modules/aliased_headerunit/src/foo/hello.mpp new file mode 100644 index 000000000..0a8de6291 --- /dev/null +++ b/tests/projects/c++/modules/aliased_headerunit/src/foo/hello.mpp @@ -0,0 +1,12 @@ +module; +#include <cstdio> + +export module hello; + +import "../header.hpp"; + +export namespace hello { + void say(const char *arg) { + printf("%s: %s\n", FOO, arg); + } +} diff --git a/tests/projects/c++/modules/aliased_headerunit/src/header.hpp b/tests/projects/c++/modules/aliased_headerunit/src/header.hpp new file mode 100644 index 000000000..ab02a6792 --- /dev/null +++ b/tests/projects/c++/modules/aliased_headerunit/src/header.hpp @@ -0,0 +1,5 @@ +#pragma once + +namespace hello { + inline constexpr auto FOO = "Hello"; +} diff --git a/tests/projects/c++/modules/aliased_headerunit/src/main.cpp b/tests/projects/c++/modules/aliased_headerunit/src/main.cpp new file mode 100644 index 000000000..ad786367e --- /dev/null +++ b/tests/projects/c++/modules/aliased_headerunit/src/main.cpp @@ -0,0 +1,7 @@ +import hello; +import "header.hpp"; + +int main() { + hello::say(hello::FOO); + return 0; +} diff --git a/tests/projects/c++/modules/aliased_headerunit/test.lua b/tests/projects/c++/modules/aliased_headerunit/test.lua new file mode 100644 index 000000000..c18e5a1d0 --- /dev/null +++ b/tests/projects/c++/modules/aliased_headerunit/test.lua @@ -0,0 +1 @@ +inherit(".test_headerunits") diff --git a/tests/projects/c++/modules/aliased_headerunit/xmake.lua b/tests/projects/c++/modules/aliased_headerunit/xmake.lua new file mode 100644 index 000000000..5b4827d09 --- /dev/null +++ b/tests/projects/c++/modules/aliased_headerunit/xmake.lua @@ -0,0 +1,8 @@ +add_rules("mode.release", "mode.debug") +set_languages("c++20") + +-- header.hpp should be built only one time +target("aliased_headerunit") + set_kind("binary") + add_headerfiles("src/*.hpp") + add_files("src/*.cpp", "src/foo/*.mpp") diff --git a/tests/projects/c++/modules/cpp_with_moduledeps/xmake.lua b/tests/projects/c++/modules/cpp_with_moduledeps/xmake.lua index 6a9b3538f..206e3746f 100644 --- a/tests/projects/c++/modules/cpp_with_moduledeps/xmake.lua +++ b/tests/projects/c++/modules/cpp_with_moduledeps/xmake.lua @@ -3,7 +3,8 @@ set_languages("c++20") target("mod") set_kind("static") - add_files("src/mod.mpp", "src/mod.cpp") + add_files("src/mod.mpp", {public = true}) + add_files("src/mod.cpp") target("cpp_with_moduledeps") set_kind("binary") diff --git a/tests/projects/c++/modules/inline_and_template/src/main.cpp b/tests/projects/c++/modules/inline_and_template/src/main.cpp index a34667fbe..bf68f307d 100644 --- a/tests/projects/c++/modules/inline_and_template/src/main.cpp +++ b/tests/projects/c++/modules/inline_and_template/src/main.cpp @@ -1,12 +1,12 @@ +#include <iostream> + import hello; import say; import foo; -#include <iostream> - int main() { hello::say_hello(); say{}.hello<sizeof(say)>(); std::cout << foo<int>{}.hello() << std::endl; return 0; -}
\ No newline at end of file +} diff --git a/tests/projects/c++/modules/link_order/xmake.lua b/tests/projects/c++/modules/link_order/xmake.lua index 6a11418ac..b062dbe66 100644 --- a/tests/projects/c++/modules/link_order/xmake.lua +++ b/tests/projects/c++/modules/link_order/xmake.lua @@ -4,12 +4,12 @@ set_languages("c++20") target("foo") add_rules("c++") set_kind("static") - add_files("src/foo.mpp") + add_files("src/foo.mpp", {public = true}) target("bar") add_rules("c++") set_kind("static") - add_files("src/bar.mpp") + add_files("src/bar.mpp", {public = true}) target("link_order_1") set_kind("binary") diff --git a/tests/projects/c++/modules/packages/my-repo/packages/b/bar/src/bar.cpp b/tests/projects/c++/modules/packages/my-repo/packages/b/bar/src/bar.cpp index 5bbb5e5c1..279541ed0 100644 --- a/tests/projects/c++/modules/packages/my-repo/packages/b/bar/src/bar.cpp +++ b/tests/projects/c++/modules/packages/my-repo/packages/b/bar/src/bar.cpp @@ -1,5 +1,5 @@ -module bar; +#include <a.hpp> -const char *bar() { +const char *hello() { return "Hello world"; -}
\ No newline at end of file +} diff --git a/tests/projects/c++/modules/packages/my-repo/packages/b/bar/src/bar.mpp b/tests/projects/c++/modules/packages/my-repo/packages/b/bar/src/bar.mpp index a13487fea..48ed6b73b 100644 --- a/tests/projects/c++/modules/packages/my-repo/packages/b/bar/src/bar.mpp +++ b/tests/projects/c++/modules/packages/my-repo/packages/b/bar/src/bar.mpp @@ -1,3 +1,12 @@ +module; + +#include <a.hpp> + export module bar; -export const char *bar();
\ No newline at end of file +export namespace bar { +const char *hello() { + return ::hello(); +} +} + diff --git a/tests/projects/c++/modules/packages/my-repo/packages/b/bar/src/include/a.hpp b/tests/projects/c++/modules/packages/my-repo/packages/b/bar/src/include/a.hpp new file mode 100644 index 000000000..7cd8caadb --- /dev/null +++ b/tests/projects/c++/modules/packages/my-repo/packages/b/bar/src/include/a.hpp @@ -0,0 +1,6 @@ +#ifndef A_HPP +#define A_HPP + +[[gnu::visibility("default")]] const char *hello(); + +#endif diff --git a/tests/projects/c++/modules/packages/my-repo/packages/b/bar/src/xmake.lua b/tests/projects/c++/modules/packages/my-repo/packages/b/bar/src/xmake.lua index 345dd2db4..d11bc4f60 100644 --- a/tests/projects/c++/modules/packages/my-repo/packages/b/bar/src/xmake.lua +++ b/tests/projects/c++/modules/packages/my-repo/packages/b/bar/src/xmake.lua @@ -3,5 +3,7 @@ set_languages("c++20") target("bar") set_kind("static") + add_headerfiles("include/(**.hpp)") + add_includedirs("include") add_files("*.cpp") - add_files("*.mpp", { install = true }) + add_files("*.mpp", { public = true }) diff --git a/tests/projects/c++/modules/packages/my-repo/packages/b/bar/xmake.lua b/tests/projects/c++/modules/packages/my-repo/packages/b/bar/xmake.lua index 301166807..1592fc623 100644 --- a/tests/projects/c++/modules/packages/my-repo/packages/b/bar/xmake.lua +++ b/tests/projects/c++/modules/packages/my-repo/packages/b/bar/xmake.lua @@ -3,4 +3,4 @@ package("bar") on_install(function(package) import("package.tools.xmake").install(package, {}) - end)
\ No newline at end of file + end) diff --git a/tests/projects/c++/modules/packages/my-repo/packages/f/foo/src/foo.mpp b/tests/projects/c++/modules/packages/my-repo/packages/f/foo/src/foo.mpp index 4cab3d977..a97f3d62b 100644 --- a/tests/projects/c++/modules/packages/my-repo/packages/f/foo/src/foo.mpp +++ b/tests/projects/c++/modules/packages/my-repo/packages/f/foo/src/foo.mpp @@ -1,5 +1,7 @@ export module foo; export namespace foo { + #ifdef FOO_EXPORT void say(const char *); -}
\ No newline at end of file + #endif +} diff --git a/tests/projects/c++/modules/packages/my-repo/packages/f/foo/src/xmake.lua b/tests/projects/c++/modules/packages/my-repo/packages/f/foo/src/xmake.lua index d79b2ac54..9fa37e1d7 100644 --- a/tests/projects/c++/modules/packages/my-repo/packages/f/foo/src/xmake.lua +++ b/tests/projects/c++/modules/packages/my-repo/packages/f/foo/src/xmake.lua @@ -4,4 +4,4 @@ set_languages("c++20") target("foo") set_kind("static") add_files("*.cpp") - add_files("*.mpp", { install = true }) + add_files("*.mpp", {defines = "FOO_EXPORT", public = true}) diff --git a/tests/projects/c++/modules/packages/src/main.cpp b/tests/projects/c++/modules/packages/src/main.cpp index 10c501c4a..d12361c45 100644 --- a/tests/projects/c++/modules/packages/src/main.cpp +++ b/tests/projects/c++/modules/packages/src/main.cpp @@ -2,6 +2,6 @@ import foo; import bar; int main() { - foo::say(bar()); + foo::say(bar::hello()); return 0; } diff --git a/tests/projects/c++/modules/packages/xmake.lua b/tests/projects/c++/modules/packages/xmake.lua index fe3cc7dc5..f772d6668 100644 --- a/tests/projects/c++/modules/packages/xmake.lua +++ b/tests/projects/c++/modules/packages/xmake.lua @@ -1,5 +1,5 @@ add_rules("mode.release", "mode.debug") -set_languages("c++20") +set_languages("c++2b") add_repositories("my-repo my-repo") add_requires("foo", "bar") diff --git a/tests/projects/c++/modules/staticlib/xmake.lua b/tests/projects/c++/modules/staticlib/xmake.lua index ca0e9e343..d353774e4 100644 --- a/tests/projects/c++/modules/staticlib/xmake.lua +++ b/tests/projects/c++/modules/staticlib/xmake.lua @@ -3,7 +3,7 @@ set_languages("c++20") target("mod") set_kind("static") - add_files("src/mod.mpp", "src/mod.cpp") + add_files("src/mod.mpp", "src/mod.cpp", {public = true}) target("hello") set_kind("binary") diff --git a/tests/projects/c++/modules/stdmodules/xmake.lua b/tests/projects/c++/modules/stdmodules/xmake.lua index 0603a4c51..02447729c 100644 --- a/tests/projects/c++/modules/stdmodules/xmake.lua +++ b/tests/projects/c++/modules/stdmodules/xmake.lua @@ -3,11 +3,10 @@ set_languages("c++latest") target("mod") set_kind("static") - add_files("src/*.cpp", "src/*.mpp") - set_policy("build.c++.clang.stdmodules", true) + add_files("src/*.cpp") + add_files("src/*.mpp", {public = true}) target("stdmodules") set_kind("binary") add_files("test/*.cpp") add_deps("mod") - set_policy("build.c++.clang.stdmodules", true) diff --git a/tests/projects/c++/modules/stdmodules_cpp_only/xmake.lua b/tests/projects/c++/modules/stdmodules_cpp_only/xmake.lua index d7acc0d85..6f86e1efc 100644 --- a/tests/projects/c++/modules/stdmodules_cpp_only/xmake.lua +++ b/tests/projects/c++/modules/stdmodules_cpp_only/xmake.lua @@ -6,5 +6,4 @@ target("stdmodules_cpp_only") set_kind("binary") add_files("src/*.cpp") set_policy("build.c++.modules", true) - set_policy("build.c++.clang.stdmodules", true) diff --git a/tests/projects/c++/modules/stdmodules_multiple_targets/xmake.lua b/tests/projects/c++/modules/stdmodules_multiple_targets/xmake.lua index 32bed613b..61d451908 100644 --- a/tests/projects/c++/modules/stdmodules_multiple_targets/xmake.lua +++ b/tests/projects/c++/modules/stdmodules_multiple_targets/xmake.lua @@ -5,10 +5,6 @@ target("mod") set_kind("static") add_files("src/*.cpp", "src/*.mpp") - set_policy("build.c++.clang.stdmodules", true) - target("mod2") set_kind("static") add_files("src/*.cpp", "src/*.mpp") - - set_policy("build.c++.clang.stdmodules", true) diff --git a/tests/projects/c++/modules/test_base.lua b/tests/projects/c++/modules/test_base.lua index efef15520..c4252d41c 100644 --- a/tests/projects/c++/modules/test_base.lua +++ b/tests/projects/c++/modules/test_base.lua @@ -12,21 +12,34 @@ end function main(t) if is_subhost("windows") then - os.exec("xmake f -c") + local clang = find_tool("clang", {version = true}) + if clang and clang.version and semver.compare(clang.version, "14.0") >= 0 then + os.exec("xmake f --toolchain=clang -c --yes") + _build() + os.exec("xmake clean -a") + os.exec("xmake f --toolchain=clang --runtimes=c++_shared -c --yes") + _build() + end + + os.exec("xmake clean -a") + os.exec("xmake f -c --yes") + _build() + elseif is_subhost("msys") then + os.exec("xmake f -c -p mingw --yes") _build() elseif is_host("linux") then local gcc = find_tool("gcc", {version = true}) - if is_host("linux") and gcc and gcc.version and semver.compare(gcc.version, "11.0") >= 0 then - os.exec("xmake f -c") + if gcc and gcc.version and semver.compare(gcc.version, "11.0") >= 0 then + os.exec("xmake f -c --yes") _build() end local clang = find_tool("clang", {version = true}) if clang and clang.version and semver.compare(clang.version, "14.0") >= 0 then os.exec("xmake clean -a") - os.exec("xmake f --toolchain=clang -c") + os.exec("xmake f --toolchain=clang -c --yes") _build() os.exec("xmake clean -a") - os.exec("xmake f --toolchain=clang --cxxflags=\"-stdlib=libc++\" -c") + os.exec("xmake f --toolchain=clang --runtimes=c++_shared -c --yes") _build() end end diff --git a/tests/projects/c++/modules/test_headerunits.lua b/tests/projects/c++/modules/test_headerunits.lua index 3b664c96c..ba7fde015 100644 --- a/tests/projects/c++/modules/test_headerunits.lua +++ b/tests/projects/c++/modules/test_headerunits.lua @@ -13,15 +13,33 @@ end function main(t) if is_subhost("windows") then + local clang = find_tool("clang", {version = true}) + if clang and clang.version and semver.compare(clang.version, "15.0") >= 0 then + -- clang headerunit are bugged + -- os.exec("xmake f --toolchain=clang --policies=build.c++.clang.fallbackscanner -c --yes") + -- _build() + -- if semver.compare(clang.version, "17.0") >= 0 then + -- os.exec("xmake clean -a") + -- -- clang-scan-deps dependency detection doesn't support header units atm + -- os.exec("xmake f --toolchain=clang --policies=build.c++.clang.fallbackscanner --runtimes=c++_shared -c --yes") + -- _build() + -- end + end + local vs = find_vstudio() if vs and vs["2022"] then + os.exec("xmake clean -a") os.exec("xmake f -c --yes") _build() end + elseif is_subhost("msys") then + -- on windows, mingw modulemapper doesn't handle headeunit path correctly, but it's working with mingw on macOS / Linux + -- os.exec("xmake f -c -p mingw --yes") + -- _build() elseif is_host("linux") then local gcc = find_tool("gcc", {version = true}) if gcc and gcc.version and semver.compare(gcc.version, "11.0") >= 0 then - -- gcc trtbd dependency detection doesn't support header units atm + -- gcc dependency detection doesn't support header units atm os.exec("xmake f --policies=build.c++.gcc.fallbackscanner -c --yes") _build() end @@ -30,15 +48,16 @@ function main(t) if semver.compare(clang.version, "15.0") >= 0 then os.exec("xmake clean -a") -- clang-scan-deps dependency detection doesn't support header units atm - os.exec("xmake f --toolchain=clang --policies=build.c++.clang.fallbackscanner -c") + os.exec("xmake f --toolchain=clang --policies=build.c++.clang.fallbackscanner -c --yes") _build() - -- elseif semver.compare(clang.version, "15.0") >= 0 then - -- there is currently a bug on llvm git that prevent to build STL header units https://github.com/llvm/llvm-project/issues/58540 - -- os.exec("xmake clean -a") - -- clang-scan-deps dependency detection doesn't support header units atm - -- os.exec("xmake f --toolchain=clang --policies=build.c++.modules.fallbackscanner.clang --cxxflags=\"-stdlib=libc++\" -c") - -- _build() end + -- libc++ headerunit are bugged + -- if semver.compare(clang.version, "17.0") >= 0 then + -- os.exec("xmake clean -a") + -- -- clang-scan-deps dependency detection doesn't support header units atm + -- os.exec("xmake f --toolchain=clang --policies=build.c++.clang.fallbackscanner --runtimes=c++_shared -c --yes") + -- _build() + -- end end end end diff --git a/tests/projects/c++/modules/test_stdmodules.lua b/tests/projects/c++/modules/test_stdmodules.lua index 360a56cbc..222ec9458 100644 --- a/tests/projects/c++/modules/test_stdmodules.lua +++ b/tests/projects/c++/modules/test_stdmodules.lua @@ -13,33 +13,47 @@ end function main(t) if is_subhost("windows") then + -- local clang = find_tool("clang", {version = true}) + -- if clang and clang.version and semver.compare(clang.version, "18.0") >= 0 then + -- os.exec("xmake f --toolchain=clang -c --yes") + -- _build() + -- clang don't support libc++ std modules atm + -- os.exec("xmake clean -a") + -- os.exec("xmake f --toolchain=clang --runtimes=c++_shared -c --yes") + -- _build() + -- end local msvc = toolchain.load("msvc") if msvc and msvc:check() then local vcvars = msvc:config("vcvars") if vcvars and vcvars.VCInstallDir and vcvars.VCToolsVersion and semver.compare(vcvars.VCToolsVersion, "14.35") then local stdmodulesdir = path.join(vcvars.VCInstallDir, "Tools", "MSVC", vcvars.VCToolsVersion, "modules") if os.isdir(stdmodulesdir) then - os.exec("xmake f -c") + os.exec("xmake clean -a") + os.exec("xmake f -c --yes") _build() end end end + elseif is_subhost("msys") then + -- os.exec("xmake f -c -p mingw --yes") + -- _build() elseif is_host("linux") then -- or is_host("macosx") then -- gcc don't support std modules atm -- local gcc = find_tool("gcc", {version = true}) -- if is_host("linux") and gcc and gcc.version and semver.compare(gcc.version, "11.0") >= 0 then - -- os.exec("xmake f -c") + -- os.exec("xmake f -c --yes") -- _build() -- end - local clang = find_tool("clang", {version = true}) - if clang and clang.version and semver.compare(clang.version, "14.0") >= 0 then + -- local clang = find_tool("clang", {version = true}) + -- if clang and clang.version and semver.compare(clang.version, "18.0") >= 0 then -- clang don't support libstdc++ std modules atm -- os.exec("xmake clean -a") - -- os.exec("xmake f --toolchain=clang -c") + -- os.exec("xmake f --toolchain=clang -c --yes") -- _build() - os.exec("xmake clean -a") - os.exec("xmake f --toolchain=clang --cxxflags=\"-stdlib=libc++\" -c") - _build() - end + -- clang don't support libc++ std modules atm + -- os.exec("xmake clean -a") + -- os.exec("xmake f --toolchain=clang --runtimes=c++_shared -c --yes") + -- _build() + -- end end end diff --git a/tests/projects/c++/modules/user_headerunit2/a/xmake.lua b/tests/projects/c++/modules/user_headerunit2/a/xmake.lua index cffe161b2..3225b2814 100644 --- a/tests/projects/c++/modules/user_headerunit2/a/xmake.lua +++ b/tests/projects/c++/modules/user_headerunit2/a/xmake.lua @@ -1,4 +1,4 @@ target("a")
set_languages("cxxlatest")
set_kind("object")
- add_files("a.mpp")
+ add_files("a.mpp", {public = true})
diff --git a/tests/projects/c++/modules/user_headerunit2/b/xmake.lua b/tests/projects/c++/modules/user_headerunit2/b/xmake.lua index 98cff4124..24f9c9b1f 100644 --- a/tests/projects/c++/modules/user_headerunit2/b/xmake.lua +++ b/tests/projects/c++/modules/user_headerunit2/b/xmake.lua @@ -2,4 +2,4 @@ add_deps("a")
set_languages("cxxlatest")
set_kind("object")
- add_files("b.mpp")
+ add_files("b.mpp", {public = true})
|
