@@ -23,6 +23,7 @@ import("core.base.option")
2323import (" core.project.config" )
2424import (" core.base.semver" )
2525import (" core.tool.linker" )
26+ import (" core.tool.toolchain" , {alias = " _toolchain" })
2627import (" core.tool.compiler" )
2728import (" core.language.language" )
2829import (" lib.detect.find_tool" )
183184
184185-- get llvm sdk resource directory
185186function _get_llvm_resourcedir (toolchain )
186- local llvm_resourcedir = _g ._LLVM_RESOURCE_DIR
187+ local memcache = _toolchain .memcache ()
188+ local cachekey = toolchain :cachekey () .. " _get_llvm_resourcedir"
189+ local llvm_resourcedir = memcache :get2 (cachekey )
187190 if llvm_resourcedir == nil then
188191 local outdata = try { function () return os .iorunv (toolchain :tool (" cc" ), {" -print-resource-dir" }) end }
189192 if outdata then
@@ -192,14 +195,16 @@ function _get_llvm_resourcedir(toolchain)
192195 llvm_resourcedir = nil
193196 end
194197 end
195- _g . _LLVM_RESOURCE_DIR = llvm_resourcedir or false
198+ memcache : set ( cachekey , llvm_resourcedir or false )
196199 end
197200 return llvm_resourcedir or nil
198201end
199202
200203-- get llvm sdk root directory
201204function _get_llvm_rootdir (toolchain )
202- local llvm_rootdir = _g ._LLVM_ROOTDIR
205+ local memcache = _toolchain .memcache ()
206+ local cachekey = toolchain :cachekey () .. " _get_llvm_rootdir"
207+ local llvm_rootdir = memcache :get2 (cachekey , " rootdir" )
203208 if llvm_rootdir == nil then
204209 local resourcedir = _get_llvm_resourcedir (toolchain )
205210 if resourcedir then
@@ -208,7 +213,7 @@ function _get_llvm_rootdir(toolchain)
208213 llvm_rootdir = nil
209214 end
210215 end
211- _g . _LLVM_ROOTDIR = llvm_rootdir or false
216+ memcache : set ( cachekey , llvm_rootdir or false )
212217 end
213218 return llvm_rootdir or nil
214219end
@@ -254,20 +259,24 @@ end
254259
255260-- get llvm target triple
256261function _get_llvm_target_triple (toolchain )
257- local llvm_targettriple = _g ._LLVM_TARGETTRIPLE
262+ local memcache = _toolchain .memcache ()
263+ local cachekey = toolchain :cachekey () .. " _get_llvm_target_triple"
264+ local llvm_targettriple = memcache :get (cachekey )
258265 if llvm_targettriple == nil then
259266 local outdata = try { function () return os .iorunv (toolchain :tool (" cc" ), {" -print-target-triple" }) end }
260267 if outdata then
261268 llvm_targettriple = outdata :trim ()
262269 end
263- _g . _LLVM_TARGETTRIPLE = llvm_targettriple or false
270+ memcache : set ( cachekey , llvm_targettriple or false )
264271 end
265272 return llvm_targettriple or nil
266273end
267274
268275-- get llvm toolchain dirs
269276function get_llvm_dirs (toolchain )
270- local llvm_dirs = _g .llvm_dirs
277+ local memcache = _toolchain .memcache ()
278+ local cachekey = toolchain :cachekey () .. " _get_llvm_dirs"
279+ local llvm_dirs = memcache :get (cachekey )
271280 if llvm_dirs == nil then
272281 local rootdir = toolchain :sdkdir ()
273282 if not rootdir and toolchain :is_plat (" windows" ) then
@@ -313,6 +322,7 @@ function get_llvm_dirs(toolchain)
313322 rt = rtdir ,
314323 rtlib = rtlib ,
315324 rtlink = rtlink }
325+ memcache :set (cachekey , llvm_dirs )
316326 _g .llvm_dirs = llvm_dirs
317327 end
318328 return llvm_dirs
0 commit comments