summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2023-08-11 13:08:38 +0800
committerGitHub <[email protected]>2023-08-11 13:08:38 +0800
commit898698717c518de2ca6f3354e0dd29bfb436187e (patch)
tree32cece84ccac8ed0931566144136ee2b369cdfbb
parentfdead41fed6b6d0d1d8c699f810bf8ffbf995a8b (diff)
parent704cc78dd4fa1e108f946fc51fcd538ea05d01de (diff)
Merge pull request #4060 from xmake-io/toolchain
improve target toolchain
-rw-r--r--xmake/actions/config/main.lua14
-rw-r--r--xmake/core/platform/platform.lua6
-rw-r--r--xmake/core/project/target.lua22
3 files changed, 34 insertions, 8 deletions
diff --git a/xmake/actions/config/main.lua b/xmake/actions/config/main.lua
index 47f542706..eaa61f490 100644
--- a/xmake/actions/config/main.lua
+++ b/xmake/actions/config/main.lua
@@ -125,6 +125,14 @@ function _check_target_toolchains()
if target:is_enabled() and (target:get("toolchains") or
not target:is_plat(config.get("plat")) or
not target:is_arch(config.get("arch"))) then
+
+ -- check platform toolchains first
+ -- `target/set_plat()` and target:toolchains() need it
+ local ok, errors = target:platform():check()
+ if not ok then
+ raise(errors)
+ end
+
local target_toolchains = target:get("toolchains")
if target_toolchains then
target_toolchains = hashset.from(table.wrap(target_toolchains))
@@ -134,12 +142,6 @@ function _check_target_toolchains()
raise("toolchain(\"%s\"): not found!", toolchain_inst:name())
end
end
- else
- -- check platform toolchains for `target/set_plat()`
- local ok, errors = target:platform():check()
- if not ok then
- raise(errors)
- end
end
elseif not target:get("toolset") then
-- we only abort it when we know that toolchains of platform and target do not found
diff --git a/xmake/core/platform/platform.lua b/xmake/core/platform/platform.lua
index 01d5b0e5e..148120d49 100644
--- a/xmake/core/platform/platform.lua
+++ b/xmake/core/platform/platform.lua
@@ -234,6 +234,10 @@ end
-- do check
function _instance:check()
+ local checked = self._CHECKED
+ if checked ~= nil then
+ return checked
+ end
-- check toolchains
local toolchains = self:toolchains({all = true})
@@ -256,11 +260,13 @@ function _instance:check()
end
end
if #toolchains == 0 then
+ self._CHECKED = false
return false, "toolchains not found!"
end
-- save valid toolchains
config.set("__toolchains_" .. self:name() .. "_" .. self:arch(), toolchains_valid)
+ self._CHECKED = true
return true
end
diff --git a/xmake/core/project/target.lua b/xmake/core/project/target.lua
index 60a4d182a..ca46a7b69 100644
--- a/xmake/core/project/target.lua
+++ b/xmake/core/project/target.lua
@@ -2076,7 +2076,8 @@ function _instance:toolchains()
local toolchains = self:_memcache():get("toolchains")
if toolchains == nil then
- -- load target toolchains
+ -- load target toolchains first
+ local has_standalone = false
local target_toolchains = self:get("toolchains")
if target_toolchains then
toolchains = {}
@@ -2092,12 +2093,29 @@ function _instance:toolchains()
if not toolchain_inst then
os.raise(errors)
end
+ if toolchain_inst:is_standalone() then
+ has_standalone = true
+ end
table.insert(toolchains, toolchain_inst)
end
+
+ -- we always need a standalone toolchain
+ -- because we maybe only set partial toolchains in target, e.g. nasm toolchain
+ --
+ -- @note platform has been checked in config/_check_target_toolchains
+ if not has_standalone then
+ for _, toolchain_inst in ipairs(self:platform():toolchains()) do
+ if toolchain_inst:is_standalone() then
+ table.insert(toolchains, toolchain_inst)
+ has_standalone = true
+ break
+ end
+ end
+ end
else
- -- load platform toolchains
toolchains = self:platform():toolchains()
end
+
self:_memcache():set("toolchains", toolchains)
end
return toolchains