cc runfiles - `BAZEL_CURRENT_REPOSITORY` should be `_main` when run from the root module
- Dominant language
- Java
- Stars
- 25.8k
- Forks
- 4.6k
- Avg merge
- 2d 20h
- Merged PRs (30d)
- 72
Description
### Description of the feature request:
When you use runfiles as per the documentation in [runfiles.h](https://github.com/bazelbuild/rules_cc/blob/0.1.1/cc/runfiles/runfiles.h), `BAZEL_CURRENT_REPOSITORY` turns out to be:
- Module name of the 3P library that has the code if the usage is in a 3P library - good 👍🏾 working as expected.
- empty if run from the root module. - ❌ not intuitive.
**Request:**
Return `BAZEL_CURRENT_REPOSITORY` as `_main` instead of returning empty when run from the root module. That also easily resolves runfiles from that path.
### Which category does this issue belong to?
Core
### What underlying problem are you trying to solve with this feature?
**Problem:**
The runfile object doesn't exist at the path that I construct from `BAZEL_CURRENT_REPOSITORY` as the files are present in `_main` instead of `` (empty path) for the root module.
**Workaround:**
The current workaround is to catch the empty, interpret it as `_main` but this is undocumented in the header file and/or confusing.
### Which operating system are you running Bazel on?
linux x86_64
### What is the output of `bazel info release`?
release 8.1.1
### If `bazel info release` returns `development version` or `(@non-git)`, tell us how you built Bazel.
N/A - bazelisk
### What's the output of `git remote get-url origin; git rev-parse HEAD` ?
```text
N/A - private repo
```
### Have you found anything relevant by searching the web?
_No response_
### Any other information, logs, or outputs that you want to share?
I'm creating the bug here instead of `rules_cc` because as I understand, the value of `BAZEL_CURRENT_REPOSITORY` is provided by bazel itself (and _not_ rules_cc)
Cc: @meteorcloudy
Contributor guide
Research direction
Start with the runfiles documentation in cc/runfiles/runfiles.h and trace how Bazel provides BAZEL_CURRENT_REPOSITORY for code in the root module versus a third-party module. Identify the relevant Bazel entry point and tests, then verify that root-module lookups use _main and that the existing third-party behavior remains unchanged.
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
- Mostly clear
- Newbie friendliness
- 35/100