From 9dda4775ad3113086a42e611e590b215e35e0404 Mon Sep 17 00:00:00 2001 From: ruki Date: Sat, 9 Aug 2025 23:32:27 +0800 Subject: fix compiler cache #6672 --- xmake/core/tool/compiler.lua | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/xmake/core/tool/compiler.lua b/xmake/core/tool/compiler.lua index b3a84e2a5..2d305dcf9 100644 --- a/xmake/core/tool/compiler.lua +++ b/xmake/core/tool/compiler.lua @@ -136,6 +136,9 @@ function compiler.load(sourcekind, target) local plat = compiler_tool:plat() or config.plat() or os.host() local arch = compiler_tool:arch() or config.arch() or os.arch() local cachekey = sourcekind .. (program_or_errors or "") .. plat .. arch + if target then + cachekey = cachekey .. tostring(target) + end -- get it directly from cache dirst compiler._INSTANCES = compiler._INSTANCES or {} @@ -322,14 +325,10 @@ end -- @return flags list -- function compiler:compflags(opt) - - -- init options opt = opt or {} -- get target - local target = opt.target - - -- get target kind + local target = opt.target or self:target() local targetkind = opt.targetkind if not targetkind and target and target:type() == "target" then targetkind = target:kind() -- cgit v1.3.1 From d9af634da2cbbe29c1e185890255db39a4d5f60b Mon Sep 17 00:00:00 2001 From: ruki Date: Sat, 9 Aug 2025 23:49:51 +0800 Subject: fix tool cache --- xmake/core/tool/compiler.lua | 14 -------------- xmake/core/tool/tool.lua | 5 +++++ 2 files changed, 5 insertions(+), 14 deletions(-) diff --git a/xmake/core/tool/compiler.lua b/xmake/core/tool/compiler.lua index 2d305dcf9..541a172b6 100644 --- a/xmake/core/tool/compiler.lua +++ b/xmake/core/tool/compiler.lua @@ -93,8 +93,6 @@ end -- load compiler tool function compiler._load_tool(sourcekind, target) - - -- get program from target local program, toolname, toolchain_info if target and target.tool then program, toolname, toolchain_info = target:tool(sourcekind) @@ -144,11 +142,7 @@ function compiler.load(sourcekind, target) compiler._INSTANCES = compiler._INSTANCES or {} local instance = compiler._INSTANCES[cachekey] if not instance then - - -- new instance instance = table.inherit(compiler, builder) - - -- save the compiler tool instance._TOOL = compiler_tool -- load the compiler language from the source kind @@ -203,8 +197,6 @@ end -- build the source files (compile and link) function compiler:build(sourcefiles, targetfile, opt) - - -- init options opt = opt or {} -- get compile flags @@ -228,15 +220,11 @@ function compiler:build(sourcefiles, targetfile, opt) if not targetkind and opt.target and opt.target.targetkind then targetkind = opt.target:kind() end - - -- get it return sandbox.load(self:_tool().build, self:_tool(), sourcefiles, targetkind or "binary", targetfile, flags) end -- get the build arguments list (compile and link) function compiler:buildargv(sourcefiles, targetfile, opt) - - -- init options opt = opt or {} -- get compile flags @@ -260,8 +248,6 @@ function compiler:buildargv(sourcefiles, targetfile, opt) if not targetkind and opt.target and opt.target.targetkind then targetkind = opt.target:kind() end - - -- get it return self:_tool():buildargv(sourcefiles, targetkind or "binary", targetfile, flags) end diff --git a/xmake/core/tool/tool.lua b/xmake/core/tool/tool.lua index 0443498fe..06a5ca3ad 100644 --- a/xmake/core/tool/tool.lua +++ b/xmake/core/tool/tool.lua @@ -246,6 +246,11 @@ function tool.load(kind, opt) -- init cachekey local cachekey = kind .. (program or "") .. plat .. arch .. (opt.host and "host" or "") + if toolchain_info and toolchain_info.cachekey then + -- it maybe contains target key + -- @see https://github.com/xmake-io/xmake/issues/6672 + cachekey = cachekey .. toolchain_info.cachekey + end -- get it directly from cache dirst tool._TOOLS = tool._TOOLS or {} -- cgit v1.3.1