diff options
| author | Arthur LAURENT <[email protected]> | 2025-10-26 17:00:12 +0100 |
|---|---|---|
| committer | Arthur LAURENT <[email protected]> | 2025-10-26 17:23:35 +0100 |
| commit | 56583f742da88091b9916fa91034f83e2aa67438 (patch) | |
| tree | f0f63b36aac14902028e22319fa8da53dfb9841a | |
| parent | f0c987ee98d91da8f3a7d507a979a7f26b8b903c (diff) | |
nfc(swift) cache cpp langflags
| -rw-r--r-- | xmake/core/tool/compiler.lua | 7 | ||||
| -rw-r--r-- | xmake/rules/swift/xmake.lua | 37 |
2 files changed, 23 insertions, 21 deletions
diff --git a/xmake/core/tool/compiler.lua b/xmake/core/tool/compiler.lua index 5c974edb3..ff8ce6a5d 100644 --- a/xmake/core/tool/compiler.lua +++ b/xmake/core/tool/compiler.lua @@ -363,12 +363,5 @@ function compiler:compflags(opt) return self:_preprocess_flags(flags) end --- get the tool language flags --- --- @return flags list -function compiler:languageflags(lang) - return self:_tool():nf_language(lang) -end - -- return module return compiler diff --git a/xmake/rules/swift/xmake.lua b/xmake/rules/swift/xmake.lua index a3181fd6a..9f9f6bd19 100644 --- a/xmake/rules/swift/xmake.lua +++ b/xmake/rules/swift/xmake.lua @@ -72,22 +72,28 @@ rule("swift.interop", function() on_prepare_files(function(target, jobgraph, sourcebatch, opt) import("utils.progress") import("core.base.option") + import("core.tool.compiler") import("core.language.language") import("core.project.depend") + import("core.cache.localcache") - local function _get_target_cppversion() - local compinst = target:compiler("cxx") - local languages = target:get("languages") - for _, language in ipairs(languages) do - if language:startswith("c++") - or language:startswith("cxx") - or language:startswith("gnu++") - or language:startswith("gnuxx") then - -- c++26 currently prevent compilation of swift modules - local v = compinst:languageflags(language:gsub("26", "23"):gsub("latest", "23")) - if v then return v end + local function _get_target_cpp_langflags() + local cpp_langflags = _g.cpp_langflags + if cpp_langflags == nil then + local languages = target:get("languages") + for _, language in ipairs(languages) do + if language:startswith("c++") + or language:startswith("cxx") + or language:startswith("gnu++") + or language:startswith("gnuxx") then + -- c++26 currently prevent compilation of swift modules + language = language:gsub("26", "23"):gsub("latest", "23") + cpp_langflags = compiler.map_flags("cxx", "language", language, {target = target}) + _g.cpp_langflags = cpp_langflags or false + end end end + return cpp_langflags or nil end local mode = target:data("swift.interop") @@ -116,9 +122,12 @@ rule("swift.interop", function() depend.on_changed(function() local stdflag if mode == "cxx" then - local cxxstandard = _get_target_cppversion() - if cxxstandard then - stdflag = {"-Xcc", cxxstandard} + local cpp_langflags = _get_target_cpp_langflags() + if cpp_langflags then + for _, flag in ipairs(cpp_langflags) do + stdflag = stdflag or {} + table.join2(stdflag, {"-Xcc", flag}) + end end end |
