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

Bump ScalaPB, protoc-bridge, gRPC, and Guava deps, and add ProtobufAdapters and ScalaPBCodeGenerator wrappers #1648

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
1 change: 1 addition & 0 deletions scala/private/macros/scala_repositories.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ def _artifact_ids(scala_version):
"io_bazel_rules_scala_scala_library",
"io_bazel_rules_scala_scala_parser_combinators",
"io_bazel_rules_scala_scala_xml",
"org_scala_lang_modules_scala_collection_compat",
]

if scala_version.startswith("2."):
Expand Down
23 changes: 10 additions & 13 deletions scala_proto/BUILD
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
load(
"//scala_proto:scala_proto_toolchain.bzl",
"scala_proto_deps_toolchain",
"scala_proto_toolchain",
)
load("//scala:providers.bzl", "declare_deps_provider")
load(
"//scala_proto/default:default_deps.bzl",
"DEFAULT_SCALAPB_COMPILE_DEPS",
"DEFAULT_SCALAPB_GRPC_DEPS",
"DEFAULT_SCALAPB_WORKER_DEPS",
)
load("//scala:providers.bzl", "declare_deps_provider")
load("//scala_proto/private:toolchain_deps.bzl", "export_scalapb_toolchain_deps")
load(
"//scala_proto:scala_proto_toolchain.bzl",
"scala_proto_deps_toolchain",
"scala_proto_toolchain",
)

