Skip to content

Ensure that we link the right set of compatibility libraries on Apple OS's #39738

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

Merged
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
2 changes: 1 addition & 1 deletion include/swift/Frontend/BackDeploymentLibs.def
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@
BACK_DEPLOYMENT_LIB((5, 0), all, "swiftCompatibility50")
BACK_DEPLOYMENT_LIB((5, 1), all, "swiftCompatibility51")
BACK_DEPLOYMENT_LIB((5, 0), executable, "swiftCompatibilityDynamicReplacements")
BACK_DEPLOYMENT_LIB((5, 5), all, "swiftCompatibilityConcurrency")
BACK_DEPLOYMENT_LIB((5, 4), all, "swiftCompatibilityConcurrency")

#undef BACK_DEPLOYMENT_LIB
43 changes: 32 additions & 11 deletions lib/Basic/Platform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -395,32 +395,46 @@ swift::getSwiftRuntimeCompatibilityVersionForTarget(
}
}
} else if (Major == 11) {
return floorFor64(llvm::VersionTuple(5, 3));
if (Minor <= 3)
return floorFor64(llvm::VersionTuple(5, 3));

return floorFor64(llvm::VersionTuple(5, 4));
} else if (Major == 12) {
return floorFor64(llvm::VersionTuple(5, 5));
}
} else if (Triple.isiOS()) { // includes tvOS
Triple.getiOSVersion(Major, Minor, Micro);

auto floorFor64e = [&Triple](llvm::VersionTuple v) {
auto floorForArchitecture = [&Triple, Major](llvm::VersionTuple v) {
// arm64 simulators and macCatalyst are introduced in iOS 14.0/tvOS 14.0
// with Swift 5.3
if (Triple.isAArch64() && Major <= 14 &&
(Triple.isSimulatorEnvironment() ||
Triple.isMacCatalystEnvironment()))
return MAX(v, llvm::VersionTuple(5, 3));

if (Triple.getArchName() != "arm64e") return v;

// iOS got first arm64e support in 12.0, which has a Swift runtime version
// older than 5.0, so let's floor at VersionTuple(5, 0) instead.
return MAX(v, llvm::VersionTuple(5, 0));
};

// arm64 simulators and macCatalyst are introduced in iOS 14.0/tvOS 14.0
// with Swift 5.3
if (Triple.isAArch64() && Major <= 14 &&
(Triple.isSimulatorEnvironment() || Triple.isMacCatalystEnvironment()))
return floorFor64e(llvm::VersionTuple(5, 3));

if (Major <= 12) {
return floorFor64e(llvm::VersionTuple(5, 0));
return floorForArchitecture(llvm::VersionTuple(5, 0));
} else if (Major <= 13) {
if (Minor <= 3) {
return floorFor64e(llvm::VersionTuple(5, 1));
return floorForArchitecture(llvm::VersionTuple(5, 1));
} else {
return floorFor64e(llvm::VersionTuple(5, 2));
return floorForArchitecture(llvm::VersionTuple(5, 2));
}
} else if (Major <= 14) {
if (Minor <= 4)
return floorForArchitecture(llvm::VersionTuple(5, 3));

return floorForArchitecture(llvm::VersionTuple(5, 4));
} else if (Major <= 15) {
return floorForArchitecture(llvm::VersionTuple(5, 5));
}
} else if (Triple.isWatchOS()) {
auto floorFor64bits = [&Triple](llvm::VersionTuple v) {
Expand All @@ -438,6 +452,13 @@ swift::getSwiftRuntimeCompatibilityVersionForTarget(
} else {
return floorFor64bits(llvm::VersionTuple(5, 2));
}
} else if (Major <= 7) {
if (Minor <= 4)
return floorFor64bits(llvm::VersionTuple(5, 3));

return floorFor64bits(llvm::VersionTuple(5, 4));
} else if (Major <= 8) {
return floorFor64bits(llvm::VersionTuple(5, 5));
}
}

Expand Down
3 changes: 2 additions & 1 deletion stdlib/public/BackDeployConcurrency/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ add_compile_definitions(SWIFT_CONCURRENCY_BACK_DEPLOYMENT)
set(swift_concurrency_install_component back-deployment)
set(swift_concurrency_options
BACK_DEPLOYMENT_LIBRARY 5.5
DARWIN_INSTALL_NAME_DIR "@rpath")
DARWIN_INSTALL_NAME_DIR "@rpath"
LINK_FLAGS -lobjc)
set(swift_concurrency_extra_sources
"../BackDeployConcurrency/Exclusivity.cpp"
"../BackDeployConcurrency/Metadata.cpp"
Expand Down
24 changes: 21 additions & 3 deletions test/IRGen/autolink-runtime-compatibility.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@
// Only autolinks 5.1 compatibility library because target OS has 5.1
// RUN: %target-swift-frontend -target %target-cpu-apple-macosx10.15 -emit-ir -parse-stdlib %s | %FileCheck -check-prefix=FORCE-LOAD-51 %s

// Only autolinks concurrency compatibility library because target OS has 5.3
// RUN: %target-swift-frontend -target %target-cpu-apple-macosx11 -emit-ir -parse-stdlib %s | %FileCheck -check-prefix=FORCE-LOAD-53 %s

// Only autolinks concurrency compatibility library because target OS has 5.4
// RUN: %target-swift-frontend -target %target-cpu-apple-macosx11.3 -emit-ir -parse-stdlib %s | %FileCheck -check-prefix=FORCE-LOAD-54 %s

// Autolinks because compatibility library was explicitly asked for
// RUN: %target-swift-frontend -runtime-compatibility-version 5.0 -emit-ir -parse-stdlib %s | %FileCheck -check-prefix=FORCE-LOAD %s
// RUN: %target-swift-frontend -runtime-compatibility-version 5.1 -emit-ir -parse-stdlib %s | %FileCheck -check-prefix=FORCE-LOAD-51 %s
Expand Down Expand Up @@ -50,15 +56,27 @@ public func foo() {}
// FORCE-LOAD-51-NOT: @"_swift_FORCE_LOAD_$_swiftCompatibility50"
// FORCE-LOAD-51-NOT: @"_swift_FORCE_LOAD_$_swiftCompatibilityDynamicReplacements"

// FORCE-LOAD-53-NOT: @"_swift_FORCE_LOAD_$_swiftCompatibility50"
// FORCE-LOAD-53-NOT: @"_swift_FORCE_LOAD_$_swiftCompatibilityDynamicReplacements"
// FORCE-LOAD-53-NOT: @"_swift_FORCE_LOAD_$_swiftCompatibility51"
// FORCE-LOAD-53-DAG: declare {{.*}} @"_swift_FORCE_LOAD_$_swiftCompatibilityConcurrency"
// FORCE-LOAD-53-DAG: [[AUTOLINK_SWIFT_COMPAT_CONCURRENCY:![0-9]+]] = !{!"-lswiftCompatibilityConcurrency"}

// FORCE-LOAD-54-NOT: @"_swift_FORCE_LOAD_$_swiftCompatibility50"
// FORCE-LOAD-54-NOT: @"_swift_FORCE_LOAD_$_swiftCompatibilityDynamicReplacements"
// FORCE-LOAD-54-NOT: @"_swift_FORCE_LOAD_$_swiftCompatibility51"
// FORCE-LOAD-54-DAG: declare {{.*}} @"_swift_FORCE_LOAD_$_swiftCompatibilityConcurrency"
// FORCE-LOAD-54-DAG: [[AUTOLINK_SWIFT_COMPAT_CONCURRENCY:![0-9]+]] = !{!"-lswiftCompatibilityConcurrency"}

// FORCE-LOAD-55-NOT: @"_swift_FORCE_LOAD_$_swiftCompatibility51"

// FORCE-LOAD-55-NOT: @"_swift_FORCE_LOAD_$_swiftCompatibility50"
// FORCE-LOAD-55-NOT: @"_swift_FORCE_LOAD_$_swiftCompatibilityDynamicReplacements"
// FORCE-LOAD-55-NOT: @"_swift_FORCE_LOAD_$_swiftCompatibility51"
// FORCE-LOAD-55-DAG: declare {{.*}} @"_swift_FORCE_LOAD_$_swiftCompatibilityConcurrency"
// FORCE-LOAD-55-NOT: @"_swift_FORCE_LOAD_$_swiftCompatibilityConcurrency"
// FORCE-LOAD-55-NOT: @"_swift_FORCE_LOAD_$_swiftCompatibility50"
// FORCE-LOAD-55-NOT: @"_swift_FORCE_LOAD_$_swiftCompatibilityDynamicReplacements"
// FORCE-LOAD-55-NOT: @"_swift_FORCE_LOAD_$_swiftCompatibility51"
// FORCE-LOAD-55-DAG: [[AUTOLINK_SWIFT_COMPAT_CONCURRENCY:![0-9]+]] = !{!"-lswiftCompatibilityConcurrency"}
// FORCE-LOAD-55-DAG: !llvm.linker.options = !{{{.*}}[[AUTOLINK_SWIFT_COMPAT_CONCURRENCY]]{{[,}]}}
// FORCE-LOAD-55-NOT: @"_swift_FORCE_LOAD_$_swiftCompatibility50"
// FORCE-LOAD-55-NOT: @"_swift_FORCE_LOAD_$_swiftCompatibilityDynamicReplacements"
// FORCE-LOAD-55-NOT: @"_swift_FORCE_LOAD_$_swiftCompatibility51"