summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2023-01-12 08:36:43 +0800
committerGitHub <[email protected]>2023-01-12 08:36:43 +0800
commit4a911fb47f4fd12cefbc4580d5ddceb9f65b9a81 (patch)
tree738e993d5055ec7e701e31631dd5818510f8f95a
parent15733580777f5a1c0a15da835a27d2c832539c93 (diff)
parent9793894c1d2e055a4cfe044002bea4c7e6bb075d (diff)
Merge pull request #3255 from Arthapz/improve-clang-modules-support-with-libc++
improve clang libc++ module support
-rw-r--r--tests/projects/c++/modules/class/xmake.lua4
-rw-r--r--tests/projects/c++/modules/cpp_with_moduledeps/xmake.lua3
-rw-r--r--tests/projects/c++/modules/dependence/xmake.lua3
-rw-r--r--tests/projects/c++/modules/dependence2/xmake.lua4
-rw-r--r--tests/projects/c++/modules/headerunits_person/xmake.lua5
-rw-r--r--tests/projects/c++/modules/hello with spaces/xmake.lua3
-rw-r--r--tests/projects/c++/modules/hello/xmake.lua1
-rw-r--r--tests/projects/c++/modules/ifdef_module/xmake.lua1
-rw-r--r--tests/projects/c++/modules/impl_unit/xmake.lua2
-rw-r--r--tests/projects/c++/modules/inline_and_template/xmake.lua3
-rw-r--r--tests/projects/c++/modules/internal_partition/xmake.lua1
-rw-r--r--tests/projects/c++/modules/partitions/test.lua2
-rw-r--r--tests/projects/c++/modules/partitions/xmake.lua6
-rw-r--r--tests/projects/c++/modules/partitions2/test.lua2
-rw-r--r--tests/projects/c++/modules/partitions2/xmake.lua4
-rw-r--r--tests/projects/c++/modules/private_module/xmake.lua1
-rw-r--r--tests/projects/c++/modules/staticlib/xmake.lua3
-rw-r--r--tests/projects/c++/modules/stdmodules/test.lua2
-rw-r--r--tests/projects/c++/modules/stdmodules/xmake.lua9
-rw-r--r--tests/projects/c++/modules/stdmodules_multiple_targets/test.lua2
-rw-r--r--tests/projects/c++/modules/stdmodules_multiple_targets/xmake.lua7
-rw-r--r--tests/projects/c++/modules/stl_headerunit/xmake.lua3
-rw-r--r--tests/projects/c++/modules/stl_headerunit_cpp_only/xmake.lua74
-rw-r--r--tests/projects/c++/modules/submodules/xmake.lua4
-rw-r--r--tests/projects/c++/modules/submodules2/xmake.lua4
-rw-r--r--tests/projects/c++/modules/test_base.lua5
-rw-r--r--tests/projects/c++/modules/test_headerunits.lua15
-rw-r--r--tests/projects/c++/modules/test_stdmodules.lua (renamed from tests/projects/c++/modules/test_msvc.lua)17
-rw-r--r--tests/projects/c++/modules/user_headerunit/xmake.lua2
-rw-r--r--xmake/core/project/policy.lua2
-rw-r--r--xmake/rules/c++/modules/modules_support/clang.lua105
31 files changed, 180 insertions, 119 deletions
diff --git a/tests/projects/c++/modules/class/xmake.lua b/tests/projects/c++/modules/class/xmake.lua
index 6d6eaddee..42da78369 100644
--- a/tests/projects/c++/modules/class/xmake.lua
+++ b/tests/projects/c++/modules/class/xmake.lua
@@ -1,4 +1,8 @@
+add_rules("mode.release", "mode.debug")
set_languages("c++20")
+
target("class")
set_kind("binary")
add_files("src/*.cpp", "src/*.mpp")
+
+
diff --git a/tests/projects/c++/modules/cpp_with_moduledeps/xmake.lua b/tests/projects/c++/modules/cpp_with_moduledeps/xmake.lua
index 5c7a8a6f7..6a9b3538f 100644
--- a/tests/projects/c++/modules/cpp_with_moduledeps/xmake.lua
+++ b/tests/projects/c++/modules/cpp_with_moduledeps/xmake.lua
@@ -1,10 +1,11 @@
+add_rules("mode.release", "mode.debug")
set_languages("c++20")
target("mod")
set_kind("static")
add_files("src/mod.mpp", "src/mod.cpp")
-target("main")
+target("cpp_with_moduledeps")
set_kind("binary")
add_deps("mod")
add_files("src/main.cpp")
diff --git a/tests/projects/c++/modules/dependence/xmake.lua b/tests/projects/c++/modules/dependence/xmake.lua
index 6d64b49b1..4d035c42b 100644
--- a/tests/projects/c++/modules/dependence/xmake.lua
+++ b/tests/projects/c++/modules/dependence/xmake.lua
@@ -1,4 +1,7 @@
+add_rules("mode.release", "mode.debug")
set_languages("c++20")
+
target("dependence")
set_kind("binary")
add_files("src/*.cpp", "src/*.mpp")
+
diff --git a/tests/projects/c++/modules/dependence2/xmake.lua b/tests/projects/c++/modules/dependence2/xmake.lua
index 6d64b49b1..4f2905fe9 100644
--- a/tests/projects/c++/modules/dependence2/xmake.lua
+++ b/tests/projects/c++/modules/dependence2/xmake.lua
@@ -1,4 +1,6 @@
+add_rules("mode.release", "mode.debug")
set_languages("c++20")
-target("dependence")
+
+target("dependence2")
set_kind("binary")
add_files("src/*.cpp", "src/*.mpp")
diff --git a/tests/projects/c++/modules/headerunits_person/xmake.lua b/tests/projects/c++/modules/headerunits_person/xmake.lua
index c9290833b..d11b49824 100644
--- a/tests/projects/c++/modules/headerunits_person/xmake.lua
+++ b/tests/projects/c++/modules/headerunits_person/xmake.lua
@@ -1,4 +1,7 @@
+add_rules("mode.release", "mode.debug")
set_languages("c++20")
-target("hello")
+
+target("headerunits_person")
set_kind("binary")
add_files("src/*.cpp", "src/*.mpp")
+
diff --git a/tests/projects/c++/modules/hello with spaces/xmake.lua b/tests/projects/c++/modules/hello with spaces/xmake.lua
index 4f46b699d..4369a892f 100644
--- a/tests/projects/c++/modules/hello with spaces/xmake.lua
+++ b/tests/projects/c++/modules/hello with spaces/xmake.lua
@@ -1,5 +1,6 @@
add_rules("mode.release", "mode.debug")
set_languages("c++20")
-target("A hello")
+
+target("hello with spaces")
set_kind("binary")
add_files("src/*.cpp", "src/*.mpp")
diff --git a/tests/projects/c++/modules/hello/xmake.lua b/tests/projects/c++/modules/hello/xmake.lua
index de13fc409..4f6fdab98 100644
--- a/tests/projects/c++/modules/hello/xmake.lua
+++ b/tests/projects/c++/modules/hello/xmake.lua
@@ -1,5 +1,6 @@
add_rules("mode.release", "mode.debug")
set_languages("c++20")
+
target("hello")
set_kind("binary")
add_files("src/*.cpp", "src/*.mpp")
diff --git a/tests/projects/c++/modules/ifdef_module/xmake.lua b/tests/projects/c++/modules/ifdef_module/xmake.lua
index ee931a801..25933a35f 100644
--- a/tests/projects/c++/modules/ifdef_module/xmake.lua
+++ b/tests/projects/c++/modules/ifdef_module/xmake.lua
@@ -1,5 +1,6 @@
add_rules("mode.release", "mode.debug")
set_languages("c++20")
+
target("ifdef_module")
set_kind("binary")
add_files("src/*.cpp")
diff --git a/tests/projects/c++/modules/impl_unit/xmake.lua b/tests/projects/c++/modules/impl_unit/xmake.lua
index abe41d20a..991f2a895 100644
--- a/tests/projects/c++/modules/impl_unit/xmake.lua
+++ b/tests/projects/c++/modules/impl_unit/xmake.lua
@@ -1,4 +1,6 @@
+add_rules("mode.release", "mode.debug")
set_languages("c++20")
+
target("impl_unit")
set_kind("binary")
add_files("src/*.cpp", "src/*.mpp")
diff --git a/tests/projects/c++/modules/inline_and_template/xmake.lua b/tests/projects/c++/modules/inline_and_template/xmake.lua
index 4810edb85..8c981fae9 100644
--- a/tests/projects/c++/modules/inline_and_template/xmake.lua
+++ b/tests/projects/c++/modules/inline_and_template/xmake.lua
@@ -1,4 +1,7 @@
+add_rules("mode.release", "mode.debug")
set_languages("c++20")
+
target("inline_and_template")
set_kind("binary")
add_files("src/*.cpp", "src/*.mpp")
+
diff --git a/tests/projects/c++/modules/internal_partition/xmake.lua b/tests/projects/c++/modules/internal_partition/xmake.lua
index f7ca6f7cf..422292295 100644
--- a/tests/projects/c++/modules/internal_partition/xmake.lua
+++ b/tests/projects/c++/modules/internal_partition/xmake.lua
@@ -1,5 +1,6 @@
add_rules("mode.release", "mode.debug")
set_languages("c++20")
+
target("internal_partition")
set_kind("binary")
add_files("src/*.cpp", "src/hello.mpp")
diff --git a/tests/projects/c++/modules/partitions/test.lua b/tests/projects/c++/modules/partitions/test.lua
index c18e5a1d0..e77adc4ae 100644
--- a/tests/projects/c++/modules/partitions/test.lua
+++ b/tests/projects/c++/modules/partitions/test.lua
@@ -1 +1 @@
-inherit(".test_headerunits")
+inherit(".test_stdmodules")
diff --git a/tests/projects/c++/modules/partitions/xmake.lua b/tests/projects/c++/modules/partitions/xmake.lua
index 672034947..4b575432a 100644
--- a/tests/projects/c++/modules/partitions/xmake.lua
+++ b/tests/projects/c++/modules/partitions/xmake.lua
@@ -1,4 +1,6 @@
+add_rules("mode.release", "mode.debug")
set_languages("c++20")
-target("math")
+
+target("partition")
set_kind("binary")
- add_files("src/*.cpp", "src/*.mpp")
+ add_files("src/*.cpp", "src/*.mpp") \ No newline at end of file
diff --git a/tests/projects/c++/modules/partitions2/test.lua b/tests/projects/c++/modules/partitions2/test.lua
index c18e5a1d0..e77adc4ae 100644
--- a/tests/projects/c++/modules/partitions2/test.lua
+++ b/tests/projects/c++/modules/partitions2/test.lua
@@ -1 +1 @@
-inherit(".test_headerunits")
+inherit(".test_stdmodules")
diff --git a/tests/projects/c++/modules/partitions2/xmake.lua b/tests/projects/c++/modules/partitions2/xmake.lua
index c9290833b..9e0ab37bb 100644
--- a/tests/projects/c++/modules/partitions2/xmake.lua
+++ b/tests/projects/c++/modules/partitions2/xmake.lua
@@ -1,4 +1,6 @@
+add_rules("mode.release", "mode.debug")
set_languages("c++20")
-target("hello")
+
+target("partition2")
set_kind("binary")
add_files("src/*.cpp", "src/*.mpp")
diff --git a/tests/projects/c++/modules/private_module/xmake.lua b/tests/projects/c++/modules/private_module/xmake.lua
index 1930f1188..57ede6993 100644
--- a/tests/projects/c++/modules/private_module/xmake.lua
+++ b/tests/projects/c++/modules/private_module/xmake.lua
@@ -1,5 +1,6 @@
add_rules("mode.release", "mode.debug")
set_languages("c++20")
+
target("private_module")
add_rules("c++")
set_kind("$(kind)")
diff --git a/tests/projects/c++/modules/staticlib/xmake.lua b/tests/projects/c++/modules/staticlib/xmake.lua
index 93045c18f..5a3a9f4c6 100644
--- a/tests/projects/c++/modules/staticlib/xmake.lua
+++ b/tests/projects/c++/modules/staticlib/xmake.lua
@@ -1,10 +1,11 @@
+add_rules("mode.release", "mode.debug")
set_languages("c++20")
target("mod")
set_kind("static")
add_files("src/mod.mpp", "src/mod.cpp")
-target("test")
+target("staticlib")
set_kind("binary")
add_deps("mod")
add_files("src/main.cpp")
diff --git a/tests/projects/c++/modules/stdmodules/test.lua b/tests/projects/c++/modules/stdmodules/test.lua
index 0657ead56..e77adc4ae 100644
--- a/tests/projects/c++/modules/stdmodules/test.lua
+++ b/tests/projects/c++/modules/stdmodules/test.lua
@@ -1 +1 @@
-inherit(".test_msvc")
+inherit(".test_stdmodules")
diff --git a/tests/projects/c++/modules/stdmodules/xmake.lua b/tests/projects/c++/modules/stdmodules/xmake.lua
index 85e738d14..5cf4ccb9d 100644
--- a/tests/projects/c++/modules/stdmodules/xmake.lua
+++ b/tests/projects/c++/modules/stdmodules/xmake.lua
@@ -1,14 +1,15 @@
add_rules("mode.debug", "mode.release")
-
-add_cxxflags("clang::-stdlib=libc++")
-
set_languages("c++latest")
target("mod")
set_kind("static")
add_files("src/*.cpp", "src/*.mpp")
-target("test")
+ set_policy("build.c++.clang.stdmodules", true)
+
+target("stdmodules")
set_kind("binary")
add_files("test/*.cpp")
add_deps("mod")
+
+ set_policy("build.c++.clang.stdmodules", true)
diff --git a/tests/projects/c++/modules/stdmodules_multiple_targets/test.lua b/tests/projects/c++/modules/stdmodules_multiple_targets/test.lua
index 0657ead56..e77adc4ae 100644
--- a/tests/projects/c++/modules/stdmodules_multiple_targets/test.lua
+++ b/tests/projects/c++/modules/stdmodules_multiple_targets/test.lua
@@ -1 +1 @@
-inherit(".test_msvc")
+inherit(".test_stdmodules")
diff --git a/tests/projects/c++/modules/stdmodules_multiple_targets/xmake.lua b/tests/projects/c++/modules/stdmodules_multiple_targets/xmake.lua
index 859dddc7c..32bed613b 100644
--- a/tests/projects/c++/modules/stdmodules_multiple_targets/xmake.lua
+++ b/tests/projects/c++/modules/stdmodules_multiple_targets/xmake.lua
@@ -1,13 +1,14 @@
add_rules("mode.debug", "mode.release")
-
-add_cxxflags("clang::-stdlib=libc++")
-
set_languages("c++latest")
target("mod")
set_kind("static")
add_files("src/*.cpp", "src/*.mpp")
+ set_policy("build.c++.clang.stdmodules", true)
+
target("mod2")
set_kind("static")
add_files("src/*.cpp", "src/*.mpp")
+
+ set_policy("build.c++.clang.stdmodules", true)
diff --git a/tests/projects/c++/modules/stl_headerunit/xmake.lua b/tests/projects/c++/modules/stl_headerunit/xmake.lua
index e85378c46..55d55a5fd 100644
--- a/tests/projects/c++/modules/stl_headerunit/xmake.lua
+++ b/tests/projects/c++/modules/stl_headerunit/xmake.lua
@@ -1,4 +1,7 @@
+add_rules("mode.release", "mode.debug")
set_languages("c++20")
+
target("stl_headerunit")
set_kind("binary")
add_files("src/*.cpp", "src/*.mpp")
+
diff --git a/tests/projects/c++/modules/stl_headerunit_cpp_only/xmake.lua b/tests/projects/c++/modules/stl_headerunit_cpp_only/xmake.lua
index 101a95fe7..97a260e1e 100644
--- a/tests/projects/c++/modules/stl_headerunit_cpp_only/xmake.lua
+++ b/tests/projects/c++/modules/stl_headerunit_cpp_only/xmake.lua
@@ -1,76 +1,8 @@
-add_rules("mode.debug", "mode.release")
+add_rules("mode.release", "mode.debug")
+set_languages("c++20")
-target("test")
+target("stl_headerunit_cpp_only")
set_kind("binary")
add_files("src/*.cpp")
- set_languages("c++20")
set_policy("build.c++.modules", true)
---
--- If you want to known more usage about xmake, please see https://xmake.io
---
--- ## FAQ
---
--- You can enter the project directory firstly before building project.
---
--- $ cd projectdir
---
--- 1. How to build project?
---
--- $ xmake
---
--- 2. How to configure project?
---
--- $ xmake f -p [macosx|linux|iphoneos ..] -a [x86_64|i386|arm64 ..] -m [debug|release]
---
--- 3. Where is the build output directory?
---
--- The default output directory is `./build` and you can configure the output directory.
---
--- $ xmake f -o outputdir
--- $ xmake
---
--- 4. How to run and debug target after building project?
---
--- $ xmake run [targetname]
--- $ xmake run -d [targetname]
---
--- 5. How to install target to the system directory or other output directory?
---
--- $ xmake install
--- $ xmake install -o installdir
---
--- 6. Add some frequently-used compilation flags in xmake.lua
---
--- @code
--- -- add debug and release modes
--- add_rules("mode.debug", "mode.release")
---
--- -- add macro defination
--- add_defines("NDEBUG", "_GNU_SOURCE=1")
---
--- -- set warning all as error
--- set_warnings("all", "error")
---
--- -- set language: c99, c++11
--- set_languages("c99", "c++11")
---
--- -- set optimization: none, faster, fastest, smallest
--- set_optimize("fastest")
---
--- -- add include search directories
--- add_includedirs("/usr/include", "/usr/local/include")
---
--- -- add link libraries and search directories
--- add_links("tbox")
--- add_linkdirs("/usr/local/lib", "/usr/lib")
---
--- -- add system link libraries
--- add_syslinks("z", "pthread")
---
--- -- add compilation and link flags
--- add_cxflags("-stdnolib", "-fno-strict-aliasing")
--- add_ldflags("-L/usr/local/lib", "-lpthread", {force = true})
---
--- @endcode
---
diff --git a/tests/projects/c++/modules/submodules/xmake.lua b/tests/projects/c++/modules/submodules/xmake.lua
index 672034947..e84b63a9f 100644
--- a/tests/projects/c++/modules/submodules/xmake.lua
+++ b/tests/projects/c++/modules/submodules/xmake.lua
@@ -1,4 +1,6 @@
+add_rules("mode.release", "mode.debug")
set_languages("c++20")
-target("math")
+
+target("submodule")
set_kind("binary")
add_files("src/*.cpp", "src/*.mpp")
diff --git a/tests/projects/c++/modules/submodules2/xmake.lua b/tests/projects/c++/modules/submodules2/xmake.lua
index 672034947..9dc2ee320 100644
--- a/tests/projects/c++/modules/submodules2/xmake.lua
+++ b/tests/projects/c++/modules/submodules2/xmake.lua
@@ -1,4 +1,6 @@
+add_rules("mode.release", "mode.debug")
set_languages("c++20")
-target("math")
+
+target("submodules2")
set_kind("binary")
add_files("src/*.cpp", "src/*.mpp")
diff --git a/tests/projects/c++/modules/test_base.lua b/tests/projects/c++/modules/test_base.lua
index 4aee9f8e7..efef15520 100644
--- a/tests/projects/c++/modules/test_base.lua
+++ b/tests/projects/c++/modules/test_base.lua
@@ -16,7 +16,7 @@ function main(t)
_build()
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
@@ -25,6 +25,9 @@ function main(t)
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()
end
end
end
diff --git a/tests/projects/c++/modules/test_headerunits.lua b/tests/projects/c++/modules/test_headerunits.lua
index 78c999497..6a942e583 100644
--- a/tests/projects/c++/modules/test_headerunits.lua
+++ b/tests/projects/c++/modules/test_headerunits.lua
@@ -25,10 +25,17 @@ function main(t)
_build()
end
local clang = find_tool("clang", {version = true})
- if clang and clang.version and semver.compare(clang.version, "16.0") >= 0 then
- os.exec("xmake clean -a")
- os.exec("xmake f --toolchain=clang -c --yes")
- _build()
+ if clang and clang.version then
+ if semver.compare(clang.version, "15.0") >= 0 then
+ os.exec("xmake clean -a")
+ os.exec("xmake f --toolchain=clang -c")
+ _build()
+ -- elseif semver.compare(clang.version, "15.0") >= 0 then
+ -- there is currently a bug on llvm git that prevent to build STL header units https://github.com/llvm/llvm-project/issues/58540
+ -- os.exec("xmake clean -a")
+ -- os.exec("xmake f --toolchain=clang --cxxflags=\"-stdlib=libc++\" -c")
+ -- _build()
+ end
end
end
end
diff --git a/tests/projects/c++/modules/test_msvc.lua b/tests/projects/c++/modules/test_stdmodules.lua
index a436b5814..360a56cbc 100644
--- a/tests/projects/c++/modules/test_msvc.lua
+++ b/tests/projects/c++/modules/test_stdmodules.lua
@@ -24,5 +24,22 @@ function main(t)
end
end
end
+ 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
+ -- 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
+ -- 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()
+ end
end
end
diff --git a/tests/projects/c++/modules/user_headerunit/xmake.lua b/tests/projects/c++/modules/user_headerunit/xmake.lua
index dae91d11f..e305044b5 100644
--- a/tests/projects/c++/modules/user_headerunit/xmake.lua
+++ b/tests/projects/c++/modules/user_headerunit/xmake.lua
@@ -1,4 +1,6 @@
+add_rules("mode.release", "mode.debug")
set_languages("c++20")
+
target("user_headerunit")
set_kind("binary")
add_headerfiles("src/*.hpp")
diff --git a/xmake/core/project/policy.lua b/xmake/core/project/policy.lua
index 8148a37e2..4c9f87cd1 100644
--- a/xmake/core/project/policy.lua
+++ b/xmake/core/project/policy.lua
@@ -53,6 +53,8 @@ function policy.policies()
["build.optimization.lto"] = {description = "Enable LTO linker-time optimization 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"},
-- preprocessor configuration for ccache/distcc, we can disable linemarkers to speed up preprocess
["preprocessor.linemarkers"] = {description = "Enable linemarkers for preprocessor.", default = true, type = "boolean"},
-- preprocessor configuration for ccache/distcc, we can disable it to avoid cache object file with __DATE__, __TIME__
diff --git a/xmake/rules/c++/modules/modules_support/clang.lua b/xmake/rules/c++/modules/modules_support/clang.lua
index 0f159ae57..4d1f07747 100644
--- a/xmake/rules/c++/modules/modules_support/clang.lua
+++ b/xmake/rules/c++/modules/modules_support/clang.lua
@@ -65,16 +65,31 @@ function _get_modulemap_from_mapper(target, name)
return common.localcache():get2(_mapper_cachekey(target), "modulemap" .. name) or nil
end
+-- enable libc++
+function _enable_libcxx(target)
+ target:add("cxxflags", "-stdlib=libc++")
+ target:add("syslinks", "c++")
+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)
- target:add("cxxflags", builtinmodulemapflag, {force = true})
- target:add("cxxflags", implicitmodulesflag, {force = true})
+ if not modulesflag or target:is_plat("macosx") then
+ target:add("cxxflags", modulestsflag)
+ end
+
+ if target:policy("build.c++.clang.stdmodules") then
+ target:add("cxxflags", builtinmodulemapflag, {force = true})
+ target:add("cxxflags", implicitmodulesflag, {force = true})
+ else
+ target:add("cxxflags", noimplicitmodulemapsflag, {force = true})
+ 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.
@@ -98,9 +113,10 @@ function load(target)
-- on ubuntu:
-- sudo apt install libc++-dev libc++abi-15-dev
--
- target:data_set("cxx.modules.use_libc++", table.contains(target:get("cxxflags"), "-stdlib=libc++", "clang::-stdlib=libc++"))
+ local flags = table.join(target:get("cxxflags"), get_config("cxxflags") or {})
+ target:data_set("cxx.modules.use_libc++", table.contains(flags, "-stdlib=libc++", "clang::-stdlib=libc++"))
if target:data("cxx.modules.use_libc++") then
- target:add("syslinks", "c++")
+ _enable_libcxx(target)
end
end
@@ -118,7 +134,7 @@ function _get_toolchain_includedirs_for_stlheaders(target, includedirs, clang)
if target:data("cxx.modules.use_libc++") then
table.insert(argv, 1, "-stdlib=libc++")
end
- local result = try {function () return os.iorunv(clang, {"-E", "-x", "c++", tmpfile}) end}
+ local result = try {function () return os.iorunv(clang, argv) end}
if result then
for _, line in ipairs(result:split("\n", {plain = true})) do
line = line:trim()
@@ -169,7 +185,7 @@ function _build_modulefile(target, sourcefile, opt)
local bmiflags
if opt.provide then
bmifile = opt.provide.bmifile
- bmiflags = table.join("-x", "c++-module", "--precompile", compflags, common_args, requiresflags or {})
+ bmiflags = table.join("-x", "c++-module", "--precompile", compflags, common_args, requiresflags)
vprint(compinst:compcmd(sourcefile, bmifile, {compflags = bmiflags, rawargs = true}))
end
@@ -200,7 +216,7 @@ function toolchain_includedirs(target)
local clang, toolname = target:tool("cxx")
assert(toolname == "clang")
_get_toolchain_includedirs_for_stlheaders(target, includedirs, clang)
- local _, result = try {function () return os.iorunv(clang, {"-E", "-Wp,-v", "-xc", os.nuldev()}) end}
+ local _, result = try {function () return os.iorunv(clang, {"-E", "-stdlib=libc++", "-Wp,-v", "-xc", os.nuldev()}) end}
if result then
for _, line in ipairs(result:split("\n", {plain = true})) do
line = line:trim()
@@ -264,8 +280,39 @@ function generate_dependencies(target, sourcebatch, opt)
end)
changed = true
- local dependinfo = io.readfile(jsonfile)
- return {moduleinfo = dependinfo}
+ local rawdependinfo = io.readfile(jsonfile)
+ if rawdependinfo then
+ local dependinfo = json.decode(rawdependinfo)
+ if not target:data("cxx.modules.use_libc++") then
+ local has_std_modules = false
+ for _, r in ipairs(dependinfo.rules) do
+ for _, required in ipairs(r.requires) do
+ if required["logical-name"] == "std" or required["logical-name"] == "std.compat" then
+ has_std_modules = true
+ break
+ end
+ end
+
+ if has_std_modules then
+ break
+ end
+ end
+
+ assert(not (has_std_modules and not target:policy("build.c++.clang.stdmodules")),
+ [[On llvm <= 16 standard C++ modules are not supported ;
+ they can be emulated through clang modules and supported only on libc++ ;
+ please add -stdlib=libc++ cxx flag or disable strict mode]])
+
+ if has_std_modules then
+ target:data_set("cxx.modules.use_libc++", true)
+ if target:data("cxx.modules.use_libc++") then
+ _enable_libcxx(target)
+ end
+ end
+ end
+ end
+
+ return {moduleinfo = rawdependinfo}
end, {dependfile = dependfile, files = {sourcefile}})
end
return changed
@@ -293,7 +340,7 @@ function generate_stl_headerunits_for_batchjobs(target, batchjobs, headerunits,
if not common.memcache():get2(headerunit.name, "building") then
common.memcache():set2(headerunit.name, "building", true)
progress.show((index * 100) / total, "${color.build.object}compiling.headerunit.$(mode) %s", headerunit.name)
- local args = {modulecachepathflag .. stlcachedir, "-c", "-o", bmifile, "-x", "c++-system-header", headerunit.name}
+ local args = {modulecachepathflag .. stlcachedir, "-c", "-Wno-everything", "-o", bmifile, "-x", "c++-system-header", headerunit.name}
os.vrunv(compinst:program(), table.join(compinst:compflags({target = target}), args))
end
@@ -618,20 +665,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)
@@ -664,6 +711,19 @@ function get_implicitmodulesflag(target)
return implicitmodulesflag or nil
end
+function get_implicitmodulemapsflag(target)
+ local implicitmodulemapsflag = _g.implicitmodulemapsflag
+ if implicitmodulemapsflag == nil then
+ local compinst = target:compiler("cxx")
+ if compinst:has_flags("-fimplicit-module-maps", "cxxflags", {flagskey = "clang_implicit_module_map"}) then
+ implicitmodulemapsflag = "-fimplicit-module-maps"
+ end
+ assert(implicitmodulemapsflag, "compiler(clang): does not support c++ module!")
+ _g.implicitmodulemapsflag = implicitmodulemapsflag or false
+ end
+ return implicitmodulemapsflag or nil
+end
+
function get_noimplicitmodulemapsflag(target)
local noimplicitmodulemapsflag = _g.noimplicitmodulemapsflag
if noimplicitmodulemapsflag == nil then
@@ -720,8 +780,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
@@ -745,7 +806,7 @@ function get_requiresflags(target, requires)
already_mapped_modules[name] = true
table.insert(flags, modulemap_.flag)
if modulemap_.deps then
- table.shallow_join2(flags, modulemap_.deps)
+ table.join2(flags, modulemap_.deps)
end
goto continue
end
@@ -757,7 +818,7 @@ function get_requiresflags(target, requires)
already_mapped_modules[name] = true
table.insert(flags, modulemap.flag)
if modulemap.deps then
- table.shallow_join2(flags, modulemap.deps)
+ table.join2(flags, modulemap.deps)
end
goto continue
end