diff options
| author | ruki <[email protected]> | 2024-02-18 21:41:52 +0800 |
|---|---|---|
| committer | GitHub <[email protected]> | 2024-02-18 21:41:52 +0800 |
| commit | 3c1163b36e0817dbd5b62ec1ff495dc2e830d6ac (patch) | |
| tree | 16f6cb664c031d80b1841e6978fc1d8753eb6761 /tests/projects/c++/modules | |
| parent | cda48025005f9aa23bdd582e29bb0f1f1ca24d27 (diff) | |
| parent | bc1a30db6041c2c14ca79ccf0aa35b2d550e64e5 (diff) | |
Merge pull request #4673 from xmake-io/modules
Refactor modules support
Diffstat (limited to 'tests/projects/c++/modules')
44 files changed, 270 insertions, 73 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/circular_dependency/src/hello.mpp b/tests/projects/c++/modules/circular_dependency/src/hello.mpp new file mode 100644 index 000000000..50f0f2c8f --- /dev/null +++ b/tests/projects/c++/modules/circular_dependency/src/hello.mpp @@ -0,0 +1,13 @@ +export module hello; + +import hello3; + +export namespace hello { + class say { + public: + say(int data); + void hello(); + private: + int data_; + }; +} diff --git a/tests/projects/c++/modules/circular_dependency/src/hello2.mpp b/tests/projects/c++/modules/circular_dependency/src/hello2.mpp new file mode 100644 index 000000000..1b6258af1 --- /dev/null +++ b/tests/projects/c++/modules/circular_dependency/src/hello2.mpp @@ -0,0 +1,3 @@ +export module hello2; + +import hello; diff --git a/tests/projects/c++/modules/circular_dependency/src/hello3.mpp b/tests/projects/c++/modules/circular_dependency/src/hello3.mpp new file mode 100644 index 000000000..4966cf0c0 --- /dev/null +++ b/tests/projects/c++/modules/circular_dependency/src/hello3.mpp @@ -0,0 +1,3 @@ +export module hello3; + +import hello2; diff --git a/tests/projects/c++/modules/circular_dependency/src/main.cpp b/tests/projects/c++/modules/circular_dependency/src/main.cpp new file mode 100644 index 000000000..6f80b6c7d --- /dev/null +++ b/tests/projects/c++/modules/circular_dependency/src/main.cpp @@ -0,0 +1,7 @@ +import hello; + +int main() { + hello::say s(sizeof(hello::say)); + s.hello(); + return 0; +}
\ No newline at end of file diff --git a/tests/projects/c++/modules/circular_dependency/test.lua b/tests/projects/c++/modules/circular_dependency/test.lua new file mode 100644 index 000000000..727e9187e --- /dev/null +++ b/tests/projects/c++/modules/circular_dependency/test.lua @@ -0,0 +1,7 @@ +import(".test_base", {alias = "test_build"}) + +function main(t) + if test_build.can_build() then + t:will_raise(test_build, "circular modules dependency detected") + end +end diff --git a/tests/projects/c++/modules/circular_dependency/xmake.lua b/tests/projects/c++/modules/circular_dependency/xmake.lua new file mode 100644 index 000000000..73254924e --- /dev/null +++ b/tests/projects/c++/modules/circular_dependency/xmake.lua @@ -0,0 +1,8 @@ +add_rules("mode.release", "mode.debug") +set_languages("c++20") + +target("circular_dependency") + set_kind("binary") + add_files("src/*.cpp", "src/*.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/internal_partition/src/hello_internal.mpp b/tests/projects/c++/modules/internal_partition/src/hello_internal.mpp index 8d0d4bee0..46a86c361 100644 --- a/tests/projects/c++/modules/internal_partition/src/hello_internal.mpp +++ b/tests/projects/c++/modules/internal_partition/src/hello_internal.mpp @@ -7,5 +7,5 @@ module hello:part_internal; namespace hello { void say_internal(const char *str) { printf("%s\n", str); - } -}
\ 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..4cb2af87f 100644 --- a/tests/projects/c++/modules/link_order/xmake.lua +++ b/tests/projects/c++/modules/link_order/xmake.lua @@ -2,13 +2,11 @@ add_rules("mode.release", "mode.debug") set_languages("c++20") target("foo") - add_rules("c++") - set_kind("static") + set_kind("moduleonly") add_files("src/foo.mpp") target("bar") - add_rules("c++") - set_kind("static") + set_kind("moduleonly") add_files("src/bar.mpp") target("link_order_1") diff --git a/tests/projects/c++/modules/staticlib_without_cpp/src/mod.mpp b/tests/projects/c++/modules/moduleonly/src/mod.mpp index b7dd3883c..b7dd3883c 100644 --- a/tests/projects/c++/modules/staticlib_without_cpp/src/mod.mpp +++ b/tests/projects/c++/modules/moduleonly/src/mod.mpp diff --git a/tests/projects/c++/modules/staticlib_without_cpp/test.lua b/tests/projects/c++/modules/moduleonly/test.lua index 7717f8049..7717f8049 100644 --- a/tests/projects/c++/modules/staticlib_without_cpp/test.lua +++ b/tests/projects/c++/modules/moduleonly/test.lua diff --git a/tests/projects/c++/modules/staticlib_without_cpp/xmake.lua b/tests/projects/c++/modules/moduleonly/xmake.lua index a06091414..54c681cc8 100644 --- a/tests/projects/c++/modules/staticlib_without_cpp/xmake.lua +++ b/tests/projects/c++/modules/moduleonly/xmake.lua @@ -2,5 +2,5 @@ add_rules("mode.release", "mode.debug") set_languages("c++20") target("mod") - set_kind("static") + set_kind("moduleonly") add_files("src/mod.mpp") 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/b/bar2/src/bar.mpp b/tests/projects/c++/modules/packages/my-repo/packages/b/bar2/src/bar.mpp new file mode 100644 index 000000000..ee9fb2c78 --- /dev/null +++ b/tests/projects/c++/modules/packages/my-repo/packages/b/bar2/src/bar.mpp @@ -0,0 +1,8 @@ +export module bar2; + +export namespace bar { + const char *hello2() { + return "Hello world"; + } +} + diff --git a/tests/projects/c++/modules/packages/my-repo/packages/b/bar2/src/xmake.lua b/tests/projects/c++/modules/packages/my-repo/packages/b/bar2/src/xmake.lua new file mode 100644 index 000000000..0324fa931 --- /dev/null +++ b/tests/projects/c++/modules/packages/my-repo/packages/b/bar2/src/xmake.lua @@ -0,0 +1,6 @@ +add_rules("mode.release", "mode.debug") +set_languages("c++20") + +target("bar2") + set_kind("moduleonly") + add_files("*.mpp") diff --git a/tests/projects/c++/modules/packages/my-repo/packages/b/bar2/xmake.lua b/tests/projects/c++/modules/packages/my-repo/packages/b/bar2/xmake.lua new file mode 100644 index 000000000..ffa208234 --- /dev/null +++ b/tests/projects/c++/modules/packages/my-repo/packages/b/bar2/xmake.lua @@ -0,0 +1,7 @@ +package("bar2") + set_kind("library") + set_sourcedir(path.join(os.scriptdir(), "src")) + + on_install(function(package) + import("package.tools.xmake").install(package, {}) + 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..d6f2218c0 100644 --- a/tests/projects/c++/modules/packages/src/main.cpp +++ b/tests/projects/c++/modules/packages/src/main.cpp @@ -1,7 +1,9 @@ import foo; import bar; +import bar2; int main() { - foo::say(bar()); + foo::say(bar::hello()); + foo::say(bar::hello2()); return 0; } diff --git a/tests/projects/c++/modules/packages/xmake.lua b/tests/projects/c++/modules/packages/xmake.lua index fe3cc7dc5..62dba119b 100644 --- a/tests/projects/c++/modules/packages/xmake.lua +++ b/tests/projects/c++/modules/packages/xmake.lua @@ -1,11 +1,11 @@ add_rules("mode.release", "mode.debug") -set_languages("c++20") +set_languages("c++2b") add_repositories("my-repo my-repo") -add_requires("foo", "bar") +add_requires("foo", "bar", "bar2") target("packages") set_kind("binary") add_files("src/*.cpp") - add_packages("foo", "bar") + add_packages("foo", "bar", "bar2") set_policy("build.c++.modules", true) diff --git a/tests/projects/c++/modules/private_module/src/use.cpp b/tests/projects/c++/modules/private_module/src/use.cpp new file mode 100644 index 000000000..f71a3057e --- /dev/null +++ b/tests/projects/c++/modules/private_module/src/use.cpp @@ -0,0 +1,8 @@ +module use; + +import dep1; +import dep2; + +int lib() { + return m() + i(); +} diff --git a/tests/projects/c++/modules/private_module/src/use.mpp b/tests/projects/c++/modules/private_module/src/use.mpp index 8450c341c..33f90c14a 100644 --- a/tests/projects/c++/modules/private_module/src/use.mpp +++ b/tests/projects/c++/modules/private_module/src/use.mpp @@ -1,6 +1,3 @@ -import dep1; -import dep2; +export module use; -int lib() { - return m() + i(); -}
\ No newline at end of file +export int lib(); diff --git a/tests/projects/c++/modules/private_module/xmake.lua b/tests/projects/c++/modules/private_module/xmake.lua index 57ede6993..16a2bea92 100644 --- a/tests/projects/c++/modules/private_module/xmake.lua +++ b/tests/projects/c++/modules/private_module/xmake.lua @@ -5,3 +5,4 @@ target("private_module") add_rules("c++") set_kind("$(kind)") add_files("src/*.mpp") + add_files("src/*.cpp") diff --git a/tests/projects/c++/modules/staticlib/xmake.lua b/tests/projects/c++/modules/staticlib/xmake.lua index ca0e9e343..9e1cf4221 100644 --- a/tests/projects/c++/modules/staticlib/xmake.lua +++ b/tests/projects/c++/modules/staticlib/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("hello") set_kind("binary") diff --git a/tests/projects/c++/modules/stdmodules/src/my_module.cpp b/tests/projects/c++/modules/stdmodules/src/my_module.cpp index b87808a6e..ab3119785 100644 --- a/tests/projects/c++/modules/stdmodules/src/my_module.cpp +++ b/tests/projects/c++/modules/stdmodules/src/my_module.cpp @@ -2,4 +2,4 @@ module my_module; import std; -auto my_sum(size_t a, size_t b) -> size_t { return a + b; } +auto my_sum(std::size_t a, std::size_t b) -> std::size_t { return a + b; } diff --git a/tests/projects/c++/modules/stdmodules/src/my_module.mpp b/tests/projects/c++/modules/stdmodules/src/my_module.mpp index bbebb2766..a1cd98e57 100644 --- a/tests/projects/c++/modules/stdmodules/src/my_module.mpp +++ b/tests/projects/c++/modules/stdmodules/src/my_module.mpp @@ -2,4 +2,4 @@ export module my_module; import std; -export auto my_sum(size_t a, size_t b) -> size_t; +export auto my_sum(std::size_t a, std::size_t b) -> std::size_t; 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..219901c63 100644 --- a/tests/projects/c++/modules/test_base.lua +++ b/tests/projects/c++/modules/test_base.lua @@ -1,32 +1,68 @@ import("lib.detect.find_tool") import("core.base.semver") +import("utils.ci.is_running", {alias = "ci_is_running"}) function _build() - local ci = (os.getenv("CI") or os.getenv("GITHUB_ACTIONS") or ""):lower() - if ci == "true" then - os.exec("xmake -rvD") + if ci_is_running() then + os.run("xmake -rvD") else - os.exec("xmake -r") + os.run("xmake -r") + end + local outdata = os.iorun("xmake") + if outdata then + if outdata:find("compiling") or outdata:find("linking") or outdata:find("generating") then + raise("Modules incremental compilation does not work\n%s", outdata) + end + end +end + +function can_build() + if is_subhost("windows") then + return true + elseif is_subhost("msys") then + return true + 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 + return true + end + local clang = find_tool("clang", {version = true}) + if clang and clang.version and semver.compare(clang.version, "14.0") >= 0 then + return true + end end 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..70e8b3d51 100644 --- a/tests/projects/c++/modules/test_headerunits.lua +++ b/tests/projects/c++/modules/test_headerunits.lua @@ -1,27 +1,51 @@ import("lib.detect.find_tool") import("core.base.semver") import("detect.sdks.find_vstudio") +import("utils.ci.is_running", {alias = "ci_is_running"}) function _build() - local ci = (os.getenv("CI") or os.getenv("GITHUB_ACTIONS") or ""):lower() - if ci == "true" then - os.exec("xmake -rvD") + if ci_is_running() then + os.run("xmake -rvD") else - os.exec("xmake -r") + os.run("xmake -r") + end + local outdata = os.iorun("xmake") + if outdata then + if outdata:find("compiling") or outdata:find("linking") or outdata:find("generating") then + raise("Modules incremental compilation does not work\n%s", outdata) + end end 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 +54,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..6c3a16b2c 100644 --- a/tests/projects/c++/modules/test_stdmodules.lua +++ b/tests/projects/c++/modules/test_stdmodules.lua @@ -1,44 +1,63 @@ import("lib.detect.find_tool") import("core.base.semver") import("core.tool.toolchain") +import("utils.ci.is_running", {alias = "ci_is_running"}) function _build() - local ci = (os.getenv("CI") or os.getenv("GITHUB_ACTIONS") or ""):lower() - if ci == "true" then - os.exec("xmake -rvD") + if ci_is_running() then + os.run("xmake -rvD") else - os.exec("xmake -r") + os.run("xmake -r") + end + local outdata = os.iorun("xmake") + if outdata then + if outdata:find("compiling") or outdata:find("linking") or outdata:find("generating") then + raise("Modules incremental compilation does not work\n%s", outdata) + end end 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 + -- clang don't support msstl std modules atm + -- 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 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 + 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") + os.exec("xmake f --toolchain=clang --runtimes=c++_shared -c --yes") _build() 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..a3c5906fc 100644 --- a/tests/projects/c++/modules/user_headerunit2/a/xmake.lua +++ b/tests/projects/c++/modules/user_headerunit2/a/xmake.lua @@ -1,4 +1,5 @@ target("a")
- set_languages("cxxlatest")
- set_kind("object")
+ set_kind("moduleonly")
+ add_headerfiles("*.hpp")
add_files("a.mpp")
+ set_languages("cxxlatest")
diff --git a/tests/projects/c++/modules/user_headerunit2/b/xmake.lua b/tests/projects/c++/modules/user_headerunit2/b/xmake.lua index 98cff4124..7a353ec26 100644 --- a/tests/projects/c++/modules/user_headerunit2/b/xmake.lua +++ b/tests/projects/c++/modules/user_headerunit2/b/xmake.lua @@ -1,5 +1,5 @@ target("b")
add_deps("a")
- set_languages("cxxlatest")
- set_kind("object")
+ set_kind("moduleonly")
add_files("b.mpp")
+ set_languages("cxxlatest")
|
