Skip to content

Commit 738384d

Browse files
committed
Use LLVM runtimes build
LLVM plans to remove the legacy methods for building compiler-rt. This change updates build-script to use LLVM_ENABLE_RUNTIMES to build compiler-rt with the just-built clang instead of the legacy methods. This does not update the llvm-install-components in build-presets.ini -- this is done on purpose to stress more the migration logic, some of the presets will be updated with a subsequent PRs Addresses rdar://113972453
1 parent a829fa2 commit 738384d

File tree

5 files changed

+29
-45
lines changed

5 files changed

+29
-45
lines changed

utils/build-presets.ini

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -697,12 +697,6 @@ reconfigure
697697
verbose-build
698698
build-ninja
699699

700-
# TODO: remove when we will transition from LLVM_TOOL_COMPILER_RT_BUILD
701-
# to LLVM_USE_RUNTIMES to build compiler-rt (#60993), so we can leverage
702-
# the value for SANITIZER_MIN_OSX_VERSION set in cmake_product.py
703-
extra-cmake-options=
704-
-DCLANG_COMPILER_RT_CMAKE_ARGS:STRING="-DSANITIZER_MIN_OSX_VERSION:STRING=13.0"
705-
706700
# Do not build swift or cmark
707701
skip-build-swift
708702
skip-build-cmark

