diff --git a/utils/build-presets.ini b/utils/build-presets.ini index 27223b02310fa..5c45994cc93cd 100644 --- a/utils/build-presets.ini +++ b/utils/build-presets.ini @@ -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 diff --git a/utils/build-script-impl b/utils/build-script-impl index 06b54cc6c8eb2..dea3f5931a4f9 100755 --- a/utils/build-script-impl +++ b/utils/build-script-impl @@ -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. diff --git a/utils/build_swift/build_swift/defaults.py b/utils/build_swift/build_swift/defaults.py index 99b7b85d72aad..650a809f4dad3 100644 --- a/utils/build_swift/build_swift/defaults.py +++ b/utils/build_swift/build_swift/defaults.py @@ -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']) diff --git a/utils/swift_build_support/swift_build_support/products/cmake_product.py b/utils/swift_build_support/swift_build_support/products/cmake_product.py index dc338334f284d..8804f6d8ca441 100644 --- a/utils/swift_build_support/swift_build_support/products/cmake_product.py +++ b/utils/swift_build_support/swift_build_support/products/cmake_product.py @@ -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. diff --git a/utils/swift_build_support/swift_build_support/products/llvm.py b/utils/swift_build_support/swift_build_support/products/llvm.py index 48f77c0af0b93..ca59be23eab8d 100644 --- a/utils/swift_build_support/swift_build_support/products/llvm.py +++ b/utils/swift_build_support/swift_build_support/products/llvm.py @@ -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') @@ -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! @@ -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))