summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2024-08-30 00:58:10 +0800
committerruki <[email protected]>2024-08-30 00:58:10 +0800
commitd1b64e63ff0e39badc4bd03b65033149af66c5f8 (patch)
treea6c1aef78807b40fac09e95c1d5c4efc41a30764
parent7336c8a5459d105febde0a2f43c02502bce30fc7 (diff)
improve linker for package #5542
-rw-r--r--xmake/core/package/package.lua22
1 files changed, 16 insertions, 6 deletions
diff --git a/xmake/core/package/package.lua b/xmake/core/package/package.lua
index fe22a2e8b..a833a2f0b 100644
--- a/xmake/core/package/package.lua
+++ b/xmake/core/package/package.lua
@@ -1281,7 +1281,7 @@ function _instance:toolconfig(name)
end
end
--- get the target compiler
+-- get the package compiler
function _instance:compiler(sourcekind)
local compilerinst = self:_memcache():get("compiler")
if not compilerinst then
@@ -1298,6 +1298,20 @@ function _instance:compiler(sourcekind)
return compilerinst
end
+-- get the package linker
+function _instance:linker(targetkind, sourcekinds)
+ local linkerinst = self:_memcache():get("linker")
+ if not linkerinst then
+ local instance, errors = linker.load(targetkind, sourcekinds, self)
+ if not instance then
+ os.raise(errors)
+ end
+ linkerinst = instance
+ self:_memcache():set("linker", linkerinst)
+ end
+ return linkerinst
+end
+
-- has the given tool for the current package?
--
-- e.g.
@@ -2358,11 +2372,7 @@ function _instance:_generate_build_configs(configs, opt)
end
if runtimes then
local sourcekind = opt.sourcekind or "cxx"
- local tool, name = self:tool("ld")
- local linker, errors = linker.load("binary", sourcekind, {target = package})
- if not linker then
- os.raise(errors)
- end
+ local linker = self:linker("binary", sourcekind)
local fake_target = {is_shared = function(_) return false end,
sourcekinds = function(_) return sourcekind end}
local compiler = self:compiler(sourcekind)