From 3ccafc91abbbf5dec13c752c4c6bdb957973f049 Mon Sep 17 00:00:00 2001 From: Yuta Saito Date: Tue, 11 Jun 2024 03:30:33 +0000 Subject: [PATCH] [ScanDependency] Track link libraries specified by `-public-autolink-library` option `explicit-auto-linking` mode should track library dependencies specified by `-public-autolink-library` option too. --- include/swift/AST/ModuleLoader.h | 3 ++- include/swift/Frontend/ModuleInterfaceLoader.h | 1 + lib/Frontend/ModuleInterfaceLoader.cpp | 4 +++- lib/Serialization/ScanningLoaders.cpp | 9 ++++++++- .../Inputs/Swift/HasLinkDependency.swiftinterface | 3 +++ test/ScanDependencies/module_deps_link_libs.swift | 5 +++++ 6 files changed, 22 insertions(+), 3 deletions(-) create mode 100644 test/ScanDependencies/Inputs/Swift/HasLinkDependency.swiftinterface diff --git a/include/swift/AST/ModuleLoader.h b/include/swift/AST/ModuleLoader.h index 1e4f234abeb20..d6827dfa4261e 100644 --- a/include/swift/AST/ModuleLoader.h +++ b/include/swift/AST/ModuleLoader.h @@ -214,7 +214,8 @@ struct InterfaceSubContextDelegate { SourceLoc diagLoc, llvm::function_ref, - ArrayRef, StringRef)> action) = 0; + ArrayRef, + ArrayRef, StringRef)> action) = 0; virtual std::error_code runInSubCompilerInstance(StringRef moduleName, StringRef interfacePath, StringRef sdkPath, diff --git a/include/swift/Frontend/ModuleInterfaceLoader.h b/include/swift/Frontend/ModuleInterfaceLoader.h index 8b2c6449f7004..ab47745d869c4 100644 --- a/include/swift/Frontend/ModuleInterfaceLoader.h +++ b/include/swift/Frontend/ModuleInterfaceLoader.h @@ -688,6 +688,7 @@ struct InterfaceSubContextDelegateImpl: InterfaceSubContextDelegate { SourceLoc diagLoc, llvm::function_ref, ArrayRef, + ArrayRef, StringRef)> action) override; std::error_code runInSubCompilerInstance(StringRef moduleName, StringRef interfacePath, diff --git a/lib/Frontend/ModuleInterfaceLoader.cpp b/lib/Frontend/ModuleInterfaceLoader.cpp index 2b73ce3e38c60..2864438ee9f3c 100644 --- a/lib/Frontend/ModuleInterfaceLoader.cpp +++ b/lib/Frontend/ModuleInterfaceLoader.cpp @@ -2095,14 +2095,16 @@ InterfaceSubContextDelegateImpl::runInSubContext(StringRef moduleName, StringRef outputPath, SourceLoc diagLoc, llvm::function_ref, - ArrayRef, StringRef)> action) { + ArrayRef, ArrayRef, StringRef)> action) { return runInSubCompilerInstance(moduleName, interfacePath, sdkPath, outputPath, diagLoc, /*silenceErrors=*/false, [&](SubCompilerInstanceInfo &info){ + auto irGenOpts = info.Instance->getInvocation().getIRGenOptions(); return action(info.Instance->getASTContext(), info.Instance->getMainModule(), info.BuildArguments, info.ExtraPCMArgs, + irGenOpts.PublicLinkLibraries, info.Hash); }); } diff --git a/lib/Serialization/ScanningLoaders.cpp b/lib/Serialization/ScanningLoaders.cpp index be657331dfecf..3e3dc7e683b39 100644 --- a/lib/Serialization/ScanningLoaders.cpp +++ b/lib/Serialization/ScanningLoaders.cpp @@ -153,7 +153,8 @@ SwiftModuleScanner::scanInterfaceFile(Twine moduleInterfacePath, realModuleName.str(), moduleInterfacePath.str(), sdkPath, StringRef(), SourceLoc(), [&](ASTContext &Ctx, ModuleDecl *mainMod, ArrayRef BaseArgs, - ArrayRef PCMArgs, StringRef Hash) { + ArrayRef PCMArgs, ArrayRef PublicLinkLibs, StringRef Hash) { + assert(mainMod); std::string InPath = moduleInterfacePath.str(); auto compiledCandidates = @@ -241,6 +242,12 @@ SwiftModuleScanner::scanInterfaceFile(Twine moduleInterfacePath, isFramework ? LibraryKind::Framework : LibraryKind::Library, true}); } + + // Register libraries specified by `-public-autolink-library` + for (auto publicLinkLibrary : PublicLinkLibs) { + linkLibraries.push_back(LinkLibrary(publicLinkLibrary, LibraryKind::Library)); + } + bool isStatic = llvm::find(ArgsRefs, "-static") != ArgsRefs.end(); Result = ModuleDependencyInfo::forSwiftInterfaceModule( diff --git a/test/ScanDependencies/Inputs/Swift/HasLinkDependency.swiftinterface b/test/ScanDependencies/Inputs/Swift/HasLinkDependency.swiftinterface new file mode 100644 index 0000000000000..7e44f827b9990 --- /dev/null +++ b/test/ScanDependencies/Inputs/Swift/HasLinkDependency.swiftinterface @@ -0,0 +1,3 @@ +// swift-interface-format-version: 1.0 +// swift-module-flags: -module-name HasLinkDependency -public-autolink-library linkDep +import Swift diff --git a/test/ScanDependencies/module_deps_link_libs.swift b/test/ScanDependencies/module_deps_link_libs.swift index 6b27388bc54cd..840ce4f6a9f72 100644 --- a/test/ScanDependencies/module_deps_link_libs.swift +++ b/test/ScanDependencies/module_deps_link_libs.swift @@ -9,6 +9,7 @@ import C import E import G import SubE +import HasLinkDependency // CHECK: "mainModuleName": "deps" @@ -29,6 +30,10 @@ import SubE // CHECK-NEXT: "isFramework": false, // CHECK-NEXT: "shouldForceLoad": false +// CHECK-DAG: "linkName": "linkDep", +// CHECK-NEXT: "isFramework": false, +// CHECK-NEXT: "shouldForceLoad": false + // CHECK-DAG: "linkName": "swiftyLibE", // CHECK-NEXT: "isFramework": false, // CHECK-NEXT: "shouldForceLoad": true