diff --git a/clang/docs/StandardCPlusPlusModules.rst b/clang/docs/StandardCPlusPlusModules.rst index 06609063c61c9..3aeb55d8f4dad 100644 --- a/clang/docs/StandardCPlusPlusModules.rst +++ b/clang/docs/StandardCPlusPlusModules.rst @@ -1072,12 +1072,6 @@ the user can choose to get the dependency information per file. For example: $ clang-scan-deps -format=p1689 -- /clang++ -std=c++20 impl_part.cppm -c -o impl_part.o -.. warning:: - - The ``/clang++`` should point to the real - binary and not to a symlink. If it points to a symlink the include paths - will not be correctly resolved. - And we'll get: .. code-block:: text @@ -1134,6 +1128,32 @@ We will get: When clang-scan-deps detects ``-MF`` option, clang-scan-deps will try to write the dependency information for headers to the file specified by ``-MF``. +Possible Issues: Failed to find system headers +---------------------------------------------- + +In case the users encounter errors like ``fatal error: 'stddef.h' file not found``, +probably the specified ``/clang++`` refers to a symlink +instead a real binary. There are 4 potential solutions to the problem: + +* (1) End users can resolve the issue by pointing the specified compiler executable to + the real binary instead of the symlink. +* (2) End users can invoke ``/clang++ -print-resource-dir`` + to get the corresponding resource directory for your compiler and add that directory + to the include search paths manually in the build scripts. +* (3) Build systems that use a compilation database as the input for clang-scan-deps + scanner, the build system can add the flag ``--resource-dir-recipe invoke-compiler`` to + the clang-scan-deps scanner to calculate the resources directory dynamically. + The calculation happens only once for a unique ``/clang++``. +* (4) For build systems that invokes the clang-scan-deps scanner per file, repeatedly + calculating the resource directory may be inefficient. In such cases, the build + system can cache the resource directory by itself and pass ``-resource-dir `` + explicitly in the command line options: + +.. code-block:: console + + $ clang-scan-deps -format=p1689 -- /clang++ -std=c++20 -resource-dir mod.cppm -c -o mod.o + + Possible Questions ================== diff --git a/clang/test/ClangScanDeps/pr61006.cppm b/clang/test/ClangScanDeps/pr61006.cppm new file mode 100644 index 0000000000000..13cfe385be2e2 --- /dev/null +++ b/clang/test/ClangScanDeps/pr61006.cppm @@ -0,0 +1,44 @@ +// The slash direction in linux and windows are different. +// Also the command to create symbolic link is different. +// UNSUPPORTED: system-windows +// +// RUN: rm -fr %t +// RUN: mkdir -p %t +// RUN: split-file %s %t +// +// RUN: EXPECTED_RESOURCE_DIR=`%clang -print-resource-dir` +// RUN: ln -s %clang++ %t/clang++ +// RUN: sed "s|EXPECTED_RESOURCE_DIR|$EXPECTED_RESOURCE_DIR|g; s|DIR|%/t|g" %t/P1689.json.in > %t/P1689.json +// RUN: clang-scan-deps -compilation-database %t/P1689.json -format=p1689 | FileCheck %t/a.cpp -DPREFIX=%/t +// RUN: clang-scan-deps -format=p1689 \ +// RUN: -- %t/clang++ -std=c++20 -c -fprebuilt-module-path=%t %t/a.cpp -o %t/a.o \ +// RUN: -resource-dir $EXPECTED_RESOURCE_DIR | FileCheck %t/a.cpp -DPREFIX=%/t + +//--- P1689.json.in +[ +{ + "directory": "DIR", + "command": "DIR/clang++ -std=c++20 -c -fprebuilt-module-path=DIR DIR/a.cpp -o DIR/a.o -resource-dir EXPECTED_RESOURCE_DIR", + "file": "DIR/a.cpp", + "output": "DIR/a.o" +} +] + +//--- a.cpp +#include +import b; + +// CHECK: { +// CHECK-NEXT: "revision": 0, +// CHECK-NEXT: "rules": [ +// CHECK-NEXT: { +// CHECK-NEXT: "primary-output": "[[PREFIX]]/a.o", +// CHECK-NEXT: "requires": [ +// CHECK-NEXT: { +// CHECK-NEXT: "logical-name": "b" +// CHECK-NEXT: } +// CHECK-NEXT: ] +// CHECK-NEXT: } +// CHECK-NEXT: ], +// CHECK-NEXT: "version": 1 +// CHECK-NEXT: }