-
Notifications
You must be signed in to change notification settings - Fork 10.6k
Use autolinking to pull in compatibility libraries. #25148
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -730,7 +730,8 @@ function(_add_swift_library_single target name) | |
OBJECT_LIBRARY | ||
SHARED | ||
STATIC | ||
TARGET_LIBRARY) | ||
TARGET_LIBRARY | ||
INSTALL_WITH_SHARED) | ||
set(SWIFTLIB_SINGLE_single_parameter_options | ||
ARCHITECTURE | ||
DEPLOYMENT_VERSION_IOS | ||
|
@@ -1085,18 +1086,24 @@ function(_add_swift_library_single target name) | |
BINARY_DIR ${SWIFT_RUNTIME_OUTPUT_INTDIR} | ||
LIBRARY_DIR ${SWIFT_LIBRARY_OUTPUT_INTDIR}) | ||
|
||
if(SWIFTLIB_INSTALL_WITH_SHARED) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For this sort of logic I usually prefer: set(swift_lib_dir "${SWIFTSTATICLIB_DIR}")
if(SWIFTLIB_INSTALL_WITH_SHARED)
set(swift_lib_dir "${SWIFTLIB_DIR}")
endif() |
||
set(swift_lib_dir ${SWIFTLIB_DIR}) | ||
else() | ||
set(swift_lib_dir ${SWIFTSTATICLIB_DIR}) | ||
endif() | ||
|
||
foreach(config ${CMAKE_CONFIGURATION_TYPES}) | ||
string(TOUPPER ${config} config_upper) | ||
escape_path_for_xcode( | ||
"${config}" "${SWIFTSTATICLIB_DIR}" config_lib_dir) | ||
"${config}" "${swift_lib_dir}" config_lib_dir) | ||
set_target_properties(${target_static} PROPERTIES | ||
LIBRARY_OUTPUT_DIRECTORY_${config_upper} ${config_lib_dir}/${SWIFTLIB_SINGLE_SUBDIR} | ||
ARCHIVE_OUTPUT_DIRECTORY_${config_upper} ${config_lib_dir}/${SWIFTLIB_SINGLE_SUBDIR}) | ||
endforeach() | ||
|
||
set_target_properties(${target_static} PROPERTIES | ||
LIBRARY_OUTPUT_DIRECTORY ${SWIFTSTATICLIB_DIR}/${SWIFTLIB_SINGLE_SUBDIR} | ||
ARCHIVE_OUTPUT_DIRECTORY ${SWIFTSTATICLIB_DIR}/${SWIFTLIB_SINGLE_SUBDIR}) | ||
LIBRARY_OUTPUT_DIRECTORY ${swift_lib_dir}/${SWIFTLIB_SINGLE_SUBDIR} | ||
ARCHIVE_OUTPUT_DIRECTORY ${swift_lib_dir}/${SWIFTLIB_SINGLE_SUBDIR}) | ||
endif() | ||
|
||
set_target_properties(${target} | ||
|
@@ -1347,8 +1354,14 @@ function(_add_swift_library_single target name) | |
set_property(TARGET "${target_static}" APPEND_STRING PROPERTY | ||
COMPILE_FLAGS " ${c_compile_flags}") | ||
# FIXME: The fallback paths here are going to be dynamic libraries. | ||
|
||
if(SWIFTLIB_INSTALL_WITH_SHARED) | ||
set(search_base_dir ${SWIFTLIB_DIR}) | ||
else() | ||
set(search_base_dir ${SWIFTSTATICLIB_DIR}) | ||
endif() | ||
set(library_search_directories | ||
"${SWIFTSTATICLIB_DIR}/${SWIFTLIB_SINGLE_SUBDIR}" | ||
"${search_base_dir}/${SWIFTLIB_SINGLE_SUBDIR}" | ||
"${SWIFT_NATIVE_SWIFT_TOOLS_PATH}/../lib/swift/${SWIFTLIB_SINGLE_SUBDIR}" | ||
"${SWIFT_NATIVE_SWIFT_TOOLS_PATH}/../lib/swift/${SWIFT_SDK_${SWIFTLIB_SINGLE_SDK}_LIB_SUBDIR}") | ||
swift_target_link_search_directories("${target_static}" "${library_search_directories}") | ||
|
@@ -1477,6 +1490,7 @@ endfunction() | |
# [IS_STDLIB] | ||
# [IS_STDLIB_CORE] | ||
# [TARGET_LIBRARY] | ||
# [INSTALL_WITH_SHARED] | ||
# INSTALL_IN_COMPONENT comp | ||
# DEPLOYMENT_VERSION_OSX version | ||
# DEPLOYMENT_VERSION_IOS version | ||
|
@@ -1583,6 +1597,9 @@ endfunction() | |
# DEPLOYMENT_VERSION_WATCHOS | ||
# The minimum deployment version to build for if this is an WATCHOS library. | ||
# | ||
# INSTALL_WITH_SHARED | ||
# Install a static library target alongside shared libraries | ||
# | ||
# source1 ... | ||
# Sources to add into this library. | ||
function(add_swift_target_library name) | ||
|
@@ -1597,7 +1614,8 @@ function(add_swift_target_library name) | |
OBJECT_LIBRARY | ||
SHARED | ||
STATIC | ||
TARGET_LIBRARY) | ||
TARGET_LIBRARY | ||
INSTALL_WITH_SHARED) | ||
set(SWIFTLIB_single_parameter_options | ||
DEPLOYMENT_VERSION_IOS | ||
DEPLOYMENT_VERSION_OSX | ||
|
@@ -1882,6 +1900,7 @@ function(add_swift_target_library name) | |
${SWIFTLIB_SHARED_keyword} | ||
${SWIFTLIB_STATIC_keyword} | ||
${SWIFTLIB_OBJECT_LIBRARY_keyword} | ||
${SWIFTLIB_INSTALL_WITH_SHARED_keyword} | ||
${SWIFTLIB_SOURCES} | ||
MODULE_TARGET ${MODULE_VARIANT_NAME} | ||
SDK ${sdk} | ||
|
@@ -1996,7 +2015,7 @@ function(add_swift_target_library name) | |
set(resource_dir_sdk_subdir "${SWIFT_SDK_${sdk}_LIB_SUBDIR}") | ||
precondition(resource_dir_sdk_subdir) | ||
|
||
if(SWIFTLIB_SHARED) | ||
if(SWIFTLIB_SHARED OR SWIFTLIB_INSTALL_WITH_SHARED) | ||
set(resource_dir "swift") | ||
set(file_permissions | ||
OWNER_READ OWNER_WRITE OWNER_EXECUTE | ||
|
@@ -2058,10 +2077,18 @@ function(add_swift_target_library name) | |
list(APPEND THIN_INPUT_TARGETS_STATIC "${TARGET}-static") | ||
endforeach() | ||
|
||
if(SWIFTLIB_INSTALL_WITH_SHARED) | ||
set(install_subdir "swift") | ||
set(universal_subdir ${SWIFTLIB_DIR}) | ||
else() | ||
set(install_subdir "swift_static") | ||
set(universal_subdir ${SWIFTSTATICLIB_DIR}) | ||
endif() | ||
|
||
set(lipo_target_static | ||
"${name}-${SWIFT_SDK_${sdk}_LIB_SUBDIR}-static") | ||
set(UNIVERSAL_LIBRARY_NAME | ||
"${SWIFTSTATICLIB_DIR}/${SWIFT_SDK_${sdk}_LIB_SUBDIR}/${CMAKE_STATIC_LIBRARY_PREFIX}${name}${CMAKE_STATIC_LIBRARY_SUFFIX}") | ||
"${universal_subdir}/${SWIFT_SDK_${sdk}_LIB_SUBDIR}/${CMAKE_STATIC_LIBRARY_PREFIX}${name}${CMAKE_STATIC_LIBRARY_SUFFIX}") | ||
_add_swift_lipo_target(SDK | ||
${sdk} | ||
TARGET | ||
|
@@ -2070,7 +2097,7 @@ function(add_swift_target_library name) | |
"${UNIVERSAL_LIBRARY_NAME}" | ||
${THIN_INPUT_TARGETS_STATIC}) | ||
swift_install_in_component(FILES "${UNIVERSAL_LIBRARY_NAME}" | ||
DESTINATION "lib${LLVM_LIBDIR_SUFFIX}/swift_static/${resource_dir_sdk_subdir}" | ||
DESTINATION "lib${LLVM_LIBDIR_SUFFIX}/${install_subdir}/${resource_dir_sdk_subdir}" | ||
PERMISSIONS | ||
OWNER_READ OWNER_WRITE | ||
GROUP_READ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,7 @@ | |
#include "llvm/ADT/StringExtras.h" | ||
#include "llvm/ADT/StringSwitch.h" | ||
#include "llvm/ADT/Triple.h" | ||
#include "llvm/Support/VersionTuple.h" | ||
|
||
using namespace swift; | ||
|
||
|
@@ -313,3 +314,37 @@ llvm::Triple swift::getTargetSpecificModuleTriple(const llvm::Triple &triple) { | |
return triple; | ||
} | ||
|
||
Optional<llvm::VersionTuple> | ||
swift::getSwiftRuntimeCompatibilityVersionForTarget(const llvm::Triple &Triple){ | ||
unsigned Major, Minor, Micro; | ||
|
||
if (Triple.isMacOSX()) { | ||
Triple.getMacOSXVersion(Major, Minor, Micro); | ||
if (Major == 10) { | ||
|
||
if (Minor <= 14) { | ||
return llvm::VersionTuple(5, 0); | ||
} else { | ||
return None; | ||
} | ||
} else { | ||
return None; | ||
} | ||
} else if (Triple.isiOS()) { // includes tvOS | ||
Triple.getiOSVersion(Major, Minor, Micro); | ||
if (Major <= 12) { | ||
|
||
return llvm::VersionTuple(5, 0); | ||
} else { | ||
return None; | ||
} | ||
} else if (Triple.isWatchOS()) { | ||
Triple.getWatchOSVersion(Major, Minor, Micro); | ||
if (Major <= 5) { | ||
return llvm::VersionTuple(5, 0); | ||
} else { | ||
|
||
return None; | ||
} | ||
} else { | ||
return None; | ||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,6 +33,7 @@ | |
#include "llvm/Support/Path.h" | ||
#include "llvm/Support/Process.h" | ||
#include "llvm/Support/Program.h" | ||
#include "llvm/Support/VersionTuple.h" | ||
|
||
using namespace swift; | ||
using namespace swift::driver; | ||
|
@@ -221,42 +222,6 @@ static bool wantsObjCRuntime(const llvm::Triple &triple) { | |
llvm_unreachable("unknown Darwin OS"); | ||
} | ||
|
||
/// Return the earliest backward deployment compatibility version we need to | ||
/// link in for the given target triple, if any. | ||
static Optional<std::pair<unsigned, unsigned>> | ||
getSwiftRuntimeCompatibilityVersionForTarget(const llvm::Triple &Triple) { | ||
unsigned Major, Minor, Micro; | ||
|
||
if (Triple.isMacOSX()) { | ||
Triple.getMacOSXVersion(Major, Minor, Micro); | ||
if (Major == 10) { | ||
if (Minor <= 14) { | ||
return std::make_pair(5u, 0u); | ||
} else { | ||
return None; | ||
} | ||
} else { | ||
return None; | ||
} | ||
} else if (Triple.isiOS()) { // includes tvOS | ||
Triple.getiOSVersion(Major, Minor, Micro); | ||
if (Major <= 12) { | ||
return std::make_pair(5u, 0u); | ||
} else { | ||
return None; | ||
} | ||
} else if (Triple.isWatchOS()) { | ||
Triple.getWatchOSVersion(Major, Minor, Micro); | ||
if (Major <= 5) { | ||
return std::make_pair(5u, 0u); | ||
} else { | ||
return None; | ||
} | ||
} else { | ||
return None; | ||
} | ||
} | ||
|
||
ToolChain::InvocationInfo | ||
toolchains::Darwin::constructInvocation(const LinkJobAction &job, | ||
const JobContext &context) const | ||
|
@@ -431,12 +396,13 @@ toolchains::Darwin::constructInvocation(const LinkJobAction &job, | |
|
||
// Link compatibility libraries, if we're deploying back to OSes that | ||
// have an older Swift runtime. | ||
Optional<std::pair<unsigned, unsigned>> runtimeCompatibilityVersion; | ||
Optional<llvm::VersionTuple> runtimeCompatibilityVersion; | ||
|
||
if (context.Args.hasArg(options::OPT_runtime_compatibility_version)) { | ||
auto value = context.Args.getLastArgValue(options::OPT_runtime_compatibility_version); | ||
auto value = context.Args.getLastArgValue( | ||
options::OPT_runtime_compatibility_version); | ||
|
||
if (value.equals("5.0")) { | ||
runtimeCompatibilityVersion = std::make_pair(5u, 0u); | ||
runtimeCompatibilityVersion = llvm::VersionTuple(5, 0); | ||
} else if (value.equals("none")) { | ||
runtimeCompatibilityVersion = None; | ||
} else { | ||
|
@@ -448,7 +414,7 @@ toolchains::Darwin::constructInvocation(const LinkJobAction &job, | |
} | ||
|
||
if (runtimeCompatibilityVersion) { | ||
if (*runtimeCompatibilityVersion <= std::make_pair(5u, 0u)) { | ||
if (*runtimeCompatibilityVersion <= llvm::VersionTuple(5, 0)) { | ||
// Swift 5.0 compatibility library | ||
SmallString<128> BackDeployLib; | ||
BackDeployLib.append(RuntimeLibPath); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure I agree with adding yet another single purpose flag to
add_swift_target_library
. Is there a more generic purpose here? Say maybe anINSTALL_PATH
or something?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I'm torn about that too. YAGNI convinced me to stick with just the flag for now. A small generalization in between this and INSTALL_PATH might be to have an
INSTALL_AS [SHARED|STATIC]
flag, so you could also choose to send dylibs to the static dir and v.v.?