Skip to content

Commit d1b64e6

Browse files
committed
improve linker for package #5542
1 parent 7336c8a commit d1b64e6

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

xmake/core/package/package.lua

+16-6
Original file line numberDiff line numberDiff line change
@@ -1281,7 +1281,7 @@ function _instance:toolconfig(name)
12811281
end
12821282
end
12831283

1284-
-- get the target compiler
1284+
-- get the package compiler
12851285
function _instance:compiler(sourcekind)
12861286
local compilerinst = self:_memcache():get("compiler")
12871287
if not compilerinst then
@@ -1298,6 +1298,20 @@ function _instance:compiler(sourcekind)
12981298
return compilerinst
12991299
end
13001300

1301+
-- get the package linker
1302+
function _instance:linker(targetkind, sourcekinds)
1303+
local linkerinst = self:_memcache():get("linker")
1304+
if not linkerinst then
1305+
local instance, errors = linker.load(targetkind, sourcekinds, self)
1306+
if not instance then
1307+
os.raise(errors)
1308+
end
1309+
linkerinst = instance
1310+
self:_memcache():set("linker", linkerinst)
1311+
end
1312+
return linkerinst
1313+
end
1314+
13011315
-- has the given tool for the current package?
13021316
--
13031317
-- e.g.
@@ -2358,11 +2372,7 @@ function _instance:_generate_build_configs(configs, opt)
23582372
end
23592373
if runtimes then
23602374
local sourcekind = opt.sourcekind or "cxx"
2361-
local tool, name = self:tool("ld")
2362-
local linker, errors = linker.load("binary", sourcekind, {target = package})
2363-
if not linker then
2364-
os.raise(errors)
2365-
end
2375+
local linker = self:linker("binary", sourcekind)
23662376
local fake_target = {is_shared = function(_) return false end,
23672377
sourcekinds = function(_) return sourcekind end}
23682378
local compiler = self:compiler(sourcekind)

0 commit comments

Comments
 (0)