diff options
| author | ruki <[email protected]> | 2024-01-20 23:22:46 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2024-01-25 12:09:58 +0800 |
| commit | c622a4e8a6542cc9234344ab323139f5e8f23612 (patch) | |
| tree | e31a08aefcf1456aec4c992c08ccf65653aa1817 | |
| parent | 64df1054c8c48a5f9008bd801759f8f4d696f616 (diff) | |
pass runtimes to toolchain
| -rw-r--r-- | xmake/actions/config/xmake.lua | 1 | ||||
| -rw-r--r-- | xmake/core/platform/platform.lua | 25 | ||||
| -rw-r--r-- | xmake/core/project/target.lua | 26 | ||||
| -rw-r--r-- | xmake/core/tool/toolchain.lua | 20 |
4 files changed, 58 insertions, 14 deletions
diff --git a/xmake/actions/config/xmake.lua b/xmake/actions/config/xmake.lua index 57b9ff7ee..4bf43c787 100644 --- a/xmake/actions/config/xmake.lua +++ b/xmake/actions/config/xmake.lua @@ -217,7 +217,6 @@ task("config") , "e.g. " , " - xmake f --runtimes=MTd" , " - xmake f --runtimes=MT,c++_static" - , " - xmake f --runtimes=gcc::stdc++_static,clang::c++_static" , values = {"MT", "MTd", "MD", "MDd", -- only for msvc "c++_static", "c++_shared", -- gcc/clang/android ndk "stdc++_static", "stdc++_shared", -- gcc/clang diff --git a/xmake/core/platform/platform.lua b/xmake/core/platform/platform.lua index 8a56a816e..322e976b8 100644 --- a/xmake/core/platform/platform.lua +++ b/xmake/core/platform/platform.lua @@ -147,6 +147,25 @@ function _instance:runenvs() return runenvs end +-- get runtimes +function _instance:runtimes() + local runtimes = self:_memcache():get("runtimes") + if runtimes == nil then + runtimes = config.get("runtimes") + if self:name() == "windows" then + runtimes = runtimes or config.get("vs_runtime") + elseif self:name() == "android" then + runtimes = runtimes or config.get("ndk_cxxstl") + end + if runtimes then + runtimes = table.unwrap(runtimes:split(",", {plain = true})) + end + runtimes = runtimes or false + self:_memcache():set("runtimes", runtimes) + end + return runtimes or nil +end + -- get the toolchains function _instance:toolchains(opt) local toolchains = self:_memcache():get("toolchains") @@ -162,7 +181,8 @@ function _instance:toolchains(opt) -- get the given toolchain local toolchain_given = config.get("toolchain") if toolchain_given then - local toolchain_inst, errors = toolchain.load(toolchain_given, {plat = self:name(), arch = self:arch()}) + local toolchain_inst, errors = toolchain.load(toolchain_given, { + plat = self:name(), arch = self:arch(), runtimes = self:runtimes()}) -- attempt to load toolchain from project if not toolchain_inst and platform._project() then toolchain_inst = platform._project().toolchain(toolchain_given) @@ -181,7 +201,8 @@ function _instance:toolchains(opt) end if names then for _, name in ipairs(table.wrap(names)) do - local toolchain_inst, errors = toolchain.load(name, {plat = self:name(), arch = self:arch()}) + local toolchain_inst, errors = toolchain.load(name, { + plat = self:name(), arch = self:arch(), runtimes = self:runtimes()}) -- attempt to load toolchain from project if not toolchain_inst and platform._project() then toolchain_inst = platform._project().toolchain(name) diff --git a/xmake/core/project/target.lua b/xmake/core/project/target.lua index ba87fa08d..74d8b77b5 100644 --- a/xmake/core/project/target.lua +++ b/xmake/core/project/target.lua @@ -2381,11 +2381,6 @@ function _instance:pcoutputfile(langkind) end -- get runtimes --- --- set_runtimes("MTd") --- set_runtimes("MT,c++_static") --- set_runtimes("gcc::stdc++_static,clang::c++_static") --- function _instance:runtimes() local runtimes = self:_memcache():get("runtimes") if runtimes == nil then @@ -2396,17 +2391,26 @@ function _instance:runtimes() runtimes = runtimes or config.get("ndk_cxxstl") end if runtimes then - runtimes = runtimes:split(",", {plain = true}) + runtimes = table.unwrap(runtimes:split(",", {plain = true})) end - runtimes = runtimes or {} + runtimes = runtimes or false self:_memcache():set("runtimes", runtimes) end - return runtimes + return runtimes or nil end --- has the given runtime for the current toolchain? -function _instance:has_runtime(name) - -- TODO +-- has the given runtime for the current toolchains? +function _instance:has_runtime(...) + local runtimes_set = self._RUNTIMES_SET + if runtimes_set == nil then + runtimes_set = hashset.from(table.wrap(self:runtimes())) + self._RUNTIMES_SET = runtimes_set + end + for _, v in ipairs(table.pack(...)) do + if runtimes_set:has(v) then + return true + end + end end -- get the given toolchain diff --git a/xmake/core/tool/toolchain.lua b/xmake/core/tool/toolchain.lua index 4831bce5c..020b790d8 100644 --- a/xmake/core/tool/toolchain.lua +++ b/xmake/core/tool/toolchain.lua @@ -29,6 +29,7 @@ local utils = require("base/utils") local table = require("base/table") local global = require("base/global") local option = require("base/option") +local hashset = require("base/hashset") local scopeinfo = require("base/scopeinfo") local interpreter = require("base/interpreter") local config = require("project/config") @@ -107,6 +108,25 @@ function _instance:is_arch(...) end end +-- get toolchain runtimes +function _instance:runtimes() + return self:config("runtimes") +end + +-- has the given runtime for the current toolchains? +function _instance:has_runtime(...) + local runtimes_set = self._RUNTIMES_SET + if runtimes_set == nil then + runtimes_set = hashset.from(table.wrap(self:runtimes())) + self._RUNTIMES_SET = runtimes_set + end + for _, v in ipairs(table.pack(...)) do + if runtimes_set:has(v) then + return true + end + end +end + -- get toolchain info function _instance:info() local arch = self:arch() |
