blob: 71bde7c0f4f36827e7b08eb854902408f9070414 [file]
package main
var scalaWorkspaceTemplate = mustTemplate(`load("@build_stack_rules_proto//{{ .Lang.Dir }}:deps.bzl", "{{ .Rule.Name }}")
{{ .Rule.Name }}()
# rules_go used here to compile a wrapper around the protoc-gen-scala plugin
load("@io_bazel_rules_go//go:deps.bzl", "go_register_toolchains", "go_rules_dependencies")
go_rules_dependencies()
go_register_toolchains()
load("@io_bazel_rules_scala//scala:scala.bzl", "scala_repositories")
scala_repositories()
load("@io_bazel_rules_scala//scala:toolchains.bzl", "scala_register_toolchains")
scala_register_toolchains()
load("@io_bazel_rules_scala//scala_proto:scala_proto.bzl", "scala_proto_repositories")
scala_proto_repositories()`)
var scalaLibraryRuleTemplate = mustTemplate(`load("@build_stack_rules_proto//{{ .Lang.Dir }}:{{ .Lang.Name }}_{{ .Rule.Kind }}_compile.bzl", "{{ .Lang.Name }}_{{ .Rule.Kind }}_compile")
load("@io_bazel_rules_scala//scala:scala.bzl", "scala_library")
def {{ .Rule.Name }}(**kwargs):
# Compile protos
name_pb = kwargs.get("name") + "_pb"
{{ .Lang.Name }}_{{ .Rule.Kind }}_compile(
name = name_pb,
**{k: v for (k, v) in kwargs.items() if k in ("deps", "verbose")} # Forward args
)
# Create {{ .Lang.Name }} library
scala_library(
name = kwargs.get("name"),
srcs = [name_pb],
deps = [Label("//scala:{{ .Rule.Kind }}_deps")],
exports = [
Label("//scala:{{ .Rule.Kind }}_deps"),
],
visibility = kwargs.get("visibility"),
)`)
func makeScala() *Language {
return &Language{
Dir: "scala",
Name: "scala",
Notes: mustTemplate("Rules for `scala_grpc_{compile|library}` don't produce code that compiles! Use `@//io_bazel_rules_scala//scala_proto:scala_proto.bzl` instead"),
Flags: commonLangFlags,
SkipDirectoriesMerge: true,
Rules: []*Rule{
&Rule{
Name: "scala_proto_compile",
Kind: "proto",
Implementation: aspectRuleTemplate,
Plugins: []string{"//scala:scala"},
WorkspaceExample: scalaWorkspaceTemplate,
BuildExample: protoCompileExampleTemplate,
Doc: "Generates *.scala protobuf artifacts",
Attrs: aspectProtoCompileAttrs,
},
&Rule{
Name: "scala_grpc_compile",
Kind: "grpc",
Implementation: aspectRuleTemplate,
Plugins: []string{"//scala:grpc_scala"},
WorkspaceExample: scalaWorkspaceTemplate,
BuildExample: grpcCompileExampleTemplate,
Doc: "Generates *.scala protobuf+gRPC artifacts",
Attrs: aspectProtoCompileAttrs,
Experimental: true,
},
&Rule{
Name: "scala_proto_library",
Kind: "proto",
Implementation: scalaLibraryRuleTemplate,
WorkspaceExample: scalaWorkspaceTemplate,
BuildExample: protoLibraryExampleTemplate,
Doc: "Generates *.scala protobuf library",
Attrs: aspectProtoCompileAttrs,
},
&Rule{
Name: "scala_grpc_library",
Kind: "grpc",
Implementation: scalaLibraryRuleTemplate,
WorkspaceExample: scalaWorkspaceTemplate,
BuildExample: grpcLibraryExampleTemplate,
Doc: "Generates *.scala protobuf+gRPC library",
Attrs: aspectProtoCompileAttrs,
Experimental: true,
},
},
}
}