diff options
| author | ruki <[email protected]> | 2022-11-04 22:44:52 +0800 |
|---|---|---|
| committer | GitHub <[email protected]> | 2022-11-04 22:44:52 +0800 |
| commit | 6c819d681111add7afa70920b788d8d56f620d77 (patch) | |
| tree | 9a7f2af95e6e16541fd05dc7dec3957f79df69b3 /xmake/rules/c++/modules/modules_support | |
| parent | 9fe1d17945bc670c0ec3b394c39e17e0cedb7b44 (diff) | |
| parent | 0fdefd2f7280db640ed09df068e09f98649ce7ec (diff) | |
Merge pull request #3016 from xmake-io/module
Improve clang/gcc/msvc to better support std modules
Diffstat (limited to 'xmake/rules/c++/modules/modules_support')
| -rw-r--r-- | xmake/rules/c++/modules/modules_support/clang.lua | 36 | ||||
| -rw-r--r-- | xmake/rules/c++/modules/modules_support/msvc.lua | 25 |
2 files changed, 45 insertions, 16 deletions
diff --git a/xmake/rules/c++/modules/modules_support/clang.lua b/xmake/rules/c++/modules/modules_support/clang.lua index 100830046..a3cf06e79 100644 --- a/xmake/rules/c++/modules/modules_support/clang.lua +++ b/xmake/rules/c++/modules/modules_support/clang.lua @@ -66,21 +66,41 @@ 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}) - target:data_set("cxx.modules.use_libc++", table.contains(target:get("cxxflags"), "-stdlib=libc++")) + -- 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. + local dep_symbols + local has_shared_deps = false + for _, dep in ipairs(target:orderdeps()) do + if dep:is_shared() then + dep_symbols = dep:get("symbols") + has_shared_deps = true + break + end + end + if has_shared_deps then + target:set("symbols", dep_symbols and dep_symbols or "none") + end + + -- 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++", "clang::-stdlib=libc++")) + if target:data("cxx.modules.use_libc++") then + target:add("syslinks", "c++") + end end -- get includedirs for stl headers @@ -93,6 +113,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 diff --git a/xmake/rules/c++/modules/modules_support/msvc.lua b/xmake/rules/c++/modules/modules_support/msvc.lua index 04ab2bf7a..b57ac4520 100644 --- a/xmake/rules/c++/modules/modules_support/msvc.lua +++ b/xmake/rules/c++/modules/modules_support/msvc.lua @@ -126,25 +126,30 @@ end -- load module support for the current target function load(target) - -- get flags - local modulesflag = get_modulesflag(target) -- add modules flags + local modulesflag = get_modulesflag(target) target:add("cxxflags", modulesflag) -- add stdifcdir in case of if the user ask for it - if target:values("msvc.modules.stdifcdir") then - local stdifcdirflag = get_stdifcdirflag(target) - for _, toolchain_inst in ipairs(target:toolchains()) do - if toolchain_inst:name() == "msvc" then - local vcvars = toolchain_inst:config("vcvars") - if vcvars.VCInstallDir and vcvars.VCToolsVersion then - local stdifcdir = path.join(vcvars.VCInstallDir, "Tools", "MSVC", vcvars.VCToolsVersion, "ifc", target:is_arch("x64") and "x64" or "x86") + local stdifcdirflag = get_stdifcdirflag(target) + if stdifcdirflag then + local msvc = target:toolchain("msvc") + if msvc then + local vcvars = msvc:config("vcvars") + if vcvars.VCInstallDir and vcvars.VCToolsVersion then + local arch + if target:is_arch("x64", "x86_64") then + arch = "x64" + elseif target:is_arch("x86", "i386") then + arch = "x86" + end + if arch then + local stdifcdir = path.join(vcvars.VCInstallDir, "Tools", "MSVC", vcvars.VCToolsVersion, "ifc", arch) if os.isdir(stdifcdir) then target:add("cxxflags", {stdifcdirflag, winos.short_path(stdifcdir)}, {force = true, expand = false}) end end - break end end end |
