bazel
bazel copied to clipboard
[WIP] [5/5] support C++20 Modules, construct build graph
I split the XXL PR https://github.com/bazelbuild/bazel/pull/19940 into several small patches. This is the fifth patch of Support C++20 Modules, I construct the build graph of compile with C++20 Modules.
Firstly, all files are scanned to generate .ddi files. All the .ddi files are then aggregated to create a .CXXModules.json file. Subsequently, based on the .CXXModules.json file and their respective .ddi files, .modmap files are generated. Finally, the compilation begins. The two-phase compilation is employed here.
┌────────┐ ┌────────┐ ┌────────┐
│foo.cppm│ │bar.cppm│ │main.cc │
└────┬───┘ └────┬───┘ └────┬───┘
c++20-deps-scanning│ │ │
│ │ │
┌────▼───┐ ┌────▼───┐ ┌────▼───┐
│foo.ddi │ │bar.ddi │ │main.ddi│
└────┬───┘ └────┬───┘ └────┬───┘
│ │ │
└───────────────────────────┼───────────────────────────┘
│Cpp20ModulesInfoAction
┌────────▼───────────┐
│demo.CXXModules.json│
└────────────────────┘
┌────────────────────┐
│demo.CXXModules.json│
└─────┬──────────────┘
│
│
┌───────┐ │ ┌───────────┐
┌─►│foo.ddi├─────────┤ │ bar.cppm │
│ └───────┘ │ └─────┬─────┘
│ │ │
│ │ │
│ │ │
│ │ │
┌────────┐ c++20-deps-scanning │ ┌───────┐ ┌─────▼────┐ ┌────▼─────┐
│foo.cppm├─────────────────────┴─►│foo.d │ │foo.modmap│ │ bar.pcm │
└───┬────┘ └──┬────┘ └────┬─────┘ └────┬─────┘
│c++20-module-compile │ │ │
┌───▼───┐ │ │ │
│foo.pcm├────────────────────────────┴─────────────┼─────────────────┘
└───────┘ │c++20-module-codegen
┌────▼─────┐
│ foo.o │
└──────────┘
Note: To make the code review convenient, I keep only one commit. Due to patch dependencies, it may build and test failed. I will update the patch after all the prerequisite patches have been merged. At that time, I will then troubleshoot the build and test failures.
as https://github.com/bazelbuild/bazel/pull/19940#discussion_r1608064853 mentioned, I will remove remove the reuse of the .d file.
@PikachuHyA Could you please take a look at the failing checks?
@PikachuHyA Could you please take a look at the failing checks?
This patch is dependent on the changes in https://github.com/bazelbuild/bazel/pull/22553. I will update this patch once that pull request has been merged.