[CC Toolchains] Enable access to bazel generated files for tool paths
- Dominant language
- Java
- Stars
- 25.8k
- Forks
- 4.6k
- Avg merge
- 2d 18h
- Merged PRs (30d)
- 75
Description
### Description of the feature request:
Allow tool_paths to access generated files for toolchains in a third party dependency.
### Which category does this issue belong to?
C++ Rules
### What underlying problem are you trying to solve with this feature?
I am attempting to create a hermetic cc toolchain for a project at our company. However the toolchain (specifically their version of "GCC") likes using absolute paths and requires an environment variable that represents an absolute path. Since the sandbox path changes at any given moment for the build, my goal is to create a wrapper script which will resolve the correct path and call "GCC" with the right arguments.
I have a third party dependency that wraps the toolchain. When I create the toolchain with the `cc_toolchain` rule, it takes in "all_files" as a filegroup. That filegroup also contains the wrapper script, which is generated via a "write_file" rule. However, when I can't seem to point `tool paths` to the wrapper script since it shows up in `bazel-out/-fastbuild/bin` instead of the repo directly. When I try to use some relative path or a non-normalized path (such as `../../bazel-out/...`) it complains with the following error:
```
File "/virtual_builtins_bzl/common/cc/cc_toolchain.bzl", line 55, column 45, in _cc_toolchain_impl
File "/virtual_builtins_bzl/common/cc/cc_toolchain_provider_helper.bzl", line 173, column 37, in get_cc_toolchain_provider
File "/virtual_builtins_bzl/common/cc/cc_toolchain_provider_helper.bzl", line 78, column 17, in _compute_tool_paths
Error in fail: The include path '../../bazel-out/linux_x86_64_platform-opt-exec/bin/external/dep/wrapper_script.sh' is not normalized.
```
### Which operating system are you running Bazel on?
Linux
### What is the output of `bazel info release`?
7.0.2
### If `bazel info release` returns `development version` or `(@non-git)`, tell us how you built Bazel.
_No response_
### What's the output of `git remote get-url origin; git rev-parse HEAD` ?
_No response_
### Have you found anything relevant by searching the web?
_No response_
### Any other information, logs, or outputs that you want to share?
_No response_
Contributor guide
Research direction
Reproduce the third-party cc_toolchain case with a write_file-generated wrapper in all_files, then inspect the cited virtual builtins files: common/cc/cc_toolchain.bzl and common/cc/cc_toolchain_provider_helper.bzl. Start at _compute_tool_paths and verify the expected handling of generated paths; done means tool_paths can reference the generated wrapper without the non-normalized-path error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- build-system
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100