-
Notifications
You must be signed in to change notification settings - Fork 10.6k
[Macros] Add swift-plugin-server executable #64376
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
Changes from 5 commits
c4b3edd
1851ba2
c675ecf
025d874
54884f0
b2542a7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -382,6 +382,11 @@ class SearchPathOptions { | |
| /// macro implementations. | ||
| std::vector<std::string> PluginSearchPaths; | ||
|
|
||
| /// Paths that contain compiler plugins and the path to the plugin server | ||
| /// executable. | ||
| /// e.g. '/path/to/usr/lib/swift/host/plugins#/path/to/usr/bin/plugin-server'. | ||
| std::vector<std::string> ExternalPluginSearchPaths; | ||
|
||
|
|
||
| /// Don't look in for compiler-provided modules. | ||
| bool SkipRuntimeLibraryImportPaths = false; | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -49,6 +49,7 @@ struct ExternalMacroDefinition; | |
| class ClosureExpr; | ||
| class GenericParamList; | ||
| class LabeledStmt; | ||
| class LoadedExecutablePlugin; | ||
| class MacroDefinition; | ||
| class PrecedenceGroupDecl; | ||
| class PropertyWrapperInitializerInfo; | ||
|
|
@@ -4000,19 +4001,51 @@ class ExpandSynthesizedMemberMacroRequest | |
| /// Load a plugin module with the given name. | ||
| /// | ||
| /// | ||
| class LoadedCompilerPlugin { | ||
| enum class PluginKind : uint8_t { | ||
| None, | ||
| InProcess, | ||
| Executable, | ||
| }; | ||
| PluginKind kind; | ||
| void *ptr; | ||
|
|
||
| LoadedCompilerPlugin(PluginKind kind, void *ptr) : kind(kind), ptr(ptr) { | ||
| assert(ptr != nullptr || kind == PluginKind::None); | ||
| } | ||
|
|
||
| public: | ||
| LoadedCompilerPlugin(std::nullptr_t) : kind(PluginKind::None), ptr(nullptr) {} | ||
|
|
||
| static LoadedCompilerPlugin inProcess(void *ptr) { | ||
| return {PluginKind::InProcess, ptr}; | ||
| } | ||
| static LoadedCompilerPlugin executable(LoadedExecutablePlugin *ptr) { | ||
| return {PluginKind::Executable, ptr}; | ||
| } | ||
|
|
||
| void *getAsInProcessPlugin() const { | ||
| return kind == PluginKind::InProcess ? static_cast<void *>(ptr) : nullptr; | ||
|
||
| } | ||
| LoadedExecutablePlugin *getAsExecutablePlugin() const { | ||
| return kind == PluginKind::Executable | ||
| ? static_cast<LoadedExecutablePlugin *>(ptr) | ||
| : nullptr; | ||
| } | ||
| }; | ||
|
|
||
| class CompilerPluginLoadRequest | ||
| : public SimpleRequest<CompilerPluginLoadRequest, | ||
| void *(ASTContext *, Identifier), | ||
| RequestFlags::Cached> { | ||
| : public SimpleRequest<CompilerPluginLoadRequest, | ||
| LoadedCompilerPlugin(ASTContext *, Identifier), | ||
| RequestFlags::Cached> { | ||
| public: | ||
| using SimpleRequest::SimpleRequest; | ||
|
|
||
| private: | ||
| friend SimpleRequest; | ||
|
|
||
| void *evaluate( | ||
| Evaluator &evaluator, ASTContext *ctx, Identifier moduleName | ||
| ) const; | ||
| LoadedCompilerPlugin evaluate(Evaluator &evaluator, ASTContext *ctx, | ||
| Identifier moduleName) const; | ||
|
|
||
| public: | ||
| // Source location | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -67,6 +67,7 @@ | |
| #include "llvm/ADT/Statistic.h" | ||
| #include "llvm/ADT/StringMap.h" | ||
| #include "llvm/ADT/StringSwitch.h" | ||
| #include "llvm/Config/config.h" | ||
|
||
| #include "llvm/IR/LLVMContext.h" | ||
| #include "llvm/Support/Allocator.h" | ||
| #include "llvm/Support/Compiler.h" | ||
|
|
@@ -6344,15 +6345,34 @@ Type ASTContext::getNamedSwiftType(ModuleDecl *module, StringRef name) { | |
| return decl->getDeclaredInterfaceType(); | ||
| } | ||
|
|
||
| LoadedExecutablePlugin * | ||
| Optional<StringRef> | ||
| ASTContext::lookupExecutablePluginByModuleName(Identifier moduleName) { | ||
| auto &execPluginPaths = getImpl().ExecutablePluginPaths; | ||
| auto found = execPluginPaths.find(moduleName); | ||
| if (found == execPluginPaths.end()) | ||
| return nullptr; | ||
| return None; | ||
| return found->second; | ||
| } | ||
|
|
||
| Optional<std::pair<std::string, std::string>> | ||
| ASTContext::lookupExternalLibraryPluginByModuleName(Identifier moduleName) { | ||
| auto fs = this->SourceMgr.getFileSystem(); | ||
| for (auto &pair : SearchPathOpts.ExternalPluginSearchPaths) { | ||
| StringRef searchPath; | ||
| StringRef serverPath; | ||
| std::tie(searchPath, serverPath) = StringRef(pair).split('#'); | ||
|
|
||
| SmallString<128> fullPath(searchPath); | ||
| llvm::sys::path::append(fullPath, "lib" + moduleName.str() + LTDL_SHLIB_EXT); | ||
|
|
||
| if (fs->exists(fullPath)) { | ||
| return {{std::string(fullPath), serverPath.str()}}; | ||
| } | ||
| } | ||
| return None; | ||
| } | ||
|
|
||
| // Let the VFS to map the path. | ||
| auto &path = found->second; | ||
| LoadedExecutablePlugin *ASTContext::loadExecutablePlugin(StringRef path) { | ||
| SmallString<128> resolvedPath; | ||
| auto fs = this->SourceMgr.getFileSystem(); | ||
| if (auto err = fs->getRealPath(path, resolvedPath)) { | ||
|
|
||
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.
Type on
equialent. But how about:One problem with
getRealPathhere is that it's possible that the overlay hasuseExternalNameset to false, in which case that still won't give the real path 😓.