@@ -193,7 +193,8 @@ ClangImporter::createClangArgs(const ClangImporterOptions &ClangImporterOpts,
193193static SmallVector<std::pair<std::string, std::string>, 2 >
194194getLibcFileMapping (ASTContext &ctx, StringRef modulemapFileName,
195195 std::optional<ArrayRef<StringRef>> maybeHeaderFileNames,
196- const llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> &vfs) {
196+ const llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> &vfs,
197+ bool suppressDiagnostic) {
197198 const llvm::Triple &triple = ctx.LangOpts .Target ;
198199
199200 // Extract the libc path from Clang driver.
@@ -217,7 +218,8 @@ getLibcFileMapping(ASTContext &ctx, StringRef modulemapFileName,
217218 parsedIncludeArgs, {" inttypes.h" , " unistd.h" , " stdint.h" }, vfs)) {
218219 libcDir = dir.value ();
219220 } else {
220- ctx.Diags .diagnose (SourceLoc (), diag::libc_not_found, triple.str ());
221+ if (!suppressDiagnostic)
222+ ctx.Diags .diagnose (SourceLoc (), diag::libc_not_found, triple.str ());
221223 return {};
222224 }
223225
@@ -255,7 +257,8 @@ getLibcFileMapping(ASTContext &ctx, StringRef modulemapFileName,
255257
256258static void getLibStdCxxFileMapping (
257259 ClangInvocationFileMapping &fileMapping, ASTContext &ctx,
258- const llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> &vfs) {
260+ const llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> &vfs,
261+ bool suppressDiagnostic) {
259262 assert (ctx.LangOpts .EnableCXXInterop &&
260263 " libstdc++ is only injected if C++ interop is enabled" );
261264
@@ -290,7 +293,8 @@ static void getLibStdCxxFileMapping(
290293 {" cstdlib" , " string" , " vector" }, vfs)) {
291294 cxxStdlibDir = dir.value ();
292295 } else {
293- ctx.Diags .diagnose (SourceLoc (), diag::libstdcxx_not_found, triple.str ());
296+ if (!suppressDiagnostic)
297+ ctx.Diags .diagnose (SourceLoc (), diag::libstdcxx_not_found, triple.str ());
294298 return ;
295299 }
296300
@@ -545,7 +549,8 @@ SmallVector<std::pair<std::string, std::string>, 2> GetWindowsFileMappings(
545549} // namespace
546550
547551ClangInvocationFileMapping swift::getClangInvocationFileMapping (
548- ASTContext &ctx, llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> vfs) {
552+ ASTContext &ctx, llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> vfs,
553+ bool suppressDiagnostic) {
549554 ClangInvocationFileMapping result;
550555 if (!vfs)
551556 vfs = llvm::vfs::getRealFileSystem ();
@@ -575,18 +580,21 @@ ClangInvocationFileMapping swift::getClangInvocationFileMapping(
575580 if (triple.isOSWASI ()) {
576581 // WASI Mappings
577582 libcFileMapping =
578- getLibcFileMapping (ctx, " wasi-libc.modulemap" , std::nullopt , vfs);
583+ getLibcFileMapping (ctx, " wasi-libc.modulemap" , std::nullopt , vfs,
584+ suppressDiagnostic);
579585
580586 // WASI's module map needs fixing
581587 result.requiresBuiltinHeadersInSystemModules = true ;
582588 } else if (triple.isMusl ()) {
583589 libcFileMapping =
584- getLibcFileMapping (ctx, " musl.modulemap" , StringRef (" SwiftMusl.h" ), vfs);
590+ getLibcFileMapping (ctx, " musl.modulemap" , StringRef (" SwiftMusl.h" ), vfs,
591+ suppressDiagnostic);
585592 } else if (triple.isAndroid ()) {
586593 // Android uses the android-specific module map that overlays the NDK.
587594 StringRef headerFiles[] = {" SwiftAndroidNDK.h" , " SwiftBionic.h" };
588595 libcFileMapping =
589- getLibcFileMapping (ctx, " android.modulemap" , headerFiles, vfs);
596+ getLibcFileMapping (ctx, " android.modulemap" , headerFiles, vfs,
597+ suppressDiagnostic);
590598
591599 if (!libcFileMapping.empty ()) {
592600 sysroot = libcFileMapping[0 ].first ;
@@ -596,15 +604,16 @@ ClangInvocationFileMapping swift::getClangInvocationFileMapping(
596604 triple.isOSFreeBSD ()) {
597605 // BSD/Linux Mappings
598606 libcFileMapping = getLibcFileMapping (ctx, " glibc.modulemap" ,
599- StringRef (" SwiftGlibc.h" ), vfs);
607+ StringRef (" SwiftGlibc.h" ), vfs,
608+ suppressDiagnostic);
600609
601610 // glibc.modulemap needs fixing
602611 result.requiresBuiltinHeadersInSystemModules = true ;
603612 }
604613 result.redirectedFiles .append (libcFileMapping);
605614
606615 if (ctx.LangOpts .EnableCXXInterop )
607- getLibStdCxxFileMapping (result, ctx, vfs);
616+ getLibStdCxxFileMapping (result, ctx, vfs, suppressDiagnostic );
608617
609618 result.redirectedFiles .append (GetWindowsFileMappings (
610619 ctx, vfs, result.requiresBuiltinHeadersInSystemModules ));
0 commit comments