Skip to content

Commit bdb3da8

Browse files
committed
Frontend: allow directory layout for Swift on non-Darwin platforms
Adjust the serialized module loader to allow directory layouts for the Swift module on non-Darwin targets, unifying the layout across all the platforms. It also eases cross-architecture and cross-platform development by having the same layout, which can enable more similar flag usage.
1 parent 1298f71 commit bdb3da8

File tree

2 files changed

+14
-10
lines changed

2 files changed

+14
-10
lines changed

lib/Frontend/CompilerInvocation.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,10 +137,14 @@ static void updateRuntimeLibraryPaths(SearchPathOptions &SearchPathOpts,
137137
if (SearchPathOpts.SkipRuntimeLibraryImportPaths)
138138
return;
139139

140-
if (!Triple.isOSDarwin())
141-
llvm::sys::path::append(LibPath, swift::getMajorArchitectureName(Triple));
142140
SearchPathOpts.RuntimeLibraryImportPaths.push_back(std::string(LibPath.str()));
143141

142+
// This is compatibility for <=5.3
143+
if (!Triple.isOSDarwin()) {
144+
llvm::sys::path::append(LibPath, swift::getMajorArchitectureName(Triple));
145+
SearchPathOpts.RuntimeLibraryImportPaths.push_back(std::string(LibPath.str()));
146+
}
147+
144148
if (!SearchPathOpts.SDKPath.empty()) {
145149
if (tripleIsMacCatalystEnvironment(Triple)) {
146150
LibPath = SearchPathOpts.SDKPath;

lib/Serialization/SerializedModuleLoader.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -586,17 +586,17 @@ SerializedModuleLoaderBase::findModule(ImportPath::Element moduleID,
586586
case SearchPathKind::RuntimeLibrary: {
587587
isFramework = false;
588588

589-
bool checkTargetSpecificModule;
590-
if (Kind == SearchPathKind::RuntimeLibrary) {
591-
// Apple platforms always use target-specific files within a
592-
// .swiftmodule directory for the stdlib; non-Apple platforms
593-
// always use single-architecture swiftmodules.
594-
checkTargetSpecificModule = Ctx.LangOpts.Target.isOSDarwin();
595-
} else {
589+
// On Apple platforms, we can assume that the runtime libraries use
590+
// target-specifi module files wihtin a `.swiftmodule` directory.
591+
// This was not always true on non-Apple platforms, and in order to
592+
// ease the transition, check both layouts.
593+
bool checkTargetSpecificModule = true;
594+
if (Kind != SearchPathKind::RuntimeLibrary ||
595+
!Ctx.LangOpts.Target.isOSDarwin()) {
596596
auto modulePath = currPath;
597597
llvm::sys::path::append(modulePath, genericModuleFileName);
598-
599598
llvm::ErrorOr<llvm::vfs::Status> statResult = fs.status(modulePath);
599+
600600
// Even if stat fails, we can't just return the error; the path
601601
// we're looking for might not be "Foo.swiftmodule".
602602
checkTargetSpecificModule = statResult && statResult->isDirectory();

0 commit comments

Comments
 (0)