Repository navigation
Conversation
|
Hi @phr4nky! Thank you for your pull request and welcome to our community. Action RequiredIn order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you. ProcessIn order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA. Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with If you have received this in error or have any questions, please contact us at [email protected]. Thanks! |
The system C++ toolchain mapped compiler_type "clang_cl" to the
show_headers dep tracking mode, which passes `-H`. clang-cl does not act
on `-H` ("argument unused during compilation: '-H'"), so every dep file
listed only the source file and edits to headers did not invalidate
cached compiles.
Use show_includes for clang_cl, as for cl.exe. clang-cl prints the
`Note: including file:` lines but, unlike cl.exe, no source file line
first, so only skip the first line of the output when it is not an
include note.
ba800b1 to
6249a15
Compare
|
This pull request has been imported. If you are a Meta employee, you can view this in D134594282. (Because this pull request was imported automatically, there will not be any future comments.) |
Summary:
`system_cxx_toolchain` (and `cxx_tools_info_toolchain`) with `compiler_type = "clang_cl"` tracks C/C++ dependencies with the `show_headers` mode, which passes `-H -fno-color-diagnostics`. clang-cl does not act on `-H`, so the dep file of every compile lists only the source file. Buck2 then treats all headers as unused by the compile, and edits to a header do not invalidate the cached object.
## Affected version
origin/main 4b47e1430e (checked) and release 2026-11-15 (5b3b13d3ea, same code). The mapping in `prelude/toolchains/cxx.bzl` has been in place since b179908fbd.
## Reproduction
```
printf 'int h1;\n' > h1.h
printf '#include "h1.h"\nint main(){return h1;}\n' > a.cpp
# what the toolchain runs today (show_headers mode):
python3 prelude/cxx/tools/dep_file_processor.py show_headers a.cpp dep.txt clang --driver-mode=cl /c a.cpp /Foa.obj -H -fno-color-diagnostics
cat dep.txt
# what clang-cl offers instead:
clang --driver-mode=cl /c a.cpp /Foa.obj /showIncludes
```
## Expected
The dep file lists `h1.h` and `a.cpp`, as it does for the same compile through clang's GNU driver (`clang -c a.cpp -H`).
## Actual
```
clang: warning: argument unused during compilation: '-H' [-Wunused-command-line-argument]
$ cat dep.txt
a.cpp
```
`/showIncludes` prints `Note: including file: ./h1.h`.
## Analysis (optional)
`_cxx_toolchain_from_cxx_tools_info` in `prelude/toolchains/cxx.bzl` maps `clang_cl` to `DepTrackingMode("show_headers")`, whose flags come from `tree_style_cc_dep_files` in `prelude/cxx/compiler.bzl`. clang-cl accepts `/showIncludes` like cl.exe, but unlike cl.exe it does not print the source file name as the first line of its output, and `show_includes_to_dep_file.py` drops the first line unconditionally, so the first header would still be lost after switching the mode.
## Patch (optional)
Map `clang_cl` to `show_includes`, and skip the first line of the `/showIncludes` output only when it is not an include note. Test Plan: new `ShowIncludesTest` cases in `prelude/cxx/tools/tests/test_dep_file_processor.py` (the clang-cl case fails before the change); the reproduction above with the `show_includes` mode and `/showIncludes` now writes `h1.h` and `a.cpp`; a cl.exe-style output with the source file line first still writes the same dep file as before. Tested with clang 21 in `--driver-mode=cl` on macOS, not with clang-cl.exe on Windows.
X-link: meta/buck2#1656
Reviewed By: dtolnay
Differential Revision: D134594282
fbshipit-source-id: 3630e28b64afd07f7ca1af093b5eff90de9d127a
|
This pull request has been merged in 4f16d9e. |
Summary: `system_cxx_toolchain` (and `cxx_tools_info_toolchain`) with `compiler_type = "clang"` tracks C/C++ dependencies with the `show_headers` mode, `clang -H`. clang does not print the headers it reads through `-include` or anything they include, and it does not print the files of `#embed`. The rules pass `prefix_header`, and a `precompiled_header` that is not compiled, as `-include <header>` tagged with the headers tag. The dep file leaves these headers out, so Buck2 treats them as unused, and an edit to one of them is a dep file cache hit that keeps the old object. This PR switches `clang` to the `makefile` mode, as gcc already uses: `clang -MD` lists all of them. ## Affected version origin/main 00c2ee4f74. The mapping in `prelude/toolchains/cxx.bzl` has been in place since b179908fbd (meta/buck2#1005). ## Reproduction ``` mkdir inc printf '#pragma once\nint inner;\n' > inc/inner.h printf '#pragma once\n#include "inner.h"\nint p;\n' > inc/prefix.h printf '#pragma once\nint q;\n' > inc/normal.h printf '#include "normal.h"\nint main(){return q+p+inner;}\n' > b.c python3 prelude/cxx/tools/dep_file_processor.py show_headers b.c dep.txt clang -Iinc -include inc/prefix.h -H -fno-color-diagnostics -c b.c -o b.o cat dep.txt ``` Through Buck2, with the e2e fixture of this PR and the prelude of origin/main: build `root//:lib[objects][r.c.o]`, edit `pi.h` (included by the prefix header `p.h`), and build again. ## Expected The dep file lists `inc/prefix.h` and `inc/inner.h`, as `dep_file_processor.py makefile` does for the same compile with `-MD`. The second build compiles again. ## Actual ``` inc/normal.h b.c ``` `buck2 audit dep-files root//:lib c_compile r.c` lists neither `p.h` nor `pi.h`, and `buck2 log what-ran` shows the second build as `LocalDepFileCache`. With this PR, both headers are listed and the compile runs again (`Local`). ## Notes - `clang_cl` and `clang_windows` keep their modes. meta/buck2#1656 changes the `clang_cl` line of the same block, so whichever lands second needs a trivial rebase. - With `makefile` mode, clang compiles also pick up the `\#` / `$$` unescaping of meta/buck2#1657. X-link: meta/buck2#1665 Reviewed By: dtolnay Differential Revision: D134817891 fbshipit-source-id: 7a5415dc4ca4385c3291fb61d0d7e48921610f9d
Summary: `system_cxx_toolchain` (and `cxx_tools_info_toolchain`) with `compiler_type = "clang"` tracks C/C++ dependencies with the `show_headers` mode, `clang -H`. clang does not print the headers it reads through `-include` or anything they include, and it does not print the files of `#embed`. The rules pass `prefix_header`, and a `precompiled_header` that is not compiled, as `-include <header>` tagged with the headers tag. The dep file leaves these headers out, so Buck2 treats them as unused, and an edit to one of them is a dep file cache hit that keeps the old object. This PR switches `clang` to the `makefile` mode, as gcc already uses: `clang -MD` lists all of them. ## Affected version origin/main 00c2ee4. The mapping in `prelude/toolchains/cxx.bzl` has been in place since b179908 (#1005). ## Reproduction ``` mkdir inc printf '#pragma once\nint inner;\n' > inc/inner.h printf '#pragma once\n#include "inner.h"\nint p;\n' > inc/prefix.h printf '#pragma once\nint q;\n' > inc/normal.h printf '#include "normal.h"\nint main(){return q+p+inner;}\n' > b.c python3 prelude/cxx/tools/dep_file_processor.py show_headers b.c dep.txt clang -Iinc -include inc/prefix.h -H -fno-color-diagnostics -c b.c -o b.o cat dep.txt ``` Through Buck2, with the e2e fixture of this PR and the prelude of origin/main: build `root//:lib[objects][r.c.o]`, edit `pi.h` (included by the prefix header `p.h`), and build again. ## Expected The dep file lists `inc/prefix.h` and `inc/inner.h`, as `dep_file_processor.py makefile` does for the same compile with `-MD`. The second build compiles again. ## Actual ``` inc/normal.h b.c ``` `buck2 audit dep-files root//:lib c_compile r.c` lists neither `p.h` nor `pi.h`, and `buck2 log what-ran` shows the second build as `LocalDepFileCache`. With this PR, both headers are listed and the compile runs again (`Local`). ## Notes - `clang_cl` and `clang_windows` keep their modes. #1656 changes the `clang_cl` line of the same block, so whichever lands second needs a trivial rebase. - With `makefile` mode, clang compiles also pick up the `\#` / `$$` unescaping of #1657. Pull Request resolved: #1665 Test Plan: - `tests/e2e/test_prelude_tools.rs`: the fixture library gets `prefix_header = "p.h"`, which includes `pi.h`. `test_dep_file_keeps_the_headers_found_next_to_the_source` expects both in the dep file. The new `test_edit_to_a_header_of_the_prefix_header_rebuilds_the_object` edits only `pi.h` and expects a `Local` compile. - Checked manually on macOS (the e2e test is skipped there) with a locally built buck2 against the fixture: origin/main gives `LocalDepFileCache`, this branch gives `Local`. Reviewed By: dtolnay Differential Revision: D134817891 fbshipit-source-id: 7a5415dc4ca4385c3291fb61d0d7e48921610f9d
Summary
system_cxx_toolchain(andcxx_tools_info_toolchain) withcompiler_type = "clang_cl"tracks C/C++ dependencies with theshow_headersmode, which passes-H -fno-color-diagnostics. clang-cl does not act on-H, so the dep file of every compile lists only the source file. Buck2 then treats all headers as unused by the compile, and edits to a header do not invalidate the cached object.Affected version
origin/main 4b47e14 (checked) and release 2026-11-15 (5b3b13d, same code). The mapping in
prelude/toolchains/cxx.bzlhas been in place since b179908.Reproduction
Expected
The dep file lists
h1.handa.cpp, as it does for the same compile through clang's GNU driver (clang -c a.cpp -H).Actual
/showIncludesprintsNote: including file: ./h1.h.Analysis (optional)
_cxx_toolchain_from_cxx_tools_infoinprelude/toolchains/cxx.bzlmapsclang_cltoDepTrackingMode("show_headers"), whose flags come fromtree_style_cc_dep_filesinprelude/cxx/compiler.bzl. clang-cl accepts/showIncludeslike cl.exe, but unlike cl.exe it does not print the source file name as the first line of its output, andshow_includes_to_dep_file.pydrops the first line unconditionally, so the first header would still be lost after switching the mode.Patch (optional)
Map
clang_cltoshow_includes, and skip the first line of the/showIncludesoutput only when it is not an include note. Test Plan: newShowIncludesTestcases inprelude/cxx/tools/tests/test_dep_file_processor.py(the clang-cl case fails before the change); the reproduction above with theshow_includesmode and/showIncludesnow writesh1.handa.cpp; a cl.exe-style output with the source file line first still writes the same dep file as before. Tested with clang 21 in--driver-mode=clon macOS, not with clang-cl.exe on Windows.