Repository navigation
Conversation
Contributor
|
This pull request has been imported. If you are a Meta employee, you can view this in D134817891. (Because this pull request was imported automatically, there will not be any future comments.) |
|
Please rebase, this conflicted with #1656. |
`system_cxx_toolchain` with `compiler_type = "clang"` tracked headers with `clang -H`. clang does not print what it reads through `-include`, which is how the rules pass `prefix_header` (and a `precompiled_header` that is not compiled), nor anything those headers include, nor the files of `#embed`. The dep file left them out, so Buck2 treated them as unused, and an edit to them was a dep file cache hit that kept the old object. Use the `makefile` mode for clang, as for gcc: `clang -MD` lists all of them. The e2e fixture gets a prefix header that includes another header.
phr4nky
force-pushed
the
fix-clang-prefix-header-dep-files
branch
from
November 28, 2026 08:00
d4a17c7 to
62f641e
Compare
Contributor
Author
|
@dtolnay thanks - rebased and merge conflict solved. |
dtolnay
approved these changes
Nov 28, 2026
meta-codesync Bot
pushed a commit
to meta/buck2-prelude
that referenced
this pull request
Nov 28, 2026
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
Contributor
|
This pull request has been merged in d2a81a5. |
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
system_cxx_toolchain(andcxx_tools_info_toolchain) withcompiler_type = "clang"tracks C/C++ dependencies with theshow_headersmode,clang -H. clang does not print the headers it reads through-includeor anything they include, and it does not print the files of#embed. The rules passprefix_header, and aprecompiled_headerthat 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
clangto themakefilemode, as gcc already uses:clang -MDlists all of them.Affected version
origin/main 00c2ee4. The mapping in
prelude/toolchains/cxx.bzlhas been in place since b179908 (#1005).Reproduction
Through Buck2, with the e2e fixture of this PR and the prelude of origin/main: build
root//:lib[objects][r.c.o], editpi.h(included by the prefix headerp.h), and build again.Expected
The dep file lists
inc/prefix.handinc/inner.h, asdep_file_processor.py makefiledoes for the same compile with-MD. The second build compiles again.Actual
buck2 audit dep-files root//:lib c_compile r.clists neitherp.hnorpi.h, andbuck2 log what-ranshows the second build asLocalDepFileCache. With this PR, both headers are listed and the compile runs again (Local).Notes
clang_clandclang_windowskeep their modes. prelude: Track headers of clang-cl compiles with /showIncludes #1656 changes theclang_clline of the same block, so whichever lands second needs a trivial rebase.makefilemode, clang compiles also pick up the\#/$$unescaping of prelude: Unescape#and$in makefile dep files #1657.Test plan
tests/e2e/test_prelude_tools.rs: the fixture library getsprefix_header = "p.h", which includespi.h.test_dep_file_keeps_the_headers_found_next_to_the_sourceexpects both in the dep file. The newtest_edit_to_a_header_of_the_prefix_header_rebuilds_the_objectedits onlypi.hand expects aLocalcompile.LocalDepFileCache, this branch givesLocal.