Fix rust_bindgen's clang include path and dep wiring - #4218
Open
AustinSchuh wants to merge 1 commit into
Open
Conversation
rust_bindgen rebuilds clang's command line from the cc_toolchain, but only keeps flags from an allowlist, and -idirafter isn't on it. toolchains_llvm passes every sysroot and builtin include directory that way (together with -nostdinc, so clang won't rediscover them on its own), which leaves bindgen parsing headers against a truncated include path. Whatever survives that filter is still a C++ compile's flags being handed to a C parse, so clang warns "argument unused during compilation" for each one, burying the real output. Add -Wno-unused-command-line-argument the same way the rule already adds -Wno-unknown-warning-option; both are clang-only, which is fine since everything after `--` goes to the clang bindgen forcibly uses. Finally, rules_rust now warns that a CcInfo-only target in a rust_library's 'deps' should be in 'link_deps'. Two of the targets the macro generates trip that: the thunks cc_library, and the bindgen target itself when merge_cc_lib_objects_into_rlib is off. Move those. The bindgen target has to stay in 'deps' when that flag is on (the default). There it links cc_lib into the rlib through a BuildInfo carrying -lstatic=/-Lnative= flags, and deliberately withholds cc_lib's libraries from its CcInfo so nothing downstream links them twice. transform_link_deps keeps only CcInfo, so routing it through 'link_deps' drops the objects and the binary fails to link. It also never warned, since BuildInfo already marks it as a Rust target. Signed-off-by: Austin Schuh <austin.linux@gmail.com>
AustinSchuh
force-pushed
the
bindgen-idirafter-and-link-deps
branch
from
August 10, 2026 07:23
440b326 to
977bf2f
Compare
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.
rust_bindgen rebuilds clang's command line from the cc_toolchain, but only keeps flags from an allowlist, and -idirafter isn't on it. toolchains_llvm passes every sysroot and builtin include directory that way (together with -nostdinc, so clang won't rediscover them on its own), which leaves bindgen parsing headers against a truncated include path.
Whatever survives that filter is still a C++ compile's flags being handed to a C parse, so clang warns "argument unused during compilation" for each one, burying the real output. Add -Wno-unused-command-line-argument the same way the rule already adds -Wno-unknown-warning-option; both are clang-only, which is fine since everything after
--goes to the clang bindgen forcibly uses.Finally, rules_rust now warns that a CcInfo-only target in a rust_library's 'deps' should be in 'link_deps'. Two of the targets the macro generates trip that: the thunks cc_library, and the bindgen target itself when merge_cc_lib_objects_into_rlib is off. Move those.
The bindgen target has to stay in 'deps' when that flag is on (the default). There it links cc_lib into the rlib through a BuildInfo carrying -lstatic=/-Lnative= flags, and deliberately withholds cc_lib's libraries from its CcInfo so nothing downstream links them twice. transform_link_deps keeps only CcInfo, so routing it through 'link_deps' drops the objects and the binary fails to link. It also never warned, since BuildInfo already marks it as a Rust target.