Skip to content

Commit 618af04

Browse files
committed
[Frontend] Add compatibility libraries to -print-target-info.
The driver and any other client that attempts to properly link Swift code need to know which compatibility libraries should be linked on a per-target basis. Vend that information as part of -print-target-info.
1 parent f818a1e commit 618af04

File tree

2 files changed

+55
-4
lines changed

2 files changed

+55
-4
lines changed

lib/FrontendTool/FrontendTool.cpp

Lines changed: 49 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1948,8 +1948,36 @@ createJSONFixItDiagnosticConsumerIfNeeded(
19481948
});
19491949
}
19501950

1951+
/// Print information about a
1952+
static void printCompatibilityLibrary(
1953+
llvm::VersionTuple runtimeVersion, llvm::VersionTuple maxVersion,
1954+
StringRef filter, StringRef libraryName, bool &printedAny,
1955+
llvm::raw_ostream &out) {
1956+
if (runtimeVersion > maxVersion)
1957+
return;
1958+
1959+
if (printedAny) {
1960+
out << ",";
1961+
}
1962+
1963+
out << "\n";
1964+
out << " {\n";
1965+
1966+
out << " \"libraryName\": \"";
1967+
out.write_escaped(libraryName);
1968+
out << "\",\n";
1969+
1970+
out << " \"filter\": \"";
1971+
out.write_escaped(filter);
1972+
out << "\"\n";
1973+
out << " }";
1974+
1975+
printedAny = true;
1976+
}
1977+
19511978
/// Print information about the target triple in JSON.
19521979
static void printTripleInfo(const llvm::Triple &triple,
1980+
llvm::Optional<llvm::VersionTuple> runtimeVersion,
19531981
llvm::raw_ostream &out) {
19541982
out << "{\n";
19551983

@@ -1965,11 +1993,26 @@ static void printTripleInfo(const llvm::Triple &triple,
19651993
out.write_escaped(getTargetSpecificModuleTriple(triple).getTriple());
19661994
out << "\",\n";
19671995

1968-
if (auto runtimeVersion = getSwiftRuntimeCompatibilityVersionForTarget(
1969-
triple)) {
1996+
if (runtimeVersion) {
19701997
out << " \"swiftRuntimeCompatibilityVersion\": \"";
19711998
out.write_escaped(runtimeVersion->getAsString());
19721999
out << "\",\n";
2000+
2001+
// Compatibility libraries that need to be linked.
2002+
out << " \"compatibilityLibraries\": [";
2003+
bool printedAnyCompatibilityLibrary = false;
2004+
#define BACK_DEPLOYMENT_LIB(Version, Filter, LibraryName) \
2005+
printCompatibilityLibrary( \
2006+
*runtimeVersion, llvm::VersionTuple Version, #Filter, LibraryName, \
2007+
printedAnyCompatibilityLibrary, out);
2008+
#include "swift/Frontend/BackDeploymentLibs.def"
2009+
2010+
if (printedAnyCompatibilityLibrary) {
2011+
out << "\n ";
2012+
}
2013+
out << " ],\n";
2014+
} else {
2015+
out << " \"compatibilityLibraries\": [ ],\n";
19732016
}
19742017

19752018
out << " \"librariesRequireRPath\": "
@@ -1992,14 +2035,16 @@ static void printTargetInfo(const CompilerInvocation &invocation,
19922035
out << "\",\n";
19932036

19942037
// Target triple and target variant triple.
2038+
auto runtimeVersion =
2039+
invocation.getIRGenOptions().AutolinkRuntimeCompatibilityLibraryVersion;
19952040
auto &langOpts = invocation.getLangOptions();
19962041
out << " \"target\": ";
1997-
printTripleInfo(langOpts.Target, out);
2042+
printTripleInfo(langOpts.Target, runtimeVersion, out);
19982043
out << ",\n";
19992044

20002045
if (auto &variant = langOpts.TargetVariant) {
20012046
out << " \"targetVariant\": ";
2002-
printTripleInfo(*variant, out);
2047+
printTripleInfo(*variant, runtimeVersion, out);
20032048
out << ",\n";
20042049
}
20052050

test/Driver/print_target_info.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@
1616
// CHECK-IOS: "unversionedTriple": "arm64-apple-ios",
1717
// CHECK-IOS: "moduleTriple": "arm64-apple-ios",
1818
// CHECK-IOS: "swiftRuntimeCompatibilityVersion": "5.0",
19+
// CHECK-IOS: "compatibilityLibraries": [
20+
// CHECK-IOS: "libraryName": "swiftCompatibility50",
21+
// CHECK-IOS: "libraryName": "swiftCompatibility51",
22+
// CHECK-IOS: "libraryName": "swiftCompatibilityDynamicReplacements"
23+
// CHECK-IOS: "filter": "executable"
24+
// CHECK-IOS: ],
1925
// CHECK-IOS: "librariesRequireRPath": true
2026
// CHECK-IOS: }
2127

0 commit comments

Comments
 (0)