To use this rule, you'll first need to add the following to your WORKSPACE
file,
which adds a few dependencies needed for ScalaPB:
load("@io_bazel_rules_scala//scala_proto:scala_proto.bzl", "scala_proto_repositories")
scala_proto_repositories(scala_version = "2.12.8") # or whatever scala_version you're on
Then you can import scala_proto_library
in any BUILD
file like this:
load("@io_bazel_rules_scala//scala_proto:scala_proto.bzl", "scala_proto_library")
scala_proto_library(
name = "my_scala_proto_lib",
deps = [":my_target"],
)
scala_proto_library
generates a Scala library of Scala proto bindings
generated by the ScalaPB compiler.
Attribute name | Description |
---|---|
name | Name, required A unique name for this target. |
deps | List of labels, required A list of proto_library targets for which to generate Scala code. |
To configure ScalaPB options, configure a different scala_proto_toolchain
and declare it in a BUILD
file:
load("@io_bazel_rules_scala//scala_proto:scala_proto_toolchain.bzl", "scala_proto_toolchain")
scala_proto_toolchain(
name = "scala_proto_toolchain_configuration",
with_grpc = False,
with_flat_package = False,
with_single_line_to_string = False,
visibility = ["//visibility:public"],
)
toolchain(
name = "scalapb_toolchain",
toolchain = ":scala_proto_toolchain_configuration",
toolchain_type = "@io_bazel_rules_scala//scala_proto:toolchain_type",
visibility = ["//visibility:public"],
)
Attribute name | Description |
---|---|
name | Name, required A unique name for this toolchain. |
with_grpc | boolean, optional (default False) Enables generation of grpc service bindings for services. |
with_flat_package | boolean, optional (default False) When true, ScalaPB will not append the protofile base name to the package name. |
with_single_line_to_string | boolean, optional (default False) Enables generation of toString() methods that use a single line format. |
blacklisted_protos | List of labels, optional List of protobuf targets to exclude from recursive building. |
code_generator | Label, optional (has default) Which code generator to use. A sensible default is provided. |
named_generators | String dict, optional |
extra_generator_dependencies | List of labels, optional |
grpc_deps | List of labels, optional (has default) gRPC dependencies. A sensible default is provided. |
implicit_compile_deps | List of labels, optional (has default) ScalaPB dependencies. A sensible default is provided. |
scalac | Label, optional (has default) Target for scalac. A sensible default is provided. |