summaryrefslogtreecommitdiff
path: root/xmake/rules/c++/modules/clang
diff options
context:
space:
mode:
Diffstat (limited to 'xmake/rules/c++/modules/clang')
-rw-r--r--xmake/rules/c++/modules/clang/builder.lua8
-rw-r--r--xmake/rules/c++/modules/clang/support.lua26
2 files changed, 31 insertions, 3 deletions
diff --git a/xmake/rules/c++/modules/clang/builder.lua b/xmake/rules/c++/modules/clang/builder.lua
index 4839733e0..4ecafb17e 100644
--- a/xmake/rules/c++/modules/clang/builder.lua
+++ b/xmake/rules/c++/modules/clang/builder.lua
@@ -65,6 +65,8 @@ function _make_modulebuildflags(target, module, opt)
local modules_reduced_bmi_flag = support.get_modulesreducedbmiflag(target)
local has_two_phases = target:policy("build.c++.modules.two_phases")
+ local has_precompile_reduced_bmi = support.has_precompile_reduced_bmi_support(target)
+ local modules_precompile_reduced_bmi_flag = has_precompile_reduced_bmi and support.get_modulesprecompilereducedbmiflag(target)
local flags
if opt.bmi then
local module_outputflag = support.get_moduleoutputflag(target)
@@ -72,7 +74,7 @@ function _make_modulebuildflags(target, module, opt)
flags = {"-x", "c++-module"}
if not opt.objectfile then
- table.insert(flags, "--precompile")
+ table.insert(flags, modules_precompile_reduced_bmi_flag or "--precompile")
if target:has_tool("cxx", "clang_cl") then
table.join2(flags, "/clang:-o", "/clang:" .. module.bmifile)
end
@@ -92,7 +94,7 @@ function _make_modulebuildflags(target, module, opt)
end
else
flags = {}
- if not has_two_phases or not module.bmifile then
+ if (has_precompile_reduced_bmi and support.has_module_extension(module.sourcefile)) or not has_two_phases or not module.bmifile then
flags = {"-x", "c++"}
end
local std = (module.name == "std" or module.name == "std.compat")
@@ -171,7 +173,7 @@ function _compile(target, flags, module, opt)
opt = opt or {}
local sourcefile = module.sourcefile
- if not opt.bmi and opt.objectfile and module.bmifile then
+ if not support.has_precompile_reduced_bmi_support(target) and not opt.bmi and opt.objectfile and module.bmifile then
sourcefile = module.bmifile
end
local outputfile = ((opt.bmi and not opt.objectfile) or opt.headerunit) and module.bmifile or module.objectfile
diff --git a/xmake/rules/c++/modules/clang/support.lua b/xmake/rules/c++/modules/clang/support.lua
index 71bd2e735..a010fdde1 100644
--- a/xmake/rules/c++/modules/clang/support.lua
+++ b/xmake/rules/c++/modules/clang/support.lua
@@ -130,6 +130,13 @@ function has_two_phase_compilation_support(target)
return target:policy("build.c++.modules.two_phases")
end
+function has_precompile_reduced_bmi_support(target)
+ if not target:policy("build.c++.modules.clang.precompile_reduced_bmi") or not has_two_phase_compilation_support(target) then
+ return false
+ end
+ return get_modulesprecompilereducedbmiflag(target) ~= nil
+end
+
-- flags that doesn't affect bmi generation
function strippeable_flags()
-- speculative list as there is no resource that list flags that prevent reusability, this list will likely be improve over time
@@ -411,6 +418,25 @@ function get_modulesreducedbmiflag(target)
return modulesreducedbmiflag or nil
end
+function get_modulesprecompilereducedbmiflag(target)
+ local modulesprecompilereducedbmiflag = _g.modulesprecompilereducedbmiflag
+ if modulesprecompilereducedbmiflag == nil then
+ local compinst = target:compiler("cxx")
+ local checkflags = "--precompile-reduced-bmi"
+ if target:has_tool("cxx", "clang_cl") then
+ -- clang_cl.has_flags() appends -c and treats unused-argument warnings as errors,
+ -- but --precompile-reduced-bmi does not use -c. Ignore that specific warning and
+ -- treat unknown-argument warnings as errors to reject unsupported flags.
+ checkflags = {checkflags, "-Wno-unused-command-line-argument", "-Werror=unknown-argument"}
+ end
+ if compinst:has_flags(checkflags, "cxxflags", {flagskey = "clang_modules_precompile_reduced_bmi", tryrun = true}) then
+ modulesprecompilereducedbmiflag = "--precompile-reduced-bmi"
+ end
+ _g.modulesprecompilereducedbmiflag = modulesprecompilereducedbmiflag or false
+ end
+ return modulesprecompilereducedbmiflag or nil
+end
+
function has_clangscandepssupport(target)
local support_clangscandeps = _g.support_clangscandeps
if support_clangscandeps == nil then