@@ -142,6 +142,23 @@ bool SerializedModuleLoader::maybeDiagnoseArchitectureMismatch(
142
142
return true ;
143
143
}
144
144
145
+ static std::pair<llvm::SmallString<16 >, llvm::SmallString<16 >>
146
+ getArchSpecificModuleFileNames (StringRef archName) {
147
+ llvm::SmallString<16 > archFile, archDocFile;
148
+
149
+ if (!archName.empty ()) {
150
+ archFile += archName;
151
+ archFile += ' .' ;
152
+ archFile += file_types::getExtension (file_types::TY_SwiftModuleFile);
153
+
154
+ archDocFile += archName;
155
+ archDocFile += ' .' ;
156
+ archDocFile += file_types::getExtension (file_types::TY_SwiftModuleDocFile);
157
+ }
158
+
159
+ return {archFile, archDocFile};
160
+ }
161
+
145
162
bool
146
163
SerializedModuleLoaderBase::findModule (AccessPathElem moduleID,
147
164
std::unique_ptr<llvm::MemoryBuffer> *moduleBuffer,
@@ -157,19 +174,19 @@ SerializedModuleLoaderBase::findModule(AccessPathElem moduleID,
157
174
moduleDocFilename +=
158
175
file_types::getExtension (file_types::TY_SwiftModuleDocFile);
159
176
160
- // FIXME: Which name should we be using here? Do we care about CPU subtypes?
161
- // FIXME: At the very least, don't hardcode "arch".
162
- llvm::SmallString<16 > archName{
163
- Ctx.LangOpts .getPlatformConditionValue (PlatformConditionKind::Arch)};
164
- llvm::SmallString<16 > archFile{archName};
165
- llvm::SmallString<16 > archDocFile{archName};
166
- if (!archFile.empty ()) {
167
- archFile += ' .' ;
168
- archFile += file_types::getExtension (file_types::TY_SwiftModuleFile);
177
+ StringRef archName = Ctx.LangOpts .Target .getArchName ();
178
+ auto archFileNames = getArchSpecificModuleFileNames (archName);
169
179
170
- archDocFile += ' .' ;
171
- archDocFile += file_types::getExtension (file_types::TY_SwiftModuleDocFile);
172
- }
180
+ // FIXME: We used to use "major architecture" names for these files---the
181
+ // names checked in "#if arch(...)". Fall back to that name in the one case
182
+ // where it's different from what Swift 4.2 supported: 32-bit ARM platforms.
183
+ // We should be able to drop this once there's an Xcode that supports the
184
+ // new names.
185
+ StringRef alternateArchName;
186
+ if (Ctx.LangOpts .Target .getArch () == llvm::Triple::ArchType::arm)
187
+ alternateArchName = " arm" ;
188
+ auto alternateArchFileNames =
189
+ getArchSpecificModuleFileNames (alternateArchName);
173
190
174
191
auto &fs = *Ctx.SourceMgr .getFileSystem ();
175
192
isFramework = false ;
@@ -188,10 +205,19 @@ SerializedModuleLoaderBase::findModule(AccessPathElem moduleID,
188
205
if (statResult && statResult->isDirectory ()) {
189
206
// A .swiftmodule directory contains architecture-specific files.
190
207
result = openModuleFiles (currPath,
191
- archFile. str (), archDocFile. str () ,
208
+ archFileNames. first , archFileNames. second ,
192
209
moduleBuffer, moduleDocBuffer,
193
210
scratch);
194
211
212
+ if (result == std::errc::no_such_file_or_directory &&
213
+ !alternateArchName.empty ()) {
214
+ result = openModuleFiles (currPath,
215
+ alternateArchFileNames.first ,
216
+ alternateArchFileNames.second ,
217
+ moduleBuffer, moduleDocBuffer,
218
+ scratch);
219
+ }
220
+
195
221
if (result == std::errc::no_such_file_or_directory) {
196
222
if (maybeDiagnoseArchitectureMismatch (moduleID.second , moduleName,
197
223
archName, currPath)) {
@@ -228,9 +254,18 @@ SerializedModuleLoaderBase::findModule(AccessPathElem moduleID,
228
254
// Frameworks always use architecture-specific files within a .swiftmodule
229
255
// directory.
230
256
llvm::sys::path::append (currPath, " Modules" , moduleFilename.str ());
231
- auto err = openModuleFiles (currPath, archFile.str (), archDocFile.str (),
257
+ auto err = openModuleFiles (currPath,
258
+ archFileNames.first , archFileNames.second ,
232
259
moduleBuffer, moduleDocBuffer, scratch);
233
260
261
+ if (err == std::errc::no_such_file_or_directory &&
262
+ !alternateArchName.empty ()) {
263
+ err = openModuleFiles (currPath,
264
+ alternateArchFileNames.first ,
265
+ alternateArchFileNames.second ,
266
+ moduleBuffer, moduleDocBuffer, scratch);
267
+ }
268
+
234
269
if (err == std::errc::no_such_file_or_directory) {
235
270
if (maybeDiagnoseArchitectureMismatch (moduleID.second , moduleName,
236
271
archName, currPath)) {
0 commit comments