Skip to content

Commit 65ab3f3

Browse files
committed
[Macros] In-process plugin server library tied to compiler host, not target
PR swiftlang#73725 introduced the in-process plugin server library, but the selection of the library depends on the selected toolchain, which depends on the compiler target, not the host. When cross-compiling (for example from macOS to a embedded Unix target), the compiler will incorrectly chose the `.so` file, not find it, and fail to compile things like the `@debugDescription` macro. Move the in-process plugin server library code from the platform toolchains into the parent type, and code it so it uses the right name depending on the compiler host at compilation time. This discards the target and only relies on the compiler host for selecting the right library.
1 parent f795666 commit 65ab3f3

File tree

5 files changed

+26
-15
lines changed

5 files changed

+26
-15
lines changed

include/swift/Driver/ToolChain.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,10 @@ class ToolChain {
344344
virtual void addPluginArguments(const llvm::opt::ArgList &Args,
345345
llvm::opt::ArgStringList &Arguments) const {}
346346

347+
void addInProcPluginServerPath(const StringRef PluginPath,
348+
const llvm::opt::ArgList &Args,
349+
llvm::opt::ArgStringList &Arguments) const;
350+
347351
/// Validates arguments passed to the toolchain.
348352
///
349353
/// An override point for platform-specific subclasses to customize the

lib/Driver/DarwinToolChains.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -138,11 +138,7 @@ toolchains::Darwin::addPluginArguments(const ArgList &Args,
138138
programPath, /*shared=*/true, pluginPath);
139139

140140
// In-process plugin server path.
141-
auto inProcPluginServerPath = pluginPath;
142-
llvm::sys::path::append(inProcPluginServerPath, "host",
143-
"libSwiftInProcPluginServer.dylib");
144-
Arguments.push_back("-in-process-plugin-server-path");
145-
Arguments.push_back(Args.MakeArgString(inProcPluginServerPath));
141+
addInProcPluginServerPath(pluginPath, Args, Arguments);
146142

147143
// Default plugin path.
148144
auto defaultPluginPath = pluginPath;

lib/Driver/ToolChains.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1468,6 +1468,25 @@ void ToolChain::addLinkRuntimeLib(const ArgList &Args, ArgStringList &Arguments,
14681468
Arguments.push_back(Args.MakeArgString(P));
14691469
}
14701470

1471+
void ToolChain::addInProcPluginServerPath(const StringRef PluginPath,
1472+
const llvm::opt::ArgList &Args,
1473+
llvm::opt::ArgStringList &Arguments) const {
1474+
SmallString<128> inProcPluginServerPath = PluginPath;
1475+
llvm::sys::path::append(inProcPluginServerPath, "host",
1476+
#if defined(__APPLE__)
1477+
"libSwiftInProcPluginServer.dylib"
1478+
#elif defined(_WIN32)
1479+
"SwiftInProcPluginServer.dll"
1480+
#elif defined(__unix__)
1481+
"libSwiftInProcPluginServer.so"
1482+
#else
1483+
#error Unknown compiler host
1484+
#endif
1485+
);
1486+
Arguments.push_back("-in-process-plugin-server-path");
1487+
Arguments.push_back(Args.MakeArgString(inProcPluginServerPath));
1488+
}
1489+
14711490
void ToolChain::getClangLibraryPath(const ArgList &Args,
14721491
SmallString<128> &LibPath) const {
14731492
const llvm::Triple &T = getTriple();

lib/Driver/UnixToolChains.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,7 @@ toolchains::GenericUnix::addPluginArguments(const ArgList &Args,
5959
programPath, /*shared=*/true, pluginPath);
6060

6161
// In-process plugin server path.
62-
auto inProcPluginServerPath = pluginPath;
63-
llvm::sys::path::append(inProcPluginServerPath, "host",
64-
"libSwiftInProcPluginServer.so");
65-
Arguments.push_back("-in-process-plugin-server-path");
66-
Arguments.push_back(Args.MakeArgString(inProcPluginServerPath));
62+
addInProcPluginServerPath(pluginPath, Args, Arguments);
6763

6864
// Default plugin path.
6965
auto defaultPluginPath = pluginPath;

lib/Driver/WindowsToolChains.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,7 @@ toolchains::Windows::addPluginArguments(const ArgList &Args,
5151
llvm::sys::path::remove_filename(LibraryPath); // Remove `swift`
5252

5353
// In-process plugin server path.
54-
SmallString<261> InProcPluginServerPath = LibraryPath;
55-
llvm::sys::path::append(InProcPluginServerPath,
56-
"SwiftInProcPluginServer.dll");
57-
Arguments.push_back("-in-process-plugin-server-path");
58-
Arguments.push_back(Args.MakeArgString(InProcPluginServerPath));
54+
addInProcPluginServerPath(LibraryPath, Args, Arguments);
5955

6056
// Default plugin path.
6157
Arguments.push_back("-plugin-path");

0 commit comments

Comments
 (0)