-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[Macros] In-process plugin server library tied to compiler host, not target #74785
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Macros] In-process plugin server library tied to compiler host, not target #74785
Conversation
@swift-ci please test |
lib/Driver/WindowsToolChains.cpp
Outdated
SmallString<261> InProcPluginServerPath = LibraryPath; | ||
llvm::sys::path::append(InProcPluginServerPath, | ||
"SwiftInProcPluginServer.dll"); | ||
Arguments.push_back("-in-process-plugin-server-path"); | ||
Arguments.push_back(Args.MakeArgString(InProcPluginServerPath)); | ||
addInProcPluginServerPath(LibraryPath, Args, Arguments); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rintaro what I was commenting in #74740 (comment) about "not fully sure if the code around it is completely correct" is about the calculation of PluginPath
and LibraryPath
. The code right now is part of the *ToolChains.cpp
, but I am not sure if it should move to a more central place as well, since I think it depends on the compiler host, not the target as well.
I can do the change, but I am not sure about its correctness, so I will wait until someone with more knowledge can say if this is the right place or it should be moved out of the *ToolChains.cpp
and into the ToolChains.cpp
file as well.
65ab3f3
to
979c98b
Compare
@swift-ci please test |
lib/Driver/ToolChains.cpp
Outdated
@@ -1468,6 +1468,25 @@ void ToolChain::addLinkRuntimeLib(const ArgList &Args, ArgStringList &Arguments, | |||
Arguments.push_back(Args.MakeArgString(P)); | |||
} | |||
|
|||
void ToolChain::addInProcPluginServerPath(const StringRef PluginPath, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel this is still incorrect. Say when building in macOS targeting Windows, WindowsToolchain
is used, and it passes in the bin
directory. But in macOS hosts this function expects lib/swift
.
Yes, as you said the entire addPluginArguments
looks not doing the right thing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. That's what I was asking in the comment above. It looks like more than this needs to move outside the *ToolChains.cpp
and into ToolChains.cpp
and make it compile conditionally depending on the platform, but I was not completely sure.
If I see things correctly I think this is what is happening:
- In
addPluginArguments
- Calculate a base path.
- Darwin and Unix: Use
computeRuntimeResourcePathFromExecutablePath
- Windows: Use executable path (?)
- Darwin and Unix: Use
- Add the
-in-process-plugin-server-path
(this PR)- Darwin and Unix: Use a "host" directory. Each one with its platform extension.
- Windows: Don't use extra directories. No "lib" prefix and ".dll" extension.
- Add a
-plugin-path
- Darwin and Unix: Uses base path + "host/plugins"
- Windows: Uses the executable path (?)
- Add a local plugin path
- Darwin and Unix: Add a "../../local/lib/swift/host/plugins" with an extra
-plugin-path
- Windows: nothing
- Darwin and Unix: Add a "../../local/lib/swift/host/plugins" with an extra
- Calculate a base path.
- In
addExternalPluginFrontendArgs
andaddPlatformSpecificPluginFrontendArgs
- Only exist on Darwin
- Does this need to be in fact for the Darwin compiler, and not for the Darwin targets?
I think all the code in addPluginArguments
should be tied to the compiler host, and not the target, but I wanted to first have confirmation that this is in fact necessary. There might be something that I don't completely understand about the plugin compilation module. If you agree with the above and can answer about addPlatformSpecificPluginFrontendArgs
I can try to do the changes. I knew this works in the case I was experiencing, probably because the addPluginArguments
ended up being the same for Darwin and Unix after my changes, but I imagine Windows -> Unix will have its own share of problems as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for doing this Daniel!
As for addPluginArguments
, I believe everything you mentioned is correct. In Windows host, everything must be in the same directory as the getDriver().getSwiftProgramPath()
.
As for addExternalPluginFrontendArgs()
, this is for users of the macOS/iOS/etc SDKs, so it's basically tied to the target, and I believe it's fine this is in DarwinToolchain
. That said, since Apple doesn't provide swift-plugin-server
that runs other host platforms, maybe we should wrap this function's body with #if defined(__APPLE__)
, but I don't think it's really necessary.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I hopefully matched the code as close as possible to the one in the swift-driver
. Hopefully it is what you were asking for.
979c98b
to
104ac44
Compare
@swift-ci please smoke test |
lib/Driver/ToolChains.cpp
Outdated
auto swiftProgramPath = getDriver().getSwiftProgramPath(); | ||
#if defined(_WIN32) | ||
SmallString<261> pluginPathBase = StringRef(swiftProgramPath); | ||
llvm::sys::path::remove_filename(pluginPathBase); // Remove `swift` | ||
#elif defined(__APPLE__) || defined(__unix__) | ||
SmallString<64> pluginPathBase; | ||
CompilerInvocation::computeRuntimeResourcePathFromExecutablePath( | ||
swiftProgramPath, /*shared=*/true, pluginPathBase); | ||
#else |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I checked swift-driver
implementation
https://github.com/apple/swift-driver/blob/6d1e5d2bd8e67432176cd843704bd2277616376f/Sources/SwiftDriver/Jobs/FrontendJobHelpers.swift#L793-L802
Since it's all based on the parent of the executable directory. Let's align with it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And yes, adding pluginPathRoot.localPluginPath
in Windows is wrong 😅
https://github.com/apple/swift-driver/blob/6d1e5d2bd8e67432176cd843704bd2277616376f/Sources/SwiftDriver/Jobs/FrontendJobHelpers.swift#L810
ed88c2b
to
177d342
Compare
@swift-ci please smoke test |
177d342
to
eb3cf18
Compare
@swift-ci please smoke test |
…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.
eb3cf18
to
55d9e74
Compare
@swift-ci please smoke test |
@rintaro seems that I got it right this time. Please review the final version and let me know if I should merge. |
Thank you! |
PR #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.