-
Notifications
You must be signed in to change notification settings - Fork 4.4k
Bazel can't resolve "platforms" repository, despite explicit module dependency #17655
Description
Description of the bug:
Per discussion in the "bzlmod" channel of the "Bazel" Slack workspace, and possibly related to #17289, when I try to use rules_oci's oci_image rule in a root module (that is, in a Bazel workspace with a MODULE.bazel file and with the --enable_bzlmod flag active), building the target fails due to Bazel claiming that there is no repository named "platforms" defined:
bazel build //test:image
ERROR: Analysis of target '//test:image' failed;
build aborted: no such package '@platforms//cpu':
The repository '@platforms' could not be resolved: Repository '@platforms' is not defined
This error arises even when I have the following function call in my MODULE.bazel file, referring to the "platforms" module:
bazel_dep(name = "platforms", version = "0.0.6")If I don't mention the "platforms" module's repository explicitly anywhere in my code and remove that entry from my MODULE.bazel file, then Bazel fails differently, though this is not the root of my complaint here:
bazel build //test:image
ERROR: /private/var/tmp/.../external/yq_toolchains/BUILD.bazel:12:10:
no such package '@platforms//cpu':
The repository '@platforms' could not be resolved:
Repository '@platforms' is not defined and referenced by '@yq_toolchains//:darwin_amd64_toolchain'
ERROR: /.../bzlmod-platforms-test/test/BUILD.bazel:14:10:
While resolving toolchains for target //test:image:
invalid registered toolchain '@yq_toolchains//:darwin_amd64_toolchain':
Analysis failed
What's the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.
Please find attached here an archive of a Bazel repository, with a root module named "bzlmod_platforms_test." In the WORKSPACE.bzlmod file, it uses rules_oci's oci_pull rule to pull an OCI image from the distroless project.
In the "test" package, there's a tiny shell program named greet.sh, packaged into a tar archive by pkg_tar, and then used as the content of an OCI image in the "image" target by way of the oci_image rule.
Unpack that archive, and attempt to build the "test:image" target.
tar zxf bzlmod-platforms-test.tar.gz
cd bzlmod-platforms-test
bazel build //test:imageObserve that the build fails for lack of the "platforms" repository (nominated in the error message as "@platforms").
Which operating system are you running Bazel on?
macOS 13.2.1
What is the output of bazel info release?
release 6.0.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 master; git rev-parse HEAD ?
No response
Have you found anything relevant by searching the web?
The use of rules_oci and pkg_tar is based mostly on @alexeagle's bazel-contrib/rules_oci#77, simplified here to show that I'm not even using the "platforms" module explicitly in my own code. In the real repository in which this problem arose, I am using that module explicitly in various places, but I wanted to show that I was unable to use pkg_tar and rules_oci together both with and without a dependency on the "platforms" module. In other words, while the error message makes it look like I'm missing a dependency, expressing that dependency explicitly doesn't help.
Any other information, logs, or outputs that you want to share?
No response