Skip to content

Commit b6028df

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 b6028df

File tree

6 files changed

+22
-3
lines changed

6 files changed

+22
-3
lines changed

include/swift/AST/ModuleLoader.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,8 @@ struct InterfaceSubContextDelegate {
214214
SourceLoc diagLoc,
215215
llvm::function_ref<std::error_code(ASTContext&, ModuleDecl*,
216216
ArrayRef<StringRef>,
217-
ArrayRef<StringRef>, StringRef)> action) = 0;
217+
ArrayRef<StringRef>,
218+
ArrayRef<std::string>, StringRef)> action) = 0;
218219
virtual std::error_code runInSubCompilerInstance(StringRef moduleName,
219220
StringRef interfacePath,
220221
StringRef sdkPath,

include/swift/Frontend/ModuleInterfaceLoader.h

+1
Original file line numberDiff line numberDiff line change
@@ -688,6 +688,7 @@ struct InterfaceSubContextDelegateImpl: InterfaceSubContextDelegate {
688688
SourceLoc diagLoc,
689689
llvm::function_ref<std::error_code(ASTContext&, ModuleDecl*,
690690
ArrayRef<StringRef>, ArrayRef<StringRef>,
691+
ArrayRef<std::string>,
691692
StringRef)> action) override;
692693
std::error_code runInSubCompilerInstance(StringRef moduleName,
693694
StringRef interfacePath,

lib/Frontend/ModuleInterfaceLoader.cpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -2095,14 +2095,16 @@ InterfaceSubContextDelegateImpl::runInSubContext(StringRef moduleName,
20952095
StringRef outputPath,
20962096
SourceLoc diagLoc,
20972097
llvm::function_ref<std::error_code(ASTContext&, ModuleDecl*, ArrayRef<StringRef>,
2098-
ArrayRef<StringRef>, StringRef)> action) {
2098+
ArrayRef<StringRef>, ArrayRef<std::string>, StringRef)> action) {
20992099
return runInSubCompilerInstance(moduleName, interfacePath, sdkPath, outputPath,
21002100
diagLoc, /*silenceErrors=*/false,
21012101
[&](SubCompilerInstanceInfo &info){
2102+
auto irGenOpts = info.Instance->getInvocation().getIRGenOptions();
21022103
return action(info.Instance->getASTContext(),
21032104
info.Instance->getMainModule(),
21042105
info.BuildArguments,
21052106
info.ExtraPCMArgs,
2107+
irGenOpts.PublicLinkLibraries,
21062108
info.Hash);
21072109
});
21082110
}

lib/Serialization/ScanningLoaders.cpp

+8-1
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,8 @@ SwiftModuleScanner::scanInterfaceFile(Twine moduleInterfacePath,
153153
realModuleName.str(), moduleInterfacePath.str(), sdkPath,
154154
StringRef(), SourceLoc(),
155155
[&](ASTContext &Ctx, ModuleDecl *mainMod, ArrayRef<StringRef> BaseArgs,
156-
ArrayRef<StringRef> PCMArgs, StringRef Hash) {
156+
ArrayRef<StringRef> PCMArgs, ArrayRef<std::string> PublicLinkLibs, StringRef Hash) {
157+
157158
assert(mainMod);
158159
std::string InPath = moduleInterfacePath.str();
159160
auto compiledCandidates =
@@ -241,6 +242,12 @@ SwiftModuleScanner::scanInterfaceFile(Twine moduleInterfacePath,
241242
isFramework ? LibraryKind::Framework : LibraryKind::Library,
242243
true});
243244
}
245+
246+
// Register libraries specified by `-public-autolink-library`
247+
for (auto publicLinkLibrary : PublicLinkLibs) {
248+
linkLibraries.push_back(LinkLibrary(publicLinkLibrary, LibraryKind::Library));
249+
}
250+
244251
bool isStatic = llvm::find(ArgsRefs, "-static") != ArgsRefs.end();
245252

246253
Result = ModuleDependencyInfo::forSwiftInterfaceModule(
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

+5
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)