Skip to content

[clang] Unconditionally add autolink hints for frameworks. #6502

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

Closed
wants to merge 1 commit into from
Closed
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
31 changes: 7 additions & 24 deletions clang/lib/Lex/ModuleMap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -947,28 +947,13 @@ Module *ModuleMap::createHeaderUnit(SourceLocation Loc, StringRef Name,

/// For a framework module, infer the framework against which we
/// should link.
static void inferFrameworkLink(Module *Mod, const DirectoryEntry *FrameworkDir,
FileManager &FileMgr) {
static void inferFrameworkLink(Module *Mod) {
assert(Mod->IsFramework && "Can only infer linking for framework modules");
assert(!Mod->isSubFramework() &&
"Can only infer linking for top-level frameworks");

SmallString<128> LibName;
LibName += FrameworkDir->getName();
llvm::sys::path::append(LibName, Mod->Name);

// The library name of a framework has more than one possible extension since
// the introduction of the text-based dynamic library format. We need to check
// for both before we give up.
for (const char *extension : {"", ".tbd"}) {
llvm::sys::path::replace_extension(LibName, extension);
// Use VFS exists to avoid depending on the file's contents in cached builds
if (FileMgr.getVirtualFileSystem().exists(LibName)) {
Mod->LinkLibraries.push_back(Module::LinkLibrary(Mod->Name,
/*IsFramework=*/true));
return;
}
}
Mod->LinkLibraries.push_back(Module::LinkLibrary(Mod->Name,
/*IsFramework=*/true));
}

Module *ModuleMap::inferFrameworkModule(const DirectoryEntry *FrameworkDir,
Expand Down Expand Up @@ -1147,9 +1132,8 @@ Module *ModuleMap::inferFrameworkModule(const DirectoryEntry *FrameworkDir,

// If the module is a top-level framework, automatically link against the
// framework.
if (!Result->isSubFramework()) {
inferFrameworkLink(Result, FrameworkDir, FileMgr);
}
if (!Result->isSubFramework())
inferFrameworkLink(Result);

return Result;
}
Expand Down Expand Up @@ -2206,9 +2190,8 @@ void ModuleMapParser::parseModuleDecl() {
// If the active module is a top-level framework, and there are no link
// libraries, automatically link against the framework.
if (ActiveModule->IsFramework && !ActiveModule->isSubFramework() &&
ActiveModule->LinkLibraries.empty()) {
inferFrameworkLink(ActiveModule, Directory, SourceMgr.getFileManager());
}
ActiveModule->LinkLibraries.empty())
inferFrameworkLink(ActiveModule);

// If the module meets all requirements but is still unavailable, mark the
// whole tree as unavailable to prevent it from building.
Expand Down
10 changes: 6 additions & 4 deletions clang/test/Modules/use-exportas-for-link.m
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,17 @@
#endif

// RUN: %clang_cc1 -emit-llvm -o - -fmodules-cache-path=%t -DE -fmodules -fimplicit-module-maps -F %S/Inputs/exportas-link %s | FileCheck --check-prefix=CHECK_E %s
// CHECK_E: !llvm.linker.options = !{![[MODULE:[0-9]+]]}
// CHECK_E: ![[MODULE]] = !{!"-framework", !"SomeKitCore"}
// CHECK_E: !llvm.linker.options = !{![[MODULE1:[0-9]+]], ![[MODULE2:[0-9]+]]}
// CHECK_E: ![[MODULE1]] = !{!"-framework", !"OtherKit"}
// CHECK_E: ![[MODULE2]] = !{!"-framework", !"SomeKitCore"}
#ifdef E
@import OtherKit;
#endif

// RUN: %clang_cc1 -emit-llvm -o - -fmodules-cache-path=%t -DF -fmodules -fimplicit-module-maps -F %S/Inputs/exportas-link %s | FileCheck --check-prefix=CHECK_F %s
// CHECK_F: !llvm.linker.options = !{![[MODULE:[0-9]+]]}
// CHECK_F: ![[MODULE]] = !{!"-framework", !"SomeKit"}
// CHECK_F: !llvm.linker.options = !{![[MODULE1:[0-9]+]], ![[MODULE2:[0-9]+]]}
// CHECK_F: ![[MODULE1]] = !{!"-framework", !"OtherKit"}
// CHECK_F: ![[MODULE2]] = !{!"-framework", !"SomeKit"}
#ifdef F
@import OtherKit;
#endif