Skip to content
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

Bazel 8.0.0 compatibility #1652

Open
gergelyfabian opened this issue Nov 25, 2024 · 28 comments
Open

Bazel 8.0.0 compatibility #1652

gergelyfabian opened this issue Nov 25, 2024 · 28 comments

Comments

@gergelyfabian
Copy link
Contributor

When testing Bazel 8.0.0 RC versions I discovered rules_scala may be incompatible with the latest rules_java (that you in turn my need for Bazel 8.0.0).

This came out when testing a Bazel bug's solution: bazelbuild/bazel#24235.

After upgrading rules_java to 8.5.0+ rules_scala reported errors:

# Using https://github.com/gergelyfabian/bazel-scala-example/tree/bazel-8.0.0rc1
$ USE_BAZEL_VERSION=8.0.0rc3 bazel build //...
INFO: Invocation ID: b8abf68e-49c2-48ee-a5e4-f0d8710f759d
ERROR: Traceback (most recent call last):
	File "/home/user/.cache/bazel/_bazel_user/64527517dacf7170f7d914889f83481c/external/io_bazel_rules_scala/scala/private/rules/scala_doc.bzl", line 52, column 37, in <toplevel>
		_scaladoc_transitive_aspect = aspect(
Error in aspect: Illegal argument: element in 'required_aspect_providers' is of unexpected type. Either all elements should be providers, or all elements should be lists of providers, but got list with an element of type NoneType.
ERROR: Error computing the main repository mapping: at /home/user/.cache/bazel/_bazel_user/64527517dacf7170f7d914889f83481c/external/io_bazel_rules_scala/scala/scala.bzl:20:5: initialization of module 'scala/private/rules/scala_doc.bzl' failed

# Or another one:

$ USE_BAZEL_VERSION=8.0.0rc3 bazel build //...
INFO: Invocation ID: 117a90d7-da17-400c-9f83-908c7ddd7317
WARNING: WORKSPACE support will be removed in Bazel 9 (late 2025), please migrate to Bzlmod, see https://bazel.build/external/migration.
ERROR: Traceback (most recent call last):
	File "/home/user/.cache/bazel/_bazel_user/64527517dacf7170f7d914889f83481c/external/io_bazel_rules_scala/scala/private/common_attributes.bzl", line 18, column 28, in <toplevel>
		"deps": attr.label_list(
Error in label_list: Illegal argument: element in 'providers' is of unexpected type. Either all elements should be providers, or all elements should be lists of providers, but got list with an element of type NoneType.
ERROR: Error computing the main repository mapping: at /home/user/.cache/bazel/_bazel_user/64527517dacf7170f7d914889f83481c/external/io_bazel_rules_scala/scala/scala.bzl:37:5: at /home/user/.cache/bazel/_bazel_user/64527517dacf7170f7d914889f83481c/external/io_bazel_rules_scala/scala/private/rules/scala_repl.bzl:5:5: initialization of module 'scala/private/common_attributes.bzl' failed

Please note, that rules_cc version is also too "old" for Bazel 8.0.0, so I upgraded it on my branch too explicitly. It may need to be updated in rules_scala.

@mbland
Copy link
Contributor

mbland commented Nov 26, 2024

I noted in #1625, based on copious notes from cd22d88 (under Bump to rules_java 7.9.0 for Bazel 7 compatibility), why we're stuck at rules_java 7.9.0 for now.

But, the good news is, Bzlmod builds aren't affected by that particular problem, and Bzlmodification is in the home stretch. Once that lands, we can bump up the rules_java version.

FWIW, I've been using rules_java 7.11.1 in my bzlmod working branch. I'll try to bump it to the latest 8.5.1 and see what happens.

@mbland
Copy link
Contributor

mbland commented Nov 26, 2024

Ah. We have a continuation of the protobuf + ScalaPB saga from #1647.

If I bump to rules_java 8.5.1 (and rules_cc 0.1.0), and stick with protobuf 21.7 (the current rules_scala version, via single_version_override) or protobuf 24.4 (the latest Bazel Central Registry protobuf module compatible with ScalaPB 0.11.17), I get:

$ bazel build //src/... //test/... //third_party/... //scala_proto/...

ERROR: Skipping '//src/...': error loading package under directory 'src':
  error loading package 'src/java/io/bazel/rulesscala/io_utils':
  at .../external/rules_java~/java/defs.bzl:16:6:

Label '@@protobuf~//bazel:java_lite_proto_library.bzl' is invalid because
  'bazel' is not a package; perhaps you meant to put the colon here:
  '@@protobuf~//:bazel/java_lite_proto_library.bzl'?

ERROR: error loading package under directory 'src':
  error loading package 'src/java/io/bazel/rulesscala/io_utils':
  at .../external/rules_java~/java/defs.bzl:16:6:
  
Label '@@protobuf~//bazel:java_lite_proto_library.bzl' is invalid because 
  'bazel' is not a package; perhaps you meant to put the colon here:
  '@@protobuf~//:bazel/java_lite_proto_library.bzl'?

The //bazel package doesn't appear until Protobuf v25.0, and //bazel:java_lite_proto_library.bzl doesn't appear until Protobuf v27.0. Per #1647, there's no version of ScalaPB that works with Protobuf v27.

However, bumping ScalaPB to 1.0.0-alpha.1 and Protobuf v28.3 did work. But as noted in #1647, committing the ScalaPB 1.0.0-alpha.1 bump would mean effectively forcing rules_scala users to upgrade to at least Protobuf v28.2 immediately.

Maybe that's what we ought to do anyway, because clearly we don't want to block anyone from upgrading to Bazel 8. But we'd have to shout it from the rooftops—at the same time we try to persuade folks to switch from depending on rules_scala via WORKSPACE to Bzlmod.

Even so, rules_cc 0.0.9 and rules_java 7.9.0 still work with Protobuf v28.3 and ScalaPB 1.0.0-alpha.1. That means we wouldn't leave Bazel 6 or 7 WORKSPACE users behind entirely, so long as Protobuf v28.3 works for them, if they insist on holding onto WORKSPACE for now.

@mbland
Copy link
Contributor

mbland commented Nov 26, 2024

Ah, more info. The results from my last comment were from building with Bazel 7.4.1. Building with 8.0.0rc4 is not yet possible.

First, I had to update to the highest versions of all dependencies in the Bazel module graph:

bazel_dep(name = "rules_cc", version = "0.1.0")
bazel_dep(name = "rules_java", version = "8.5.1")
bazel_dep(name = "rules_proto", version = "7.0.2")
bazel_dep(name = "protobuf", version = "29.0-rc3", repo_name = "com_google_protobuf")
bazel_dep(name = "rules_python", version = "0.40.0", dev_dependency = True)

I also bumped the following in scripts/create_repository.py and ran it:

PROTOBUF_JAVA_VERSION = "4.29.0-RC3"

I had to add one, the other, or both of these lines to the *.bzl files that needed them:

load("@rules_java//java/common:java_common.bzl", "java_common")
load("@rules_java//java/common:java_info.bzl", "JavaInfo")

But sadly, ScalaPB 1.0.0-alpha.1 and protobuf-java:4.29.0-RC3 aren't compatible:

$ bazel build //src/... //test/... //third_party/... //scala_proto/...

ERROR: .../test/proto/BUILD:184:14:
  ProtoScalaPBRule test/proto/nested_proto_jvm_extra_protobuf_generator_scalapb.srcjar
  failed: (Exit 1): scalapb_worker failed:
  error executing ProtoScalaPBRule command
  (from target //test/proto:nested_proto)
  bazel-out/.../bin/src/scala/scripts/scalapb_worker ...
    (remaining 2 arguments skipped)

--jvm_extra_protobuf_generator_out: java.lang.ExceptionInInitializerError
  at scalapb.options.compiler.Scalapb$.registerAllExtensions(Scalapb.scala:8)
  at scalarules.test.extra_protobuf_generator.ExtraProtobufGenerator$.run(ExtraProtobufGenerator.scala:53)
  at protocbridge.frontend.PluginFrontend$.$anonfun$runWithBytes$1(PluginFrontend.scala:51)
  at scala.util.Try$.apply(Try.scala:217)
  at protocbridge.frontend.PluginFrontend$.runWithBytes(PluginFrontend.scala:51)
  at protocbridge.frontend.PluginFrontend$.runWithInputStream(PluginFrontend.scala:121)
  at protocbridge.frontend.PosixPluginFrontend$.$anonfun$prepare$2(PosixPluginFrontend.scala:40)
  at scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.scala:18)
  at scala.concurrent.impl.ExecutionContextImpl$DefaultThreadFactory$$anon$1$$anon$2.block(ExecutionContextImpl.scala:60)
  at java.base/java.util.concurrent.ForkJoinPool.managedBlock(ForkJoinPool.java:3118)
  at scala.concurrent.impl.ExecutionContextImpl$DefaultThreadFactory$$anon$1.blockOn(ExecutionContextImpl.scala:71)
  at scala.concurrent.package$.blocking(package.scala:124)
  at protocbridge.frontend.PosixPluginFrontend$.$anonfun$prepare$1(PosixPluginFrontend.scala:38)
  at scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.scala:18)
  at scala.concurrent.Future$.$anonfun$apply$1(Future.scala:687)
  at scala.concurrent.impl.Promise$Transformation.run(Promise.scala:467)
  at java.base/java.util.concurrent.ForkJoinTask$RunnableExecuteAction.exec(ForkJoinTask.java:1426)
  at java.base/java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:290)
  at java.base/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1020)
  at java.base/java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:1656)
  at java.base/java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1594)
  at java.base/java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:183)

Caused by: com.google.protobuf.RuntimeVersion$ProtobufRuntimeVersionException:
  Detected mismatched Protobuf Gencode/Runtime version suffixes when loading
  scalapb.options.Scalapb: gencode 4.28.2, runtime 4.29.0-rc3.
  Version suffixes must be the same.

  at com.google.protobuf.RuntimeVersion.validateProtobufGencodeVersionImpl(RuntimeVersion.java:126)
  at com.google.protobuf.RuntimeVersion.validateProtobufGencodeVersion(RuntimeVersion.java:71)
  at scalapb.options.Scalapb.<clinit>(Scalapb.java:11)
  ... 22 more

java.lang.RuntimeException: Exit with code 1
  at scala.sys.package$.error(package.scala:27)
  at scripts.ScalaPBWorker$.work(ScalaPBWorker.scala:44)
  at io.bazel.rulesscala.worker.Worker.persistentWorkerMain(Worker.java:96)
  at io.bazel.rulesscala.worker.Worker.workerMain(Worker.java:49)
  at scripts.ScalaPBWorker$.main(ScalaPBWorker.scala:39)
  at scripts.ScalaPBWorker.main(ScalaPBWorker.scala)

