Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[C++20] [Modules] [ClangScanDeps] Add ClangScanDeps support for C++20…
… Named Modules in P1689 format (2/4) Close #51792 Close #56770 This patch adds ClangScanDeps support for C++20 Named Modules in P1689 format. We can find the P1689 format at: https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2022/p1689r5.html. After we land the patch, we're able to compile C++20 Named Modules with CMake! And although P1689 is written by kitware people, other build systems should be able to use the format to compile C++20 Named Modules too. TODO: Support header units in P1689 Format. TODO2: Support C++20 Modules in the full dependency format of ClangScanDeps. We also want to support C++20 Modules and clang modules together according to https://discourse.llvm.org/t/how-should-we-support-dependency-scanner-for-c-20-modules/66027. But P1689 format cares about C++20 Modules only for now. So let's focus on C++ Modules and P1689 format. And look at the full dependency format later. I'll add the ReleaseNotes and Documentations after the patch get landed. Reviewed By: jansvoboda11 Differential Revision: https://reviews.llvm.org/D137527
- Loading branch information
1 parent
6470706
commit de17c66
Showing
9 changed files
with
382 additions
and
13 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,157 @@ | ||
// RUN: rm -fr %t | ||
// RUN: mkdir -p %t | ||
// RUN: split-file %s %t | ||
// | ||
// RUN: sed "s|DIR|%/t|g" %t/P1689.json.in > %t/P1689.json | ||
// RUN: clang-scan-deps -compilation-database %t/P1689.json -format=p1689 | FileCheck %t/Checks.cpp -DPREFIX=%/t | ||
// RUN: clang-scan-deps --mode=preprocess-dependency-directives -compilation-database %t/P1689.json -format=p1689 | FileCheck %t/Checks.cpp -DPREFIX=%/t | ||
|
||
//--- P1689.json.in | ||
[ | ||
{ | ||
"directory": "DIR", | ||
"command": "clang++ -std=c++20 DIR/M.cppm -c -o DIR/M.o", | ||
"file": "DIR/M.cppm", | ||
"output": "DIR/M.o" | ||
}, | ||
{ | ||
"directory": "DIR", | ||
"command": "clang++ -std=c++20 DIR/Impl.cpp -c -o DIR/Impl.o", | ||
"file": "DIR/Impl.cpp", | ||
"output": "DIR/Impl.o" | ||
}, | ||
{ | ||
"directory": "DIR", | ||
"command": "clang++ -std=c++20 DIR/impl_part.cppm -c -o DIR/impl_part.o", | ||
"file": "DIR/impl_part.cppm", | ||
"output": "DIR/impl_part.o" | ||
}, | ||
{ | ||
"directory": "DIR", | ||
"command": "clang++ -std=c++20 DIR/interface_part.cppm -c -o DIR/interface_part.o", | ||
"file": "DIR/interface_part.cppm", | ||
"output": "DIR/interface_part.o" | ||
}, | ||
{ | ||
"directory": "DIR", | ||
"command": "clang++ -std=c++20 DIR/User.cpp -c -o DIR/User.o", | ||
"file": "DIR/User.cpp", | ||
"output": "DIR/User.o" | ||
} | ||
] | ||
|
||
|
||
//--- M.cppm | ||
export module M; | ||
export import :interface_part; | ||
import :impl_part; | ||
export void Hello(); | ||
|
||
//--- Impl.cpp | ||
module; | ||
#include "header.mock" | ||
module M; | ||
void Hello() { | ||
std::cout << "Hello "; | ||
} | ||
|
||
//--- impl_part.cppm | ||
module; | ||
#include "header.mock" | ||
module M:impl_part; | ||
import :interface_part; | ||
|
||
std::string W = "World."; | ||
void World() { | ||
std::cout << W << std::endl; | ||
} | ||
|
||
//--- interface_part.cppm | ||
export module M:interface_part; | ||
export void World(); | ||
|
||
//--- User.cpp | ||
import M; | ||
import third_party_module; | ||
int main() { | ||
Hello(); | ||
World(); | ||
return 0; | ||
} | ||
|
||
//--- Checks.cpp | ||
// CHECK: { | ||
// CHECK-NEXT: "revision": 0, | ||
// CHECK-NEXT: "rules": [ | ||
// CHECK-NEXT: { | ||
// CHECK-NEXT: "primary-output": "[[PREFIX]]/Impl.o", | ||
// CHECK-NEXT: "requires": [ | ||
// CHECK-NEXT: { | ||
// CHECK-NEXT: "logical-name": "M", | ||
// CHECK-NEXT: "source-path": "[[PREFIX]]/M.cppm" | ||
// CHECK-NEXT: } | ||
// CHECK-NEXT: ] | ||
// CHECK-NEXT: }, | ||
// CHECK-NEXT: { | ||
// CHECK-NEXT: "primary-output": "[[PREFIX]]/M.o", | ||
// CHECK-NEXT: "provides": [ | ||
// CHECK-NEXT: { | ||
// CHECK-NEXT: "is-interface": true, | ||
// CHECK-NEXT: "logical-name": "M", | ||
// CHECK-NEXT: "source-path": "[[PREFIX]]/M.cppm" | ||
// CHECK-NEXT: } | ||
// CHECK-NEXT: ], | ||
// CHECK-NEXT: "requires": [ | ||
// CHECK-NEXT: { | ||
// CHECK-NEXT: "logical-name": "M:interface_part", | ||
// CHECK-NEXT: "source-path": "[[PREFIX]]/interface_part.cppm" | ||
// CHECK-NEXT: }, | ||
// CHECK-NEXT: { | ||
// CHECK-NEXT: "logical-name": "M:impl_part", | ||
// CHECK-NEXT: "source-path": "[[PREFIX]]/impl_part.cppm" | ||
// CHECK-NEXT: } | ||
// CHECK-NEXT: ] | ||
// CHECK-NEXT: }, | ||
// CHECK-NEXT: { | ||
// CHECK-NEXT: "primary-output": "[[PREFIX]]/User.o", | ||
// CHECK-NEXT: "requires": [ | ||
// CHECK-NEXT: { | ||
// CHECK-NEXT: "logical-name": "M", | ||
// CHECK-NEXT: "source-path": "[[PREFIX]]/M.cppm" | ||
// CHECK-NEXT: }, | ||
// CHECK-NEXT: { | ||
// CHECK-NEXT: "logical-name": "third_party_module" | ||
// CHECK-NEXT: } | ||
// CHECK-NEXT: ] | ||
// CHECK-NEXT: }, | ||
// CHECK-NEXT: { | ||
// CHECK-NEXT: "primary-output": "[[PREFIX]]/impl_part.o", | ||
// CHECK-NEXT: "provides": [ | ||
// CHECK-NEXT: { | ||
// CHECK-NEXT: "is-interface": false, | ||
// CHECK-NEXT: "logical-name": "M:impl_part", | ||
// CHECK-NEXT: "source-path": "[[PREFIX]]/impl_part.cppm" | ||
// CHECK-NEXT: } | ||
// CHECK-NEXT: ], | ||
// CHECK-NEXT: "requires": [ | ||
// CHECK-NEXT: { | ||
// CHECK-NEXT: "logical-name": "M:interface_part", | ||
// CHECK-NEXT: "source-path": "[[PREFIX]]/interface_part.cppm" | ||
// CHECK-NEXT: } | ||
// CHECK-NEXT: ] | ||
// CHECK-NEXT: }, | ||
// CHECK-NEXT: { | ||
// CHECK-NEXT: "primary-output": "[[PREFIX]]/interface_part.o", | ||
// CHECK-NEXT: "provides": [ | ||
// CHECK-NEXT: { | ||
// CHECK-NEXT: "is-interface": true, | ||
// CHECK-NEXT: "logical-name": "M:interface_part", | ||
// CHECK-NEXT: "source-path": "[[PREFIX]]/interface_part.cppm" | ||
// CHECK-NEXT: } | ||
// CHECK-NEXT: ] | ||
// CHECK-NEXT: } | ||
// CHECK-NEXT: ], | ||
// CHECK-NEXT: "version": 1 | ||
// CHECK-NEXT: } | ||
|
||
//--- header.mock |
Oops, something went wrong.