Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Stick with protoc-{bridge,gen}_2.13 under Scala 3
As noted in the comment added to `select_root_artifacts()`, `com.thesamet.scalapb:compilerplugin_3:0.11.17` depends on `com.thesamet.scalapb:protoc-gen_2.13:0.9.7`. When using `com.thesamet.scalapb:protoc-gen_3:0.9.8` instead, we get a crash: ```txt $ bazel build --repo_env=SCALA_VERSION=3.6.2 //third_party/test/proto:scala [ ...snip... ] 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 command (from target //third_party/test/proto:proto) bazel-out/darwin_arm64-opt-exec-2B5CBBC6/bin/src/scala/scripts/scalapb_worker ... --scala_out: java.lang.NoClassDefFoundError: Could not initialize class scalapb.ScalaPbCodeGenerator$ at scripts.ScalaPbCodeGenerator$.process(ScalaPbCodeGeneratorWrapper.scala:7) at protocgen.CodeGenApp.run(CodeGenApp.scala:48) at protocgen.CodeGenApp.run$(CodeGenApp.scala:23) at scripts.ScalaPbCodeGenerator$.run(ScalaPbCodeGeneratorWrapper.scala:5) at protocgen.CodeGenApp.run(CodeGenApp.scala:33) at protocgen.CodeGenApp.run$(CodeGenApp.scala:23) at scripts.ScalaPbCodeGenerator$.run(ScalaPbCodeGeneratorWrapper.scala:5) at protocbridge.frontend.PluginFrontend$.runWithBytes(PluginFrontend.scala:48) at protocbridge.frontend.PluginFrontend$.runWithInputStream(PluginFrontend.scala:113) at protocbridge.frontend.SocketBasedPluginFrontend.prepare$$anonfun$1$$anonfun$1(SocketBasedPluginFrontend.scala:31) at protocbridge.frontend.SocketBasedPluginFrontend.prepare$$anonfun$1$$anonfun$adapted$1(SocketBasedPluginFrontend.scala:37) 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.SocketBasedPluginFrontend.prepare$$anonfun$1(SocketBasedPluginFrontend.scala:37) at protocbridge.frontend.SocketBasedPluginFrontend.prepare$$anonfun$adapted$1(SocketBasedPluginFrontend.scala:38) 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) Target //third_party/test/proto:scala failed to build ERROR: test/proto/BUILD.bazel:4:14 scala @//third_party/test/proto:proto failed: (Exit 1): scalapb_worker failed: error executing command (from target //third_party/test/proto:proto) ``` --- As I was going back and testing some more, I couldn't reproduce the `ProtoScalaPBRule` hanging by setting `protoc-bridge` to 0.9.7 and `protobuf` to v26.1. I was using this command (using Bazel 7.4.1 to avoid setting C++ compiler flags for Bazel 6.5.0): ```txt USE_BAZEL_VERSION=7.4.1 bazel build //third_party/test/proto:scala ``` The command kept crashing every time, instead of hanging. I eventually realized this was because of two things: - `scalarules.test.extra_protobuf_generator.ExtraProtobufGenerator.run` was still catching `Throwable`, since Scala 2.11 support ends with `protoc-bridge` 0.7.14. - Bazel kept persistent `io.bazel.rulesscala.scalac.ScalacWorker` workers running with `ExtraProtobufGenerator` code that still had the `try`/`catch` block after I tried removing it. After temporarily editing out the `try`/`catch` block from `ExtraProtobufGenerator.run` and running `bazel shutdown`, I could reproduce the hang. I could then confirm `protoc-bridge` 0.9.8 fixed it. --- Also, TIL that `scripts.ScalaPbCodeGenerator.process` (from `src/scala/scripts/ScalaPbCodeGeneratorWrapper`) never needed a `try`/`catch` block. When bumping to `com.thesamet.scalapb:compilerplugin_2.12:0.11.17` in bazelbuild#1648 (commit 23ae356), `scalapb.ScalaPbCodeGenerator` went from implementing `protocbridge.ProtocCodeGenerator` to implementing `protocgen.CodeGenApp`: - https://github.com/scalapb/ScalaPB/blob/v0.9.7/compiler-plugin/src/main/scala/scalapb/ScalaPbCodeGenerator.scala#L9 - https://github.com/scalapb/ScalaPB/blob/v0.11.17/compiler-plugin/src/main/scala/scalapb/ScalaPbCodeGenerator.scala#L11 That commit introduced `com.thesamet.scalapb:protoc-gen_2.12:0.9.7`, and `protocgen.CodeGenApp.run()` already had a `try`/`catch` block for `Throwable`: - https://github.com/scalapb/protoc-bridge/blob/v0.9.7/protoc-gen/src/main/scala/protocgen/CodeGenApp.scala#L49-L56 However, `protocbridge.ProtocCodeGenerator`, which `protocgen.CodeGenApp` extends, only declares a `run()` method with no implementation (and no `try`/`catch` block): - https://github.com/scalapb/protoc-bridge/blob/v0.9.7/bridge/src/main/scala/protocbridge/ProtocCodeGenerator.scala#L5 The aforementioned `ExtraProtobufGenerator` only extends `protocbridge.ProtocCodeGenerator`, not `protocgen.CodeGenApp`. That's why it will still hang when we remove the `try`/`catch` block from its `run()` method and run with `protoc-bridge` 0.9.7 and `protobuf` > v25.5.
- Loading branch information