Skip to content

Commit a86743e

Browse files
authored
Merge pull request #79278 from compnerd/modular
2 parents 134eb51 + 79d2af7 commit a86743e

File tree

2 files changed

+25
-9
lines changed

2 files changed

+25
-9
lines changed

lib/ClangImporter/ClangIncludePaths.cpp

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -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

stdlib/public/Platform/vcruntime.modulemap

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -707,6 +707,11 @@ module std [system] {
707707
export *
708708
}
709709

710+
explicit module __msvc_string_view {
711+
header "__msvc_string_view.hpp"
712+
export *
713+
}
714+
710715
explicit module xatomic {
711716
header "xatomic.h"
712717
export *

0 commit comments

Comments
 (0)