Use autolinking to pull in compatibility libraries.

Many build systems that support Swift don't use swiftc to drive the linker. To make things
easier for these build systems, also use autolinking to pull in the needed compatibility
libraries. This is less ideal than letting the driver add it at link time, since individual
compile jobs don't know whether they're building an executable or not. Introduce a
`-disable-autolink-runtime-compatibility` flag, which build systems that do drive the linker
with swiftc can pass to avoid autolinking.

rdar://problem/50057445
This commit is contained in:
Joe Groff
2019-05-30 12:25:53 -07:00
parent b794cf0c85
commit dffd1b27a1
13 changed files with 156 additions and 50 deletions

View File

@@ -1158,6 +1158,30 @@ static bool ParseIRGenArgs(IRGenOptions &Opts, ArgList &Args,
A->getAsString(Args), A->getValue());
}
}
// Autolink runtime compatibility libraries, if asked to.
if (!Args.hasArg(options::OPT_disable_autolinking_runtime_compatibility)) {
Optional<llvm::VersionTuple> runtimeCompatibilityVersion;
if (auto versionArg = Args.getLastArg(
options::OPT_runtime_compatibility_version)) {
auto version = StringRef(versionArg->getValue());
if (version.equals("none")) {
runtimeCompatibilityVersion = None;
} else if (version.equals("5.0")) {
runtimeCompatibilityVersion = llvm::VersionTuple(5, 0);
} else {
Diags.diagnose(SourceLoc(), diag::error_invalid_arg_value,
versionArg->getAsString(Args), version);
}
} else {
runtimeCompatibilityVersion =
getSwiftRuntimeCompatibilityVersionForTarget(Triple);
}
Opts.AutolinkRuntimeCompatibilityLibraryVersion =
runtimeCompatibilityVersion;
}
return false;
}