Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: allow labels as path argument of local_repository rule #11573

Open
smolkaj opened this issue Jun 10, 2020 · 3 comments
Open
Labels
P4 This is either out of scope or we don't have bandwidth to review a PR. (No assignee) team-ExternalDeps External dependency handling, remote repositiories, WORKSPACE file. type: feature request

Comments

@smolkaj
Copy link

smolkaj commented Jun 10, 2020

Description of feature request:

The path argument of the local_repository rule can currently be only a relative or absolute path, see https://docs.bazel.build/versions/master/be/workspace.html#local_repository_args.
This request asks to support labels as well.

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

Projects using the local_repository rule are currently not compositional in the sense that they brake when nested inside other Bazel projects. The root cause is that relative paths are resolved with respect to the including project instead of the included project.

Details

To allow the nested use of bazel projects within other bazel projects, it is customary to define a function <project name>_deps that sets up all necessary repositories like so:

# awesome_project/awesome_project_deps.bzl
def awesome_project_deps():
    """Loads dependencies need to compile this project."""
    if not native.existing_rule("com_google_googletest"):
        http_archive(
            name = "com_google_googletest",
            urls = ["https://github.com/google/googletest/archive/release-1.10.0.tar.gz"],
            strip_prefix = "googletest-release-1.10.0",
            sha256 = "9dc9157a9a1551ec7a7e43daea9a694a0bb5fb8bec81235d8a1e6ef64c716dcb",
        )
        native.local_repository(
            name = "com_google_protobuf",
            // If we call this function from another Bazel project, the below path will be
            // interpreted relative to the root of that project, causing breakage. 
            path = "third_party/protobuf",
            // This problem could be solved by allowing the use of labels:
            // path = "@com_github_awesome_project//:third_party/protobuf",
        )
    ...

Users of the project can then load all transitive dependencies by calling the function in their WORKSPACE file:

# another_project/WORKSPACE
load(@com_github_awesome_project//:awesome_project_deps.bzl, awesome_project_deps)
awesome_project_deps()  # Fails because `another_project/third_party/protobuf` does not exist.

Here are examples of this pattern in widely used projects: protobuf, grpc, ...

Unfortunately, this pattern brakes when local_repository together with a local path is used by the project one includes, as the relative path is resolved with respect to the root of the including (rather than the included) project.
The problem could be solved by using a label instead of a relative path, since labels can be absolute rather than relative.

@smolkaj
Copy link
Author

smolkaj commented Jun 10, 2020

@stefanheule FYI

smolkaj added a commit to smolkaj/p4c that referenced this issue Jun 10, 2020
…roject.

* Use local repositories for local build, but fall back to git repositories for
  3rd party build. This is necessary due to
  bazelbuild/bazel#11573

* Rename lex -> flex.

* Ignore bazel sub-projects so `bazel build //...` works.
smolkaj added a commit to smolkaj/p4c that referenced this issue Jun 10, 2020
…roject.

* Use local repositories for local build, but fall back to git repositories for
  3rd party build. This is necessary due to
  bazelbuild/bazel#11573

* Rename lex -> flex.

* Ignore bazel sub-projects so `bazel build //...` works.
smolkaj added a commit to smolkaj/p4c that referenced this issue Jun 10, 2020
…roject.

* Use local repositories for local build, but fall back to git repositories for
  3rd party build. This is necessary due to
  bazelbuild/bazel#11573

* Rename lex -> flex.

* Ignore bazel sub-projects so `bazel build //...` works.
@jin jin added team-ExternalDeps External dependency handling, remote repositiories, WORKSPACE file. untriaged labels Jun 10, 2020
@philwo philwo added the team-OSS Issues for the Bazel OSS team: installation, release processBazel packaging, website label Jun 15, 2020
@philwo philwo added P4 This is either out of scope or we don't have bandwidth to review a PR. (No assignee) type: feature request and removed untriaged labels Dec 8, 2020
@philwo philwo removed the team-OSS Issues for the Bazel OSS team: installation, release processBazel packaging, website label Nov 29, 2021
@github-actions
Copy link

Thank you for contributing to the Bazel repository! This issue has been marked as stale since it has not had any activity in the last 1+ years. It will be closed in the next 14 days unless any other activity occurs or one of the following labels is added: "not stale", "awaiting-bazeler". Please reach out to the triage team (@bazelbuild/triage) if you think this issue is still relevant or you are interested in getting the issue resolved.

@github-actions github-actions bot added the stale Issues or PRs that are stale (no activity for 30 days) label May 24, 2023
@sudoforge
Copy link

@bazelbuild/triage please review this issue; i believe it is a valid feature request.

@github-actions github-actions bot removed the stale Issues or PRs that are stale (no activity for 30 days) label May 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P4 This is either out of scope or we don't have bandwidth to review a PR. (No assignee) team-ExternalDeps External dependency handling, remote repositiories, WORKSPACE file. type: feature request
Projects
None yet
Development

No branches or pull requests

4 participants