@@ -552,6 +552,7 @@ void ABIDependencyEvaluator::printABIExportMap(llvm::raw_ostream &os) const {
552552// FIXME: Use the VFS instead of handling paths directly. We are particularly
553553// sloppy about handling relative paths in the dependency tracker.
554554static void computeSwiftModuleTraceInfo (
555+ ASTContext &ctx,
555556 const SmallPtrSetImpl<ModuleDecl *> &abiDependencies,
556557 const llvm::DenseMap<StringRef, ModuleDecl *> &pathToModuleDecl,
557558 const DependencyTracker &depTracker, StringRef prebuiltCachePath,
@@ -569,6 +570,8 @@ static void computeSwiftModuleTraceInfo(
569570 SmallVector<std::string, 16 > dependencies{deps.begin (), deps.end ()};
570571 auto incrDeps = depTracker.getIncrementalDependencyPaths ();
571572 dependencies.append (incrDeps.begin (), incrDeps.end ());
573+ auto sharedLibraryExtRegex =
574+ llvm::Regex (" dylib|so|dll" , llvm::Regex::IgnoreCase);
572575 for (const auto &depPath : dependencies) {
573576
574577 // Decide if this is a swiftmodule based on the extension of the raw
@@ -580,8 +583,10 @@ static void computeSwiftModuleTraceInfo(
580583 auto isSwiftmodule = moduleFileType == file_types::TY_SwiftModuleFile;
581584 auto isSwiftinterface =
582585 moduleFileType == file_types::TY_SwiftModuleInterfaceFile;
586+ auto isSharedLibrary =
587+ sharedLibraryExtRegex.match (llvm::sys::path::extension (depPath));
583588
584- if (!(isSwiftmodule || isSwiftinterface))
589+ if (!(isSwiftmodule || isSwiftinterface || isSharedLibrary ))
585590 continue ;
586591
587592 auto dep = pathToModuleDecl.find (depPath);
@@ -637,6 +642,34 @@ static void computeSwiftModuleTraceInfo(
637642 continue ;
638643 }
639644
645+ // If we found a shared library, it must be a compiler plugin dependency.
646+ if (isSharedLibrary) {
647+ // Infer the module name by dropping the library prefix and extension.
648+ // e.g "/path/to/lib/libPlugin.dylib" -> "Plugin"
649+ auto moduleName = llvm::sys::path::stem (depPath);
650+ #if !defined(_WIN32)
651+ moduleName.consume_front (" lib" );
652+ #endif
653+
654+ StringRef realDepPath =
655+ fs::real_path (depPath, buffer, /* expand_tile*/ true )
656+ ? StringRef (depPath)
657+ : buffer.str ();
658+
659+ traceInfo.push_back (
660+ {/* Name=*/
661+ ctx.getIdentifier (moduleName),
662+ /* Path=*/
663+ realDepPath.str (),
664+ /* IsImportedDirectly=*/
665+ false ,
666+ /* SupportsLibraryEvolution=*/
667+ false });
668+ buffer.clear ();
669+
670+ continue ;
671+ }
672+
640673 // Skip cached modules in the prebuilt cache. We will add the corresponding
641674 // swiftinterface from the SDK directly, but this isn't checked. :-/
642675 //
@@ -731,8 +764,9 @@ bool swift::emitLoadedModuleTraceIfNeeded(ModuleDecl *mainModule,
731764 }
732765
733766 std::vector<SwiftModuleTraceInfo> swiftModules;
734- computeSwiftModuleTraceInfo (abiDependencies, pathToModuleDecl, *depTracker,
735- opts.PrebuiltModuleCachePath , swiftModules);
767+ computeSwiftModuleTraceInfo (ctxt, abiDependencies, pathToModuleDecl,
768+ *depTracker, opts.PrebuiltModuleCachePath ,
769+ swiftModules);
736770
737771 LoadedModuleTraceFormat trace = {
738772 /* version=*/ LoadedModuleTraceFormat::CurrentVersion,
0 commit comments