Repository navigation
Normalize Clang forwarded system header paths - #4321
Merged
Merged
Conversation
This was referenced Oct 8, 2026
cerisier
marked this pull request as ready for review
October 8, 2026 11:30
cerisier
added a commit
to hermeticbuild/hermetic-llvm
that referenced
this pull request
Nov 17, 2026
Fixes #804 ## Why Toolchain `-isystem` paths can outrank dependency headers, Clang builtins, and libc++ wrappers. This can select the wrong header or break `#include_next` chains. Explicit component directories need the search order chosen by Clang's target toolchain, while builtins remain owned by `-resource-dir`. ## How Pass component paths through the driver categories that own their final order: - C++ roots use joined `-stdlib++-isystem<dir>` options, forwarded through `/clang:` for clang-cl. On macOS, the selected split libc++ roots replace duplicate SDK discovery. Opt-in MSVC STL keeps `/imsvc`. - GNU kernel/libc roots use `-Xclang -internal-externc-isystem -Xclang <dir>`. - MinGW and MSVC C/SDK roots use forwarded `-internal-isystem` pairs. Clang builtins remain under `-resource-dir`. Musl retains its existing `-isystem` flags and C-before-builtin order. Its separate user-header precedence issue is tracked in #820, so its desired-order goldens remain manual. This PR remains the alternative to #818. The required consumer fixes are merged and adopted through released modules, without temporary overrides for these fixes: - [rules_go #4739](bazel-contrib/rules_go#4739) makes explicit Clang header paths absolute when cgo changes directories and preserves forwarded path operands. Adopted through rules_go 0.65.0. - [rules_rust #4321](bazelbuild/rules_rust#4321) makes forwarded extern-C header paths absolute when Cargo build scripts change directories. Adopted through rules_rust 0.75.0. - [hermeticbuild/rules_rust #85](hermeticbuild/rules_rust#85) ports that path fix to the fork consumed by rules_rs. Adopted through rules_rs 0.2.4. - [rules_foreign_cc #1603](bazel-contrib/rules_foreign_cc#1603) keeps complete Clang header-flag groups in `CC` because bootstrap configure probes can omit `CFLAGS`. Adopted through rules_foreign_cc 0.17.0. Longer term, the [LLVM `-cstdlib-isystem` RFC](https://discourse.llvm.org/t/rfc-add-a-driver-option-to-specify-c-library-header-directories/92650) proposes a public driver option for explicit C header roots, letting Clang place them according to each target's search order without private frontend flags. ## Tests Bazel fixtures compile real `#include_next` wrappers and libc++ C wrappers. Golden tests replay native Bazel compile actions with `-E -v` and compare the effective quote and angle search lists. All 39 active golden tests pass under [Bazel 8](https://app.buildbuddy.io/invocation/47dc38e5-9042-4b97-8340-5bb051ea3aa3), [Bazel 9](https://app.buildbuddy.io/invocation/808e4295-808f-439d-bc49-cb75f169dee5), and [Bazel 10 RC](https://app.buildbuddy.io/invocation/bf4ea14d-066e-4aea-a0f2-438648baad5c); [native macOS arm64 C/C++ tests pass](https://app.buildbuddy.io/invocation/62876405-755d-49c2-b56a-5ecc37563fd8). Musl desired-order goldens remain manual until #820.
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.
Cargo build scripts change working directory, so execroot-relative C/C++ header operands must be made absolute. The existing path mapper does not recognize
-internal-externc-isystem, and clears its pending operand when it encounters-Xpreprocessor. Clang then loses the libc headers, causing failures such asstdlib.hnot found when building lz4-sys.Recognize the extern-C system-header category and skip either Clang forwarding token while awaiting the path. Keep absolute paths and unrelated flags unchanged. This supports both late
-Xclangforwarding and early-Xpreprocessorforwarding without changing header order.Eight generated-action regressions cover the two forwarding forms, two header categories, and relative/absolute operands. On unmodified main, the three newly affected relative-path cases report missing rewritten operands during analysis. With the fix, all 38 tests pass:
USE_BAZEL_VERSION=8.6.0 bazel test --lockfile_mode=off //cargo/tests/cargo_build_script/cc_args_and_env:all