Skip to content

Commit 481ada9

Browse files
committed
(C++ modules support) fix clang-cl
1 parent 42ba909 commit 481ada9

File tree

4 files changed

+35
-7
lines changed

4 files changed

+35
-7
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,13 @@
11
inherit(".test_base")
2+
3+
CLANG_MIN_VER = "17"
4+
GCC_MIN_VER = "11"
5+
MSVC_MIN_VER = "14.29"
6+
7+
function main(_)
8+
-- clang-cl doesn't support mixing pch and C++ module atm
9+
local clang_options = {compiler = "clang", version = CLANG_MIN_VER, disable_clang_cl = true}
10+
local gcc_options = {compiler = "gcc", version = GCC_MIN_VER}
11+
local msvc_options = {version = MSVC_MIN_VER}
12+
run_tests(clang_options, gcc_options, msvc_options)
13+
end

tests/projects/c++/modules/test_base.lua

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import("core.tool.toolchain")
44
import("utils.ci.is_running", {alias = "ci_is_running"})
55

66
CLANG_MIN_VER = "17"
7+
CLANG_CL_MIN_VER = "19"
78
GCC_MIN_VER = "11"
89
MSVC_MIN_VER = "14.29"
910

@@ -83,7 +84,7 @@ function build_tests(toolchain_name, opt)
8384
wprint(version_str .. "not found, skipping tests")
8485
return
8586
end
86-
87+
8788
local policies = "--policies=build.c++.modules.std:" .. (opt.stdmodule and "y" or "n")
8889
policies = policies .. ",build.c++.modules.fallbackscanner:" .. (opt.fallbackscanner and "y" or "n")
8990

@@ -127,9 +128,12 @@ function run_tests(clang_options, gcc_options, msvc_options)
127128
if clang_options then
128129
build_tests("llvm", clang_options)
129130
build_tests("clang", clang_options)
130-
local clang_cl_options = table.clone(clang_options)
131-
clang_cl_options.compiler = "clang-cl"
132-
build_tests("clang-cl", clang_cl_options)
131+
if not clang_options.disable_clang_cl then
132+
local clang_cl_options = table.clone(clang_options)
133+
clang_cl_options.compiler = "clang-cl"
134+
clang_cl_options.version = CLANG_CL_MIN_VER
135+
build_tests("clang-cl", clang_cl_options)
136+
end
133137
if not clang_options.stdmodule then
134138
build_tests("llvm", clang_libcpp_options)
135139
build_tests("clang", clang_libcpp_options)

xmake/rules/c++/modules/clang/builder.lua

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ function _make_modulebuildflags(target, module, opt)
4040
flags = {"-x", "c++-module"}
4141
if not opt.objectfile then
4242
table.insert(flags, "--precompile")
43+
if target:has_tool("cxx", "clang_cl") then
44+
table.join2(flags, "/clang:-o", "/clang:" .. module.bmifile)
45+
end
4346
end
4447
local std = (module.name == "std" or module.name == "std.compat")
4548
if std then
@@ -182,7 +185,6 @@ function _get_requiresflags(target, module)
182185
end
183186
end
184187
requiresflags = table.unique(requiresflags)
185-
-- table.sort(requiresflags)
186188
support.memcache():set2(cachekey, "requiresflags", requiresflags)
187189
support.memcache():set2(cachekey, "oldrequires", requires)
188190
end

xmake/rules/c++/modules/scanner.lua

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,12 @@ function _patch_sourcebatch(target, sourcebatch)
389389

390390
local can_reuse = nocheck or _are_flags_compatible(target, dep, sourcefile, {strict = strict})
391391
if can_reuse then
392-
support.set_reused(target, dep, sourcefile)
392+
local _reused, from = support.is_reused(dep, sourcefile)
393+
if _reused then
394+
support.set_reused(target, from, sourcefile)
395+
else
396+
support.set_reused(target, dep, sourcefile)
397+
end
393398
table.insert(reused, sourcefile)
394399
if dep:is_moduleonly() then
395400
dep:data_set("cxx.modules.reused", true)
@@ -417,10 +422,15 @@ function _patch_sourcebatch(target, sourcebatch)
417422
if reused:has(sourcefile) then
418423
local dep = target:dep(fileconfig.external)
419424
assert(dep, "dep target <%s> for <%s> not found", fileconfig.external, target:fullname())
425+
local _reused, from = support.is_reused(dep, sourcefile)
426+
if _reused then
427+
support.set_reused(target, from, sourcefile)
428+
else
429+
support.set_reused(target, dep, sourcefile)
430+
end
420431
if dep:is_moduleonly() then
421432
dep:data_set("cxx.modules.reused", true)
422433
end
423-
support.set_reused(target, dep, sourcefile)
424434
end
425435
target:fileconfig_add(sourcefile, fileconfig)
426436
end

0 commit comments

Comments
 (0)