bazel-contrib / rules_jvm_external

Bazel rules to resolve, fetch and export Maven artifacts
Apache License 2.0
337 stars 256 forks source link

Fix `android_extensions.bzl` with Bazel 8.0.0rc1 and later #1270

Open meteorcloudy opened 1 month ago

meteorcloudy commented 1 month ago

Running bazel mod deps with Bazel 8.0.0rc1 or later results:

ERROR: Error loading '@@bazel_tools//tools/android:android_extensions.bzl' for module extensions, requested by https://bcr.bazel.build/modules/rules_jvm_external/6.0/MODULE.bazel:29:42: Label '@@bazel_tools//tools/android:android_extensions.bzl' is invalid because 'tools/android' is not a package; perhaps you meant to put the colon here: '@@bazel_tools//tools:android/android_extensions.bzl'?: Label '@@bazel_tools//tools/android:android_extensions.bzl' is invalid because 'tools/android' is not a package; perhaps you meant to put the colon here: '@@bazel_tools//tools:android/android_extensions.bzl'?. Type 'bazel help mod' for syntax and help.

This is due to https://github.com/bazelbuild/bazel/commit/ef1a21fd05e061a7bb7cb75c9c909af6b3adbbb1 and probably should switch to use https://github.com/bazelbuild/rules_android/blob/e7729c61025c394fb77b220b917e15494271d7b8/MODULE.bazel#L140-L141 from rules_android

meteorcloudy commented 1 month ago

@shs96c @jin @ahumesky

shs96c commented 1 month ago

Presumably the new rules_android will also work with Bazel 6? We'd like to continue supporting that until Bazel 9 ships

ahumesky commented 1 month ago

rules_android has only been targeting bazel 7 and 8, we'll have to see what does and doesn't work with bazel 6, and what can be worked around in the rules. I can see when I pick https://github.com/bazel-contrib/rules_jvm_external/pull/1215 back up

meteorcloudy commented 1 month ago

Presumably the new rules_android will also work with Bazel 6?

Do you actually need to support Bazel 6 with Bzlmod enabled (which is not the default)?

meteorcloudy commented 1 month ago

I was trying to fix this for rules_jvm_external but found out rules_kotlin is also broken

ERROR: Error loading '@@bazel_tools//tools/android:android_extensions.bzl' for module extensions, requested by https://bcr.bazel.build/modules/rules_kotlin/1.9.6/MODULE.bazel:29:42: Label '@@bazel_tools//tools/android:android_extensions.bzl' is invalid because 'tools/android' is not a package; perhaps you meant to put the colon here: '@@bazel_tools//tools:android/android_extensions.bzl'?: Label '@@bazel_tools//tools/android:android_extensions.bzl' is invalid because 'tools/android' is not a package; perhaps you meant to put the colon here: '@@bazel_tools//tools:android/android_extensions.bzl'?. Type 'bazel help mod' for syntax and help.

https://github.com/bazelbuild/rules_kotlin/blob/c93d6ae990a1d063f0a4e6fbef7447af2799f661/MODULE.bazel#L45-L47

@ahumesky @ted-xie Can we partially revert https://github.com/bazelbuild/bazel/commit/ef1a21fd05e061a7bb7cb75c9c909af6b3adbbb1#diff-cefcdd5baa8fc0ebdd3c850a8e698499ecebba0b1072d429743c05b1ef287d2e in Bazel 8.0.0, otherwise, older version of rules_jvm_external and rules_kotlin will just be broken with Bazel 8+

shs96c commented 1 month ago

We only support blzmod when using Bazel 7+, but we still want to support folks using Bazel 6 and workspace-based builds, and we normally try and keep rules we depend on in sync between the workspace and bzlmod builds.

meteorcloudy commented 1 month ago

Yeah, rules_jvm_external@HEAD should probably migrate to use the latest version of rules_android. I sent https://github.com/bazelbuild/bazel/pull/24094 to hopefully make bazel 8 also work with older rules_jvm_external versions.

ahumesky commented 1 month ago

rules_jvm_external@HEAD should probably migrate to use the latest version of rules_android

That's what my PR that was reverted here is about: https://github.com/bazel-contrib/rules_jvm_external/pull/1215

Reapplying / unreverting that is blocked on rules_android 0.6.0, which is blocked on getting it to work with bazel 8.0, which is blocked on protobuf issues (include https://github.com/bazelbuild/bazel/pull/23908 that you reference in https://github.com/bazelbuild/bazel/pull/24094)

I was trying to fix this for rules_jvm_external but found out rules_kotlin is also broken

rules_kotlin has a pending PR (https://github.com/bazelbuild/rules_kotlin/pull/1205) to update to use rules_android, but they're blocked on rules_jvm_external updating to rules_android (which is blocked as above)

rules_kotlin has a similar PR to remove dependending on @bazel_tools (https://github.com/bazelbuild/rules_kotlin/pull/1228)

ahumesky commented 1 month ago

hopefully make bazel 8 also work with older rules_jvm_external versions

How far back do we need to go? Older versions of rules_jvm_external e.g. rely on natively-defined aar_import, which is deleted in bazel 8

jin commented 1 month ago

Sorry if I've missed a crucial point, but I think it'll help discussions if we can come up with an actual compatibility matrix here. e.g. it would be really good if RJE can retain N-2 LTS versions, but to what degree is this requirement a hard blocker for the other rulesets (android, kotlin, java) to make progress?