diff --git a/xmake/core/base/private/instance_deps.lua b/xmake/core/base/private/instance_deps.lua index 535b2d2bb9c..e001505c8c5 100644 --- a/xmake/core/base/private/instance_deps.lua +++ b/xmake/core/base/private/instance_deps.lua @@ -32,11 +32,19 @@ local table = require("base/table") -- -- a.deps = b -- b.deps = c +-- foo.deps = a d -- --- orderdeps: c -> b -> a +-- orderdeps: c -> b -> d -> a -> foo +-- +-- if they're target, their links order is reverse(orderdeps), e.g. foo-> a -> d -> b -> c -- function instance_deps.load_deps(instance, instances, deps, orderdeps, depspath) - for _, dep in ipairs(table.wrap(instance:get("deps"))) do + local deps = table.wrap(instance:get("deps")) + local total = #deps + for idx, _ in ipairs(deps) do + -- we reverse to get the flat dependencies in order to ensure the correct linking order + -- @see https://github.com/xmake-io/xmake/issues/3144 + local dep = deps[total + 1 - idx] local depinst = instances[dep] if depinst then local depspath_sub diff --git a/xmake/core/project/target.lua b/xmake/core/project/target.lua index b0cd6fa0db0..e991d288cda 100644 --- a/xmake/core/project/target.lua +++ b/xmake/core/project/target.lua @@ -389,7 +389,9 @@ end function _instance:get_from_deps(name, opt) local values = {} local orderdeps = self:orderdeps() - for _, dep in ipairs(orderdeps) do + local total = #orderdeps + for idx, _ in ipairs(orderdeps) do + local dep = orderdeps[total + 1 - idx] local depinherit = self:extraconf("deps", dep:name(), "inherit") if depinherit == nil or depinherit then table.join2(values, dep:get(name, opt))