@@ -185,7 +185,7 @@ static bool shouldInjectLibcModulemap(const llvm::Triple &triple) {
185
185
186
186
static SmallVector<std::pair<std::string, std::string>, 2 >
187
187
getLibcFileMapping (ASTContext &ctx, StringRef modulemapFileName,
188
- std::optional<StringRef> maybeHeaderFileName ,
188
+ std::optional<ArrayRef< StringRef>> maybeHeaderFileNames ,
189
189
const llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> &vfs) {
190
190
const llvm::Triple &triple = ctx.LangOpts .Target ;
191
191
if (!shouldInjectLibcModulemap (triple))
@@ -227,18 +227,20 @@ getLibcFileMapping(ASTContext &ctx, StringRef modulemapFileName,
227
227
SmallVector<std::pair<std::string, std::string>, 2 > vfsMappings{
228
228
{std::string (injectedModuleMapPath), std::string (actualModuleMapPath)}};
229
229
230
- if (maybeHeaderFileName) {
231
- // TODO: remove the SwiftGlibc.h header and reference all Glibc headers
232
- // directly from the modulemap.
233
- Path actualHeaderPath = actualModuleMapPath;
234
- llvm::sys::path::remove_filename (actualHeaderPath);
235
- llvm::sys::path::append (actualHeaderPath, maybeHeaderFileName.value ());
230
+ if (maybeHeaderFileNames) {
231
+ for (const auto &filename : *maybeHeaderFileNames) {
232
+ // TODO: remove the SwiftGlibc.h header and reference all Glibc headers
233
+ // directly from the modulemap.
234
+ Path actualHeaderPath = actualModuleMapPath;
235
+ llvm::sys::path::remove_filename (actualHeaderPath);
236
+ llvm::sys::path::append (actualHeaderPath, filename);
236
237
237
- Path injectedHeaderPath (libcDir);
238
- llvm::sys::path::append (injectedHeaderPath, maybeHeaderFileName. value () );
238
+ Path injectedHeaderPath (libcDir);
239
+ llvm::sys::path::append (injectedHeaderPath, filename );
239
240
240
- vfsMappings.push_back (
241
- {std::string (injectedHeaderPath), std::string (actualHeaderPath)});
241
+ vfsMappings.push_back (
242
+ {std::string (injectedHeaderPath), std::string (actualHeaderPath)});
243
+ }
242
244
}
243
245
244
246
return vfsMappings;
@@ -534,8 +536,13 @@ ClangInvocationFileMapping swift::getClangInvocationFileMapping(
534
536
// WASI Mappings
535
537
libcFileMapping =
536
538
getLibcFileMapping (ctx, " wasi-libc.modulemap" , std::nullopt , vfs);
539
+ } else if (triple.isAndroid ()) {
540
+ // Android uses the android-specific module map that overlays the NDK.
541
+ StringRef headerFiles[] = {" SwiftAndroidNDK.h" , " SwiftBionic.h" };
542
+ libcFileMapping =
543
+ getLibcFileMapping (ctx, " android.modulemap" , headerFiles, vfs);
537
544
} else {
538
- // Android/ BSD/Linux Mappings
545
+ // BSD/Linux Mappings
539
546
libcFileMapping = getLibcFileMapping (ctx, " glibc.modulemap" ,
540
547
StringRef (" SwiftGlibc.h" ), vfs);
541
548
}
0 commit comments