Skip to content

[ScanDependency] Track link libraries specified by -public-autolink-library option #74278

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion include/swift/AST/ModuleLoader.h
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,8 @@ struct InterfaceSubContextDelegate {
SourceLoc diagLoc,
llvm::function_ref<std::error_code(ASTContext&, ModuleDecl*,
ArrayRef<StringRef>,
ArrayRef<StringRef>, StringRef)> action) = 0;
ArrayRef<StringRef>,
ArrayRef<std::string>, StringRef)> action) = 0;
virtual std::error_code runInSubCompilerInstance(StringRef moduleName,
StringRef interfacePath,
StringRef sdkPath,
Expand Down
1 change: 1 addition & 0 deletions include/swift/Frontend/ModuleInterfaceLoader.h
Original file line number Diff line number Diff line change
Expand Up @@ -688,6 +688,7 @@ struct InterfaceSubContextDelegateImpl: InterfaceSubContextDelegate {
SourceLoc diagLoc,
llvm::function_ref<std::error_code(ASTContext&, ModuleDecl*,
ArrayRef<StringRef>, ArrayRef<StringRef>,
ArrayRef<std::string>,
StringRef)> action) override;
std::error_code runInSubCompilerInstance(StringRef moduleName,
StringRef interfacePath,
Expand Down
4 changes: 3 additions & 1 deletion lib/Frontend/ModuleInterfaceLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2095,14 +2095,16 @@ InterfaceSubContextDelegateImpl::runInSubContext(StringRef moduleName,
StringRef outputPath,
SourceLoc diagLoc,
llvm::function_ref<std::error_code(ASTContext&, ModuleDecl*, ArrayRef<StringRef>,
ArrayRef<StringRef>, StringRef)> action) {
ArrayRef<StringRef>, ArrayRef<std::string>, 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);
});
}
Expand Down
9 changes: 8 additions & 1 deletion lib/Serialization/ScanningLoaders.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,8 @@ SwiftModuleScanner::scanInterfaceFile(Twine moduleInterfacePath,
realModuleName.str(), moduleInterfacePath.str(), sdkPath,
StringRef(), SourceLoc(),
[&](ASTContext &Ctx, ModuleDecl *mainMod, ArrayRef<StringRef> BaseArgs,
ArrayRef<StringRef> PCMArgs, StringRef Hash) {
ArrayRef<StringRef> PCMArgs, ArrayRef<std::string> PublicLinkLibs, StringRef Hash) {

assert(mainMod);
std::string InPath = moduleInterfacePath.str();
auto compiledCandidates =
Expand Down Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// swift-interface-format-version: 1.0
// swift-module-flags: -module-name HasLinkDependency -public-autolink-library linkDep
import Swift
5 changes: 5 additions & 0 deletions test/ScanDependencies/module_deps_link_libs.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import C
import E
import G
import SubE
import HasLinkDependency

// CHECK: "mainModuleName": "deps"

Expand All @@ -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
Expand Down