Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tc_build: llvm: Move compiler-rt to LLVM_ENABLE_RUNTIMES #289

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 33 additions & 2 deletions tc_build/llvm.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -200,6 +201,7 @@ def configure(self):
raise RuntimeError('No targets set?')

self.validate_targets()
self.set_llvm_major_version()

# yapf: disable
cmake_cmd = [
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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',
Expand All @@ -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
Expand All @@ -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
Expand Down