Skip to content

Commit 74f61a3

Browse files
authored
Merge pull request #6686 from xmake-io/toolchain
fix compiler cache #6672
2 parents 58f011f + d9af634 commit 74f61a3

2 files changed

Lines changed: 9 additions & 19 deletions

File tree

xmake/core/tool/compiler.lua

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,6 @@ end
9393

9494
-- load compiler tool
9595
function compiler._load_tool(sourcekind, target)
96-
97-
-- get program from target
9896
local program, toolname, toolchain_info
9997
if target and target.tool then
10098
program, toolname, toolchain_info = target:tool(sourcekind)
@@ -136,16 +134,15 @@ function compiler.load(sourcekind, target)
136134
local plat = compiler_tool:plat() or config.plat() or os.host()
137135
local arch = compiler_tool:arch() or config.arch() or os.arch()
138136
local cachekey = sourcekind .. (program_or_errors or "") .. plat .. arch
137+
if target then
138+
cachekey = cachekey .. tostring(target)
139+
end
139140

140141
-- get it directly from cache dirst
141142
compiler._INSTANCES = compiler._INSTANCES or {}
142143
local instance = compiler._INSTANCES[cachekey]
143144
if not instance then
144-
145-
-- new instance
146145
instance = table.inherit(compiler, builder)
147-
148-
-- save the compiler tool
149146
instance._TOOL = compiler_tool
150147

151148
-- load the compiler language from the source kind
@@ -200,8 +197,6 @@ end
200197

201198
-- build the source files (compile and link)
202199
function compiler:build(sourcefiles, targetfile, opt)
203-
204-
-- init options
205200
opt = opt or {}
206201

207202
-- get compile flags
@@ -225,15 +220,11 @@ function compiler:build(sourcefiles, targetfile, opt)
225220
if not targetkind and opt.target and opt.target.targetkind then
226221
targetkind = opt.target:kind()
227222
end
228-
229-
-- get it
230223
return sandbox.load(self:_tool().build, self:_tool(), sourcefiles, targetkind or "binary", targetfile, flags)
231224
end
232225

233226
-- get the build arguments list (compile and link)
234227
function compiler:buildargv(sourcefiles, targetfile, opt)
235-
236-
-- init options
237228
opt = opt or {}
238229

239230
-- get compile flags
@@ -257,8 +248,6 @@ function compiler:buildargv(sourcefiles, targetfile, opt)
257248
if not targetkind and opt.target and opt.target.targetkind then
258249
targetkind = opt.target:kind()
259250
end
260-
261-
-- get it
262251
return self:_tool():buildargv(sourcefiles, targetkind or "binary", targetfile, flags)
263252
end
264253

@@ -322,14 +311,10 @@ end
322311
-- @return flags list
323312
--
324313
function compiler:compflags(opt)
325-
326-
-- init options
327314
opt = opt or {}
328315

329316
-- get target
330-
local target = opt.target
331-
332-
-- get target kind
317+
local target = opt.target or self:target()
333318
local targetkind = opt.targetkind
334319
if not targetkind and target and target:type() == "target" then
335320
targetkind = target:kind()

xmake/core/tool/tool.lua

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,11 @@ function tool.load(kind, opt)
246246

247247
-- init cachekey
248248
local cachekey = kind .. (program or "") .. plat .. arch .. (opt.host and "host" or "")
249+
if toolchain_info and toolchain_info.cachekey then
250+
-- it maybe contains target key
251+
-- @see https://github.com/xmake-io/xmake/issues/6672
252+
cachekey = cachekey .. toolchain_info.cachekey
253+
end
249254

250255
-- get it directly from cache dirst
251256
tool._TOOLS = tool._TOOLS or {}

0 commit comments

Comments
 (0)