Skip to content

Commit efce129

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 efce129

File tree

5 files changed

+45
-45
lines changed

5 files changed

+45
-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: 44 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,22 @@ def should_build(self, host_target):
217217
# LLVM will always be built in part
218218
return True
219219

220+
@classmethod
221+
def compute_cmake_args_for_runtimes(cls, host_target):
222+
# Swift expects the old layout for the runtime directory
223+
args_for_runtime = '-DLLVM_ENABLE_PER_TARGET_RUNTIME_DIR:BOOL=OFF'
224+
225+
if host_target.startswith('linux'):
226+
# This preserves the behaviour we had when using
227+
# LLVM_BUILD_EXTERNAL COMPILER_RT --
228+
# that is, having the linker not complaing if symbols used
229+
# by TSan are undefined (namely the ones for Blocks Runtime)
230+
# In the long term, we want to remove this and
231+
# build Blocks Runtime before LLVM
232+
args_for_runtime += ';-DSANITIZER_COMMON_LINK_FLAGS:STRING=-Wl,-z,undefs'
233+
234+
return args_for_runtime
235+
220236
def build(self, host_target):
221237
"""build() -> void
222238
@@ -291,6 +307,9 @@ def build(self, host_target):
291307
llvm_cmake_options.define('LLVM_INCLUDE_DOCS:BOOL', 'TRUE')
292308
llvm_cmake_options.define('LLVM_ENABLE_LTO:STRING', self.args.lto_type)
293309
llvm_cmake_options.define('COMPILER_RT_INTERCEPT_LIBDISPATCH', 'ON')
310+
llvm_cmake_options.define(
311+
'RUNTIMES_CMAKE_ARGS',
312+
LLVM.compute_cmake_args_for_runtimes(host_target))
294313

295314
if self.args.build_embedded_stdlib and system() == "Darwin":
296315
# Ask for Mach-O cross-compilation builtins (for Embedded Swift)
@@ -299,10 +318,12 @@ def build(self, host_target):
299318
'armv6 armv6m armv7 armv7m armv7em')
300319

301320
llvm_enable_projects = ['clang']
321+
llvm_enable_runtimes = []
302322

303323
if self.args.build_compiler_rt and \
304324
not self.is_cross_compile_target(host_target):
305-
llvm_enable_projects.append('compiler-rt')
325+
llvm_enable_runtimes.append('compiler-rt')
326+
build_targets.append("runtimes")
306327

307328
if self.args.build_clang_tools_extra:
308329
llvm_enable_projects.append('clang-tools-extra')
@@ -316,18 +337,20 @@ def build(self, host_target):
316337
if self.args.build_lld:
317338
llvm_enable_projects.append('lld')
318339

340+
if self.args.test:
341+
# LLVMTestingSupport is not built at part of `all`
342+
# and is required by some Swift tests
343+
build_targets.append('LLVMTestingSupport')
344+
319345
llvm_cmake_options.define('LLVM_ENABLE_PROJECTS',
320346
';'.join(llvm_enable_projects))
347+
llvm_cmake_options.define('LLVM_ENABLE_RUNTIMES',
348+
';'.join(llvm_enable_runtimes))
321349

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')
350+
# This accounts for previous incremental runs that may have set
351+
# those in the LLVM CMakeCache.txt
352+
llvm_cmake_options.undefine('LLVM_TOOL_COMPILER_RT_BUILD')
353+
llvm_cmake_options.undefine('LLVM_BUILD_EXTERNAL_COMPILER_RT')
331354

332355
# NOTE: This is not a dead option! It is relied upon for certain
333356
# bots/build-configs!
@@ -491,9 +514,19 @@ def install(self, host_target):
491514
self.args.llvm_install_components != 'all':
492515
install_targets = []
493516
components = self.args.llvm_install_components.split(';')
517+
if 'compiler-rt' in components:
518+
# This is a courtesy fallback to avoid breaking downstream presets
519+
# we are not aware of
520+
components.remove('compiler-rt')
521+
components.append('builtins')
522+
components.append('runtimes')
523+
print('warning: replaced legacy LLVM component compiler-rt '
524+
'with builtins;runtimes -- consider updating your preset',
525+
flush=True)
526+
494527
for component in components:
495528
if self.is_cross_compile_target(host_target):
496-
if component == 'compiler-rt':
529+
if component in ['builtins', 'runtimes']:
497530
continue
498531
install_targets.append('install-{}'.format(component))
499532

0 commit comments

Comments
 (0)