bazelbuild / bazel

a fast, scalable, multi-language and extensible build system
https://bazel.build
Apache License 2.0
22.74k stars 3.99k forks source link

`use_extension` fails with bzl from a repo introduced by `use_repo_rule` #22414

Open laurentlb opened 2 months ago

laurentlb commented 2 months ago

Description of the bug:

My MODULE.bazel file looks like this:

http_archive = use_repo_rule("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
http_archive(
    name = "config",
    ...)

repo_ext = use_extension("@config//:repo_ext.bzl", "repo_ext")
use_repo(repo_ext, "llvm")

I get the error: no repo visible as '@config' here. My code builds if I use a local label (//:repo_ext.bzl instead of @config//:repo_ext.bzl).

Tested with Bazel 7.1, but it repros with USE_BAZEL_VERSION=last_green.

Which category does this issue belong to?

No response

What's the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.

No response

Which operating system are you running Bazel on?

MacOS

What is the output of bazel info release?

release 7.1.0

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

Is this a regression? If yes, please try to identify the Bazel commit where the bug was introduced.

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

fmeum commented 1 month ago

Could you explain your use case for using extensions from non-module repos?

If this was allowed, repo rules could generate extension definitions. This has the disadvantage that it can become pretty complex on a conceptual level, but the advantage that it would potentially allow implementing isolated extension usages in "user space" (that's actually what I tried first before introducing isolate = True to use_extension).

laurentlb commented 1 month ago

After chatting with @Wyverald, I've updated my code to use bazel_dep followed by archive_override. This works fine for me.

I'm still learning how to use the module system, it was not clear to me that http_archive wouldn't work. Maybe the error message could be improved, or the documentation, or you can close the issue.