From e2ab5bcf569107caf8c5efb6013d6902fe32238b Mon Sep 17 00:00:00 2001 From: Shoaib Meenai Date: Thu, 20 Aug 2020 12:18:15 -0700 Subject: [PATCH] [runtimes] Allow LLVM_BUILTIN_TARGETS to include Darwin We have two ways of using the runtimes build setup to build the builtins. You can either have an empty LLVM_BUILTIN_TARGETS (or have it include the "default" target), in which case builtin_default_target is called to set up the default target, or you can have actual triples in LLVM_BUILTIN_TARGETS, in which case builtin_register_target is called for each triple. builtin_default_target lets you build the builtins for Darwin (assuming your default triple is Darwin); builtin_register_target does not. I don't understand the reason for this distinction. The Darwin builtins build is special in that a single CMake configure handles building the builtins for multiple platforms (e.g. macOS, iPhoneSimulator, and iOS) and architectures (e.g. arm64, armv7, and x86_64). Consequently, if you specify multiple Darwin triples in LLVM_BUILTIN_TARGETS, expecting each configure to only build for that particular triple, it won't work. However, if you specify a *single* x86_64-apple-darwin triple in LLVM_BUILTIN_TARGETS, that single configure will build the builtins for all Darwin targets, exactly the same way that the default target would. The only difference between the configuration for the default target and the x86_64-apple-darwin triple is that the latter runs the configuration with `-DCOMPILER_RT_DEFAULT_TARGET_ONLY=ON`, but that makes no difference for Apple targets (none of the CMake codepaths which have different behavior based on that variable are run for Apple targets). I tested this by running two builtins builds on my Mac, one with the default target and one with the x86_64-apple-darwin19.5.0 target (which is the default target triple for my clang). The only relevant CMakeCache.txt difference was the following, and as discussed above, it has no effect on the actual build for Apple targets: ``` -//Default triple for which compiler-rt runtimes will be built. -COMPILER_RT_DEFAULT_TARGET_TRIPLE:STRING=x86_64-apple-darwin19.5.0 +//No help, variable specified on the command line. +COMPILER_RT_DEFAULT_TARGET_ONLY:UNINITIALIZED=ON ``` Furthermore, when I add the `-D` flag to compiler-rt's libtool invocations, the libraries produced by the two builds are *identical*. If anything, I would expect builtin_register_target to complain if you tried specifying a triple for a particular Apple platform triple (e.g. macosx), since that's the scenario in which it won't work as you want. The generic darwin triple should be fine though, as best as I can tell. I'm happy to add the error for specific Apple platform triples, either in this diff or in a follow-up. Reviewed By: phosek Differential Revision: https://reviews.llvm.org/D86313 --- llvm/runtimes/CMakeLists.txt | 38 +++++++++++++++++++++++++++++++------- 1 file changed, 31 insertions(+), 7 deletions(-) diff --git a/llvm/runtimes/CMakeLists.txt b/llvm/runtimes/CMakeLists.txt index dc74a46..b97cc73 100644 --- a/llvm/runtimes/CMakeLists.txt +++ b/llvm/runtimes/CMakeLists.txt @@ -233,6 +233,34 @@ else() # if this is included from LLVM's CMake set(EXTRA_ARGS EXCLUDE_FROM_ALL) endif() + function(check_apple_target triple builtin_or_runtime) + set(error "\ +compiler-rt for Darwin builds for all platforms and architectures using a \ +single configuration. Specify only a single darwin triple (e.g. x86_64-apple-darwin) \ +in your targets list (and not a triple for a specific platform such as macos). \ +You can use variables such as COMPILER_RT_ENABLE_IOS and DARWIN_ios_ARCHS to \ +control the specific platforms and architectures to build.") + + set(seen_property ${builtin_or_runtime}_darwin_triple_seen) + string(REPLACE "-" ";" triple_components ${triple}) + foreach(component ${triple_components}) + string(TOLOWER "${component}" component_lower) + if(component_lower MATCHES "^darwin") + get_property(darwin_triple_seen GLOBAL PROPERTY ${seen_property}) + if(darwin_triple_seen) + message(FATAL_ERROR "${error}") + endif() + set_property(GLOBAL PROPERTY ${seen_property} YES) + if(NOT RUNTIMES_BUILD_ALLOW_DARWIN) + message(FATAL_ERROR "\ +${error} Set RUNTIMES_BUILD_ALLOW_DARWIN to allow a single darwin triple.") + endif() + elseif(component_lower MATCHES "^ios|^macos|^tvos|^watchos") + message(FATAL_ERROR "${error}") + endif() + endforeach() + endfunction() + function(builtin_default_target compiler_rt_path) cmake_parse_arguments(ARG "" "" "DEPENDS" ${ARGN}) @@ -256,13 +284,7 @@ else() # if this is included from LLVM's CMake function(builtin_register_target compiler_rt_path target) cmake_parse_arguments(ARG "" "" "DEPENDS" ${ARGN}) - string(REPLACE "-" ";" builtin_target_list ${target}) - foreach(item ${builtin_target_list}) - string(TOLOWER "${item}" item_lower) - if(item_lower MATCHES "darwin") - message(FATAL_ERROR "LLVM_BUILTIN_TARGETS isn't implemented for Darwin platform!") - endif() - endforeach() + check_apple_target(${target} builtin) get_cmake_property(variableNames VARIABLES) foreach(variableName ${variableNames}) @@ -417,6 +439,8 @@ else() # if this is included from LLVM's CMake include(${LLVM_BINARY_DIR}/runtimes/${name}/Components.cmake OPTIONAL) set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS ${LLVM_BINARY_DIR}/runtimes/${name}/Components.cmake) + check_apple_target(${target} runtime) + set(${name}_deps ${ARG_DEPENDS}) if(NOT name STREQUAL target) list(APPEND ${name}_deps runtimes-${target}) -- 2.7.4