summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArthur LAURENT <[email protected]>2024-01-23 20:05:00 +0100
committerArthur LAURENT <[email protected]>2024-01-26 18:20:58 +0100
commita6f1cc3b301da925684e937489bddf8c41ac440a (patch)
tree15ebdd564192a7aa0acaf51fc778491aab243f7c
parent7dddd80a592a16f5b718ec8cf96254ac220205f7 (diff)
add a policy to toggle C++23 std module
-rw-r--r--xmake/core/project/policy.lua4
-rw-r--r--xmake/rules/c++/modules/modules_support/clang/compiler_support.lua50
-rw-r--r--xmake/rules/c++/modules/modules_support/gcc/compiler_support.lua2
-rw-r--r--xmake/rules/c++/modules/modules_support/msvc/compiler_support.lua26
4 files changed, 43 insertions, 39 deletions
diff --git a/xmake/core/project/policy.lua b/xmake/core/project/policy.lua
index e7212189e..916ce9677 100644
--- a/xmake/core/project/policy.lua
+++ b/xmake/core/project/policy.lua
@@ -64,8 +64,8 @@ function policy.policies()
["build.sanitizer.undefined"] = {description = "Enable undefined sanitizer for c/c++ building.", type = "boolean"},
-- Enable C++ modules for C++ building, even if no .mpp is involved in the compilation
["build.c++.modules"] = {description = "Enable C++ modules for C++ building.", type = "boolean"},
- -- Enable clang std modulemap
- ["build.c++.clang.stdmodules"] = {description = "Enable clang std modulemap.", default = false, type = "boolean"},
+ -- Enable std module
+ ["build.c++.modules.std"] = {description = "Enable std modules.", default = true, type = "boolean"},
-- Force C++ modules fallback dependency scanner for clang
["build.c++.clang.fallbackscanner"] = {description = "Force clang fallback module dependency scanner.", default = false, type = "boolean"},
-- Force C++ modules fallback dependency scanner for msvc
diff --git a/xmake/rules/c++/modules/modules_support/clang/compiler_support.lua b/xmake/rules/c++/modules/modules_support/clang/compiler_support.lua
index ea2301859..a1f10b5ae 100644
--- a/xmake/rules/c++/modules/modules_support/clang/compiler_support.lua
+++ b/xmake/rules/c++/modules/modules_support/clang/compiler_support.lua
@@ -74,11 +74,6 @@ function load(target)
target:add("cxxflags", modulestsflag)
end
- -- enable clang modules to emulate std modules
- if target:policy("build.c++.clang.stdmodules") then
- target:add("cxxflags", clangmodulesflag)
- 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.
--
@@ -211,28 +206,31 @@ end
-- not supported atm
function get_stdmodules(target)
- if _use_stdlib(target, "libc++") then
- -- TODO support libc++ std module file when https://github.com/xmake-io/xmake/pull/4630
- return {}
- elseif _use_stdlib(target, "libstdc++") then
- -- libstdc++ doesn't have a std module file atm
- return {}
- elseif _use_stdlib(target, "msstl") then
- -- msstl std module file is not compatible with llvm <= 18
- -- local toolchain = target:toolchain("clang")
- -- local msvc = import("core.tool.toolchain", {anonymous = true}).load("msvc", {plat = toolchain:plat(), arch = toolchain:arch()})
- -- if msvc then
- -- local vcvars = msvc:config("vcvars")
- -- if vcvars.VCInstallDir and vcvars.VCToolsVersion then
- -- modules = {}
- --
- -- local stdmodulesdir = path.join(vcvars.VCInstallDir, "Tools", "MSVC", vcvars.VCToolsVersion, "modules")
- -- assert(stdmodulesdir, "Can't enable C++23 std modules, directory missing !")
- --
- -- return {path.join(stdmodulesdir, "std.ixx"), path.join(stdmodulesdir, "std.compat.ixx")}
- -- end
- -- end
+ if target:policy("build.c++.modules.std") then
+ if _use_stdlib(target, "libc++") then
+ -- TODO support libc++ std module file when https://github.com/xmake-io/xmake/pull/4630
+ return {}
+ elseif _use_stdlib(target, "libstdc++") then
+ -- libstdc++ doesn't have a std module file atm
+ elseif _use_stdlib(target, "msstl") then
+ -- msstl std module file is not compatible with llvm <= 18
+ -- local toolchain = target:toolchain("clang")
+ -- local msvc = import("core.tool.toolchain", {anonymous = true}).load("msvc", {plat = toolchain:plat(), arch = toolchain:arch()})
+ -- if msvc then
+ -- local vcvars = msvc:config("vcvars")
+ -- if vcvars.VCInstallDir and vcvars.VCToolsVersion then
+ -- modules = {}
+ --
+ -- local stdmodulesdir = path.join(vcvars.VCInstallDir, "Tools", "MSVC", vcvars.VCToolsVersion, "modules")
+ -- assert(stdmodulesdir, "Can't enable C++23 std modules, directory missing !")
+ --
+ -- return {path.join(stdmodulesdir, "std.ixx"), path.join(stdmodulesdir, "std.compat.ixx")}
+ -- end
+ -- end
+ end
end
+
+ return {}
end
function get_bmi_extension()
diff --git a/xmake/rules/c++/modules/modules_support/gcc/compiler_support.lua b/xmake/rules/c++/modules/modules_support/gcc/compiler_support.lua
index 147c8eeb1..7dab1f4da 100644
--- a/xmake/rules/c++/modules/modules_support/gcc/compiler_support.lua
+++ b/xmake/rules/c++/modules/modules_support/gcc/compiler_support.lua
@@ -101,6 +101,8 @@ end
-- not supported atm
function get_stdmodules(_)
+ if target:policy("build.c++.modules.std") then
+ end
return {}
end
diff --git a/xmake/rules/c++/modules/modules_support/msvc/compiler_support.lua b/xmake/rules/c++/modules/modules_support/msvc/compiler_support.lua
index 3b6aafb9a..3f67e0291 100644
--- a/xmake/rules/c++/modules/modules_support/msvc/compiler_support.lua
+++ b/xmake/rules/c++/modules/modules_support/msvc/compiler_support.lua
@@ -31,7 +31,7 @@ function load(target)
local vcvars = msvc:config("vcvars")
-- enable std modules if c++23 by defaults
- if target:data("c++.msvc.enable_std_import") == nil then
+ if target:data("c++.msvc.enable_std_import") == nil and target:policy("build.c++.modules.std") then
local languages = target:get("languages")
local isatleastcpp23 = false
for _, language in ipairs(languages) do
@@ -70,22 +70,26 @@ function toolchain_includedirs(target)
raise("msvc toolchain includedirs not found!")
end
+-- build c++23 standard modules if needed
function get_stdmodules(target)
- -- build c++23 standard modules if needed
- if target:data("c++.msvc.enable_std_import") then
- local msvc = target:toolchain("msvc")
- if msvc then
- local vcvars = msvc:config("vcvars")
- if vcvars.VCInstallDir and vcvars.VCToolsVersion then
- modules = {}
+ if target:policy("build.c++.modules.std") then
+ if target:data("c++.msvc.enable_std_import") then
+ local msvc = target:toolchain("msvc")
+ if msvc then
+ local vcvars = msvc:config("vcvars")
+ if vcvars.VCInstallDir and vcvars.VCToolsVersion then
+ modules = {}
- local stdmodulesdir = path.join(vcvars.VCInstallDir, "Tools", "MSVC", vcvars.VCToolsVersion, "modules")
- assert(stdmodulesdir, "Can't enable C++23 std modules, directory missing !")
+ local stdmodulesdir = path.join(vcvars.VCInstallDir, "Tools", "MSVC", vcvars.VCToolsVersion, "modules")
+ assert(stdmodulesdir, "Can't enable C++23 std modules, directory missing !")
- return {path.join(stdmodulesdir, "std.ixx"), path.join(stdmodulesdir, "std.compat.ixx")}
+ return {path.join(stdmodulesdir, "std.ixx"), path.join(stdmodulesdir, "std.compat.ixx")}
+ end
end
end
end
+
+ return {}
end
function get_bmi_extension()