utils/build-script-impl

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -803,20 +803,6 @@ function set_build_options_for_host() {
803803
esac
804804

805805

806-
# We don't currently support building compiler-rt for cross-compile targets.
807-
# It's not clear that's useful anyway.
808-
if [[ $(is_cross_tools_host "${host}") ]] ; then
809-
llvm_cmake_options+=(
810-
-DLLVM_TOOL_COMPILER_RT_BUILD:BOOL=FALSE
811-
-DLLVM_BUILD_EXTERNAL_COMPILER_RT:BOOL=FALSE
812-
)
813-
else
814-
llvm_cmake_options+=(
815-
-DLLVM_TOOL_COMPILER_RT_BUILD:BOOL="$(false_true ${SKIP_BUILD_COMPILER_RT})"
816-
-DLLVM_BUILD_EXTERNAL_COMPILER_RT:BOOL="$(false_true ${SKIP_BUILD_COMPILER_RT})"
817-
)
818-
fi
819-
820806
# If we are asked to not generate test targets for LLVM and or Swift,
821807
# disable as many LLVM tools as we can. This improves compile time when
822808
# compiling with LTO.

utils/build_swift/build_swift/defaults.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ def llvm_install_components():
123123
platforms.
124124
"""
125125
components = ['llvm-ar', 'llvm-cov', 'llvm-profdata', 'IndexStore', 'clang',
126-
'clang-resource-headers', 'compiler-rt', 'clangd', 'LTO',
126+
'clang-resource-headers', 'builtins', 'runtimes', 'clangd', 'LTO',
127127
'lld']
128128
if os.sys.platform == 'darwin':
129129
components.extend(['dsymutil'])

utils/swift_build_support/swift_build_support/products/cmake_product.py

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -381,19 +381,6 @@ def host_cmake_options(self, host_target):
381381
# in the compiler checks CMake performs
382382
swift_cmake_options.define('CMAKE_OSX_ARCHITECTURES', arch)
383383

384-
# We don't currently support building compiler-rt for cross-compile targets.
385-
# It's not clear that's useful anyway.
386-
if self.is_cross_compile_target(host_target):
387-
llvm_cmake_options.define('LLVM_TOOL_COMPILER_RT_BUILD:BOOL', 'FALSE')
388-
llvm_cmake_options.define('LLVM_BUILD_EXTERNAL_COMPILER_RT:BOOL', 'FALSE')
389-
else:
390-
llvm_cmake_options.define('LLVM_TOOL_COMPILER_RT_BUILD:BOOL',
391-
cmake.CMakeOptions.true_false(
392-
self.args.build_compiler_rt))
393-
llvm_cmake_options.define('LLVM_BUILD_EXTERNAL_COMPILER_RT:BOOL',
394-
cmake.CMakeOptions.true_false(
395-
self.args.build_compiler_rt))
396-
397384
# If we are asked to not generate test targets for LLVM and or Swift,
398385
# disable as many LLVM tools as we can. This improves compile time when
399386
# compiling with LTO.

utils/swift_build_support/swift_build_support/products/llvm.py

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,7 @@ def build(self, host_target):
291291
llvm_cmake_options.define('LLVM_INCLUDE_DOCS:BOOL', 'TRUE')
292292
llvm_cmake_options.define('LLVM_ENABLE_LTO:STRING', self.args.lto_type)
293293
llvm_cmake_options.define('COMPILER_RT_INTERCEPT_LIBDISPATCH', 'ON')
294+
llvm_cmake_options.define('RUNTIMES_CMAKE_ARGS', '-DLLVM_ENABLE_PER_TARGET_RUNTIME_DIR:BOOL=OFF')
294295

295296
if self.args.build_embedded_stdlib and system() == "Darwin":
296297
# Ask for Mach-O cross-compilation builtins (for Embedded Swift)
@@ -299,10 +300,14 @@ def build(self, host_target):
299300
'armv6 armv6m armv7 armv7m armv7em')
300301

301302
llvm_enable_projects = ['clang']
303+
llvm_enable_runtimes = []
302304

303305
if self.args.build_compiler_rt and \
304306
not self.is_cross_compile_target(host_target):
305-
llvm_enable_projects.append('compiler-rt')
307+
llvm_enable_runtimes.append('compiler-rt')
308+
build_targets.append("runtimes")
309+
# This is needed to build correctly TSan under Linux
310+
llvm_cmake_options.define('COMPILER_RT_USE_BUILTINS_LIBRARY', 'ON')
306311

307312
if self.args.build_clang_tools_extra:
308313
llvm_enable_projects.append('clang-tools-extra')
@@ -316,18 +321,20 @@ def build(self, host_target):
316321
if self.args.build_lld:
317322
llvm_enable_projects.append('lld')
318323

324+
if self.args.test:
325+
# LLVMTestingSupport is not built at part of `all`
326+
# and is required by some Swift tests
327+
build_targets.append('LLVMTestingSupport')
328+
319329
llvm_cmake_options.define('LLVM_ENABLE_PROJECTS',
320330
';'.join(llvm_enable_projects))
331+
llvm_cmake_options.define('LLVM_ENABLE_RUNTIMES',
332+
';'.join(llvm_enable_runtimes))
321333

322-
# In the near future we are aiming to build compiler-rt with
323-
# LLVM_ENABLE_RUNTIMES
324-
# Until that happens, we need to unset this variable from
325-
# LLVM CMakeCache.txt for two reasons
326-
# * prevent PRs testing this variable to affect other runs landing
327-
# unrelated features
328-
# * avoid fallouts should we land such change and then have to revert
329-
# it to account for unforeseen regressions
330-
llvm_cmake_options.undefine('LLVM_ENABLE_RUNTIMES')
334+
# This accounts for previous incremental runs that may have set
335+
# those in the LLVM CMakeCache.txt
336+
llvm_cmake_options.undefine('LLVM_TOOL_COMPILER_RT_BUILD')
337+
llvm_cmake_options.undefine('LLVM_BUILD_EXTERNAL_COMPILER_RT')
331338

332339
# NOTE: This is not a dead option! It is relied upon for certain
333340
# bots/build-configs!
@@ -491,9 +498,19 @@ def install(self, host_target):
491498
self.args.llvm_install_components != 'all':
492499
install_targets = []
493500
components = self.args.llvm_install_components.split(';')
501+
if 'compiler-rt' in components:
502+
# This is a courtesy fallback to avoid breaking downstream presets
503+
# we are not aware of
504+
components.remove('compiler-rt')
505+
components.append('builtins')
506+
components.append('runtimes')
507+
print('warning: replaced legacy LLVM component compiler-rt '
508+
'with builtins;runtimes -- consider updating your preset',
509+
flush=True)
510+
494511
for component in components:
495512
if self.is_cross_compile_target(host_target):
496-
if component == 'compiler-rt':
513+
if component in ['builtins', 'runtimes']:
497514
continue
498515
install_targets.append('install-{}'.format(component))
499516

0 commit comments

Comments
 (0)