Skip to content

Support C++20 modules, MSVC part - #836

Open
PikachuHyA wants to merge 2 commits into
bazelbuild:mainfrom
PikachuHyA:fix-msvc-cpp-modules
Open

Support C++20 modules, MSVC part#836
PikachuHyA wants to merge 2 commits into
bazelbuild:mainfrom
PikachuHyA:fix-msvc-cpp-modules

Conversation

@PikachuHyA

Copy link
Copy Markdown
Contributor

Fix C++ module support on the MSVC toolchain

Apply the MSVC runtime library flags (/MT, /MTd, /MD, /MDd) to the module compile and codegen actions (cpp_module_compile, cpp_module_codegen, cpp20_module_compile, cpp20_module_codegen). Previously module interface units were compiled with no runtime library flag, so cl.exe fell back to the static CRT while importing TUs used /MD, which produced C5050 at import time and LNK4098 at link time.

Also fix module dependency scanning on Windows: the deps scanner wrapper passed /scanDependencies- (which disables scanning) and redirected stdout to an output file Bazel never consumes. Pass /scanDependencies with the output file path as an argument and provide DEPS_SCANNER_OUTPUT_FILE to the scanning action, and declare the cpp_module artifact name pattern (.ifc) so module interface files are named correctly.

about cl.exe /scanDependencies, see https://learn.microsoft.com/en-us/cpp/build/reference/scandependencies?view=msvc-170

Fix C++ module support on the MSVC toolchain

Apply the MSVC runtime library flags (/MT, /MTd, /MD, /MDd) to the module
compile and codegen actions (cpp_module_compile, cpp_module_codegen,
cpp20_module_compile, cpp20_module_codegen). Previously module interface
units were compiled with no runtime library flag, so cl.exe fell back to
the static CRT while importing TUs used /MD, which produced C5050 at
import time and LNK4098 at link time.

Also fix module dependency scanning on Windows: the deps scanner wrapper
passed /scanDependencies- (which disables scanning) and redirected stdout
to an output file Bazel never consumes. Pass /scanDependencies with the
output file path as an argument and provide DEPS_SCANNER_OUTPUT_FILE to
the scanning action, and declare the cpp_module artifact name pattern
(.ifc) so module interface files are named correctly.
The include_paths feature only covered regular compile actions, so module
dependency scanning and module interface compiles ran cl.exe without /I
flags. Headers and modules that resolve through include paths (includes =
[...] attributes or external deps) were invisible to the scanner, which
could miss dependencies or fail to find headers. Align the action list
with the Unix toolchain and also cover the module codegen actions.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant