Skip to content

Commit c53a7f9

Browse files
[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.
1 parent 6a11171 commit c53a7f9

File tree

3 files changed

+24
-4
lines changed

3 files changed

+24
-4
lines changed

lib/Serialization/ScanningLoaders.cpp

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -149,11 +149,17 @@ SwiftModuleScanner::scanInterfaceFile(Twine moduleInterfacePath,
149149
llvm::SmallString<32> modulePath = realModuleName.str();
150150
llvm::sys::path::replace_extension(modulePath, newExt);
151151
std::optional<ModuleDependencyInfo> Result;
152-
std::error_code code = astDelegate.runInSubContext(
152+
std::error_code code = astDelegate.runInSubCompilerInstance(
153153
realModuleName.str(), moduleInterfacePath.str(), sdkPath,
154-
StringRef(), SourceLoc(),
155-
[&](ASTContext &Ctx, ModuleDecl *mainMod, ArrayRef<StringRef> BaseArgs,
156-
ArrayRef<StringRef> PCMArgs, StringRef Hash) {
154+
StringRef(), SourceLoc(), /*silenceErrors=*/false,
155+
[&](SubCompilerInstanceInfo &info) {
156+
ASTContext &Ctx = info.Instance->getASTContext();
157+
ModuleDecl *mainMod = info.Instance->getMainModule();
158+
ArrayRef<StringRef> BaseArgs = info.BuildArguments;
159+
ArrayRef<StringRef> PCMArgs = info.ExtraPCMArgs;
160+
StringRef Hash = info.Hash;
161+
const CompilerInvocation &Invocation = info.Instance->getInvocation();
162+
157163
assert(mainMod);
158164
std::string InPath = moduleInterfacePath.str();
159165
auto compiledCandidates =
@@ -241,6 +247,12 @@ SwiftModuleScanner::scanInterfaceFile(Twine moduleInterfacePath,
241247
isFramework ? LibraryKind::Framework : LibraryKind::Library,
242248
true});
243249
}
250+
251+
// Register libraries specified by `-public-autolink-library`
252+
for (auto publicLinkLibrary : Invocation.getIRGenOptions().PublicLinkLibraries) {
253+
linkLibraries.push_back(LinkLibrary(publicLinkLibrary, LibraryKind::Library));
254+
}
255+
244256
bool isStatic = llvm::find(ArgsRefs, "-static") != ArgsRefs.end();
245257

246258
Result = ModuleDependencyInfo::forSwiftInterfaceModule(
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// swift-interface-format-version: 1.0
2+
// swift-module-flags: -module-name HasLinkDependency -public-autolink-library linkDep
3+
import Swift

test/ScanDependencies/module_deps_link_libs.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import C
99
import E
1010
import G
1111
import SubE
12+
import HasLinkDependency
1213

1314
// CHECK: "mainModuleName": "deps"
1415

@@ -33,6 +34,10 @@ import SubE
3334
// CHECK-NEXT: "isFramework": false,
3435
// CHECK-NEXT: "shouldForceLoad": true
3536

37+
// CHECK-DAG: "linkName": "linkDep",
38+
// CHECK-NEXT: "isFramework": false,
39+
// CHECK-NEXT: "shouldForceLoad": false
40+
3641
// CHECK-DAG: "linkName": "nonSwiftyLibC",
3742
// CHECK-NEXT: "isFramework": true,
3843
// CHECK-NEXT: "shouldForceLoad": false

0 commit comments

Comments
 (0)