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