Properly compute resource folder when linking statically

- deduplicate the logic to compute the resource folder
- install headers and module files in shared and static resource folders
- forward -static flag when calling swiftc with -print-target-info
This commit is contained in:
Dario Rexin
2020-07-28 15:17:20 -07:00
parent 6187697a6c
commit 0850436d9f
14 changed files with 241 additions and 29 deletions

View File

@@ -44,16 +44,25 @@ swift::CompilerInvocation::CompilerInvocation() {
}
void CompilerInvocation::computeRuntimeResourcePathFromExecutablePath(
StringRef mainExecutablePath, llvm::SmallString<128> &runtimeResourcePath) {
runtimeResourcePath.assign(mainExecutablePath);
StringRef mainExecutablePath, bool shared,
llvm::SmallVectorImpl<char> &runtimeResourcePath) {
runtimeResourcePath.append(mainExecutablePath.begin(),
mainExecutablePath.end());
llvm::sys::path::remove_filename(runtimeResourcePath); // Remove /swift
llvm::sys::path::remove_filename(runtimeResourcePath); // Remove /bin
llvm::sys::path::append(runtimeResourcePath, "lib", "swift");
appendSwiftLibDir(runtimeResourcePath, shared);
}
void CompilerInvocation::appendSwiftLibDir(llvm::SmallVectorImpl<char> &path,
bool shared) {
llvm::sys::path::append(path, "lib", shared ? "swift" : "swift_static");
}
void CompilerInvocation::setMainExecutablePath(StringRef Path) {
llvm::SmallString<128> LibPath;
computeRuntimeResourcePathFromExecutablePath(Path, LibPath);
computeRuntimeResourcePathFromExecutablePath(
Path, FrontendOpts.UseSharedResourceFolder, LibPath);
setRuntimeResourcePath(LibPath.str());
llvm::SmallString<128> DiagnosticDocsPath(Path);
@@ -1715,11 +1724,10 @@ static bool ParseMigratorArgs(MigratorOptions &Opts,
}
bool CompilerInvocation::parseArgs(
ArrayRef<const char *> Args,
DiagnosticEngine &Diags,
ArrayRef<const char *> Args, DiagnosticEngine &Diags,
SmallVectorImpl<std::unique_ptr<llvm::MemoryBuffer>>
*ConfigurationFileBuffers,
StringRef workingDirectory) {
StringRef workingDirectory, StringRef mainExecutablePath) {
using namespace options;
if (Args.empty())
@@ -1750,6 +1758,10 @@ bool CompilerInvocation::parseArgs(
return true;
}
if (!mainExecutablePath.empty()) {
setMainExecutablePath(mainExecutablePath);
}
ParseModuleInterfaceArgs(ModuleInterfaceOpts, ParsedArgs);
SaveModuleInterfaceArgs(ModuleInterfaceOpts, FrontendOpts, ParsedArgs, Diags);