Skip to content

Commit 23ae356

Browse files
authored
Bump ScalaPB, protoc-bridge, gRPC, and Guava deps, and add ProtobufAdapters and ScalaPBCodeGenerator wrappers (#1648)
* Bump ScalaPB and gRPC, exclude listenablefuture Adds these versions to `scripts/create_repository.py`. There are breakages still that future commits will address, but the following are fixed in this one. Removes the unnecessary `true` parameter from `.getPlaintext(true)` in `test/TestServer.scala` to fix this error after the gRPC bump: ```txt ERROR: .../test/BUILD:676:14: scala @//test:lib_with_scala_proto_dep failed: (Exit 1): scalac failed: error executing command (from target //test:lib_with_scala_proto_dep) bazel-bin/src/java/io/bazel/rulesscala/scalac/scalac @bazel-out/darwin_arm64-fastbuild/bin/test/lib_with_scala_proto_dep.jar-0.params test/TestServer.scala:70: error: no arguments allowed for nullary method usePlaintext: ()?0 val channel = ManagedChannelBuilder.forAddress(host, port).usePlaintext(true).build ^ ``` We exclude `com.google.guava:listenablefuture` because trying to download it breaks the build with an HTTP 404 (everything builds fine without it anyway): ```txt INFO: repository @io_bazel_rules_scala_listenablefuture' used the following cache hits instead of downloading the corresponding file. * Hash '...' for https://repo.maven.apache.org/maven2/com/google/guava/listenablefuture/9999.0-empty-to-avoid-conflict-with-guava/listenablefuture-9999.0-empty-to-avoid-conflict-with-guava.jar WARNING: Download from https://repo.maven.apache.org/maven2/com/google/guava/listenablefuture/9999.0-empty-to-avoid-conflict-with-guava/listenablefuture-9999.0-empty-to-avoid-conflict-with-guava-sources.jar failed: class java.io.FileNotFoundException GET returned 404 Not Found WARNING: Download from https://maven-central.storage-download.googleapis.com/maven2/com/google/guava/listenablefuture/9999.0-empty-to-avoid-conflict-with-guava/listenablefuture-9999.0-empty-to-avoid-conflict-with-guava-sources.jar failed: class java.io.FileNotFoundException GET returned 404 Not Found WARNING: Download from https://mirror.bazel.build/repo1.maven.org/maven2/com/google/guava/listenablefuture/9999.0-empty-to-avoid-conflict-with-guava/listenablefuture-9999.0-empty-to-avoid-conflict-with-guava-sources.jar failed: class java.io.FileNotFoundException GET returned 404 Not Found WARNING: Download from https://jcenter.bintray.com/com/google/guava/listenablefuture/9999.0-empty-to-avoid-conflict-with-guava/listenablefuture-9999.0-empty-to-avoid-conflict-with-guava-sources.jar failed: class java.io.FileNotFoundException GET returned 404 Not Found ERROR: An error occurred during the fetch of repository 'io_bazel_rules_scala_listenablefuture': Traceback (most recent call last): File ".../scala/scala_maven_import_external.bzl", line 130, column 32, in _jvm_import_external repository_ctx.download(srcurls, srcpath, srcsha, auth = _get_auth(repository_ctx, srcurls)) Error in download: java.io.IOException: Error downloading [ ...4 URLs from WARNINGs above... ] to .../external/io_bazel_rules_scala_listenablefuture/listenablefuture-9999.0-empty-to-avoid-conflict-with-guava-src.jar: GET returned 404 Not Found ERROR: /Users/mbland/src/bazelbuild/rules_scala/WORKSPACE:75:25: fetching jvm_import_external rule //external:io_bazel_rules_scala_listenablefuture: [ ...Traceback, java.io.IOException, and HTTP 404 from above... ] ERROR: .../external/io_bazel_rules_scala_guava/BUILD:9:13: @io_bazel_rules_scala_guava//:io_bazel_rules_scala_guava depends on @io_bazel_rules_scala_listenablefuture//:io_bazel_rules_scala_listenablefuture in repository @io_bazel_rules_scala_listenablefuture which failed to fetch. no such package '@io_bazel_rules_scala_listenablefuture//': [ ...java.io.IOException and HTTP 404 from above... ] ERROR: Analysis of target '//test/proto/custom_generator:failing_scala_proto_deps_toolchain_def' failed; build aborted: ``` * Update scala_proto repositories for Scala 2.11 Since Scala 2.11 is stuck on ScalaPB 0.9.8, its dependencies don't include the `dev.dirs:directories` artifact. Before this change, building with `--repo_env=SCALA_VERSION=2.11.12 would die with: ```txt $ bazel build --repo_env=SCALA_VERSION=2.11.12 \ //src/... //test/... //third_party/... //scala_proto/... ERROR: Traceback (most recent call last): File "/Users/mbland/src/bazelbuild/rules_scala/WORKSPACE", line 75, column 25, in <toplevel> scala_proto_repositories() File "/Users/mbland/src/bazelbuild/rules_scala/scala_proto/scala_proto.bzl", line 17, column 37, in scala_proto_repositories scala_proto_default_repositories(**kwargs) File "/Users/mbland/src/bazelbuild/rules_scala/scala_proto/default/repositories.bzl", line 7, column 17, in scala_proto_default_repositories repositories( File "/Users/mbland/src/bazelbuild/rules_scala/third_party/repositories/repositories.bzl", line 107, column 17, in repositories fail("artifact %s not in third_party/repositories/scala_%s.bzl" % ( Error in fail: artifact dev_dirs_directories not in third_party/repositories/scala_2_11.bzl ERROR: Error computing the main repository mapping: Encountered error while reading extension file 'go/deps.bzl': no such package '@io_bazel_rules_go//go': error loading package 'external': Could not load //external package ``` This is a preview of scala_proto toolchainization, given the addition of `scala_version` and `register_toolchains` parameters to `scala_proto_default_repositories`. * Add scalapb:compilerplugin to root artifacts Without this, the `com.thesamet.scalapb:compilerplugin` artifact is out of sync with other ScalaPB artifacts, leading to this error: ```txt $ bazel build //test/proto_cross_repo_boundary/... ERROR: .../external/proto_cross_repo_boundary/BUILD.bazel:3:14: scala @proto_cross_repo_boundary//:sample_proto failed: (Exit 1): scalac failed: error executing command (from target @proto_cross_repo_boundary//:sample_proto) bazel-out/.../bin/src/java/io/bazel/rulesscala/scalac/scalac @bazel-out/.../bin/external/proto_cross_repo_boundary/sample_proto_scalapb.jar-0.params bazel-out/.../bin/external/proto_cross_repo_boundary/_scalac/sample_proto/sources/1_sample_proto_scala_scalapb.srcjar/sample/sample/Sample.scala:11: error: class Any needs to be a trait to be mixed in ) extends scalapb.GeneratedMessage with scalapb.Message[Sample] with scalapb.lenses.Updatable[Sample] { ^ Target //test/proto_cross_repo_boundary:sample_scala_proto failed to build ``` * Fix scalapb-runtime 0.11.17 errors There were API changes from scalapb-runtime 0.9.7 causing the following errors: ```txt ERROR: .../test/src/main/scala/scalarules/test/extra_protobuf_generator/BUILD:3:14: scala @//test/src/main/scala/scalarules/test/extra_protobuf_generator:extra_protobuf_generator failed: (Exit 1): scalac failed: error executing Scalac command (from target //test/src/main/scala/scalarules/test/extra_protobuf_generator:extra_protobuf_generator) bazel-out/darwin_arm64-opt-exec-ST-a828a81199fe/bin/src/java/io/bazel/rulesscala/scalac/scalac ... (remaining 1 argument skipped) test/src/main/scala/scalarules/test/extra_protobuf_generator/ExtraProtobufGenerator.scala:20: error: value nameSymbol is not a member of com.google.protobuf.Descriptors.Descriptor .add(s"final case object Custom${message.nameSymbol}{}") ^ test/src/main/scala/scalarules/test/extra_protobuf_generator/ExtraProtobufGenerator.scala:34: error: value fileDescriptorObjectName is not a member of com.google.protobuf.Descriptors.FileDescriptor b.setName(file.scalaDirectory + "/Custom" + file.fileDescriptorObjectName + ".scala") ^ test/src/main/scala/scalarules/test/extra_protobuf_generator/ExtraProtobufGenerator.scala:66: error: value FileDescriptorPimp is not a member of scalapb.compiler.DescriptorImplicits import implicits.FileDescriptorPimp ^ ``` Since Scala 2.11 can't advance past scalapb-runtime 0.9.8, we use `select_for_scala_version` to select the appropriate `ProtobufAdapter` to maintain API compatibility. Also, `import implicits.FileDescriptorPimp` turned out to be unnecessary after all, even under Scala 2.11. * Add `null` as dummy `TestMessage` parameter Fixes the `test_demonstrate_INCORRECT_scala_proto_library_stamp` test case from `test/shell/test_strict_dependency.sh` after the ScalaPB 0.11.17 bump. Somehow, bumping that library (presumably, instead of gRPC, et. al.) changed the parameter list of `TestMessage` from `String` to `String,UnknownFieldSet`. The test then failed because the following command produced this unexpected error: ```txt $ bazel build --verbose_failures \ //test_expect_failure/missing_direct_deps/scala_proto_deps:uses_transitive_scala_proto \ --extra_toolchains=//test/toolchains:ast_plus_one_deps_strict_deps_error ERROR: .../test_expect_failure/missing_direct_deps/scala_proto_deps/BUILD:25:13: Building test_expect_failure/missing_direct_deps/scala_proto_deps/libtransitive.jar (1 source file) failed: (Exit 1): java failed: error executing command (from target //test_expect_failure/missing_direct_deps/scala_proto_deps:transitive) (cd ... [ ...snip... ] external/remotejdk11_macos_aarch64/bin/java -XX:-CompactStrings [ ...snip... ] external/remote_java_tools/java_tools/JavaBuilder_deploy.jar @bazel-out/.../bin/test_expect_failure/missing_direct_deps/scala_proto_deps/libtransitive.jar-0.params @bazel-out/.../bin/test_expect_failure/missing_direct_deps/scala_proto_deps/libtransitive.jar-1.params) test_expect_failure/missing_direct_deps/scala_proto_deps/UseTestMessage.java:7: error: constructor TestMessage in class TestMessage cannot be applied to given types; private final TestMessage m = new TestMessage(""); ^ required: String,UnknownFieldSet found: String reason: actual and formal argument lists differ in length ``` After this change, the same command produces the following failure that the test is expecting to catch: ```txt ERROR: .../test_expect_failure/missing_direct_deps/scala_proto_deps/BUILD:18:14: scala @//test_expect_failure/missing_direct_deps/scala_proto_deps:uses_transitive_scala_proto failed: (Exit 1): scalac failed: error executing command (from target //test_expect_failure/missing_direct_deps/scala_proto_deps:uses_transitive_scala_proto) (cd .../execroot/io_bazel_rules_scala && \ exec env - \ bazel-out/.../bin/src/java/io/bazel/rulesscala/scalac/scalac @bazel-out/.../bin/test_expect_failure/missing_direct_deps/scala_proto_deps/uses_transitive_scala_proto.jar-0.params) test_expect_failure/missing_direct_deps/scala_proto_deps/UseScalaProtoIndirectly.scala:6: error: Target '@//test_expect_failure/missing_direct_deps/scala_proto_deps:some_proto' is used but isn't explicitly declared, please add it to the deps. You can use the following buildozer command: buildozer 'add deps @//test_expect_failure/missing_direct_deps/scala_proto_deps:some_proto' //test_expect_failure/missing_direct_deps/scala_proto_deps:uses_transitive_scala_proto val foo: TestMessage = new UseTestMessage().getM ^ one error found Build failure with errors. Target //test_expect_failure/missing_direct_deps/scala_proto_deps:uses_transitive_scala_proto failed to build ``` * Remove unnecessary .getPlaintext() parameter Already did this for `test/TestServer.scala` as part of the gRPC bump. `test_version/version_specific_tests_dir/TestServer.scala` gets the same treatment now to fix `test_scala_version 2.11.12` from `test_version.sh`, which failed with: ``` ERROR: .../test_version/test_scala_version_1731027515/BUILD:161:14: scala @//:lib_with_scala_proto_dep failed: (Exit 1): scalac failed: error executing command (from target //:lib_with_scala_proto_dep) bazel-out/.../bin/external/io_bazel_rules_scala/src/java/io/bazel/rulesscala/scalac/scalac @bazel-out/.../bin/lib_with_scala_proto_dep.jar-0.params TestServer.scala:70: error: too many arguments for method usePlaintext: ()?0 val channel = ManagedChannelBuilder.forAddress(host, port).usePlaintext(true).build ^ ``` * Add org_scala_lang_modules_scala_collection_compat More specifically, add it to the list of core scala repository imports. It had been generated before, but somehow hadn't been required until now. With this change, all tests now pass after the ScalaPB 0.11.17, gRPC 1.68.1, and Guava 33.3.1-jre version bumps. Fixes the following error in `test_scala_version 2.12.20` from `test_version.sh`: ```txt ERROR: .../external/scala_proto_rules_scalapb_compilerplugin/BUILD:9:13: no such package '@org_scala_lang_modules_scala_collection_compat//': The repository '@org_scala_lang_modules_scala_collection_compat' could not be resolved: Repository '@org_scala_lang_modules_scala_collection_compat' is not defined and referenced by '@scala_proto_rules_scalapb_compilerplugin//:scala_proto_rules_scalapb_compilerplugin' ERROR: Analysis of target '//proto:test_proto_nogrpc' failed; build aborted: ``` * Wrap ScalaPbCodeGenerator, expose Scala 2.11 error Wraps `scalapb.ScalaPbCodeGenerator` to catch and return all errors. Without this, any errors escaping from `scalapb.ScalaPbCodeGenerator` will cause the `scala_proto` aspect workers to hang. Also deletes some `@io_bazel_rules_scala` references, replacing them with `Label` instances as appropriate. The `test_scala_version 2.11.12` case from `test_version.sh` would previously hang given the combination of ScalaPB 0.9.8 (the newest available for Scala 2.11) and Protobuf v28.3. Running the following in a `test_version/test_scala_version_*` repo generated by `test_version.sh` reproduced the hang: ```txt $ bazel build --repo_env=SCALA_VERSION=2.11.12 //proto:test_proto [ ...wait 10 seconds, then CTRL-C... ] INFO: Analyzed target //proto:test_proto (2 packages loaded, 22 targets configured). INFO: Found 1 target... [1,038 / 1,047] 4 actions running ProtoScalaPBRule proto/test_service_scala_scalapb.srcjar; 10s worker ProtoScalaPBRule proto/test2_scala_scalapb.srcjar; 10s worker Target //proto:test_proto failed to build ``` With this change, the command now exposes the exact incompatibility between these versions: ```txt $ bazel build --repo_env=SCALA_VERSION=2.11.12 //proto:test_proto ERROR: .../test_version/test_scala_version_1731169107/proto/BUILD:14:14: ProtoScalaPBRule proto/test3_scala_scalapb.srcjar failed: (Exit 1): scalapb_worker failed: error executing command (from target //proto:test3) bazel-out/.../bin/external/io_bazel_rules_scala/src/scala/scripts/scalapb_worker ... (remaining 2 arguments skipped) --scala_out: java.lang.NoSuchMethodError: 'void com.google.protobuf.Descriptors$FileDescriptor.internalBuildGeneratedFileFrom(java.lang.String[], com.google.protobuf.Descriptors$FileDescriptor[], com.google.protobuf.Descriptors$FileDescriptor$InternalDescriptorAssigner)' at scalapb.options.compiler.Scalapb.<clinit>(Scalapb.java:10592) at scalapb.ScalaPbCodeGenerator$.run(ScalaPbCodeGenerator.scala:14) at scalapb.ScalaPbCodeGenerator$.run(ScalaPbCodeGenerator.scala:10) at scripts.ScalaPbCodeGenerator$.run(ScalaPbCodeGeneratorWrapper_2_11.scala:8) at protocbridge.frontend.PluginFrontend$$anonfun$runWithBytes$2.apply(PluginFrontend.scala:52) at protocbridge.frontend.PluginFrontend$$anonfun$runWithBytes$2.apply(PluginFrontend.scala:52) at scala.util.Try$.apply(Try.scala:192) at protocbridge.frontend.PluginFrontend$.runWithBytes(PluginFrontend.scala:51) at protocbridge.frontend.PluginFrontend$.runWithInputStream(PluginFrontend.scala:103) at protocbridge.frontend.PosixPluginFrontend$$anonfun$prepare$1.apply$mcV$sp(PosixPluginFrontend.scala:33) at protocbridge.frontend.PosixPluginFrontend$$anonfun$prepare$1.apply(PosixPluginFrontend.scala:31) at protocbridge.frontend.PosixPluginFrontend$$anonfun$prepare$1.apply(PosixPluginFrontend.scala:31) at scala.concurrent.impl.Future$PromiseCompletingRunnable.liftedTree1$1(Future.scala:24) at scala.concurrent.impl.Future$PromiseCompletingRunnable.run(Future.scala:24) at scala.concurrent.impl.ExecutionContextImpl$AdaptedForkJoinTask.exec(ExecutionContextImpl.scala:121) at scala.concurrent.forkjoin.ForkJoinTask.doExec(ForkJoinTask.java:260) at scala.concurrent.forkjoin.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1339) at scala.concurrent.forkjoin.ForkJoinPool.runWorker(ForkJoinPool.java:1979) at scala.concurrent.forkjoin.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:107) 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 //proto:test_proto failed to build ``` * Extract `scala_proto_artifact_ids` This will support the upcoming schema whereby `scala_toolchains` will import all artifact IDs via macros like this, and invoke `repositories` itself. This will avoid instantiating the same artifact repository multiple times for different frameworks that depend on it. Under `WORKSPACE`, this isn't a problem, but it's an error under Bzlmod, as a module extension can only instantiate a repository once. The commit message to toolchainize Scalafmt will provide more details on this.
1 parent d43ae0d commit 23ae356

File tree

25 files changed

+2237
-471
lines changed

25 files changed

+2237
-471
lines changed

scala/private/macros/scala_repositories.bzl

+1
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ def _artifact_ids(scala_version):
181181
"io_bazel_rules_scala_scala_library",
182182
"io_bazel_rules_scala_scala_parser_combinators",
183183
"io_bazel_rules_scala_scala_xml",
184+
"org_scala_lang_modules_scala_collection_compat",
184185
]
185186

