Repository navigation
Normalize Clang forwarded system header paths - #85
Merged
Merged
Conversation
This was referenced Oct 8, 2026
Draft
cerisier
marked this pull request as ready for review
October 8, 2026 11:29
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.
Port of bazelbuild#4321 onto this fork's main, preserving its existing path mapper and user compile-flag regressions. This is the copy needed by consumers such as rules_rs that pin hermeticbuild/rules_rust.
Cargo build scripts change working directory, so execroot-relative header operands must be made absolute. Recognize
-internal-externc-isystemand preserve-Xpreprocessorwhile awaiting the header path, just as for-Xclang. Otherwise Clang loses libc headers, producing errors such asstdlib.hnot found. Absolute paths and unrelated flags stay unchanged.Eight generated-action regressions cover both forwarding forms, both header categories, and relative/absolute operands. The corresponding tests expose three missing rewrites on upstream's unmodified baseline. All 40 tests in this fork's flag-handling package pass:
USE_BAZEL_VERSION=8.6.0 bazel test --config=remote --lockfile_mode=off \ --local_test_jobs=1 //cargo/tests/cargo_build_script/cc_args_and_env:allThe first concurrent macOS run hit a
generate-xml.shsegmentation fault on the existingbindir_relative_test; the sequential retry passed all 40 tests. Buildifier formatting/lint and whitespace checks pass.Merge blocker for hermeticbuild/hermetic-llvm#819 and hermeticbuild/hermetic-llvm#820, alongside the bazelbuild PR. Consumers must adopt a release or pin containing this fix before the hermetic-llvm stack merges.