forked from higherkindness/rules_scala
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathscala_proto.bzl
82 lines (74 loc) · 2.67 KB
/
scala_proto.bzl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
load("@bazel_skylib//lib:dicts.bzl", _dicts = "dicts")
load(
"//rules/scala_proto:private/core.bzl",
_scala_proto_library_implementation = "scala_proto_library_implementation",
_scala_proto_library_private_attributes = "scala_proto_library_private_attributes",
)
scala_proto_library = rule(
attrs = _dicts.add(
_scala_proto_library_private_attributes,
{
"deps": attr.label_list(
doc = "The proto_library targets you wish to generate Scala from",
providers = [ProtoInfo],
),
"_zipper": attr.label(cfg = "host", default = "@bazel_tools//tools/zip:zipper", executable = True),
},
),
doc = """
Generates Scala code from proto sources. The output is a `.srcjar` that can be passed into other rules for compilation.
See example use in [/tests/proto/BUILD](/tests/proto/BUILD)
""",
toolchains = [
"@rules_scala_annex//rules/scala_proto:compiler_toolchain_type",
],
outputs = {
"srcjar": "%{name}.srcjar",
},
implementation = _scala_proto_library_implementation,
)
def _scala_proto_toolchain_implementation(ctx):
return [platform_common.ToolchainInfo(
compiler = ctx.attr.compiler,
compiler_supports_workers = ctx.attr.compiler_supports_workers,
)]
scala_proto_toolchain = rule(
attrs = {
"compiler": attr.label(
doc = "The compiler to use to generate Scala form proto sources",
allow_files = True,
executable = True,
cfg = "host",
),
"compiler_supports_workers": attr.bool(default = False),
},
doc = """
Specifies a toolchain of the `@rules_scala_annex//rules/scala_proto:compiler_toolchain_type` toolchain type.
This rule should be used with an accompanying `toolchain` that binds it and specifies constraints
(See the official documentation for more info on [Bazel Toolchains](https://docs.bazel.build/versions/master/toolchains.html))
For example:
```python
scala_proto_toolchain(
name = "scalapb_toolchain_example",
compiler = ":worker",
compiler_supports_workers = True,
visibility = ["//visibility:public"],
)
toolchain(
name = "scalapb_toolchain_example_linux",
toolchain = ":scalapb_toolchain_example",
toolchain_type = "@rules_scala_annex//rules/scala_proto:compiler_toolchain_type",
exec_compatible_with = [
"@bazel_tools//platforms:linux",
"@bazel_tools//platforms:x86_64",
],
target_compatible_with = [
"@bazel_tools//platforms:linux",
"@bazel_tools//platforms:x86_64",
],
visibility = ["//visibility:public"],
)
```
""",
implementation = _scala_proto_toolchain_implementation,
)