From 0497293c09538713734b1b76b0577263a7139e80 Mon Sep 17 00:00:00 2001 From: ruki Date: Tue, 23 Dec 2025 23:37:40 +0800 Subject: fix envs for clang-cl --- xmake/toolchains/clang-cl/load.lua | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/xmake/toolchains/clang-cl/load.lua b/xmake/toolchains/clang-cl/load.lua index 69f9c8297..e06883012 100644 --- a/xmake/toolchains/clang-cl/load.lua +++ b/xmake/toolchains/clang-cl/load.lua @@ -47,9 +47,6 @@ function main(toolchain) toolchain:set("toolset", "ar", "link.exe") end - -- add vs environments - toolchain_utils.add_vsenvs(toolchain) - -- add llvm runenvs before adding vsenvs -- -- The dynamic libraries (DLLs) for Clang ASan and MSVC ASan share the same filename, making them incompatible. @@ -57,6 +54,9 @@ function main(toolchain) -- If the Clang path is not prioritized (placed first), the system incorrectly loads the MSVC ASan DLL, resulting in a runtime failure. toolchain_utils.add_llvm_runenvs(toolchain) + -- add vs environments + toolchain_utils.add_vsenvs(toolchain) + -- add target flags local flags = toolchain_utils.get_clang_target_flags(toolchain) if flags then -- cgit v1.3.1 From 2a8c2f054da67e68ab0bb727976a7ab52d55f12d Mon Sep 17 00:00:00 2001 From: ruki Date: Wed, 24 Dec 2025 23:17:41 +0800 Subject: improve to add vsenvs --- xmake/modules/private/utils/toolchain.lua | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/xmake/modules/private/utils/toolchain.lua b/xmake/modules/private/utils/toolchain.lua index 48aabdffa..263137300 100644 --- a/xmake/modules/private/utils/toolchain.lua +++ b/xmake/modules/private/utils/toolchain.lua @@ -180,14 +180,15 @@ function get_clang_target_flags(toolchain) end -- add vs environments -function add_vsenvs(toolchain, expect_vars) +function add_vsenvs(toolchain, opt) + opt = opt or {} local curenvs = os.getenvs() - expect_vars = expect_vars or {"PATH", "LIB", "INCLUDE", "LIBPATH"} - for _, name in ipairs(expect_vars) do + local varnames = opt.varnames or {"PATH", "LIB", "INCLUDE", "LIBPATH"} + for _, name in ipairs(varnames) do _add_vsenv(toolchain, name, curenvs) end for _, name in ipairs(find_vstudio.get_vcvars()) do - if not table.contains(expect_vars, name:upper()) then + if not table.contains(varnames, name:upper()) then _add_vsenv(toolchain, name, curenvs) end end -- cgit v1.3.1 From 0322af3c7241da09e69282c369bfbbf9d5931c9b Mon Sep 17 00:00:00 2001 From: ruki Date: Thu, 25 Dec 2025 21:01:23 +0800 Subject: improve tests --- tests/projects/c++/modules/packages-subtarget/xmake.lua | 2 +- tests/projects/c++/modules/packages/xmake.lua | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/projects/c++/modules/packages-subtarget/xmake.lua b/tests/projects/c++/modules/packages-subtarget/xmake.lua index bfafb232b..365ef08da 100644 --- a/tests/projects/c++/modules/packages-subtarget/xmake.lua +++ b/tests/projects/c++/modules/packages-subtarget/xmake.lua @@ -1,5 +1,5 @@ add_rules("mode.release", "mode.debug") -set_languages("c++2b") +set_languages("c++20") add_repositories("my-repo my-repo") add_requires("foo", "bar", "bar2") diff --git a/tests/projects/c++/modules/packages/xmake.lua b/tests/projects/c++/modules/packages/xmake.lua index 62dba119b..936b83daf 100644 --- a/tests/projects/c++/modules/packages/xmake.lua +++ b/tests/projects/c++/modules/packages/xmake.lua @@ -1,5 +1,5 @@ add_rules("mode.release", "mode.debug") -set_languages("c++2b") +set_languages("c++20") add_repositories("my-repo my-repo") add_requires("foo", "bar", "bar2") -- cgit v1.3.1 From 06b9a04ed59c2595c2c7610d7f8b08712d710352 Mon Sep 17 00:00:00 2001 From: ruki Date: Fri, 26 Dec 2025 00:01:13 +0800 Subject: improve clang module flags --- xmake/rules/c++/modules/clang/support.lua | 67 +++++++++++++++++++------------ 1 file changed, 41 insertions(+), 26 deletions(-) diff --git a/xmake/rules/c++/modules/clang/support.lua b/xmake/rules/c++/modules/clang/support.lua index 9447d9c97..cb5b342ea 100644 --- a/xmake/rules/c++/modules/clang/support.lua +++ b/xmake/rules/c++/modules/clang/support.lua @@ -325,16 +325,18 @@ function get_modulesflag(target) local modulestsflag = _g.modulestsflag local withoutflag = _g.withoutflag if clangmodulesflag == nil and modulestsflag == nil then - local compinst = target:compiler("cxx") - if compinst:has_flags("-fmodules", "cxxflags", {flagskey = "clang_modules"}) then - clangmodulesflag = "-fmodules" - end - if compinst:has_flags("-fmodules-ts", "cxxflags", {flagskey = "clang_modules_ts"}) then - modulestsflag = "-fmodules-ts" - end local clang_version = get_clang_version(target) withoutflag = semver.compare(clang_version, "16.0") >= 0 - assert(withoutflag or modulestsflag, "compiler(clang): does not support c++ module!") + if not withoutflag then + local compinst = target:compiler("cxx") + if compinst:has_flags("-fmodules", "cxxflags", {flagskey = "clang_modules"}) then + clangmodulesflag = "-fmodules" + end + if compinst:has_flags("-fmodules-ts", "cxxflags", {flagskey = "clang_modules_ts"}) then + modulestsflag = "-fmodules-ts" + end + assert(modulestsflag or clangmodulesflag, "compiler(clang): does not support c++ module!") + end _g.clangmodulesflag = clangmodulesflag or false _g.modulestsflag = modulestsflag or false _g.withoutflag = withoutflag or false @@ -345,9 +347,12 @@ end function get_modulefileflag(target) local modulefileflag = _g.modulefileflag if modulefileflag == nil then - local compinst = target:compiler("cxx") - if compinst:has_flags("-fmodule-file=" .. os.tmpfile() .. get_bmi_extension(), "cxxflags", {flagskey = "clang_module_file"}) then - modulefileflag = "-fmodule-file=" + local clang_version = get_clang_version(target) + if semver.compare(clang_version, "16.0") >= 0 then + local compinst = target:compiler("cxx") + if compinst:has_flags("-fmodule-file=" .. os.tmpfile() .. get_bmi_extension(), "cxxflags", {flagskey = "clang_module_file"}) then + modulefileflag = "-fmodule-file=" + end end assert(modulefileflag, "compiler(clang): does not support c++ module!") _g.modulefileflag = modulefileflag or false @@ -358,9 +363,12 @@ end function get_moduleheaderflag(target) local moduleheaderflag = _g.moduleheaderflag if moduleheaderflag == nil then - local compinst = target:compiler("cxx") - if compinst:has_flags("-fmodule-header=system", "cxxflags", {flagskey = "clang_module_header"}) then - moduleheaderflag = "-fmodule-header=" + local clang_version = get_clang_version(target) + if semver.compare(clang_version, "16.0") >= 0 then + local compinst = target:compiler("cxx") + if compinst:has_flags("-fmodule-header=system", "cxxflags", {flagskey = "clang_module_header"}) then + moduleheaderflag = "-fmodule-header=" + end end _g.moduleheaderflag = moduleheaderflag or false end @@ -370,11 +378,14 @@ end function get_modulesreducedbmiflag(target) local modulesreducedbmiflag = _g.modulesreducedbmiflag if modulesreducedbmiflag == nil then - local compinst = target:compiler("cxx") - if compinst:has_flags("-fmodules-reduced-bmi", "cxxflags", {flagskey = "clang_modules_reduced_bmi"}) then - modulesreducedbmiflag = "-fmodules-reduced-bmi" - elseif compinst:has_flags("-fexperimental-modules-reduced-bmi", "cxxflags", {flagskey = "clang_modules_reduced_bmi"}) then - modulesreducedbmiflag = "-fexperimental-modules-reduced-bmi" + local clang_version = get_clang_version(target) + if semver.compare(clang_version, "16.0") >= 0 then + local compinst = target:compiler("cxx") + if compinst:has_flags("-fmodules-reduced-bmi", "cxxflags", {flagskey = "clang_modules_reduced_bmi"}) then + modulesreducedbmiflag = "-fmodules-reduced-bmi" + elseif compinst:has_flags("-fexperimental-modules-reduced-bmi", "cxxflags", {flagskey = "clang_modules_reduced_bmi"}) then + modulesreducedbmiflag = "-fexperimental-modules-reduced-bmi" + end end _g.modulesreducedbmiflag = modulesreducedbmiflag or false end @@ -411,11 +422,12 @@ end function get_moduleoutputflag(target) local moduleoutputflag = _g.moduleoutputflag if moduleoutputflag == nil then - local compinst = target:compiler("cxx") local clang_version = get_clang_version(target) - if compinst:has_flags("-fmodule-output=", "cxxflags", {flagskey = "clang_module_output", tryrun = true}) and - semver.compare(clang_version, "16.0") >= 0 then - moduleoutputflag = "-fmodule-output=" + if semver.compare(clang_version, "16.0") >= 0 then + local compinst = target:compiler("cxx") + if compinst:has_flags("-fmodule-output=", "cxxflags", {flagskey = "clang_module_output", tryrun = true}) then + moduleoutputflag = "-fmodule-output=" + end end _g.moduleoutputflag = moduleoutputflag or false end @@ -425,9 +437,12 @@ end function get_print_library_module_manifest_path_flag(target) local print_library_module_manifest_path_flag = _g.print_library_module_manifest_path_flag if print_library_module_manifest_path_flag == nil then - local compinst = target:compiler("cxx") - if compinst:has_flags("-print-library-module-manifest-path", "cxxflags", {flagskey = "clang_print_library_module_manifest_path", tryrun = true}) then - print_library_module_manifest_path_flag = "-print-library-module-manifest-path" + local clang_version = get_clang_version(target) + if semver.compare(clang_version, "16.0") >= 0 then + local compinst = target:compiler("cxx") + if compinst:has_flags("-print-library-module-manifest-path", "cxxflags", {flagskey = "clang_print_library_module_manifest_path", tryrun = true}) then + print_library_module_manifest_path_flag = "-print-library-module-manifest-path" + end end _g.print_library_module_manifest_path_flag = print_library_module_manifest_path_flag or false end -- cgit v1.3.1 From 098e88709689198cb4d5145f9e24e70d86f3d1dd Mon Sep 17 00:00:00 2001 From: ruki Date: Fri, 26 Dec 2025 00:01:59 +0800 Subject: force test code --- tests/projects/c++/modules/xmake_tests1/xmake.lua | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/projects/c++/modules/xmake_tests1/xmake.lua b/tests/projects/c++/modules/xmake_tests1/xmake.lua index 64198ec69..c0f5530fe 100644 --- a/tests/projects/c++/modules/xmake_tests1/xmake.lua +++ b/tests/projects/c++/modules/xmake_tests1/xmake.lua @@ -1,6 +1,7 @@ add_rules('mode.debug', 'mode.release') - set_languages('c++23') - set_policy('build.c++.modules.std', false) + +set_languages('c++23') +set_policy('build.c++.modules.std', false) target('module_dep') set_kind('moduleonly') -- cgit v1.3.1 From 946aad1e5021fd07d70a109497ca064aa14bc8c6 Mon Sep 17 00:00:00 2001 From: ruki Date: Fri, 26 Dec 2025 00:16:43 +0800 Subject: revert clang flags --- xmake/rules/c++/modules/clang/support.lua | 67 ++++++++++++------------------- 1 file changed, 26 insertions(+), 41 deletions(-) diff --git a/xmake/rules/c++/modules/clang/support.lua b/xmake/rules/c++/modules/clang/support.lua index cb5b342ea..9447d9c97 100644 --- a/xmake/rules/c++/modules/clang/support.lua +++ b/xmake/rules/c++/modules/clang/support.lua @@ -325,18 +325,16 @@ function get_modulesflag(target) local modulestsflag = _g.modulestsflag local withoutflag = _g.withoutflag if clangmodulesflag == nil and modulestsflag == nil then + local compinst = target:compiler("cxx") + if compinst:has_flags("-fmodules", "cxxflags", {flagskey = "clang_modules"}) then + clangmodulesflag = "-fmodules" + end + if compinst:has_flags("-fmodules-ts", "cxxflags", {flagskey = "clang_modules_ts"}) then + modulestsflag = "-fmodules-ts" + end local clang_version = get_clang_version(target) withoutflag = semver.compare(clang_version, "16.0") >= 0 - if not withoutflag then - local compinst = target:compiler("cxx") - if compinst:has_flags("-fmodules", "cxxflags", {flagskey = "clang_modules"}) then - clangmodulesflag = "-fmodules" - end - if compinst:has_flags("-fmodules-ts", "cxxflags", {flagskey = "clang_modules_ts"}) then - modulestsflag = "-fmodules-ts" - end - assert(modulestsflag or clangmodulesflag, "compiler(clang): does not support c++ module!") - end + assert(withoutflag or modulestsflag, "compiler(clang): does not support c++ module!") _g.clangmodulesflag = clangmodulesflag or false _g.modulestsflag = modulestsflag or false _g.withoutflag = withoutflag or false @@ -347,12 +345,9 @@ end function get_modulefileflag(target) local modulefileflag = _g.modulefileflag if modulefileflag == nil then - local clang_version = get_clang_version(target) - if semver.compare(clang_version, "16.0") >= 0 then - local compinst = target:compiler("cxx") - if compinst:has_flags("-fmodule-file=" .. os.tmpfile() .. get_bmi_extension(), "cxxflags", {flagskey = "clang_module_file"}) then - modulefileflag = "-fmodule-file=" - end + local compinst = target:compiler("cxx") + if compinst:has_flags("-fmodule-file=" .. os.tmpfile() .. get_bmi_extension(), "cxxflags", {flagskey = "clang_module_file"}) then + modulefileflag = "-fmodule-file=" end assert(modulefileflag, "compiler(clang): does not support c++ module!") _g.modulefileflag = modulefileflag or false @@ -363,12 +358,9 @@ end function get_moduleheaderflag(target) local moduleheaderflag = _g.moduleheaderflag if moduleheaderflag == nil then - local clang_version = get_clang_version(target) - if semver.compare(clang_version, "16.0") >= 0 then - local compinst = target:compiler("cxx") - if compinst:has_flags("-fmodule-header=system", "cxxflags", {flagskey = "clang_module_header"}) then - moduleheaderflag = "-fmodule-header=" - end + local compinst = target:compiler("cxx") + if compinst:has_flags("-fmodule-header=system", "cxxflags", {flagskey = "clang_module_header"}) then + moduleheaderflag = "-fmodule-header=" end _g.moduleheaderflag = moduleheaderflag or false end @@ -378,14 +370,11 @@ end function get_modulesreducedbmiflag(target) local modulesreducedbmiflag = _g.modulesreducedbmiflag if modulesreducedbmiflag == nil then - local clang_version = get_clang_version(target) - if semver.compare(clang_version, "16.0") >= 0 then - local compinst = target:compiler("cxx") - if compinst:has_flags("-fmodules-reduced-bmi", "cxxflags", {flagskey = "clang_modules_reduced_bmi"}) then - modulesreducedbmiflag = "-fmodules-reduced-bmi" - elseif compinst:has_flags("-fexperimental-modules-reduced-bmi", "cxxflags", {flagskey = "clang_modules_reduced_bmi"}) then - modulesreducedbmiflag = "-fexperimental-modules-reduced-bmi" - end + local compinst = target:compiler("cxx") + if compinst:has_flags("-fmodules-reduced-bmi", "cxxflags", {flagskey = "clang_modules_reduced_bmi"}) then + modulesreducedbmiflag = "-fmodules-reduced-bmi" + elseif compinst:has_flags("-fexperimental-modules-reduced-bmi", "cxxflags", {flagskey = "clang_modules_reduced_bmi"}) then + modulesreducedbmiflag = "-fexperimental-modules-reduced-bmi" end _g.modulesreducedbmiflag = modulesreducedbmiflag or false end @@ -422,12 +411,11 @@ end function get_moduleoutputflag(target) local moduleoutputflag = _g.moduleoutputflag if moduleoutputflag == nil then + local compinst = target:compiler("cxx") local clang_version = get_clang_version(target) - if semver.compare(clang_version, "16.0") >= 0 then - local compinst = target:compiler("cxx") - if compinst:has_flags("-fmodule-output=", "cxxflags", {flagskey = "clang_module_output", tryrun = true}) then - moduleoutputflag = "-fmodule-output=" - end + if compinst:has_flags("-fmodule-output=", "cxxflags", {flagskey = "clang_module_output", tryrun = true}) and + semver.compare(clang_version, "16.0") >= 0 then + moduleoutputflag = "-fmodule-output=" end _g.moduleoutputflag = moduleoutputflag or false end @@ -437,12 +425,9 @@ end function get_print_library_module_manifest_path_flag(target) local print_library_module_manifest_path_flag = _g.print_library_module_manifest_path_flag if print_library_module_manifest_path_flag == nil then - local clang_version = get_clang_version(target) - if semver.compare(clang_version, "16.0") >= 0 then - local compinst = target:compiler("cxx") - if compinst:has_flags("-print-library-module-manifest-path", "cxxflags", {flagskey = "clang_print_library_module_manifest_path", tryrun = true}) then - print_library_module_manifest_path_flag = "-print-library-module-manifest-path" - end + local compinst = target:compiler("cxx") + if compinst:has_flags("-print-library-module-manifest-path", "cxxflags", {flagskey = "clang_print_library_module_manifest_path", tryrun = true}) then + print_library_module_manifest_path_flag = "-print-library-module-manifest-path" end _g.print_library_module_manifest_path_flag = print_library_module_manifest_path_flag or false end -- cgit v1.3.1 From fd0512ecccfc30a82356747e106ed98db45ae0cf Mon Sep 17 00:00:00 2001 From: ruki Date: Fri, 26 Dec 2025 22:34:13 +0800 Subject: disable c++23preview for clang-cl --- xmake/modules/core/tools/cl.lua | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/xmake/modules/core/tools/cl.lua b/xmake/modules/core/tools/cl.lua index 240189e4c..e5f8f7eaf 100644 --- a/xmake/modules/core/tools/cl.lua +++ b/xmake/modules/core/tools/cl.lua @@ -267,6 +267,13 @@ function nf_language(self, stdname) -- the stdc++ maps if _g.cxxmaps == nil then + -- clang-cl with c++23preview does not work for c++ modules + -- https://github.com/xmake-io/xmake/issues/7169 + local cxx23 = {"-std:c++23", "-std:c++23preview", "-std:c++latest"} + if self:name() == "clang_cl" then + cxx23 = {"-std:c++23", "-std:c++latest"} + end + local cxx2b = cxx23 _g.cxxmaps = { cxx11 = "-std:c++11" @@ -281,10 +288,10 @@ function nf_language(self, stdname) , gnuxx20 = {"-std:c++20", "-std:c++latest"} , cxx2a = {"-std:c++20", "-std:c++latest"} , gnuxx2a = {"-std:c++20", "-std:c++latest"} - , cxx23 = {"-std:c++23", "-std:c++23preview", "-std:c++latest"} - , gnuxx23 = {"-std:c++23", "-std:c++23preview", "-std:c++latest"} - , cxx2b = {"-std:c++23", "-std:c++23preview", "-std:c++latest"} - , gnuxx2b = {"-std:c++23", "-std:c++23preview", "-std:c++latest"} + , cxx23 = cxx23 + , gnuxx23 = cxx23 + , cxx2b = cxx2b + , gnuxx2b = cxx2b , cxx26 = {"-std:c++26", "-std:c++latest"} , gnuxx26 = {"-std:c++26", "-std:c++latest"} , cxxlatest = "-std:c++latest" -- cgit v1.3.1