From 13ae811418d4855cb5cc223d7e4546771f704e6f Mon Sep 17 00:00:00 2001 From: Arthur LAURENT Date: Wed, 4 Jan 2023 22:30:23 +0100 Subject: Improve compatibility with libc++ --- tests/projects/c++/modules/test_headerunits.lua | 3 +++ 1 file changed, 3 insertions(+) (limited to 'tests/projects/c++/modules/test_headerunits.lua') diff --git a/tests/projects/c++/modules/test_headerunits.lua b/tests/projects/c++/modules/test_headerunits.lua index 905812c14..85c6c35b3 100644 --- a/tests/projects/c++/modules/test_headerunits.lua +++ b/tests/projects/c++/modules/test_headerunits.lua @@ -29,6 +29,9 @@ function main(t) os.exec("xmake clean -a") os.exec("xmake f --toolchain=clang -c") _build() + os.exec("xmake clean -a") + os.exec("xmake f --toolchain=clang --cxxflags=\"-stdlib=libc++\" -c") + _build() end end end -- cgit v1.3.1 From ae744259de3d03a24b7a261251ebf0f4628fed87 Mon Sep 17 00:00:00 2001 From: Arthur LAURENT Date: Fri, 6 Jan 2023 12:20:10 +0100 Subject: disable clang header units tests with -stdlib=libc++ --- tests/projects/c++/modules/test_headerunits.lua | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'tests/projects/c++/modules/test_headerunits.lua') diff --git a/tests/projects/c++/modules/test_headerunits.lua b/tests/projects/c++/modules/test_headerunits.lua index 85c6c35b3..872defb35 100644 --- a/tests/projects/c++/modules/test_headerunits.lua +++ b/tests/projects/c++/modules/test_headerunits.lua @@ -29,9 +29,9 @@ function main(t) os.exec("xmake clean -a") os.exec("xmake f --toolchain=clang -c") _build() - os.exec("xmake clean -a") - os.exec("xmake f --toolchain=clang --cxxflags=\"-stdlib=libc++\" -c") - _build() + -- os.exec("xmake clean -a") 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 f --toolchain=clang --cxxflags=\"-stdlib=libc++\" -c") + -- _build() end end end -- cgit v1.3.1 From 3755a6f67399b8e42df9f39ec7c506918dbb433a Mon Sep 17 00:00:00 2001 From: Arthur LAURENT Date: Sat, 7 Jan 2023 17:44:36 +0100 Subject: reenable old clang modules by default and fix tests --- tests/projects/c++/modules/class/xmake.lua | 4 ++ .../c++/modules/cpp_with_moduledeps/xmake.lua | 3 +- tests/projects/c++/modules/dependence/xmake.lua | 6 ++ tests/projects/c++/modules/dependence2/xmake.lua | 4 +- .../c++/modules/headerunits_person/xmake.lua | 6 +- .../c++/modules/hello with spaces/xmake.lua | 3 +- tests/projects/c++/modules/hello/xmake.lua | 1 + tests/projects/c++/modules/ifdef_module/xmake.lua | 1 + tests/projects/c++/modules/impl_unit/xmake.lua | 4 ++ .../c++/modules/inline_and_template/xmake.lua | 4 ++ .../c++/modules/internal_partition/xmake.lua | 1 + tests/projects/c++/modules/link_order/xmake.lua | 5 ++ tests/projects/c++/modules/partitions/test.lua | 2 +- tests/projects/c++/modules/partitions/xmake.lua | 6 +- tests/projects/c++/modules/partitions2/test.lua | 2 +- tests/projects/c++/modules/partitions2/xmake.lua | 6 +- .../projects/c++/modules/private_module/xmake.lua | 1 + tests/projects/c++/modules/staticlib/xmake.lua | 3 +- tests/projects/c++/modules/stdmodules/test.lua | 2 +- tests/projects/c++/modules/stdmodules/xmake.lua | 5 +- .../modules/stdmodules_multiple_targets/test.lua | 2 +- .../modules/stdmodules_multiple_targets/xmake.lua | 3 - .../projects/c++/modules/stl_headerunit/xmake.lua | 4 ++ .../c++/modules/stl_headerunit_cpp_only/xmake.lua | 75 ++-------------------- tests/projects/c++/modules/submodules/xmake.lua | 6 +- tests/projects/c++/modules/submodules2/xmake.lua | 4 +- tests/projects/c++/modules/test_base.lua | 10 +-- tests/projects/c++/modules/test_headerunits.lua | 11 ++-- tests/projects/c++/modules/test_msvc.lua | 28 -------- tests/projects/c++/modules/test_stdmodules.lua | 47 ++++++++++++++ .../projects/c++/modules/user_headerunit/xmake.lua | 2 + xmake/rules/c++/modules/modules_support/clang.lua | 10 ++- 32 files changed, 143 insertions(+), 128 deletions(-) delete mode 100644 tests/projects/c++/modules/test_msvc.lua create mode 100644 tests/projects/c++/modules/test_stdmodules.lua (limited to 'tests/projects/c++/modules/test_headerunits.lua') diff --git a/tests/projects/c++/modules/class/xmake.lua b/tests/projects/c++/modules/class/xmake.lua index 6d6eaddee..2dfca344c 100644 --- a/tests/projects/c++/modules/class/xmake.lua +++ b/tests/projects/c++/modules/class/xmake.lua @@ -1,4 +1,8 @@ +add_rules("mode.release", "mode.debug") set_languages("c++20") + target("class") set_kind("binary") add_files("src/*.cpp", "src/*.mpp") + + set_values("c++.clang.modules.strict", true) -- clang std module clash with stl headers, header units and c++23 std module so we disable it when using libc++ diff --git a/tests/projects/c++/modules/cpp_with_moduledeps/xmake.lua b/tests/projects/c++/modules/cpp_with_moduledeps/xmake.lua index 5c7a8a6f7..6a9b3538f 100644 --- a/tests/projects/c++/modules/cpp_with_moduledeps/xmake.lua +++ b/tests/projects/c++/modules/cpp_with_moduledeps/xmake.lua @@ -1,10 +1,11 @@ +add_rules("mode.release", "mode.debug") set_languages("c++20") target("mod") set_kind("static") add_files("src/mod.mpp", "src/mod.cpp") -target("main") +target("cpp_with_moduledeps") set_kind("binary") add_deps("mod") add_files("src/main.cpp") diff --git a/tests/projects/c++/modules/dependence/xmake.lua b/tests/projects/c++/modules/dependence/xmake.lua index 6d64b49b1..b4ecdb1b9 100644 --- a/tests/projects/c++/modules/dependence/xmake.lua +++ b/tests/projects/c++/modules/dependence/xmake.lua @@ -1,4 +1,10 @@ +add_rules("mode.release", "mode.debug") set_languages("c++20") + target("dependence") set_kind("binary") add_files("src/*.cpp", "src/*.mpp") + + if has_config("libc++") then + set_values("c++.clang.modules.strict", true) -- clang std module clash with stl headers, header units and c++23 std module so we disable it when using libc++ + end \ No newline at end of file diff --git a/tests/projects/c++/modules/dependence2/xmake.lua b/tests/projects/c++/modules/dependence2/xmake.lua index 6d64b49b1..4f2905fe9 100644 --- a/tests/projects/c++/modules/dependence2/xmake.lua +++ b/tests/projects/c++/modules/dependence2/xmake.lua @@ -1,4 +1,6 @@ +add_rules("mode.release", "mode.debug") set_languages("c++20") -target("dependence") + +target("dependence2") set_kind("binary") add_files("src/*.cpp", "src/*.mpp") diff --git a/tests/projects/c++/modules/headerunits_person/xmake.lua b/tests/projects/c++/modules/headerunits_person/xmake.lua index c9290833b..93b635988 100644 --- a/tests/projects/c++/modules/headerunits_person/xmake.lua +++ b/tests/projects/c++/modules/headerunits_person/xmake.lua @@ -1,4 +1,8 @@ +add_rules("mode.release", "mode.debug") set_languages("c++20") -target("hello") + +target("headerunits_person") set_kind("binary") add_files("src/*.cpp", "src/*.mpp") + + set_values("c++.clang.modules.strict", true) -- clang std module clash with stl headers, header units and c++23 std module so we disable it \ No newline at end of file diff --git a/tests/projects/c++/modules/hello with spaces/xmake.lua b/tests/projects/c++/modules/hello with spaces/xmake.lua index 4f46b699d..4369a892f 100644 --- a/tests/projects/c++/modules/hello with spaces/xmake.lua +++ b/tests/projects/c++/modules/hello with spaces/xmake.lua @@ -1,5 +1,6 @@ add_rules("mode.release", "mode.debug") set_languages("c++20") -target("A hello") + +target("hello with spaces") set_kind("binary") add_files("src/*.cpp", "src/*.mpp") diff --git a/tests/projects/c++/modules/hello/xmake.lua b/tests/projects/c++/modules/hello/xmake.lua index de13fc409..4f6fdab98 100644 --- a/tests/projects/c++/modules/hello/xmake.lua +++ b/tests/projects/c++/modules/hello/xmake.lua @@ -1,5 +1,6 @@ add_rules("mode.release", "mode.debug") set_languages("c++20") + target("hello") set_kind("binary") add_files("src/*.cpp", "src/*.mpp") diff --git a/tests/projects/c++/modules/ifdef_module/xmake.lua b/tests/projects/c++/modules/ifdef_module/xmake.lua index ee931a801..25933a35f 100644 --- a/tests/projects/c++/modules/ifdef_module/xmake.lua +++ b/tests/projects/c++/modules/ifdef_module/xmake.lua @@ -1,5 +1,6 @@ add_rules("mode.release", "mode.debug") set_languages("c++20") + target("ifdef_module") set_kind("binary") add_files("src/*.cpp") diff --git a/tests/projects/c++/modules/impl_unit/xmake.lua b/tests/projects/c++/modules/impl_unit/xmake.lua index abe41d20a..64db3cf8c 100644 --- a/tests/projects/c++/modules/impl_unit/xmake.lua +++ b/tests/projects/c++/modules/impl_unit/xmake.lua @@ -1,4 +1,8 @@ +add_rules("mode.release", "mode.debug") set_languages("c++20") + target("impl_unit") set_kind("binary") add_files("src/*.cpp", "src/*.mpp") + + set_values("c++.clang.modules.strict", true) -- clang std module clash with stl headers, header units and c++23 std module so we disable it when using libc++ \ No newline at end of file diff --git a/tests/projects/c++/modules/inline_and_template/xmake.lua b/tests/projects/c++/modules/inline_and_template/xmake.lua index 4810edb85..57635eff3 100644 --- a/tests/projects/c++/modules/inline_and_template/xmake.lua +++ b/tests/projects/c++/modules/inline_and_template/xmake.lua @@ -1,4 +1,8 @@ +add_rules("mode.release", "mode.debug") set_languages("c++20") + target("inline_and_template") set_kind("binary") add_files("src/*.cpp", "src/*.mpp") + + set_values("c++.clang.modules.strict", true) -- clang std module clash with stl headers, header units and c++23 std module so we disable it when using libc++ \ No newline at end of file diff --git a/tests/projects/c++/modules/internal_partition/xmake.lua b/tests/projects/c++/modules/internal_partition/xmake.lua index f7ca6f7cf..422292295 100644 --- a/tests/projects/c++/modules/internal_partition/xmake.lua +++ b/tests/projects/c++/modules/internal_partition/xmake.lua @@ -1,5 +1,6 @@ add_rules("mode.release", "mode.debug") set_languages("c++20") + target("internal_partition") set_kind("binary") add_files("src/*.cpp", "src/hello.mpp") diff --git a/tests/projects/c++/modules/link_order/xmake.lua b/tests/projects/c++/modules/link_order/xmake.lua index 6a11418ac..c6310055c 100644 --- a/tests/projects/c++/modules/link_order/xmake.lua +++ b/tests/projects/c++/modules/link_order/xmake.lua @@ -1,3 +1,8 @@ +option("libc++") + set_default(false) + set_showmenu(true) +option_end() + add_rules("mode.release", "mode.debug") set_languages("c++20") diff --git a/tests/projects/c++/modules/partitions/test.lua b/tests/projects/c++/modules/partitions/test.lua index c18e5a1d0..e77adc4ae 100644 --- a/tests/projects/c++/modules/partitions/test.lua +++ b/tests/projects/c++/modules/partitions/test.lua @@ -1 +1 @@ -inherit(".test_headerunits") +inherit(".test_stdmodules") diff --git a/tests/projects/c++/modules/partitions/xmake.lua b/tests/projects/c++/modules/partitions/xmake.lua index 672034947..68602dce4 100644 --- a/tests/projects/c++/modules/partitions/xmake.lua +++ b/tests/projects/c++/modules/partitions/xmake.lua @@ -1,4 +1,8 @@ +add_rules("mode.release", "mode.debug") set_languages("c++20") -target("math") + +target("partition") set_kind("binary") add_files("src/*.cpp", "src/*.mpp") + + set_values("c++.clang.modules.strict", true) -- clang std module clash with stl headers, header units and c++23 std module so we disable it when using libc++ \ No newline at end of file diff --git a/tests/projects/c++/modules/partitions2/test.lua b/tests/projects/c++/modules/partitions2/test.lua index c18e5a1d0..e77adc4ae 100644 --- a/tests/projects/c++/modules/partitions2/test.lua +++ b/tests/projects/c++/modules/partitions2/test.lua @@ -1 +1 @@ -inherit(".test_headerunits") +inherit(".test_stdmodules") diff --git a/tests/projects/c++/modules/partitions2/xmake.lua b/tests/projects/c++/modules/partitions2/xmake.lua index c9290833b..1dfd2321b 100644 --- a/tests/projects/c++/modules/partitions2/xmake.lua +++ b/tests/projects/c++/modules/partitions2/xmake.lua @@ -1,4 +1,8 @@ +add_rules("mode.release", "mode.debug") set_languages("c++20") -target("hello") + +target("partition2") set_kind("binary") add_files("src/*.cpp", "src/*.mpp") + + set_values("c++.clang.modules.strict", true) -- clang std module clash with stl headers, header units and c++23 std module so we disable it when using libc++ diff --git a/tests/projects/c++/modules/private_module/xmake.lua b/tests/projects/c++/modules/private_module/xmake.lua index 1930f1188..57ede6993 100644 --- a/tests/projects/c++/modules/private_module/xmake.lua +++ b/tests/projects/c++/modules/private_module/xmake.lua @@ -1,5 +1,6 @@ add_rules("mode.release", "mode.debug") set_languages("c++20") + target("private_module") add_rules("c++") set_kind("$(kind)") diff --git a/tests/projects/c++/modules/staticlib/xmake.lua b/tests/projects/c++/modules/staticlib/xmake.lua index 93045c18f..5a3a9f4c6 100644 --- a/tests/projects/c++/modules/staticlib/xmake.lua +++ b/tests/projects/c++/modules/staticlib/xmake.lua @@ -1,10 +1,11 @@ +add_rules("mode.release", "mode.debug") set_languages("c++20") target("mod") set_kind("static") add_files("src/mod.mpp", "src/mod.cpp") -target("test") +target("staticlib") set_kind("binary") add_deps("mod") add_files("src/main.cpp") diff --git a/tests/projects/c++/modules/stdmodules/test.lua b/tests/projects/c++/modules/stdmodules/test.lua index 0657ead56..e77adc4ae 100644 --- a/tests/projects/c++/modules/stdmodules/test.lua +++ b/tests/projects/c++/modules/stdmodules/test.lua @@ -1 +1 @@ -inherit(".test_msvc") +inherit(".test_stdmodules") diff --git a/tests/projects/c++/modules/stdmodules/xmake.lua b/tests/projects/c++/modules/stdmodules/xmake.lua index 85e738d14..134aee26c 100644 --- a/tests/projects/c++/modules/stdmodules/xmake.lua +++ b/tests/projects/c++/modules/stdmodules/xmake.lua @@ -1,14 +1,11 @@ add_rules("mode.debug", "mode.release") - -add_cxxflags("clang::-stdlib=libc++") - set_languages("c++latest") target("mod") set_kind("static") add_files("src/*.cpp", "src/*.mpp") -target("test") +target("stdmodules") set_kind("binary") add_files("test/*.cpp") add_deps("mod") diff --git a/tests/projects/c++/modules/stdmodules_multiple_targets/test.lua b/tests/projects/c++/modules/stdmodules_multiple_targets/test.lua index 0657ead56..e77adc4ae 100644 --- a/tests/projects/c++/modules/stdmodules_multiple_targets/test.lua +++ b/tests/projects/c++/modules/stdmodules_multiple_targets/test.lua @@ -1 +1 @@ -inherit(".test_msvc") +inherit(".test_stdmodules") diff --git a/tests/projects/c++/modules/stdmodules_multiple_targets/xmake.lua b/tests/projects/c++/modules/stdmodules_multiple_targets/xmake.lua index 859dddc7c..61d451908 100644 --- a/tests/projects/c++/modules/stdmodules_multiple_targets/xmake.lua +++ b/tests/projects/c++/modules/stdmodules_multiple_targets/xmake.lua @@ -1,7 +1,4 @@ add_rules("mode.debug", "mode.release") - -add_cxxflags("clang::-stdlib=libc++") - set_languages("c++latest") target("mod") diff --git a/tests/projects/c++/modules/stl_headerunit/xmake.lua b/tests/projects/c++/modules/stl_headerunit/xmake.lua index e85378c46..b73913a87 100644 --- a/tests/projects/c++/modules/stl_headerunit/xmake.lua +++ b/tests/projects/c++/modules/stl_headerunit/xmake.lua @@ -1,4 +1,8 @@ +add_rules("mode.release", "mode.debug") set_languages("c++20") + target("stl_headerunit") set_kind("binary") add_files("src/*.cpp", "src/*.mpp") + + set_values("c++.clang.modules.strict", true) -- clang std module clash with stl header units or c++23 std module so we disable it \ No newline at end of file diff --git a/tests/projects/c++/modules/stl_headerunit_cpp_only/xmake.lua b/tests/projects/c++/modules/stl_headerunit_cpp_only/xmake.lua index 101a95fe7..03a6168b0 100644 --- a/tests/projects/c++/modules/stl_headerunit_cpp_only/xmake.lua +++ b/tests/projects/c++/modules/stl_headerunit_cpp_only/xmake.lua @@ -1,76 +1,9 @@ -add_rules("mode.debug", "mode.release") +add_rules("mode.release", "mode.debug") + set_languages("c++20") -target("test") +target("stl_headerunit_cpp_only") set_kind("binary") add_files("src/*.cpp") - set_languages("c++20") set_policy("build.c++.modules", true) --- --- If you want to known more usage about xmake, please see https://xmake.io --- --- ## FAQ --- --- You can enter the project directory firstly before building project. --- --- $ cd projectdir --- --- 1. How to build project? --- --- $ xmake --- --- 2. How to configure project? --- --- $ xmake f -p [macosx|linux|iphoneos ..] -a [x86_64|i386|arm64 ..] -m [debug|release] --- --- 3. Where is the build output directory? --- --- The default output directory is `./build` and you can configure the output directory. --- --- $ xmake f -o outputdir --- $ xmake --- --- 4. How to run and debug target after building project? --- --- $ xmake run [targetname] --- $ xmake run -d [targetname] --- --- 5. How to install target to the system directory or other output directory? --- --- $ xmake install --- $ xmake install -o installdir --- --- 6. Add some frequently-used compilation flags in xmake.lua --- --- @code --- -- add debug and release modes --- add_rules("mode.debug", "mode.release") --- --- -- add macro defination --- add_defines("NDEBUG", "_GNU_SOURCE=1") --- --- -- set warning all as error --- set_warnings("all", "error") --- --- -- set language: c99, c++11 --- set_languages("c99", "c++11") --- --- -- set optimization: none, faster, fastest, smallest --- set_optimize("fastest") --- --- -- add include search directories --- add_includedirs("/usr/include", "/usr/local/include") --- --- -- add link libraries and search directories --- add_links("tbox") --- add_linkdirs("/usr/local/lib", "/usr/lib") --- --- -- add system link libraries --- add_syslinks("z", "pthread") --- --- -- add compilation and link flags --- add_cxflags("-stdnolib", "-fno-strict-aliasing") --- add_ldflags("-L/usr/local/lib", "-lpthread", {force = true}) --- --- @endcode --- + set_values("c++.clang.modules.strict", true) -- clang std module clash with stl header units or c++23 std module so we disable it diff --git a/tests/projects/c++/modules/submodules/xmake.lua b/tests/projects/c++/modules/submodules/xmake.lua index 672034947..5f2b4ca78 100644 --- a/tests/projects/c++/modules/submodules/xmake.lua +++ b/tests/projects/c++/modules/submodules/xmake.lua @@ -1,4 +1,8 @@ +add_rules("mode.release", "mode.debug") set_languages("c++20") -target("math") + +target("submodule") set_kind("binary") add_files("src/*.cpp", "src/*.mpp") + + set_values("c++.clang.modules.strict", true) -- clang std module clash with stl headers, header units and c++23 std module so we disable it when using libc++ diff --git a/tests/projects/c++/modules/submodules2/xmake.lua b/tests/projects/c++/modules/submodules2/xmake.lua index 672034947..9dc2ee320 100644 --- a/tests/projects/c++/modules/submodules2/xmake.lua +++ b/tests/projects/c++/modules/submodules2/xmake.lua @@ -1,4 +1,6 @@ +add_rules("mode.release", "mode.debug") set_languages("c++20") -target("math") + +target("submodules2") set_kind("binary") add_files("src/*.cpp", "src/*.mpp") diff --git a/tests/projects/c++/modules/test_base.lua b/tests/projects/c++/modules/test_base.lua index 580110cb6..6ac816d66 100644 --- a/tests/projects/c++/modules/test_base.lua +++ b/tests/projects/c++/modules/test_base.lua @@ -14,7 +14,7 @@ function main(t) if is_subhost("windows") then os.exec("xmake f -c") _build() - elseif is_host("linux") then + elseif is_host("linux") or is_host("macos") then local gcc = find_tool("gcc", {version = true}) if gcc and gcc.version and semver.compare(gcc.version, "11.0") >= 0 then os.exec("xmake f -c") @@ -22,9 +22,11 @@ function main(t) 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") - _build() + if is_host("linux") then + os.exec("xmake clean -a") + os.exec("xmake f --toolchain=clang -c") + _build() + end os.exec("xmake clean -a") os.exec("xmake f --toolchain=clang --cxxflags=\"-stdlib=libc++\" -c") _build() diff --git a/tests/projects/c++/modules/test_headerunits.lua b/tests/projects/c++/modules/test_headerunits.lua index 872defb35..747ec6535 100644 --- a/tests/projects/c++/modules/test_headerunits.lua +++ b/tests/projects/c++/modules/test_headerunits.lua @@ -26,10 +26,13 @@ function main(t) end local clang = find_tool("clang", {version = true}) if clang and clang.version and semver.compare(clang.version, "16.0") >= 0 then - os.exec("xmake clean -a") - os.exec("xmake f --toolchain=clang -c") - _build() - -- os.exec("xmake clean -a") there is currently a bug on llvm git that prevent to build STL header units https://github.com/llvm/llvm-project/issues/58540 + if is_host("linux") then + os.exec("xmake clean -a") + os.exec("xmake f --toolchain=clang -c") + _build() + end + -- 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") -- os.exec("xmake f --toolchain=clang --cxxflags=\"-stdlib=libc++\" -c") -- _build() end diff --git a/tests/projects/c++/modules/test_msvc.lua b/tests/projects/c++/modules/test_msvc.lua deleted file mode 100644 index a436b5814..000000000 --- a/tests/projects/c++/modules/test_msvc.lua +++ /dev/null @@ -1,28 +0,0 @@ -import("lib.detect.find_tool") -import("core.base.semver") -import("core.tool.toolchain") - -function _build() - local ci = (os.getenv("CI") or os.getenv("GITHUB_ACTIONS") or ""):lower() - if ci == "true" then - os.exec("xmake -rvD") - else - os.exec("xmake -r") - end -end - -function main(t) - if is_subhost("windows") then - 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") - _build() - end - end - end - end -end diff --git a/tests/projects/c++/modules/test_stdmodules.lua b/tests/projects/c++/modules/test_stdmodules.lua new file mode 100644 index 000000000..2d8861d09 --- /dev/null +++ b/tests/projects/c++/modules/test_stdmodules.lua @@ -0,0 +1,47 @@ +import("lib.detect.find_tool") +import("core.base.semver") +import("core.tool.toolchain") + +function _build() + local ci = (os.getenv("CI") or os.getenv("GITHUB_ACTIONS") or ""):lower() + if ci == "true" then + os.exec("xmake -rvD") + else + os.exec("xmake -r") + end +end + +function main(t) + if is_subhost("windows") then + 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") + _build() + end + end + end + elseif is_host("linux") or is_host("macos") then + -- gcc don't support std modules atm + -- local gcc = find_tool("gcc", {version = true}) + -- if gcc and gcc.version and semver.compare(gcc.version, "11.0") >= 0 then + -- os.exec("xmake f -c") + -- _build() + -- end + local clang = find_tool("clang", {version = true}) + if clang and clang.version and semver.compare(clang.version, "14.0") >= 0 then + if is_host("linux") then + -- clang don't support libstdc++ std modules atm + -- os.exec("xmake clean -a") + -- os.exec("xmake f --toolchain=clang -c") + -- _build() + end + os.exec("xmake clean -a") + os.exec("xmake f --toolchain=clang --cxxflags=\"-stdlib=libc++\" -c") + _build() + end + end +end diff --git a/tests/projects/c++/modules/user_headerunit/xmake.lua b/tests/projects/c++/modules/user_headerunit/xmake.lua index dae91d11f..e305044b5 100644 --- a/tests/projects/c++/modules/user_headerunit/xmake.lua +++ b/tests/projects/c++/modules/user_headerunit/xmake.lua @@ -1,4 +1,6 @@ +add_rules("mode.release", "mode.debug") set_languages("c++20") + target("user_headerunit") set_kind("binary") add_headerfiles("src/*.hpp") diff --git a/xmake/rules/c++/modules/modules_support/clang.lua b/xmake/rules/c++/modules/modules_support/clang.lua index 9cf7edcdf..7a63c027d 100644 --- a/xmake/rules/c++/modules/modules_support/clang.lua +++ b/xmake/rules/c++/modules/modules_support/clang.lua @@ -67,11 +67,19 @@ end -- load module support for the current target function load(target) local modulesflag = get_modulesflag(target) + local builtinmodulemapflag = get_builtinmodulemapflag(target) + local implicitmodulesflag = get_implicitmodulesflag(target) local noimplicitmodulemapsflag = get_noimplicitmodulemapsflag(target) -- add module flags target:add("cxxflags", modulesflag) - target:add("cxxflags", noimplicitmodulemapsflag, {force = true}) + + if not target:values("c++.clang.modules.strict") then + target:add("cxxflags", builtinmodulemapflag, {force = true}) + target:add("cxxflags", implicitmodulesflag, {force = true}) + else + target:add("cxxflags", noimplicitmodulemapsflag, {force = true}) + end -- fix default visibility for functions and variables [-fvisibility] differs in PCH file vs. current file -- module.pcm cannot be loaded due to a configuration mismatch with the current compilation. -- cgit v1.3.1