Skip to content

Commit e3902b6

Browse files
committed
[android][clang importer] overlay the android NDK module map in the clang importer
1 parent d7d730d commit e3902b6

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

lib/ClangImporter/ClangIncludePaths.cpp

+11-1
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,12 @@ getLibcFileMapping(ASTContext &ctx, StringRef modulemapFileName,
206206
// Ideally we would check that all of the headers referenced from the
207207
// modulemap are present.
208208
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(
210215
parsedIncludeArgs, {"inttypes.h", "unistd.h", "stdint.h"}, vfs)) {
211216
libcDir = dir.value();
212217
} else {
@@ -540,6 +545,11 @@ ClangInvocationFileMapping swift::getClangInvocationFileMapping(
540545
StringRef("SwiftGlibc.h"), vfs);
541546
}
542547
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+
}
543553
// Both libc module maps have the C standard library headers all together in a
544554
// SwiftLibc module. That leads to module cycles with the clang _Builtin_
545555
// modules. e.g. <inttypes.h> includes <stdint.h> on these platforms. The

0 commit comments

Comments
 (0)