toolchain_type(
name = "toolchain_type",
Expand Down Expand Up @@ -37,7 +38,7 @@ scala_proto_toolchain(
toolchain(
name = "default_toolchain",
toolchain = ":default_toolchain_impl",
toolchain_type = "@io_bazel_rules_scala//scala_proto:toolchain_type",
toolchain_type = "//scala_proto:toolchain_type",
visibility = ["//visibility:public"],
)

Expand All @@ -58,7 +59,7 @@ scala_proto_toolchain(
toolchain(
name = "enable_all_options_toolchain",
toolchain = ":enable_all_options_toolchain_impl",
toolchain_type = "@io_bazel_rules_scala//scala_proto:toolchain_type",
toolchain_type = "//scala_proto:toolchain_type",
visibility = ["//visibility:public"],
)

Expand All @@ -80,11 +81,7 @@ declare_deps_provider(
name = "scalapb_worker_deps_provider",
deps_id = "scalapb_worker_deps",
visibility = ["//visibility:public"],
deps = [
"@com_google_protobuf//:protobuf_java",
"@scala_proto_rules_scalapb_compilerplugin",
"@scala_proto_rules_scalapb_protoc_bridge",
],
deps = DEFAULT_SCALAPB_WORKER_DEPS,
)

export_scalapb_toolchain_deps(
Expand Down
22 changes: 17 additions & 5 deletions scala_proto/default/default_deps.bzl
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
# These are the compile/runtime dependencies needed for scalapb compilation
# and grpc compile/runtime.
#
# In a complex environment you may want to update the toolchain to not refer to these anymore
# If you are using a resolver (like bazel-deps) that can export compile + runtime jar paths
# for you, then you should only need much shorter dependency lists. This needs to be the unrolled
# transitive path to be used without such a facility.
#
# In a complex environment you may want to update the toolchain to not refer to
# these anymore If you are using a resolver (like bazel-deps) that can export
# compile + runtime jar paths for you, then you should only need much shorter
# dependency lists. This needs to be the unrolled transitive path to be used
# without such a facility.

load("//scala:scala_cross_version_select.bzl", "select_for_scala_version")

DEFAULT_SCALAPB_COMPILE_DEPS = [
"//scala/private/toolchain_deps:scala_library_classpath",
"@com_google_protobuf//:protobuf_java",
Expand Down Expand Up @@ -41,3 +44,12 @@ DEFAULT_SCALAPB_GRPC_DEPS = [
"@scala_proto_rules_perfmark_api",
"@scala_proto_rules_scalapb_runtime_grpc",
]

DEFAULT_SCALAPB_WORKER_DEPS = [
"@com_google_protobuf//:protobuf_java",
"@scala_proto_rules_scalapb_compilerplugin",
"@scala_proto_rules_scalapb_protoc_bridge",
] + select_for_scala_version(
any_2_11 = [],
since_2_12 = ["@scala_proto_rules_scalapb_protoc_gen"],
)
101 changes: 66 additions & 35 deletions scala_proto/default/repositories.bzl
Original file line number Diff line number Diff line change
@@ -1,47 +1,78 @@
load("//scala:scala_cross_version.bzl", "default_maven_server_urls")
load("//third_party/repositories:repositories.bzl", "repositories")
load("@io_bazel_rules_scala_config//:config.bzl", "SCALA_VERSION")

# Needed by scalafmt
SCALAPB_COMPILE_ARTIFACT_IDS = [
"com_google_protobuf_protobuf_java",
"com_lihaoyi_fastparse",
"com_lihaoyi_sourcecode",
"scala_proto_rules_scalapb_lenses",
"scala_proto_rules_scalapb_runtime",
]

# Needed by twitter_scrooge
GUAVA_ARTIFACT_IDS = [
"com_google_code_findbugs_jsr305",
"com_google_errorprone_error_prone_annotations",
"com_google_j2objc_j2objc_annotations",
"io_bazel_rules_scala_guava",
"io_bazel_rules_scala_failureaccess",
"org_checkerframework_checker_qual",
]

def scala_proto_artifact_ids(scala_version):
return ([] if scala_version.startswith("2.11.") else [
"dev_dirs_directories",
"scala_proto_rules_scalapb_protoc_gen",
]) + [
"com_google_android_annotations",
"com_google_code_gson_gson",
"org_codehaus_mojo_animal_sniffer_annotations",
"scala_proto_rules_disruptor",
"scala_proto_rules_grpc_api",
"scala_proto_rules_grpc_context",
"scala_proto_rules_grpc_core",
"scala_proto_rules_grpc_netty",
"scala_proto_rules_grpc_protobuf",
"scala_proto_rules_grpc_protobuf_lite",
"scala_proto_rules_grpc_stub",
"scala_proto_rules_grpc_util",
"scala_proto_rules_instrumentation_api",
"scala_proto_rules_netty_buffer",
"scala_proto_rules_netty_codec",
"scala_proto_rules_netty_codec_http",
"scala_proto_rules_netty_codec_http2",
"scala_proto_rules_netty_codec_socks",
"scala_proto_rules_netty_common",
"scala_proto_rules_netty_handler",
"scala_proto_rules_netty_handler_proxy",
"scala_proto_rules_netty_resolver",
"scala_proto_rules_netty_transport",
"scala_proto_rules_netty_transport_native_unix_common",
"scala_proto_rules_opencensus_api",
"scala_proto_rules_opencensus_contrib_grpc_metrics",
"scala_proto_rules_opencensus_impl",
"scala_proto_rules_opencensus_impl_core",
"scala_proto_rules_perfmark_api",
"scala_proto_rules_proto_google_common_protos",
"scala_proto_rules_scalapb_compilerplugin",
"scala_proto_rules_scalapb_protoc_bridge",
"scala_proto_rules_scalapb_runtime_grpc",
] + SCALAPB_COMPILE_ARTIFACT_IDS + GUAVA_ARTIFACT_IDS

def scala_proto_default_repositories(
maven_servers = default_maven_server_urls(),
scala_version = SCALA_VERSION,
overriden_artifacts = {}):
repositories(
for_artifact_ids = [
"com_google_protobuf_protobuf_java",
"com_lihaoyi_fastparse",
"com_lihaoyi_sourcecode",
"io_bazel_rules_scala_guava",
"scala_proto_rules_disruptor",
"scala_proto_rules_instrumentation_api",
"scala_proto_rules_grpc_api",
"scala_proto_rules_grpc_context",
"scala_proto_rules_grpc_core",
"scala_proto_rules_grpc_netty",
"scala_proto_rules_grpc_protobuf",
"scala_proto_rules_grpc_stub",
"scala_proto_rules_netty_buffer",
"scala_proto_rules_netty_codec",
"scala_proto_rules_netty_codec_http",
"scala_proto_rules_netty_codec_http2",
"scala_proto_rules_netty_codec_socks",
"scala_proto_rules_netty_common",
"scala_proto_rules_netty_handler",
"scala_proto_rules_netty_handler_proxy",
"scala_proto_rules_netty_resolver",
"scala_proto_rules_netty_transport",
"scala_proto_rules_opencensus_api",
"scala_proto_rules_opencensus_contrib_grpc_metrics",
"scala_proto_rules_opencensus_impl",
"scala_proto_rules_opencensus_impl_core",
"scala_proto_rules_perfmark_api",
"scala_proto_rules_scalapb_compilerplugin",
"scala_proto_rules_scalapb_lenses",
"scala_proto_rules_scalapb_protoc_bridge",
"scala_proto_rules_scalapb_runtime",
"scala_proto_rules_scalapb_runtime_grpc",
],
scala_version = scala_version,
for_artifact_ids = scala_proto_artifact_ids(scala_version),
maven_servers = maven_servers,
fetch_sources = True,
overriden_artifacts = overriden_artifacts,
)

native.register_toolchains("@io_bazel_rules_scala//scala_proto:default_deps_toolchain")
native.register_toolchains(
str(Label("//scala_proto:default_deps_toolchain")),
)
29 changes: 21 additions & 8 deletions scala_proto/scala_proto_toolchain.bzl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
load("@io_bazel_rules_scala//scala:providers.bzl", "DepsInfo")
load("//scala:providers.bzl", "DepsInfo")

def _generators(ctx):
return dict(
Expand All @@ -7,9 +7,12 @@ def _generators(ctx):
)

def _generators_jars(ctx):
generator_deps = ctx.attr.extra_generator_dependencies + [
ctx.attr._main_generator_dep,
]
return depset(transitive = [
dep[JavaInfo].transitive_runtime_jars
for dep in ctx.attr.extra_generator_dependencies
for dep in generator_deps
])

def _generators_opts(ctx):
Expand Down Expand Up @@ -74,18 +77,20 @@ scala_proto_toolchain = rule(
"code_generator": attr.label(
executable = True,
cfg = "exec",
default = Label("@io_bazel_rules_scala//src/scala/scripts:scalapb_worker"),
default = Label("//src/scala/scripts:scalapb_worker"),
allow_files = True,
),
"main_generator": attr.string(default = "scalapb.ScalaPbCodeGenerator"),
"main_generator": attr.string(
default = "scripts.ScalaPbCodeGenerator",
),
"named_generators": attr.string_dict(),
"extra_generator_dependencies": attr.label_list(
providers = [JavaInfo],
),
"scalac": attr.label(
executable = True,
cfg = "exec",
default = Label("@io_bazel_rules_scala//src/java/io/bazel/rulesscala/scalac"),
default = Label("//src/java/io/bazel/rulesscala/scalac"),
allow_files = True,
),
"protoc": attr.label(
Expand All @@ -105,6 +110,14 @@ scala_proto_toolchain = rule(
[proto rules documentation](https://docs.bazel.build/versions/master/be/protocol-buffer.html#proto_library)
""",
),
"_main_generator_dep": attr.label(
default = Label(
"//src/scala/scripts:scalapb_codegenerator_wrapper",
),
allow_single_file = True,
executable = False,
cfg = "exec",
),
},
)

Expand All @@ -119,9 +132,9 @@ scala_proto_deps_toolchain = rule(
attrs = {
"dep_providers": attr.label_list(
default = [
"@io_bazel_rules_scala//scala_proto:scalapb_compile_deps_provider",
"@io_bazel_rules_scala//scala_proto:scalapb_grpc_deps_provider",
"@io_bazel_rules_scala//scala_proto:scalapb_worker_deps_provider",
Label("//scala_proto:scalapb_compile_deps_provider"),
Label("//scala_proto:scalapb_grpc_deps_provider"),
Label("//scala_proto:scalapb_worker_deps_provider"),
],
cfg = "target",
providers = [DepsInfo],
Expand Down
26 changes: 21 additions & 5 deletions scripts/create_repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,14 @@
KIND_PROJECTOR_VERSION = "0.13.3"
PROTOBUF_JAVA_VERSION = "4.28.3"
JLINE_VERSION = '3.27.1'
SCALAPB_VERSION = '0.9.8'
SCALAPB_VERSION = '0.11.17'
PROTOC_BRIDGE_VERSION = '0.9.7'
GRPC_VERSION = '1.68.1'
GRPC_COMMON_PROTOS_VERSION = '2.48.0'
GRPC_LIBS = ['netty', 'protobuf', 'stub']
GUAVA_VERSION = '33.3.1-jre'

EXCLUDED_ARTIFACTS = set()
EXCLUDED_ARTIFACTS = set(["com.google.guava:listenablefuture"])

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

scalafmt_version = SCALAFMT_VERSION
scalapb_version = SCALAPB_VERSION
protoc_bridge_version = PROTOC_BRIDGE_VERSION

if scala_major == '2.11':
scalafmt_version = '2.7.5'
scalapb_version = '0.9.8'
protoc_bridge_version = '0.7.14'

root_artifacts = [
'com.google.api.grpc:proto-google-common-protos:' +
GRPC_COMMON_PROTOS_VERSION,
f'com.google.guava:guava:{GUAVA_VERSION}',
f'com.google.protobuf:protobuf-java:{PROTOBUF_JAVA_VERSION}',
f'com.thesamet.scalapb:compilerplugin_{scala_2_major}:' +
scalapb_version,
f'com.thesamet.scalapb:protoc-bridge_{scala_2_major}:' +
protoc_bridge_version,
f'com.thesamet.scalapb:scalapb-runtime_{scala_2_major}:' +
scalapb_version,
f'com.thesamet.scalapb:scalapb-runtime-grpc_{scala_2_major}:' +
scalapb_version,
f'org.scala-lang.modules:scala-parser-combinators_{scala_2_major}:' +
PARSER_COMBINATORS_VERSION,
f'org.scalameta:scalafmt-core_{scala_2_major}:{scalafmt_version}',
f'org.scalatest:scalatest_{scalatest_major}:{SCALATEST_VERSION}',
f'org.scala-lang:scala-compiler:{scala_2_version}',
f'org.scala-lang:scala-library:{scala_2_version}',
f'org.scala-lang:scala-reflect:{scala_2_version}',
f'org.scala-lang:scalap:{scala_2_version}',
f'org.scalameta:scalafmt-core_{scala_2_major}:{scalafmt_version}',
f'org.scalatest:scalatest_{scalatest_major}:{SCALATEST_VERSION}',
f'org.typelevel:kind-projector_{scala_2_version}:' +
KIND_PROJECTOR_VERSION,
]
] + [f'io.grpc:grpc-{lib}:{GRPC_VERSION}' for lib in GRPC_LIBS]

if scala_version == max_scala_2_version or is_scala_3:
# Since the Scala 2.13 compiler is included in Scala 3 deps.
Expand Down
13 changes: 13 additions & 0 deletions src/scala/scripts/BUILD
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
load("//scala:scala.bzl", "scala_binary", "scala_library")
load("//scala:scala_cross_version_select.bzl", "select_for_scala_version")

scala_library(
name = "scrooge_worker_lib",
Expand All @@ -22,6 +23,18 @@ scala_binary(
],
)

scala_library(
name = "scalapb_codegenerator_wrapper",
srcs = select_for_scala_version(
any_2_11 = ["ScalaPbCodeGeneratorWrapper_2_11.scala"],
since_2_12 = ["ScalaPbCodeGeneratorWrapper.scala"],
),
visibility = ["//visibility:public"],
deps = [
"//scala_proto:scalapb_worker_deps",
],
)

scala_library(
name = "scalapb_worker_lib",
srcs = ["ScalaPBWorker.scala"],
Expand Down
17 changes: 17 additions & 0 deletions src/scala/scripts/ScalaPbCodeGeneratorWrapper.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package scripts

import protocgen.{CodeGenApp,CodeGenRequest,CodeGenResponse}

object ScalaPbCodeGenerator extends CodeGenApp {
def process(request: CodeGenRequest): CodeGenResponse = {
try {
scalapb.ScalaPbCodeGenerator.process(request)

} catch {
case e: Throwable =>
val stackStream = new java.io.ByteArrayOutputStream
e.printStackTrace(new java.io.PrintStream(stackStream))
CodeGenResponse.fail(stackStream.toString())
}
}
}
Loading