-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
bzlmod: module extension-invoked repository rules from .bzl
files that (transitively) load from external repos yield cycle errors w/usage in WORKSPACE.bzlmod
#21289
Comments
@meteorcloudy I think this is actually a bug (the same one that @fmeum mentioned about rules_jni on Slack). I'll see if I can get to it this week, but either way, we should fix it for 7.1.0. |
@bazel-io fork 7.1.0 |
…SPACE Mappings for repos defined in WORKSPACE are extremely annoying to verify given the chunked loading (we'd have to record which chunk the repo mapping was used in, and then load that chunk while verifying). This is extremely not worth the effort (especially since nobody really uses repo mappings in WORKSPACE) so we just don't record it. This also means, during verification, we can safely use the main repo mapping without WORKSPACE (since repos defined in Bzlmod can't see stuff from WORKSPACE anyway). Fixes #21289.
…SPACE Mappings for repos defined in WORKSPACE are extremely annoying to verify given the chunked loading (we'd have to record which chunk the repo mapping was used in, and then load that chunk while verifying). This is extremely not worth the effort (especially since nobody really uses repo mappings in WORKSPACE) so we just don't record it. This also means, during verification, we can safely use the main repo mapping without WORKSPACE (since repos defined in Bzlmod can't see stuff from WORKSPACE anyway). Fixes #21289. Closes #21393. PiperOrigin-RevId: 608258493 Change-Id: Ife6a01221e6f5e1685d859eaa5acc8b370ab8483
…SPACE Mappings for repos defined in WORKSPACE are extremely annoying to verify given the chunked loading (we'd have to record which chunk the repo mapping was used in, and then load that chunk while verifying). This is extremely not worth the effort (especially since nobody really uses repo mappings in WORKSPACE) so we just don't record it. This also means, during verification, we can safely use the main repo mapping without WORKSPACE (since repos defined in Bzlmod can't see stuff from WORKSPACE anyway). Fixes #21289. Closes #21393. PiperOrigin-RevId: 608258493 Change-Id: Ife6a01221e6f5e1685d859eaa5acc8b370ab8483
A fix for this issue has been included in Bazel 7.1.0 RC1. Please test out the release candidate and report any issues as soon as possible. Thanks! |
…SPACE Mappings for repos defined in WORKSPACE are extremely annoying to verify given the chunked loading (we'd have to record which chunk the repo mapping was used in, and then load that chunk while verifying). This is extremely not worth the effort (especially since nobody really uses repo mappings in WORKSPACE) so we just don't record it. This also means, during verification, we can safely use the main repo mapping without WORKSPACE (since repos defined in Bzlmod can't see stuff from WORKSPACE anyway). Fixes bazelbuild#21289. Closes bazelbuild#21393. PiperOrigin-RevId: 608258493 Change-Id: Ife6a01221e6f5e1685d859eaa5acc8b370ab8483
Was the bazel stacktrace meant to be fixed in 7.1.x? I see the exact same stacktrace when using https://github.com/GoogleContainerTools/rules_distroless in GoogleContainerTools/rules_distroless#37 (comment) |
issue
This is another issue like #20942 but with a twist: rather than being triggered by usages of external repos within the repository rule that's invoked by the module extension, this time the cycle error is triggered by
load
s (including transitive loads) from an external repo 1 by the.bzl
file defining the repository rule.To recap, here are the conditions necessary to trigger this error:
.bzl
file, (transitively) loads from an external repouse_repo
'dLike in #20942 the actual cycle is not displayed (even with #20958 applied):
This issue is not fixed by #20982.
Further,
bazel info
(on alternate runs) causes Bazel to crash:minimal repro
# BUILD.bazel
Same behavior as in #20942; we see errors after the first evaluation of
.bzl
files records the deps.To reproduce, run:
bazel build ...
: loads .bzl files, writes marker filesbazel clean
bazel build ...
: recompute repo mapping, using the marker files writtenErrors with:
Alternatively:
bazel info
bazel shutdown
bazel info
Errors with:
A
bazel clean --expunge
is necessary to getbazel build
,bazel info
, etc. to work again.python bzlmod test
Alternatively, here's a minimal repro as a bzlmod python test, in the style of @Wyverald's test in #20982:
repository rule vs module extension
Important
It's a dependency (transitively) on an external repo from the .bzl file where the repository rule is defined that causes a problem.
If we split
mod_ext.bzl
in the above so that the repository rule is defined in a separaterepo.bzl
, this has the issue (external load is present inrepo.bzl
):And this (external load is only in
mod_ext.bzl
) does not:details
cycle
As mentioned, Bazel does not report the actual cycle error, even with @fmeum's patch in #20958. This is because these particular cycles do not match this predicate:
bazel/src/main/java/com/google/devtools/build/lib/skyframe/BzlmodRepoCycleReporter.java
Line 117 in fc36c87
We can see the cycle in the java log though:
marker file
<output_base>/external/@_main~ext~some_repo.marker
has:Removing the
REPO_MAPPING
for skylib "fixes" the issue (at least until the marker is updated...) as we'd expect.misc
Running with
--noenable_workspace
also sidesteps this error, as we'd expect.I think it's possible to abuse the unfortunate behavior described by @Wyverald here as a "workaround" (i.e. factoring out the literal
repository_rule
invocation into a separate.bzl
file where there are no transitive external loads).I cannot reproduce this issue on
7.0.2
.root cause
With the above repro and this script
git bisect
is able to find where this first started failing:9edaddd comes from #21131 which indeed did not make it into 7.0.2 (but has been applied to the 7.1.0 branch: #21172)
cc: @fmeum @Wyverald @meteorcloudy
I'm not familiar with this part of the Bazel codebase but, IIUC, the issue is that when resolving deps for the mod-ext produced repo (on the path:
root mapping -> WORKSPACE.bzlmod -> mod-ext provided repo (some_repo) -> [repo from bzlmod (skylib)]
), the root mapping is requested again forming a cycle (even though in reality only bzlmod-produced repos should be accessible to the repo rule since it's instantiated from bzlmod).It's not clear to me what the best way to fix this would be but please let me know if there's anything I can do to help.
Footnotes
Not sure if it's all external repo loads or just loads from bzlmod produced repos; since repository rules invoked by module extensions don't see
WORKSPACE.bzlmod
.defined repos it's maybe not a meaningful distinction. ↩The text was updated successfully, but these errors were encountered: