@@ -439,17 +439,16 @@ GetPlatformAuxiliaryFile(StringRef Platform, StringRef File,
439
439
return " " ;
440
440
}
441
441
442
- SmallVector<std::pair<std::string, std::string>, 2 > GetWindowsFileMappings (
443
- ASTContext &Context,
442
+ void GetWindowsFileMappings (
443
+ ClangInvocationFileMapping &fileMapping, ASTContext &Context,
444
444
const llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> &driverVFS,
445
445
bool &requiresBuiltinHeadersInSystemModules) {
446
446
const llvm::Triple &Triple = Context.LangOpts .Target ;
447
447
const SearchPathOptions &SearchPathOpts = Context.SearchPathOpts ;
448
- SmallVector<std::pair<std::string, std::string>, 2 > Mappings;
449
448
std::string AuxiliaryFile;
450
449
451
450
if (!Triple.isWindowsMSVCEnvironment ())
452
- return Mappings ;
451
+ return ;
453
452
454
453
auto [Driver, clangDiagEngine] = ClangImporter::createClangDriver (
455
454
Context.LangOpts , Context.ClangImporterOpts , driverVFS);
@@ -478,7 +477,8 @@ SmallVector<std::pair<std::string, std::string>, 2> GetWindowsFileMappings(
478
477
AuxiliaryFile =
479
478
GetPlatformAuxiliaryFile (" windows" , " winsdk.modulemap" , SearchPathOpts);
480
479
if (!AuxiliaryFile.empty ())
481
- Mappings.emplace_back (std::string (WinSDKInjection), AuxiliaryFile);
480
+ fileMapping.redirectedFiles .emplace_back (std::string (WinSDKInjection),
481
+ AuxiliaryFile);
482
482
}
483
483
484
484
struct {
@@ -506,7 +506,8 @@ SmallVector<std::pair<std::string, std::string>, 2> GetWindowsFileMappings(
506
506
// cycle goes away. Note that -fbuiltin-headers-in-system-modules does
507
507
// nothing to fix the same problem with C++ headers, and is generally
508
508
// fragile.
509
- Mappings.emplace_back (std::string (UCRTInjection), AuxiliaryFile);
509
+ fileMapping.redirectedFiles .emplace_back (std::string (UCRTInjection),
510
+ AuxiliaryFile);
510
511
requiresBuiltinHeadersInSystemModules = true ;
511
512
}
512
513
}
@@ -533,18 +534,28 @@ SmallVector<std::pair<std::string, std::string>, 2> GetWindowsFileMappings(
533
534
GetPlatformAuxiliaryFile (" windows" , " vcruntime.modulemap" ,
534
535
SearchPathOpts);
535
536
if (!AuxiliaryFile.empty ())
536
- Mappings.emplace_back (std::string (VCToolsInjection), AuxiliaryFile);
537
+ fileMapping.redirectedFiles .emplace_back (std::string (VCToolsInjection),
538
+ AuxiliaryFile);
537
539
538
540
llvm::sys::path::remove_filename (VCToolsInjection);
539
541
llvm::sys::path::append (VCToolsInjection, " vcruntime.apinotes" );
540
542
AuxiliaryFile =
541
543
GetPlatformAuxiliaryFile (" windows" , " vcruntime.apinotes" ,
542
544
SearchPathOpts);
543
545
if (!AuxiliaryFile.empty ())
544
- Mappings. emplace_back (std::string (VCToolsInjection), AuxiliaryFile);
545
- }
546
+ fileMapping. redirectedFiles . emplace_back (std::string (VCToolsInjection),
547
+ AuxiliaryFile);
546
548
547
- return Mappings;
549
+ // __msvc_bit_utils.hpp was added in a recent VS 2022 version. It has to be
550
+ // referenced from the modulemap directly to avoid modularization errors.
551
+ // Older VS versions might not have it. Let's inject an empty header file if
552
+ // it isn't available.
553
+ llvm::sys::path::remove_filename (VCToolsInjection);
554
+ llvm::sys::path::append (VCToolsInjection, " __msvc_bit_utils.hpp" );
555
+ if (!llvm::sys::fs::exists (VCToolsInjection))
556
+ fileMapping.overridenFiles .emplace_back (std::string (VCToolsInjection),
557
+ " " );
558
+ }
548
559
}
549
560
} // namespace
550
561
@@ -615,7 +626,7 @@ ClangInvocationFileMapping swift::getClangInvocationFileMapping(
615
626
if (ctx.LangOpts .EnableCXXInterop )
616
627
getLibStdCxxFileMapping (result, ctx, vfs, suppressDiagnostic);
617
628
618
- result. redirectedFiles . append ( GetWindowsFileMappings (
619
- ctx, vfs, result.requiresBuiltinHeadersInSystemModules ) );
629
+ GetWindowsFileMappings (result, ctx, vfs,
630
+ result.requiresBuiltinHeadersInSystemModules );
620
631
return result;
621
632
}
0 commit comments