summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArthur LAURENT <[email protected]>2025-05-22 08:51:48 +0200
committerArthur LAURENT <[email protected]>2025-05-22 08:51:48 +0200
commit481ada9f541be6754801d36bd03c84e7b8665b58 (patch)
tree951bba94cd5c7cb82b5d0239b1415fc26dccfdc4
parent42ba909a17dd780a8bf1ba51a8fcd05ad9418ebd (diff)
(C++ modules support) fix clang-cl
-rw-r--r--tests/projects/c++/modules/hello_with_pch/test.lua12
-rw-r--r--tests/projects/c++/modules/test_base.lua12
-rw-r--r--xmake/rules/c++/modules/clang/builder.lua4
-rw-r--r--xmake/rules/c++/modules/scanner.lua14
4 files changed, 35 insertions, 7 deletions
diff --git a/tests/projects/c++/modules/hello_with_pch/test.lua b/tests/projects/c++/modules/hello_with_pch/test.lua
index 7717f8049..033d2882c 100644
--- a/tests/projects/c++/modules/hello_with_pch/test.lua
+++ b/tests/projects/c++/modules/hello_with_pch/test.lua
@@ -1 +1,13 @@
inherit(".test_base")
+
+CLANG_MIN_VER = "17"
+GCC_MIN_VER = "11"
+MSVC_MIN_VER = "14.29"
+
+function main(_)
+ -- clang-cl doesn't support mixing pch and C++ module atm
+ local clang_options = {compiler = "clang", version = CLANG_MIN_VER, disable_clang_cl = true}
+ local gcc_options = {compiler = "gcc", version = GCC_MIN_VER}
+ local msvc_options = {version = MSVC_MIN_VER}
+ run_tests(clang_options, gcc_options, msvc_options)
+end
diff --git a/tests/projects/c++/modules/test_base.lua b/tests/projects/c++/modules/test_base.lua
index 3f05281f3..0f030e065 100644
--- a/tests/projects/c++/modules/test_base.lua
+++ b/tests/projects/c++/modules/test_base.lua
@@ -4,6 +4,7 @@ import("core.tool.toolchain")
import("utils.ci.is_running", {alias = "ci_is_running"})
CLANG_MIN_VER = "17"
+CLANG_CL_MIN_VER = "19"
GCC_MIN_VER = "11"
MSVC_MIN_VER = "14.29"
@@ -83,7 +84,7 @@ function build_tests(toolchain_name, opt)
wprint(version_str .. "not found, skipping tests")
return
end
-
+
local policies = "--policies=build.c++.modules.std:" .. (opt.stdmodule and "y" or "n")
policies = policies .. ",build.c++.modules.fallbackscanner:" .. (opt.fallbackscanner and "y" or "n")
@@ -127,9 +128,12 @@ function run_tests(clang_options, gcc_options, msvc_options)
if clang_options then
build_tests("llvm", clang_options)
build_tests("clang", clang_options)
- local clang_cl_options = table.clone(clang_options)
- clang_cl_options.compiler = "clang-cl"
- build_tests("clang-cl", clang_cl_options)
+ if not clang_options.disable_clang_cl then
+ local clang_cl_options = table.clone(clang_options)
+ clang_cl_options.compiler = "clang-cl"
+ clang_cl_options.version = CLANG_CL_MIN_VER
+ build_tests("clang-cl", clang_cl_options)
+ end
if not clang_options.stdmodule then
build_tests("llvm", clang_libcpp_options)
build_tests("clang", clang_libcpp_options)
diff --git a/xmake/rules/c++/modules/clang/builder.lua b/xmake/rules/c++/modules/clang/builder.lua
index 797167283..17189b790 100644
--- a/xmake/rules/c++/modules/clang/builder.lua
+++ b/xmake/rules/c++/modules/clang/builder.lua
@@ -40,6 +40,9 @@ function _make_modulebuildflags(target, module, opt)
flags = {"-x", "c++-module"}
if not opt.objectfile then
table.insert(flags, "--precompile")
+ if target:has_tool("cxx", "clang_cl") then
+ table.join2(flags, "/clang:-o", "/clang:" .. module.bmifile)
+ end
end
local std = (module.name == "std" or module.name == "std.compat")
if std then
@@ -182,7 +185,6 @@ function _get_requiresflags(target, module)
end
end
requiresflags = table.unique(requiresflags)
- -- table.sort(requiresflags)
support.memcache():set2(cachekey, "requiresflags", requiresflags)
support.memcache():set2(cachekey, "oldrequires", requires)
end
diff --git a/xmake/rules/c++/modules/scanner.lua b/xmake/rules/c++/modules/scanner.lua
index 9e95f3cfd..537fb91d9 100644
--- a/xmake/rules/c++/modules/scanner.lua
+++ b/xmake/rules/c++/modules/scanner.lua
@@ -389,7 +389,12 @@ function _patch_sourcebatch(target, sourcebatch)
local can_reuse = nocheck or _are_flags_compatible(target, dep, sourcefile, {strict = strict})
if can_reuse then
- support.set_reused(target, dep, sourcefile)
+ local _reused, from = support.is_reused(dep, sourcefile)
+ if _reused then
+ support.set_reused(target, from, sourcefile)
+ else
+ support.set_reused(target, dep, sourcefile)
+ end
table.insert(reused, sourcefile)
if dep:is_moduleonly() then
dep:data_set("cxx.modules.reused", true)
@@ -417,10 +422,15 @@ function _patch_sourcebatch(target, sourcebatch)
if reused:has(sourcefile) then
local dep = target:dep(fileconfig.external)
assert(dep, "dep target <%s> for <%s> not found", fileconfig.external, target:fullname())
+ local _reused, from = support.is_reused(dep, sourcefile)
+ if _reused then
+ support.set_reused(target, from, sourcefile)
+ else
+ support.set_reused(target, dep, sourcefile)
+ end
if dep:is_moduleonly() then
dep:data_set("cxx.modules.reused", true)
end
- support.set_reused(target, dep, sourcefile)
end
target:fileconfig_add(sourcefile, fileconfig)
end