186187
if scala_version.startswith("2."):

scala_proto/BUILD

+10-13
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
1-
load(
2-
"//scala_proto:scala_proto_toolchain.bzl",
3-
"scala_proto_deps_toolchain",
4-
"scala_proto_toolchain",
5-
)
1+
load("//scala:providers.bzl", "declare_deps_provider")
62
load(
73
"//scala_proto/default:default_deps.bzl",
84
"DEFAULT_SCALAPB_COMPILE_DEPS",
95
"DEFAULT_SCALAPB_GRPC_DEPS",
6+
"DEFAULT_SCALAPB_WORKER_DEPS",
107
)
11-
load("//scala:providers.bzl", "declare_deps_provider")
128
load("//scala_proto/private:toolchain_deps.bzl", "export_scalapb_toolchain_deps")
9+
load(
10+
"//scala_proto:scala_proto_toolchain.bzl",
11+
"scala_proto_deps_toolchain",
12+
"scala_proto_toolchain",
13+
)
1314

1415
toolchain_type(
1516
name = "toolchain_type",
@@ -37,7 +38,7 @@ scala_proto_toolchain(
3738
toolchain(
3839
name = "default_toolchain",
3940
toolchain = ":default_toolchain_impl",
40-
toolchain_type = "@io_bazel_rules_scala//scala_proto:toolchain_type",
41+
toolchain_type = "//scala_proto:toolchain_type",
4142
visibility = ["//visibility:public"],
4243
)
4344

@@ -58,7 +59,7 @@ scala_proto_toolchain(
5859
toolchain(
5960
name = "enable_all_options_toolchain",
6061
toolchain = ":enable_all_options_toolchain_impl",
61-
toolchain_type = "@io_bazel_rules_scala//scala_proto:toolchain_type",
62+
toolchain_type = "//scala_proto:toolchain_type",
6263
visibility = ["//visibility:public"],
6364
)
6465

@@ -80,11 +81,7 @@ declare_deps_provider(
8081
name = "scalapb_worker_deps_provider",
8182
deps_id = "scalapb_worker_deps",
8283
visibility = ["//visibility:public"],
83-
deps = [
84-
"@com_google_protobuf//:protobuf_java",
85-
"@scala_proto_rules_scalapb_compilerplugin",
86-
"@scala_proto_rules_scalapb_protoc_bridge",
87-
],
84+
deps = DEFAULT_SCALAPB_WORKER_DEPS,
8885
)
8986

9087
export_scalapb_toolchain_deps(

scala_proto/default/default_deps.bzl

+17-5
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
# These are the compile/runtime dependencies needed for scalapb compilation
22
# and grpc compile/runtime.
33
#
4-
# In a complex environment you may want to update the toolchain to not refer to these anymore
5-
# If you are using a resolver (like bazel-deps) that can export compile + runtime jar paths
6-
# for you, then you should only need much shorter dependency lists. This needs to be the unrolled
7-
# transitive path to be used without such a facility.
8-
#
4+
# In a complex environment you may want to update the toolchain to not refer to
5+
# these anymore If you are using a resolver (like bazel-deps) that can export
6+
# compile + runtime jar paths for you, then you should only need much shorter
7+
# dependency lists. This needs to be the unrolled transitive path to be used
8+
# without such a facility.
9+
10+
load("//scala:scala_cross_version_select.bzl", "select_for_scala_version")
11+
912
DEFAULT_SCALAPB_COMPILE_DEPS = [
1013
"//scala/private/toolchain_deps:scala_library_classpath",
1114
"@com_google_protobuf//:protobuf_java",
@@ -41,3 +44,12 @@ DEFAULT_SCALAPB_GRPC_DEPS = [
4144
"@scala_proto_rules_perfmark_api",
4245
"@scala_proto_rules_scalapb_runtime_grpc",
4346
]
47+
48+
DEFAULT_SCALAPB_WORKER_DEPS = [
49+
"@com_google_protobuf//:protobuf_java",
50+
"@scala_proto_rules_scalapb_compilerplugin",
51+
"@scala_proto_rules_scalapb_protoc_bridge",
52+
] + select_for_scala_version(
53+
any_2_11 = [],
54+
since_2_12 = ["@scala_proto_rules_scalapb_protoc_gen"],
55+
)

scala_proto/default/repositories.bzl

+66-35
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,78 @@
11
load("//scala:scala_cross_version.bzl", "default_maven_server_urls")
22
load("//third_party/repositories:repositories.bzl", "repositories")
3+
load("@io_bazel_rules_scala_config//:config.bzl", "SCALA_VERSION")
4+
5+
# Needed by scalafmt
6+
SCALAPB_COMPILE_ARTIFACT_IDS = [
7+
"com_google_protobuf_protobuf_java",
8+
"com_lihaoyi_fastparse",
9+
"com_lihaoyi_sourcecode",
10+
"scala_proto_rules_scalapb_lenses",
11+
"scala_proto_rules_scalapb_runtime",
12+
]
13+
14+
# Needed by twitter_scrooge
15+
GUAVA_ARTIFACT_IDS = [
16+
"com_google_code_findbugs_jsr305",
17+
"com_google_errorprone_error_prone_annotations",
18+
"com_google_j2objc_j2objc_annotations",
19+
"io_bazel_rules_scala_guava",
20+
"io_bazel_rules_scala_failureaccess",
21+
"org_checkerframework_checker_qual",
22+
]
23+
24+
def scala_proto_artifact_ids(scala_version):
25+
return ([] if scala_version.startswith("2.11.") else [
26+
"dev_dirs_directories",
27+
"scala_proto_rules_scalapb_protoc_gen",
28+
]) + [
29+
"com_google_android_annotations",
30+
"com_google_code_gson_gson",
31+
"org_codehaus_mojo_animal_sniffer_annotations",
32+
"scala_proto_rules_disruptor",
33+
"scala_proto_rules_grpc_api",
34+
"scala_proto_rules_grpc_context",
35+
"scala_proto_rules_grpc_core",
36+
"scala_proto_rules_grpc_netty",
37+
"scala_proto_rules_grpc_protobuf",
38+
"scala_proto_rules_grpc_protobuf_lite",
39+
"scala_proto_rules_grpc_stub",
40+
"scala_proto_rules_grpc_util",
41+
"scala_proto_rules_instrumentation_api",
42+
"scala_proto_rules_netty_buffer",
43+
"scala_proto_rules_netty_codec",
44+
"scala_proto_rules_netty_codec_http",
45+
"scala_proto_rules_netty_codec_http2",
46+
"scala_proto_rules_netty_codec_socks",
47+
"scala_proto_rules_netty_common",
48+
"scala_proto_rules_netty_handler",
49+
"scala_proto_rules_netty_handler_proxy",
50+
"scala_proto_rules_netty_resolver",
51+
"scala_proto_rules_netty_transport",
52+
"scala_proto_rules_netty_transport_native_unix_common",
53+
"scala_proto_rules_opencensus_api",
54+
"scala_proto_rules_opencensus_contrib_grpc_metrics",
55+
"scala_proto_rules_opencensus_impl",
56+
"scala_proto_rules_opencensus_impl_core",
57+
"scala_proto_rules_perfmark_api",
58+
"scala_proto_rules_proto_google_common_protos",
59+
"scala_proto_rules_scalapb_compilerplugin",
60+
"scala_proto_rules_scalapb_protoc_bridge",
61+
"scala_proto_rules_scalapb_runtime_grpc",
62+
] + SCALAPB_COMPILE_ARTIFACT_IDS + GUAVA_ARTIFACT_IDS
363

464
def scala_proto_default_repositories(
565
maven_servers = default_maven_server_urls(),
66+
scala_version = SCALA_VERSION,
667
overriden_artifacts = {}):
768
repositories(
8-
for_artifact_ids = [
9-
"com_google_protobuf_protobuf_java",
10-
"com_lihaoyi_fastparse",
11-
"com_lihaoyi_sourcecode",
12-
"io_bazel_rules_scala_guava",
13-
"scala_proto_rules_disruptor",
14-
"scala_proto_rules_instrumentation_api",
15-
"scala_proto_rules_grpc_api",
16-
"scala_proto_rules_grpc_context",
17-
"scala_proto_rules_grpc_core",
18-
"scala_proto_rules_grpc_netty",
19-
"scala_proto_rules_grpc_protobuf",
20-
"scala_proto_rules_grpc_stub",
21-
"scala_proto_rules_netty_buffer",
22-
"scala_proto_rules_netty_codec",
23-
"scala_proto_rules_netty_codec_http",
24-
"scala_proto_rules_netty_codec_http2",
25-
"scala_proto_rules_netty_codec_socks",
26-
"scala_proto_rules_netty_common",
27-
"scala_proto_rules_netty_handler",
28-
"scala_proto_rules_netty_handler_proxy",
29-
"scala_proto_rules_netty_resolver",
30-
"scala_proto_rules_netty_transport",
31-
"scala_proto_rules_opencensus_api",
32-
"scala_proto_rules_opencensus_contrib_grpc_metrics",
33-
"scala_proto_rules_opencensus_impl",
34-
"scala_proto_rules_opencensus_impl_core",
35-
"scala_proto_rules_perfmark_api",
36-
"scala_proto_rules_scalapb_compilerplugin",
37-
"scala_proto_rules_scalapb_lenses",
38-
"scala_proto_rules_scalapb_protoc_bridge",
39-
"scala_proto_rules_scalapb_runtime",
40-
"scala_proto_rules_scalapb_runtime_grpc",
41-
],
69+
scala_version = scala_version,
70+
for_artifact_ids = scala_proto_artifact_ids(scala_version),
4271
maven_servers = maven_servers,
4372
fetch_sources = True,
4473
overriden_artifacts = overriden_artifacts,
4574
)
4675

47-
native.register_toolchains("@io_bazel_rules_scala//scala_proto:default_deps_toolchain")
76+
native.register_toolchains(
77+
str(Label("//scala_proto:default_deps_toolchain")),
78+
)

scala_proto/scala_proto_toolchain.bzl

+21-8
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
load("@io_bazel_rules_scala//scala:providers.bzl", "DepsInfo")
1+
load("//scala:providers.bzl", "DepsInfo")
22

33
def _generators(ctx):
44
return dict(
@@ -7,9 +7,12 @@ def _generators(ctx):
77
)
88

99
def _generators_jars(ctx):
10+
generator_deps = ctx.attr.extra_generator_dependencies + [
11+
ctx.attr._main_generator_dep,
12+
]
1013
return depset(transitive = [
1114
dep[JavaInfo].transitive_runtime_jars
12-
for dep in ctx.attr.extra_generator_dependencies
15+
for dep in generator_deps
1316
])
1417

1518
def _generators_opts(ctx):
@@ -74,18 +77,20 @@ scala_proto_toolchain = rule(
7477
"code_generator": attr.label(
7578
executable = True,
7679
cfg = "exec",
77-
default = Label("@io_bazel_rules_scala//src/scala/scripts:scalapb_worker"),
80+
default = Label("//src/scala/scripts:scalapb_worker"),
7881
allow_files = True,
7982
),
80-
"main_generator": attr.string(default = "scalapb.ScalaPbCodeGenerator"),
83+
"main_generator": attr.string(
84+
default = "scripts.ScalaPbCodeGenerator",
85+
),
8186
"named_generators": attr.string_dict(),
8287
"extra_generator_dependencies": attr.label_list(
8388
providers = [JavaInfo],
8489
),
8590
"scalac": attr.label(
8691
executable = True,
8792
cfg = "exec",
88-
default = Label("@io_bazel_rules_scala//src/java/io/bazel/rulesscala/scalac"),
93+
default = Label("//src/java/io/bazel/rulesscala/scalac"),
8994
allow_files = True,
9095
),
9196
"protoc": attr.label(
@@ -105,6 +110,14 @@ scala_proto_toolchain = rule(
105110
[proto rules documentation](https://docs.bazel.build/versions/master/be/protocol-buffer.html#proto_library)
106111
""",
107112
),
113+
"_main_generator_dep": attr.label(
114+
default = Label(
115+
"//src/scala/scripts:scalapb_codegenerator_wrapper",
116+
),
117+
allow_single_file = True,
118+
executable = False,
119+
cfg = "exec",
120+
),
108121
},
109122
)
110123

@@ -119,9 +132,9 @@ scala_proto_deps_toolchain = rule(
119132
attrs = {
120133
"dep_providers": attr.label_list(
121134
default = [
122-
"@io_bazel_rules_scala//scala_proto:scalapb_compile_deps_provider",
123-
"@io_bazel_rules_scala//scala_proto:scalapb_grpc_deps_provider",
124-
"@io_bazel_rules_scala//scala_proto:scalapb_worker_deps_provider",
135+
Label("//scala_proto:scalapb_compile_deps_provider"),
136+
Label("//scala_proto:scalapb_grpc_deps_provider"),
137+
Label("//scala_proto:scalapb_worker_deps_provider"),
125138
],
126139
cfg = "target",
127140
providers = [DepsInfo],

scripts/create_repository.py

+21-5
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,14 @@
3232
KIND_PROJECTOR_VERSION = "0.13.3"
3333
PROTOBUF_JAVA_VERSION = "4.28.3"
3434
JLINE_VERSION = '3.27.1'
35-
SCALAPB_VERSION = '0.9.8'
35+
SCALAPB_VERSION = '0.11.17'
36+
PROTOC_BRIDGE_VERSION = '0.9.7'
37+
GRPC_VERSION = '1.68.1'
38+
GRPC_COMMON_PROTOS_VERSION = '2.48.0'
39+
GRPC_LIBS = ['netty', 'protobuf', 'stub']
40+
GUAVA_VERSION = '33.3.1-jre'
3641

37-
EXCLUDED_ARTIFACTS = set()
42+
EXCLUDED_ARTIFACTS = set(["com.google.guava:listenablefuture"])
3843

3944
THIS_FILE = Path(__file__)
4045
REPO_ROOT = THIS_FILE.parent.parent
@@ -79,26 +84,37 @@ def select_root_artifacts(scala_version, scala_major, is_scala_3) -> List[str]:
7984

8085
scalafmt_version = SCALAFMT_VERSION
8186
scalapb_version = SCALAPB_VERSION
87+
protoc_bridge_version = PROTOC_BRIDGE_VERSION
8288

8389
if scala_major == '2.11':
8490
scalafmt_version = '2.7.5'
8591
scalapb_version = '0.9.8'
92+
protoc_bridge_version = '0.7.14'
8693

8794
root_artifacts = [
95+
'com.google.api.grpc:proto-google-common-protos:' +
96+
GRPC_COMMON_PROTOS_VERSION,
97+
f'com.google.guava:guava:{GUAVA_VERSION}',
8898
f'com.google.protobuf:protobuf-java:{PROTOBUF_JAVA_VERSION}',
99+
f'com.thesamet.scalapb:compilerplugin_{scala_2_major}:' +
100+
scalapb_version,
101+
f'com.thesamet.scalapb:protoc-bridge_{scala_2_major}:' +
102+
protoc_bridge_version,
89103
f'com.thesamet.scalapb:scalapb-runtime_{scala_2_major}:' +
90104
scalapb_version,
105+
f'com.thesamet.scalapb:scalapb-runtime-grpc_{scala_2_major}:' +
106+
scalapb_version,
91107
f'org.scala-lang.modules:scala-parser-combinators_{scala_2_major}:' +
92108
PARSER_COMBINATORS_VERSION,
93-
f'org.scalameta:scalafmt-core_{scala_2_major}:{scalafmt_version}',
94-
f'org.scalatest:scalatest_{scalatest_major}:{SCALATEST_VERSION}',
95109
f'org.scala-lang:scala-compiler:{scala_2_version}',
96110
f'org.scala-lang:scala-library:{scala_2_version}',
97111
f'org.scala-lang:scala-reflect:{scala_2_version}',
98112
f'org.scala-lang:scalap:{scala_2_version}',
113+
f'org.scalameta:scalafmt-core_{scala_2_major}:{scalafmt_version}',
114+
f'org.scalatest:scalatest_{scalatest_major}:{SCALATEST_VERSION}',
99115
f'org.typelevel:kind-projector_{scala_2_version}:' +
100116
KIND_PROJECTOR_VERSION,
101-
]
117+
] + [f'io.grpc:grpc-{lib}:{GRPC_VERSION}' for lib in GRPC_LIBS]
102118

103119
if scala_version == max_scala_2_version or is_scala_3:
104120
# Since the Scala 2.13 compiler is included in Scala 3 deps.

src/scala/scripts/BUILD

+13
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
load("//scala:scala.bzl", "scala_binary", "scala_library")
2+
load("//scala:scala_cross_version_select.bzl", "select_for_scala_version")
23

34
scala_library(
45
name = "scrooge_worker_lib",
@@ -22,6 +23,18 @@ scala_binary(
2223
],
2324
)
2425

26+
scala_library(
27+
name = "scalapb_codegenerator_wrapper",
28+
srcs = select_for_scala_version(
29+
any_2_11 = ["ScalaPbCodeGeneratorWrapper_2_11.scala"],
30+
since_2_12 = ["ScalaPbCodeGeneratorWrapper.scala"],
31+
),
32+
visibility = ["//visibility:public"],
33+
deps = [
34+
"//scala_proto:scalapb_worker_deps",
35+
],
36+
)
37+
2538
scala_library(
2639
name = "scalapb_worker_lib",
2740
srcs = ["ScalaPBWorker.scala"],
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package scripts
2+
3+
import protocgen.{CodeGenApp,CodeGenRequest,CodeGenResponse}
4+
5+
object ScalaPbCodeGenerator extends CodeGenApp {
6+
def process(request: CodeGenRequest): CodeGenResponse = {
7+
try {
8+
scalapb.ScalaPbCodeGenerator.process(request)
9+
10+
} catch {
11+
case e: Throwable =>
12+
val stackStream = new java.io.ByteArrayOutputStream
13+
e.printStackTrace(new java.io.PrintStream(stackStream))
14+
CodeGenResponse.fail(stackStream.toString())
15+
}
16+
}
17+
}

0 commit comments

Comments
 (0)