forked from TraceMachina/nativelink
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBUILD.bazel
128 lines (116 loc) · 3.11 KB
/
BUILD.bazel
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
load(
"@rules_rust//rust:defs.bzl",
"rust_binary",
"rust_doc",
"rust_doc_test",
"rust_library",
)
PROTO_NAMES = [
"build.bazel.remote.execution.v2",
"build.bazel.semver",
"com.github.trace_machina.nativelink.remote_execution",
"google.api",
"google.bytestream",
"google.devtools.build.v1",
"google.longrunning",
"google.rpc",
]
rust_binary(
name = "gen_protos_tool",
srcs = ["gen_protos_tool.rs"],
deps = [
"@crates//:clap",
"@crates//:prost-build",
"@crates//:tonic-build",
],
)
genrule(
name = "gen_rs_protos",
srcs = [
"build/bazel/remote/execution/v2/remote_execution.proto",
"build/bazel/semver/semver.proto",
"com/github/trace_machina/nativelink/remote_execution/worker_api.proto",
"google/api/annotations.proto",
"google/api/client.proto",
"google/api/field_behavior.proto",
"google/api/http.proto",
"google/bytestream/bytestream.proto",
"google/devtools/build/v1/build_events.proto",
"google/devtools/build/v1/build_status.proto",
"google/devtools/build/v1/publish_build_event.proto",
"google/longrunning/operations.proto",
"google/protobuf/any.proto",
"google/protobuf/descriptor.proto",
"google/protobuf/duration.proto",
"google/protobuf/empty.proto",
"google/protobuf/timestamp.proto",
"google/protobuf/wrappers.proto",
"google/rpc/status.proto",
],
outs = ["{}.pb.rs".format(name) for name in PROTO_NAMES],
cmd = '''
set -e
export PROTOC=$(execpath @protobuf//:protoc)
$(execpath :gen_protos_tool) $(SRCS) -o $(RULEDIR)
for file in $(RULEDIR)/*.rs; do
mv -- "$$file" "$${file%.rs}.pb.rs"
done
''',
tools = [
":gen_protos_tool",
"@protobuf//:protoc",
],
)
py_binary(
name = "gen_lib_rs_tool",
srcs = ["gen_lib_rs_tool.py"],
)
genrule(
name = "gen_lib_rs",
srcs = [":gen_rs_protos"],
outs = ["lib.rs"],
cmd = "$(execpath :gen_lib_rs_tool) --rootdir $(RULEDIR) $(SRCS) > $@",
tools = [":gen_lib_rs_tool"],
)
rust_library(
name = "nativelink-proto",
srcs = glob(["genproto/*.rs"]),
tags = ["no-rustfmt"],
visibility = ["//visibility:public"],
deps = [
"@crates//:prost",
"@crates//:prost-types",
"@crates//:tonic",
],
)
py_binary(
name = "update_protos",
srcs = ["update_protos.py"],
args = ["--update"] + PROTO_NAMES,
data = [
":gen_lib_rs",
":gen_rs_protos",
],
)
# Test to ensure the proto files are in sync with the checked in files.
py_test(
name = "update_protos_test",
timeout = "short",
srcs = ["update_protos.py"],
args = ["--check"] + PROTO_NAMES,
data = glob(["genproto/*.rs"]) + [
":gen_lib_rs",
":gen_rs_protos",
],
main = "update_protos.py",
)
rust_doc(
name = "docs",
crate = ":nativelink-proto",
visibility = ["//visibility:public"],
)
rust_doc_test(
name = "doc_test",
timeout = "short",
crate = ":nativelink-proto",
)