@@ -189,7 +189,8 @@ ClangImporter::createClangArgs(const ClangImporterOptions &ClangImporterOpts,
189189static SmallVector<std::pair<std::string, std::string>, 2 >
190190getLibcFileMapping (ASTContext &ctx, StringRef modulemapFileName,
191191 std::optional<ArrayRef<StringRef>> maybeHeaderFileNames,
192- const llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> &vfs) {
192+ const llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> &vfs,
193+ bool suppressDiagnostic) {
193194 const llvm::Triple &triple = ctx.LangOpts .Target ;
194195
195196 // Extract the libc path from Clang driver.
@@ -213,7 +214,8 @@ getLibcFileMapping(ASTContext &ctx, StringRef modulemapFileName,
213214 parsedIncludeArgs, {" inttypes.h" , " unistd.h" , " stdint.h" }, vfs)) {
214215 libcDir = dir.value ();
215216 } else {
216- ctx.Diags .diagnose (SourceLoc (), diag::libc_not_found, triple.str ());
217+ if (!suppressDiagnostic)
218+ ctx.Diags .diagnose (SourceLoc (), diag::libc_not_found, triple.str ());
217219 return {};
218220 }
219221
@@ -251,7 +253,8 @@ getLibcFileMapping(ASTContext &ctx, StringRef modulemapFileName,
251253
252254static void getLibStdCxxFileMapping (
253255 ClangInvocationFileMapping &fileMapping, ASTContext &ctx,
254- const llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> &vfs) {
256+ const llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> &vfs,
257+ bool suppressDiagnostic) {
255258 assert (ctx.LangOpts .EnableCXXInterop &&
256259 " libstdc++ is only injected if C++ interop is enabled" );
257260
@@ -286,7 +289,8 @@ static void getLibStdCxxFileMapping(
286289 {" cstdlib" , " string" , " vector" }, vfs)) {
287290 cxxStdlibDir = dir.value ();
288291 } else {
289- ctx.Diags .diagnose (SourceLoc (), diag::libstdcxx_not_found, triple.str ());
292+ if (!suppressDiagnostic)
293+ ctx.Diags .diagnose (SourceLoc (), diag::libstdcxx_not_found, triple.str ());
290294 return ;
291295 }
292296
@@ -541,7 +545,8 @@ SmallVector<std::pair<std::string, std::string>, 2> GetWindowsFileMappings(
541545} // namespace
542546
543547ClangInvocationFileMapping swift::getClangInvocationFileMapping (
544- ASTContext &ctx, llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> vfs) {
548+ ASTContext &ctx, llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> vfs,
549+ bool suppressDiagnostic) {
545550 ClangInvocationFileMapping result;
546551 if (!vfs)
547552 vfs = llvm::vfs::getRealFileSystem ();
@@ -571,18 +576,21 @@ ClangInvocationFileMapping swift::getClangInvocationFileMapping(
571576 if (triple.isOSWASI ()) {
572577 // WASI Mappings
573578 libcFileMapping =
574- getLibcFileMapping (ctx, " wasi-libc.modulemap" , std::nullopt , vfs);
579+ getLibcFileMapping (ctx, " wasi-libc.modulemap" , std::nullopt , vfs,
580+ suppressDiagnostic);
575581
576582 // WASI's module map needs fixing
577583 result.requiresBuiltinHeadersInSystemModules = true ;
578584 } else if (triple.isMusl ()) {
579585 libcFileMapping =
580- getLibcFileMapping (ctx, " musl.modulemap" , StringRef (" SwiftMusl.h" ), vfs);
586+ getLibcFileMapping (ctx, " musl.modulemap" , StringRef (" SwiftMusl.h" ), vfs,
587+ suppressDiagnostic);
581588 } else if (triple.isAndroid ()) {
582589 // Android uses the android-specific module map that overlays the NDK.
583590 StringRef headerFiles[] = {" SwiftAndroidNDK.h" , " SwiftBionic.h" };
584591 libcFileMapping =
585- getLibcFileMapping (ctx, " android.modulemap" , headerFiles, vfs);
592+ getLibcFileMapping (ctx, " android.modulemap" , headerFiles, vfs,
593+ suppressDiagnostic);
586594
587595 if (!libcFileMapping.empty ()) {
588596 sysroot = libcFileMapping[0 ].first ;
@@ -592,15 +600,16 @@ ClangInvocationFileMapping swift::getClangInvocationFileMapping(
592600 triple.isOSFreeBSD ()) {
593601 // BSD/Linux Mappings
594602 libcFileMapping = getLibcFileMapping (ctx, " glibc.modulemap" ,
595- StringRef (" SwiftGlibc.h" ), vfs);
603+ StringRef (" SwiftGlibc.h" ), vfs,
604+ suppressDiagnostic);
596605
597606 // glibc.modulemap needs fixing
598607 result.requiresBuiltinHeadersInSystemModules = true ;
599608 }
600609 result.redirectedFiles .append (libcFileMapping);
601610
602611 if (ctx.LangOpts .EnableCXXInterop )
603- getLibStdCxxFileMapping (result, ctx, vfs);
612+ getLibStdCxxFileMapping (result, ctx, vfs, suppressDiagnostic );
604613
605614 result.redirectedFiles .append (GetWindowsFileMappings (
606615 ctx, vfs, result.requiresBuiltinHeadersInSystemModules ));
0 commit comments