@@ -193,7 +193,8 @@ ClangImporter::createClangArgs(const ClangImporterOptions &ClangImporterOpts,
193
193
static SmallVector<std::pair<std::string, std::string>, 2 >
194
194
getLibcFileMapping (ASTContext &ctx, StringRef modulemapFileName,
195
195
std::optional<ArrayRef<StringRef>> maybeHeaderFileNames,
196
- const llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> &vfs) {
196
+ const llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> &vfs,
197
+ bool suppressDiagnostic) {
197
198
const llvm::Triple &triple = ctx.LangOpts .Target ;
198
199
199
200
// Extract the libc path from Clang driver.
@@ -217,7 +218,8 @@ getLibcFileMapping(ASTContext &ctx, StringRef modulemapFileName,
217
218
parsedIncludeArgs, {" inttypes.h" , " unistd.h" , " stdint.h" }, vfs)) {
218
219
libcDir = dir.value ();
219
220
} 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 ());
221
223
return {};
222
224
}
223
225
@@ -255,7 +257,8 @@ getLibcFileMapping(ASTContext &ctx, StringRef modulemapFileName,
255
257
256
258
static void getLibStdCxxFileMapping (
257
259
ClangInvocationFileMapping &fileMapping, ASTContext &ctx,
258
- const llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> &vfs) {
260
+ const llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> &vfs,
261
+ bool suppressDiagnostic) {
259
262
assert (ctx.LangOpts .EnableCXXInterop &&
260
263
" libstdc++ is only injected if C++ interop is enabled" );
261
264
@@ -290,7 +293,8 @@ static void getLibStdCxxFileMapping(
290
293
{" cstdlib" , " string" , " vector" }, vfs)) {
291
294
cxxStdlibDir = dir.value ();
292
295
} 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 ());
294
298
return ;
295
299
}
296
300
@@ -545,7 +549,8 @@ SmallVector<std::pair<std::string, std::string>, 2> GetWindowsFileMappings(
545
549
} // namespace
546
550
547
551
ClangInvocationFileMapping swift::getClangInvocationFileMapping (
548
- ASTContext &ctx, llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> vfs) {
552
+ ASTContext &ctx, llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> vfs,
553
+ bool suppressDiagnostic) {
549
554
ClangInvocationFileMapping result;
550
555
if (!vfs)
551
556
vfs = llvm::vfs::getRealFileSystem ();
@@ -575,18 +580,21 @@ ClangInvocationFileMapping swift::getClangInvocationFileMapping(
575
580
if (triple.isOSWASI ()) {
576
581
// WASI Mappings
577
582
libcFileMapping =
578
- getLibcFileMapping (ctx, " wasi-libc.modulemap" , std::nullopt, vfs);
583
+ getLibcFileMapping (ctx, " wasi-libc.modulemap" , std::nullopt, vfs,
584
+ suppressDiagnostic);
579
585
580
586
// WASI's module map needs fixing
581
587
result.requiresBuiltinHeadersInSystemModules = true ;
582
588
} else if (triple.isMusl ()) {
583
589
libcFileMapping =
584
- getLibcFileMapping (ctx, " musl.modulemap" , StringRef (" SwiftMusl.h" ), vfs);
590
+ getLibcFileMapping (ctx, " musl.modulemap" , StringRef (" SwiftMusl.h" ), vfs,
591
+ suppressDiagnostic);
585
592
} else if (triple.isAndroid ()) {
586
593
// Android uses the android-specific module map that overlays the NDK.
587
594
StringRef headerFiles[] = {" SwiftAndroidNDK.h" , " SwiftBionic.h" };
588
595
libcFileMapping =
589
- getLibcFileMapping (ctx, " android.modulemap" , headerFiles, vfs);
596
+ getLibcFileMapping (ctx, " android.modulemap" , headerFiles, vfs,
597
+ suppressDiagnostic);
590
598
591
599
if (!libcFileMapping.empty ()) {
592
600
sysroot = libcFileMapping[0 ].first ;
@@ -596,15 +604,16 @@ ClangInvocationFileMapping swift::getClangInvocationFileMapping(
596
604
triple.isOSFreeBSD ()) {
597
605
// BSD/Linux Mappings
598
606
libcFileMapping = getLibcFileMapping (ctx, " glibc.modulemap" ,
599
- StringRef (" SwiftGlibc.h" ), vfs);
607
+ StringRef (" SwiftGlibc.h" ), vfs,
608
+ suppressDiagnostic);
600
609
601
610
// glibc.modulemap needs fixing
602
611
result.requiresBuiltinHeadersInSystemModules = true ;
603
612
}
604
613
result.redirectedFiles .append (libcFileMapping);
605
614
606
615
if (ctx.LangOpts .EnableCXXInterop )
607
- getLibStdCxxFileMapping (result, ctx, vfs);
616
+ getLibStdCxxFileMapping (result, ctx, vfs, suppressDiagnostic );
608
617
609
618
result.redirectedFiles .append (GetWindowsFileMappings (
610
619
ctx, vfs, result.requiresBuiltinHeadersInSystemModules ));
0 commit comments