To use this rule, you'll first need to add the following to your WORKSPACE
file,
which adds a few dependencies needed for ScalaPB:
scala_toolchains(
# Other toolchains settings...
scala_proto = True,
scala_proto_options = [
"grpc",
"flat_package",
"scala3_sources",
],
)
scala_register_toolchains()
Then you can import scala_proto_library
in any BUILD
file like this:
load("@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(
"@rules_scala//scala_proto:scala_proto_toolchain.bzl",
"scala_proto_toolchain",
)
scala_proto_toolchain(
name = "scala_proto_toolchain",
generators_opts = {
"scala": [
"grpc",
"flat_package",
"scala3_sources",
]
},
visibility = ["//visibility:public"],
)
toolchain(
name = "scalapb_toolchain",
toolchain = ":scala_proto_toolchain",
toolchain_type = "@rules_scala//scala_proto:toolchain_type",
visibility = ["//visibility:public"],
)
Attribute name | Description |
---|---|
name | Name, required A unique name for this toolchain. |
generators_opts | List of strings, optional Additional protobuf options like 'grpc', 'flat_package' or 'scala3_sources'. |
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. |
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("@rules_scala//scala:providers.bzl", "declare_deps_provider")
load(
"@rules_scala//scala_proto:scala_proto_toolchain.bzl",
"scala_proto_deps_toolchain",
)
scala_proto_deps_toolchain(
name = "default_deps_toolchain_impl",
visibility = ["//visibility:public"],
dep_providers = [
":my_compile_deps",
],
)
toolchain(
name = "default_deps_toolchain",
toolchain = ":default_deps_toolchain_impl",
toolchain_type = "@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"],
)
Attribute name | Description |
---|---|
dep_providers | List of labels, optional (has default) allows injection of gRPC (deps_id - scalapb_worker_deps ) and ScalaPB (deps_id scalapb_compile_deps ) dependencies |