bazelbuild / bazelbuild/rules_cc
Fragment flags are not considered during builtin includes resolution
- Dominant language
- Starlark
- Stars
- 247
- Forks
- 196
- PR merge metrics
- No merged PRs in 30d
Description
https://github.com/bazelbuild/rules_cc/blob/fe7ca631abefced2830a4b18e5d29eb3f1d82013/cc/private/toolchain/unix_cc_configure.bzl#L469
Here only the value from the environment variable is considered but flags from the [fragment](https://bazel.build/rules/lib/fragments/cpp#cxxopts) are ignored. I am aware that fragments are not available in repository rules. However, builtin includes might be resolved incorrectly in some cases if options are only provided using the fragment.
For example if for example when `-stdlib=libc++` is defined using the flag:
```
bazel cquery '@@rules_cc+//cc:current_cc_toolchain' --output=starlark --starlark:expr='providers(target)["@@_builtins//:common/cc/cc_toolchain_info.bzl%CcToolchainInfo"].built_in_include_directories' --action_env=CC=/usr/bin/clang --action_env=CXX=/usr/bin/clang --cxxopt=-stdlib=libc++
["/usr/lib/clang/20/include", "/usr/local/include", "/usr/include", "/usr/lib/clang/20/share", "/usr/include/c++/15", "/usr/include/c++/15/x86_64-redhat-linux", "/usr/include/c++/15/backward", "/usr/include/c++/v1", "/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk"]
```
And when `-stdlib=libc++` is defined using the environment variable:
```
BAZEL_CXXOPTS=-stdlib=libc++ bazel cquery '@@rules_cc+//cc:current_cc_toolchain' --output=starlark --starlark:expr='providers(target)["@@_builtins//:common/cc/cc_toolchain_info.bzl%CcToolchainInfo"].built_in_include_directories' --action_env=CC=/usr/bin/clang --action_env=CXX=/usr/bin/clang
["/usr/lib/clang/20/include", "/usr/local/include", "/usr/include", "/usr/lib/clang/20/share", "/usr/include/c++/v1", "/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk"]
```
Contributor guide
Research direction
Start in cc/private/toolchain/unix_cc_configure.bzl around line 469 and compare the reported cquery results for --cxxopt=-stdlib=libc++ with those using BAZEL_CXXOPTS. Trace how builtin_include_directories are resolved, then verify that fragment-provided flags produce the same correct include paths without changing the environment-variable case.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- build-system, compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100