@@ -206,7 +206,12 @@ getLibcFileMapping(ASTContext &ctx, StringRef modulemapFileName,
206
206
// Ideally we would check that all of the headers referenced from the
207
207
// modulemap are present.
208
208
Path libcDir;
209
- if (auto dir = findFirstIncludeDir (
209
+ if (triple.isAndroid () &&
210
+ !clangDriverArgs.getLastArgValue (clang::driver::options::OPT__sysroot_EQ).empty ()) {
211
+ // Swift's driver passes in the Android NDK path using the --sysroot Clang flag.
212
+ libcDir = clangDriverArgs.getLastArgValue (clang::driver::options::OPT__sysroot_EQ).str ();
213
+ llvm::sys::path::append (libcDir, " usr" , " include" );
214
+ } else if (auto dir = findFirstIncludeDir (
210
215
parsedIncludeArgs, {" inttypes.h" , " unistd.h" , " stdint.h" }, vfs)) {
211
216
libcDir = dir.value ();
212
217
} else {
@@ -540,6 +545,11 @@ ClangInvocationFileMapping swift::getClangInvocationFileMapping(
540
545
StringRef (" SwiftGlibc.h" ), vfs);
541
546
}
542
547
result.redirectedFiles .append (libcFileMapping);
548
+ if (triple.isAndroid ()) {
549
+ // Android uses the android-specific module map that overlays the NDK.
550
+ // FIXME: Drop Glibc mapping for android as well.
551
+ result.redirectedFiles .append (getLibcFileMapping (ctx, " android.modulemap" , std::nullopt, vfs));
552
+ }
543
553
// Both libc module maps have the C standard library headers all together in a
544
554
// SwiftLibc module. That leads to module cycles with the clang _Builtin_
545
555
// modules. e.g. <inttypes.h> includes <stdint.h> on these platforms. The
0 commit comments