@@ -32,6 +32,7 @@ def __init__(self):
3232 self .check_targets = []
3333 self .cmake_defines = {}
3434 self .install_targets = []
35+ self .llvm_major_version = 0
3536 self .tools = None
3637 self .projects = []
3738 self .quiet_cmake = False
@@ -200,6 +201,7 @@ def configure(self):
200201 raise RuntimeError ('No targets set?' )
201202
202203 self .validate_targets ()
204+ self .set_llvm_major_version ()
203205
204206 # yapf: disable
205207 cmake_cmd = [
@@ -247,7 +249,12 @@ def configure(self):
247249 if self .folders .install :
248250 self .cmake_defines ['CMAKE_INSTALL_PREFIX' ] = self .folders .install
249251
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 )
251258 # Remove system dependency on terminfo to keep the dynamic library
252259 # dependencies slim. This can be done unconditionally when the option
253260 # exists, as it does not impact clang's ability to show colors for
@@ -321,6 +328,21 @@ def host_target_is_enabled(self):
321328 def project_is_enabled (self , project ):
322329 return 'all' in self .projects or project in self .projects
323330
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+
324346 def show_install_info (self ):
325347 # Installation folder is optional, show build folder as the
326348 # installation location in that case.
@@ -389,7 +411,10 @@ def configure(self):
389411
390412 llvm_build_tools = self .cmake_defines .get ('LLVM_BUILD_TOOLS' , 'ON' ) == 'ON'
391413
414+ self .set_llvm_major_version ()
415+
392416 distribution_components = []
417+ runtime_distribution_components = []
393418 if llvm_build_tools :
394419 distribution_components += [
395420 'llvm-ar' ,
@@ -407,7 +432,11 @@ def configure(self):
407432 if self .project_is_enabled ('lld' ):
408433 distribution_components .append ('lld' )
409434 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' )
411440
412441 slim_llvm_defines = {
413442 # Tools needed by bootstrapping
@@ -423,6 +452,8 @@ def configure(self):
423452 # Don't include example build targets to save on cmake cycles
424453 'LLVM_INCLUDE_EXAMPLES' : 'OFF' ,
425454 }
455+ if runtime_distribution_components :
456+ slim_llvm_defines ['LLVM_RUNTIME_DISTRIBUTION_COMPONENTS' ] = ';' .join (runtime_distribution_components )
426457
427458 slim_compiler_rt_defines = {
428459 # Don't build libfuzzer when compiler-rt is enabled, it invokes cmake again and we don't use it
0 commit comments