Skip to content

Commit 4d42b59

Browse files
committed
[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.
1 parent 2f7aa42 commit 4d42b59

File tree

4 files changed

+37
-9
lines changed

4 files changed

+37
-9
lines changed

include/swift/Frontend/Frontend.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,12 @@ class CompilerInvocation {
250250
/// If we haven't explicitly passed -blocklist-paths, set it to the default value.
251251
void setDefaultBlocklistsIfNecessary();
252252

253+
/// If we haven't explicitly passed '-in-process-plugin-server-path', infer
254+
/// it as a default value.
255+
///
256+
/// FIXME: Remove this after all the clients start sending it.
257+
void setDefaultInProcessPluginServerPathIfNecessary();
258+
253259
/// Computes the runtime resource path relative to the given Swift
254260
/// executable.
255261
static void computeRuntimeResourcePathFromExecutablePath(

lib/Frontend/CompilerInvocation.cpp

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,35 @@ void CompilerInvocation::setDefaultBlocklistsIfNecessary() {
187187
}
188188
}
189189

190+
void CompilerInvocation::setDefaultInProcessPluginServerPathIfNecessary() {
191+
if (!SearchPathOpts.InProcessPluginServerPath.empty())
192+
return;
193+
194+
// '/usr/bin/swift'
195+
SmallString<64> serverLibPath{FrontendOpts.MainExecutablePath};
196+
llvm::sys::path::remove_filename(serverLibPath); // remove 'swift'
197+
198+
#if defined(_WIN32)
199+
// Windows: usr\bin\SwiftInProcPluginServer.dll
200+
llvm::sys::path::append(serverLibPath, "SwiftInProcPluginServer.dll");
201+
202+
#elif defined(__APPLE__)
203+
// Darwin: usr/lib/swift/host/libSwiftInProcPluginServer.dylib
204+
llvm::sys::path::remove_filename(serverLibPath); // remove 'bin'
205+
llvm::sys::path::append(serverLibPath, "lib", "swift", "host");
206+
llvm::sys::path::append(serverLibPath, "libSwiftInProcPluginServer.dylib");
207+
208+
#else
209+
// Other: usr/lib/swift/host/libSwiftInProcPluginServer.so
210+
llvm::sys::path::remove_filename(serverLibPath); // remove 'bin'
211+
llvm::sys::path::append(serverLibPath, "lib", "swift", "host");
212+
llvm::sys::path::append(serverLibPath, "libSwiftInProcPluginServer.so");
213+
214+
#endif
215+
216+
SearchPathOpts.InProcessPluginServerPath = serverLibPath.str();
217+
}
218+
190219
static void updateRuntimeLibraryPaths(SearchPathOptions &SearchPathOpts,
191220
const FrontendOptions &FrontendOpts,
192221
const LangOptions &LangOpts) {
@@ -3532,6 +3561,7 @@ bool CompilerInvocation::parseArgs(
35323561
updateRuntimeLibraryPaths(SearchPathOpts, FrontendOpts, LangOpts);
35333562
setDefaultPrebuiltCacheIfNecessary();
35343563
setDefaultBlocklistsIfNecessary();
3564+
setDefaultInProcessPluginServerPathIfNecessary();
35353565

35363566
// Now that we've parsed everything, setup some inter-option-dependent state.
35373567
setIRGenOutputOptsFromFrontendOptions(IRGenOpts, FrontendOpts);

test/lit.cfg

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1272,9 +1272,6 @@ if run_vendor == 'apple':
12721272
config.resource_dir_opt = "-resource-dir %s" % new_resource_dir
12731273
lit_config.note('Using freestanding resource dir: ' + new_resource_dir)
12741274

1275-
config.swift_in_process_plugin_server_path = make_path(config.swift_lib_dir, 'swift', 'host', 'libSwiftInProcPluginServer.dylib')
1276-
config.swift_test_options += " -in-process-plugin-server-path %s" % shell_quote(config.swift_in_process_plugin_server_path)
1277-
12781275
# Auto-linking does not work when stdlib is built with LTO, because linked
12791276
# libraries are discovered too late (after optimizations are applied), and
12801277
# ld64 hits an assert and crashes, or worse, deadlocks. Until ld64 fixes
@@ -1625,9 +1622,6 @@ elif run_os in ['windows-msvc']:
16251622
config.target_msvc_runtime_opt += ' -D_DLL'
16261623
config.target_env_prefix = ''
16271624

1628-
config.swift_in_process_plugin_server_path = make_path(config.swift_bin_dir, 'SwiftInProcPluginServer.dll')
1629-
config.swift_test_options += " -in-process-plugin-server-path %s" % shell_quote(config.swift_in_process_plugin_server_path)
1630-
16311625
config.target_build_swift = \
16321626
('%r -target %s %s %s %s %s %s -libc %s' % \
16331627
(config.swiftc, config.variant_triple, \
@@ -1759,9 +1753,6 @@ elif (run_os in ['linux-gnu', 'linux-gnueabihf', 'freebsd', 'openbsd', 'windows-
17591753
config.target_runtime = "native"
17601754
config.target_swift_autolink_extract = inferSwiftBinary("swift-autolink-extract")
17611755

1762-
config.swift_in_process_plugin_server_path = make_path(config.swift_lib_dir, 'swift', 'host', 'libSwiftInProcPluginServer.so')
1763-
config.swift_test_options += " -in-process-plugin-server-path %s" % shell_quote(config.swift_in_process_plugin_server_path)
1764-
17651756
libdispatch_artifact_dir = config.libdispatch_build_path
17661757
libdispatch_swift_module_dir = make_path(libdispatch_artifact_dir, 'src', 'swift', 'swift')
17671758
libdispatch_source_dir = make_path(config.swift_src_root, os.pardir, 'swift-corelibs-libdispatch')

tools/swift-ide-test/swift-ide-test.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4576,6 +4576,7 @@ int main(int argc, char *argv[]) {
45764576
InitInvok.getSearchPathOptions().PluginSearchOpts.emplace_back(
45774577
PluginSearchOption::PluginPath{path});
45784578
}
4579+
InitInvok.setDefaultInProcessPluginServerPathIfNecessary();
45794580

45804581
// Process the clang arguments last and allow them to override previously
45814582
// set options.

0 commit comments

Comments
 (0)