@@ -560,15 +560,26 @@ void GetWindowsFileMappings(
560560 fileMapping.redirectedFiles .emplace_back (std::string (VCToolsInjection),
561561 AuxiliaryFile);
562562
563- // __msvc_bit_utils.hpp was added in a recent VS 2022 version. It has to be
564- // referenced from the modulemap directly to avoid modularization errors.
565- // Older VS versions might not have it. Let's inject an empty header file if
566- // it isn't available.
567- llvm::sys::path::remove_filename (VCToolsInjection);
568- llvm::sys::path::append (VCToolsInjection, " __msvc_bit_utils.hpp" );
569- if (!llvm::sys::fs::exists (VCToolsInjection))
570- fileMapping.overridenFiles .emplace_back (std::string (VCToolsInjection),
571- " " );
563+ // Because we wish to be backwrds compatible with older Visual Studio
564+ // releases, we inject empty headers which allow us to have definitions for
565+ // modules referencing headers which may not exist. We stub out the headers
566+ // with empty files to allow a single module definition to work across
567+ // different MSVC STL releases.
568+ //
569+ // __msvc_bit_utils.hpp was introduced in VS 2022 STL release 17.8.
570+ // __msvc_string_view.hpp was introduced in VS 2022 STL release 17.11.
571+ static const char * const kInjectedHeaders [] = {
572+ " __msvc_bit_utils.hpp" ,
573+ " __msvc_string_view.hpp" ,
574+ };
575+
576+ for (const char * const header : kInjectedHeaders ) {
577+ llvm::sys::path::remove_filename (VCToolsInjection);
578+ llvm::sys::path::append (VCToolsInjection, header);
579+ if (!llvm::sys::fs::exists (VCToolsInjection))
580+ fileMapping.overridenFiles .emplace_back (std::string{VCToolsInjection},
581+ " " );
582+ }
572583 }
573584}
574585} // namespace
0 commit comments