[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.
This commit is contained in:
Doug Gregor
2020-07-07 23:24:38 -07:00
parent f818a1e1b0
commit 618af0420f
2 changed files with 55 additions and 4 deletions

View File

@@ -1948,8 +1948,36 @@ createJSONFixItDiagnosticConsumerIfNeeded(
});
}
/// Print information about a
static void printCompatibilityLibrary(
llvm::VersionTuple runtimeVersion, llvm::VersionTuple maxVersion,
StringRef filter, StringRef libraryName, bool &printedAny,
llvm::raw_ostream &out) {
if (runtimeVersion > maxVersion)
return;
if (printedAny) {
out << ",";
}
out << "\n";
out << " {\n";
out << " \"libraryName\": \"";
out.write_escaped(libraryName);
out << "\",\n";
out << " \"filter\": \"";
out.write_escaped(filter);
out << "\"\n";
out << " }";
printedAny = true;
}
/// Print information about the target triple in JSON.
static void printTripleInfo(const llvm::Triple &triple,
llvm::Optional<llvm::VersionTuple> runtimeVersion,
llvm::raw_ostream &out) {
out << "{\n";
@@ -1965,11 +1993,26 @@ static void printTripleInfo(const llvm::Triple &triple,
out.write_escaped(getTargetSpecificModuleTriple(triple).getTriple());
out << "\",\n";
if (auto runtimeVersion = getSwiftRuntimeCompatibilityVersionForTarget(
triple)) {
if (runtimeVersion) {
out << " \"swiftRuntimeCompatibilityVersion\": \"";
out.write_escaped(runtimeVersion->getAsString());
out << "\",\n";
// Compatibility libraries that need to be linked.
out << " \"compatibilityLibraries\": [";
bool printedAnyCompatibilityLibrary = false;
#define BACK_DEPLOYMENT_LIB(Version, Filter, LibraryName) \
printCompatibilityLibrary( \
*runtimeVersion, llvm::VersionTuple Version, #Filter, LibraryName, \
printedAnyCompatibilityLibrary, out);
#include "swift/Frontend/BackDeploymentLibs.def"
if (printedAnyCompatibilityLibrary) {
out << "\n ";
}
out << " ],\n";
} else {
out << " \"compatibilityLibraries\": [ ],\n";
}
out << " \"librariesRequireRPath\": "
@@ -1992,14 +2035,16 @@ static void printTargetInfo(const CompilerInvocation &invocation,
out << "\",\n";
// Target triple and target variant triple.
auto runtimeVersion =
invocation.getIRGenOptions().AutolinkRuntimeCompatibilityLibraryVersion;
auto &langOpts = invocation.getLangOptions();
out << " \"target\": ";
printTripleInfo(langOpts.Target, out);
printTripleInfo(langOpts.Target, runtimeVersion, out);
out << ",\n";
if (auto &variant = langOpts.TargetVariant) {
out << " \"targetVariant\": ";
printTripleInfo(*variant, out);
printTripleInfo(*variant, runtimeVersion, out);
out << ",\n";
}