Support Using Clang Module Map to Avoid mixing #include and import pr…#777
Open
PikachuHyA wants to merge 1 commit into
Open
Support Using Clang Module Map to Avoid mixing #include and import pr…#777PikachuHyA wants to merge 1 commit into
PikachuHyA wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
…oblems
Motivation
We are refactoring our legacy code to enable C++20 Modules. With this approach, we do not need to change the actual business code, or only need to make very small changes. We only need to add a
.modulemapfile to get the benefits of C++20 Modules.Summary
Adds a new
module_header_mapsattribute tocc_libraryandcc_binaryso targets can use Clang header module maps (.modulemap+-fmodule-map-file) alongside C++20 named modules (module_interfaces).This addresses the common case where legacy
#includeandimportmust coexist in the same translation unit: Clang can treat headers as part of a named module when a module map is provided, without requiring every header to be rewritten as a module interface. see https://clang.llvm.org/docs/StandardCPlusPlusModules.html#using-clang-module-map-to-avoid-mixing-include-and-import-problemsNew attribute
module_header_maps:dictmapping module name →.modulemaplabel (viastring_keyed_label_dict)--experimental_cpp_modulesand the toolchaincpp_modulesfeature (same asmodule_interfaces)Compile behavior
When
module_header_mapsis set on a target:generate-modmapare skipped for.ccfiles on that target.generate-modmap/CppGenModmappipeline:.ccsources..modulemapfiles are passed as compileadditional_compilation_inputsand emitted via a new toolchain featurecpp_module_header_map_filesas-fmodule-map-file=...(Linux Clang toolchain only).Intentional v1 limitations
To simplify the implementation
module_header_mapsis not propagated throughCcCompilationContext; each target that compiles.ccand needs header maps must declare them explicitly (same pattern as earlymodule_interfacesusage)..ccdependency analysis: the shared modmap includes all modules listed in the dict for every.ccon the target.cpp_module_header_map_filesis registered only on the Unix/Linux toolchain config (not Windows/macOS yet).