Skip to content

Commit 3b147a8

Browse files
authored
Add stackb:rules_proto:grpc_zio_scala_library (#350)
* Add support for scalapb:zio-grpc * Add zio maven deps
1 parent 5428336 commit 3b147a8

File tree

11 files changed

+349
-0
lines changed

11 files changed

+349
-0
lines changed

WORKSPACE

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,22 @@ load("@maven_akka//:defs.bzl", pinned_maven_akka_install = "pinned_maven_install
259259

260260
pinned_maven_akka_install()
261261

262+
# bazel run @maven_zio//:pin, but first comment out the "maven_install_json"
263+
# (put it back once pinned again)
264+
maven_install(
265+
name = "maven_zio",
266+
artifacts = [
267+
"com.thesamet.scalapb.zio-grpc:zio-grpc-codegen_2.12:0.6.0",
268+
],
269+
fetch_sources = True,
270+
maven_install_json = "//:maven_zio_install.json",
271+
repositories = ["https://repo1.maven.org/maven2"],
272+
)
273+
274+
load("@maven_zio//:defs.bzl", pinned_maven_zio_install = "pinned_maven_install")
275+
276+
pinned_maven_zio_install()
277+
262278
# ----------------------------------------------------
263279
# Closure
264280
# ----------------------------------------------------

language/protobuf/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ go_library(
1818
"//pkg/plugin/grpc/grpcweb",
1919
"//pkg/plugin/grpcecosystem/grpcgateway",
2020
"//pkg/plugin/scalapb/scalapb",
21+
"//pkg/plugin/scalapb/zio_grpc",
2122
"//pkg/plugin/stackb/grpc_js",
2223
"//pkg/plugin/stephenh/ts-proto",
2324
"//pkg/rule/rules_cc",

language/protobuf/protobuf.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
_ "github.com/stackb/rules_proto/pkg/plugin/grpc/grpcweb"
1616
_ "github.com/stackb/rules_proto/pkg/plugin/grpcecosystem/grpcgateway"
1717
_ "github.com/stackb/rules_proto/pkg/plugin/scalapb/scalapb"
18+
_ "github.com/stackb/rules_proto/pkg/plugin/scalapb/zio_grpc"
1819
_ "github.com/stackb/rules_proto/pkg/plugin/stackb/grpc_js"
1920
_ "github.com/stackb/rules_proto/pkg/plugin/bufbuild"
2021
_ "github.com/stackb/rules_proto/pkg/plugin/stephenh/ts-proto"

maven_zio_install.json

Lines changed: 179 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,179 @@
1+
{
2+
"__AUTOGENERATED_FILE_DO_NOT_MODIFY_THIS_FILE_MANUALLY": "THERE_IS_NO_DATA_ONLY_ZUUL",
3+
"__INPUT_ARTIFACTS_HASH": 799888365,
4+
"__RESOLVED_ARTIFACTS_HASH": 669377701,
5+
"artifacts": {
6+
"com.google.protobuf:protobuf-java": {
7+
"shasums": {
8+
"jar": "6a9a2dff91dcf71f85be71ae971f6164b5a631dcd34bff08f0618535ca44ad02",
9+
"sources": "98118edf28c74f173b25d8fce03f86ff95d61009df0c66324333573ec842f5d3"
10+
},
11+
"version": "3.19.6"
12+
},
13+
"com.thesamet.scalapb.zio-grpc:zio-grpc-codegen_2.12": {
14+
"shasums": {
15+
"jar": "0a47494a502470e5a7e13a55a2a91b020ef3cef7642932ae0332a9d53fed2bd4",
16+
"sources": "a2ea65c99beb8375f16f79a57b8f69cf396245d228f43f72d8a3b8fedc494e95"
17+
},
18+
"version": "0.6.0"
19+
},
20+
"com.thesamet.scalapb:compilerplugin_2.12": {
21+
"shasums": {
22+
"jar": "7fae6c1e7301fba88cef19551027dee077208799130c8f8bbfe3e8addf0b5aa9",
23+
"sources": "1c0ae73755353a67f3bd5e50496243c1edabeadbdff895e56234e9e0d601b8af"
24+
},
25+
"version": "0.11.13"
26+
},
27+
"com.thesamet.scalapb:protoc-bridge_2.12": {
28+
"shasums": {
29+
"jar": "5bbecd8ede37b266740ea523d65ebec27cdfbded40850013667ea9ed23be76d1",
30+
"sources": "c2287667773b171051065ceb76adfbe9f6dc1f4e4fff03e0f0b288d659b7a47c"
31+
},
32+
"version": "0.9.6"
33+
},
34+
"com.thesamet.scalapb:protoc-gen_2.12": {
35+
"shasums": {
36+
"jar": "9483c434afe0bdb9e68da0a4a9b76f76a350ef4f6f397bda23f8fa6061153727",
37+
"sources": "da917be8e7ba6c8eccdb5b155c9c515fbf2ef9e295b30934c27e2cf6519ab8b5"
38+
},
39+
"version": "0.9.6"
40+
},
41+
"dev.dirs:directories": {
42+
"shasums": {
43+
"jar": "6d18fe25aa30b7e08b908cd21151d8f96e22965c640acd7751add9bbfe6137d4",
44+
"sources": "192050e3a2a0eba7f22745765aaaf567ce6d515fe6a992688b4e262e9f14947b"
45+
},
46+
"version": "26"
47+
},
48+
"org.scala-lang.modules:scala-collection-compat_2.12": {
49+
"shasums": {
50+
"jar": "873344f3788c84b6314afd20334b18a0821109a3635ecc71dac3598325e030ac",
51+
"sources": "70682c87d4b7c3fd21f1f7a2c3a09fce812bab6d5aad2fbc5a68f1aa3f48e0dd"
52+
},
53+
"version": "2.9.0"
54+
},
55+
"org.scala-lang:scala-library": {
56+
"shasums": {
57+
"jar": "e51e6636c003359e106bea4ad99def70e613c290190c8c84f10f9560dd5b00ae",
58+
"sources": "a34db9ab4b38c57f998e8f671b33762e2d6c3e39b8abf6fb8660a417447fa449"
59+
},
60+
"version": "2.12.18"
61+
}
62+
},
63+
"dependencies": {
64+
"com.thesamet.scalapb.zio-grpc:zio-grpc-codegen_2.12": [
65+
"com.thesamet.scalapb:compilerplugin_2.12",
66+
"org.scala-lang:scala-library"
67+
],
68+
"com.thesamet.scalapb:compilerplugin_2.12": [
69+
"com.google.protobuf:protobuf-java",
70+
"com.thesamet.scalapb:protoc-gen_2.12",
71+
"org.scala-lang.modules:scala-collection-compat_2.12",
72+
"org.scala-lang:scala-library"
73+
],
74+
"com.thesamet.scalapb:protoc-bridge_2.12": [
75+
"dev.dirs:directories",
76+
"org.scala-lang:scala-library"
77+
],
78+
"com.thesamet.scalapb:protoc-gen_2.12": [
79+
"com.thesamet.scalapb:protoc-bridge_2.12",
80+
"org.scala-lang:scala-library"
81+
],
82+
"org.scala-lang.modules:scala-collection-compat_2.12": [
83+
"org.scala-lang:scala-library"
84+
]
85+
},
86+
"packages": {
87+
"com.google.protobuf:protobuf-java": [
88+
"com.google.protobuf",
89+
"com.google.protobuf.compiler"
90+
],
91+
"com.thesamet.scalapb.zio-grpc:zio-grpc-codegen_2.12": [
92+
"scalapb.zio_grpc"
93+
],
94+
"com.thesamet.scalapb:compilerplugin_2.12": [
95+
"scalapb",
96+
"scalapb.compiler",
97+
"scalapb.internal",
98+
"scalapb.options",
99+
"scalapb.options.compiler"
100+
],
101+
"com.thesamet.scalapb:protoc-bridge_2.12": [
102+
"protocbridge",
103+
"protocbridge.codegen",
104+
"protocbridge.frontend"
105+
],
106+
"com.thesamet.scalapb:protoc-gen_2.12": [
107+
"protocgen"
108+
],
109+
"dev.dirs:directories": [
110+
"dev.dirs"
111+
],
112+
"org.scala-lang.modules:scala-collection-compat_2.12": [
113+
"scala.annotation",
114+
"scala.collection.compat",
115+
"scala.collection.compat.immutable",
116+
"scala.jdk",
117+
"scala.jdk.javaapi",
118+
"scala.util",
119+
"scala.util.control.compat"
120+
],
121+
"org.scala-lang:scala-library": [
122+
"scala",
123+
"scala.annotation",
124+
"scala.annotation.meta",
125+
"scala.annotation.unchecked",
126+
"scala.beans",
127+
"scala.collection",
128+
"scala.collection.concurrent",
129+
"scala.collection.convert",
130+
"scala.collection.generic",
131+
"scala.collection.immutable",
132+
"scala.collection.mutable",
133+
"scala.collection.parallel",
134+
"scala.collection.parallel.immutable",
135+
"scala.collection.parallel.mutable",
136+
"scala.collection.script",
137+
"scala.compat",
138+
"scala.concurrent",
139+
"scala.concurrent.duration",
140+
"scala.concurrent.forkjoin",
141+
"scala.concurrent.impl",
142+
"scala.io",
143+
"scala.math",
144+
"scala.ref",
145+
"scala.reflect",
146+
"scala.reflect.macros.internal",
147+
"scala.runtime",
148+
"scala.runtime.java8",
149+
"scala.sys",
150+
"scala.sys.process",
151+
"scala.text",
152+
"scala.util",
153+
"scala.util.control",
154+
"scala.util.hashing",
155+
"scala.util.matching"
156+
]
157+
},
158+
"repositories": {
159+
"https://repo1.maven.org/maven2/": [
160+
"com.google.protobuf:protobuf-java",
161+
"com.google.protobuf:protobuf-java:jar:sources",
162+
"com.thesamet.scalapb.zio-grpc:zio-grpc-codegen_2.12",
163+
"com.thesamet.scalapb.zio-grpc:zio-grpc-codegen_2.12:jar:sources",
164+
"com.thesamet.scalapb:compilerplugin_2.12",
165+
"com.thesamet.scalapb:compilerplugin_2.12:jar:sources",
166+
"com.thesamet.scalapb:protoc-bridge_2.12",
167+
"com.thesamet.scalapb:protoc-bridge_2.12:jar:sources",
168+
"com.thesamet.scalapb:protoc-gen_2.12",
169+
"com.thesamet.scalapb:protoc-gen_2.12:jar:sources",
170+
"dev.dirs:directories",
171+
"dev.dirs:directories:jar:sources",
172+
"org.scala-lang.modules:scala-collection-compat_2.12",
173+
"org.scala-lang.modules:scala-collection-compat_2.12:jar:sources",
174+
"org.scala-lang:scala-library",
175+
"org.scala-lang:scala-library:jar:sources"
176+
]
177+
},
178+
"version": "2"
179+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test")
2+
3+
go_library(
4+
name = "zio_grpc",
5+
srcs = ["protoc_gen_zio_grpc.go"],
6+
importpath = "github.com/stackb/rules_proto/pkg/plugin/scalapb/zio_grpc",
7+
visibility = ["//visibility:public"],
8+
deps = [
9+
"//pkg/protoc",
10+
"@bazel_gazelle//label:go_default_library",
11+
],
12+
)
13+
14+
go_test(
15+
name = "zio_grpc_test",
16+
srcs = ["protoc_gen_zio_grpc_test.go"],
17+
deps = [
18+
":zio_grpc",
19+
"//pkg/plugintest",
20+
],
21+
)
22+
23+
filegroup(
24+
name = "all_files",
25+
testonly = True,
26+
srcs = [
27+
"BUILD.bazel",
28+
] + glob(["*.go"]),
29+
visibility = ["//pkg:__pkg__"],
30+
)
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package zio_grpc
2+
3+
import (
4+
"path"
5+
6+
"github.com/bazelbuild/bazel-gazelle/label"
7+
"github.com/stackb/rules_proto/pkg/protoc"
8+
)
9+
10+
const ZioGrpcPluginName = "scalapb:zio-grpc:protoc-gen-zio-grpc"
11+
12+
func init() {
13+
protoc.Plugins().MustRegisterPlugin(&ProtocGenZioGrpcPlugin{})
14+
}
15+
16+
// ProtocGenZioGrpcPlugin implements Plugin for the zio-grpc plugin.
17+
type ProtocGenZioGrpcPlugin struct{}
18+
19+
// Name implements part of the Plugin interface.
20+
func (p *ProtocGenZioGrpcPlugin) Name() string {
21+
return ZioGrpcPluginName
22+
}
23+
24+
// Configure implements part of the Plugin interface.
25+
func (p *ProtocGenZioGrpcPlugin) Configure(ctx *protoc.PluginContext) *protoc.PluginConfiguration {
26+
if !protoc.HasServices(ctx.ProtoLibrary.Files()...) {
27+
return nil
28+
}
29+
30+
srcjar := ctx.ProtoLibrary.BaseName() + "_zio_grpc.srcjar"
31+
if ctx.Rel != "" {
32+
srcjar = path.Join(ctx.Rel, srcjar)
33+
}
34+
35+
return &protoc.PluginConfiguration{
36+
Label: label.New("build_stack_rules_proto", "plugin/scalapb/zio-grpc", "protoc-gen-zio-grpc"),
37+
Outputs: []string{srcjar},
38+
Options: ctx.PluginConfig.GetOptions(),
39+
}
40+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package zio_grpc_test
2+
3+
import (
4+
"testing"
5+
6+
"github.com/stackb/rules_proto/pkg/plugin/scalapb/zio_grpc"
7+
"github.com/stackb/rules_proto/pkg/plugintest"
8+
)
9+
10+
func TestProtoGenZioGrpcPlugin(t *testing.T) {
11+
plugintest.Cases(t, &zio_grpc.ProtocGenZioGrpcPlugin{}, map[string]plugintest.Case{
12+
"empty file": {
13+
Input: "",
14+
Directives: plugintest.WithDirectives(
15+
"proto_plugin", "zio implementation scalapb:zio-grpc:protoc-gen-zio-grpc",
16+
),
17+
PluginName: "zio",
18+
SkipIntegration: true,
19+
},
20+
"only messages, no srcjar produced": {
21+
Input: "package pkg;\n\nmessage M{}",
22+
Directives: plugintest.WithDirectives(
23+
"proto_plugin", "zio implementation scalapb:zio-grpc:protoc-gen-zio-grpc",
24+
),
25+
PluginName: "zio",
26+
SkipIntegration: true,
27+
},
28+
"with service": {
29+
Input: "package pkg;\n\nservice S{}",
30+
Directives: plugintest.WithDirectives(
31+
"proto_plugin", "zio implementation scalapb:zio-grpc:protoc-gen-zio-grpc",
32+
),
33+
PluginName: "zio",
34+
Configuration: plugintest.WithConfiguration(
35+
plugintest.WithLabel(t, "@build_stack_rules_proto//plugin/scalapb/zio-grpc:protoc-gen-zio-grpc"),
36+
plugintest.WithOutputs("test_zio_grpc.srcjar"),
37+
),
38+
SkipIntegration: true,
39+
},
40+
})
41+
}

pkg/rule/rules_scala/scala_library.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,11 @@ import (
2020

2121
const (
2222
GrpcscalaLibraryRuleName = "grpc_scala_library"
23+
GrpcZioscalaLibraryRuleName = "grpc_zio_scala_library"
2324
ProtoscalaLibraryRuleName = "proto_scala_library"
2425
protoScalaLibraryRuleSuffix = "_proto_scala_library"
2526
grpcScalaLibraryRuleSuffix = "_grpc_scala_library"
27+
grpcZioScalaLibraryRuleSuffix = "_grpc_zio_scala_library"
2628
scalaPbPluginOptionsPrivateKey = "_scalapb_plugin"
2729
akkaGrpcPluginOptionsPrivateKey = "_akka_grpc_plugin"
2830
scalapbOptionsName = "(scalapb.options)"
@@ -43,6 +45,12 @@ func init() {
4345
ruleSuffix: grpcScalaLibraryRuleSuffix,
4446
protoFileFilter: serviceFiles,
4547
})
48+
protoc.Rules().MustRegisterRule("stackb:rules_proto:"+GrpcZioscalaLibraryRuleName,
49+
&scalaLibrary{
50+
kindName: GrpcZioscalaLibraryRuleName,
51+
ruleSuffix: grpcZioScalaLibraryRuleSuffix,
52+
protoFileFilter: serviceFiles,
53+
})
4654
}
4755

4856
// scalaLibrary implements LanguageRule for the 'proto_scala_library' rule from

plugin/scalapb/zio-grpc/BUILD.bazel

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
load("@build_stack_rules_proto//rules:proto_plugin.bzl", "proto_plugin")
2+
3+
proto_plugin(
4+
name = "protoc-gen-zio-grpc",
5+
out = "{BIN_DIR}/{PACKAGE}/{PROTO_LIBRARY_BASENAME}_zio_grpc.srcjar",
6+
options = ["flat_package"],
7+
tool = ":zio_grpc_codegen",
8+
use_built_in_shell_environment = True,
9+
visibility = ["//visibility:public"],
10+
)
11+
12+
java_binary(
13+
name = "zio_grpc_codegen",
14+
main_class = "scalapb.zio_grpc.ZioCodeGenerator",
15+
visibility = ["//visibility:public"],
16+
runtime_deps = [
17+
"@maven_zio//:com_thesamet_scalapb_zio_grpc_zio_grpc_codegen_2_12",
18+
],
19+
)
20+
21+
filegroup(
22+
name = "all_files",
23+
testonly = True,
24+
srcs = ["BUILD.bazel"],
25+
visibility = ["//plugin:__pkg__"],
26+
)

rules/scala/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ filegroup(
44
srcs = [
55
"BUILD.bazel",
66
"grpc_scala_library.bzl",
7+
"grpc_zio_scala_library.bzl",
78
"proto_scala_library.bzl",
89
"scala_proto_library.bzl",
910
],

0 commit comments

Comments
 (0)