1515LLVM_VER_FOR_RUNTIMES = 20
1616
1717
18- def get_all_targets (llvm_folder ):
18+ def get_all_targets (llvm_folder , experimental = False ):
19+ variables = ['LLVM_ALL_TARGETS' ]
20+ if experimental :
21+ variables .append ('LLVM_ALL_EXPERIMENTAL_TARGETS' )
22+
1923 contents = Path (llvm_folder , 'llvm/CMakeLists.txt' ).read_text (encoding = 'utf-8' )
20- if not (match := re .search (r'set\(LLVM_ALL_TARGETS([\w|\s]+)\)' , contents )):
21- raise RuntimeError ('Could not find LLVM_ALL_TARGETS?' )
22- return [val for target in match .group (1 ).splitlines () if (val := target .strip ())]
24+
25+ targets = []
26+ for variable in variables :
27+ if not (match := re .search (fr"set\({ variable } ([\w|\s]+)\)" , contents )):
28+ raise RuntimeError (f"Could not find { variables } ?" )
29+ targets += [val for target in match .group (1 ).splitlines () if (val := target .strip ())]
30+ return targets
2331
2432
2533class LLVMBuilder (Builder ):
@@ -305,10 +313,27 @@ def configure(self):
305313 self .cmake_defines ['LLVM_ENABLE_WARNINGS' ] = 'OFF'
306314 if self .tools .llvm_tblgen :
307315 self .cmake_defines ['LLVM_TABLEGEN' ] = self .tools .llvm_tblgen
308- self .cmake_defines ['LLVM_TARGETS_TO_BUILD' ] = ';' .join (self .targets )
309316 if self .tools .ld :
310317 self .cmake_defines ['LLVM_USE_LINKER' ] = self .tools .ld
311318
319+ # Separate "standard" targets from experimental targets. We know that
320+ # all values in targets are valid at this point from the
321+ # validate_targets() call above. If a value is not in the supported
322+ # standard targets list, it must be an experimental target.
323+ supported_standard_targets = get_all_targets (self .folders .source )
324+ standard_targets = []
325+ experimental_targets = []
326+ for target in self .targets :
327+ if target in supported_standard_targets :
328+ standard_targets .append (target )
329+ else :
330+ experimental_targets .append (target )
331+ if standard_targets :
332+ self .cmake_defines ['LLVM_TARGETS_TO_BUILD' ] = ';' .join (standard_targets )
333+ if experimental_targets :
334+ self .cmake_defines ['LLVM_EXPERIMENTAL_TARGETS_TO_BUILD' ] = ';' .join (
335+ experimental_targets )
336+
312337 # Clear Linux needs a different target to find all of the C++ header files, otherwise
313338 # stage 2+ compiles will fail without this
314339 # We figure this out based on the existence of x86_64-generic-linux in the C++ headers path
@@ -404,7 +429,7 @@ def validate_targets(self):
404429 if not self .targets :
405430 raise RuntimeError ('No targets set?' )
406431
407- all_targets = get_all_targets (self .folders .source )
432+ all_targets = get_all_targets (self .folders .source , experimental = True )
408433
409434 for target in self .targets :
410435 if target in ('all' , 'host' ):
@@ -414,7 +439,7 @@ def validate_targets(self):
414439 # tuple() for shorter pretty printing versus instead of
415440 # ('{"', '".join(all_targets)}')
416441 raise RuntimeError (
417- f"Requested target ('{ target } ') was not found in LLVM_ALL_TARGETS { tuple (all_targets )} , check spelling?"
442+ f"Requested target ('{ target } ') was not found in LLVM_ALL_TARGETS or LLVM_ALL_EXPERIMENTAL_TARGETS { tuple (all_targets )} , check spelling?"
418443 )
419444
420445
0 commit comments