@@ -180,7 +180,7 @@ createClangArgs(const ASTContext &ctx, clang::driver::Driver &clangDriver) {
180180
181181static SmallVector<std::pair<std::string, std::string>, 2 >
182182getLibcFileMapping (ASTContext &ctx, StringRef modulemapFileName,
183- std::optional<StringRef> maybeHeaderFileName ,
183+ std::optional<ArrayRef< StringRef>> maybeHeaderFileNames ,
184184 const llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> &vfs) {
185185 const llvm::Triple &triple = ctx.LangOpts .Target ;
186186
@@ -220,18 +220,20 @@ getLibcFileMapping(ASTContext &ctx, StringRef modulemapFileName,
220220 SmallVector<std::pair<std::string, std::string>, 2 > vfsMappings{
221221 {std::string (injectedModuleMapPath), std::string (actualModuleMapPath)}};
222222
223- if (maybeHeaderFileName) {
224- // TODO: remove the SwiftGlibc.h header and reference all Glibc headers
225- // directly from the modulemap.
226- Path actualHeaderPath = actualModuleMapPath;
227- llvm::sys::path::remove_filename (actualHeaderPath);
228- llvm::sys::path::append (actualHeaderPath, maybeHeaderFileName.value ());
223+ if (maybeHeaderFileNames) {
224+ for (const auto &filename : *maybeHeaderFileNames) {
225+ // TODO: remove the SwiftGlibc.h header and reference all Glibc headers
226+ // directly from the modulemap.
227+ Path actualHeaderPath = actualModuleMapPath;
228+ llvm::sys::path::remove_filename (actualHeaderPath);
229+ llvm::sys::path::append (actualHeaderPath, filename);
229230
230- Path injectedHeaderPath (libcDir);
231- llvm::sys::path::append (injectedHeaderPath, maybeHeaderFileName. value () );
231+ Path injectedHeaderPath (libcDir);
232+ llvm::sys::path::append (injectedHeaderPath, filename );
232233
233- vfsMappings.push_back (
234- {std::string (injectedHeaderPath), std::string (actualHeaderPath)});
234+ vfsMappings.push_back (
235+ {std::string (injectedHeaderPath), std::string (actualHeaderPath)});
236+ }
235237 }
236238
237239 return vfsMappings;
@@ -552,9 +554,14 @@ ClangInvocationFileMapping swift::getClangInvocationFileMapping(
552554 } else if (triple.isMusl ()) {
553555 libcFileMapping =
554556 getLibcFileMapping (ctx, " musl.modulemap" , StringRef (" SwiftMusl.h" ), vfs);
557+ } else if (triple.isAndroid ()) {
558+ // Android uses the android-specific module map that overlays the NDK.
559+ StringRef headerFiles[] = {" SwiftAndroidNDK.h" , " SwiftBionic.h" };
560+ libcFileMapping =
561+ getLibcFileMapping (ctx, " android.modulemap" , headerFiles, vfs);
555562 } else if (triple.isOSGlibc () || triple.isOSOpenBSD () ||
556- triple.isOSFreeBSD () || triple. isAndroid () ) {
557- // Android/ BSD/Linux Mappings
563+ triple.isOSFreeBSD ()) {
564+ // BSD/Linux Mappings
558565 libcFileMapping = getLibcFileMapping (ctx, " glibc.modulemap" ,
559566 StringRef (" SwiftGlibc.h" ), vfs);
560567
0 commit comments