bazelbuild / bazelbuild/bazel

Allow creating a label to the directory at the root of an external repo

Open
#26,721 0 comments 0 reactions 0 assignees View on GitHub
P3 team-ExternalDeps type: feature request
Dominant language
Java
Stars
25.8k
Forks
4.6k
Avg merge
2d 18h
Merged PRs (30d)
75

Description

### Description of the feature request:

I was asked to file this by @fmeum.

A frequent pain point I have is the inability to unequivocally reference the root of an external repo. The most common workarounds I've seen is using `@repo//:all` or `@repo//:BUILD.bazel` and then just dropping the path-piece in the rule/macro where you use it, but this can't safely work in all cases (and requires every consumer to have specific code to ignore the path). Allowing something like `@repo//:self` or just `@repo//` to reference the root of the repo would allow for an unequivocal expression of intent.

There are a lot of APIs spread across various modules that are affected by this lack:
- rules_go takes a label to a file at the root, and then infers the directory from that ([ref](https://github.com/bazel-contrib/rules_go/blob/master/go/toolchains.rst#go_wrap_sdk))
- rules_pkg has a complicated mix of magic stripping (strip_prefix) that can't target arbitrary labels, and the (deprecated) string-based stripping (remap_paths).
- rules_python uses the BUILD.bazel workaround for [`_python_path_entries`](https://github.com/bazel-contrib/rules_python/blob/babfc2b336ba9386f3a6c30ac5017969f7dae031/python/private/pypi/whl_library.bzl#L633).
- rules_scala uses the [`:all` trick](https://github.com/bazel-contrib/rules_scala/blob/f7bacdf1cb19a36739607934ae53e4935da7206c/scala/toolchains_repo.bzl#L45)

I'm sure there are others!

### Which category does this issue belong to?

External Dependency

### What underlying problem are you trying to solve with this feature?

To provide an unequivocal method of referring to the root of an external as a label, to facilitate attributes that need directories instead of files.

### Which operating system are you running Bazel on?

linux

### What is the output of `bazel info release`?

release 8.3.1

### 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` ?

```text

```

### 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

Open the contributing guide

Research direction

No Bazel source files or tests are named. Start by locating the label-parsing and external-repository handling entry points, then trace how root labels are represented and validated. Done means an external repository root has one unequivocal label form, with coverage for the proposed syntax and affected label consumers.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
build-system
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.