Commit 5c3e987
[4/5] support C++20 Modules, support one phase compilation
I split the XXL PR bazelbuild/bazel#19940 into several small patches.
This is the fourth patch of Support C++20 Modules, which supports one phase compilation.
## Changes of build graph
First, files are scanned, resulting in the creation of `.ddi` files. If the compiler being used is Clang, the tool `clang-scan-deps` is employed.
Next, the generated `.ddi` files are aggregated into a `.CXXModules.json` file using the `aggregate-ddi` tool.
Following this, the `.CXXModules.json` file, along with the `.ddi` files, is used to generate `.modmap` files through the `generate-modmap` tool.
Finally, the source files are compiled into object files. If a file is a module interface, a corresponding module file is produced as a byproduct.
The following diagram illustrates the scanning process.
```
┌────────┐ ┌────────┐ ┌────────┐
│foo.cppm│ │bar.cppm│ │main.cc │
└────┬───┘ └────┬───┘ └────┬───┘
│ c++-module-deps-scanning │ │
│ │ │
┌────▼───┐ ┌────▼───┐ ┌────▼───┐
│foo.ddi │ │bar.ddi │ │main.ddi│
└────┬───┘ └────┬───┘ └────┬───┘
│ │ │
└───────────────────────────┼───────────────────────────┘
│aggregate-ddi
┌────────▼───────────┐
│demo.CXXModules.json│
└────────────────────┘
```
The following diagram illustrates the compile process of `foo.cppm`.
```
┌────────────────────┐
│demo.CXXModules.json│
└─────┬──────────────┘
│
│
┌───────┐ │ ┌───────────┐
┌─►│foo.ddi├─────────┤ │ bar.cppm │
│ └───────┘ │ └─────┬─────┘
│ │ │
│ │ │
│ │ │
c++-module-deps-scanning │ │ │
┌────────┐ │ ┌───────┐ ┌─────▼────┐ ┌────▼─────┐
│foo.cppm├─────────────────────┴─►│foo.d │ │foo.modmap│ │ bar.pcm │
└───┬────┘ └──┬────┘ └────┬─────┘ └────┬─────┘
│ │ │ │
│ │ │ │
│◄───────────────────────────────┴─────────────┴─────────────────┘
│ c++20-module-compile
┌────────▼─────────┐
│ foo.pcm && foo.o │
└──────────────────┘
```
## Changes of compile
I modified the CppCompileAction to include the relevant context, inputs, and outputs.
Context: Module files and `.CXXModules.json` files
Inputs: Module files, `.modmap` file, and `.modmap.input` file
Outputs: Module files and `.CXXModules.json` files
The primary difference in CppCompileAction is the addition of the `computeUsedCpp20Modules` function.
The restart mechanism is utilized; if the necessary C++20 Modules files are not ready during compilation, the current compilation will exit and wait for an appropriate time to recompile.
Closes #22553.
PiperOrigin-RevId: 826606472
Change-Id: I7548ebfbf71a1faaa5d08317429a1e77e2454b541 parent 9b9efed commit 5c3e987
File tree
3 files changed
+757
-6
lines changed- cc/private
- compile
3 files changed
+757
-6
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
538 | 538 | | |
539 | 539 | | |
540 | 540 | | |
| 541 | + | |
| 542 | + | |
| 543 | + | |
| 544 | + | |
| 545 | + | |
| 546 | + | |
| 547 | + | |
| 548 | + | |
| 549 | + | |
| 550 | + | |
| 551 | + | |
| 552 | + | |
| 553 | + | |
| 554 | + | |
| 555 | + | |
| 556 | + | |
| 557 | + | |
| 558 | + | |
| 559 | + | |
| 560 | + | |
| 561 | + | |
| 562 | + | |
| 563 | + | |
| 564 | + | |
| 565 | + | |
| 566 | + | |
| 567 | + | |
| 568 | + | |
| 569 | + | |
| 570 | + | |
| 571 | + | |
| 572 | + | |
| 573 | + | |
| 574 | + | |
| 575 | + | |
| 576 | + | |
| 577 | + | |
| 578 | + | |
| 579 | + | |
| 580 | + | |
| 581 | + | |
| 582 | + | |
| 583 | + | |
| 584 | + | |
| 585 | + | |
| 586 | + | |
| 587 | + | |
| 588 | + | |
| 589 | + | |
541 | 590 | | |
542 | 591 | | |
543 | 592 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
37 | 37 | | |
38 | 38 | | |
39 | 39 | | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
40 | 44 | | |
41 | 45 | | |
42 | 46 | | |
| |||
51 | 55 | | |
52 | 56 | | |
53 | 57 | | |
54 | | - | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
55 | 63 | | |
56 | 64 | | |
57 | 65 | | |
| |||
65 | 73 | | |
66 | 74 | | |
67 | 75 | | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
68 | 80 | | |
69 | 81 | | |
70 | 82 | | |
| |||
82 | 94 | | |
83 | 95 | | |
84 | 96 | | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
85 | 101 | | |
86 | 102 | | |
87 | 103 | | |
| |||
0 commit comments