@@ -180,7 +180,7 @@ createClangArgs(const ASTContext &ctx, clang::driver::Driver &clangDriver) {
180
180
181
181
static SmallVector<std::pair<std::string, std::string>, 2 >
182
182
getLibcFileMapping (ASTContext &ctx, StringRef modulemapFileName,
183
- std::optional<StringRef> maybeHeaderFileName ,
183
+ std::optional<ArrayRef< StringRef>> maybeHeaderFileNames ,
184
184
const llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> &vfs) {
185
185
const llvm::Triple &triple = ctx.LangOpts .Target ;
186
186
@@ -220,18 +220,20 @@ getLibcFileMapping(ASTContext &ctx, StringRef modulemapFileName,
220
220
SmallVector<std::pair<std::string, std::string>, 2 > vfsMappings{
221
221
{std::string (injectedModuleMapPath), std::string (actualModuleMapPath)}};
222
222
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);
229
230
230
- Path injectedHeaderPath (libcDir);
231
- llvm::sys::path::append (injectedHeaderPath, maybeHeaderFileName. value () );
231
+ Path injectedHeaderPath (libcDir);
232
+ llvm::sys::path::append (injectedHeaderPath, filename );
232
233
233
- vfsMappings.push_back (
234
- {std::string (injectedHeaderPath), std::string (actualHeaderPath)});
234
+ vfsMappings.push_back (
235
+ {std::string (injectedHeaderPath), std::string (actualHeaderPath)});
236
+ }
235
237
}
236
238
237
239
return vfsMappings;
@@ -552,9 +554,14 @@ ClangInvocationFileMapping swift::getClangInvocationFileMapping(
552
554
} else if (triple.isMusl ()) {
553
555
libcFileMapping =
554
556
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);
555
562
} else if (triple.isOSGlibc () || triple.isOSOpenBSD () ||
556
- triple.isOSFreeBSD () || triple. isAndroid () ) {
557
- // Android/ BSD/Linux Mappings
563
+ triple.isOSFreeBSD ()) {
564
+ // BSD/Linux Mappings
558
565
libcFileMapping = getLibcFileMapping (ctx, " glibc.modulemap" ,
559
566
StringRef (" SwiftGlibc.h" ), vfs);
560
567
0 commit comments