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()
load("@io_bazel_rules_scala//scala_proto:toolchains.bzl", "scala_proto_register_toolchains")
scala_proto_register_toolchains()
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. |
If you want to have a different configuration from scala_proto_repositories
,
you can configure ScalaPB options and dependencies via toolchains.
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",
with_grpc = False,
with_flat_package = False,
with_single_line_to_string = False,
visibility = ["//visibility:public"],
)
toolchain(
name = "scalapb_toolchain",
toolchain = ":scala_proto_toolchain",
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 |
scalac | Label, optional (has default) Target for scalac. A sensible default is provided. |
To configure dependencies, configure a different scala_proto_deps_toolchain
and declare it in a BUILD
file:
load("@io_bazel_rules_scala//scala_proto:scala_proto_toolchain.bzl", "scala_proto_deps_toolchain")
load("@io_bazel_rules_scala//scala:providers.bzl", "declare_deps_provider")
scala_proto_deps_toolchain(
name = "default_deps_toolchain_impl",
visibility = ["//visibility:public"],
dep_providers = [
":my_compile_deps",
":my_grpc_deps",
],
)
toolchain(
name = "default_deps_toolchain",
toolchain = ":default_deps_toolchain_impl",
toolchain_type = "@io_bazel_rules_scala//scala_proto:deps_toolchain_type",
)
declare_deps_provider(
name = "my_compile_deps",
deps_id = "scalapb_compile_deps",
deps = ["@dep1", "@dep2"],
visibility = ["//visibility:public"],
)
declare_deps_provider(
name = "my_grpc_deps",
deps_id = "scalapb_grpc_deps",
deps = ["@dep3", "@dep4"],
visibility = ["//visibility:public"],
)
Attribute name | Description |
---|---|
dep_providers | List of labels, optional (has default) allows inject gRPC (deps_id - scalapb_grpc_deps ) and ScalaPB (deps_id scalapb_compile_deps ) dependencies |