diff options
| author | ruki <[email protected]> | 2022-11-03 22:52:10 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2022-11-03 13:06:03 +0800 |
| commit | f2ea9f6021fcb21ad0f8fc42d3bc78a3ae7d2283 (patch) | |
| tree | 753bf9e75b590e4e66a02496051b11f3d046add9 | |
| parent | f95014b8e8c6e32471cf8bfa97988519dac25950 (diff) | |
improve clang to support std modules
7 files changed, 63 insertions, 5 deletions
diff --git a/tests/projects/c++/modules/stdmodules/.gitignore b/tests/projects/c++/modules/stdmodules/.gitignore new file mode 100644 index 000000000..152105761 --- /dev/null +++ b/tests/projects/c++/modules/stdmodules/.gitignore @@ -0,0 +1,8 @@ +# Xmake cache +.xmake/ +build/ + +# MacOS Cache +.DS_Store + + diff --git a/tests/projects/c++/modules/stdmodules/src/my_module.cpp b/tests/projects/c++/modules/stdmodules/src/my_module.cpp new file mode 100644 index 000000000..829be43e3 --- /dev/null +++ b/tests/projects/c++/modules/stdmodules/src/my_module.cpp @@ -0,0 +1,5 @@ +module my_module; + +import std; + +auto my_sum(size_t a, size_t b) -> size_t { return a + b; }
\ No newline at end of file diff --git a/tests/projects/c++/modules/stdmodules/src/my_module.mpp b/tests/projects/c++/modules/stdmodules/src/my_module.mpp new file mode 100644 index 000000000..196b33381 --- /dev/null +++ b/tests/projects/c++/modules/stdmodules/src/my_module.mpp @@ -0,0 +1,5 @@ +export module my_module; + +import std; + +export auto my_sum(size_t a, size_t b) -> size_t;
\ No newline at end of file diff --git a/tests/projects/c++/modules/stdmodules/test/test.cpp b/tests/projects/c++/modules/stdmodules/test/test.cpp new file mode 100644 index 000000000..c23ef7efa --- /dev/null +++ b/tests/projects/c++/modules/stdmodules/test/test.cpp @@ -0,0 +1,10 @@ +// Copyright 2022 Ângelo Andrade Cirino + +#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN +#include <doctest/doctest.h> + +import std; + +import my_module; + +TEST_CASE("Test sum") { CHECK(my_sum(1, 1) == 2); } diff --git a/tests/projects/c++/modules/stdmodules/xmake.lua b/tests/projects/c++/modules/stdmodules/xmake.lua new file mode 100644 index 000000000..e62141e28 --- /dev/null +++ b/tests/projects/c++/modules/stdmodules/xmake.lua @@ -0,0 +1,15 @@ +add_rules("mode.debug", "mode.release") +set_languages("c++20") + +add_requires("doctest", { alias = "doctest" }) + +add_cxxflags("-stdlib=libc++") +target("trouble") + set_kind("shared") + add_files("src/*.cpp", "src/*.mpp") + +target("test") + set_kind("binary") + add_files("test/*.cpp") + add_deps("trouble") + add_packages("doctest") diff --git a/tests/projects/c++/modules/stdmodules/xonga.cpp b/tests/projects/c++/modules/stdmodules/xonga.cpp new file mode 100644 index 000000000..bb6a32b1b --- /dev/null +++ b/tests/projects/c++/modules/stdmodules/xonga.cpp @@ -0,0 +1,2 @@ +#include <version> + diff --git a/xmake/rules/c++/modules/modules_support/clang.lua b/xmake/rules/c++/modules/modules_support/clang.lua index 100830046..e0a7b0228 100644 --- a/xmake/rules/c++/modules/modules_support/clang.lua +++ b/xmake/rules/c++/modules/modules_support/clang.lua @@ -66,21 +66,30 @@ end -- load module support for the current target function load(target) - -- get module and module cache flags local modulesflag = 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) - - -- add the module cache directory target:add("cxxflags", builtinmodulemapflag, {force = true}) target:add("cxxflags", implicitmodulesflag, {force = true}) - target:add("cxxflags", noimplicitmodulemapsflag, {force = true}) + -- TODO 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. + -- + -- it will happen in binary target depend ont shared target with modules, and enable release mode at same time. + target:set("symbols", "none") + + -- if use libc++, we need install libc++ and libc++abi + -- + -- 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++")) + if target:data("cxx.modules.use_libc++") then + target:add("syslinks", "c++") + end end -- get includedirs for stl headers @@ -93,6 +102,10 @@ end function _get_toolchain_includedirs_for_stlheaders(includedirs, clang) local tmpfile = os.tmpfile() .. ".cc" io.writefile(tmpfile, "#include <vector>") + local argv = {"-E", "-x", "c++", tmpfile} + 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} if result then for _, line in ipairs(result:split("\n", {plain = true})) do |
