Skip to content

Use LLVM runtimes build #67986

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

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
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
6 changes: 0 additions & 6 deletions utils/build-presets.ini
Original file line number Diff line number Diff line change
Expand Up @@ -697,12 +697,6 @@ reconfigure
verbose-build
build-ninja

# TODO: remove when we will transition from LLVM_TOOL_COMPILER_RT_BUILD
# to LLVM_USE_RUNTIMES to build compiler-rt (#60993), so we can leverage
# the value for SANITIZER_MIN_OSX_VERSION set in cmake_product.py
extra-cmake-options=
-DCLANG_COMPILER_RT_CMAKE_ARGS:STRING="-DSANITIZER_MIN_OSX_VERSION:STRING=13.0"

# Do not build swift or cmark
skip-build-swift
skip-build-cmark
Expand Down
14 changes: 0 additions & 14 deletions utils/build-script-impl
Original file line number Diff line number Diff line change
Expand Up @@ -803,20 +803,6 @@ function set_build_options_for_host() {
esac


# We don't currently support building compiler-rt for cross-compile targets.
# It's not clear that's useful anyway.
if [[ $(is_cross_tools_host "${host}") ]] ; then
llvm_cmake_options+=(
-DLLVM_TOOL_COMPILER_RT_BUILD:BOOL=FALSE
-DLLVM_BUILD_EXTERNAL_COMPILER_RT:BOOL=FALSE
)
else
llvm_cmake_options+=(
-DLLVM_TOOL_COMPILER_RT_BUILD:BOOL="$(false_true ${SKIP_BUILD_COMPILER_RT})"
-DLLVM_BUILD_EXTERNAL_COMPILER_RT:BOOL="$(false_true ${SKIP_BUILD_COMPILER_RT})"
)
fi

# If we are asked to not generate test targets for LLVM and or Swift,
# disable as many LLVM tools as we can. This improves compile time when
# compiling with LTO.
Expand Down
2 changes: 1 addition & 1 deletion utils/build_swift/build_swift/defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ def llvm_install_components():
platforms.
"""
components = ['llvm-ar', 'llvm-cov', 'llvm-profdata', 'IndexStore', 'clang',
'clang-resource-headers', 'compiler-rt', 'clangd', 'LTO',
'clang-resource-headers', 'builtins', 'runtimes', 'clangd', 'LTO',
'lld']
if os.sys.platform == 'darwin':
components.extend(['dsymutil'])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -381,19 +381,6 @@ def host_cmake_options(self, host_target):
# in the compiler checks CMake performs
swift_cmake_options.define('CMAKE_OSX_ARCHITECTURES', arch)

# We don't currently support building compiler-rt for cross-compile targets.
# It's not clear that's useful anyway.
if self.is_cross_compile_target(host_target):
llvm_cmake_options.define('LLVM_TOOL_COMPILER_RT_BUILD:BOOL', 'FALSE')
llvm_cmake_options.define('LLVM_BUILD_EXTERNAL_COMPILER_RT:BOOL', 'FALSE')
else:
llvm_cmake_options.define('LLVM_TOOL_COMPILER_RT_BUILD:BOOL',
cmake.CMakeOptions.true_false(
self.args.build_compiler_rt))
llvm_cmake_options.define('LLVM_BUILD_EXTERNAL_COMPILER_RT:BOOL',
cmake.CMakeOptions.true_false(
self.args.build_compiler_rt))

# If we are asked to not generate test targets for LLVM and or Swift,
# disable as many LLVM tools as we can. This improves compile time when
# compiling with LTO.
Expand Down
59 changes: 48 additions & 11 deletions utils/swift_build_support/swift_build_support/products/llvm.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,18 +291,43 @@ def build(self, host_target):
llvm_cmake_options.define('LLVM_INCLUDE_DOCS:BOOL', 'TRUE')
llvm_cmake_options.define('LLVM_ENABLE_LTO:STRING', self.args.lto_type)
llvm_cmake_options.define('COMPILER_RT_INTERCEPT_LIBDISPATCH', 'ON')
# Swift expects the old layout for the runtime directory
llvm_cmake_options.define('LLVM_ENABLE_PER_TARGET_RUNTIME_DIR', 'OFF')
if host_target.startswith('linux'):
# This preserves the behaviour we had when using
# LLVM_BUILD_EXTERNAL COMPILER_RT --
# that is, having the linker not complaing if symbols used
# by TSan are undefined (namely the ones for Blocks Runtime)
# In the long term, we want to remove this and
# build Blocks Runtime before LLVM
llvm_cmake_options.define(
'SANITIZER_COMMON_LINK_FLAGS:STRING', '-Wl,-z,undefs')
if system() == "Darwin":
llvm_cmake_options.define('LLVM_BUILTIN_TARGETS', 'arm64-apple-darwin')
llvm_cmake_options.define('LLVM_RUNTIME_TARGETS', 'arm64-apple-darwin')
llvm_cmake_options.define('RUNTIMES_BUILD_ALLOW_DARWIN', 'ON')
llvm_cmake_options.define(
'RUNTIMES_arm64-apple-darwin_COMPILER_RT_SANITIZERS_TO_BUILD',
'asan;dfsan;msan;hwasan;tsan;safestack;cfi;scudo_standalone'
';ubsan_minimal;gwp_asan;nsan;asan_abi')

if self.args.build_embedded_stdlib and system() == "Darwin":
# Ask for Mach-O cross-compilation builtins (for Embedded Swift)
llvm_cmake_options.define(
'COMPILER_RT_FORCE_BUILD_BAREMETAL_MACHO_BUILTINS_ARCHS:STRING',
'armv6 armv6m armv7 armv7m armv7em')
llvm_cmake_options.define(
'BUILTINS_arm64-apple-darwin_'
'COMPILER_RT_FORCE_BUILD_BAREMETAL_MACHO_BUILTINS_ARCHS:'
'STRING', 'armv6 armv6m armv7 armv7m armv7em')

llvm_enable_projects = ['clang']
llvm_enable_runtimes = []

if self.args.build_compiler_rt and \
not self.is_cross_compile_target(host_target):
llvm_enable_projects.append('compiler-rt')
llvm_enable_runtimes.append('compiler-rt')
build_targets.append("runtimes")

if self.args.build_clang_tools_extra:
llvm_enable_projects.append('clang-tools-extra')
Expand All @@ -316,18 +341,20 @@ def build(self, host_target):
if self.args.build_lld:
llvm_enable_projects.append('lld')

if self.args.test:
# LLVMTestingSupport is not built at part of `all`
# and is required by some Swift tests
build_targets.append('LLVMTestingSupport')

llvm_cmake_options.define('LLVM_ENABLE_PROJECTS',
';'.join(llvm_enable_projects))
llvm_cmake_options.define('LLVM_ENABLE_RUNTIMES',
';'.join(llvm_enable_runtimes))

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

# NOTE: This is not a dead option! It is relied upon for certain
# bots/build-configs!
Expand Down Expand Up @@ -491,9 +518,19 @@ def install(self, host_target):
self.args.llvm_install_components != 'all':
install_targets = []
components = self.args.llvm_install_components.split(';')
if 'compiler-rt' in components:
# This is a courtesy fallback to avoid breaking downstream presets
# we are not aware of
components.remove('compiler-rt')
components.append('builtins')
components.append('runtimes')
print('warning: replaced legacy LLVM component compiler-rt '
'with builtins;runtimes -- consider updating your preset',
flush=True)

for component in components:
if self.is_cross_compile_target(host_target):
if component == 'compiler-rt':
if component in ['builtins', 'runtimes']:
continue
install_targets.append('install-{}'.format(component))

Expand Down