@@ -206,8 +206,18 @@ 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 (
210
- parsedIncludeArgs, {" inttypes.h" , " unistd.h" , " stdint.h" }, vfs)) {
209
+ if (triple.isAndroid () &&
210
+ !clangDriverArgs.getLastArgValue (clang::driver::options::OPT__sysroot_EQ)
211
+ .empty ()) {
212
+ // Swift's driver passes in the Android NDK path using the --sysroot Clang
213
+ // flag.
214
+ libcDir =
215
+ clangDriverArgs.getLastArgValue (clang::driver::options::OPT__sysroot_EQ)
216
+ .str ();
217
+ llvm::sys::path::append (libcDir, " usr" , " include" );
218
+ } else if (auto dir = findFirstIncludeDir (
219
+ parsedIncludeArgs, {" inttypes.h" , " unistd.h" , " stdint.h" },
220
+ vfs)) {
211
221
libcDir = dir.value ();
212
222
} else {
213
223
ctx.Diags .diagnose (SourceLoc (), diag::libc_not_found, triple.str ());
@@ -540,6 +550,12 @@ ClangInvocationFileMapping swift::getClangInvocationFileMapping(
540
550
StringRef (" SwiftGlibc.h" ), vfs);
541
551
}
542
552
result.redirectedFiles .append (libcFileMapping);
553
+ if (triple.isAndroid ()) {
554
+ // Android uses the android-specific module map that overlays the NDK.
555
+ // FIXME: Drop Glibc mapping for android as well.
556
+ result.redirectedFiles .append (
557
+ getLibcFileMapping (ctx, " android.modulemap" , std::nullopt, vfs));
558
+ }
543
559
// Both libc module maps have the C standard library headers all together in a
544
560
// SwiftLibc module. That leads to module cycles with the clang _Builtin_
545
561
// modules. e.g. <inttypes.h> includes <stdint.h> on these platforms. The
0 commit comments