From 3755a6f67399b8e42df9f39ec7c506918dbb433a Mon Sep 17 00:00:00 2001 From: Arthur LAURENT Date: Sat, 7 Jan 2023 17:44:36 +0100 Subject: reenable old clang modules by default and fix tests --- tests/projects/c++/modules/test_stdmodules.lua | 47 ++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 tests/projects/c++/modules/test_stdmodules.lua (limited to 'tests/projects/c++/modules/test_stdmodules.lua') diff --git a/tests/projects/c++/modules/test_stdmodules.lua b/tests/projects/c++/modules/test_stdmodules.lua new file mode 100644 index 000000000..2d8861d09 --- /dev/null +++ b/tests/projects/c++/modules/test_stdmodules.lua @@ -0,0 +1,47 @@ +import("lib.detect.find_tool") +import("core.base.semver") +import("core.tool.toolchain") + +function _build() + local ci = (os.getenv("CI") or os.getenv("GITHUB_ACTIONS") or ""):lower() + if ci == "true" then + os.exec("xmake -rvD") + else + os.exec("xmake -r") + end +end + +function main(t) + if is_subhost("windows") then + local msvc = toolchain.load("msvc") + if msvc and msvc:check() then + local vcvars = msvc:config("vcvars") + if vcvars and vcvars.VCInstallDir and vcvars.VCToolsVersion and semver.compare(vcvars.VCToolsVersion, "14.35") then + local stdmodulesdir = path.join(vcvars.VCInstallDir, "Tools", "MSVC", vcvars.VCToolsVersion, "modules") + if os.isdir(stdmodulesdir) then + os.exec("xmake f -c") + _build() + end + end + end + elseif is_host("linux") or is_host("macos") then + -- gcc don't support std modules atm + -- local gcc = find_tool("gcc", {version = true}) + -- if gcc and gcc.version and semver.compare(gcc.version, "11.0") >= 0 then + -- os.exec("xmake f -c") + -- _build() + -- end + local clang = find_tool("clang", {version = true}) + if clang and clang.version and semver.compare(clang.version, "14.0") >= 0 then + if is_host("linux") then + -- clang don't support libstdc++ std modules atm + -- os.exec("xmake clean -a") + -- os.exec("xmake f --toolchain=clang -c") + -- _build() + end + os.exec("xmake clean -a") + os.exec("xmake f --toolchain=clang --cxxflags=\"-stdlib=libc++\" -c") + _build() + end + end +end -- cgit v1.3.1 From d20bf041ae327176e2105ceca24b0089798477a1 Mon Sep 17 00:00:00 2001 From: Arthur LAURENT Date: Sat, 7 Jan 2023 19:18:18 +0100 Subject: fix on macos fix on macos --- tests/projects/c++/modules/test_base.lua | 12 +++++------- tests/projects/c++/modules/test_stdmodules.lua | 14 ++++++------- xmake/rules/c++/modules/modules_support/clang.lua | 24 +++++++++++++---------- 3 files changed, 25 insertions(+), 25 deletions(-) (limited to 'tests/projects/c++/modules/test_stdmodules.lua') diff --git a/tests/projects/c++/modules/test_base.lua b/tests/projects/c++/modules/test_base.lua index 6ac816d66..efef15520 100644 --- a/tests/projects/c++/modules/test_base.lua +++ b/tests/projects/c++/modules/test_base.lua @@ -14,19 +14,17 @@ function main(t) if is_subhost("windows") then os.exec("xmake f -c") _build() - elseif is_host("linux") or is_host("macos") then + elseif is_host("linux") then local gcc = find_tool("gcc", {version = true}) - if gcc and gcc.version and semver.compare(gcc.version, "11.0") >= 0 then + if is_host("linux") and gcc and gcc.version and semver.compare(gcc.version, "11.0") >= 0 then os.exec("xmake f -c") _build() end local clang = find_tool("clang", {version = true}) if clang and clang.version and semver.compare(clang.version, "14.0") >= 0 then - if is_host("linux") then - os.exec("xmake clean -a") - os.exec("xmake f --toolchain=clang -c") - _build() - end + os.exec("xmake clean -a") + os.exec("xmake f --toolchain=clang -c") + _build() os.exec("xmake clean -a") os.exec("xmake f --toolchain=clang --cxxflags=\"-stdlib=libc++\" -c") _build() diff --git a/tests/projects/c++/modules/test_stdmodules.lua b/tests/projects/c++/modules/test_stdmodules.lua index 2d8861d09..621f0b1d4 100644 --- a/tests/projects/c++/modules/test_stdmodules.lua +++ b/tests/projects/c++/modules/test_stdmodules.lua @@ -24,21 +24,19 @@ function main(t) end end end - elseif is_host("linux") or is_host("macos") then + elseif is_host("linux") then -- or is_host("macos") then -- gcc don't support std modules atm -- local gcc = find_tool("gcc", {version = true}) - -- if gcc and gcc.version and semver.compare(gcc.version, "11.0") >= 0 then + -- if is_host("linux") and gcc and gcc.version and semver.compare(gcc.version, "11.0") >= 0 then -- os.exec("xmake f -c") -- _build() -- end local clang = find_tool("clang", {version = true}) if clang and clang.version and semver.compare(clang.version, "14.0") >= 0 then - if is_host("linux") then - -- clang don't support libstdc++ std modules atm - -- os.exec("xmake clean -a") - -- os.exec("xmake f --toolchain=clang -c") - -- _build() - end + -- clang don't support libstdc++ std modules atm + -- os.exec("xmake clean -a") + -- os.exec("xmake f --toolchain=clang -c") + -- _build() os.exec("xmake clean -a") os.exec("xmake f --toolchain=clang --cxxflags=\"-stdlib=libc++\" -c") _build() diff --git a/xmake/rules/c++/modules/modules_support/clang.lua b/xmake/rules/c++/modules/modules_support/clang.lua index 7a63c027d..129221e5d 100644 --- a/xmake/rules/c++/modules/modules_support/clang.lua +++ b/xmake/rules/c++/modules/modules_support/clang.lua @@ -66,13 +66,16 @@ end -- load module support for the current target function load(target) - local modulesflag = get_modulesflag(target) + local modulesflag, modulestsflag = get_modulesflag(target) local builtinmodulemapflag = get_builtinmodulemapflag(target) local implicitmodulesflag = get_implicitmodulesflag(target) local noimplicitmodulemapsflag = get_noimplicitmodulemapsflag(target) -- add module flags target:add("cxxflags", modulesflag) + if not modulesflag or is_host("macos") then + target:add("cxxflags", modulestsflag) + end if not target:values("c++.clang.modules.strict") then target:add("cxxflags", builtinmodulemapflag, {force = true}) @@ -583,20 +586,20 @@ end function get_modulesflag(target) local modulesflag = _g.modulesflag - if modulesflag == nil then + local modulestsflag = _g.modulestsflag + if modulesflag == nil and modulestsflag == nil then local compinst = target:compiler("cxx") if compinst:has_flags("-fmodules", "cxxflags", {flagskey = "clang_modules"}) then modulesflag = "-fmodules" end - if not modulesflag then - if compinst:has_flags("-fmodules-ts", "cxxflags", {flagskey = "clang_modules_ts"}) then - modulesflag = "-fmodules-ts" - end + if compinst:has_flags("-fmodules-ts", "cxxflags", {flagskey = "clang_modules_ts"}) then + modulestsflag = "-fmodules-ts" end - assert(modulesflag, "compiler(clang): does not support c++ module!") + assert(modulesflag or modulestsflag, "compiler(clang): does not support c++ module!") _g.modulesflag = modulesflag or false + _g.modulestsflag = modulestsflag or false end - return modulesflag or nil + return modulesflag or nil, modulestsflag or nil end function get_builtinmodulemapflag(target) @@ -698,8 +701,9 @@ function has_headerunitsupport(target) local support_headerunits = _g.support_headerunits if support_headerunits == nil then local compinst = target:compiler("cxx") - if compinst:has_flags(get_modulesflag(target) .. " -std=c++20 -x c++-user-header", "cxxflags", {flagskey = "clang_user_header_unit_support", tryrun = true}) and - compinst:has_flags(get_modulesflag(target) .. " -std=c++20 -x c++-system-header", "cxxflags", {flagskey = "clang_system_header_unit_support", tryrun = true}) then + local modulesflag, modulestsflag = get_modulesflag(target) + if compinst:has_flags(modulesflag or moduletsflag .. " -std=c++20 -x c++-user-header", "cxxflags", {flagskey = "clang_user_header_unit_support", tryrun = true}) and + compinst:has_flags(modulesflag or moduletsflag .. " -std=c++20 -x c++-system-header", "cxxflags", {flagskey = "clang_system_header_unit_support", tryrun = true}) then support_headerunits = true end _g.support_headerunits = support_headerunits or false -- cgit v1.3.1 From 80f582eb5af42fa9121f6bb294d2d4952140b046 Mon Sep 17 00:00:00 2001 From: ruki Date: Sun, 8 Jan 2023 10:34:13 +0800 Subject: Update test_stdmodules.lua --- tests/projects/c++/modules/test_stdmodules.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests/projects/c++/modules/test_stdmodules.lua') diff --git a/tests/projects/c++/modules/test_stdmodules.lua b/tests/projects/c++/modules/test_stdmodules.lua index 621f0b1d4..360a56cbc 100644 --- a/tests/projects/c++/modules/test_stdmodules.lua +++ b/tests/projects/c++/modules/test_stdmodules.lua @@ -24,7 +24,7 @@ function main(t) end end end - elseif is_host("linux") then -- or is_host("macos") then + elseif is_host("linux") then -- or is_host("macosx") then -- gcc don't support std modules atm -- local gcc = find_tool("gcc", {version = true}) -- if is_host("linux") and gcc and gcc.version and semver.compare(gcc.version, "11.0") >= 0 then -- cgit v1.3.1