From c8636072845fae4438427267067983bc030313dd Mon Sep 17 00:00:00 2001 From: Nathan Chancellor Date: Thu, 30 Jan 2025 22:11:54 -0700 Subject: [PATCH] tc_build: llvm: Move compiler-rt to LLVM_ENABLE_RUNTIMES Per the new deprecation warning: https://github.com/llvm/llvm-project/commit/b593110d89aea76b8b10152b24ece154bff3e4b5 Do the check based on LLVM_VERSION_MAJOR from source to avoid a complicated and potentially hard to maintain dynamic check. Signed-off-by: Nathan Chancellor --- tc_build/llvm.py | 35 +++++++++++++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) diff --git a/tc_build/llvm.py b/tc_build/llvm.py index 3fb2f57f..a045b37d 100644 --- a/tc_build/llvm.py +++ b/tc_build/llvm.py @@ -32,6 +32,7 @@ def __init__(self): self.check_targets = [] self.cmake_defines = {} self.install_targets = [] + self.llvm_major_version = 0 self.tools = None self.projects = [] self.quiet_cmake = False @@ -200,6 +201,7 @@ def configure(self): raise RuntimeError('No targets set?') self.validate_targets() + self.set_llvm_major_version() # yapf: disable cmake_cmd = [ @@ -247,7 +249,12 @@ def configure(self): if self.folders.install: self.cmake_defines['CMAKE_INSTALL_PREFIX'] = self.folders.install - self.cmake_defines['LLVM_ENABLE_PROJECTS'] = ';'.join(self.projects) + # https://github.com/llvm/llvm-project/commit/b593110d89aea76b8b10152b24ece154bff3e4b5 + llvm_enable_projects = self.projects.copy() + if self.llvm_major_version >= 21 and self.project_is_enabled('compiler-rt'): + llvm_enable_projects.remove('compiler-rt') + self.cmake_defines['LLVM_ENABLE_RUNTIMES'] = 'compiler-rt' + self.cmake_defines['LLVM_ENABLE_PROJECTS'] = ';'.join(llvm_enable_projects) # Remove system dependency on terminfo to keep the dynamic library # dependencies slim. This can be done unconditionally when the option # exists, as it does not impact clang's ability to show colors for @@ -321,6 +328,21 @@ def host_target_is_enabled(self): def project_is_enabled(self, project): return 'all' in self.projects or project in self.projects + def set_llvm_major_version(self): + if self.llvm_major_version: + return # no need to set if already set + if not self.folders.source: + raise RuntimeError('No source folder set?') + if (llvmversion_cmake := Path(self.folders.source, + 'cmake/Modules/LLVMVersion.cmake')).exists(): + text_to_search = llvmversion_cmake.read_text(encoding='utf-8') + else: + text_to_search = Path(self.folders.source, + 'llvm/CMakeLists.txt').read_text(encoding='utf-8') + if not (match := re.search(r'set\(LLVM_VERSION_MAJOR (\d+)\)', text_to_search)): + raise RuntimeError('Could not find LLVM_VERSION_MAJOR in text?') + self.llvm_major_version = int(match.group(1)) + def show_install_info(self): # Installation folder is optional, show build folder as the # installation location in that case. @@ -389,7 +411,10 @@ def configure(self): llvm_build_tools = self.cmake_defines.get('LLVM_BUILD_TOOLS', 'ON') == 'ON' + self.set_llvm_major_version() + distribution_components = [] + runtime_distribution_components = [] if llvm_build_tools: distribution_components += [ 'llvm-ar', @@ -407,7 +432,11 @@ def configure(self): if self.project_is_enabled('lld'): distribution_components.append('lld') if build_compiler_rt: - distribution_components += ['llvm-profdata', 'profile'] + distribution_components.append('llvm-profdata') + if self.llvm_major_version >= 21: + runtime_distribution_components.append('profile') + else: + distribution_components.append('profile') slim_llvm_defines = { # Tools needed by bootstrapping @@ -423,6 +452,8 @@ def configure(self): # Don't include example build targets to save on cmake cycles 'LLVM_INCLUDE_EXAMPLES': 'OFF', } + if runtime_distribution_components: + slim_llvm_defines['LLVM_RUNTIME_DISTRIBUTION_COMPONENTS'] = ';'.join(runtime_distribution_components) slim_compiler_rt_defines = { # Don't build libfuzzer when compiler-rt is enabled, it invokes cmake again and we don't use it