@@ -122,17 +122,18 @@ function compiler.load(sourcekind, target)
122
122
return nil , " unknown source kind!"
123
123
end
124
124
125
- -- load compiler tool first (with cache)
126
- local compiler_tool , program_or_errors = compiler ._load_tool (sourcekind , target )
127
- if not compiler_tool then
128
- return nil , program_or_errors
129
- end
130
-
131
125
-- init cache key
132
126
-- @note we need plat/arch,
133
127
-- because it is possible for the compiler to do cross-compilation with the -target parameter
134
- local plat = compiler_tool :plat () or config .plat () or os .host ()
135
- local arch = compiler_tool :arch () or config .arch () or os .arch ()
128
+ local plat = config .plat () or os .host ()
129
+ local arch = config .arch () or os .arch ()
130
+ if target and target .tool then
131
+ local _ , _ , toolchain_info = target :tool (sourcekind )
132
+ if toolchain_info then
133
+ plat = toolchain_info .plat
134
+ arch = toolchain_info .arch
135
+ end
136
+ end
136
137
local cachekey = sourcekind .. (program_or_errors or " " ) .. plat .. arch
137
138
if target then
138
139
cachekey = cachekey .. tostring (target )
@@ -143,6 +144,13 @@ function compiler.load(sourcekind, target)
143
144
local instance = compiler ._INSTANCES [cachekey ]
144
145
if not instance then
145
146
instance = table .inherit (compiler , builder )
147
+
148
+ -- load compiler tool
149
+ -- @NOTE We cannot cache the tool, otherwise it may cause duplicate toolchain flags to be added
150
+ local compiler_tool , program_or_errors = compiler ._load_tool (sourcekind , target )
151
+ if not compiler_tool then
152
+ return nil , program_or_errors
153
+ end
146
154
instance ._TOOL = compiler_tool
147
155
148
156
-- load the compiler language from the source kind
@@ -188,7 +196,7 @@ function compiler.load(sourcekind, target)
188
196
189
197
-- we need to load it at the end because in tool.load().
190
198
-- because we may need to call has_flags, which requires the full platform toolchain flags
191
- local ok , errors = compiler_tool :_load_once ()
199
+ local ok , errors = instance : _tool () :_load_once ()
192
200
if not ok then
193
201
return nil , errors
194
202
end
0 commit comments