ERROR: .../test/proto/BUILD:184:14
  Building source jar test/proto/nested_proto_scalapb-src.jar failed:
  (Exit 1): scalapb_worker failed:
  error executing ProtoScalaPBRule command
  (from target //test/proto:nested_proto)
  bazel-out/.../bin/src/scala/scripts/scalapb_worker ...
    (remaining 2 arguments skipped)

Pinning Protobuf to v28.3 using single_version_override didn't work:

$ bazel build //src/... //test/... //third_party/... //scala_proto/...

ERROR: Skipping '//scala_proto/...':
  error loading package under directory 'scala_proto':
  error loading package 'scala_proto/private':
  Internal error while loading Starlark builtins:
  Failed to autoload external symbols:
  cannot load '@@protobuf+//bazel/private:bazel_cc_proto_library.bzl':
  no such file

ERROR: error loading package under directory 'scala_proto':
  error loading package 'scala_proto/private':
  Internal error while loading Starlark builtins:
  Failed to autoload external symbols:
  cannot load '@@protobuf+//bazel/private:bazel_cc_proto_library.bzl':
  no such file

@protobuf//bazel/private:bazel_cc_proto_library.bzl doesn't appear until v29-dev.

These aren't insurmountable issues; perhaps once Protobuf v29.0 lands, I can try again, and ScalaPB v1.0.0-alpha.1 will be happy with plain protobuf-java:4.29.0. Building with Bazel 8 will be blocked until then, even after Bzlmodification.

However, building with Bazel 8 will require those new load("@rules_java//") statements, and that will break WORKSPACE users for sure.

@mbland
Copy link
Contributor

mbland commented Nov 26, 2024

I spoke too soon: I can get a WORKSPACE build to use rules_java 8.5.1 and the other updated repo versions, and get to the point where it reaches the Detected mismatched Protobuf Gencode/Runtime version suffixes error.

So it seems we could bump to Bazel 8 without abandoning WORKSPACE, but we will abandon Bazel 6 and 7 at that point.

Update: To confirm, I went back to Bazel 7.4.1 to build using the new WORKSPACE config with rules_java 8.5.1, etc., and it died on building the remote_java_tools repo:

$ bazel build //src/... //test/... //third_party/... //scala_proto/...

ERROR: Traceback (most recent call last):
  File ".../external/remote_java_tools/BUILD", line 7, column 60, in <toplevel>
    load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library", "cc_proto_library")
Error: file '@rules_cc//cc:defs.bzl' does not contain symbol 'cc_proto_library'

ERROR: .../external/remote_java_tools/BUILD:
  no such target '@@remote_java_tools//:TurbineDirect':
  target 'TurbineDirect' not declared in package ''
  defined by .../external/remote_java_tools/BUILD

ERROR: .../test/toolchains/BUILD.bazel:10:23:
  no such target '@@remote_java_tools//:TurbineDirect':
  target 'TurbineDirect' not declared in package ''
  defined by .../external/remote_java_tools/BUILD
  and referenced by '//test/toolchains:java21_toolchain'

ERROR: Analysis of target '//test/toolchains:java21_toolchain' failed;
  build aborted: Analysis failed

mbland added a commit to mbland/rules_scala that referenced this issue Nov 26, 2024
These changes enable both `WORKSPACE` and Bzlmod builds to reach a point
where both fail with the following errors. Part of bazelbuild#1652.

- To use `WORKSPACE`, specify `--enable_workspace --noenable_bzlmod` on
  the command line or add them to `.bazelrc`.

Per that issue, the following breakages may be resolved by a new
`protobuf-java:4.29.0` release (without the `-RC3` suffix. Then we can
try to run the rest of the `rules_scala` test suite.

Also per that issue, adopting Bazel 8 and rules_java 8 compatibility
will necessarily break Bazel 6 and 7 compatibility.

---

Hoisted the `load_rules_dependencies()` macro into the new
`//scala:deps.bzl` file to avoid copying everything into `WORKSPACE`.
Changed the order of `http_archive()` calls as well. Without importing
these repos in this order, the build would break under `WORKSPACE`.
Without the `rules_java_dependencies()` and `protobuf_deps()` calls
where they are, the build also breaks.

---

Under both `WORKSPACE` and Bzlmod, the following build command will fail
with a `mismatched Protobuf Gencode/Runtime version suffixes` error:

```txt
$ bazel build //src/... //test/... //third_party/... //scala_proto/...

ERROR: .../external/protobuf+/src/google/protobuf/BUILD.bazel:130:14:
  ProtoScalaPBRule
  external/protobuf+/src/google/protobuf/wrappers_proto_jvm_extra_protobuf_generator_scalapb.srcjar
  failed: (Exit 1): scalapb_worker failed:
  error executing ProtoScalaPBRule command
  (from target @@protobuf+//src/google/protobuf:wrappers_proto)
  bazel-out/darwin_arm64-opt-exec-ST-d57f47055a04/bin/src/scala/scripts/scalapb_worker
    ... (remaining 2 arguments skipped)

--jvm_extra_protobuf_generator_out:
  java.lang.ExceptionInInitializerError
    at scalapb.options.compiler.Scalapb$.registerAllExtensions(Scalapb.scala:8)
    at scalarules.test.extra_protobuf_generator.ExtraProtobufGenerator$.run(ExtraProtobufGenerator.scala:53)
    at protocbridge.frontend.PluginFrontend$.$anonfun$runWithBytes$1(PluginFrontend.scala:51)
    at scala.util.Try$.apply(Try.scala:217)
    at protocbridge.frontend.PluginFrontend$.runWithBytes(PluginFrontend.scala:51)
    at protocbridge.frontend.PluginFrontend$.runWithInputStream(PluginFrontend.scala:121)
    at protocbridge.frontend.PosixPluginFrontend$.$anonfun$prepare$2(PosixPluginFrontend.scala:40)
    at scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.scala:18)
    at scala.concurrent.impl.ExecutionContextImpl$DefaultThreadFactory$$anon$1$$anon$2.block(ExecutionContextImpl.scala:60)
    at java.base/java.util.concurrent.ForkJoinPool.managedBlock(ForkJoinPool.java:3118)
    at scala.concurrent.impl.ExecutionContextImpl$DefaultThreadFactory$$anon$1.blockOn(ExecutionContextImpl.scala:71)
    at scala.concurrent.package$.blocking(package.scala:124)
    at protocbridge.frontend.PosixPluginFrontend$.$anonfun$prepare$1(PosixPluginFrontend.scala:38)
    at scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.scala:18)
    at scala.concurrent.Future$.$anonfun$apply$1(Future.scala:687)
    at scala.concurrent.impl.Promise$Transformation.run(Promise.scala:467)
    at java.base/java.util.concurrent.ForkJoinTask$RunnableExecuteAction.exec(ForkJoinTask.java:1426)
    at java.base/java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:290)
    at java.base/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1020)
    at java.base/java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:1656)
    at java.base/java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1594)
    at java.base/java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:183)

Caused by:
  com.google.protobuf.RuntimeVersion$ProtobufRuntimeVersionException:
  Detected mismatched Protobuf Gencode/Runtime version suffixes when
  loading scalapb.options.Scalapb: gencode 4.28.2, runtime 4.29.0-rc3.
  Version suffixes must be the same.

    at com.google.protobuf.RuntimeVersion.validateProtobufGencodeVersionImpl(RuntimeVersion.java:126)
    at com.google.protobuf.RuntimeVersion.validateProtobufGencodeVersion(RuntimeVersion.java:71)
    at scalapb.options.Scalapb.<clinit>(Scalapb.java:11)
    ... 22 more

java.lang.RuntimeException: Exit with code 1
    at scala.sys.package$.error(package.scala:27)
    at scripts.ScalaPBWorker$.work(ScalaPBWorker.scala:44)
    at io.bazel.rulesscala.worker.Worker.persistentWorkerMain(Worker.java:96)
    at io.bazel.rulesscala.worker.Worker.workerMain(Worker.java:49)
    at scripts.ScalaPBWorker$.main(ScalaPBWorker.scala:39)
    at scripts.ScalaPBWorker.main(ScalaPBWorker.scala)

ERROR: .../external/protobuf+/src/google/protobuf/BUILD.bazel:130:14
  scala @@protobuf+//src/google/protobuf:wrappers_proto
  failed: (Exit 1): scalapb_worker failed:
  error executing ProtoScalaPBRule command
  (from target @@protobuf+//src/google/protobuf:wrappers_proto)
  bazel-out/darwin_arm64-opt-exec-ST-d57f47055a04/bin/src/scala/scripts/scalapb_worker
    ... (remaining 2 arguments skipped)
```

Later builds then fail with `java.lang.NoClassDefFoundError: Could not
initialize class scalapb.options.Scalapb`:

```txt
$ bazel build //src/... //test/... //third_party/... //scala_proto/...

ERROR: .../third_party/test/proto/BUILD.bazel:4:14:
  ProtoScalaPBRule
  third_party/test/proto/proto_jvm_extra_protobuf_generator_scalapb.srcjar
  failed: (Exit 1): scalapb_worker failed:
  error executing ProtoScalaPBRule command
  (from target //third_party/test/proto:proto)
  bazel-out/darwin_arm64-opt-exec-ST-d57f47055a04/bin/src/scala/scripts/scalapb_worker
    ... (remaining 2 arguments skipped)

--jvm_extra_protobuf_generator_out:
  java.lang.NoClassDefFoundError:
  Could not initialize class scalapb.options.Scalapb
    at scalapb.options.compiler.Scalapb$.registerAllExtensions(Scalapb.scala:8)
    at scalarules.test.extra_protobuf_generator.ExtraProtobufGenerator$.run(ExtraProtobufGenerator.scala:53)
    at protocbridge.frontend.PluginFrontend$.$anonfun$runWithBytes$1(PluginFrontend.scala:51)
    at scala.util.Try$.apply(Try.scala:217)
    at protocbridge.frontend.PluginFrontend$.runWithBytes(PluginFrontend.scala:51)
    at protocbridge.frontend.PluginFrontend$.runWithInputStream(PluginFrontend.scala:121)
    at protocbridge.frontend.PosixPluginFrontend$.$anonfun$prepare$2(PosixPluginFrontend.scala:40)
    at scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.scala:18)
    at scala.concurrent.impl.ExecutionContextImpl$DefaultThreadFactory$$anon$1$$anon$2.block(ExecutionContextImpl.scala:60)
    at java.base/java.util.concurrent.ForkJoinPool.managedBlock(ForkJoinPool.java:3118)
    at scala.concurrent.impl.ExecutionContextImpl$DefaultThreadFactory$$anon$1.blockOn(ExecutionContextImpl.scala:71)
    at scala.concurrent.package$.blocking(package.scala:124)
    at protocbridge.frontend.PosixPluginFrontend$.$anonfun$prepare$1(PosixPluginFrontend.scala:38)
    at scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.scala:18)
    at scala.concurrent.Future$.$anonfun$apply$1(Future.scala:687)
    at scala.concurrent.impl.Promise$Transformation.run(Promise.scala:467)
    at java.base/java.util.concurrent.ForkJoinTask$RunnableExecuteAction.exec(ForkJoinTask.java:1426)
    at java.base/java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:290)
    at java.base/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1020)
    at java.base/java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:1656)
    at java.base/java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1594)
    at java.base/java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:183)

java.lang.RuntimeException: Exit with code 1
    at scala.sys.package$.error(package.scala:27)
    at scripts.ScalaPBWorker$.work(ScalaPBWorker.scala:44)
    at io.bazel.rulesscala.worker.Worker.persistentWorkerMain(Worker.java:96)
    at io.bazel.rulesscala.worker.Worker.workerMain(Worker.java:49)
    at scripts.ScalaPBWorker$.main(ScalaPBWorker.scala:39)
    at scripts.ScalaPBWorker.main(ScalaPBWorker.scala)

ERROR: .../third_party/test/proto/BUILD.bazel:4:14
  Building source jar third_party/test/proto/proto_scalapb-src.jar
  failed: (Exit 1): scalapb_worker failed:
  error executing ProtoScalaPBRule command
  (from target //third_party/test/proto:proto)
  bazel-out/darwin_arm64-opt-exec-ST-d57f47055a04/bin/src/scala/scripts/scalapb_worker
    ... (remaining 2 arguments skipped)
```
@mbland
Copy link
Contributor

mbland commented Nov 26, 2024

I've created the bazel-8-compatibility working branch in my rules_scala fork with the commit message for mbland@ebe714d describing the current build breakages, which are the same under WORKSPACE and Bzlmod.

Note that this branch/commit is based on my bzlmod working branch, not the current upstream master branch.

@hvadehra
Copy link
Member

I believe the original issue in the description (#1652 (comment)) is because the scala/scala.bzl file exports helper macros for WORKSPACE setup (such as scala_repositories.bzl) but also transitively loads bzl files not intended for WORKSPACE evaluation - for eg scala_library.bzl. The latter refer to BUILD/bzl symbols such as JavaInfo, and this breaks with Bazel 8 / Bazel@HEAD as these symbols have been removed.

Historically, this has only worked by accident, as the Starlark environment for WORKSPACE evaluation also (incorrectly) included these symbols. See bazelbuild/bazel#17713 for when this first occurred while moving some of these symbols to Starlark (but still embedded in Bazel).

The right fix would to partition the rules_scala bzl load graph into non-overlapping WORKSPACE & BUILD/bzl subsets.

(cc @comius, @meteorcloudy)
However, it may also be possible to make Bazel 8 fully backwards-compatibile by also injecting the relocated symbols in the WORKSPACE environment here . Another alternative could be to fix this by replacing the symbols with non-functional but type-compatible ones (i.e. a dummy Provider instead of Starlark.NONE for JavaInfo).

@meteorcloudy
Copy link
Member

I think it's better to do the right thing here instead of implementing more hacks that would be remove anyway in future.

@hvadehra
Copy link
Member

However, it may also be possible to make Bazel 8 fully backwards-compatibile by also injecting the relocated symbols in the WORKSPACE environment here.

As it turns out, this can't actually work (at least not easily), as WORKSPACE evaluation is itself needed before these symbols are available for injection.

Another alternative could be to fix this by replacing the symbols with non-functional but type-compatible ones (i.e. a dummy Provider instead of Starlark.NONE for JavaInfo).

This seems doable and I might end up doing this for Bazel@HEAD, if only to turn our downstream CI green. However, (if it does happen) cherry-picking the fix to Bazel 8 will only occur if we end up needing a new RC for other reasons.

copybara-service bot pushed a commit to bazelbuild/bazel that referenced this issue Nov 29, 2024
Context: bazelbuild/rules_scala#1652 (comment)

This will fix the issue in Bazel@HEAD, and the primary motivation is to turn downstream CI green.

On the off-chance we are making a new Bazel 8 RC, we can include this. Otherwise, maybe this can go in 8.1.0

PiperOrigin-RevId: 701260369
Change-Id: If62eb015b5220b574ce34a26a194d2722021082f
mbland added a commit to mbland/rules_scala that referenced this issue Nov 29, 2024
Moves functions out of `//scala:scala.bzl` and updates `WORKSPACE` to
load `//scala:toolchains.bzl` to avoid importing macros that depend on
`JavaInfo` and `java_common` during `WORKSPACE` evaluation. Based on
advice from @hvadehra in bazelbuild#1652.

I haven't tried this under Bzlmod yet, and it still fails with the
following error. This is due to bumping to Protobuf v29.0 and
protobuf-java:4.29.0, and I believe I can update
`ExtraProtobufGenerator.scala` to fix this. But the point is that I do
_not_ have to `load()` files from `@rules_java` after all.

```txt
ERROR: .../external/com_google_protobuf/src/google/protobuf/BUILD.bazel:23:14:
  ProtoScalaPBRule external/com_google_protobuf/src/google/protobuf/any_proto_jvm_extra_protobuf_generator_scalapb.srcjar
  failed: (Exit 1): scalapb_worker failed:
  error executing ProtoScalaPBRule command
  (from target @@com_google_protobuf//src/google/protobuf:any_proto)
  bazel-out/.../bin/src/scala/scripts/scalapb_worker
    ... (remaining 2 arguments skipped)

--jvm_extra_protobuf_generator_out:
  java.lang.NoSuchMethodError:
  'java.lang.Object com.google.protobuf.DescriptorProtos$FieldOptions.getExtension(com.google.protobuf.GeneratedMessage$GeneratedExtension)'
    at scalapb.compiler.DescriptorImplicits$ExtendedFieldDescriptor.fieldOptions(DescriptorImplicits.scala:329)
    at scalapb.compiler.DescriptorImplicits$ExtendedFieldDescriptor.scalaName(DescriptorImplicits.scala:207)
    at scalapb.compiler.ProtoValidation.validateField(ProtoValidation.scala:121)
    at scalapb.compiler.ProtoValidation.$anonfun$validateMessage$3(ProtoValidation.scala:56)
    at scalapb.compiler.ProtoValidation.$anonfun$validateMessage$3$adapted(ProtoValidation.scala:56)
    at scala.collection.Iterator.foreach(Iterator.scala:943)
    at scala.collection.Iterator.foreach$(Iterator.scala:943)
    at scala.collection.AbstractIterator.foreach(Iterator.scala:1431)
    at scala.collection.IterableLike.foreach(IterableLike.scala:74)
    at scala.collection.IterableLike.foreach$(IterableLike.scala:73)
    at scala.collection.AbstractIterable.foreach(Iterable.scala:56)
    at scalapb.compiler.ProtoValidation.validateMessage(ProtoValidation.scala:56)
    at scalapb.compiler.ProtoValidation.$anonfun$validateFile$2(ProtoValidation.scala:17)
    at scalapb.compiler.ProtoValidation.$anonfun$validateFile$2$adapted(ProtoValidation.scala:17)
    at scala.collection.Iterator.foreach(Iterator.scala:943)
    at scala.collection.Iterator.foreach$(Iterator.scala:943)
    at scala.collection.AbstractIterator.foreach(Iterator.scala:1431)
    at scala.collection.IterableLike.foreach(IterableLike.scala:74)
    at scala.collection.IterableLike.foreach$(IterableLike.scala:73)
    at scala.collection.AbstractIterable.foreach(Iterable.scala:56)
    at scalapb.compiler.ProtoValidation.validateFile(ProtoValidation.scala:17)
    at scalapb.compiler.ProtoValidation.$anonfun$validateFiles$1(ProtoValidation.scala:10)
    at scalapb.compiler.ProtoValidation.$anonfun$validateFiles$1$adapted(ProtoValidation.scala:10)
    at scala.collection.immutable.Stream.foreach(Stream.scala:533)
    at scalapb.compiler.ProtoValidation.validateFiles(ProtoValidation.scala:10)
    at scalarules.test.extra_protobuf_generator.ExtraProtobufGenerator$.handleCodeGeneratorRequest(ExtraProtobufGenerator.scala:86)
    at scalarules.test.extra_protobuf_generator.ExtraProtobufGenerator$.run(ExtraProtobufGenerator.scala:55)
    at protocbridge.frontend.PluginFrontend$.$anonfun$runWithBytes$1(PluginFrontend.scala:51)
    at scala.util.Try$.apply(Try.scala:213)
    at protocbridge.frontend.PluginFrontend$.runWithBytes(PluginFrontend.scala:51)
    at protocbridge.frontend.PluginFrontend$.runWithInputStream(PluginFrontend.scala:121)
    at protocbridge.frontend.PosixPluginFrontend$.$anonfun$prepare$2(PosixPluginFrontend.scala:40)
    at scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:23)
    at scala.concurrent.impl.ExecutionContextImpl$DefaultThreadFactory$$anon$1$$anon$2.block(ExecutionContextImpl.scala:75)
    at java.base/java.util.concurrent.ForkJoinPool.managedBlock(ForkJoinPool.java:3118)
    at scala.concurrent.impl.ExecutionContextImpl$DefaultThreadFactory$$anon$1.blockOn(ExecutionContextImpl.scala:87)
    at scala.concurrent.package$.blocking(package.scala:146)
    at protocbridge.frontend.PosixPluginFrontend$.$anonfun$prepare$1(PosixPluginFrontend.scala:38)
    at scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:23)
    at scala.concurrent.Future$.$anonfun$apply$1(Future.scala:659)
    at scala.util.Success.$anonfun$map$1(Try.scala:255)
    at scala.util.Success.map(Try.scala:213)
    at scala.concurrent.Future.$anonfun$map$1(Future.scala:292)
    at scala.concurrent.impl.Promise.$anonfun$transform$1(Promise.scala:42)
    at scala.concurrent.impl.CallbackRunnable.run(Promise.scala:74)
    at java.base/java.util.concurrent.ForkJoinTask$RunnableExecuteAction.exec(ForkJoinTask.java:1426)
    at java.base/java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:290)
    at java.base/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1020)
    at java.base/java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:1656)
    at java.base/java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1594)
    at java.base/java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:183)

java.lang.RuntimeException: Exit with code 1
    at scala.sys.package$.error(package.scala:30)
    at scripts.ScalaPBWorker$.work(ScalaPBWorker.scala:44)
    at io.bazel.rulesscala.worker.Worker.persistentWorkerMain(Worker.java:96)
    at io.bazel.rulesscala.worker.Worker.workerMain(Worker.java:49)
    at scripts.ScalaPBWorker$.main(ScalaPBWorker.scala:39)
    at scripts.ScalaPBWorker.main(ScalaPBWorker.scala)

ERROR: .../external/com_google_protobuf/src/google/protobuf/BUILD.bazel:23:14
  Building source jar external/com_google_protobuf/src/google/protobuf/any_proto_scalapb-src.jar
  failed: (Exit 1): scalapb_worker failed:
  error executing ProtoScalaPBRule command
  (from target @@com_google_protobuf//src/google/protobuf:any_proto)
  bazel-out/darwin_arm64-opt-exec-ST-a828a81199fe/bin/src/scala/scripts/scalapb_worker
    ... (remaining 2 arguments skipped)
```
@mbland
Copy link
Contributor

mbland commented Nov 29, 2024

@hvadehra Thanks for the hint about partitioning the .bzl files. I've done so successfully in my new bazel-8-compatibility-split-files branch, specifically in commit mbland@cdfec73, building under Bazel 8.0.0rc6. I didn't have to load() any @rules_java symbols at all.

As noted in the commit message, I haven't tried it under Bzlmod yet. , and there's still a Protobuf related breakage. But, I don't think there'll be any problem under Bzlmod , and now that Protobuf v29 and protobuf-java:4.29.0 are out (as of two days ago, after I ran my initial experiment), I think I can actually fix this breakage on the rules_scala side.

Update: Ah, I forgot to bump the ScalaPB version to 1.0.0-alpha.1. Once I did that, success! bazel build //src/... //test/... //third_party/... //scala_proto/... builds!

I can actually begin to land the .bzl file partitioning as I land more of my changes from #1482, and land the protobuf-java:4.29.0 update on the side. Unless the Protobuf v29 bump is an absolute requirement for Bazel 8 and/or rules_java 8, we might be able ensure Bazel 8 compatibility without requiring a separate major version bump just for that (we're already planning a bump for the Bzlmod changes).

Going to play with this some more in the coming days to see what I find out. @simuons and @liucijus Here's a heads-up that I may start sending pull requests related to these findings.

mbland added a commit to mbland/rules_scala that referenced this issue Nov 29, 2024
Every Scala version now uses com.google.protobuf:protobuf-java:4.29.0.
Part of bazelbuild#1482 and bazelbuild#1652.

This is necessary, but not sufficient, to make `rules_scala` Bazel 8
compatible by enabling an update to `protobuf` v29.0. Building with
Bazel 6.5.0 and `protobuf` v21.7 continues to pass all tests after this
change.
mbland added a commit to mbland/rules_scala that referenced this issue Nov 29, 2024
Ensures we get all the versions of dependencies we want in `WORKSPACE`,
while providing a new API to consumers. Part of bazelbuild#1652.
mbland added a commit to mbland/rules_scala that referenced this issue Nov 30, 2024
Ensures we get all the versions of dependencies we want in `WORKSPACE`,
while providing a new API to consumers. Part of bazelbuild#1652.
mbland added a commit to mbland/rules_scala that referenced this issue Nov 30, 2024
Ensures we get all the versions of dependencies we want in `WORKSPACE`,
while providing a new API to consumers. Part of bazelbuild#1652.
dkashyn-sfdc added a commit to dkashyn-sfdc/intellij that referenced this issue Nov 30, 2024
mbland added a commit to mbland/rules_scala that referenced this issue Nov 30, 2024
Ensures we get all the versions of dependencies we want in `WORKSPACE`,
while providing a new API to consumers. Part of bazelbuild#1652.

Bumps several packages as high as they can go and still be compatible
with Bazel 6 and 7:

- `bazel_skylib`: 1.4.1 => 1.7.1
- `rules_cc`: 0.0.6 => 0.0.9
- `rules_python`: 0.36.0 => 0.38.0
- `rules_go`: 0.50.1

The following packages are at the maximum version to prevent breakages
under Bazel 6.5.0.

---

`abseil-cpp` and `protobuf` have to stay at 20220623.1 and v27.1,
respectively, for Bazel 6 compatibility per bazelbuild#1647. `protobuf` up to
v25.5 is compatible with Bazel 6 provided users set the compiler flags
mentioned in that issue.

---

`rules_python` 0.38.0 => 0.39.0 requires at least `rules_cc` 0.0.10,
which introduced `cc/common/cc_info.bzl`:

```txt
$ bazel build //{src,test,third_party,scala_proto}/...

[ ...snip... ]
ERROR: error loading package under directory 'test':
  error loading package 'test':
  at .../external/rules_python/python/defs.bzl:17:6:
  at .../external/rules_python/python/py_binary.bzl:18:6:
  at .../external/rules_python/python/private/py_binary_macro.bzl:16:6:
  at .../external/rules_python/python/private/common_bazel.bzl:19:6:
  Label '@rules_cc//cc/common:cc_info.bzl' is invalid
    because 'cc/common' is not a package;
    perhaps you meant to put the colon here:
    '@rules_cc//cc:common/cc_info.bzl'?
```

---

`rules_cc` 0.0.9 => 0.10.0 requires Bazel 7, which defines
`CcSharedLibraryHintInfo`:

```txt
$ bazel build //{src,test,third_party,scala_proto}/...

ERROR: .../external/rules_cc/cc/private/rules_impl/native.bzl:40:33:
  name 'CcSharedLibraryHintInfo' is not defined (did you mean
  'CcSharedLibraryInfo'?)

[ ...snip... ]

ERROR: error loading package under directory 'test':
  error loading package 'test':
  at .../external/rules_python/python/defs.bzl:17:6:
  at .../external/rules_python/python/py_binary.bzl:18:6:
  at .../external/rules_python/python/private/py_binary_macro.bzl:16:6:
  at .../external/rules_python/python/private/common_bazel.bzl:18:6:
  at .../external/rules_cc/cc/common/cc_common.bzl:17:6:
  compilation of module 'cc/private/rules_impl/native.bzl' failed
```

---

`rules_java` remains at 7.9.0 due to the more complicated situation it
presents. The current version that could be compatible with Bazel 6 and
7 is 7.12.2.

As it turns out, we could include `rules_java` versions up to and
including 7.12.2 if we don't call the following in `WORKSPACE`:

```py
load("@rules_java//java:repositories.bzl", "rules_java_dependencies",
"rules_java_toolchains")
rules_java_dependencies()
rules_java_toolchains()
```

In fact, __we don't do that today__. When we do, Bazel 7.4.1 builds
successfully, but Bazel 6.5.2 fails with:

```txt
$ bazel build //{src,test,third_party,scala_proto}/...

ERROR:
  .../external/rules_java/toolchains/java_toolchain_alias.bzl:83:34:
  Use of Starlark transition without allowlist attribute
  '_allowlist_function_transition'.
  See Starlark transitions documentation for details and usage:
  @rules_java//toolchains:java_toolchain_alias.bzl NORMAL

ERROR:
  .../src/java/io/bazel/rulesscala/coverage/instrumenter/BUILD:3:12:
  While resolving toolchains for target
  //src/java/io/bazel/rulesscala/coverage/instrumenter:instrumenter:
  invalid registered toolchain '//toolchains:all':
  while parsing '//toolchains:all':
  error loading package '@rules_java//toolchains':
  initialization of module 'toolchains/java_toolchain_alias.bzl' failed

ERROR: Analysis of target
  '//src/java/io/bazel/rulesscala/coverage/instrumenter:instrumenter'
  failed; build aborted:
```

When we bump to rules_java 7.10.0, which contains
bazelbuild/rules_java#210, Bazel 7.4.1 fails
with:

```txt
$ bazel build //{src,test,third_party,scala_proto}/...

ERROR: .../external/rules_java_builtin/toolchains/BUILD:254:14:
  While resolving toolchains for target
  @@rules_java_builtin//toolchains:platformclasspath (096dcc8):
  No matching toolchains found for types
  @@bazel_tools//tools/jdk:bootstrap_runtime_toolchain_type.

To debug, rerun with
  --toolchain_resolution_debug='@@bazel_tools//tools/jdk:bootstrap_runtime_toolchain_type'
If platforms or toolchains are a new concept for you, we'd encourage
  reading https://bazel.build/concepts/platforms-intro.

ERROR: Analysis of target '//test/toolchains:java21_toolchain' failed;
  build aborted: Analysis failed
```

This is the error I described in bazelbuild#1619, under "Bump to rules_java 7.9.0
for Bazel 7 compatibility" in the message for
commit cd22d88.

Today I rediscovered:

- bazelbuild/rules_java: Regression with
  @@rules_java//toolchains:bootstrap_runtime_toolchain_type in 7.10.0
  bazelbuild/rules_java#214

But even worse, Bazel 6.5.0 fails with:

```txt
$ bazel build //{src,test,third_party,scala_proto}/...

[ ...snip... ]

ERROR: .../test/src/main/resources/java_sources/BUILD:5:14:
  Building test/src/main/resources/java_sources/CompiledWithJava8_java.jar
  (1 source file) failed: Worker process did not return a WorkResponse:

---8<---8<--- Start of log, file at .../bazel-workers/multiplex-worker-18-Javac.log ---8<---8<---
Error thrown by worker thread, shutting down worker.
java.lang.NoSuchMethodError:
  'java.lang.Iterable
   com.google.devtools.build.buildjar.javac.BlazeJavacMain$ClassloaderMaskingFileManager.getJavaFileObjectsFromPaths(java.util.Collection)'
    at com.google.devtools.build.buildjar.javac.BlazeJavacMain.compile(BlazeJavacMain.java:142)
    at com.google.devtools.build.buildjar.ReducedClasspathJavaLibraryBuilder.compileSources(ReducedClasspathJavaLibraryBuilder.java:57)
    at com.google.devtools.build.buildjar.SimpleJavaLibraryBuilder.compileJavaLibrary(SimpleJavaLibraryBuilder.java:110)
    at com.google.devtools.build.buildjar.SimpleJavaLibraryBuilder.run(SimpleJavaLibraryBuilder.java:118)
    at com.google.devtools.build.buildjar.BazelJavaBuilder.build(BazelJavaBuilder.java:111)
    at com.google.devtools.build.buildjar.BazelJavaBuilder.parseAndBuild(BazelJavaBuilder.java:91)
    at com.google.devtools.build.buildjar.BazelJavaBuilder.lambda$main$0(BazelJavaBuilder.java:52)
    at com.google.devtools.build.lib.worker.WorkRequestHandler$WorkRequestCallback.apply(WorkRequestHandler.java:252)
    at com.google.devtools.build.lib.worker.WorkRequestHandler.respondToRequest(WorkRequestHandler.java:480)
    at com.google.devtools.build.lib.worker.WorkRequestHandler.lambda$startResponseThread$1(WorkRequestHandler.java:433)
    at java.base/java.lang.Thread.run(Thread.java:829)
---8<---8<--- End of log ---8<---8<---

ERROR: .../test/src/main/resources/java_sources/BUILD:11:14:
  Building test/src/main/resources/java_sources/CompiledWithJava11_java.jar
  (1 source file) failed: Worker process did not return a WorkResponse:

---8<---8<--- Start of log, file at .../bazel-workers/multiplex-worker-18-Javac.log ---8<---8<---
Error thrown by worker thread, shutting down worker.
java.lang.NoSuchMethodError:
  'java.lang.Iterable
   com.google.devtools.build.buildjar.javac.BlazeJavacMain$ClassloaderMaskingFileManager.getJavaFileObjectsFromPaths(java.util.Collection)'
    at com.google.devtools.build.buildjar.javac.BlazeJavacMain.compile(BlazeJavacMain.java:142)
    at com.google.devtools.build.buildjar.ReducedClasspathJavaLibraryBuilder.compileSources(ReducedClasspathJavaLibraryBuilder.java:57)
    at com.google.devtools.build.buildjar.SimpleJavaLibraryBuilder.compileJavaLibrary(SimpleJavaLibraryBuilder.java:110)
    at com.google.devtools.build.buildjar.SimpleJavaLibraryBuilder.run(SimpleJavaLibraryBuilder.java:118)
    at com.google.devtools.build.buildjar.BazelJavaBuilder.build(BazelJavaBuilder.java:111)
    at com.google.devtools.build.buildjar.BazelJavaBuilder.parseAndBuild(BazelJavaBuilder.java:91)
    at com.google.devtools.build.buildjar.BazelJavaBuilder.lambda$main$0(BazelJavaBuilder.java:52)
    at com.google.devtools.build.lib.worker.WorkRequestHandler$WorkRequestCallback.apply(WorkRequestHandler.java:252)
    at com.google.devtools.build.lib.worker.WorkRequestHandler.respondToRequest(WorkRequestHandler.java:480)
    at com.google.devtools.build.lib.worker.WorkRequestHandler.lambda$startResponseThread$1(WorkRequestHandler.java:433)
    at java.base/java.lang.Thread.run(Thread.java:829)
---8<---8<--- End of log ---8<---8<---
```

In bazelbuild#1619, I thought we wanted to keep `@bazel_tools//tools/jdk:` as the
canonical Java toolchains package, instead of
`@rules_java//toolchains:`. But based on this comment from @fmeum, I'm
inclined to believe switching to `@rules_java//toolchains:` actually is
the preferred, futureproof approach:

- bazelbuild/rules_java#214 (comment)

---

Bazel 8 requires `rules_java` 8, per bazelbuild#1652. We can't update to
`rules_java` 8 right now, unless we decided to do the following:

- Tell Bazel 6 users to add C++ compiler flags to support the newer
  `abseil-cpp` versions required by newer `protobuf` versions.

- Abandon Bazel 6 support in favor of supporting Bazel 7 at a minimum.

- In addition to either of the above cases, update ScalaPB to
  1.0.0-alpha.1 or higher to support `protobuf` v28.

Here are the details explaining why `rules_java` 8 currently breaks.

`rules_java` 8.0.0 requires Bazel >= 7.3.2, which provides the `subrule`
API. Compatibility with Bazel >= 6.3.0 isn't restored until `rules_java`
8.3.2.

```txt
$ bazel build //{src,test,third_party,scala_proto}/...

ERROR:
  .../external/rules_java/java/common/rules/android_lint.bzl:142:24:
  name 'subrule' is not defined (did you mean 'rule'?)

ERROR: Error computing the main repository mapping:
  at .../scala/private/extensions/dev_deps.bzl:8:6:
  at .../external/rules_java/java/repositories.bzl:20:6:
  at .../external/rules_java/toolchains/local_java_repository.bzl:17:6:
  at .../external/rules_java/java/defs.bzl:18:6:
  at .../external/rules_java/java/java_library.bzl:16:6:
  at .../external/rules_java/java/bazel/rules/bazel_java_library.bzl:21:6:
  compilation of module 'java/common/rules/android_lint.bzl' failed
```

`rules_java` 8.3.0 is broken, as it can't find its own
`@compatibility_proxy` repo:

```txt
$ bazel build //{src,test,third_party,scala_proto}/...

ERROR: error loading package under directory 'src':
  error loading package 'src/protobuf/io/bazel/rules_scala':
  at .../external/rules_java/java/defs.bzl:22:6:
  at .../external/rules_java/java/java_test.bzl:16:6:
  Unable to find package for @compatibility_proxy//:proxy.bzl:
  The repository '@compatibility_proxy' could not be resolved:
  Repository '@compatibility_proxy' is not defined.
```

`rules_java` 8.3.1 seems to fix this, presumably by importing the
`protobuf` repo as `com_google_protobuf`. However, it now requires at
least `protobuf` v27.0, which adds `bazel/java/lite_proto_library.bzl`.
Per bazelbuild#1647, we'd have to update to ScalaPB 1.0.0-alpha.1 to support
`protobuf` v28, abandoning users of previous `protobuf` versions or
forcing them to upgrade.

```txt
$ bazel build //{src,test,third_party,scala_proto}/...

[...snip...]
ERROR: error loading package under directory 'src':
  error loading package 'src/java/io/bazel/rulesscala/worker':
  at .../external/rules_java/java/defs.bzl:16:6:
  Label '@com_google_protobuf//bazel:java_lite_proto_library.bzl'
  is invalid because 'bazel' is not a package;
  perhaps you meant to put the colon here:
  '@com_google_protobuf//:bazel/java_lite_proto_library.bzl'?
```
mbland added a commit to mbland/rules_scala that referenced this issue Nov 30, 2024
Updates almost all dependencies on `@bazel_tools//tools/jdk:` toolchain
targets and `.bzl` files to corresponding targets and files in
`@rules_java//toolchains:`. Part of bazelbuild#1482 and bazelbuild#1652.

All dependencies on `@bazel_tools//tools/jdk:toolchain_type` remain,
however, as there is not yet a corresponding target in
`@rules_java//toolchains:`.

Adds the `WORKSPACE` stanza recommended in the `rules_java` release
notes, and removes our own calls to instantiate `rules_java` repos and
to register `rules_java` toolchains.

These changes are required to avoid build breakages when updating to
`rules_scala` 7.10.0 and higher. All targets build and all tests pass
under Bazel 6.5.0 and 7.4.1.

---

I was on the right track in my analysis from bazelbuild#1619 ("Bump to
rules_java 7.9.0 for Bazel 7 compatibility" in the message for
commit cd22d88). However, I thought we
_shouldn't_ update any targets from `@bazel_tools//tools/jdk:` to
`@rules_java//toolchains:`. That's why I thought we were stuck on
`rules_java` 7.9.0.

However, this comment from @fmeum made me think switching to
`@rules_java//toolchains:` actually is the preferred approach:

- bazelbuild/rules_java#214 (comment)

So this is a potentially breaking change, but in the good kind of way,
in that it requires an easy, future proof update.
mbland added a commit to mbland/rules_scala that referenced this issue Dec 1, 2024
It's not just `rules_java` in the new preamble, but that's what's
precipitating the change. This preamble also works under Bazel 8, per my
investigation in bazelbuild#1652.
mbland added a commit to mbland/rules_scala that referenced this issue Dec 1, 2024
Removes this symbol from `scala/scala.bzl` as well as
`setup_scala_testing_toolchain`, and deletes
`scala/private/macros/toolchains.bzl`. Part of bazelbuild#1482 and bazelbuild#1652.

This is required for Bazel 8 and `rules_java` 8 compatibility, but is
also compatible with Bazel 6 and 7. In bazelbuild#1652, @hvadehra suggested
partitioning the `.bzl` files such that `WORKSPACE` doesn't `load` a
file that tries to `load` symbols from `rules_java`. I successfully did
so in a separate branch, and along with other minor changes, got
`rules_scala` to build with `rules_java` 8.5.1.

The other changes will come in separate pull requests, but it makes
sense to land this change now before adding any other toolchains to
`scala_toolchains`.

---

Arguably, we should remove all macros exported from `scala/scala.bzl`
that only instantiate toolchain dependencies and define toolchains. That
may be a breaking change for some users, but will ultimately be
necessary for these macros to remain compatible with Bazel 8.
mbland added a commit to mbland/rules_scala that referenced this issue Dec 1, 2024
Adds the jmh toolchain to `scala_toolchains()` and moves
`jmh_repositories()` to `jmh/toolchain/toolchain.bzl` for `rules_java` 8
compatibility. Part of bazelbuild#1482 and bazelbuild#1652.
mbland added a commit to mbland/rules_scala that referenced this issue Dec 1, 2024
This is the last of the toolchain to receive the "toolchainization"
treatment prior to Bzlmodification, and moves `twitter_scrooge()` to
`twitter_scrooge/toolchain/toolchain.bzl` for `rules_java` 8
compatibility. Part of bazelbuild#1482 and bazelbuild#1652.
mbland added a commit to mbland/rules_scala that referenced this issue Jan 27, 2025
Adds the jmh toolchain to `scala_toolchains()` and moves
`jmh_repositories()` to `jmh/toolchain/toolchain.bzl` for `rules_java` 8
compatibility. Part of bazelbuild#1482 and bazelbuild#1652.
mbland added a commit to mbland/rules_scala that referenced this issue Jan 27, 2025
This is the last of the toolchain to receive the "toolchainization"
treatment prior to Bzlmodification, and moves `twitter_scrooge()` to
`twitter_scrooge/toolchain/toolchain.bzl` for `rules_java` 8
compatibility. Part of bazelbuild#1482 and bazelbuild#1652.
mbland added a commit to mbland/rules_scala that referenced this issue Jan 27, 2025
Bumps dependencies to versions that are compatible with both Bazel 7.4.1
and 8.0.0. Part of bazelbuild#1652.

- ScalaPB jars: 0.11.17 => 1.0.0-alpha.1
- `rules_python`: 0.38.0 => 1.0.0
- `rules_cc`: 0.0.9 => 0.1.0
- `abseil-cpp`: 20220623.1 => 20240722.0
- `rules_java`: 7.12.3 => 8.6.2
- `protobuf`: 21.7 => 29.1
- `rules_proto`: 6.0.2 => 7.0.2

This precipitated the following updates also included in this commit:

- Loads `java_proto_library` from `com_google_protobuf`.
- Calls `java_repository()` after `protobuf_deps()` in `WORKSPACE`.
- Bumps `.bazelversion` to 7.4.1.
- Sets `common --{,no}enable_{workspace,bzlmod}`.
- Adds `allow_empty = True` to a `glob` expression in
  `//test/semanticdb:lib_with_tempsrc`.
- Removes Scala 2.11 test cases.

With this change:

- `WORKSPACE` builds succeed under Bazel 6.5.0, 7.4.1, and 8.0.0.
- Bzlmod builds succeed under Bazel 7.4.1 under 8.0.0.

Bazel 8 and `rules_java` 8 require `protobuf` >= v29. Bazel 6 Bzlmod
builds aren't supported because it doesn't provide `use_repo_rule`,
which is required by `rules_jvm_external` 6.3, which is required by
`protobuf` v29.

After the `protobuf` v29 bump, and before the ScalaPB 1.0.0-alpha.1
bump, `scala_proto` targets would fail with the following error:

```txt
ERROR: .../external/com_google_protobuf/src/google/protobuf/BUILD.bazel:23:14:
  ProtoScalaPBRule external/com_google_protobuf/src/google/protobuf/any_proto_jvm_extra_protobuf_generator_scalapb.srcjar
  failed: (Exit 1): scalapb_worker failed:
  error executing ProtoScalaPBRule command
  (from target @@com_google_protobuf//src/google/protobuf:any_proto)
  bazel-out/.../bin/src/scala/scripts/scalapb_worker
    ... (remaining 2 arguments skipped)

--jvm_extra_protobuf_generator_out:
  java.lang.NoSuchMethodError:
  'java.lang.Object com.google.protobuf.DescriptorProtos$FieldOptions.getExtension(com.google.protobuf.GeneratedMessage$GeneratedExtension)'
    at scalapb.compiler.DescriptorImplicits$ExtendedFieldDescriptor.fieldOptions(DescriptorImplicits.scala:329)
    at scalapb.compiler.DescriptorImplicits$ExtendedFieldDescriptor.scalaName(DescriptorImplicits.scala:207)
    at scalapb.compiler.ProtoValidation.validateField(ProtoValidation.scala:121)
    at scalapb.compiler.ProtoValidation.$anonfun$validateMessage$3(ProtoValidation.scala:56)
    at scalapb.compiler.ProtoValidation.$anonfun$validateMessage$3$adapted(ProtoValidation.scala:56)
    at scala.collection.Iterator.foreach(Iterator.scala:943)
    at scala.collection.Iterator.foreach$(Iterator.scala:943)
    at scala.collection.AbstractIterator.foreach(Iterator.scala:1431)
    at scala.collection.IterableLike.foreach(IterableLike.scala:74)
    at scala.collection.IterableLike.foreach$(IterableLike.scala:73)
    at scala.collection.AbstractIterable.foreach(Iterable.scala:56)
    at scalapb.compiler.ProtoValidation.validateMessage(ProtoValidation.scala:56)
    at scalapb.compiler.ProtoValidation.$anonfun$validateFile$2(ProtoValidation.scala:17)
    at scalapb.compiler.ProtoValidation.$anonfun$validateFile$2$adapted(ProtoValidation.scala:17)
    at scala.collection.Iterator.foreach(Iterator.scala:943)
    at scala.collection.Iterator.foreach$(Iterator.scala:943)
    at scala.collection.AbstractIterator.foreach(Iterator.scala:1431)
    at scala.collection.IterableLike.foreach(IterableLike.scala:74)
    at scala.collection.IterableLike.foreach$(IterableLike.scala:73)
    at scala.collection.AbstractIterable.foreach(Iterable.scala:56)
    at scalapb.compiler.ProtoValidation.validateFile(ProtoValidation.scala:17)
    at scalapb.compiler.ProtoValidation.$anonfun$validateFiles$1(ProtoValidation.scala:10)
    at scalapb.compiler.ProtoValidation.$anonfun$validateFiles$1$adapted(ProtoValidation.scala:10)
    at scala.collection.immutable.Stream.foreach(Stream.scala:533)
    at scalapb.compiler.ProtoValidation.validateFiles(ProtoValidation.scala:10)
    at scalarules.test.extra_protobuf_generator.ExtraProtobufGenerator$.handleCodeGeneratorRequest(ExtraProtobufGenerator.scala:86)
    at scalarules.test.extra_protobuf_generator.ExtraProtobufGenerator$.run(ExtraProtobufGenerator.scala:55)
    at protocbridge.frontend.PluginFrontend$.$anonfun$runWithBytes$1(PluginFrontend.scala:51)
    at scala.util.Try$.apply(Try.scala:213)
    at protocbridge.frontend.PluginFrontend$.runWithBytes(PluginFrontend.scala:51)
    at protocbridge.frontend.PluginFrontend$.runWithInputStream(PluginFrontend.scala:121)
    at protocbridge.frontend.PosixPluginFrontend$.$anonfun$prepare$2(PosixPluginFrontend.scala:40)
    at scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:23)
    at scala.concurrent.impl.ExecutionContextImpl$DefaultThreadFactory$$anon$1$$anon$2.block(ExecutionContextImpl.scala:75)
    at java.base/java.util.concurrent.ForkJoinPool.managedBlock(ForkJoinPool.java:3118)
    at scala.concurrent.impl.ExecutionContextImpl$DefaultThreadFactory$$anon$1.blockOn(ExecutionContextImpl.scala:87)
    at scala.concurrent.package$.blocking(package.scala:146)
    at protocbridge.frontend.PosixPluginFrontend$.$anonfun$prepare$1(PosixPluginFrontend.scala:38)
    at scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:23)
    at scala.concurrent.Future$.$anonfun$apply$1(Future.scala:659)
    at scala.util.Success.$anonfun$map$1(Try.scala:255)
    at scala.util.Success.map(Try.scala:213)
    at scala.concurrent.Future.$anonfun$map$1(Future.scala:292)
    at scala.concurrent.impl.Promise.$anonfun$transform$1(Promise.scala:42)
    at scala.concurrent.impl.CallbackRunnable.run(Promise.scala:74)
    at java.base/java.util.concurrent.ForkJoinTask$RunnableExecuteAction.exec(ForkJoinTask.java:1426)
    at java.base/java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:290)
    at java.base/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1020)
    at java.base/java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:1656)
    at java.base/java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1594)
    at java.base/java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:183)

java.lang.RuntimeException: Exit with code 1
    at scala.sys.package$.error(package.scala:30)
    at scripts.ScalaPBWorker$.work(ScalaPBWorker.scala:44)
    at io.bazel.rulesscala.worker.Worker.persistentWorkerMain(Worker.java:96)
    at io.bazel.rulesscala.worker.Worker.workerMain(Worker.java:49)
    at scripts.ScalaPBWorker$.main(ScalaPBWorker.scala:39)
    at scripts.ScalaPBWorker.main(ScalaPBWorker.scala)

ERROR: .../external/com_google_protobuf/src/google/protobuf/BUILD.bazel:23:14
  Building source jar external/com_google_protobuf/src/google/protobuf/any_proto_scalapb-src.jar
  failed: (Exit 1): scalapb_worker failed:
  error executing ProtoScalaPBRule command
  (from target @@com_google_protobuf//src/google/protobuf:any_proto)
  bazel-out/darwin_arm64-opt-exec-ST-a828a81199fe/bin/src/scala/scripts/scalapb_worker
    ... (remaining 2 arguments skipped)
```

Here's why the other changes were necessary in light of the version
bumps:

- `java_proto_library` from `rules_java` is now officially deprecated,
  hence loading it from `com_google_protobuf`.

- The `rules_java` release notes suggest either loading
  `proto_bazel_features` from `@com_google_protobuf` or just calling
  `protobuf_deps()`. The key point is that the project must instantiate
  the `@proto_bazel_features` repo _before_ calling
  `rules_java_toolchains`. Hence, we've moved the
  `rules_java_toolchains()` call to follow `protobuf_deps()`.

- We're using Bazel 7.4.1 in order to upgrade `abseil-cpp` to 20240722.0
  and `protobuf` to v29.0. This is instead of keeping `.bazelversion` at
  6.5.0 and setting C++ compiler flags in `.bazelrc` as described in
  bazelbuild#1647.

- Setting `common --{,no}enable_{workspace,bzlmod}` fixes
  `test_semanticdb_handles_removed_sourcefiles`. This test relies on
  `bazel query`, which is also affected by these flags, hence `common`
  instead of `build`. Bazel 8 defaults to `--enable_bzlmod
  --noenable_workspace`, causing the `WORKSPACE` run of this test to
  fail.

- `glob` requires an explicit `allow_empty = True` parameter now that
  `--incompatible_disallow_empty_glob` defaults to `True` in Bazel 8.

- ScalaPB 0.9.8, the last version compatible with Scala 2.11, does not
  support `protobuf` >= 26.0. For this reason, we must remove the Scala
  2.11 test cases.

We should probably drop Scala 2.11 support at this point, since there's
no ScalaPB release that supports `protobuf` > v25.5.

Or perhaps we can at least document that `scala_proto` or any rules
otherwise depending on `protobuf` are no longer supported out of the
box. Such users will have to ensure they register their own downgraded
versions:

- `protobuf` <= v25.5
- `abseil-cpp` <= 20220623.1
- `rules_java` <= 7.12.2
- `rules_cc` <= 0.0.9
mbland added a commit to mbland/rules_scala that referenced this issue Jan 27, 2025
Bumps dependencies to versions that are compatible with both Bazel 7.4.1
and 8.0.0. Part of bazelbuild#1652.

- ScalaPB jars: 0.11.17 => 1.0.0-alpha.1
- `rules_python`: 0.38.0 => 1.0.0
- `rules_cc`: 0.0.9 => 0.1.0
- `abseil-cpp`: 20220623.1 => 20240722.0
- `rules_java`: 7.12.3 => 8.6.2
- `protobuf`: 21.7 => 29.1
- `rules_proto`: 6.0.2 => 7.0.2

This precipitated the following updates also included in this commit:

- Loads `java_proto_library` from `com_google_protobuf`.
- Calls `java_repository()` after `protobuf_deps()` in `WORKSPACE`.
- Bumps `.bazelversion` to 7.4.1.
- Sets `common --{,no}enable_{workspace,bzlmod}`.
- Adds `allow_empty = True` to a `glob` expression in
  `//test/semanticdb:lib_with_tempsrc`.
- Removes Scala 2.11 test cases.

With this change:

- `WORKSPACE` builds succeed under Bazel 6.5.0, 7.4.1, and 8.0.0.
- Bzlmod builds succeed under Bazel 7.4.1 under 8.0.0.

Bazel 8 and `rules_java` 8 require `protobuf` >= v29. Bazel 6 Bzlmod
builds aren't supported because it doesn't provide `use_repo_rule`,
which is required by `rules_jvm_external` 6.3, which is required by
`protobuf` v29.

After the `protobuf` v29 bump, and before the ScalaPB 1.0.0-alpha.1
bump, `scala_proto` targets would fail with the following error:

```txt
ERROR: .../external/com_google_protobuf/src/google/protobuf/BUILD.bazel:23:14:
  ProtoScalaPBRule external/com_google_protobuf/src/google/protobuf/any_proto_jvm_extra_protobuf_generator_scalapb.srcjar
  failed: (Exit 1): scalapb_worker failed:
  error executing ProtoScalaPBRule command
  (from target @@com_google_protobuf//src/google/protobuf:any_proto)
  bazel-out/.../bin/src/scala/scripts/scalapb_worker
    ... (remaining 2 arguments skipped)

--jvm_extra_protobuf_generator_out:
  java.lang.NoSuchMethodError:
  'java.lang.Object com.google.protobuf.DescriptorProtos$FieldOptions.getExtension(com.google.protobuf.GeneratedMessage$GeneratedExtension)'
    at scalapb.compiler.DescriptorImplicits$ExtendedFieldDescriptor.fieldOptions(DescriptorImplicits.scala:329)
    at scalapb.compiler.DescriptorImplicits$ExtendedFieldDescriptor.scalaName(DescriptorImplicits.scala:207)
    at scalapb.compiler.ProtoValidation.validateField(ProtoValidation.scala:121)
    at scalapb.compiler.ProtoValidation.$anonfun$validateMessage$3(ProtoValidation.scala:56)
    at scalapb.compiler.ProtoValidation.$anonfun$validateMessage$3$adapted(ProtoValidation.scala:56)
    at scala.collection.Iterator.foreach(Iterator.scala:943)
    at scala.collection.Iterator.foreach$(Iterator.scala:943)
    at scala.collection.AbstractIterator.foreach(Iterator.scala:1431)
    at scala.collection.IterableLike.foreach(IterableLike.scala:74)
    at scala.collection.IterableLike.foreach$(IterableLike.scala:73)
    at scala.collection.AbstractIterable.foreach(Iterable.scala:56)
    at scalapb.compiler.ProtoValidation.validateMessage(ProtoValidation.scala:56)
    at scalapb.compiler.ProtoValidation.$anonfun$validateFile$2(ProtoValidation.scala:17)
    at scalapb.compiler.ProtoValidation.$anonfun$validateFile$2$adapted(ProtoValidation.scala:17)
    at scala.collection.Iterator.foreach(Iterator.scala:943)
    at scala.collection.Iterator.foreach$(Iterator.scala:943)
    at scala.collection.AbstractIterator.foreach(Iterator.scala:1431)
    at scala.collection.IterableLike.foreach(IterableLike.scala:74)
    at scala.collection.IterableLike.foreach$(IterableLike.scala:73)
    at scala.collection.AbstractIterable.foreach(Iterable.scala:56)
    at scalapb.compiler.ProtoValidation.validateFile(ProtoValidation.scala:17)
    at scalapb.compiler.ProtoValidation.$anonfun$validateFiles$1(ProtoValidation.scala:10)
    at scalapb.compiler.ProtoValidation.$anonfun$validateFiles$1$adapted(ProtoValidation.scala:10)
    at scala.collection.immutable.Stream.foreach(Stream.scala:533)
    at scalapb.compiler.ProtoValidation.validateFiles(ProtoValidation.scala:10)
    at scalarules.test.extra_protobuf_generator.ExtraProtobufGenerator$.handleCodeGeneratorRequest(ExtraProtobufGenerator.scala:86)
    at scalarules.test.extra_protobuf_generator.ExtraProtobufGenerator$.run(ExtraProtobufGenerator.scala:55)
    at protocbridge.frontend.PluginFrontend$.$anonfun$runWithBytes$1(PluginFrontend.scala:51)
    at scala.util.Try$.apply(Try.scala:213)
    at protocbridge.frontend.PluginFrontend$.runWithBytes(PluginFrontend.scala:51)
    at protocbridge.frontend.PluginFrontend$.runWithInputStream(PluginFrontend.scala:121)
    at protocbridge.frontend.PosixPluginFrontend$.$anonfun$prepare$2(PosixPluginFrontend.scala:40)
    at scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:23)
    at scala.concurrent.impl.ExecutionContextImpl$DefaultThreadFactory$$anon$1$$anon$2.block(ExecutionContextImpl.scala:75)
    at java.base/java.util.concurrent.ForkJoinPool.managedBlock(ForkJoinPool.java:3118)
    at scala.concurrent.impl.ExecutionContextImpl$DefaultThreadFactory$$anon$1.blockOn(ExecutionContextImpl.scala:87)
    at scala.concurrent.package$.blocking(package.scala:146)
    at protocbridge.frontend.PosixPluginFrontend$.$anonfun$prepare$1(PosixPluginFrontend.scala:38)
    at scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:23)
    at scala.concurrent.Future$.$anonfun$apply$1(Future.scala:659)
    at scala.util.Success.$anonfun$map$1(Try.scala:255)
    at scala.util.Success.map(Try.scala:213)
    at scala.concurrent.Future.$anonfun$map$1(Future.scala:292)
    at scala.concurrent.impl.Promise.$anonfun$transform$1(Promise.scala:42)
    at scala.concurrent.impl.CallbackRunnable.run(Promise.scala:74)
    at java.base/java.util.concurrent.ForkJoinTask$RunnableExecuteAction.exec(ForkJoinTask.java:1426)
    at java.base/java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:290)
    at java.base/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1020)
    at java.base/java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:1656)
    at java.base/java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1594)
    at java.base/java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:183)

java.lang.RuntimeException: Exit with code 1
    at scala.sys.package$.error(package.scala:30)
    at scripts.ScalaPBWorker$.work(ScalaPBWorker.scala:44)
    at io.bazel.rulesscala.worker.Worker.persistentWorkerMain(Worker.java:96)
    at io.bazel.rulesscala.worker.Worker.workerMain(Worker.java:49)
    at scripts.ScalaPBWorker$.main(ScalaPBWorker.scala:39)
    at scripts.ScalaPBWorker.main(ScalaPBWorker.scala)

ERROR: .../external/com_google_protobuf/src/google/protobuf/BUILD.bazel:23:14
  Building source jar external/com_google_protobuf/src/google/protobuf/any_proto_scalapb-src.jar
  failed: (Exit 1): scalapb_worker failed:
  error executing ProtoScalaPBRule command
  (from target @@com_google_protobuf//src/google/protobuf:any_proto)
  bazel-out/darwin_arm64-opt-exec-ST-a828a81199fe/bin/src/scala/scripts/scalapb_worker
    ... (remaining 2 arguments skipped)
```

Here's why the other changes were necessary in light of the version
bumps:

- `java_proto_library` from `rules_java` is now officially deprecated,
  hence loading it from `com_google_protobuf`.

- The `rules_java` release notes suggest either loading
  `proto_bazel_features` from `@com_google_protobuf` or just calling
  `protobuf_deps()`. The key point is that the project must instantiate
  the `@proto_bazel_features` repo _before_ calling
  `rules_java_toolchains`. Hence, we've moved the
  `rules_java_toolchains()` call to follow `protobuf_deps()`.

- We're using Bazel 7.4.1 in order to upgrade `abseil-cpp` to 20240722.0
  and `protobuf` to v29.0. This is instead of keeping `.bazelversion` at
  6.5.0 and setting C++ compiler flags in `.bazelrc` as described in
  bazelbuild#1647.

- Setting `common --{,no}enable_{workspace,bzlmod}` fixes
  `test_semanticdb_handles_removed_sourcefiles`. This test relies on
  `bazel query`, which is also affected by these flags, hence `common`
  instead of `build`. Bazel 8 defaults to `--enable_bzlmod
  --noenable_workspace`, causing the `WORKSPACE` run of this test to
  fail.

- `glob` requires an explicit `allow_empty = True` parameter now that
  `--incompatible_disallow_empty_glob` defaults to `True` in Bazel 8.

- ScalaPB 0.9.8, the last version compatible with Scala 2.11, does not
  support `protobuf` >= 26.0. For this reason, we must remove the Scala
  2.11 test cases.

We should probably drop Scala 2.11 support at this point, since there's
no ScalaPB release that supports `protobuf` > v25.5.

Or perhaps we can at least document that `scala_proto` or any rules
otherwise depending on `protobuf` are no longer supported out of the
box. Such users will have to ensure they register their own downgraded
versions:

- `protobuf` <= v25.5
- `abseil-cpp` <= 20220623.1
- `rules_java` <= 7.12.2
- `rules_cc` <= 0.0.9
mbland added a commit to mbland/rules_scala that referenced this issue Jan 28, 2025
Bumps dependencies to versions that are compatible with both Bazel 7.4.1
and 8.0.0. Part of bazelbuild#1652.

- ScalaPB jars: 0.11.17 => 1.0.0-alpha.1
- `rules_python`: 0.38.0 => 1.1.0
- `rules_cc`: 0.0.9 => 0.0.17
- `abseil-cpp`: 20220623.1 => 20240722.1
- `rules_java`: 7.12.3 => 8.7.2
- `protobuf`: 21.7 => 29.3
- `rules_proto`: 6.0.2 => 7.1.0

rules_cc 0.1.0 exists, but we're using 0.0.17 per this advice from
https://github.com/bazelbuild/rules_cc/releases/tag/0.1.0:

> 0.1.x releases are not updated, please continue to use the latest
> 0.0.x release.

This precipitated the following updates also included in this commit:

- Loads `java_proto_library` from `com_google_protobuf`.
- Calls `java_repository()` after `protobuf_deps()` in `WORKSPACE`.
- Bumps `.bazelversion` to 7.4.1.
- Sets `common --{,no}enable_{workspace,bzlmod}`.
- Adds `allow_empty = True` to a `glob` expression in
  `//test/semanticdb:lib_with_tempsrc`.
- Removes Scala 2.11 test cases.

With this change:

- `WORKSPACE` builds succeed under Bazel 6.5.0, 7.4.1, and 8.0.0.
- Bzlmod builds succeed under Bazel 7.4.1 under 8.0.0.

Bazel 8 and `rules_java` 8 require `protobuf` >= v29. Bazel 6 Bzlmod
builds aren't supported because it doesn't provide `use_repo_rule`,
which is required by `rules_jvm_external` 6.3, which is required by
`protobuf` v29.

After the `protobuf` v29 bump, and before the ScalaPB 1.0.0-alpha.1
bump, `scala_proto` targets would fail with the following error:

```txt
ERROR: .../external/com_google_protobuf/src/google/protobuf/BUILD.bazel:23:14:
  ProtoScalaPBRule external/com_google_protobuf/src/google/protobuf/any_proto_jvm_extra_protobuf_generator_scalapb.srcjar
  failed: (Exit 1): scalapb_worker failed:
  error executing ProtoScalaPBRule command
  (from target @@com_google_protobuf//src/google/protobuf:any_proto)
  bazel-out/.../bin/src/scala/scripts/scalapb_worker
    ... (remaining 2 arguments skipped)

--jvm_extra_protobuf_generator_out:
  java.lang.NoSuchMethodError:
  'java.lang.Object com.google.protobuf.DescriptorProtos$FieldOptions.getExtension(com.google.protobuf.GeneratedMessage$GeneratedExtension)'
    at scalapb.compiler.DescriptorImplicits$ExtendedFieldDescriptor.fieldOptions(DescriptorImplicits.scala:329)
    at scalapb.compiler.DescriptorImplicits$ExtendedFieldDescriptor.scalaName(DescriptorImplicits.scala:207)
    at scalapb.compiler.ProtoValidation.validateField(ProtoValidation.scala:121)
    at scalapb.compiler.ProtoValidation.$anonfun$validateMessage$3(ProtoValidation.scala:56)
    at scalapb.compiler.ProtoValidation.$anonfun$validateMessage$3$adapted(ProtoValidation.scala:56)
    at scala.collection.Iterator.foreach(Iterator.scala:943)
    at scala.collection.Iterator.foreach$(Iterator.scala:943)
    at scala.collection.AbstractIterator.foreach(Iterator.scala:1431)
    at scala.collection.IterableLike.foreach(IterableLike.scala:74)
    at scala.collection.IterableLike.foreach$(IterableLike.scala:73)
    at scala.collection.AbstractIterable.foreach(Iterable.scala:56)
    at scalapb.compiler.ProtoValidation.validateMessage(ProtoValidation.scala:56)
    at scalapb.compiler.ProtoValidation.$anonfun$validateFile$2(ProtoValidation.scala:17)
    at scalapb.compiler.ProtoValidation.$anonfun$validateFile$2$adapted(ProtoValidation.scala:17)
    at scala.collection.Iterator.foreach(Iterator.scala:943)
    at scala.collection.Iterator.foreach$(Iterator.scala:943)
    at scala.collection.AbstractIterator.foreach(Iterator.scala:1431)
    at scala.collection.IterableLike.foreach(IterableLike.scala:74)
    at scala.collection.IterableLike.foreach$(IterableLike.scala:73)
    at scala.collection.AbstractIterable.foreach(Iterable.scala:56)
    at scalapb.compiler.ProtoValidation.validateFile(ProtoValidation.scala:17)
    at scalapb.compiler.ProtoValidation.$anonfun$validateFiles$1(ProtoValidation.scala:10)
    at scalapb.compiler.ProtoValidation.$anonfun$validateFiles$1$adapted(ProtoValidation.scala:10)
    at scala.collection.immutable.Stream.foreach(Stream.scala:533)
    at scalapb.compiler.ProtoValidation.validateFiles(ProtoValidation.scala:10)
    at scalarules.test.extra_protobuf_generator.ExtraProtobufGenerator$.handleCodeGeneratorRequest(ExtraProtobufGenerator.scala:86)
    at scalarules.test.extra_protobuf_generator.ExtraProtobufGenerator$.run(ExtraProtobufGenerator.scala:55)
    at protocbridge.frontend.PluginFrontend$.$anonfun$runWithBytes$1(PluginFrontend.scala:51)
    at scala.util.Try$.apply(Try.scala:213)
    at protocbridge.frontend.PluginFrontend$.runWithBytes(PluginFrontend.scala:51)
    at protocbridge.frontend.PluginFrontend$.runWithInputStream(PluginFrontend.scala:121)
    at protocbridge.frontend.PosixPluginFrontend$.$anonfun$prepare$2(PosixPluginFrontend.scala:40)
    at scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:23)
    at scala.concurrent.impl.ExecutionContextImpl$DefaultThreadFactory$$anon$1$$anon$2.block(ExecutionContextImpl.scala:75)
    at java.base/java.util.concurrent.ForkJoinPool.managedBlock(ForkJoinPool.java:3118)
    at scala.concurrent.impl.ExecutionContextImpl$DefaultThreadFactory$$anon$1.blockOn(ExecutionContextImpl.scala:87)
    at scala.concurrent.package$.blocking(package.scala:146)
    at protocbridge.frontend.PosixPluginFrontend$.$anonfun$prepare$1(PosixPluginFrontend.scala:38)
    at scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:23)
    at scala.concurrent.Future$.$anonfun$apply$1(Future.scala:659)
    at scala.util.Success.$anonfun$map$1(Try.scala:255)
    at scala.util.Success.map(Try.scala:213)
    at scala.concurrent.Future.$anonfun$map$1(Future.scala:292)
    at scala.concurrent.impl.Promise.$anonfun$transform$1(Promise.scala:42)
    at scala.concurrent.impl.CallbackRunnable.run(Promise.scala:74)
    at java.base/java.util.concurrent.ForkJoinTask$RunnableExecuteAction.exec(ForkJoinTask.java:1426)
    at java.base/java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:290)
    at java.base/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1020)
    at java.base/java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:1656)
    at java.base/java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1594)
    at java.base/java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:183)

java.lang.RuntimeException: Exit with code 1
    at scala.sys.package$.error(package.scala:30)
    at scripts.ScalaPBWorker$.work(ScalaPBWorker.scala:44)
    at io.bazel.rulesscala.worker.Worker.persistentWorkerMain(Worker.java:96)
    at io.bazel.rulesscala.worker.Worker.workerMain(Worker.java:49)
    at scripts.ScalaPBWorker$.main(ScalaPBWorker.scala:39)
    at scripts.ScalaPBWorker.main(ScalaPBWorker.scala)

ERROR: .../external/com_google_protobuf/src/google/protobuf/BUILD.bazel:23:14
  Building source jar external/com_google_protobuf/src/google/protobuf/any_proto_scalapb-src.jar
  failed: (Exit 1): scalapb_worker failed:
  error executing ProtoScalaPBRule command
  (from target @@com_google_protobuf//src/google/protobuf:any_proto)
  bazel-out/darwin_arm64-opt-exec-ST-a828a81199fe/bin/src/scala/scripts/scalapb_worker
    ... (remaining 2 arguments skipped)
```

Here's why the other changes were necessary in light of the version
bumps:

- `java_proto_library` from `rules_java` is now officially deprecated,
  hence loading it from `com_google_protobuf`.

- The `rules_java` release notes suggest either loading
  `proto_bazel_features` from `@com_google_protobuf` or just calling
  `protobuf_deps()`. The key point is that the project must instantiate
  the `@proto_bazel_features` repo _before_ calling
  `rules_java_toolchains`. Hence, we've moved the
  `rules_java_toolchains()` call to follow `protobuf_deps()`.

- We're using Bazel 7.4.1 in order to upgrade `abseil-cpp` to 20240722.1
  and `protobuf` to v29.3. This is instead of keeping `.bazelversion` at
  6.5.0 and setting C++ compiler flags in `.bazelrc` as described in
  bazelbuild#1647.

- Setting `common --{,no}enable_{workspace,bzlmod}` fixes
  `test_semanticdb_handles_removed_sourcefiles`. This test relies on
  `bazel query`, which is also affected by these flags, hence `common`
  instead of `build`. Bazel 8 defaults to `--enable_bzlmod
  --noenable_workspace`, causing the `WORKSPACE` run of this test to
  fail.

- `glob` requires an explicit `allow_empty = True` parameter now that
  `--incompatible_disallow_empty_glob` defaults to `True` in Bazel 8.

- ScalaPB 0.9.8, the last version compatible with Scala 2.11, does not
  support `protobuf` >= 26.0. For this reason, we must remove the Scala
  2.11 test cases.

We should probably drop Scala 2.11 support at this point, since there's
no ScalaPB release that supports `protobuf` > v25.5.

Or perhaps we can at least document that `scala_proto` or any rules
otherwise depending on `protobuf` are no longer supported out of the
box. Such users will have to ensure they register their own downgraded
versions:

- `protobuf` <= v25.5
- `abseil-cpp` <= 20220623.1
- `rules_java` <= 7.12.2
- `rules_cc` <= 0.0.9

---

Other version bumps:

- `grpc-google-common-protos`: 2.48.0 => 2.50.0
- `grpc`: 1.68.1 => 1.69.0
- `guava`: 33.3.1-jre => 33.4.0-jre
- `jline`: 3.27.1 => 3.28.0
- `rules_go`: 0.50.1 => 0.52.0
- `sbt compiler interface`: 1.10.4 => 1.10.7
- `sbt util interface`: 1.10.5 => 1.10.7

Also contains several other transitive Maven artifact dependency updates
generated by scripts/create_repository.py.
mbland added a commit to mbland/rules_scala that referenced this issue Jan 28, 2025
Bumps dependencies to versions that are compatible with both Bazel 7.4.1
and 8.0.0. Part of bazelbuild#1652.

- ScalaPB jars: 0.11.17 => 1.0.0-alpha.1
- `rules_python`: 0.38.0 => 1.1.0
- `rules_cc`: 0.0.9 => 0.0.17
- `abseil-cpp`: 20220623.1 => 20240722.1
- `rules_java`: 7.12.4 => 8.7.2
- `protobuf`: 21.7 => 29.3
- `rules_proto`: 6.0.2 => 7.1.0

rules_cc 0.1.0 exists, but we're using 0.0.17 per this advice from
https://github.com/bazelbuild/rules_cc/releases/tag/0.1.0:

> 0.1.x releases are not updated, please continue to use the latest
> 0.0.x release.

This precipitated the following updates also included in this commit:

- Loads `java_proto_library` from `com_google_protobuf`.
- Calls `java_repository()` after `protobuf_deps()` in `WORKSPACE`.
- Bumps `.bazelversion` to 7.4.1.
- Sets `common --{,no}enable_{workspace,bzlmod}`.
- Adds `allow_empty = True` to a `glob` expression in
  `//test/semanticdb:lib_with_tempsrc`.
- Removes Scala 2.11 test cases.

With this change:

- `WORKSPACE` builds succeed under Bazel 6.5.0, 7.4.1, and 8.0.0.
- Bzlmod builds succeed under Bazel 7.4.1 under 8.0.0.

Bazel 8 and `rules_java` 8 require `protobuf` >= v29. Bazel 6 Bzlmod
builds aren't supported because it doesn't provide `use_repo_rule`,
which is required by `rules_jvm_external` 6.3, which is required by
`protobuf` v29.

After the `protobuf` v29 bump, and before the ScalaPB 1.0.0-alpha.1
bump, `scala_proto` targets would fail with the following error:

```txt
ERROR: .../external/com_google_protobuf/src/google/protobuf/BUILD.bazel:23:14:
  ProtoScalaPBRule external/com_google_protobuf/src/google/protobuf/any_proto_jvm_extra_protobuf_generator_scalapb.srcjar
  failed: (Exit 1): scalapb_worker failed:
  error executing ProtoScalaPBRule command
  (from target @@com_google_protobuf//src/google/protobuf:any_proto)
  bazel-out/.../bin/src/scala/scripts/scalapb_worker
    ... (remaining 2 arguments skipped)

--jvm_extra_protobuf_generator_out:
  java.lang.NoSuchMethodError:
  'java.lang.Object com.google.protobuf.DescriptorProtos$FieldOptions.getExtension(com.google.protobuf.GeneratedMessage$GeneratedExtension)'
    at scalapb.compiler.DescriptorImplicits$ExtendedFieldDescriptor.fieldOptions(DescriptorImplicits.scala:329)
    at scalapb.compiler.DescriptorImplicits$ExtendedFieldDescriptor.scalaName(DescriptorImplicits.scala:207)
    at scalapb.compiler.ProtoValidation.validateField(ProtoValidation.scala:121)
    at scalapb.compiler.ProtoValidation.$anonfun$validateMessage$3(ProtoValidation.scala:56)
    at scalapb.compiler.ProtoValidation.$anonfun$validateMessage$3$adapted(ProtoValidation.scala:56)
    at scala.collection.Iterator.foreach(Iterator.scala:943)
    at scala.collection.Iterator.foreach$(Iterator.scala:943)
    at scala.collection.AbstractIterator.foreach(Iterator.scala:1431)
    at scala.collection.IterableLike.foreach(IterableLike.scala:74)
    at scala.collection.IterableLike.foreach$(IterableLike.scala:73)
    at scala.collection.AbstractIterable.foreach(Iterable.scala:56)
    at scalapb.compiler.ProtoValidation.validateMessage(ProtoValidation.scala:56)
    at scalapb.compiler.ProtoValidation.$anonfun$validateFile$2(ProtoValidation.scala:17)
    at scalapb.compiler.ProtoValidation.$anonfun$validateFile$2$adapted(ProtoValidation.scala:17)
    at scala.collection.Iterator.foreach(Iterator.scala:943)
    at scala.collection.Iterator.foreach$(Iterator.scala:943)
    at scala.collection.AbstractIterator.foreach(Iterator.scala:1431)
    at scala.collection.IterableLike.foreach(IterableLike.scala:74)
    at scala.collection.IterableLike.foreach$(IterableLike.scala:73)
    at scala.collection.AbstractIterable.foreach(Iterable.scala:56)
    at scalapb.compiler.ProtoValidation.validateFile(ProtoValidation.scala:17)
    at scalapb.compiler.ProtoValidation.$anonfun$validateFiles$1(ProtoValidation.scala:10)
    at scalapb.compiler.ProtoValidation.$anonfun$validateFiles$1$adapted(ProtoValidation.scala:10)
    at scala.collection.immutable.Stream.foreach(Stream.scala:533)
    at scalapb.compiler.ProtoValidation.validateFiles(ProtoValidation.scala:10)
    at scalarules.test.extra_protobuf_generator.ExtraProtobufGenerator$.handleCodeGeneratorRequest(ExtraProtobufGenerator.scala:86)
    at scalarules.test.extra_protobuf_generator.ExtraProtobufGenerator$.run(ExtraProtobufGenerator.scala:55)
    at protocbridge.frontend.PluginFrontend$.$anonfun$runWithBytes$1(PluginFrontend.scala:51)
    at scala.util.Try$.apply(Try.scala:213)
    at protocbridge.frontend.PluginFrontend$.runWithBytes(PluginFrontend.scala:51)
    at protocbridge.frontend.PluginFrontend$.runWithInputStream(PluginFrontend.scala:121)
    at protocbridge.frontend.PosixPluginFrontend$.$anonfun$prepare$2(PosixPluginFrontend.scala:40)
    at scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:23)
    at scala.concurrent.impl.ExecutionContextImpl$DefaultThreadFactory$$anon$1$$anon$2.block(ExecutionContextImpl.scala:75)
    at java.base/java.util.concurrent.ForkJoinPool.managedBlock(ForkJoinPool.java:3118)
    at scala.concurrent.impl.ExecutionContextImpl$DefaultThreadFactory$$anon$1.blockOn(ExecutionContextImpl.scala:87)
    at scala.concurrent.package$.blocking(package.scala:146)
    at protocbridge.frontend.PosixPluginFrontend$.$anonfun$prepare$1(PosixPluginFrontend.scala:38)
    at scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:23)
    at scala.concurrent.Future$.$anonfun$apply$1(Future.scala:659)
    at scala.util.Success.$anonfun$map$1(Try.scala:255)
    at scala.util.Success.map(Try.scala:213)
    at scala.concurrent.Future.$anonfun$map$1(Future.scala:292)
    at scala.concurrent.impl.Promise.$anonfun$transform$1(Promise.scala:42)
    at scala.concurrent.impl.CallbackRunnable.run(Promise.scala:74)
    at java.base/java.util.concurrent.ForkJoinTask$RunnableExecuteAction.exec(ForkJoinTask.java:1426)
    at java.base/java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:290)
    at java.base/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1020)
    at java.base/java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:1656)
    at java.base/java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1594)
    at java.base/java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:183)

java.lang.RuntimeException: Exit with code 1
    at scala.sys.package$.error(package.scala:30)
    at scripts.ScalaPBWorker$.work(ScalaPBWorker.scala:44)
    at io.bazel.rulesscala.worker.Worker.persistentWorkerMain(Worker.java:96)
    at io.bazel.rulesscala.worker.Worker.workerMain(Worker.java:49)
    at scripts.ScalaPBWorker$.main(ScalaPBWorker.scala:39)
    at scripts.ScalaPBWorker.main(ScalaPBWorker.scala)

ERROR: .../external/com_google_protobuf/src/google/protobuf/BUILD.bazel:23:14
  Building source jar external/com_google_protobuf/src/google/protobuf/any_proto_scalapb-src.jar
  failed: (Exit 1): scalapb_worker failed:
  error executing ProtoScalaPBRule command
  (from target @@com_google_protobuf//src/google/protobuf:any_proto)
  bazel-out/darwin_arm64-opt-exec-ST-a828a81199fe/bin/src/scala/scripts/scalapb_worker
    ... (remaining 2 arguments skipped)
```

Here's why the other changes were necessary in light of the version
bumps:

- `java_proto_library` from `rules_java` is now officially deprecated,
  hence loading it from `com_google_protobuf`.

- The `rules_java` release notes suggest either loading
  `proto_bazel_features` from `@com_google_protobuf` or just calling
  `protobuf_deps()`. The key point is that the project must instantiate
  the `@proto_bazel_features` repo _before_ calling
  `rules_java_toolchains`. Hence, we've moved the
  `rules_java_toolchains()` call to follow `protobuf_deps()`.

- We're using Bazel 7.4.1 in order to upgrade `abseil-cpp` to 20240722.1
  and `protobuf` to v29.3. This is instead of keeping `.bazelversion` at
  6.5.0 and setting C++ compiler flags in `.bazelrc` as described in
  bazelbuild#1647.

- Setting `common --{,no}enable_{workspace,bzlmod}` fixes
  `test_semanticdb_handles_removed_sourcefiles`. This test relies on
  `bazel query`, which is also affected by these flags, hence `common`
  instead of `build`. Bazel 8 defaults to `--enable_bzlmod
  --noenable_workspace`, causing the `WORKSPACE` run of this test to
  fail.

- `glob` requires an explicit `allow_empty = True` parameter now that
  `--incompatible_disallow_empty_glob` defaults to `True` in Bazel 8.

- ScalaPB 0.9.8, the last version compatible with Scala 2.11, does not
  support `protobuf` >= 26.0. For this reason, we must remove the Scala
  2.11 test cases.

We should probably drop Scala 2.11 support at this point, since there's
no ScalaPB release that supports `protobuf` > v25.5.

Or perhaps we can at least document that `scala_proto` or any rules
otherwise depending on `protobuf` are no longer supported out of the
box. Such users will have to ensure they register their own downgraded
versions:

- `protobuf` <= v25.5
- `abseil-cpp` <= 20220623.1
- `rules_java` <= 7.12.4
- `rules_cc` <= 0.0.9
@mbland
Copy link
Contributor

mbland commented Jan 28, 2025

#1482 weekly update

All remains working in my bzlmod-bazel-8 branch as of today with Bazels 6.5.0, 7.4.1, 8.0.1, rolling, and last_green.

mbland added a commit to mbland/rules_scala that referenced this issue Jan 31, 2025
Bumps dependencies to versions that are compatible with both Bazel 7.5.0
and 8.0.0. Part of bazelbuild#1652.

- ScalaPB jars: 0.11.17 => 1.0.0-alpha.1
- `rules_python`: 0.38.0 => 1.1.0
- `rules_cc`: 0.0.9 => 0.0.17
- `abseil-cpp`: 20220623.1 => 20240722.1
- `rules_java`: 7.12.4 => 8.8.0
- `protobuf`: 21.7 => 29.3
- `rules_proto`: 6.0.2 => 7.1.0

rules_cc 0.1.0 exists, but we're using 0.0.17 per this advice from
https://github.com/bazelbuild/rules_cc/releases/tag/0.1.0:

> 0.1.x releases are not updated, please continue to use the latest
> 0.0.x release.

This precipitated the following updates also included in this commit:

- Loads `java_proto_library` from `com_google_protobuf`.
- Calls `java_repository()` after `protobuf_deps()` in `WORKSPACE`.
- Bumps `.bazelversion` to 7.5.0.
- Sets `common --{,no}enable_{workspace,bzlmod}`.
- Adds `allow_empty = True` to a `glob` expression in
  `//test/semanticdb:lib_with_tempsrc`.
- Removes Scala 2.11 test cases.

With this change:

- `WORKSPACE` builds succeed under Bazel 6.5.0, 7.5.0, and 8.0.0.
- Bzlmod builds succeed under Bazel 7.5.0 under 8.0.0.

Bazel 8 and `rules_java` 8 require `protobuf` >= v29. Bazel 6 Bzlmod
builds aren't supported because it doesn't provide `use_repo_rule`,
which is required by `rules_jvm_external` 6.3, which is required by
`protobuf` v29.

After the `protobuf` v29 bump, and before the ScalaPB 1.0.0-alpha.1
bump, `scala_proto` targets would fail with the following error:

```txt
ERROR: .../external/com_google_protobuf/src/google/protobuf/BUILD.bazel:23:14:
  ProtoScalaPBRule external/com_google_protobuf/src/google/protobuf/any_proto_jvm_extra_protobuf_generator_scalapb.srcjar
  failed: (Exit 1): scalapb_worker failed:
  error executing ProtoScalaPBRule command
  (from target @@com_google_protobuf//src/google/protobuf:any_proto)
  bazel-out/.../bin/src/scala/scripts/scalapb_worker
    ... (remaining 2 arguments skipped)

--jvm_extra_protobuf_generator_out:
  java.lang.NoSuchMethodError:
  'java.lang.Object com.google.protobuf.DescriptorProtos$FieldOptions.getExtension(com.google.protobuf.GeneratedMessage$GeneratedExtension)'
    at scalapb.compiler.DescriptorImplicits$ExtendedFieldDescriptor.fieldOptions(DescriptorImplicits.scala:329)
    at scalapb.compiler.DescriptorImplicits$ExtendedFieldDescriptor.scalaName(DescriptorImplicits.scala:207)
    at scalapb.compiler.ProtoValidation.validateField(ProtoValidation.scala:121)
    at scalapb.compiler.ProtoValidation.$anonfun$validateMessage$3(ProtoValidation.scala:56)
    at scalapb.compiler.ProtoValidation.$anonfun$validateMessage$3$adapted(ProtoValidation.scala:56)
    at scala.collection.Iterator.foreach(Iterator.scala:943)
    at scala.collection.Iterator.foreach$(Iterator.scala:943)
    at scala.collection.AbstractIterator.foreach(Iterator.scala:1431)
    at scala.collection.IterableLike.foreach(IterableLike.scala:74)
    at scala.collection.IterableLike.foreach$(IterableLike.scala:73)
    at scala.collection.AbstractIterable.foreach(Iterable.scala:56)
    at scalapb.compiler.ProtoValidation.validateMessage(ProtoValidation.scala:56)
    at scalapb.compiler.ProtoValidation.$anonfun$validateFile$2(ProtoValidation.scala:17)
    at scalapb.compiler.ProtoValidation.$anonfun$validateFile$2$adapted(ProtoValidation.scala:17)
    at scala.collection.Iterator.foreach(Iterator.scala:943)
    at scala.collection.Iterator.foreach$(Iterator.scala:943)
    at scala.collection.AbstractIterator.foreach(Iterator.scala:1431)
    at scala.collection.IterableLike.foreach(IterableLike.scala:74)
    at scala.collection.IterableLike.foreach$(IterableLike.scala:73)
    at scala.collection.AbstractIterable.foreach(Iterable.scala:56)
    at scalapb.compiler.ProtoValidation.validateFile(ProtoValidation.scala:17)
    at scalapb.compiler.ProtoValidation.$anonfun$validateFiles$1(ProtoValidation.scala:10)
    at scalapb.compiler.ProtoValidation.$anonfun$validateFiles$1$adapted(ProtoValidation.scala:10)
    at scala.collection.immutable.Stream.foreach(Stream.scala:533)
    at scalapb.compiler.ProtoValidation.validateFiles(ProtoValidation.scala:10)
    at scalarules.test.extra_protobuf_generator.ExtraProtobufGenerator$.handleCodeGeneratorRequest(ExtraProtobufGenerator.scala:86)
    at scalarules.test.extra_protobuf_generator.ExtraProtobufGenerator$.run(ExtraProtobufGenerator.scala:55)
    at protocbridge.frontend.PluginFrontend$.$anonfun$runWithBytes$1(PluginFrontend.scala:51)
    at scala.util.Try$.apply(Try.scala:213)
    at protocbridge.frontend.PluginFrontend$.runWithBytes(PluginFrontend.scala:51)
    at protocbridge.frontend.PluginFrontend$.runWithInputStream(PluginFrontend.scala:121)
    at protocbridge.frontend.PosixPluginFrontend$.$anonfun$prepare$2(PosixPluginFrontend.scala:40)
    at scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:23)
    at scala.concurrent.impl.ExecutionContextImpl$DefaultThreadFactory$$anon$1$$anon$2.block(ExecutionContextImpl.scala:75)
    at java.base/java.util.concurrent.ForkJoinPool.managedBlock(ForkJoinPool.java:3118)
    at scala.concurrent.impl.ExecutionContextImpl$DefaultThreadFactory$$anon$1.blockOn(ExecutionContextImpl.scala:87)
    at scala.concurrent.package$.blocking(package.scala:146)
    at protocbridge.frontend.PosixPluginFrontend$.$anonfun$prepare$1(PosixPluginFrontend.scala:38)
    at scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:23)
    at scala.concurrent.Future$.$anonfun$apply$1(Future.scala:659)
    at scala.util.Success.$anonfun$map$1(Try.scala:255)
    at scala.util.Success.map(Try.scala:213)
    at scala.concurrent.Future.$anonfun$map$1(Future.scala:292)
    at scala.concurrent.impl.Promise.$anonfun$transform$1(Promise.scala:42)
    at scala.concurrent.impl.CallbackRunnable.run(Promise.scala:74)
    at java.base/java.util.concurrent.ForkJoinTask$RunnableExecuteAction.exec(ForkJoinTask.java:1426)
    at java.base/java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:290)
    at java.base/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1020)
    at java.base/java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:1656)
    at java.base/java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1594)
    at java.base/java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:183)

java.lang.RuntimeException: Exit with code 1
    at scala.sys.package$.error(package.scala:30)
    at scripts.ScalaPBWorker$.work(ScalaPBWorker.scala:44)
    at io.bazel.rulesscala.worker.Worker.persistentWorkerMain(Worker.java:96)
    at io.bazel.rulesscala.worker.Worker.workerMain(Worker.java:49)
    at scripts.ScalaPBWorker$.main(ScalaPBWorker.scala:39)
    at scripts.ScalaPBWorker.main(ScalaPBWorker.scala)

ERROR: .../external/com_google_protobuf/src/google/protobuf/BUILD.bazel:23:14
  Building source jar external/com_google_protobuf/src/google/protobuf/any_proto_scalapb-src.jar
  failed: (Exit 1): scalapb_worker failed:
  error executing ProtoScalaPBRule command
  (from target @@com_google_protobuf//src/google/protobuf:any_proto)
  bazel-out/darwin_arm64-opt-exec-ST-a828a81199fe/bin/src/scala/scripts/scalapb_worker
    ... (remaining 2 arguments skipped)
```

Here's why the other changes were necessary in light of the version
bumps:

- `java_proto_library` from `rules_java` is now officially deprecated,
  hence loading it from `com_google_protobuf`.

- The `rules_java` release notes suggest either loading
  `proto_bazel_features` from `@com_google_protobuf` or just calling
  `protobuf_deps()`. The key point is that the project must instantiate
  the `@proto_bazel_features` repo _before_ calling
  `rules_java_toolchains`. Hence, we've moved the
  `rules_java_toolchains()` call to follow `protobuf_deps()`.

- We're using Bazel 7.5.0 in order to upgrade `abseil-cpp` to 20240722.1
  and `protobuf` to v29.3. This is instead of keeping `.bazelversion` at
  6.5.0 and setting C++ compiler flags in `.bazelrc` as described in
  bazelbuild#1647.

- Setting `common --{,no}enable_{workspace,bzlmod}` fixes
  `test_semanticdb_handles_removed_sourcefiles`. This test relies on
  `bazel query`, which is also affected by these flags, hence `common`
  instead of `build`. Bazel 8 defaults to `--enable_bzlmod
  --noenable_workspace`, causing the `WORKSPACE` run of this test to
  fail.

- `glob` requires an explicit `allow_empty = True` parameter now that
  `--incompatible_disallow_empty_glob` defaults to `True` in Bazel 8.

- ScalaPB 0.9.8, the last version compatible with Scala 2.11, does not
  support `protobuf` >= 26.0. For this reason, we must remove the Scala
  2.11 test cases.

We should probably drop Scala 2.11 support at this point, since there's
no ScalaPB release that supports `protobuf` > v25.5.

Or perhaps we can at least document that `scala_proto` or any rules
otherwise depending on `protobuf` are no longer supported out of the
box. Such users will have to ensure they register their own downgraded
versions:

- `protobuf` <= v25.5
- `abseil-cpp` <= 20220623.1
- `rules_java` <= 7.12.4
- `rules_cc` <= 0.0.9
mbland added a commit to mbland/rules_scala that referenced this issue Feb 3, 2025
Adds the jmh toolchain to `scala_toolchains()` and moves
`jmh_repositories()` to `jmh/toolchain/toolchain.bzl` for `rules_java` 8
compatibility. Part of bazelbuild#1482 and bazelbuild#1652.
mbland added a commit to mbland/rules_scala that referenced this issue Feb 3, 2025
This is the last of the toolchain to receive the "toolchainization"
treatment prior to Bzlmodification, and moves `twitter_scrooge()` to
`twitter_scrooge/toolchain/toolchain.bzl` for `rules_java` 8
compatibility. Part of bazelbuild#1482 and bazelbuild#1652.
mbland added a commit to mbland/rules_scala that referenced this issue Feb 3, 2025
Bumps dependencies to versions that are compatible with both Bazel 7.5.0
and 8.0.0. Part of bazelbuild#1652.

- ScalaPB jars: 0.11.17 => 1.0.0-alpha.1
- `rules_python`: 0.38.0 => 1.1.0
- `rules_cc`: 0.0.9 => 0.0.17
- `abseil-cpp`: 20220623.1 => 20240722.1
- `rules_java`: 7.12.4 => 8.8.0
- `protobuf`: 21.7 => 29.3
- `rules_proto`: 6.0.2 => 7.1.0

rules_cc 0.1.0 exists, but we're using 0.0.17 per this advice from
https://github.com/bazelbuild/rules_cc/releases/tag/0.1.0:

> 0.1.x releases are not updated, please continue to use the latest
> 0.0.x release.

This precipitated the following updates also included in this commit:

- Loads `java_proto_library` from `com_google_protobuf`.
- Calls `java_repository()` after `protobuf_deps()` in `WORKSPACE`.
- Bumps `.bazelversion` to 7.5.0.
- Sets `common --{,no}enable_{workspace,bzlmod}`.
- Adds `allow_empty = True` to a `glob` expression in
  `//test/semanticdb:lib_with_tempsrc`.
- Removes Scala 2.11 test cases.

With this change:

- `WORKSPACE` builds succeed under Bazel 6.5.0, 7.5.0, and 8.0.0.
- Bzlmod builds succeed under Bazel 7.5.0 under 8.0.0.

Bazel 8 and `rules_java` 8 require `protobuf` >= v29. Bazel 6 Bzlmod
builds aren't supported because it doesn't provide `use_repo_rule`,
which is required by `rules_jvm_external` 6.3, which is required by
`protobuf` v29.

After the `protobuf` v29 bump, and before the ScalaPB 1.0.0-alpha.1
bump, `scala_proto` targets would fail with the following error:

```txt
ERROR: .../external/com_google_protobuf/src/google/protobuf/BUILD.bazel:23:14:
  ProtoScalaPBRule external/com_google_protobuf/src/google/protobuf/any_proto_jvm_extra_protobuf_generator_scalapb.srcjar
  failed: (Exit 1): scalapb_worker failed:
  error executing ProtoScalaPBRule command
  (from target @@com_google_protobuf//src/google/protobuf:any_proto)
  bazel-out/.../bin/src/scala/scripts/scalapb_worker
    ... (remaining 2 arguments skipped)

--jvm_extra_protobuf_generator_out:
  java.lang.NoSuchMethodError:
  'java.lang.Object com.google.protobuf.DescriptorProtos$FieldOptions.getExtension(com.google.protobuf.GeneratedMessage$GeneratedExtension)'
    at scalapb.compiler.DescriptorImplicits$ExtendedFieldDescriptor.fieldOptions(DescriptorImplicits.scala:329)
    at scalapb.compiler.DescriptorImplicits$ExtendedFieldDescriptor.scalaName(DescriptorImplicits.scala:207)
    at scalapb.compiler.ProtoValidation.validateField(ProtoValidation.scala:121)
    at scalapb.compiler.ProtoValidation.$anonfun$validateMessage$3(ProtoValidation.scala:56)
    at scalapb.compiler.ProtoValidation.$anonfun$validateMessage$3$adapted(ProtoValidation.scala:56)
    at scala.collection.Iterator.foreach(Iterator.scala:943)
    at scala.collection.Iterator.foreach$(Iterator.scala:943)
    at scala.collection.AbstractIterator.foreach(Iterator.scala:1431)
    at scala.collection.IterableLike.foreach(IterableLike.scala:74)
    at scala.collection.IterableLike.foreach$(IterableLike.scala:73)
    at scala.collection.AbstractIterable.foreach(Iterable.scala:56)
    at scalapb.compiler.ProtoValidation.validateMessage(ProtoValidation.scala:56)
    at scalapb.compiler.ProtoValidation.$anonfun$validateFile$2(ProtoValidation.scala:17)
    at scalapb.compiler.ProtoValidation.$anonfun$validateFile$2$adapted(ProtoValidation.scala:17)
    at scala.collection.Iterator.foreach(Iterator.scala:943)
    at scala.collection.Iterator.foreach$(Iterator.scala:943)
    at scala.collection.AbstractIterator.foreach(Iterator.scala:1431)
    at scala.collection.IterableLike.foreach(IterableLike.scala:74)
    at scala.collection.IterableLike.foreach$(IterableLike.scala:73)
    at scala.collection.AbstractIterable.foreach(Iterable.scala:56)
    at scalapb.compiler.ProtoValidation.validateFile(ProtoValidation.scala:17)
    at scalapb.compiler.ProtoValidation.$anonfun$validateFiles$1(ProtoValidation.scala:10)
    at scalapb.compiler.ProtoValidation.$anonfun$validateFiles$1$adapted(ProtoValidation.scala:10)
    at scala.collection.immutable.Stream.foreach(Stream.scala:533)
    at scalapb.compiler.ProtoValidation.validateFiles(ProtoValidation.scala:10)
    at scalarules.test.extra_protobuf_generator.ExtraProtobufGenerator$.handleCodeGeneratorRequest(ExtraProtobufGenerator.scala:86)
    at scalarules.test.extra_protobuf_generator.ExtraProtobufGenerator$.run(ExtraProtobufGenerator.scala:55)
    at protocbridge.frontend.PluginFrontend$.$anonfun$runWithBytes$1(PluginFrontend.scala:51)
    at scala.util.Try$.apply(Try.scala:213)
    at protocbridge.frontend.PluginFrontend$.runWithBytes(PluginFrontend.scala:51)
    at protocbridge.frontend.PluginFrontend$.runWithInputStream(PluginFrontend.scala:121)
    at protocbridge.frontend.PosixPluginFrontend$.$anonfun$prepare$2(PosixPluginFrontend.scala:40)
    at scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:23)
    at scala.concurrent.impl.ExecutionContextImpl$DefaultThreadFactory$$anon$1$$anon$2.block(ExecutionContextImpl.scala:75)
    at java.base/java.util.concurrent.ForkJoinPool.managedBlock(ForkJoinPool.java:3118)
    at scala.concurrent.impl.ExecutionContextImpl$DefaultThreadFactory$$anon$1.blockOn(ExecutionContextImpl.scala:87)
    at scala.concurrent.package$.blocking(package.scala:146)
    at protocbridge.frontend.PosixPluginFrontend$.$anonfun$prepare$1(PosixPluginFrontend.scala:38)
    at scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:23)
    at scala.concurrent.Future$.$anonfun$apply$1(Future.scala:659)
    at scala.util.Success.$anonfun$map$1(Try.scala:255)
    at scala.util.Success.map(Try.scala:213)
    at scala.concurrent.Future.$anonfun$map$1(Future.scala:292)
    at scala.concurrent.impl.Promise.$anonfun$transform$1(Promise.scala:42)
    at scala.concurrent.impl.CallbackRunnable.run(Promise.scala:74)
    at java.base/java.util.concurrent.ForkJoinTask$RunnableExecuteAction.exec(ForkJoinTask.java:1426)
    at java.base/java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:290)
    at java.base/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1020)
    at java.base/java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:1656)
    at java.base/java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1594)
    at java.base/java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:183)

java.lang.RuntimeException: Exit with code 1
    at scala.sys.package$.error(package.scala:30)
    at scripts.ScalaPBWorker$.work(ScalaPBWorker.scala:44)
    at io.bazel.rulesscala.worker.Worker.persistentWorkerMain(Worker.java:96)
    at io.bazel.rulesscala.worker.Worker.workerMain(Worker.java:49)
    at scripts.ScalaPBWorker$.main(ScalaPBWorker.scala:39)
    at scripts.ScalaPBWorker.main(ScalaPBWorker.scala)

ERROR: .../external/com_google_protobuf/src/google/protobuf/BUILD.bazel:23:14
  Building source jar external/com_google_protobuf/src/google/protobuf/any_proto_scalapb-src.jar
  failed: (Exit 1): scalapb_worker failed:
  error executing ProtoScalaPBRule command
  (from target @@com_google_protobuf//src/google/protobuf:any_proto)
  bazel-out/darwin_arm64-opt-exec-ST-a828a81199fe/bin/src/scala/scripts/scalapb_worker
    ... (remaining 2 arguments skipped)
```

Here's why the other changes were necessary in light of the version
bumps:

- `java_proto_library` from `rules_java` is now officially deprecated,
  hence loading it from `com_google_protobuf`.

- The `rules_java` release notes suggest either loading
  `proto_bazel_features` from `@com_google_protobuf` or just calling
  `protobuf_deps()`. The key point is that the project must instantiate
  the `@proto_bazel_features` repo _before_ calling
  `rules_java_toolchains`. Hence, we've moved the
  `rules_java_toolchains()` call to follow `protobuf_deps()`.

- We're using Bazel 7.5.0 in order to upgrade `abseil-cpp` to 20240722.1
  and `protobuf` to v29.3. This is instead of keeping `.bazelversion` at
  6.5.0 and setting C++ compiler flags in `.bazelrc` as described in
  bazelbuild#1647.

- Setting `common --{,no}enable_{workspace,bzlmod}` fixes
  `test_semanticdb_handles_removed_sourcefiles`. This test relies on
  `bazel query`, which is also affected by these flags, hence `common`
  instead of `build`. Bazel 8 defaults to `--enable_bzlmod
  --noenable_workspace`, causing the `WORKSPACE` run of this test to
  fail.

- `glob` requires an explicit `allow_empty = True` parameter now that
  `--incompatible_disallow_empty_glob` defaults to `True` in Bazel 8.

- ScalaPB 0.9.8, the last version compatible with Scala 2.11, does not
  support `protobuf` >= 26.0. For this reason, we must remove the Scala
  2.11 test cases.

We should probably drop Scala 2.11 support at this point, since there's
no ScalaPB release that supports `protobuf` > v25.5.

Or perhaps we can at least document that `scala_proto` or any rules
otherwise depending on `protobuf` are no longer supported out of the
box. Such users will have to ensure they register their own downgraded
versions:

- `protobuf` <= v25.5
- `abseil-cpp` <= 20220623.1
- `rules_java` <= 7.12.4
- `rules_cc` <= 0.0.9
mbland added a commit to mbland/rules_scala that referenced this issue Feb 3, 2025
Bumps dependencies to versions that are compatible with both Bazel 7.5.0
and 8.0.0. Part of bazelbuild#1652.

- ScalaPB jars: 0.11.17 => 1.0.0-alpha.1
- `rules_python`: 0.38.0 => 1.1.0
- `rules_cc`: 0.0.9 => 0.0.17
- `abseil-cpp`: 20220623.1 => 20240722.1
- `rules_java`: 7.12.4 => 8.8.0
- `protobuf`: 21.7 => 29.3
- `rules_proto`: 6.0.2 => 7.1.0

rules_cc 0.1.0 exists, but we're using 0.0.17 per this advice from
https://github.com/bazelbuild/rules_cc/releases/tag/0.1.0:

> 0.1.x releases are not updated, please continue to use the latest
> 0.0.x release.

This precipitated the following updates also included in this commit:

- Loads `java_proto_library` from `com_google_protobuf`.
- Calls `java_repository()` after `protobuf_deps()` in `WORKSPACE`.
- Bumps `.bazelversion` to 7.5.0.
- Sets `common --{,no}enable_{workspace,bzlmod}`.
- Adds `allow_empty = True` to a `glob` expression in
  `//test/semanticdb:lib_with_tempsrc`.
- Removes Scala 2.11 test cases.

With this change:

- `WORKSPACE` builds succeed under Bazel 6.5.0, 7.5.0, and 8.0.0.
- Bzlmod builds succeed under Bazel 7.5.0 under 8.0.0.

Bazel 8 and `rules_java` 8 require `protobuf` >= v29. Bazel 6 Bzlmod
builds aren't supported because it doesn't provide `use_repo_rule`,
which is required by `rules_jvm_external` 6.3, which is required by
`protobuf` v29.

After the `protobuf` v29 bump, and before the ScalaPB 1.0.0-alpha.1
bump, `scala_proto` targets would fail with the following error:

```txt
ERROR: .../external/com_google_protobuf/src/google/protobuf/BUILD.bazel:23:14:
  ProtoScalaPBRule external/com_google_protobuf/src/google/protobuf/any_proto_jvm_extra_protobuf_generator_scalapb.srcjar
  failed: (Exit 1): scalapb_worker failed:
  error executing ProtoScalaPBRule command
  (from target @@com_google_protobuf//src/google/protobuf:any_proto)
  bazel-out/.../bin/src/scala/scripts/scalapb_worker
    ... (remaining 2 arguments skipped)

--jvm_extra_protobuf_generator_out:
  java.lang.NoSuchMethodError:
  'java.lang.Object com.google.protobuf.DescriptorProtos$FieldOptions.getExtension(com.google.protobuf.GeneratedMessage$GeneratedExtension)'
    at scalapb.compiler.DescriptorImplicits$ExtendedFieldDescriptor.fieldOptions(DescriptorImplicits.scala:329)
    at scalapb.compiler.DescriptorImplicits$ExtendedFieldDescriptor.scalaName(DescriptorImplicits.scala:207)
    at scalapb.compiler.ProtoValidation.validateField(ProtoValidation.scala:121)
    at scalapb.compiler.ProtoValidation.$anonfun$validateMessage$3(ProtoValidation.scala:56)
    at scalapb.compiler.ProtoValidation.$anonfun$validateMessage$3$adapted(ProtoValidation.scala:56)
    at scala.collection.Iterator.foreach(Iterator.scala:943)
    at scala.collection.Iterator.foreach$(Iterator.scala:943)
    at scala.collection.AbstractIterator.foreach(Iterator.scala:1431)
    at scala.collection.IterableLike.foreach(IterableLike.scala:74)
    at scala.collection.IterableLike.foreach$(IterableLike.scala:73)
    at scala.collection.AbstractIterable.foreach(Iterable.scala:56)
    at scalapb.compiler.ProtoValidation.validateMessage(ProtoValidation.scala:56)
    at scalapb.compiler.ProtoValidation.$anonfun$validateFile$2(ProtoValidation.scala:17)
    at scalapb.compiler.ProtoValidation.$anonfun$validateFile$2$adapted(ProtoValidation.scala:17)
    at scala.collection.Iterator.foreach(Iterator.scala:943)
    at scala.collection.Iterator.foreach$(Iterator.scala:943)
    at scala.collection.AbstractIterator.foreach(Iterator.scala:1431)
    at scala.collection.IterableLike.foreach(IterableLike.scala:74)
    at scala.collection.IterableLike.foreach$(IterableLike.scala:73)
    at scala.collection.AbstractIterable.foreach(Iterable.scala:56)
    at scalapb.compiler.ProtoValidation.validateFile(ProtoValidation.scala:17)
    at scalapb.compiler.ProtoValidation.$anonfun$validateFiles$1(ProtoValidation.scala:10)
    at scalapb.compiler.ProtoValidation.$anonfun$validateFiles$1$adapted(ProtoValidation.scala:10)
    at scala.collection.immutable.Stream.foreach(Stream.scala:533)
    at scalapb.compiler.ProtoValidation.validateFiles(ProtoValidation.scala:10)
    at scalarules.test.extra_protobuf_generator.ExtraProtobufGenerator$.handleCodeGeneratorRequest(ExtraProtobufGenerator.scala:86)
    at scalarules.test.extra_protobuf_generator.ExtraProtobufGenerator$.run(ExtraProtobufGenerator.scala:55)
    at protocbridge.frontend.PluginFrontend$.$anonfun$runWithBytes$1(PluginFrontend.scala:51)
    at scala.util.Try$.apply(Try.scala:213)
    at protocbridge.frontend.PluginFrontend$.runWithBytes(PluginFrontend.scala:51)
    at protocbridge.frontend.PluginFrontend$.runWithInputStream(PluginFrontend.scala:121)
    at protocbridge.frontend.PosixPluginFrontend$.$anonfun$prepare$2(PosixPluginFrontend.scala:40)
    at scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:23)
    at scala.concurrent.impl.ExecutionContextImpl$DefaultThreadFactory$$anon$1$$anon$2.block(ExecutionContextImpl.scala:75)
    at java.base/java.util.concurrent.ForkJoinPool.managedBlock(ForkJoinPool.java:3118)
    at scala.concurrent.impl.ExecutionContextImpl$DefaultThreadFactory$$anon$1.blockOn(ExecutionContextImpl.scala:87)
    at scala.concurrent.package$.blocking(package.scala:146)
    at protocbridge.frontend.PosixPluginFrontend$.$anonfun$prepare$1(PosixPluginFrontend.scala:38)
    at scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:23)
    at scala.concurrent.Future$.$anonfun$apply$1(Future.scala:659)
    at scala.util.Success.$anonfun$map$1(Try.scala:255)
    at scala.util.Success.map(Try.scala:213)
    at scala.concurrent.Future.$anonfun$map$1(Future.scala:292)
    at scala.concurrent.impl.Promise.$anonfun$transform$1(Promise.scala:42)
    at scala.concurrent.impl.CallbackRunnable.run(Promise.scala:74)
    at java.base/java.util.concurrent.ForkJoinTask$RunnableExecuteAction.exec(ForkJoinTask.java:1426)
    at java.base/java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:290)
    at java.base/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1020)
    at java.base/java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:1656)
    at java.base/java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1594)
    at java.base/java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:183)

java.lang.RuntimeException: Exit with code 1
    at scala.sys.package$.error(package.scala:30)
    at scripts.ScalaPBWorker$.work(ScalaPBWorker.scala:44)
    at io.bazel.rulesscala.worker.Worker.persistentWorkerMain(Worker.java:96)
    at io.bazel.rulesscala.worker.Worker.workerMain(Worker.java:49)
    at scripts.ScalaPBWorker$.main(ScalaPBWorker.scala:39)
    at scripts.ScalaPBWorker.main(ScalaPBWorker.scala)

ERROR: .../external/com_google_protobuf/src/google/protobuf/BUILD.bazel:23:14
  Building source jar external/com_google_protobuf/src/google/protobuf/any_proto_scalapb-src.jar
  failed: (Exit 1): scalapb_worker failed:
  error executing ProtoScalaPBRule command
  (from target @@com_google_protobuf//src/google/protobuf:any_proto)
  bazel-out/darwin_arm64-opt-exec-ST-a828a81199fe/bin/src/scala/scripts/scalapb_worker
    ... (remaining 2 arguments skipped)
```

Here's why the other changes were necessary in light of the version
bumps:

- `java_proto_library` from `rules_java` is now officially deprecated,
  hence loading it from `com_google_protobuf`.

- The `rules_java` release notes suggest either loading
  `proto_bazel_features` from `@com_google_protobuf` or just calling
  `protobuf_deps()`. The key point is that the project must instantiate
  the `@proto_bazel_features` repo _before_ calling
  `rules_java_toolchains`. Hence, we've moved the
  `rules_java_toolchains()` call to follow `protobuf_deps()`.

- We're using Bazel 7.5.0 in order to upgrade `abseil-cpp` to 20240722.1
  and `protobuf` to v29.3. This is instead of keeping `.bazelversion` at
  6.5.0 and setting C++ compiler flags in `.bazelrc` as described in
  bazelbuild#1647.

- Setting `common --{,no}enable_{workspace,bzlmod}` fixes
  `test_semanticdb_handles_removed_sourcefiles`. This test relies on
  `bazel query`, which is also affected by these flags, hence `common`
  instead of `build`. Bazel 8 defaults to `--enable_bzlmod
  --noenable_workspace`, causing the `WORKSPACE` run of this test to
  fail.

- `glob` requires an explicit `allow_empty = True` parameter now that
  `--incompatible_disallow_empty_glob` defaults to `True` in Bazel 8.

- ScalaPB 0.9.8, the last version compatible with Scala 2.11, does not
  support `protobuf` >= 26.0. For this reason, we must remove the Scala
  2.11 test cases.

We should probably drop Scala 2.11 support at this point, since there's
no ScalaPB release that supports `protobuf` > v25.5.

Or perhaps we can at least document that `scala_proto` or any rules
otherwise depending on `protobuf` are no longer supported out of the
box. Such users will have to ensure they register their own downgraded
versions:

- `protobuf` <= v25.5
- `abseil-cpp` <= 20220623.1
- `rules_java` <= 7.12.4
- `rules_cc` <= 0.0.9
mbland added a commit to mbland/rules_scala that referenced this issue Feb 5, 2025
Adds the jmh toolchain to `scala_toolchains()` and moves
`jmh_repositories()` to `jmh/toolchain/toolchain.bzl` for `rules_java` 8
compatibility. Part of bazelbuild#1482 and bazelbuild#1652.
mbland added a commit to mbland/rules_scala that referenced this issue Feb 5, 2025
This is the last of the toolchain to receive the "toolchainization"
treatment prior to Bzlmodification, and moves `twitter_scrooge()` to
`twitter_scrooge/toolchain/toolchain.bzl` for `rules_java` 8
compatibility. Part of bazelbuild#1482 and bazelbuild#1652.
mbland added a commit to mbland/rules_scala that referenced this issue Feb 5, 2025
Bumps dependencies to versions that are compatible with both Bazel 7.5.0
and 8.0.0. Part of bazelbuild#1652.

- ScalaPB jars: 0.11.17 => 1.0.0-alpha.1
- `rules_python`: 0.38.0 => 1.1.0
- `rules_cc`: 0.0.9 => 0.0.17
- `abseil-cpp`: 20220623.1 => 20240722.1
- `rules_java`: 7.12.4 => 8.8.0
- `protobuf`: 21.7 => 29.3
- `rules_proto`: 6.0.2 => 7.1.0

rules_cc 0.1.0 exists, but we're using 0.0.17 per this advice from
https://github.com/bazelbuild/rules_cc/releases/tag/0.1.0:

> 0.1.x releases are not updated, please continue to use the latest
> 0.0.x release.

This precipitated the following updates also included in this commit:

- Loads `java_proto_library` from `com_google_protobuf`.
- Calls `java_repository()` after `protobuf_deps()` in `WORKSPACE`.
- Bumps `.bazelversion` to 7.5.0.
- Sets `common --{,no}enable_{workspace,bzlmod}`.
- Adds `allow_empty = True` to a `glob` expression in
  `//test/semanticdb:lib_with_tempsrc`.
- Removes Scala 2.11 test cases.

With this change:

- `WORKSPACE` builds succeed under Bazel 6.5.0, 7.5.0, and 8.0.0.
- Bzlmod builds succeed under Bazel 7.5.0 under 8.0.0.

Bazel 8 and `rules_java` 8 require `protobuf` >= v29. Bazel 6 Bzlmod
builds aren't supported because it doesn't provide `use_repo_rule`,
which is required by `rules_jvm_external` 6.3, which is required by
`protobuf` v29.

After the `protobuf` v29 bump, and before the ScalaPB 1.0.0-alpha.1
bump, `scala_proto` targets would fail with the following error:

```txt
ERROR: .../external/com_google_protobuf/src/google/protobuf/BUILD.bazel:23:14:
  ProtoScalaPBRule external/com_google_protobuf/src/google/protobuf/any_proto_jvm_extra_protobuf_generator_scalapb.srcjar
  failed: (Exit 1): scalapb_worker failed:
  error executing ProtoScalaPBRule command
  (from target @@com_google_protobuf//src/google/protobuf:any_proto)
  bazel-out/.../bin/src/scala/scripts/scalapb_worker
    ... (remaining 2 arguments skipped)

--jvm_extra_protobuf_generator_out:
  java.lang.NoSuchMethodError:
  'java.lang.Object com.google.protobuf.DescriptorProtos$FieldOptions.getExtension(com.google.protobuf.GeneratedMessage$GeneratedExtension)'
    at scalapb.compiler.DescriptorImplicits$ExtendedFieldDescriptor.fieldOptions(DescriptorImplicits.scala:329)
    at scalapb.compiler.DescriptorImplicits$ExtendedFieldDescriptor.scalaName(DescriptorImplicits.scala:207)
    at scalapb.compiler.ProtoValidation.validateField(ProtoValidation.scala:121)
    at scalapb.compiler.ProtoValidation.$anonfun$validateMessage$3(ProtoValidation.scala:56)
    at scalapb.compiler.ProtoValidation.$anonfun$validateMessage$3$adapted(ProtoValidation.scala:56)
    at scala.collection.Iterator.foreach(Iterator.scala:943)
    at scala.collection.Iterator.foreach$(Iterator.scala:943)
    at scala.collection.AbstractIterator.foreach(Iterator.scala:1431)
    at scala.collection.IterableLike.foreach(IterableLike.scala:74)
    at scala.collection.IterableLike.foreach$(IterableLike.scala:73)
    at scala.collection.AbstractIterable.foreach(Iterable.scala:56)
    at scalapb.compiler.ProtoValidation.validateMessage(ProtoValidation.scala:56)
    at scalapb.compiler.ProtoValidation.$anonfun$validateFile$2(ProtoValidation.scala:17)
    at scalapb.compiler.ProtoValidation.$anonfun$validateFile$2$adapted(ProtoValidation.scala:17)
    at scala.collection.Iterator.foreach(Iterator.scala:943)
    at scala.collection.Iterator.foreach$(Iterator.scala:943)
    at scala.collection.AbstractIterator.foreach(Iterator.scala:1431)
    at scala.collection.IterableLike.foreach(IterableLike.scala:74)
    at scala.collection.IterableLike.foreach$(IterableLike.scala:73)
    at scala.collection.AbstractIterable.foreach(Iterable.scala:56)
    at scalapb.compiler.ProtoValidation.validateFile(ProtoValidation.scala:17)
    at scalapb.compiler.ProtoValidation.$anonfun$validateFiles$1(ProtoValidation.scala:10)
    at scalapb.compiler.ProtoValidation.$anonfun$validateFiles$1$adapted(ProtoValidation.scala:10)
    at scala.collection.immutable.Stream.foreach(Stream.scala:533)
    at scalapb.compiler.ProtoValidation.validateFiles(ProtoValidation.scala:10)
    at scalarules.test.extra_protobuf_generator.ExtraProtobufGenerator$.handleCodeGeneratorRequest(ExtraProtobufGenerator.scala:86)
    at scalarules.test.extra_protobuf_generator.ExtraProtobufGenerator$.run(ExtraProtobufGenerator.scala:55)
    at protocbridge.frontend.PluginFrontend$.$anonfun$runWithBytes$1(PluginFrontend.scala:51)
    at scala.util.Try$.apply(Try.scala:213)
    at protocbridge.frontend.PluginFrontend$.runWithBytes(PluginFrontend.scala:51)
    at protocbridge.frontend.PluginFrontend$.runWithInputStream(PluginFrontend.scala:121)
    at protocbridge.frontend.PosixPluginFrontend$.$anonfun$prepare$2(PosixPluginFrontend.scala:40)
    at scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:23)
    at scala.concurrent.impl.ExecutionContextImpl$DefaultThreadFactory$$anon$1$$anon$2.block(ExecutionContextImpl.scala:75)
    at java.base/java.util.concurrent.ForkJoinPool.managedBlock(ForkJoinPool.java:3118)
    at scala.concurrent.impl.ExecutionContextImpl$DefaultThreadFactory$$anon$1.blockOn(ExecutionContextImpl.scala:87)
    at scala.concurrent.package$.blocking(package.scala:146)
    at protocbridge.frontend.PosixPluginFrontend$.$anonfun$prepare$1(PosixPluginFrontend.scala:38)
    at scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:23)
    at scala.concurrent.Future$.$anonfun$apply$1(Future.scala:659)
    at scala.util.Success.$anonfun$map$1(Try.scala:255)
    at scala.util.Success.map(Try.scala:213)
    at scala.concurrent.Future.$anonfun$map$1(Future.scala:292)
    at scala.concurrent.impl.Promise.$anonfun$transform$1(Promise.scala:42)
    at scala.concurrent.impl.CallbackRunnable.run(Promise.scala:74)
    at java.base/java.util.concurrent.ForkJoinTask$RunnableExecuteAction.exec(ForkJoinTask.java:1426)
    at java.base/java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:290)
    at java.base/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1020)
    at java.base/java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:1656)
    at java.base/java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1594)
    at java.base/java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:183)

java.lang.RuntimeException: Exit with code 1
    at scala.sys.package$.error(package.scala:30)
    at scripts.ScalaPBWorker$.work(ScalaPBWorker.scala:44)
    at io.bazel.rulesscala.worker.Worker.persistentWorkerMain(Worker.java:96)
    at io.bazel.rulesscala.worker.Worker.workerMain(Worker.java:49)
    at scripts.ScalaPBWorker$.main(ScalaPBWorker.scala:39)
    at scripts.ScalaPBWorker.main(ScalaPBWorker.scala)

ERROR: .../external/com_google_protobuf/src/google/protobuf/BUILD.bazel:23:14
  Building source jar external/com_google_protobuf/src/google/protobuf/any_proto_scalapb-src.jar
  failed: (Exit 1): scalapb_worker failed:
  error executing ProtoScalaPBRule command
  (from target @@com_google_protobuf//src/google/protobuf:any_proto)
  bazel-out/darwin_arm64-opt-exec-ST-a828a81199fe/bin/src/scala/scripts/scalapb_worker
    ... (remaining 2 arguments skipped)
```

Here's why the other changes were necessary in light of the version
bumps:

- `java_proto_library` from `rules_java` is now officially deprecated,
  hence loading it from `com_google_protobuf`.

- The `rules_java` release notes suggest either loading
  `proto_bazel_features` from `@com_google_protobuf` or just calling
  `protobuf_deps()`. The key point is that the project must instantiate
  the `@proto_bazel_features` repo _before_ calling
  `rules_java_toolchains`. Hence, we've moved the
  `rules_java_toolchains()` call to follow `protobuf_deps()`.

- We're using Bazel 7.5.0 in order to upgrade `abseil-cpp` to 20240722.1
  and `protobuf` to v29.3. This is instead of keeping `.bazelversion` at
  6.5.0 and setting C++ compiler flags in `.bazelrc` as described in
  bazelbuild#1647.

- Setting `common --{,no}enable_{workspace,bzlmod}` fixes
  `test_semanticdb_handles_removed_sourcefiles`. This test relies on
  `bazel query`, which is also affected by these flags, hence `common`
  instead of `build`. Bazel 8 defaults to `--enable_bzlmod
  --noenable_workspace`, causing the `WORKSPACE` run of this test to
  fail.

- `glob` requires an explicit `allow_empty = True` parameter now that
  `--incompatible_disallow_empty_glob` defaults to `True` in Bazel 8.

- ScalaPB 0.9.8, the last version compatible with Scala 2.11, does not
  support `protobuf` >= 26.0. For this reason, we must remove the Scala
  2.11 test cases.

We should probably drop Scala 2.11 support at this point, since there's
no ScalaPB release that supports `protobuf` > v25.5.

Or perhaps we can at least document that `scala_proto` or any rules
otherwise depending on `protobuf` are no longer supported out of the
box. Such users will have to ensure they register their own downgraded
versions:

- `protobuf` <= v25.5
- `abseil-cpp` <= 20220623.1
- `rules_java` <= 7.12.4
- `rules_cc` <= 0.0.9
@mbland
Copy link
Contributor

mbland commented Feb 5, 2025

#1482 weekly update

I pushed updates to bzlmod-bazel-8 yesterday, but am in the process of updating, testing, and pushing it again today to pick up changes merged since.

I also filed two Bazel 8 related issues yesterday:

liucijus pushed a commit that referenced this issue Feb 6, 2025
Adds the jmh toolchain to `scala_toolchains()` and moves
`jmh_repositories()` to `jmh/toolchain/toolchain.bzl` for `rules_java` 8
compatibility. Part of #1482 and #1652.
mbland added a commit to mbland/rules_scala that referenced this issue Feb 6, 2025
This is the last of the toolchain to receive the "toolchainization"
treatment prior to Bzlmodification, and moves `twitter_scrooge()` to
`twitter_scrooge/toolchain/toolchain.bzl` for `rules_java` 8
compatibility. Part of bazelbuild#1482 and bazelbuild#1652.
mbland added a commit to mbland/rules_scala that referenced this issue Feb 6, 2025
Bumps dependencies to versions that are compatible with both Bazel 7.5.0
and 8.0.0. Part of bazelbuild#1652.

- ScalaPB jars: 0.11.17 => 1.0.0-alpha.1
- `rules_python`: 0.38.0 => 1.1.0
- `rules_cc`: 0.0.9 => 0.0.17
- `abseil-cpp`: 20220623.1 => 20250127.0
- `rules_java`: 7.12.4 => 8.8.0
- `protobuf`: 21.7 => 29.3
- `rules_proto`: 6.0.2 => 7.1.0

rules_cc 0.1.0 exists, but we're using 0.0.17 per this advice from
https://github.com/bazelbuild/rules_cc/releases/tag/0.1.0:

> 0.1.x releases are not updated, please continue to use the latest
> 0.0.x release.

This precipitated the following updates also included in this commit:

- Loads `java_proto_library` from `com_google_protobuf`.
- Calls `java_repository()` after `protobuf_deps()` in `WORKSPACE`.
- Bumps `.bazelversion` to 7.5.0.
- Sets `common --{,no}enable_{workspace,bzlmod}`.
- Adds `allow_empty = True` to a `glob` expression in
  `//test/semanticdb:lib_with_tempsrc`.
- Removes Scala 2.11 test cases.

With this change:

- `WORKSPACE` builds succeed under Bazel 6.5.0, 7.5.0, and 8.0.0.
- Bzlmod builds succeed under Bazel 7.5.0 under 8.0.0.

Bazel 8 and `rules_java` 8 require `protobuf` >= v29. Bazel 6 Bzlmod
builds aren't supported because it doesn't provide `use_repo_rule`,
which is required by `rules_jvm_external` 6.3, which is required by
`protobuf` v29.

After the `protobuf` v29 bump, and before the ScalaPB 1.0.0-alpha.1
bump, `scala_proto` targets would fail with the following error:

```txt
ERROR: .../external/com_google_protobuf/src/google/protobuf/BUILD.bazel:23:14:
  ProtoScalaPBRule external/com_google_protobuf/src/google/protobuf/any_proto_jvm_extra_protobuf_generator_scalapb.srcjar
  failed: (Exit 1): scalapb_worker failed:
  error executing ProtoScalaPBRule command
  (from target @@com_google_protobuf//src/google/protobuf:any_proto)
  bazel-out/.../bin/src/scala/scripts/scalapb_worker
    ... (remaining 2 arguments skipped)

--jvm_extra_protobuf_generator_out:
  java.lang.NoSuchMethodError:
  'java.lang.Object com.google.protobuf.DescriptorProtos$FieldOptions.getExtension(com.google.protobuf.GeneratedMessage$GeneratedExtension)'
    at scalapb.compiler.DescriptorImplicits$ExtendedFieldDescriptor.fieldOptions(DescriptorImplicits.scala:329)
    at scalapb.compiler.DescriptorImplicits$ExtendedFieldDescriptor.scalaName(DescriptorImplicits.scala:207)
    at scalapb.compiler.ProtoValidation.validateField(ProtoValidation.scala:121)
    at scalapb.compiler.ProtoValidation.$anonfun$validateMessage$3(ProtoValidation.scala:56)
    at scalapb.compiler.ProtoValidation.$anonfun$validateMessage$3$adapted(ProtoValidation.scala:56)
    at scala.collection.Iterator.foreach(Iterator.scala:943)
    at scala.collection.Iterator.foreach$(Iterator.scala:943)
    at scala.collection.AbstractIterator.foreach(Iterator.scala:1431)
    at scala.collection.IterableLike.foreach(IterableLike.scala:74)
    at scala.collection.IterableLike.foreach$(IterableLike.scala:73)
    at scala.collection.AbstractIterable.foreach(Iterable.scala:56)
    at scalapb.compiler.ProtoValidation.validateMessage(ProtoValidation.scala:56)
    at scalapb.compiler.ProtoValidation.$anonfun$validateFile$2(ProtoValidation.scala:17)
    at scalapb.compiler.ProtoValidation.$anonfun$validateFile$2$adapted(ProtoValidation.scala:17)
    at scala.collection.Iterator.foreach(Iterator.scala:943)
    at scala.collection.Iterator.foreach$(Iterator.scala:943)
    at scala.collection.AbstractIterator.foreach(Iterator.scala:1431)
    at scala.collection.IterableLike.foreach(IterableLike.scala:74)
    at scala.collection.IterableLike.foreach$(IterableLike.scala:73)
    at scala.collection.AbstractIterable.foreach(Iterable.scala:56)
    at scalapb.compiler.ProtoValidation.validateFile(ProtoValidation.scala:17)
    at scalapb.compiler.ProtoValidation.$anonfun$validateFiles$1(ProtoValidation.scala:10)
    at scalapb.compiler.ProtoValidation.$anonfun$validateFiles$1$adapted(ProtoValidation.scala:10)
    at scala.collection.immutable.Stream.foreach(Stream.scala:533)
    at scalapb.compiler.ProtoValidation.validateFiles(ProtoValidation.scala:10)
    at scalarules.test.extra_protobuf_generator.ExtraProtobufGenerator$.handleCodeGeneratorRequest(ExtraProtobufGenerator.scala:86)
    at scalarules.test.extra_protobuf_generator.ExtraProtobufGenerator$.run(ExtraProtobufGenerator.scala:55)
    at protocbridge.frontend.PluginFrontend$.$anonfun$runWithBytes$1(PluginFrontend.scala:51)
    at scala.util.Try$.apply(Try.scala:213)
    at protocbridge.frontend.PluginFrontend$.runWithBytes(PluginFrontend.scala:51)
    at protocbridge.frontend.PluginFrontend$.runWithInputStream(PluginFrontend.scala:121)
    at protocbridge.frontend.PosixPluginFrontend$.$anonfun$prepare$2(PosixPluginFrontend.scala:40)
    at scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:23)
    at scala.concurrent.impl.ExecutionContextImpl$DefaultThreadFactory$$anon$1$$anon$2.block(ExecutionContextImpl.scala:75)
    at java.base/java.util.concurrent.ForkJoinPool.managedBlock(ForkJoinPool.java:3118)
    at scala.concurrent.impl.ExecutionContextImpl$DefaultThreadFactory$$anon$1.blockOn(ExecutionContextImpl.scala:87)
    at scala.concurrent.package$.blocking(package.scala:146)
    at protocbridge.frontend.PosixPluginFrontend$.$anonfun$prepare$1(PosixPluginFrontend.scala:38)
    at scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:23)
    at scala.concurrent.Future$.$anonfun$apply$1(Future.scala:659)
    at scala.util.Success.$anonfun$map$1(Try.scala:255)
    at scala.util.Success.map(Try.scala:213)
    at scala.concurrent.Future.$anonfun$map$1(Future.scala:292)
    at scala.concurrent.impl.Promise.$anonfun$transform$1(Promise.scala:42)
    at scala.concurrent.impl.CallbackRunnable.run(Promise.scala:74)
    at java.base/java.util.concurrent.ForkJoinTask$RunnableExecuteAction.exec(ForkJoinTask.java:1426)
    at java.base/java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:290)
    at java.base/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1020)
    at java.base/java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:1656)
    at java.base/java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1594)
    at java.base/java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:183)

java.lang.RuntimeException: Exit with code 1
    at scala.sys.package$.error(package.scala:30)
    at scripts.ScalaPBWorker$.work(ScalaPBWorker.scala:44)
    at io.bazel.rulesscala.worker.Worker.persistentWorkerMain(Worker.java:96)
    at io.bazel.rulesscala.worker.Worker.workerMain(Worker.java:49)
    at scripts.ScalaPBWorker$.main(ScalaPBWorker.scala:39)
    at scripts.ScalaPBWorker.main(ScalaPBWorker.scala)

ERROR: .../external/com_google_protobuf/src/google/protobuf/BUILD.bazel:23:14
  Building source jar external/com_google_protobuf/src/google/protobuf/any_proto_scalapb-src.jar
  failed: (Exit 1): scalapb_worker failed:
  error executing ProtoScalaPBRule command
  (from target @@com_google_protobuf//src/google/protobuf:any_proto)
  bazel-out/darwin_arm64-opt-exec-ST-a828a81199fe/bin/src/scala/scripts/scalapb_worker
    ... (remaining 2 arguments skipped)
```

Here's why the other changes were necessary in light of the version
bumps:

- `java_proto_library` from `rules_java` is now officially deprecated,
  hence loading it from `com_google_protobuf`.

- The `rules_java` release notes suggest either loading
  `proto_bazel_features` from `@com_google_protobuf` or just calling
  `protobuf_deps()`. The key point is that the project must instantiate
  the `@proto_bazel_features` repo _before_ calling
  `rules_java_toolchains`. Hence, we've moved the
  `rules_java_toolchains()` call to follow `protobuf_deps()`.

- We're using Bazel 7.5.0 in order to upgrade `abseil-cpp` to 20250127.0
  and `protobuf` to v29.3. This is instead of keeping `.bazelversion` at
  6.5.0 and setting C++ compiler flags in `.bazelrc` as described in
  bazelbuild#1647. (Loading this version as `abseil-cpp` also required setting
  `repo_mapping` on `com_google_protobuf`. See:
  https://github.com/abseil/abseil-cpp/releases/tag/20250127.0.)

- Setting `common --{,no}enable_{workspace,bzlmod}` fixes
  `test_semanticdb_handles_removed_sourcefiles`. This test relies on
  `bazel query`, which is also affected by these flags, hence `common`
  instead of `build`. Bazel 8 defaults to `--enable_bzlmod
  --noenable_workspace`, causing the `WORKSPACE` run of this test to
  fail.

- `glob` requires an explicit `allow_empty = True` parameter now that
  `--incompatible_disallow_empty_glob` defaults to `True` in Bazel 8.

- ScalaPB 0.9.8, the last version compatible with Scala 2.11, does not
  support `protobuf` >= 26.0. For this reason, we must remove the Scala
  2.11 test cases.

We should probably drop Scala 2.11 support at this point, since there's
no ScalaPB release that supports `protobuf` > v25.5.

Or perhaps we can at least document that `scala_proto` or any rules
otherwise depending on `protobuf` are no longer supported out of the
box. Such users will have to ensure they register their own downgraded
versions:

- `protobuf` <= v25.5
- `abseil-cpp` <= 20220623.1
- `rules_java` <= 7.12.4
- `rules_cc` <= 0.0.9
mbland added a commit to mbland/rules_scala that referenced this issue Feb 6, 2025
Prepares for `repository_ctx.original_name` support in Bazel 8.1.0 per
bazelbuild/bazel#24467 and bumps Go to 1.23.6. Part of bazelbuild#1482 and bazelbuild#1652.

The underlying repo rules will now use `repository_ctx.original_name` if
it's available.

I've confirmed that these changes use `repository_ctx.original_name`
under Bazel 8.1.0rc2 after commenting out the wrappers and restoring the
original repo rule symbols.

---

This change ensures compatibility with future Bazel releases. New
comments indicate where to simplify code after dropping support for
Bazel versions that don't have `repository_ctx.original_name`.

The Go 1.23.6 bump is a convenience update that isn't essential to the
rest of the change.

Under Bzlmod, `repository_ctx.name` contains the canonical repository
name. This broke the `_alias_repository` and `jvm_import_external`
repository rules, which used `repository_ctx.name` to generate default
top level target names for their repos. bazelbuild#1650 added wrapper macros
passing the original name as an extra attribute to the underlying repo
rules as a portable workaround.

The Bazel maintainers eventually recognized this as a common use case
and added `repository_ctx.original_name` to eliminate the need for such
wrappers (eventually).

- https://bazel.build/rules/lib/builtins/repository_ctx#name
- https://bazel.build/rules/lib/builtins/repository_ctx#original_name
mbland added a commit to mbland/rules_scala that referenced this issue Feb 6, 2025
Prepares for `repository_ctx.original_name` support in Bazel 8.1.0 per
bazelbuild/bazel#24467 and bumps Go to 1.23.6. Part of bazelbuild#1482 and bazelbuild#1652.

The underlying repo rules will now use `repository_ctx.original_name` if
it's available.

I've confirmed that these changes use `repository_ctx.original_name`
under Bazel 8.1.0rc2 after commenting out the wrappers and restoring the
original repo rule symbols.

---

This change ensures compatibility with future Bazel releases. New
comments indicate where to simplify code after dropping support for
Bazel versions that don't have `repository_ctx.original_name`.

The Go 1.23.6 bump is a convenience update that isn't essential to the
rest of the change.

Under Bzlmod, `repository_ctx.name` contains the canonical repository
name. This broke the `_alias_repository` and `jvm_import_external`
repository rules, which used `repository_ctx.name` to generate default
top level target names for their repos. bazelbuild#1650 added wrapper macros
passing the original name as an extra attribute to the underlying repo
rules as a portable workaround.

The Bazel maintainers eventually recognized this as a common use case
and added `repository_ctx.original_name` to eliminate the need for such
wrappers (eventually).

- https://bazel.build/rules/lib/builtins/repository_ctx#name
- https://bazel.build/rules/lib/builtins/repository_ctx#original_name
mbland added a commit to mbland/rules_scala that referenced this issue Feb 6, 2025
Bumps dependencies to versions that are compatible with both Bazel 7.5.0
and 8.0.0. Part of bazelbuild#1652.

- ScalaPB jars: 0.11.17 => 1.0.0-alpha.1
- `rules_python`: 0.38.0 => 1.1.0
- `rules_cc`: 0.0.9 => 0.0.17
- `abseil-cpp`: 20220623.1 => 20250127.0
- `rules_java`: 7.12.4 => 8.8.0
- `protobuf`: 21.7 => 29.3
- `rules_proto`: 6.0.2 => 7.1.0

rules_cc 0.1.0 exists, but we're using 0.0.17 per this advice from
https://github.com/bazelbuild/rules_cc/releases/tag/0.1.0:

> 0.1.x releases are not updated, please continue to use the latest
> 0.0.x release.

This precipitated the following updates also included in this commit:

- Loads `java_proto_library` from `com_google_protobuf`.
- Calls `java_repository()` after `protobuf_deps()` in `WORKSPACE`.
- Bumps `.bazelversion` to 7.5.0.
- Sets `common --{,no}enable_{workspace,bzlmod}`.
- Adds `allow_empty = True` to a `glob` expression in
  `//test/semanticdb:lib_with_tempsrc`.
- Removes Scala 2.11 test cases.

With this change:

- `WORKSPACE` builds succeed under Bazel 6.5.0, 7.5.0, and 8.0.0.
- Bzlmod builds succeed under Bazel 7.5.0 under 8.0.0.

Bazel 8 and `rules_java` 8 require `protobuf` >= v29. Bazel 6 Bzlmod
builds aren't supported because it doesn't provide `use_repo_rule`,
which is required by `rules_jvm_external` 6.3, which is required by
`protobuf` v29.

After the `protobuf` v29 bump, and before the ScalaPB 1.0.0-alpha.1
bump, `scala_proto` targets would fail with the following error:

```txt
ERROR: .../external/com_google_protobuf/src/google/protobuf/BUILD.bazel:23:14:
  ProtoScalaPBRule external/com_google_protobuf/src/google/protobuf/any_proto_jvm_extra_protobuf_generator_scalapb.srcjar
  failed: (Exit 1): scalapb_worker failed:
  error executing ProtoScalaPBRule command
  (from target @@com_google_protobuf//src/google/protobuf:any_proto)
  bazel-out/.../bin/src/scala/scripts/scalapb_worker
    ... (remaining 2 arguments skipped)

--jvm_extra_protobuf_generator_out:
  java.lang.NoSuchMethodError:
  'java.lang.Object com.google.protobuf.DescriptorProtos$FieldOptions.getExtension(com.google.protobuf.GeneratedMessage$GeneratedExtension)'
    at scalapb.compiler.DescriptorImplicits$ExtendedFieldDescriptor.fieldOptions(DescriptorImplicits.scala:329)
    at scalapb.compiler.DescriptorImplicits$ExtendedFieldDescriptor.scalaName(DescriptorImplicits.scala:207)
    at scalapb.compiler.ProtoValidation.validateField(ProtoValidation.scala:121)
    at scalapb.compiler.ProtoValidation.$anonfun$validateMessage$3(ProtoValidation.scala:56)
    at scalapb.compiler.ProtoValidation.$anonfun$validateMessage$3$adapted(ProtoValidation.scala:56)
    at scala.collection.Iterator.foreach(Iterator.scala:943)
    at scala.collection.Iterator.foreach$(Iterator.scala:943)
    at scala.collection.AbstractIterator.foreach(Iterator.scala:1431)
    at scala.collection.IterableLike.foreach(IterableLike.scala:74)
    at scala.collection.IterableLike.foreach$(IterableLike.scala:73)
    at scala.collection.AbstractIterable.foreach(Iterable.scala:56)
    at scalapb.compiler.ProtoValidation.validateMessage(ProtoValidation.scala:56)
    at scalapb.compiler.ProtoValidation.$anonfun$validateFile$2(ProtoValidation.scala:17)
    at scalapb.compiler.ProtoValidation.$anonfun$validateFile$2$adapted(ProtoValidation.scala:17)
    at scala.collection.Iterator.foreach(Iterator.scala:943)
    at scala.collection.Iterator.foreach$(Iterator.scala:943)
    at scala.collection.AbstractIterator.foreach(Iterator.scala:1431)
    at scala.collection.IterableLike.foreach(IterableLike.scala:74)
    at scala.collection.IterableLike.foreach$(IterableLike.scala:73)
    at scala.collection.AbstractIterable.foreach(Iterable.scala:56)
    at scalapb.compiler.ProtoValidation.validateFile(ProtoValidation.scala:17)
    at scalapb.compiler.ProtoValidation.$anonfun$validateFiles$1(ProtoValidation.scala:10)
    at scalapb.compiler.ProtoValidation.$anonfun$validateFiles$1$adapted(ProtoValidation.scala:10)
    at scala.collection.immutable.Stream.foreach(Stream.scala:533)
    at scalapb.compiler.ProtoValidation.validateFiles(ProtoValidation.scala:10)
    at scalarules.test.extra_protobuf_generator.ExtraProtobufGenerator$.handleCodeGeneratorRequest(ExtraProtobufGenerator.scala:86)
    at scalarules.test.extra_protobuf_generator.ExtraProtobufGenerator$.run(ExtraProtobufGenerator.scala:55)
    at protocbridge.frontend.PluginFrontend$.$anonfun$runWithBytes$1(PluginFrontend.scala:51)
    at scala.util.Try$.apply(Try.scala:213)
    at protocbridge.frontend.PluginFrontend$.runWithBytes(PluginFrontend.scala:51)
    at protocbridge.frontend.PluginFrontend$.runWithInputStream(PluginFrontend.scala:121)
    at protocbridge.frontend.PosixPluginFrontend$.$anonfun$prepare$2(PosixPluginFrontend.scala:40)
    at scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:23)
    at scala.concurrent.impl.ExecutionContextImpl$DefaultThreadFactory$$anon$1$$anon$2.block(ExecutionContextImpl.scala:75)
    at java.base/java.util.concurrent.ForkJoinPool.managedBlock(ForkJoinPool.java:3118)
    at scala.concurrent.impl.ExecutionContextImpl$DefaultThreadFactory$$anon$1.blockOn(ExecutionContextImpl.scala:87)
    at scala.concurrent.package$.blocking(package.scala:146)
    at protocbridge.frontend.PosixPluginFrontend$.$anonfun$prepare$1(PosixPluginFrontend.scala:38)
    at scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:23)
    at scala.concurrent.Future$.$anonfun$apply$1(Future.scala:659)
    at scala.util.Success.$anonfun$map$1(Try.scala:255)
    at scala.util.Success.map(Try.scala:213)
    at scala.concurrent.Future.$anonfun$map$1(Future.scala:292)
    at scala.concurrent.impl.Promise.$anonfun$transform$1(Promise.scala:42)
    at scala.concurrent.impl.CallbackRunnable.run(Promise.scala:74)
    at java.base/java.util.concurrent.ForkJoinTask$RunnableExecuteAction.exec(ForkJoinTask.java:1426)
    at java.base/java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:290)
    at java.base/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1020)
    at java.base/java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:1656)
    at java.base/java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1594)
    at java.base/java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:183)

java.lang.RuntimeException: Exit with code 1
    at scala.sys.package$.error(package.scala:30)
    at scripts.ScalaPBWorker$.work(ScalaPBWorker.scala:44)
    at io.bazel.rulesscala.worker.Worker.persistentWorkerMain(Worker.java:96)
    at io.bazel.rulesscala.worker.Worker.workerMain(Worker.java:49)
    at scripts.ScalaPBWorker$.main(ScalaPBWorker.scala:39)
    at scripts.ScalaPBWorker.main(ScalaPBWorker.scala)

ERROR: .../external/com_google_protobuf/src/google/protobuf/BUILD.bazel:23:14
  Building source jar external/com_google_protobuf/src/google/protobuf/any_proto_scalapb-src.jar
  failed: (Exit 1): scalapb_worker failed:
  error executing ProtoScalaPBRule command
  (from target @@com_google_protobuf//src/google/protobuf:any_proto)
  bazel-out/darwin_arm64-opt-exec-ST-a828a81199fe/bin/src/scala/scripts/scalapb_worker
    ... (remaining 2 arguments skipped)
```

Here's why the other changes were necessary in light of the version
bumps:

- `java_proto_library` from `rules_java` is now officially deprecated,
  hence loading it from `com_google_protobuf`.

- The `rules_java` release notes suggest either loading
  `proto_bazel_features` from `@com_google_protobuf` or just calling
  `protobuf_deps()`. The key point is that the project must instantiate
  the `@proto_bazel_features` repo _before_ calling
  `rules_java_toolchains`. Hence, we've moved the
  `rules_java_toolchains()` call to follow `protobuf_deps()`.

- We're using Bazel 7.5.0 in order to upgrade `abseil-cpp` to 20250127.0
  and `protobuf` to v29.3. This is instead of keeping `.bazelversion` at
  6.5.0 and setting C++ compiler flags in `.bazelrc` as described in
  bazelbuild#1647. (Loading this version as `abseil-cpp` also required setting
  `repo_mapping` on `com_google_protobuf`. See:
  https://github.com/abseil/abseil-cpp/releases/tag/20250127.0.)

- Setting `common --{,no}enable_{workspace,bzlmod}` fixes
  `test_semanticdb_handles_removed_sourcefiles`. This test relies on
  `bazel query`, which is also affected by these flags, hence `common`
  instead of `build`. Bazel 8 defaults to `--enable_bzlmod
  --noenable_workspace`, causing the `WORKSPACE` run of this test to
  fail.

- `glob` requires an explicit `allow_empty = True` parameter now that
  `--incompatible_disallow_empty_glob` defaults to `True` in Bazel 8.

- ScalaPB 0.9.8, the last version compatible with Scala 2.11, does not
  support `protobuf` >= 26.0. For this reason, we must remove the Scala
  2.11 test cases.

We should probably drop Scala 2.11 support at this point, since there's
no ScalaPB release that supports `protobuf` > v25.5.

Or perhaps we can at least document that `scala_proto` or any rules
otherwise depending on `protobuf` are no longer supported out of the
box. Such users will have to ensure they register their own downgraded
versions:

- `protobuf` <= v25.5
- `abseil-cpp` <= 20220623.1
- `rules_java` <= 7.12.4
- `rules_cc` <= 0.0.9
mbland added a commit to mbland/rules_scala that referenced this issue Feb 6, 2025
Fulfills most of bazelbuild#1482. Compatible with Bazel 6.5.0 and 7.5.0, but not
Bazel 8.

Documentation and "Publish to BCR" changes will come in future commits.
After that, we can close bazelbuild#1482, or we can wait to add Bazel 8
compatibility and close bazelbuild#1652 at the same time.
mbland added a commit to mbland/rules_scala that referenced this issue Feb 6, 2025
Fulfills most of bazelbuild#1482. Compatible with Bazel 6.5.0 and 7.5.0, but not
Bazel 8.

Documentation and "Publish to BCR" changes will come in future commits.
After that, we can publish a new major version and then close bazelbuild#1482.

Per bazelbuild#1647, `com_google_protobuf` remains at v21.7, and versions up to
v25.5 can work after bumping `com_google_absl` to 20240722.0 and setting
C++17 compiler flags in `.bazelrc`.

This change enables Bazel 6 and 7 users to migrate their `rules_scala`
dependency from `WORKSPACE` to `MODULE.bazel` whenever they're ready.

After the next major version release includes this change, we can update
`com_google_protobuf`, `rules_java`, and related dependencies as part of
enabling Bazel 8 compatibility (bazelbuild#1652). The `rules_jvm_external` update
in that change will effectively end Bzlmod support for Bazel 6.5.0,
effectively requiring another major version release after that.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants