diff --git a/docs/stardoc/scala_proto.md b/docs/stardoc/scala_proto.md index eb732632..825b0891 100644 --- a/docs/stardoc/scala_proto.md +++ b/docs/stardoc/scala_proto.md @@ -49,7 +49,7 @@ See example use in [/tests/proto/BUILD](/tests/proto/BUILD) ## scala_proto_toolchain
-scala_proto_toolchain(name, compiler, compiler_supports_workers)
+scala_proto_toolchain(name, compiler, compiler_supports_workers, generator_params)
 
@@ -65,6 +65,7 @@ scala_proto_toolchain( name = "scalapb_toolchain_example", compiler = ":worker", compiler_supports_workers = True, + generator_params = "grpc,java_conversions", visibility = ["//visibility:public"], ) @@ -117,6 +118,15 @@ toolchain( Boolean; optional + + generator_params + + String; optional +

+ Generator params to pass to the scala PB compiler (ie java_conversions, flat_package, grpc) +

+ + diff --git a/rules/scala_proto.bzl b/rules/scala_proto.bzl index 28cb5c63..f678ad30 100644 --- a/rules/scala_proto.bzl +++ b/rules/scala_proto.bzl @@ -33,6 +33,7 @@ def _scala_proto_toolchain_implementation(ctx): return [platform_common.ToolchainInfo( compiler = ctx.attr.compiler, compiler_supports_workers = ctx.attr.compiler_supports_workers, + generator_params = ctx.attr.generator_params, )] scala_proto_toolchain = rule( @@ -44,6 +45,10 @@ scala_proto_toolchain = rule( cfg = "host", ), "compiler_supports_workers": attr.bool(default = False), + "generator_params": attr.string( + doc = "Generator params to pass to the scala PB compiler (ie java_conversions, flat_package, grpc)", + default = "", + ), }, doc = """ Specifies a toolchain of the `@rules_scala_annex//rules/scala_proto:compiler_toolchain_type` toolchain type. @@ -58,6 +63,7 @@ scala_proto_toolchain( name = "scalapb_toolchain_example", compiler = ":worker", compiler_supports_workers = True, + generator_params = "grpc,java_conversions", visibility = ["//visibility:public"], ) diff --git a/rules/scala_proto/private/ScalaProtoWorker.scala b/rules/scala_proto/private/ScalaProtoWorker.scala index 195e0f9a..c4844415 100644 --- a/rules/scala_proto/private/ScalaProtoWorker.scala +++ b/rules/scala_proto/private/ScalaProtoWorker.scala @@ -21,6 +21,10 @@ object ScalaProtoWorker extends WorkerMain[Unit] { .help("Output dir") .metavar("output_dir") .`type`(Arguments.fileType.verifyCanCreate) + parser + .addArgument("--generator_params") + .help("Generator params to pass to scala_out") + .metavar("generator_params") parser .addArgument("sources") .help("Source files") @@ -40,12 +44,18 @@ object ScalaProtoWorker extends WorkerMain[Unit] { val scalaOut = namespace.get[File]("output_dir").toPath Files.createDirectories(scalaOut) - val params = s"--scala_out=$scalaOut" :: sources.map(_.getPath) + val generatorParams = namespace.get[String]("generator_params") + val params = if (generatorParams == null) { + s"--scala_out=$scalaOut" :: sources.map(_.getPath) + } else { + s"--scala_out=$generatorParams:$scalaOut" :: sources.map(_.getPath) + } ProtocBridge.runWithGenerators( protoc = a => com.github.os72.protocjar.Protoc.runProtoc(a.toArray), namedGenerators = List("scala" -> ScalaPbCodeGenerator), - params = params) + params = params + ) } } diff --git a/rules/scala_proto/private/core.bzl b/rules/scala_proto/private/core.bzl index 44d7277e..0d39a19e 100644 --- a/rules/scala_proto/private/core.bzl +++ b/rules/scala_proto/private/core.bzl @@ -32,6 +32,8 @@ def scala_proto_library_implementation(ctx): args = ctx.actions.args() args.add("--output_dir", gendir.path) + if compiler.generator_params: + args.add("--generator_params", compiler.generator_params) args.add_all("--", transitive_sources) args.set_param_file_format("multiline") args.use_param_file("@%s", use_always = True)