bazel: Regression: Bzlmod failing to pick up some aspect of transitive dependencies
Description of the bug:
Hi wonderful Bazelers,
I was helping out with some maintenance for google/google-toolbox-for-mac and noticed some odd behavior in 7.0.0 and the latest rolling (8.0.0-pre.20231030.2). Everything works as I’d expect in 6.4.0.
In particular, builds were failing to pick up Apple CC toolchains unless a transitive dependency was specified at the top level.
In more detail: HEAD started failing with
ERROR: /Users/cs/Developer/google-toolbox-for-mac/BUILD:4:13: in objc_library rule //:Defines:
Traceback (most recent call last):
File "/virtual_builtins_bzl/common/objc/objc_library.bzl", line 61, column 52, in _objc_library_impl
File "/virtual_builtins_bzl/common/objc/semantics.bzl", line 54, column 13, in _check_toolchain_supports_objc_compile
Error in fail: Compiling objc_library targets requires the Apple CC toolchain which can be found here: https://github.com/bazelbuild/apple_support#toolchain-setup
Module.bazel brings in (only) rules_apple, which should be sufficient (and was previously in 6.4.0).
bazel_dep(name = "rules_apple", version = "3.1.1", repo_name = "build_bazel_rules_apple")
rules_apple already depends transitively on apple_support 1.11.1, but adding in an explicit dependency mysteriously fixes the issue
bazel_dep(name = "apple_support", version = "1.11.1", repo_name = "build_bazel_apple_support")
Strange, right?
Thanks again for all you do, Chris
Which category does this issue belong to?
bzlmod
What’s the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.
Try building google/google-toolbox-for-mac w/ 7.0.0 or the latest rolling (8.0.0-pre.20231030.2). Note error as above. Then add superfluous bazel_dep(name = "apple_support", version = "1.11.1", repo_name = "build_bazel_apple_support")
to MODULE.bazel and note that error resolves.
You may also have to remove includes = ["."],
from //BUILD
, depending on the Bazel version.
Which operating system are you running Bazel on?
macOS
Is this a regression? If yes, please try to identify the Bazel commit where the bug was introduced.
It says: first bad commit is https://github.com/bazelbuild/bazel/commit/ffcf0fdc9a09ec240df39f1db35511e730366a31
But this was from a Bazel crash, like the following, of which there were significant numbers in intermediate commits.
FATAL: bazel crashed due to an internal error. Printing stack trace:
java.lang.RuntimeException: Unrecoverable error while evaluating node 'com.google.devtools.build.lib.bazel.bzlmod.BazelLockFileValue$$Lambda$219/0x00000009002a0c40@12948f4a' (requested by nodes 'com.google.devtools.build.lib.bazel.bzlmod.BazelDepGraphValue$$Lambda$346/0x00000009004d8040@62c3027d')
at com.google.devtools.build.skyframe.AbstractParallelEvaluator$Evaluate.run(AbstractParallelEvaluator.java:633)
at com.google.devtools.build.lib.concurrent.AbstractQueueVisitor$WrappedRunnable.run(AbstractQueueVisitor.java:365)
at java.base/java.util.concurrent.ForkJoinTask$AdaptedRunnableAction.exec(Unknown Source)
at java.base/java.util.concurrent.ForkJoinTask.doExec(Unknown Source)
at java.base/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(Unknown Source)
at java.base/java.util.concurrent.ForkJoinPool.scan(Unknown Source)
at java.base/java.util.concurrent.ForkJoinPool.runWorker(Unknown Source)
at java.base/java.util.concurrent.ForkJoinWorkerThread.run(Unknown Source)
Caused by: java.lang.IllegalArgumentException: com.google.devtools.build.lib.cmdline.LabelSyntaxException: invalid label 'rules_apple~3.1.1': absolute label must begin with '@' or '//'
at com.google.devtools.build.lib.cmdline.Label.parseCanonicalUnchecked(Label.java:136)
at com.google.devtools.build.lib.bazel.bzlmod.AttributeValuesAdapter.deserializeStringToObject(AttributeValuesAdapter.java:154)
at com.google.devtools.build.lib.bazel.bzlmod.AttributeValuesAdapter.deserializeObject(AttributeValuesAdapter.java:105)
at com.google.devtools.build.lib.bazel.bzlmod.AttributeValuesAdapter.read(AttributeValuesAdapter.java:56)
at com.google.devtools.build.lib.bazel.bzlmod.AttributeValuesAdapter.read(AttributeValuesAdapter.java:40)
at com.google.devtools.build.lib.bazel.bzlmod.RepoSpec_GsonTypeAdapter.read(RepoSpec_GsonTypeAdapter.java:105)
at com.google.devtools.build.lib.bazel.bzlmod.RepoSpec_GsonTypeAdapter.read(RepoSpec_GsonTypeAdapter.java:11)
at com.google.devtools.build.lib.bazel.bzlmod.Module_GsonTypeAdapter.read(Module_GsonTypeAdapter.java:226)
at com.google.devtools.build.lib.bazel.bzlmod.Module_GsonTypeAdapter.read(Module_GsonTypeAdapter.java:14)
at com.google.gson.internal.bind.TypeAdapterRuntimeTypeWrapper.read(TypeAdapterRuntimeTypeWrapper.java:41)
at com.google.gson.internal.bind.MapTypeAdapterFactory$Adapter.read(MapTypeAdapterFactory.java:187)
at com.google.gson.internal.bind.MapTypeAdapterFactory$Adapter.read(MapTypeAdapterFactory.java:145)
at com.google.devtools.build.lib.bazel.bzlmod.DelegateTypeAdapterFactory$1.read(DelegateTypeAdapterFactory.java:133)
at com.google.devtools.build.lib.bazel.bzlmod.BazelLockFileValue_GsonTypeAdapter.read(BazelLockFileValue_GsonTypeAdapter.java:159)
at com.google.devtools.build.lib.bazel.bzlmod.BazelLockFileValue_GsonTypeAdapter.read(BazelLockFileValue_GsonTypeAdapter.java:13)
at com.google.gson.Gson.fromJson(Gson.java:932)
at com.google.gson.Gson.fromJson(Gson.java:897)
at com.google.gson.Gson.fromJson(Gson.java:846)
at com.google.gson.Gson.fromJson(Gson.java:817)
at com.google.devtools.build.lib.bazel.bzlmod.BazelLockFileFunction.getLockfileValue(BazelLockFileFunction.java:101)
at com.google.devtools.build.lib.bazel.bzlmod.BazelLockFileFunction.compute(BazelLockFileFunction.java:79)
at com.google.devtools.build.skyframe.AbstractParallelEvaluator$Evaluate.run(AbstractParallelEvaluator.java:562)
... 7 more
Caused by: com.google.devtools.build.lib.cmdline.LabelSyntaxException: invalid label 'rules_apple~3.1.1': absolute label must begin with '@' or '//'
at com.google.devtools.build.lib.cmdline.LabelParser.syntaxErrorf(LabelParser.java:208)
at com.google.devtools.build.lib.cmdline.LabelParser$Parts.checkPkgIsAbsolute(LabelParser.java:194)
at com.google.devtools.build.lib.cmdline.Label.parseCanonical(Label.java:125)
at com.google.devtools.build.lib.cmdline.Label.parseCanonicalUnchecked(Label.java:134)
... 28 more
About this issue
- Original URL
- State: closed
- Created 7 months ago
- Comments: 28 (26 by maintainers)
Commits related to this issue
- Workaround Bazel 7 issue https://github.com/bazelbuild/bazel/issues/20537 — committed to cpsauer/google-toolbox-for-mac by cpsauer 7 months ago
- Workaround Bazel 7 issue https://github.com/bazelbuild/bazel/issues/20537 — committed to google/google-toolbox-for-mac by cpsauer 7 months ago
- Demonstrate toolchain resolution "best match" Quick hack as an example fixing: https://github.com/bazelbuild/bazel/issues/11454 https://github.com/bazelbuild/bazel/issues/20537 — committed to keith/bazel by keith 6 months ago
I’m back to “first registered toolchain wins” being fine
My hope is that we can drop the apple_support dependency from bazel entirely. The only reason it’s there I’m hoping we can eliminate https://github.com/bazelbuild/bazel/pull/20084/