forked from opensearch-project/opensearch-protobufs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBUILD.bazel
More file actions
157 lines (143 loc) · 5.39 KB
/
Copy pathBUILD.bazel
File metadata and controls
157 lines (143 loc) · 5.39 KB
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
load("@io_bazel_rules_go//go:def.bzl", "go_library")
load("@versioning//:version.bzl", "VERSION")
load("@rules_proto_grpc//python:defs.bzl", "python_proto_library", "python_grpc_library")
load("@rules_python//python:packaging.bzl", "py_wheel")
package(default_visibility = ["//visibility:public"])
java_library(
name = "java_protos_all",
visibility = ["//visibility:public"],
exports = [
"//protos/schemas:common_java_proto",
"//protos/services:document_service_java_proto",
"//protos/services:search_service_java_proto",
],
)
python_proto_library(
name = "python_schemas",
visibility = ["//visibility:public"],
protos = [
"//protos/schemas:common_proto",
],
)
python_grpc_library(
name = "python_services",
visibility = ["//visibility:public"],
protos = [
"//protos/services:document_service_proto",
"//protos/services:search_service_proto",
],
deps = [
":python_schemas"
]
)
go_library(
name = "go_protos_all",
visibility = ["//visibility:public"],
deps = [
"//protos/schemas:common_go_proto",
"//protos/services:document_service_go_proto",
"//protos/services:search_service_go_proto",
],
)
"""
Package python libraries into a wheel.
Protoc does not provide a package option for python so we must fix the import statements in these proto files manually:
https://github.com/protocolbuffers/protobuf/issues/7061
https://github.com/protocolbuffers/protobuf/issues/2283
Additionally rules_proto_grpc 4.5.0 (and all pre 5.0.0/bazel mod versions) do not support pyi generation.
To supply debug symbols an additional genrule is needed to compile them manually with protoc.
"""
genrule(
name = "generate_pyi_files",
srcs = [
"//protos/schemas:common.proto",
"//protos/services:document_service.proto",
"//protos/services:search_service.proto",
"@com_google_protobuf//:well_known_type_protos",
"@com_google_protobuf//:descriptor_proto_srcs",
],
outs = [
"python_pyi/schemas/common_pb2.pyi",
"python_pyi/services/document_service_pb2.pyi",
"python_pyi/services/search_service_pb2.pyi",
],
cmd = """
# Use protoc with --pyi_out to generate debug symbols
$(location @com_google_protobuf//:protoc) \
--proto_path=. \
--proto_path=external/com_google_protobuf/src \
--pyi_out=$(RULEDIR) \
protos/schemas/common.proto \
protos/services/document_service.proto \
protos/services/search_service.proto
mkdir -p $(RULEDIR)/python_pyi/
mv $(RULEDIR)/protos/schemas $(RULEDIR)/python_pyi
mv $(RULEDIR)/protos/services $(RULEDIR)/python_pyi
""",
tools = ["@com_google_protobuf//:protoc"],
)
genrule(
name = "python_protos_all",
srcs = [
":python_schemas",
":python_services",
":generate_pyi_files",
"tools/generate_init_files.py",
],
outs = [
"opensearch/protobufs/schemas/common_pb2.py",
"opensearch/protobufs/schemas/common_pb2.pyi",
"opensearch/protobufs/services/document_service_pb2.py",
"opensearch/protobufs/services/document_service_pb2.pyi",
"opensearch/protobufs/services/document_service_pb2_grpc.py",
"opensearch/protobufs/services/search_service_pb2.py",
"opensearch/protobufs/services/search_service_pb2.pyi",
"opensearch/protobufs/services/search_service_pb2_grpc.py",
"opensearch/__init__.py",
"opensearch/protobufs/__init__.py",
"opensearch/protobufs/schemas/__init__.py",
"opensearch/protobufs/services/__init__.py",
],
cmd = """
mkdir -p $(RULEDIR)/opensearch/protobufs/
cp -rL $(BINDIR)/python_schemas_pb/protos/schemas $(RULEDIR)/opensearch/protobufs
cp -rL $(BINDIR)/python_services_pb/protos/services $(RULEDIR)/opensearch/protobufs
cp -rL $(BINDIR)/python_pyi/schemas $(RULEDIR)/opensearch/protobufs
cp -rL $(BINDIR)/python_pyi/services $(RULEDIR)/opensearch/protobufs
# Find and replace "from protos" with "from opensearch.protobufs" in all files
find $(RULEDIR)/opensearch/protobufs/ -type f -exec sed -i 's/from protos/from opensearch.protobufs/g' {} +
# Generate __init__.py files automatically
python3 tools/generate_init_files.py $(RULEDIR)/opensearch/protobufs/schemas $(RULEDIR)/opensearch/protobufs/services
""",
)
py_wheel(
name = "opensearch_protos_wheel",
distribution = "opensearch-protobufs",
python_tag = "py3",
version = VERSION,
requires = [
"protobuf>=3.25.8",
"grpcio>=1.70.0",
],
author = "OpenSearch Team",
license = "Apache-2.0",
classifiers = [
"Intended Audience :: Developers",
"License :: OSI Approved :: Apache Software License",
"Programming Language :: Python :: 3",
],
homepage = "https://opensearch.org/",
project_urls = {
"Bug Tracker": "https://github.com/opensearch-project/opensearch-protobufs/issues",
"Documentation": "https://github.com/opensearch-project/opensearch-protobufs/blob/main/README.md",
"Source Code": "https://github.com/opensearch-project/opensearch-protobufs",
},
platform = "any",
python_requires = ">=3.10",
extra_distinfo_files = {
"//:LICENSE.txt": "LICENSE.txt",
},
deps = [
":python_protos_all",
],
)