@@ -32,6 +32,7 @@ def __init__(self):
32
32
self .check_targets = []
33
33
self .cmake_defines = {}
34
34
self .install_targets = []
35
+ self .llvm_major_version = 0
35
36
self .tools = None
36
37
self .projects = []
37
38
self .quiet_cmake = False
@@ -200,6 +201,7 @@ def configure(self):
200
201
raise RuntimeError ('No targets set?' )
201
202
202
203
self .validate_targets ()
204
+ self .set_llvm_major_version ()
203
205
204
206
# yapf: disable
205
207
cmake_cmd = [
@@ -247,7 +249,12 @@ def configure(self):
247
249
if self .folders .install :
248
250
self .cmake_defines ['CMAKE_INSTALL_PREFIX' ] = self .folders .install
249
251
250
- self .cmake_defines ['LLVM_ENABLE_PROJECTS' ] = ';' .join (self .projects )
252
+ # https://github.com/llvm/llvm-project/commit/b593110d89aea76b8b10152b24ece154bff3e4b5
253
+ llvm_enable_projects = self .projects .copy ()
254
+ if self .llvm_major_version >= 21 and self .project_is_enabled ('compiler-rt' ):
255
+ llvm_enable_projects .remove ('compiler-rt' )
256
+ self .cmake_defines ['LLVM_ENABLE_RUNTIMES' ] = 'compiler-rt'
257
+ self .cmake_defines ['LLVM_ENABLE_PROJECTS' ] = ';' .join (llvm_enable_projects )
251
258
# Remove system dependency on terminfo to keep the dynamic library
252
259
# dependencies slim. This can be done unconditionally when the option
253
260
# exists, as it does not impact clang's ability to show colors for
@@ -321,6 +328,21 @@ def host_target_is_enabled(self):
321
328
def project_is_enabled (self , project ):
322
329
return 'all' in self .projects or project in self .projects
323
330
331
+ def set_llvm_major_version (self ):
332
+ if self .llvm_major_version :
333
+ return # no need to set if already set
334
+ if not self .folders .source :
335
+ raise RuntimeError ('No source folder set?' )
336
+ if (llvmversion_cmake := Path (self .folders .source ,
337
+ 'cmake/Modules/LLVMVersion.cmake' )).exists ():
338
+ text_to_search = llvmversion_cmake .read_text (encoding = 'utf-8' )
339
+ else :
340
+ text_to_search = Path (self .folders .source ,
341
+ 'llvm/CMakeLists.txt' ).read_text (encoding = 'utf-8' )
342
+ if not (match := re .search (r'set\(LLVM_VERSION_MAJOR (\d+)\)' , text_to_search )):
343
+ raise RuntimeError ('Could not find LLVM_VERSION_MAJOR in text?' )
344
+ self .llvm_major_version = int (match .group (1 ))
345
+
324
346
def show_install_info (self ):
325
347
# Installation folder is optional, show build folder as the
326
348
# installation location in that case.
@@ -389,7 +411,10 @@ def configure(self):
389
411
390
412
llvm_build_tools = self .cmake_defines .get ('LLVM_BUILD_TOOLS' , 'ON' ) == 'ON'
391
413
414
+ self .set_llvm_major_version ()
415
+
392
416
distribution_components = []
417
+ runtime_distribution_components = []
393
418
if llvm_build_tools :
394
419
distribution_components += [
395
420
'llvm-ar' ,
@@ -407,7 +432,11 @@ def configure(self):
407
432
if self .project_is_enabled ('lld' ):
408
433
distribution_components .append ('lld' )
409
434
if build_compiler_rt :
410
- distribution_components += ['llvm-profdata' , 'profile' ]
435
+ distribution_components .append ('llvm-profdata' )
436
+ if self .llvm_major_version >= 21 :
437
+ runtime_distribution_components .append ('profile' )
438
+ else :
439
+ distribution_components .append ('profile' )
411
440
412
441
slim_llvm_defines = {
413
442
# Tools needed by bootstrapping
@@ -423,6 +452,8 @@ def configure(self):
423
452
# Don't include example build targets to save on cmake cycles
424
453
'LLVM_INCLUDE_EXAMPLES' : 'OFF' ,
425
454
}
455
+ if runtime_distribution_components :
456
+ slim_llvm_defines ['LLVM_RUNTIME_DISTRIBUTION_COMPONENTS' ] = ';' .join (runtime_distribution_components )
426
457
427
458
slim_compiler_rt_defines = {
428
459
# Don't build libfuzzer when compiler-rt is enabled, it invokes cmake again and we don't use it
0 commit comments