This repository has been archived by the owner on Oct 27, 2023. It is now read-only.
forked from pubref/rules_protobuf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rules.bzl
110 lines (91 loc) · 2.63 KB
/
rules.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
load("@io_bazel_rules_dotnet//dotnet:csharp.bzl", "nuget_package", "new_nuget_package", "csharp_library", "dll_import")
load("//protobuf:rules.bzl", "proto_compile", "proto_repositories", "proto_language_deps")
load("//cpp:rules.bzl", "cpp_proto_repositories")
load("//csharp:deps.bzl", "DEPS")
def csharp_proto_repositories(
omit_cpp_repositories = False,
lang_deps = DEPS,
lang_requires = [
"protoc_gen_grpc_csharp",
"nuget_google_protobuf",
"nuget_grpc",
], **kwargs):
if not omit_cpp_repositories:
cpp_proto_repositories()
rem = proto_repositories(lang_deps = lang_deps,
lang_requires = lang_requires,
**kwargs)
# Load remaining (nuget) deps
for dep in rem:
rule = dep.pop("rule")
if "new_nuget_package" == rule:
new_nuget_package(**dep)
else:
fail("Unknown loading rule %s for %s" % (rule, dep))
PB_COMPILE_DEPS = [
"@nuget_google_protobuf//:libnet45",
]
GRPC_COMPILE_DEPS = PB_COMPILE_DEPS + [
"@nuget_grpc//:core",
]
def csharp_proto_compile(langs = [str(Label("//csharp"))], **kwargs):
proto_compile(langs = langs, **kwargs)
def csharp_proto_library(
name,
langs = [str(Label("//csharp"))],
protos = [],
imports = [],
inputs = [],
proto_deps = [],
output_to_workspace = False,
protoc = None,
pb_plugin = None,
pb_options = [],
grpc_plugin = None,
grpc_options = [],
proto_compile_args = {},
with_grpc = False,
srcs = [],
deps = [],
verbose = 0,
**kwargs):
proto_compile_args += {
"name": name + ".pb",
"protos": protos,
"deps": [dep + ".pb" for dep in proto_deps],
"langs": langs,
"imports": imports,
"inputs": inputs,
"pb_options": pb_options,
"grpc_options": grpc_options,
"output_to_workspace": output_to_workspace,
"verbose": verbose,
"with_grpc": with_grpc,
}
if protoc:
proto_compile_args["protoc"] = protoc
if pb_plugin:
proto_compile_args["pb_plugin"] = pb_plugin
if grpc_plugin:
proto_compile_args["grpc_plugin"] = grpc_plugin
proto_compile(**proto_compile_args)
# proto_language_deps(
# name = name + "_deps",
# langs = langs,
# file_extensions = [".dll"],
# with_grpc = with_grpc,
# )
# dll_import(
# name = name + "_imports",
# srcs = [name + "_deps"],
# )
if with_grpc:
compile_deps = GRPC_COMPILE_DEPS
else:
compile_deps = PB_COMPILE_DEPS
csharp_library(
name = name,
srcs = srcs + [name + ".pb"],
#deps = list(set(deps + proto_deps + [name + "_imports"])),
deps = list(set(deps + proto_deps + compile_deps)),
**kwargs)