[Macros] Infer in-process plugin server in swift-frontend

Not all driver can send '-in-process-plugin-server-path'. To keep
existing '-plugin-path' working, infer default server path in the
frontend.
This commit is contained in:
Rintaro Ishizaki
2024-06-20 10:38:39 -07:00
parent 2f7aa428db
commit f08d69c6d7
4 changed files with 39 additions and 9 deletions

View File

@@ -187,6 +187,37 @@ void CompilerInvocation::setDefaultBlocklistsIfNecessary() {
}
}
void CompilerInvocation::setDefaultInProcessPluginServerPathIfNecessary() {
if (!SearchPathOpts.InProcessPluginServerPath.empty())
return;
if (FrontendOpts.MainExecutablePath.empty())
return;
// '/usr/bin/swift'
SmallString<64> serverLibPath{FrontendOpts.MainExecutablePath};
llvm::sys::path::remove_filename(serverLibPath); // remove 'swift'
#if defined(_WIN32)
// Windows: usr\bin\SwiftInProcPluginServer.dll
llvm::sys::path::append(serverLibPath, "SwiftInProcPluginServer.dll");
#elif defined(__APPLE__)
// Darwin: usr/lib/swift/host/libSwiftInProcPluginServer.dylib
llvm::sys::path::remove_filename(serverLibPath); // remove 'bin'
llvm::sys::path::append(serverLibPath, "lib", "swift", "host");
llvm::sys::path::append(serverLibPath, "libSwiftInProcPluginServer.dylib");
#else
// Other: usr/lib/swift/host/libSwiftInProcPluginServer.so
llvm::sys::path::remove_filename(serverLibPath); // remove 'bin'
llvm::sys::path::append(serverLibPath, "lib", "swift", "host");
llvm::sys::path::append(serverLibPath, "libSwiftInProcPluginServer.so");
#endif
SearchPathOpts.InProcessPluginServerPath = serverLibPath.str();
}
static void updateRuntimeLibraryPaths(SearchPathOptions &SearchPathOpts,
const FrontendOptions &FrontendOpts,
const LangOptions &LangOpts) {
@@ -3532,6 +3563,7 @@ bool CompilerInvocation::parseArgs(
updateRuntimeLibraryPaths(SearchPathOpts, FrontendOpts, LangOpts);
setDefaultPrebuiltCacheIfNecessary();
setDefaultBlocklistsIfNecessary();
setDefaultInProcessPluginServerPathIfNecessary();
// Now that we've parsed everything, setup some inter-option-dependent state.
setIRGenOutputOptsFromFrontendOptions(IRGenOpts, FrontendOpts);